skills/compile-analysis/SKILL.md
This skill should be used when the user asks to "分析编译效率", "分析编译时间", "查看头文件依赖", "保存编译命令", "提取编译命令", "生成编译脚本", "保存这个文件的编译命令", "单独编译这个文件", "编译单个文件", "单编文件", "独立编译文件", "分析这个文件的头文件依赖", "头文件依赖关系", "这个文件依赖了多少头文件", "analyze compilation", "check header dependencies", "分析文件编译开销", "save compile command", "extract compile command", "generate compile script", "compile single file", "compile individual file", "standalone compile", "analyze header dependencies", "header dependency tree", "how many header files", or mentions analyzing compilation performance, build times, include dependencies, extracting/saving compilation commands, generating standalone compilation scripts, compiling individual files in isolation, or analyzing header file dependency relationships for specific source files in the ace_engine project. Provides comprehensive compilation efficiency analysis including timing, resource usage, dependency tree visualization with automatic saving, the ability to save reusable compilation scripts with performance monitoring, and standalone compilation capabilities using generated scripts.
npx skillsauth add openharmonyinsight/openharmony-skills compile-analysisInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Analyze compilation efficiency for individual source files in the ACE Engine project. This skill provides detailed insights into compilation time, resource overhead, and header file dependencies to help identify optimization opportunities.
Compilation analysis helps identify performance bottlenecks in the build process by measuring:
Critical Requirements:
out/{product} directory (not from the project root)parse_ii.py script to analyze .ii files - do not use alternative methodsUse this analysis when:
Identify the target source file for analysis. Source files in ace_engine typically follow patterns:
frameworks/core/components_ng/base/frame_node.cppframeworks/bridge/declarative_frontend/engine/js_engine.cppThe analysis scripts automatically locate the OpenHarmony root directory by searching for the .gn file marker. Navigate to the OpenHarmony root directory to ensure proper path resolution.
Option A: Full Analysis (Execute + Display Results)
./.claude/skills/compile-analysis/scripts/analyze_compile.sh <source-file> [product-name]
Example:
./.claude/skills/compile-analysis/scripts/analyze_compile.sh frameworks/core/components_ng/base/frame_node.cpp rk3568
Option B: Save Reusable Compilation Script
Generate a standalone script that can be executed multiple times for performance testing:
./.claude/skills/compile-analysis/scripts/analyze_compile.sh <source-file> [product-name] --save-script
This creates out/{product}/compile_single_file_{name}.sh with:
The analysis produces three key outputs:
MM:SS.mm)When using --save-script, a reusable script is generated for repeated performance testing.
Primary entry point for compilation analysis. Orchestrates the entire analysis workflow:
Usage:
# Full analysis with execution
./.claude/skills/compile-analysis/scripts/analyze_compile.sh <source-file> [product-name]
# Save standalone compilation script
./.claude/skills/compile-analysis/scripts/analyze_compile.sh <source-file> [product-name] --save-script
Arguments:
source-file - Path to the source file (relative to ace_engine root or absolute)product-name - Target product (default: rk3568)--save-script - Save enhanced compilation command to reusable script fileWorkflow:
out/{product}/compile_single_file_{name}.shOutput with --save-script:
out/{product}/compile_single_file_{name}.shExtracts the complete compilation command for a source file from the ninja build system.
Usage (from ace_engine root):
# Display commands only
python3 ./.claude/skills/compile-analysis/scripts/get_compile_command.py \
<source-file> <openharmony_root>/out/<product>
# Save enhanced command (with performance monitoring)
python3 ./.claude/skills/compile-analysis/scripts/get_compile_command.py \
<source-file> <openharmony_root>/out/<product> --save-enhanced
Example:
# From ace_engine directory
python3 ./.claude/skills/compile-analysis/scripts/get_compile_command.py \
frameworks/core/components_ng/base/frame_node.cpp \
/home/sunfei/workspace/openHarmony/out/rk3568 --save-enhanced
Features:
-save-temps for analysis)Output:
--save: Creates {file}_compile_command.sh (original command)--save-enhanced: Creates compile_single_file_{file}.sh (enhanced with monitoring)Analyzes .ii preprocessed files to extract and display header file dependencies.
Usage:
python3 ./.claude/skills/compile-analysis/scripts/parse_ii.py <ii-file>
Features:
#include directives targeting foundation/arkui/Output Format:
头文件的依赖关系树:
└── foundation/arkui/ace_engine/frameworks/core/components_ng/base/frame_node.h
└── foundation/arkui/ace_engine/frameworks/core/components_ng/base/ui_node.h
├── foundation/arkui/ace_engine/frameworks/core/pipeline/base/element.h
└── ...
Format: MM:SS.mm (minutes:seconds.milliseconds)
Reported in kilobytes (KB)
The tree shows hierarchical include relationships:
#include directiveOptimization indicators:
When you need to analyze the header file dependency structure of a source file:
Important: This workflow ONLY uses .ii files generated by compilation scripts. No other dependency analysis methods are used.
Workflow:
.ii file exists in out/{product}/obj/ directory.ii exists → Parse it directly with parse_ii.py.ii doesn't exist → Generate it using compilation script, then parseout/{product}/{file_name}_dependency_tree.txtExample using Claude:
# User request: "分析 frame_node.cpp 的头文件依赖"
# Claude's response:
# Step 1: Check for existing .ii file
# ✓ Found: out/rk3568/obj/.../frame_node.ii
# Step 2: Parse .ii file and save dependency tree
python3 ./.claude/skills/compile-analysis/scripts/parse_ii.py \
out/rk3568/obj/.../frame_node.ii \
--output out/rk3568/frame_node_dependency_tree.txt
# Output:
# 头文件的依赖关系树:
# └── foundation/arkui/ace_engine/frameworks/core/components_ng/base/frame_node.h
# ├── foundation/arkui/ace_engine/frameworks/core/components_ng/base/ui_node.h
# │ ├── foundation/arkui/ace_engine/frameworks/core/pipeline/base/element.h
# │ └── foundation/arkui/ace_engine/base/memory/ace_type.h
# └── foundation/arkui/ace_engine/frameworks/core/components_ng/property/property.h
#
# ✓ 依赖树已保存到: out/rk3568/frame_node_dependency_tree.txt
If .ii file doesn't exist:
# User request: "这个文件依赖了多少头文件 text_theme.cpp"
# Claude's response:
# Step 1: Check for existing .ii file
# ✗ .ii file not found
# Step 2: Check for compilation script
# ✓ Found: out/rk3568/compile_single_file_text_theme.sh
# Step 3: Generate .ii file by running compilation script
cd out/rk3568
bash compile_single_file_text_theme.sh
# Step 4: Parse .ii file and save dependency tree
python3 ../../.claude/skills/compile-analysis/scripts/parse_ii.py \
obj/.../text_theme.ii \
--output text_theme_dependency_tree.txt
# Output:
# 头文件的依赖关系树:
# └── foundation/arkui/ace_engine/frameworks/core/components/text/text_theme.h
# ├── ...
#
# ✓ 依赖树已保存到: out/rk3568/text_theme_dependency_tree.txt
#
# 统计信息:
# - 总计依赖: 47 个头文件
# - 最大深度: 6 层
If neither .ii nor script exists:
# User request: "头文件依赖关系 button_pattern.cpp"
# Claude's response:
# Step 1: Check for existing .ii file
# ✗ .ii file not found
# Step 2: Check for compilation script
# ✗ Compilation script not found
# Step 3: Generate compilation script first
python3 ./.claude/skills/compile-analysis/scripts/get_compile_command.py \
frameworks/core/components_ng/pattern/button_pattern.cpp \
<openharmony_root>/out/rk3568 --save-enhanced
# ✓ Script generated: out/rk3568/compile_single_file_button_pattern.sh
# Step 4: Generate .ii file by running script
cd out/rk3568
bash compile_single_file_button_pattern.sh
# Step 5: Parse .ii file and save dependency tree
python3 ../../.claude/skills/compile-analysis/scripts/parse_ii.py \
obj/.../button_pattern.ii \
--output button_pattern_dependency_tree.txt
# ✓ 依赖树已保存到: out/rk3568/button_pattern_dependency_tree.txt
Trigger phrases:
Output file naming:
{file_name}_dependency_tree.txtout/{product}/out/rk3568/frame_node_dependency_tree.txtConstraints:
.ii files using parse_ii.py.ii if neededout/{product}/{file_name}_dependency_tree.txtWhen you need to compile a single file in isolation (for testing, debugging, or verification):
Important: This workflow ONLY uses pre-generated compilation scripts. No other compilation methods are used.
Workflow:
out/{product}/compile_single_file_{name}.shExample using Claude:
# User request: "单独编译 frame_node.cpp"
# Claude's response:
# Step 1: Check for existing script
# ✓ Found: out/rk3568/compile_single_file_frame_node.sh
# Step 2: Execute the script
cd out/rk3568
bash compile_single_file_frame_node.sh
# Output:
# 编译时间: 0:08.23
# 峰值内存: 234567 KB
# ✓ 已生成: obj/.../frame_node.ii obj/.../frame_node.o
If script doesn't exist:
# User request: "单编 text_theme.cpp"
# Claude's response:
# Step 1: Check for existing script
# ✗ Script not found: out/rk3568/compile_single_file_text_theme.sh
# Step 2: Generate script first
python3 ./.claude/skills/compile-analysis/scripts/get_compile_command.py \
frameworks/core/components/text/text_theme.cpp <openharmony_root>/out/rk3568 --save-enhanced
# ✓ Script generated: out/rk3568/compile_single_file_text_theme.sh
# Step 3: Execute the script
cd out/rk3568
bash compile_single_file_text_theme.sh
Trigger phrases:
Constraints:
compile_single_file_{name}.sh scriptsWhen you need to extract or save compilation commands for later use:
Save standalone script with performance monitoring:
./.claude/skills/compile-analysis/scripts/analyze_compile.sh \
frameworks/core/components_ng/base/frame_node.cpp rk3568 --save-script
# Script saved to: out/rk3568/compile_single_file_frame_node.sh
# Execute later: cd out/rk3568 && bash compile_single_file_frame_node.sh
Extract command only without execution:
python3 ./.claude/skills/compile-analysis/scripts/get_compile_command.py \
frameworks/core/components_ng/base/frame_node.cpp \
<openharmony_root>/out/rk3568 --save-enhanced
This is useful for:
When incremental builds are slower than expected:
./analyze_compile.sh <slow-file>To reduce unnecessary recompilation:
Measure optimization impact using saved scripts:
Generate baseline script:
./analyze_compile.sh <file> rk3568 --save-script
cd out/rk3568
Run baseline measurement:
bash compile_single_file_{name}.sh
# Record: 编译时间: 0:15.23, 峰值内存: 456789 KB
Apply optimizations (reduce includes, forward declarations, etc.)
Run comparison measurement:
bash compile_single_file_{name}.sh
# Record: 编译时间: 0:08.45, 峰值内存: 234567 KB
Compare results to quantify improvements
The saved script ensures identical compilation conditions for fair comparison.
Cause: Source file path doesn't match build database Solutions:
Cause: Compilation with -save-temps failed or file not created
Solutions:
-save-temps=obj flagfind out/<product>/obj -name "*.ii"Cause: parse_ii.py filters for foundation/arkui/ prefix only
Solutions:
target_prefix in parse_ii.py to include other pathsFor detailed workflows and advanced usage:
references/workflow.md - Comprehensive workflow guidereferences/optimization.md - Optimization strategies and patternsWorking examples in examples/:
examples/example-analysis.sh - Complete analysis exampleexamples/example-output.txt - Sample output with interpretationThis skill integrates with the OpenHarmony GN/Ninja build system:
out/<product>/ directorytoolchain.ninja for compiler rulesThe enhanced compilation command modifies the original command by:
-save-temps=obj (to generate .ii files)/usr/bin/time (to measure resources)-Wno-undefined-bool-conversion)This ensures accurate measurements while maintaining compilation compatibility.
development
Run local code quality checks covering a subset of OpenHarmony gate CI (copyright, CodeArts C/C++) plus additional local checks (pylint/flake8, shellcheck/bashate, gn format). Use before committing to reduce gate failures. Triggers on: /oh-precommit-codecheck, "门禁检查", "门禁预检", "检查代码", "run codecheck", "check code quality", "lint my code", "代码检查", or after completing code implementation. WHEN to use: before git commit, before creating PR, after modifying C/C++/Python/Shell/GN files, when gate CI fails with codecheck defects, or when you want to preview what gate will flag.
development
OpenHarmony PR full lifecycle workflow. Five modes: - Commit: standardized commit with DCO sign-off and Issue linking - Create PR: commit + push to fork + create Issue + create PR on upstream - Fix Codecheck: fetch gate CI codecheck defects from a PR and auto-fix them - Review PR: fetch a PR's changes to local for code review - Fix Review: fetch unresolved review comments from a PR and auto-fix them Triggers on: /oh-pr-workflow, "提交代码", "创建PR", "提个PR", "commit", "修复告警", "修复门禁", "修复codecheck", "fix codecheck", "review pr", "review这个pr", "看下这个pr", "检视pr", "修复review", "修复检视意见", "fix review", or a GitCode PR URL with fix/review intent.
testing
分析 HM Desktop PRD 文档,提取需求信息、验证完整性、检查章节顺序(需求来源→需求背景→需求价值分析→竞品分析→需求描述)、检查 KEP 定义、检测需求冲突并生成结构化分析报告。适用于用户请求:(1) 分析或审查 PRD 文档, (2) 从需求中提取 KEP 列表, (3) 检查 PRD 完整性或一致性, (4) 将需求映射到模块架构, (5) 验证 PRD 格式合规性, (6) 验证竞品分析章节完整性。关键词:PRD分析, requirement extraction, KEP验证, completeness check, chapter order validation, 竞品分析检查, analyze PRD, 需求提取, 完整性检查, 章节顺序验证
development
基于 PRD 文档自动生成鸿蒙系统设计文档,包括架构设计文档和功能设计文档。生成前会分析 OpenHarmony 存量代码结构,确保与现有架构兼容。架构设计文档第2章必须为竞品方案分析,位于需求背景之后。适用于用户请求:(1) 生成架构设计文档, (2) 生成功能设计文档, (3) 从 PRD 生成设计文档, (4) 创建系统架构设计, (5) 编写功能规格说明, (6) 分析 OH 代码结构。关键词:architecture design, functional design, design doc, 竞品方案分析, OpenHarmony code analysis, 架构设计, 功能设计, 设计文档生成, OH代码分析, analyze codebase, competitor analysis