跳到正文
Skillpedia
部署与云(DevOps)25k · #10058

gn-deps-debugging

它能做什么

这个技能帮助你的 AI 查找并修复 GN 构建依赖错误。适合在构建大型项目时遇到头文件包含或依赖检查错误的开发者。

适用场景

  • ✓当你的构建因 GN 依赖或包含可见性错误而失败时。
  • ✓当 gn check 报告某个目标不允许使用某个头文件时。
  • ✓当你需要修复构建目标之间的循环依赖时。

技能链接

https://github.com/chromium/chromium/blob/main/agents/skills/gn-deps-debugging/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/chromium/chromium/blob/main/agents/skills/gn-deps-debugging/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我的构建提示某个头文件对我的目标不可见。能找到正确的依赖来修复它吗?”

每周 5 个新技能,1 分钟读完。

工作原理

AI 读取具体的错误,找到拥有该文件的构建目标和拥有该头文件的目标,然后添加最小且正确的依赖。它会保持平台规则不变。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

GN Dependency Debugging

Fix Chromium GN dependency metadata, include visibility, and DEPS rule failures by correcting the dependency graph accurately, not by adding broad dependencies that only make errors disappear.

Core principles

  1. Read the exact error first. Identify the including source file, the included header, the failing target, and the diagnostic category before editing.
  2. Find both owning targets. Determine which GN target owns the including file and which GN target owns the included header.
  3. Prefer the narrowest dependency. Add the dependency to the smallest target that needs it, not a parent or aggregate target.
  4. Preserve platform conditions. If the failing include is in a platform-specific file such as *_win.cc, add the dependency inside the matching platform block such as if (is_win).
  5. Use deps for implementation-only dependencies. If a symbol is used only in .cc files, keep the dependency private.
  6. Use public_deps only for public API exposure. If a public header exposes a type from another target in its declarations or inline code, downstream consumers may need that dependency transitively.
  7. Prefer forward declarations in headers. If a header only needs a pointer, reference, or return type declaration, forward declare and move the include to the .cc file when possible.
  8. Do not paper over architecture issues. Circular dependencies usually indicate the need to split an interface target, move shared abstractions, or invert dependencies.
  9. Avoid // nogncheck. Use it only for known GN limitations with conditional includes, and include the required bug reference if the local codebase already documents one.

Workflow

  1. Capture the failing command and output.

    • If the user provided a truncated error, ask for or rerun the relevant gn check or build command when an output directory and target are known.
    • Do not start a broad build just to reproduce unless the output directory and target are established.
  2. Classify the failure.

    • Read common-errors.md and map the diagnostic to one of the supported categories.
    • Extract the including file, included header, and target names from the diagnostic.
  3. Find the target that owns the including file.

    • Inspect nearby BUILD.gn files first.
    • Use GN queries when an output directory is known:
      gn refs out/Default //path/to/file.cc --all
      
    • Prefer the most specific non-aggregate target that directly lists the file or owns the source set containing it.
    • Check whether the file is platform-specific, such as *_win.cc, *_mac.mm, *_linux.cc, *_android.cc, or *_ios.mm. Platform-specific files usually require platform-specific dependencies.
  4. Find the target that owns the included header.

    • Search for the header in BUILD.gn sources lists.
    • If several targets list it, prefer the public/interface target intended for consumers.
    • Check whether the header belongs to a generated target, a public variable, or a private implementation target.
  5. Choose the correct fix.

    • Read dependency-patterns.md for deps vs public_deps, forward declaration, DEPS, and cycle handling rules.
    • If the include appears only in .cc, add a private deps entry.
    • If the include appears only in a platform-specific source file, add the private deps entry inside the matching platform condition, for example if (is_win).
    • If the include appears in a public header, first try to remove the include using a forward declaration. If the header must expose the dependency, add or promote the dependency to public_deps.
    • If a DEPS file blocks the include, verify whether the dependency direction is allowed by the architecture before adding include rules.
    • If adding the dependency creates a cycle, stop and redesign the dependency boundary instead of adding broader deps. When an output directory is known, use gn path <out_dir> //target_a //target_b to inspect the dependency chain that connects the targets.
  6. Validate the narrow change.

    • Run git cl format if BUILD.gn or DEPS files were edited.
    • Re-run the smallest relevant gn check or build command that reproduced the issue.
    • If
常见问题

什么是 GN?

GN 是大型软件项目使用的构建工具,用于决定代码文件如何编译和链接在一起。

为什么不直接添加一个大的依赖来消除错误?

宽泛的依赖可能掩盖真正的问题,还会拖慢构建。因此这个技能会要求最精确的修复方式。

什么时候不应使用这个技能?

它用于依赖和包含错误。对于编译、链接或运行时失败,应采用其他方法。

详情

作者的原始描述

Diagnose Chromium GN dependency and include-visibility failures, including BUILD.gn deps/public_deps, DEPS include rules, private headers, and circular dependencies. Use for build or gn check dependency errors, not C++/link/runtime/test failures.

repo: chromium/chromium

热度

GitHub 星标
25k
排名
#10058
许可证
BSD-3-Clause
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能