Skip to content

[Nexthop] Extend buck_cmake_dep_checker to catch file-list inconsistencies.#1300

Open
benoit-nexthop wants to merge 1 commit into
facebook:mainfrom
nexthop-ai:cmake-buck-file-checker
Open

[Nexthop] Extend buck_cmake_dep_checker to catch file-list inconsistencies.#1300
benoit-nexthop wants to merge 1 commit into
facebook:mainfrom
nexthop-ai:cmake-buck-file-checker

Conversation

@benoit-nexthop

@benoit-nexthop benoit-nexthop commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends fboss/oss/scripts/buck_cmake_dep_checker.py with two new check modes and several bug fixes.

New flags

  --check-files               cmake → BUCK direction; files in cmake must
                              also appear in some BUCK target
  --check-files --from-commit REF [--to-commit REF]
                              Bidirectional check for files changed in the
                              given commit range; any touched .cpp must be
                              in both build systems
  --check-sorted              Check that srcs/headers file lists in BUCK and
                              cmake targets are sorted alphabetically
  --check-sorted --from-commit REF
                              Limit the sort check to targets defined in
                              build files (BUCK/*.cmake) touched by the
                              commit range — avoids flooding output with
                              pre-existing violations in unrelated targets

--check-files and --check-sorted can be combined; they share one parse pass:

  buck_cmake_dep_checker.py --check-files --check-sorted --from-commit HEAD~

The pre-commit hook in .pre-commit-config.yaml is updated to use this combined invocation.

Design choices (file-list check)

  • Same-name 1:1 target pairing with >0 shared .cpp as confidence gate (excludes macro/glob-generated Buck targets invisible to the parser)
  • Name normalization: cmake uses underscores (fboss2_config_lib) while BUCK uses hyphens (fboss2-config-lib); both sides are normalized before matching so the confidence gate works correctly
  • Buck headers lists are included in the global corpus (some .cpp files live under headers in BUCK, not srcs); previously these appeared as false-positive "missing from BUCK" entries
  • Files under oss/ or facebook/ path segments silently skipped (OSS shims)
  • Only paths starting with fboss/ considered

Also fixes a pre-existing parser bug

  • cpp_library/thrift_library blocks with comments between ( and name = were silently skipped; fixed by extracting the block first then searching for name= inside it (21 additional targets now parsed)

Test Plan

Tested against #1140 (config/delete tunnel ip-in-ip). With --from-commit, output is scoped to the 6 build files touched by that commit:

$ buck_cmake_dep_checker.py --check-files --check-sorted --from-commit 8caf0fc^

FILE LIST INCONSISTENCIES (changed files 8caf0fc^..HEAD)
================================================================================
No file list inconsistencies found!

FILE LIST SORT ORDER VIOLATIONS
================================================================================

fboss/cli/fboss2/test/config/BUCK:
  [buck] //fboss/cli/fboss2/test/config:cmd_config_test  (srcs)
    First unsorted entry at position 17: 'CmdConfigVlanDefaultTest.cpp'
    (expected 'CmdConfigTunnelIpInIpTest.cpp')

The CmdConfigTunnelIpInIpTest.cpp (T) was appended after CmdConfigVlanDefaultTest.cpp (V); alphabetically T < V so the test file should appear first.

Also validated against #1095 where --check-files --from-commit correctly flagged two integration test files added to BUCK but missing from cmake:

================================================================================
FILE LIST INCONSISTENCIES (changed files HEAD~1..HEAD)
================================================================================

In BUCK but missing from cmake:
  fboss/cli/fboss2/test/integration_test/ConfigInterfaceIpv6NdpTest.cpp
    Buck target: //fboss/cli/fboss2/test/integration_test:fboss2_integration_test
    Buck file:   /var/FBOSS/fboss/fboss/cli/fboss2/test/integration_test/BUCK
  fboss/cli/fboss2/test/integration_test/DeleteInterfaceIpv6NdpTest.cpp
    Buck target: //fboss/cli/fboss2/test/integration_test:fboss2_integration_test
    Buck file:   /var/FBOSS/fboss/fboss/cli/fboss2/test/integration_test/BUCK

@benoit-nexthop benoit-nexthop requested a review from a team as a code owner June 16, 2026 00:11
@meta-cla meta-cla Bot added the CLA Signed label Jun 16, 2026
@benoit-nexthop benoit-nexthop force-pushed the cmake-buck-file-checker branch from 1f12ea3 to 2a98433 Compare June 24, 2026 14:10
Adds --check-files mode to detect .cpp files present in cmake targets but
missing from BUCK (and vice versa for pre-commit mode), catching the class
of mistake where a file is added to one build system but not the other.

New flags:
  --check-files               cmake → BUCK direction; files in cmake must
                              also appear in some BUCK target
  --check-files --from-commit REF [--to-commit REF]
                              Bidirectional check for files changed in the
                              given commit range; any touched .cpp must be
                              in both build systems

Design choices to keep false-positive rate at zero:
- Same-name 1:1 target pairing with >0 shared .cpp as confidence gate
  (excludes macro/glob-generated Buck targets invisible to the parser)
- Files under oss/ or facebook/ path segments silently skipped (OSS shims)
- Only paths starting with fboss/ considered (excludes bgp++ sibling clone)
- Global corpus check: a file is only flagged if absent from the *entire*
  other build system, not just the paired target

Also fixes two pre-existing parser bugs:
- cpp_library/thrift_library blocks with comments between '(' and 'name ='
  were silently skipped; fixed by extracting the block first then searching
  for name= inside it (21 additional targets now parsed)
- bgp++ directory was polluting the Buck corpus with duplicate paths

Adds a commented-out pre-commit hook in .pre-commit-config.yaml for when
the existing violations are resolved.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@benoit-nexthop benoit-nexthop force-pushed the cmake-buck-file-checker branch from 2a98433 to c977254 Compare July 1, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant