From 8c52358ad7812634c04e12a6a136c1cd275cc68c Mon Sep 17 00:00:00 2001 From: Jingwen Chen Date: Tue, 1 Jun 2021 11:19:53 +0000 Subject: [PATCH] Fix OUT_DIR lookup in mixed builds. In mixed builds, Bazel operates in /out/soong/workspace, but the real OUT_DIR is just out/, not /out/soong/workspace/out. This CL ensures that the correct OUT_DIR is passed to mixed builds's bazel by making OUT_DIR absolute. Also add STANDALONE_BAZEL to build_test's Bazel smoke test. Test: TH Change-Id: If8b4058d43bf821f5196016f9b0ad38edfe18716 --- android/bazel_handler.go | 8 ++++++++ build_test.bash | 2 +- tests/mixed_mode_test.sh | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/android/bazel_handler.go b/android/bazel_handler.go index a1206dc53..f906c8add 100644 --- a/android/bazel_handler.go +++ b/android/bazel_handler.go @@ -351,6 +351,9 @@ func (r *builtinBazelRunner) issueBazelCommand(paths *bazelPaths, runName bazel. "HOME="+paths.homeDir, pwdPrefix(), "BUILD_DIR="+absolutePath(paths.buildDir), + // Make OUT_DIR absolute here so tools/bazel.sh uses the correct + // OUT_DIR at /out, instead of /out/soong/workspace/out. + "OUT_DIR="+absolutePath(paths.outDir()), // Disables local host detection of gcc; toolchain information is defined // explicitly in BUILD files. "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1") @@ -576,6 +579,11 @@ func (p *bazelPaths) syntheticWorkspaceDir() string { return filepath.Join(p.buildDir, "workspace") } +// Returns the path to the top level out dir ($OUT_DIR). +func (p *bazelPaths) outDir() string { + return filepath.Dir(p.buildDir) +} + // Issues commands to Bazel to receive results for all cquery requests // queued in the BazelContext. func (context *bazelContext) InvokeBazel() error { diff --git a/build_test.bash b/build_test.bash index 296a79cd0..b039285ca 100755 --- a/build_test.bash +++ b/build_test.bash @@ -54,7 +54,7 @@ df -h echo echo "Running Bazel smoke test..." -"${TOP}/tools/bazel" --batch --max_idle_secs=1 info +STANDALONE_BAZEL=true "${TOP}/tools/bazel" --batch --max_idle_secs=1 info echo echo "Running Soong test..." diff --git a/tests/mixed_mode_test.sh b/tests/mixed_mode_test.sh index 80774bf0f..b408fd325 100755 --- a/tests/mixed_mode_test.sh +++ b/tests/mixed_mode_test.sh @@ -14,7 +14,7 @@ function test_bazel_smoke { setup create_mock_bazel - run_bazel info + STANDALONE_BAZEL=true run_bazel info } test_bazel_smoke