Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ignore_directories() in REPO.bazel does not yet reliably prevent Bazel from traversing symlinks:
# https://github.com/bazelbuild/bazel/pull/24203#issuecomment-3499025997
# Keep the symlink-prone entries here as well until that is resolved.
.cache/
target/
# bazel convenience symlinks suddenly caused issues
# inside of arm64 Linux containers.
bazel-datadog-agent/
bazel-testlogs/
bazel-testlogs/
6 changes: 3 additions & 3 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
/.vscode/ @DataDog/agent-devx

# Bazel configuration
/*.bazel* @DataDog/agent-build
/.adms/ @DataDog/agent-build
/.bazel* @DataDog/agent-build
/.buildifier.json @DataDog/agent-build
/bazel/ @DataDog/agent-build
/bazel/configs/rust.bazelrc @DataDog/agent-discovery @DataDog/agent-runtimes @DataDog/agent-build
/MODULE.bazel* @DataDog/agent-build
/bazel/configs/rust.bazelrc @DataDog/agent-discovery @DataDog/agent-runtimes @DataDog/agent-build
/deps/ @DataDog/agent-build
/.buildifier.json @DataDog/agent-build

# The owner should really be to a team that does not exist yet. It would cover supply chain in general.
# For now, agent-build are the experts in that.
Expand Down
6 changes: 6 additions & 0 deletions REPO.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ignore_directories([
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh cool, I didn't know about this feature

"**/build", # avoid BUILD/build mess: https://github.com/docker/desktop-feedback/issues/251
".cache", # in-workspace cache: GitLab jobs, GitHub actions
"bazel-*", # bazel convenience symlinks: suddenly caused issues inside arm64 Linux containers
"target", # cargo build creates it where Cargo.toml lives
])
10 changes: 6 additions & 4 deletions tools/bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if [ ! -d "${XDG_CACHE_HOME:-}" ]; then
fi

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

# "--startup cmd ..." -> "--startup cmd --config=ci ..."
if [[ $# -gt 0 && -n "${CI:-}" ]]; then
if [[ $# -gt 0 && ${#extra_args[@]} -gt 0 ]]; then
args=()
cmd=
for arg in "$@"; do
args+=("$arg")
if [[ -z "$cmd" && "$arg" != -* ]]; then
cmd=$arg
[ -z "${GITHUB_ACTIONS:-}" ] && args+=(--config=ci)
# https://github.com/bazelbuild/bazel/issues/26384
[ "${XDG_CACHE_HOME:-}" = "$(dirname "$(dirname "$0")")/.cache" ] && args+=(--repo_contents_cache=)
args+=("${extra_args[@]}")
fi
done
set -- "${args[@]}"
Expand Down
24 changes: 10 additions & 14 deletions tools/bazel.bat
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ if not exist "%XDG_CACHE_HOME%" (
)

:: Ensure `bazel` & managed toolchains honor `XDG_CACHE_HOME` as per https://wiki.archlinux.org/title/XDG_Base_Directory
set "extra_args="
if defined XDG_CACHE_HOME (
set "XDG_CACHE_HOME=!XDG_CACHE_HOME:/=\!"
if "!XDG_CACHE_HOME:~1,2!" neq ":\" if "!XDG_CACHE_HOME:~0,2!" neq "\\" (
Expand All @@ -37,12 +38,15 @@ if defined XDG_CACHE_HOME (
:: https://github.com/bazelbuild/bazel/issues/27808
set "bazel_home=%XDG_CACHE_HOME%\bazel"
set bazel_home_startup_option="--output_user_root=!bazel_home!"
) else (
for %%i in ("%~dp0..\.cache") do set "XDG_CACHE_HOME=%%~fi"
if defined CI if not defined GITHUB_ACTIONS set "extra_args=--config=ci"
:: https://github.com/bazelbuild/bazel/issues/26384
for %%i in ("%~dp0..\.cache") do if "!XDG_CACHE_HOME!" == "%%~fi" (
if defined extra_args (set "extra_args=!extra_args! --repo_contents_cache=") else set "extra_args=--repo_contents_cache="
)
)

:: Check legacy max path length of 260 characters got lifted, or fail with instructions
set "more_than_260_chars=!XDG_CACHE_HOME!\more-than-260-chars"
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"
for /l %%i in (1,1,26) do set "more_than_260_chars=!more_than_260_chars!\123456789"
if not exist "!more_than_260_chars!" (
2>nul mkdir "!more_than_260_chars!"
Expand All @@ -55,20 +59,12 @@ if not exist "!more_than_260_chars!" (
)

set "args=%*"
if defined args if defined CI (
set "ci_args="
if not defined GITHUB_ACTIONS set "ci_args=--config=ci"
:: https://github.com/bazelbuild/bazel/issues/26384
for %%i in ("%~dp0..\.cache") do if "!XDG_CACHE_HOME!" == "%%~fi" (
if defined ci_args (set "ci_args=!ci_args! --repo_contents_cache=") else set "ci_args=--repo_contents_cache="
)
if defined ci_args call :inject_ci_args
)
if defined args if defined extra_args call :insert_extra_args
"%BAZEL_REAL%" !bazel_home_startup_option! !args!
exit /b !errorlevel!

:: "--startup cmd ..." -> "--startup cmd --config=ci ..."
:inject_ci_args
:insert_extra_args
set "startup_args="
set "next_args=!args!"
:parse_next_arg
Expand All @@ -81,7 +77,7 @@ for /f "tokens=1* delims= " %%i in ("!next_args!") do (
) else (
if defined startup_args set "startup_args=!startup_args:~1! "
set "cmd=%%i"
set "args=!startup_args!!cmd! !ci_args! %%j"
set "args=!startup_args!!cmd! !extra_args! %%j"
)
)
if not defined cmd if defined next_args goto :parse_next_arg
Expand Down
Loading