Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code sync #36

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion apps/generators/90-legacy/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#include <filesystem>
#include <iostream>
#include <string>
#include <system_error>
#include <vector>

int main()
{
Expand Down Expand Up @@ -117,7 +120,34 @@ int main()
});
}
}

// randomize mount points to avoid path dependency.
auto now = std::chrono::system_clock::now();
auto t = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
auto shareDir = std::filesystem::path("/run/linglong/usr/share_" + std::to_string(t));
// add mount points to XDG_DATA_DIRS
std::vector<std::string> env = content["process"]["env"];
// 查找是否存在XDG_DATA_DIRS开头的环境变量,如果存在追加到尾部,不存在则添加
auto it = std::find_if(env.begin(), env.end(), [](const std::string &var) {
return var.find("XDG_DATA_DIRS=") == 0;
});
if (it != env.end()) {
// 如果存在,追加到尾部
*it += ":" + shareDir.string();
} else {
// 如果不存在,添加到末尾
env.push_back("XDG_DATA_DIRS=" + shareDir.string());
}
std::error_code ec;
// mount for dtk
if (std::filesystem::exists("/usr/share/deepin/distribution.info", ec)) {
mounts.push_back({
{ "destination", shareDir / "deepin/distribution.info" },
{ "options", nlohmann::json::array({ "nodev", "nosuid", "mode=0644" }) },
{ "source", "/usr/share/deepin/distribution.info" },
{ "type", "bind" },
});
}
content["process"]["env"] = env;
std::cout << content.dump() << std::endl;
return 0;
}
69 changes: 34 additions & 35 deletions libs/linglong/src/linglong/builder/linglong_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ set -e

qDebug() << "generate entries";
if (this->project.package.kind != "runtime") {
// 仅导出名单中的目录,以避免意外文件影响系统功能
const QStringList exportPaths = {
"share/applications", // Copy desktop files
"share/mime", // Copy MIME Type files
Expand Down Expand Up @@ -971,18 +972,19 @@ set -e
if (!binaryFiles.exists(path)) {
continue;
}

const QString dest = QString("../../files/%1").arg(path);

// appdata是旧版本的metainfo
if (path == "share/appdata") {
if (!QFile::link(dest, binaryEntries.absoluteFilePath("share/metainfo"))) {
auto ret = copyDir(binaryFiles.absoluteFilePath(path),
binaryEntries.filePath("share/metainfo"));
if (!ret.has_value()) {
qWarning() << "link binary entries share to files share/" << path << "failed";
}

continue;
}

if (!QFile::link(dest, binaryEntries.absoluteFilePath(path))) {
auto ret =
copyDir(binaryFiles.absoluteFilePath(path), binaryEntries.absoluteFilePath(path));
if (!ret.has_value()) {
qWarning() << "link binary entries " << path << "to files share: failed";
continue;
}
Expand Down Expand Up @@ -1346,44 +1348,41 @@ utils::error::Result<void> Builder::run(const QStringList &modules,
.mounts = {},
};

auto baseRef = pullDependency(QString::fromStdString(this->project.base),
this->repo,
"binary",
this->buildOptions.skipPullDepend);
auto fuzzyBase = package::FuzzyReference::parse(QString::fromStdString(this->project.base));
if (!fuzzyBase) {
return LINGLONG_ERR(fuzzyBase);
}
auto baseRef =
this->repo.clearReference(*fuzzyBase, { .forceRemote = false, .fallbackToRemote = false });
if (!baseRef) {
return LINGLONG_ERR(baseRef);
}
auto baseDir =
debug ? this->repo.getMergedModuleDir(*baseRef) : this->repo.getLayerDir(*baseRef, "binary");
if (!baseDir) {
return LINGLONG_ERR(baseDir);
}
options.baseDir = *baseDir;

if (this->project.runtime) {
auto ref = pullDependency(QString::fromStdString(*this->project.runtime),
this->repo,
"binary",
this->buildOptions.skipPullDepend);
if (!ref) {
return LINGLONG_ERR(ref);
}
auto ret = this->repo.mergeModules();
if (!ret.has_value()) {
return ret;
auto fuzzyRuntime =
package::FuzzyReference::parse(QString::fromStdString(this->project.runtime.value()));
if (!fuzzyRuntime) {
return LINGLONG_ERR(fuzzyRuntime);
}
auto dir =
debug ? this->repo.getMergedModuleDir(*ref) : this->repo.getLayerDir(*ref, "binary");
if (!dir) {
return LINGLONG_ERR(dir);
auto runtimeRef =
this->repo.clearReference(*fuzzyRuntime,
{ .forceRemote = false, .fallbackToRemote = false });
if (!runtimeRef) {
return LINGLONG_ERR(runtimeRef);
}
options.runtimeDir = QDir(dir->absolutePath());
} else {
auto ret = this->repo.mergeModules();
if (!ret.has_value()) {
return ret;
auto runtimeDir = debug ? this->repo.getMergedModuleDir(*runtimeRef)
: this->repo.getLayerDir(*runtimeRef, "binary");
if (!runtimeDir) {
return LINGLONG_ERR(runtimeDir);
}
options.runtimeDir = *runtimeDir;
}
auto baseDir =
debug ? this->repo.getMergedModuleDir(*baseRef) : this->repo.getLayerDir(*baseRef, "binary");
if (!baseDir) {
return LINGLONG_ERR(baseDir);
}
options.baseDir = QDir(baseDir->absolutePath());

utils::error::Result<package::LayerDir> curDir;
// mergedDir 会自动在释放时删除临时目录,所以要用变量保留住
Expand Down