GN Check Autofix
This skill provides instructions for using tools_webrtc/gn_check_autofix.py to
automatically resolve common GN build configuration errors in WebRTC.
Core Workflows
Fix Missing Dependencies
When you see "Include not allowed" errors from gn gen --check, use this
workflow:
- Run the autofix tool on your output directory:
tools_webrtc/gn_check_autofix.py -C <dir> - The tool will:
- Identify targets missing dependencies.
- Add the missing
depsto the appropriateBUILD.gnfiles. - Automatically run
gn formaton modified files.
Fix rtc_source_set Violations
If you see "rtc_source_set shall not contain cc files", the tool will
automatically convert them to rtc_library:
- Run the tool:
tools_webrtc/gn_check_autofix.py -C <dir>
Clean Up Dependencies
To remove all non-absolute dependencies (those not starting with //) from
specific BUILD.gn files:
tools_webrtc/gn_check_autofix.py -r path/to/BUILD.gn
Note: This preserves absolute dependencies (starting with //) and targets
ending in _test, _tests, _unittest, or _unittests.
Integration with Include Cleaner
This tool is the recommended second step after running webrtc-include-cleaner.
While the include cleaner updates your C++ source files, gn-check-autofix
synchronizes your BUILD.gn files to match.
Parameters
-C <dir>: Path to a local build directory (e.g.,out/Default). The tool internally runsgn gen --check --error-limit=20000.-r <files>: Remove all non-absolute dependencies from the specified files.--error-limit: Can be used to override the default error cap.
Post-Fix Steps
After the tool runs, always verify the changes:
- Deduplicate: The tool may occasionally add a dependency that is already
present. Check the
depslist for duplicates. - Regenerate GN: Run
gn gen <dir>to confirm errors are resolved. - Format: The tool runs
gn format, but a finalgit cl formatis recommended for consistency. - Review: Check the diff to ensure dependencies were added to the correct targets.
Source: signalapp/webrtc — distributed by TomeVault.