Skip to content

fix: fix uab export, cross arch build and update templates#1551

Merged
dengbo11 merged 1 commit into
OpenAtom-Linyaps:masterfrom
reddevillg:fix_utils
Jan 14, 2026
Merged

fix: fix uab export, cross arch build and update templates#1551
dengbo11 merged 1 commit into
OpenAtom-Linyaps:masterfrom
reddevillg:fix_utils

Conversation

@reddevillg

Copy link
Copy Markdown
Collaborator

No description provided.

Signed-off-by: reddevillg <reddevillg@gmail.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @reddevillg, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the build system's capability to handle cross-architecture UAB exports and improving the reliability of dependency resolution for different target platforms. It streamlines the process of fetching necessary build utilities and updates the default template configurations to newer versions, ensuring a more robust and up-to-date build environment.

Highlights

  • UAB Export Logic Refinement: The Universal Application Bundle (UAB) export mechanism has been significantly refactored to ensure correct handling of target architectures, especially for cross-architecture builds and distributed exports.
  • Cross-Architecture Dependency Resolution: The ensureUtils function now unconditionally pulls base and runtime dependencies for the specified target architecture, removing a previous restriction that only pulled dependencies if the target matched the current CPU architecture. This is crucial for successful cross-architecture builds.
  • Updated Build Templates: The example.yaml build template has been updated to reference newer versions of the Deepin base and runtime environments (from 23.1.0 to 25.2.1).

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several fixes and improvements. It addresses issues with UAB export and cross-architecture builds by refactoring the logic for handling package references and dependencies. Specifically, it ensures that dependencies for build-utils are pulled correctly during cross-compilation and improves error handling and logging. The logic for determining the current package reference in exportUAB has been moved up and enhanced with better validation. Additionally, the default versions for base and runtime in the example template have been updated.

My review includes a suggestion to simplify a condition in linglong_builder.cpp by removing a redundant check, which will improve code clarity.

Comment on lines +1406 to +1411
if (underProject && this->project->package.kind != "app") {
return LINGLONG_ERR(
fmt::format("can't export {} kind UAB in executable mode, if you want to export UAB "
"in distributed mode, please use --ref option instead",
this->project->package.kind));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The underProject check is redundant here. The preceding check if (!underProject) on line 1402 ensures that underProject is true at this point, and therefore this->project has a value. You can simplify the condition to improve readability.

        if (this->project->package.kind != "app") {
            return LINGLONG_ERR(
              fmt::format("can't export {} kind UAB in executable mode, if you want to export UAB "
                          "in distributed mode, please use --ref option instead",
                          this->project->package.kind));
        }

@deepin-ci-robot

Copy link
Copy Markdown
Collaborator

deepin pr auto review

这份代码diff主要包含两个文件的修改:linglong_builder.cppexample.yaml。以下是对代码的详细审查和改进建议:

1. 代码逻辑与架构审查

linglong_builder.cpp 修改点分析

修改点1:ensureUtils 函数中的依赖拉取逻辑调整

  • 修改内容:移除了 if (arch == package::Architecture::currentCPUArchitecture()) 的条件判断,使得无论目标架构是什么,都会尝试拉取 base 和 runtime 依赖。
  • 潜在问题
    • 跨架构构建风险:注释提到 "assumes these dependencies are available for the current architecture"。如果当前是 x86_64 环境,构建 arm64 的包,代码会尝试拉取 arm64 的 base 和 runtime。如果仓库中没有对应的 arm64 依赖,或者当前环境无法解析/运行 arm64 的元数据(虽然只是拉取,通常没问题),构建会失败。
    • 依赖一致性:注释指出这要求 build-utils 为目标和当前架构都构建了相同版本。这是一个强假设。如果 cn.org.linyaps.builder.utils 的版本更新了,但只更新了 x86_64 版本,arm64 的构建流程可能会因为依赖旧版本的 utils 或找不到 utils 而中断。
  • 改进建议
    • 建议保留对架构的检查,或者增加更健壮的错误处理。如果拉取依赖失败(例如仓库中不存在该架构的依赖),应给出明确的错误提示,说明当前构建环境可能不支持该目标架构的依赖拉取,或者需要手动配置。
    • 考虑在文档或 CI 配置中明确说明跨架构构建对依赖版本的要求。

修改点2:exportUAB 函数中 curRef 计算逻辑的提前

  • 修改内容:将获取 curRef 的 lambda 表达式及其执行逻辑从函数后部移到了函数前部(在架构检查之前)。
  • 优点
    • 逻辑更清晰:先确定要导出的引用(curRef),再基于该引用进行后续的架构检查和工具准备。这符合线性思维,代码可读性更好。
    • 错误处理前置:如果 curRef 获取失败(例如解析失败、不在项目中),函数会提前返回,避免执行后续不必要的操作(如架构检查、拉取 utils)。
  • 改进建议
    • curRef 的计算逻辑中,对于 underProject 为 true 且 kind 不是 "app" 的情况,错误信息提示使用 --ref 选项。这是一个很好的用户体验改进,建议保留。
    • 逻辑移动后,确保所有使用 projectRef 的地方都替换为了 curRef(diff 中已正确替换)。

修改点3:日志级别调整

  • 修改内容:将 cn.org.linyaps.builder.utils 未找到时的日志从 LogD (Debug) 改为 LogW (Warning)。
  • 优点
    • 这是一个合理的调整。找不到构建工具是一个值得注意的情况,但可能不是致命错误(因为有 fallback 到系统工具的逻辑),因此 Warning 级别更合适。

2. 代码质量与规范

  • 命名与可读性
    • 变量名 curReflayerItembaseRef 等命名清晰,符合上下文。
    • 错误信息使用了 LINGLONG_ERR 宏,并附带上下文信息(如 "failed to pull base binary"),便于调试。
  • 代码重复
    • ensureUtils 函数中,拉取 baseruntime 的代码块非常相似。可以考虑提取一个私有辅助函数 pullRequiredDependency 来减少重复代码。
    • 示例:
      auto pullDep = [&](const std::string &depStr, const std::string &depType) -> utils::error::Result<void> {
          auto depRef = clearDependency(depStr, false, true);
          if (!depRef) {
              return LINGLONG_ERR(depType + " not exist: " + QString::fromStdString(depStr));
          }
          if (!pullDependency(*depRef, this->repo, "binary")) {
              return LINGLONG_ERR("failed to pull " + depType + " binary " + QString::fromStdString(depStr));
          }
          return utils::error::Ok();
      };
      
      if (auto res = pullDep(info.base, "base"); !res) {
          return res;
      }
      if (info.runtime) {
          if (auto res = pullDep(info.runtime.value(), "runtime"); !res) {
              return res;
          }
      }

3. 代码性能

  • ensureUtils 函数
    • 移除架构判断后,对于非当前架构的构建,增加了 getLayerItempullDependency 的调用。这会增加构建时间,特别是当依赖需要从远程仓库下载时。
    • 建议:如果跨架构构建不是高频场景,或者确定依赖总是存在,这个性能开销是可以接受的。否则,建议评估是否真的需要无条件拉取依赖。

4. 代码安全

  • 输入验证
    • exportUAB 中对 exportOpts.ref 进行了解析和验证(FuzzyReference::parseclearReference),这是好的做法。
    • clearDependencypullDependency 内部应该也有对输入的验证,建议确保这些函数能正确处理恶意或格式错误的输入。
  • 路径安全
    • getMergedModuleDirgetLayerItem 涉及文件系统操作。确保这些函数内部对路径进行了规范化处理,防止路径遍历攻击(虽然在这个上下文中,输入主要来自配置文件和内部状态,风险较低)。
  • 依赖注入
    • 代码依赖 cn.org.linyaps.builder.utils。如果这个包被篡改,可能会影响构建过程。建议确保这个包来自可信源,并在拉取时验证其签名或哈希(如果 repo 实现支持的话)。

5. 其他建议

  • 测试
    • 修改涉及跨架构构建逻辑,建议增加测试用例覆盖以下场景:
      • 当前架构构建。
      • 跨架构构建(如 x86_64 上构建 arm64)。
      • cn.org.linyaps.builder.utils 存在和不存在的情况。
      • base/runtime 依赖存在和不存在的情况。
  • 文档
    • example.yaml 的修改(base 版本更新)应该同步更新相关的文档或发布说明,告知用户 base 版本的变化可能带来的影响。

总结

这次代码修改主要是为了优化 exportUAB 的逻辑流程,并调整 ensureUtils 的依赖拉取行为。整体来看,代码质量较高,逻辑更清晰。主要的潜在风险在于跨架构构建时的依赖可用性,建议加强测试和错误处理。移除重复代码和增强日志记录是积极的改进。

@codecov

codecov Bot commented Jan 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 40 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...linglong/src/linglong/builder/linglong_builder.cpp 0.00% 40 Missing ⚠️
Files with missing lines Coverage Δ
...linglong/src/linglong/builder/linglong_builder.cpp 2.33% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes UAB export functionality for cross-architecture builds and updates template base/runtime versions from 23.1.0 to 25.2.1.

Changes:

  • Removes architecture restriction in ensureUtils to enable cross-architecture dependency pulling for build utilities
  • Refactors exportUAB to compute package reference earlier and add validation for non-app package kinds in executable mode
  • Updates example template to use newer base and runtime versions (25.2.1)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
misc/share/linglong/builder/templates/example.yaml Updates base and runtime version references from 23.1.0 to 25.2.1
libs/linglong/src/linglong/builder/linglong_builder.cpp Removes architecture check in ensureUtils and refactors exportUAB to support cross-architecture builds with earlier reference resolution

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return LINGLONG_ERR("not under project");
}

if (underProject && this->project->package.kind != "app") {

Copilot AI Jan 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition underProject && this->project->package.kind != "app" is redundant. At line 1402-1404, there's already a check that returns an error if !underProject. Therefore, at line 1406, underProject is guaranteed to be true and can be removed from the condition.

Suggested change
if (underProject && this->project->package.kind != "app") {
if (this->project->package.kind != "app") {

Copilot uses AI. Check for mistakes.
Comment on lines +453 to +462
// assumes these dependencies are available for the current architecture,
// this requires the same version of `build-utils` to be built for both
// the target and the current architectures.
auto baseRef = clearDependency(info.base, false, true);
if (!baseRef) {
return LINGLONG_ERR("base not exist: " + QString::fromStdString(info.base));
}
if (!pullDependency(*baseRef, this->repo, "binary")) {
return LINGLONG_ERR("failed to pull base binary " + QString::fromStdString(info.base));
}

Copilot AI Jan 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the architecture check that previously prevented pulling dependencies for non-matching architectures is a significant behavior change. This allows cross-architecture builds, but the new behavior assumes that the same version of build-utils is available for both target and current architectures (as noted in the comment). This change lacks test coverage to verify that the dependency pulling works correctly for cross-architecture scenarios.

Copilot uses AI. Check for mistakes.
Comment on lines +1381 to +1414
const bool underProject = this->project.has_value();
auto curRef = [this,
&exportOpts,
underProject,
distributedOnly]() -> utils::error::Result<package::Reference> {
LINGLONG_TRACE("get current reference");

if (distributedOnly) {
auto fuzzyRef = package::FuzzyReference::parse(exportOpts.ref);
if (!fuzzyRef) {
return LINGLONG_ERR("fuzzy ref", fuzzyRef);
}

auto targetRef = this->repo.clearReference(*fuzzyRef, { .fallbackToRemote = false });
if (!targetRef) {
return LINGLONG_ERR("clear ref", targetRef);
}

return targetRef;
}

if (!underProject) {
return LINGLONG_ERR("not under project");
}

if (underProject && this->project->package.kind != "app") {
return LINGLONG_ERR(
fmt::format("can't export {} kind UAB in executable mode, if you want to export UAB "
"in distributed mode, please use --ref option instead",
this->project->package.kind));
}

return currentReference(*this->project);
}();

Copilot AI Jan 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring that moves the curRef calculation earlier and adds the package kind validation is a significant change to the UAB export flow. This new logic (lines 1381-1414) and its interaction with the architecture checks (line 1420) and utility retrieval (line 1429) lacks test coverage to verify all the edge cases, particularly for non-app package kinds and distributed vs. executable export modes.

Copilot uses AI. Check for mistakes.
@dengbo11 dengbo11 merged commit 7588ca5 into OpenAtom-Linyaps:master Jan 14, 2026
14 of 15 checks passed
@deepin-ci-robot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengbo11, reddevillg

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@reddevillg reddevillg deleted the fix_utils branch January 14, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants