Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Map BUILD to Python (Starlark) for Bazel (fixes #3575)#3576

Open
vorburger wants to merge 2 commits intosharkdp:masterfrom
vorburger:patch-2
Open

feat: Map BUILD to Python (Starlark) for Bazel (fixes #3575)#3576
vorburger wants to merge 2 commits intosharkdp:masterfrom
vorburger:patch-2

Conversation

@vorburger
Copy link
Contributor

@keith-hall like this, for #3575 ?

Full disclosure: I have NOT actually tested this... as in, for #3575 I HAVE tested bat --map-syntax='BUILD:Python' BUILD locally on a pre-built binary, and looking around https://github.com/sharkdp/bat/tree/master/src/syntax_mapping/builtins/common I kinda gathered that's what you meant with your comment in #3575 - but I haven't actually rebuilt bat with this... but it looks about right (I hope).

Copilot AI review requested due to automatic review settings February 1, 2026 12:36
@vorburger
Copy link
Contributor Author

Re. 2 failing checks, let me add a line to CHANGELOG.md (coming up).

But that "[Minimum supported rust version" failure must be unrelated to this PR.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds a syntax mapping for Bazel BUILD files to be highlighted as Python (Starlark), addressing issue #3575. The change adds a new configuration file that maps the filename "BUILD" to Python syntax highlighting.

Changes:

  • Added 50-bazel.toml configuration file to map BUILD files to Python syntax

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

@@ -0,0 +1,2 @@
[mappings]
"Python" = ["BUILD"]
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

This change will break the existing test 'syntax_detection_first_line' in src/assets.rs:540-541. The test expects files named "build" (lowercase) with a bash shebang to use first-line fallback detection and be identified as "Bourne Again Shell (bash)". However, with this mapping, "build" will match the case-insensitive "BUILD" pattern and be mapped to Python, preventing first-line fallback and causing the test to fail.

Suggested change
"Python" = ["BUILD"]
# Intentionally no mapping for bare "BUILD" to avoid conflicting with
# first-line fallback detection for lowercase "build" files.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,2 @@
[mappings]
"Python" = ["BUILD"]
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

No test coverage has been added for the new BUILD file mapping. Consider adding a test case to src/assets.rs in the syntax_detection_basic test function, similar to the existing tests for other filename mappings like PKGBUILD and Makefile. For example: assert_eq!(test.syntax_for_file("BUILD"), "Python");

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,2 @@
[mappings]
"Python" = ["BUILD"]
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

The pattern "BUILD" will match files named "build" (lowercase) due to case-insensitive glob matching (see src/syntax_mapping.rs:22). This overrides the existing mapping in 99-unset-ambiguous-filenames.toml that intentionally maps "build" to MapToUnknown to prevent incorrect syntax detection for NAnt Build Files. This breaks existing behavior.

Since Bazel BUILD files are typically uppercase, consider either:

  1. Finding a way to make this mapping case-sensitive (would require code changes to the make_glob_matcher function)
  2. Documenting this as a known limitation and accepting that lowercase "build" files will now be treated as Python
  3. Not adding this mapping and relying on users to configure it manually via --map-syntax if needed

The issue noted in 99-unset-ambiguous-filenames.toml is that "NAnt Build File" should only match *.build files (with extension), not files named "build" (no extension). This PR's case-insensitive "BUILD" pattern will cause lowercase "build" files to be mapped to Python instead of remaining as MapToUnknown.

Suggested change
"Python" = ["BUILD"]

Copilot uses AI. Check for mistakes.
@vorburger
Copy link
Contributor Author

@keith-hall hm, is Copilot right about the case sensitivity? Given the test failures, I guess this would need more work.

My time is limited and my Rust is too rusty to implement that... BTW see #3577.

Also, would you want to see a test, to accept merging this?

@keith-hall
Copy link
Collaborator

Yep, looks like Copilot is correct about the case-insensitivity, which is indeed why the tests are failing. Hmm, yeah I guess we need to introduce a way to map a filename case sensitively to proceed further. As for tests, a simple test case like Copilot suggested at #3576 (comment) would suffice, if all the existing tests continue to pass unmodified.

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.

3 participants