[kdevelop/androiddocker] plugins/docker: Provide a new approach to Android based on Docker

Aleix Pol null at kde.org
Wed Mar 7 16:33:59 UTC 2018


Git commit 8019461ce7c1429a943b58a0ec539d2ebb23f30d by Aleix Pol.
Committed on 07/03/2018 at 16:01.
Pushed by apol into branch 'androiddocker'.

Provide a new approach to Android based on Docker

Apparently downloading the Qt SDK is too complex, here's an alternative
based on docker which should make it transparent to download stuff and
will make it much easier for us to provide tooling to download
dependencies, which is also a concern.

CCMAIL: kdevelop-devel at kde.org

M  +1    -1    plugins/docker/CMakeLists.txt
A  +82   -0    plugins/docker/androiddockerruntime.cpp     [License: LGPL (v2)]
A  +41   -0    plugins/docker/androiddockerruntime.h     [License: LGPL (v2)]
M  +2    -0    plugins/docker/dockerplugin.cpp
M  +4    -4    plugins/docker/dockerruntime.cpp
M  +7    -0    plugins/docker/dockerruntime.h

https://commits.kde.org/kdevelop/8019461ce7c1429a943b58a0ec539d2ebb23f30d

diff --git a/plugins/docker/CMakeLists.txt b/plugins/docker/CMakeLists.txt
index ff198ce70b..900e3875a9 100644
--- a/plugins/docker/CMakeLists.txt
+++ b/plugins/docker/CMakeLists.txt
@@ -15,7 +15,7 @@ qt5_add_resources(dockerplugin_SRCS kdevdockerplugin.qrc)
 ki18n_wrap_ui(dockerplugin_SRCS dockerpreferences.ui)
 kconfig_add_kcfg_files(dockerplugin_SRCS dockerpreferencessettings.kcfgc)
 
-kdevplatform_add_plugin(kdevdocker JSON kdevdocker.json SOURCES dockerplugin.cpp dockerruntime.cpp dockerpreferences.cpp ${dockerplugin_SRCS})
+kdevplatform_add_plugin(kdevdocker JSON kdevdocker.json SOURCES dockerplugin.cpp dockerruntime.cpp dockerpreferences.cpp androiddockerruntime.cpp ${dockerplugin_SRCS})
 target_link_libraries(kdevdocker
     KF5::CoreAddons
     KDev::Interfaces
diff --git a/plugins/docker/androiddockerruntime.cpp b/plugins/docker/androiddockerruntime.cpp
new file mode 100644
index 0000000000..c492797bb3
--- /dev/null
+++ b/plugins/docker/androiddockerruntime.cpp
@@ -0,0 +1,82 @@
+/*
+   Copyright 2018 Aleix Pol Gonzalez <aleixpol at kde.org>
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public
+   License version 2 as published by the Free Software Foundation.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this library; see the file COPYING.LIB.  If not, write to
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.
+*/
+
+#include "androiddockerruntime.h"
+#include <KProcess>
+#include <QStandardPaths>
+#include <QAction>
+#include <KLocalizedString>
+#include <QFile>
+#include <QDebug>
+#include <QDir>
+
+AndroidDockerRuntime::AndroidDockerRuntime()
+//     : DockerRuntime(QStringLiteral("kdeorg/ci-android"))
+    : DockerRuntime(QStringLiteral("asdk"))
+{
+}
+
+static QByteArray s_installPrefix = "/opt/kdev-install/";
+
+QByteArray AndroidDockerRuntime::getenv(const QByteArray& varname) const
+{
+    if (varname == "KDEV_DEFAULT_INSTALL_PREFIX") {
+        return s_installPrefix;
+    }
+    return DockerRuntime::getenv(varname);
+}
+
+QStringList AndroidDockerRuntime::extraDockerArguments() const
+{
+    const QString installPrefixLocation = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QStringLiteral("/kdevdockerandroidprefix");
+    const QString outputLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + QStringLiteral("/kdevandroid");
+    QDir().mkpath(installPrefixLocation);
+    QDir().mkpath(outputLocation);
+
+    const QString installPrefixString = QFile::decodeName(s_installPrefix);
+    auto ret = QStringList{ QStringLiteral("--volume"), (installPrefixLocation + QLatin1Char(':') + s_installPrefix) //the install prefix
+           , QStringLiteral("--volume"), (outputLocation + QStringLiteral(":/output")) //the output location
+           , QStringLiteral("-e"), (QStringLiteral("APP_INSTALL_PREFIX=") + s_installPrefix) //tells the build-cmake script where to install dependencies so we can reuse them
+    };
+    return ret;
+}
+
+QString AndroidDockerRuntime::name() const
+{
+    return QStringLiteral("Android + Qt");
+}
+
+QStringList AndroidDockerRuntime::args() const
+{
+    return { QStringLiteral("-DCMAKE_TOOLCHAIN_FILE=/opt/kdeandroid-deps/share/ECM/toolchain/Android.cmake"), QStringLiteral("-DKF5_HOST_TOOLING=/opt/nativetooling/lib/x86_64-linux-gnu/cmake/"), QStringLiteral("-DCMAKE_PREFIX_PATH=") + QString::fromUtf8(getenv("QT_ANDROID")) + QStringLiteral(";/opt/kdeandroid-deps;") + s_installPrefix };
+}
+
+QStringList AndroidDockerRuntime::extraProcessArguments(KProcess* process) const
+{
+    if (process->program().constFirst().endsWith(QLatin1String("/cmake")))
+        return args();
+    return {};
+}
+
+QStringList AndroidDockerRuntime::extraProcessArguments(QProcess* process) const
+{
+    if (process->program().endsWith(QLatin1String("/cmake")))
+        return args();
+    return {};
+}
+
diff --git a/plugins/docker/androiddockerruntime.h b/plugins/docker/androiddockerruntime.h
new file mode 100644
index 0000000000..0065487ef3
--- /dev/null
+++ b/plugins/docker/androiddockerruntime.h
@@ -0,0 +1,41 @@
+/*
+   Copyright 2018 Aleix Pol Gonzalez <aleixpol at kde.org>
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public
+   License version 2 as published by the Free Software Foundation.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this library; see the file COPYING.LIB.  If not, write to
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.
+*/
+
+#ifndef ANDROIDDOCKERRUNTIME_H
+#define ANDROIDDOCKERRUNTIME_H
+
+#include "dockerruntime.h"
+
+class AndroidDockerRuntime : public DockerRuntime
+{
+    Q_OBJECT
+public:
+    AndroidDockerRuntime();
+
+    QString name() const override;
+
+    /** offer a meaningful default install prefix */
+    QByteArray getenv(const QByteArray & varname) const override;
+    QStringList args() const;
+
+    QStringList extraProcessArguments(KProcess * p) const override;
+    QStringList extraProcessArguments(QProcess * p) const override;
+    QStringList extraDockerArguments() const override;
+};
+
+#endif // ANDROIDDOCKERRUNTIME_H
diff --git a/plugins/docker/dockerplugin.cpp b/plugins/docker/dockerplugin.cpp
index de9d535e16..873eea049d 100644
--- a/plugins/docker/dockerplugin.cpp
+++ b/plugins/docker/dockerplugin.cpp
@@ -18,6 +18,7 @@
 
 #include "dockerplugin.h"
 #include "dockerruntime.h"
+#include "androiddockerruntime.h"
 #include "dockerpreferences.h"
 #include "dockerpreferencessettings.h"
 #include <interfaces/icore.h>
@@ -80,6 +81,7 @@ void DockerPlugin::imagesListFinished(int code)
         const QString tag = parts[0] == QLatin1String("<none>") ? parts[1] : parts[0];
         ICore::self()->runtimeController()->addRuntimes(new DockerRuntime(tag));
     }
+    ICore::self()->runtimeController()->addRuntimes(new AndroidDockerRuntime());
 
     process->deleteLater();
     Q_EMIT imagesListed();
diff --git a/plugins/docker/dockerruntime.cpp b/plugins/docker/dockerruntime.cpp
index 8651689215..a07189da4c 100644
--- a/plugins/docker/dockerruntime.cpp
+++ b/plugins/docker/dockerruntime.cpp
@@ -137,12 +137,12 @@ static QStringList projectVolumes()
     for (IProject* project: ICore::self()->projectController()->projects()) {
         const Path path = project->path();
         if (path.isLocalFile()) {
-            ret << "--volume" << QStringLiteral("%1:%2").arg(path.toLocalFile(), dir + project->name());
+            ret << "--volume" << (path.toLocalFile() + QLatin1Char(':') + dir + project->name());
         }
 
         const auto ibsm = project->buildSystemManager();
         if (ibsm) {
-            ret << "--volume" << ibsm->buildDirectory(project->projectItem()).toLocalFile() + QLatin1Char(':') +  buildDir + project->name();
+            ret << "--volume" << ibsm->buildDirectory(project->projectItem()).toLocalFile() + QLatin1Char(':') + buildDir + project->name();
         }
     }
     return ret;
@@ -160,7 +160,7 @@ void DockerRuntime::startProcess(QProcess* process) const
     if (program.contains('/'))
         program = pathInRuntime(Path(program)).toLocalFile();
 
-    const QStringList args = QStringList{"run", "--rm"} << workingDirArgs(process) << KShell::splitArgs(s_settings->extraArguments()) << projectVolumes() << m_tag << program << process->arguments();
+    const QStringList args = QStringList{"run", "--rm"} << workingDirArgs(process) << KShell::splitArgs(s_settings->extraArguments()) << projectVolumes() << extraDockerArguments() << m_tag << program << process->arguments() << extraProcessArguments(process);
     process->setProgram("docker");
     process->setArguments(args);
 
@@ -173,7 +173,7 @@ void DockerRuntime::startProcess(KProcess* process) const
     auto program = process->program();
     if (program[0].contains('/'))
         program[0] = pathInRuntime(Path(program[0])).toLocalFile();
-    process->setProgram(QStringList{ "docker", "run", "--rm" } << workingDirArgs(process) << KShell::splitArgs(s_settings->extraArguments()) << projectVolumes() << m_tag << program);
+    process->setProgram(QStringList{ "docker", "run", "--rm" } << workingDirArgs(process) << KShell::splitArgs(s_settings->extraArguments()) << projectVolumes() << extraDockerArguments() << m_tag << program << extraProcessArguments(process));
 
     qCDebug(DOCKER) << "starting kprocess" << process->program().join(' ');
     process->start();
diff --git a/plugins/docker/dockerruntime.h b/plugins/docker/dockerruntime.h
index 8749e6bfd5..d8ec08f3cc 100644
--- a/plugins/docker/dockerruntime.h
+++ b/plugins/docker/dockerruntime.h
@@ -78,6 +78,13 @@ public:
 
     static DockerPreferencesSettings* s_settings;
 
+
+    /** Allow subclasses to add more arguments */
+    virtual QStringList extraProcessArguments(KProcess */*process*/) const { return {}; }
+    virtual QStringList extraProcessArguments(QProcess */*process*/) const { return {}; }
+
+    /** Allow subclasses to pass more arguments when calling docker run, such as volumes. */
+    virtual QStringList extraDockerArguments() const { return {}; }
 private:
     void inspectContainer();
     QStringList workingDirArgs(QProcess* process) const;



More information about the KDevelop-devel mailing list