Skip to content

Commit e02c86f

Browse files
committed
Make Bazel skip build directories
### What does this PR do? Add `**/build` to `REPO.bazel`'s `ignore_directories()`, replacing `.bazelignore`, and adjust `CODEOWNERS` accordingly. ### Motivation When `bazel` runs inside a Linux container on macOS via Docker Desktop, the workspace is typically mounted on a case-insensitive filesystem where `BUILD` and `build` are indistinguishable (docker/desktop-feedback#251). #48455 addressed this for `gazelle` by restricting it to `BUILD.bazel` files only. Bazel's own directory traversal, however, remained exposed to the same confusion. `REPO.bazel` gained `ignore_directories()` in Bazel **8.0*** (bazelbuild/bazel#24203), introduced as a complement to `.bazelignore` > to provide a migration path off of that weird single-purpose configuration file. It supports Bazel's native `glob()` semantics, making `**/build` a natural fit. ### Additional Notes Coming from Bazel 7, I was not aware of `REPO.bazel`, otherwise I would have added it in the first place instead of `.bazelignore` (#40153). In `CODEOWNERS`, `/MODULE.bazel*` is replaced by `/*.bazel*` to cover `REPO.bazel` as well as any future root-level `.bazel` files.
1 parent 5949a8c commit e02c86f

5 files changed

Lines changed: 29 additions & 23 deletions

File tree

.bazelignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# ignore_directories() in REPO.bazel does not yet reliably prevent Bazel from traversing symlinks:
2+
# https://github.com/bazelbuild/bazel/pull/24203#issuecomment-3499025997
3+
# Keep the symlink-prone entries here as well until that is resolved.
14
.cache/
2-
target/
35
# bazel convenience symlinks suddenly caused issues
46
# inside of arm64 Linux containers.
57
bazel-datadog-agent/
6-
bazel-testlogs/
8+
bazel-testlogs/

.github/CODEOWNERS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
/.vscode/ @DataDog/agent-devx
2424

2525
# Bazel configuration
26+
/*.bazel* @DataDog/agent-build
2627
/.adms/ @DataDog/agent-build
2728
/.bazel* @DataDog/agent-build
29+
/.buildifier.json @DataDog/agent-build
2830
/bazel/ @DataDog/agent-build
29-
/bazel/configs/rust.bazelrc @DataDog/agent-discovery @DataDog/agent-runtimes @DataDog/agent-build
30-
/MODULE.bazel* @DataDog/agent-build
31+
/bazel/configs/rust.bazelrc @DataDog/agent-discovery @DataDog/agent-runtimes @DataDog/agent-build
3132
/deps/ @DataDog/agent-build
32-
/.buildifier.json @DataDog/agent-build
3333

3434
# The owner should really be to a team that does not exist yet. It would cover supply chain in general.
3535
# For now, agent-build are the experts in that.

REPO.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ignore_directories([
2+
"**/build", # avoid BUILD/build mess: https://github.com/docker/desktop-feedback/issues/251
3+
".cache", # in-workspace cache: GitLab jobs, GitHub actions
4+
"bazel-*", # bazel convenience symlinks: suddenly caused issues inside arm64 Linux containers
5+
"target", # cargo build creates it where Cargo.toml lives
6+
])

tools/bazel

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ if [ ! -d "${XDG_CACHE_HOME:-}" ]; then
2121
fi
2222

2323
# Ensure `bazel` & managed toolchains honor `XDG_CACHE_HOME` as per https://wiki.archlinux.org/title/XDG_Base_Directory
24+
extra_args=()
2425
if [ -n "${XDG_CACHE_HOME:-}" ]; then
2526
if [[ "$XDG_CACHE_HOME" != /* ]]; then
2627
>&2 echo "🔴 XDG_CACHE_HOME ($XDG_CACHE_HOME) must denote an absolute path!"
@@ -29,19 +30,20 @@ if [ -n "${XDG_CACHE_HOME:-}" ]; then
2930
unset GOCACHE # https://pkg.go.dev/cmd/go#hdr-Build_and_test_caching
3031
export GOMODCACHE="$XDG_CACHE_HOME"/go/mod # https://wiki.archlinux.org/title/XDG_Base_Directory#Partial
3132
unset PIP_CACHE_DIR # https://pip.pypa.io/en/stable/topics/caching/#default-paths
33+
[ -n "${CI:-}" ] && [ -z "${GITHUB_ACTIONS:-}" ] && extra_args+=(--config=ci)
34+
# https://github.com/bazelbuild/bazel/issues/26384
35+
[ "$XDG_CACHE_HOME" = "$(dirname "$(dirname "$0")")/.cache" ] && extra_args+=(--repo_contents_cache=)
3236
fi
3337

3438
# "--startup cmd ..." -> "--startup cmd --config=ci ..."
35-
if [[ $# -gt 0 && -n "${CI:-}" ]]; then
39+
if [[ $# -gt 0 && ${#extra_args[@]} -gt 0 ]]; then
3640
args=()
3741
cmd=
3842
for arg in "$@"; do
3943
args+=("$arg")
4044
if [[ -z "$cmd" && "$arg" != -* ]]; then
4145
cmd=$arg
42-
[ -z "${GITHUB_ACTIONS:-}" ] && args+=(--config=ci)
43-
# https://github.com/bazelbuild/bazel/issues/26384
44-
[ "${XDG_CACHE_HOME:-}" = "$(dirname "$(dirname "$0")")/.cache" ] && args+=(--repo_contents_cache=)
46+
args+=("${extra_args[@]}")
4547
fi
4648
done
4749
set -- "${args[@]}"

tools/bazel.bat

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if not exist "%XDG_CACHE_HOME%" (
2222
)
2323

2424
:: Ensure `bazel` & managed toolchains honor `XDG_CACHE_HOME` as per https://wiki.archlinux.org/title/XDG_Base_Directory
25+
set "extra_args="
2526
if defined XDG_CACHE_HOME (
2627
set "XDG_CACHE_HOME=!XDG_CACHE_HOME:/=\!"
2728
if "!XDG_CACHE_HOME:~1,2!" neq ":\" if "!XDG_CACHE_HOME:~0,2!" neq "\\" (
@@ -37,12 +38,15 @@ if defined XDG_CACHE_HOME (
3738
:: https://github.com/bazelbuild/bazel/issues/27808
3839
set "bazel_home=%XDG_CACHE_HOME%\bazel"
3940
set bazel_home_startup_option="--output_user_root=!bazel_home!"
40-
) else (
41-
for %%i in ("%~dp0..\.cache") do set "XDG_CACHE_HOME=%%~fi"
41+
if defined CI if not defined GITHUB_ACTIONS set "extra_args=--config=ci"
42+
:: https://github.com/bazelbuild/bazel/issues/26384
43+
for %%i in ("%~dp0..\.cache") do if "!XDG_CACHE_HOME!" == "%%~fi" (
44+
if defined extra_args (set "extra_args=!extra_args! --repo_contents_cache=") else set "extra_args=--repo_contents_cache="
45+
)
4246
)
4347

4448
:: Check legacy max path length of 260 characters got lifted, or fail with instructions
45-
set "more_than_260_chars=!XDG_CACHE_HOME!\more-than-260-chars"
49+
for %%i in ("%~dp0..\.cache") do if defined XDG_CACHE_HOME (set "more_than_260_chars=!XDG_CACHE_HOME!") else set "more_than_260_chars=%%~fi"
4650
for /l %%i in (1,1,26) do set "more_than_260_chars=!more_than_260_chars!\123456789"
4751
if not exist "!more_than_260_chars!" (
4852
2>nul mkdir "!more_than_260_chars!"
@@ -55,20 +59,12 @@ if not exist "!more_than_260_chars!" (
5559
)
5660

5761
set "args=%*"
58-
if defined args if defined CI (
59-
set "ci_args="
60-
if not defined GITHUB_ACTIONS set "ci_args=--config=ci"
61-
:: https://github.com/bazelbuild/bazel/issues/26384
62-
for %%i in ("%~dp0..\.cache") do if "!XDG_CACHE_HOME!" == "%%~fi" (
63-
if defined ci_args (set "ci_args=!ci_args! --repo_contents_cache=") else set "ci_args=--repo_contents_cache="
64-
)
65-
if defined ci_args call :inject_ci_args
66-
)
62+
if defined args if defined extra_args call :insert_extra_args
6763
"%BAZEL_REAL%" !bazel_home_startup_option! !args!
6864
exit /b !errorlevel!
6965

7066
:: "--startup cmd ..." -> "--startup cmd --config=ci ..."
71-
:inject_ci_args
67+
:insert_extra_args
7268
set "startup_args="
7369
set "next_args=!args!"
7470
:parse_next_arg
@@ -81,7 +77,7 @@ for /f "tokens=1* delims= " %%i in ("!next_args!") do (
8177
) else (
8278
if defined startup_args set "startup_args=!startup_args:~1! "
8379
set "cmd=%%i"
84-
set "args=!startup_args!!cmd! !ci_args! %%j"
80+
set "args=!startup_args!!cmd! !extra_args! %%j"
8581
)
8682
)
8783
if not defined cmd if defined next_args goto :parse_next_arg

0 commit comments

Comments
 (0)