feat: ll-builder adds system environment variables
构建添加一些默认的环境变量, 支持rootfs在 /etc/profile.d 添加自定义环境变量 Log:
This commit is contained in:
parent
62a9cea5c9
commit
39f51f8f9d
|
|
@ -454,6 +454,10 @@ int main(int argc, char **argv)
|
|||
buildArch });
|
||||
|
||||
parser.addPositionalArgument("build", "build project", "build");
|
||||
parser.setApplicationDescription("linglong build command tools\n"
|
||||
"Examples:\n"
|
||||
"ll-builder build -v\n"
|
||||
"ll-builder build -v -- bash -c \"echo hello\"");
|
||||
|
||||
parser.process(app);
|
||||
|
||||
|
|
@ -477,10 +481,14 @@ int main(int argc, char **argv)
|
|||
cfg.skipCommit = true;
|
||||
builder.setConfig(cfg);
|
||||
}
|
||||
auto allArgs = QCoreApplication::arguments();
|
||||
linglong::utils::error::Result<void> ret;
|
||||
if (parser.isSet(execVerbose)) {
|
||||
auto exec = splitExec(parser.value(execVerbose));
|
||||
ret = builder.build(exec);
|
||||
} else if (allArgs.indexOf("--") > 0) {
|
||||
auto exec = allArgs.mid(allArgs.indexOf("--") + 1);
|
||||
ret = builder.build(exec);
|
||||
} else {
|
||||
ret = builder.build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QHash>
|
||||
#include <QProcess>
|
||||
#include <QScopeGuard>
|
||||
#include <QTemporaryFile>
|
||||
|
|
@ -37,6 +38,8 @@
|
|||
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
|
|
@ -161,6 +164,7 @@ void Builder::setConfig(const api::types::v1::BuilderConfig &cfg) noexcept
|
|||
this->cfg = cfg;
|
||||
}
|
||||
|
||||
// 拆分develop和runtime的文件
|
||||
utils::error::Result<void> Builder::splitDevelop(QDir developOutput,
|
||||
QDir runtimeOutput,
|
||||
QString prefix)
|
||||
|
|
@ -310,7 +314,7 @@ utils::error::Result<void> Builder::build(const QStringList &args) noexcept
|
|||
}
|
||||
|
||||
std::optional<package::Reference> runtime;
|
||||
package::LayerDir runtimeLayerDir;
|
||||
QString runtimeLayerDir;
|
||||
if (this->project.runtime) {
|
||||
auto ref =
|
||||
pullDependency(QString::fromStdString(*this->project.runtime), this->repo, false);
|
||||
|
|
@ -323,7 +327,7 @@ utils::error::Result<void> Builder::build(const QStringList &args) noexcept
|
|||
if (!ret.has_value()) {
|
||||
return LINGLONG_ERR("get runtime layer dir", ret);
|
||||
}
|
||||
runtimeLayerDir = *ret;
|
||||
runtimeLayerDir = ret->absolutePath();
|
||||
}
|
||||
|
||||
auto base = pullDependency(QString::fromStdString(this->project.base), this->repo, true);
|
||||
|
|
@ -425,9 +429,20 @@ utils::error::Result<void> Builder::build(const QStringList &args) noexcept
|
|||
}
|
||||
qDebug() << "create container success";
|
||||
|
||||
auto arguments = std::vector<std::string>{};
|
||||
for (const auto &arg : args) {
|
||||
arguments.push_back(arg.toStdString());
|
||||
QStringList shArgs;
|
||||
for (auto arg : args) {
|
||||
shArgs.push_back(QString("'%1'").arg(arg.replace("'", "'\\''")));
|
||||
}
|
||||
auto arguments = std::vector<std::string>{
|
||||
"/bin/bash",
|
||||
"-l",
|
||||
"-c",
|
||||
shArgs.join(" ").toStdString(),
|
||||
};
|
||||
|
||||
auto arch = package::Architecture::parse(QSysInfo::currentCpuArchitecture());
|
||||
if (!arch) {
|
||||
return LINGLONG_ERR(arch);
|
||||
}
|
||||
|
||||
auto process = ocppi::runtime::config::types::Process{
|
||||
|
|
@ -437,10 +452,12 @@ utils::error::Result<void> Builder::build(const QStringList &args) noexcept
|
|||
.commandLine = {},
|
||||
.consoleSize = {},
|
||||
.cwd = "/project",
|
||||
.env = { { "PREFIX=" + installPrefix.toStdString(),
|
||||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/runtime/bin"
|
||||
},
|
||||
}, // FIXME: add environments later.
|
||||
.env = { {
|
||||
"PREFIX=" + installPrefix.toStdString(),
|
||||
"TRIPLET=" + arch->getTriplet().toStdString(),
|
||||
"APP_ID=" + this->project.package.id,
|
||||
"APP_VERSION=" + this->project.package.version,
|
||||
} },
|
||||
.ioPriority = {},
|
||||
.noNewPrivileges = true,
|
||||
.oomScoreAdj = {},
|
||||
|
|
@ -449,13 +466,6 @@ utils::error::Result<void> Builder::build(const QStringList &args) noexcept
|
|||
.selinuxLabel = {},
|
||||
.terminal = true,
|
||||
};
|
||||
|
||||
auto arch = package::Architecture::parse(QSysInfo::currentCpuArchitecture());
|
||||
if (!arch) {
|
||||
return LINGLONG_ERR(arch);
|
||||
}
|
||||
process.env->push_back({ QString("TRIPLET=%1").arg(arch->getTriplet()).toStdString() });
|
||||
|
||||
auto result = (*container)->run(process);
|
||||
if (!result) {
|
||||
return LINGLONG_ERR(result);
|
||||
|
|
|
|||
|
|
@ -31,9 +31,6 @@ public:
|
|||
auto build(const QStringList &args = { "/project/linglong/entry.sh" }) noexcept
|
||||
-> utils::error::Result<void>;
|
||||
|
||||
auto splitDevelop(QDir developOutput, QDir runtimeOutput, QString prefix)
|
||||
-> utils::error::Result<void>;
|
||||
|
||||
auto exportLayer(const QString &destination) -> utils::error::Result<void>;
|
||||
|
||||
auto extractLayer(const QString &layerPath, const QString &destination)
|
||||
|
|
@ -51,6 +48,9 @@ public:
|
|||
auto appimageConvert(const QStringList &templateArgs) -> utils::error::Result<void>;
|
||||
|
||||
private:
|
||||
auto splitDevelop(QDir developOutput, QDir runtimeOutput, QString prefix)
|
||||
-> utils::error::Result<void>;
|
||||
|
||||
repo::OSTreeRepo &repo;
|
||||
QDir workingDir;
|
||||
api::types::v1::BuilderProject project;
|
||||
|
|
|
|||
Loading…
Reference in New Issue