Merge pull request #74976 from guibou/bazel_config_file_system
bazel: take into account system wide bazelrc configuration if it exists
This commit is contained in:
commit
5233338ad9
2 changed files with 33 additions and 15 deletions
13
pkgs/development/tools/build-managers/bazel/bazel_rc.patch
Normal file
13
pkgs/development/tools/build-managers/bazel/bazel_rc.patch
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc
|
||||||
|
index 8f8f15685f..a7ae52d1e4 100644
|
||||||
|
--- a/src/main/cpp/option_processor.cc
|
||||||
|
+++ b/src/main/cpp/option_processor.cc
|
||||||
|
@@ -56,7 +56,7 @@ OptionProcessor::OptionProcessor(
|
||||||
|
: workspace_layout_(workspace_layout),
|
||||||
|
startup_options_(std::move(default_startup_options)),
|
||||||
|
parse_options_called_(false),
|
||||||
|
- system_bazelrc_path_(BAZEL_SYSTEM_BAZELRC_PATH) {}
|
||||||
|
+ system_bazelrc_path_("@bazelSystemBazelRCPath@") {}
|
||||||
|
|
||||||
|
OptionProcessor::OptionProcessor(
|
||||||
|
const WorkspaceLayout* workspace_layout,
|
|
@ -21,6 +21,7 @@
|
||||||
, autoPatchelfHook
|
, autoPatchelfHook
|
||||||
, file
|
, file
|
||||||
, substituteAll
|
, substituteAll
|
||||||
|
, writeTextFile
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
@ -126,6 +127,18 @@ let
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bazelRC = writeTextFile {
|
||||||
|
name = "bazel-rc";
|
||||||
|
text = ''
|
||||||
|
build --override_repository=${remote_java_tools.name}=${remote_java_tools}
|
||||||
|
build --distdir=${distDir}
|
||||||
|
startup --server_javabase=${runJdk}
|
||||||
|
|
||||||
|
# load default location for the system wide configuration
|
||||||
|
try-import /etc/bazel.bazelrc
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
stdenv.mkDerivation rec {
|
stdenv.mkDerivation rec {
|
||||||
pname = "bazel";
|
pname = "bazel";
|
||||||
|
@ -158,6 +171,13 @@ stdenv.mkDerivation rec {
|
||||||
src = ./strict_action_env.patch;
|
src = ./strict_action_env.patch;
|
||||||
strictActionEnvPatch = defaultShellPath;
|
strictActionEnvPatch = defaultShellPath;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# bazel reads its system bazelrc in /etc
|
||||||
|
# override this path to a builtin one
|
||||||
|
(substituteAll {
|
||||||
|
src = ./bazel_rc.patch;
|
||||||
|
bazelSystemBazelRCPath = bazelRC;
|
||||||
|
})
|
||||||
] ++ lib.optional enableNixHacks ./nix-hacks.patch;
|
] ++ lib.optional enableNixHacks ./nix-hacks.patch;
|
||||||
|
|
||||||
|
|
||||||
|
@ -418,12 +438,6 @@ stdenv.mkDerivation rec {
|
||||||
mv runfiles.bash.tmp tools/bash/runfiles/runfiles.bash
|
mv runfiles.bash.tmp tools/bash/runfiles/runfiles.bash
|
||||||
|
|
||||||
patchShebangs .
|
patchShebangs .
|
||||||
|
|
||||||
# bazel reads its system bazelrc in /etc
|
|
||||||
# override this path to a builtin one
|
|
||||||
substituteInPlace \
|
|
||||||
src/main/cpp/option_processor.cc \
|
|
||||||
--replace BAZEL_SYSTEM_BAZELRC_PATH "\"$out/etc/bazelrc\""
|
|
||||||
'';
|
'';
|
||||||
in lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches
|
in lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches
|
||||||
+ genericPatches;
|
+ genericPatches;
|
||||||
|
@ -475,15 +489,6 @@ stdenv.mkDerivation rec {
|
||||||
cp ./bazel_src/scripts/packages/bazel.sh $out/bin/bazel
|
cp ./bazel_src/scripts/packages/bazel.sh $out/bin/bazel
|
||||||
mv ./bazel_src/output/bazel $out/bin/bazel-real
|
mv ./bazel_src/output/bazel $out/bin/bazel-real
|
||||||
|
|
||||||
wrapProgram "$out/bin/bazel" --add-flags --server_javabase="${runJdk}"
|
|
||||||
|
|
||||||
# generates the system bazelrc
|
|
||||||
# warning: the name of the repository depends on the system, hence
|
|
||||||
# the reference to .name
|
|
||||||
mkdir $out/etc
|
|
||||||
echo "build --override_repository=${remote_java_tools.name}=${remote_java_tools}" > $out/etc/bazelrc
|
|
||||||
echo "build --distdir=${distDir}" >> $out/etc/bazelrc
|
|
||||||
|
|
||||||
# shell completion files
|
# shell completion files
|
||||||
mkdir -p $out/share/bash-completion/completions $out/share/zsh/site-functions
|
mkdir -p $out/share/bash-completion/completions $out/share/zsh/site-functions
|
||||||
mv ./bazel_src/output/bazel-complete.bash $out/share/bash-completion/completions/bazel
|
mv ./bazel_src/output/bazel-complete.bash $out/share/bash-completion/completions/bazel
|
||||||
|
|
Loading…
Reference in a new issue