Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 8019461c authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

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@kde.org
parent bcc0bab4
......@@ -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
......
/*
Copyright 2018 Aleix Pol Gonzalez <aleixpol@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 {};
}
/*
Copyright 2018 Aleix Pol Gonzalez <aleixpol@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
......@@ -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();
......
......@@ -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();
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment