From 413a7a97fb3fb511c62416f672bebf0f7b0a3741 Mon Sep 17 00:00:00 2001 From: Rupert Shuttleworth Date: Tue, 18 May 2021 07:47:15 -0400 Subject: [PATCH] Have bp2build generate BUILD.bazel instead of generating BUILD. Test: TH Change-Id: I465d29da96dd77c432890a38a56203e291b8ceed --- bp2build/constants.go | 5 ++++- bp2build/conversion_test.go | 6 +++--- tests/bootstrap_test.sh | 34 ++++++++++++++++++---------------- tests/bp2build_bazel_test.sh | 22 ++++++++++++---------- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/bp2build/constants.go b/bp2build/constants.go index 70f320e12..4870dffff 100644 --- a/bp2build/constants.go +++ b/bp2build/constants.go @@ -19,7 +19,10 @@ var ( // be preferred for use within a Bazel build. // The file name used for automatically generated files. - GeneratedBuildFileName = "BUILD" + GeneratedBuildFileName = "BUILD.bazel" + // The file name used for hand-crafted build targets. + // NOTE: It is okay that this matches GeneratedBuildFileName, since we generate BUILD files in a different directory to source files + // FIXME: Because there are hundreds of existing BUILD.bazel files in the AOSP tree, we should pick another name here, like BUILD.android HandcraftedBuildFileName = "BUILD.bazel" ) diff --git a/bp2build/conversion_test.go b/bp2build/conversion_test.go index a08c03d05..0931ff7fc 100644 --- a/bp2build/conversion_test.go +++ b/bp2build/conversion_test.go @@ -29,7 +29,7 @@ func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) { expectedFilePaths := []bazelFilepath{ { dir: "", - basename: "BUILD", + basename: "BUILD.bazel", }, { dir: "", @@ -37,7 +37,7 @@ func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) { }, { dir: bazelRulesSubDir, - basename: "BUILD", + basename: "BUILD.bazel", }, { dir: bazelRulesSubDir, @@ -69,7 +69,7 @@ func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) { if actualFile.Dir != expectedFile.dir || actualFile.Basename != expectedFile.basename { t.Errorf("Did not find expected file %s/%s", actualFile.Dir, actualFile.Basename) - } else if actualFile.Basename == "BUILD" || actualFile.Basename == "WORKSPACE" { + } else if actualFile.Basename == "BUILD.bazel" || actualFile.Basename == "WORKSPACE" { if actualFile.Contents != "" { t.Errorf("Expected %s to have no content.", actualFile) } diff --git a/tests/bootstrap_test.sh b/tests/bootstrap_test.sh index 3f51114f9..42363e9c0 100755 --- a/tests/bootstrap_test.sh +++ b/tests/bootstrap_test.sh @@ -7,6 +7,8 @@ set -o pipefail source "$(dirname "$0")/lib.sh" +readonly GENERATED_BUILD_FILE_NAME="BUILD.bazel" + function test_smoke { setup run_soong @@ -505,8 +507,8 @@ filegroup { EOF GENERATE_BAZEL_FILES=1 run_soong - [[ -e out/soong/bp2build/a/BUILD ]] || fail "a/BUILD not created" - [[ -L out/soong/workspace/a/BUILD ]] || fail "a/BUILD not symlinked" + [[ -e out/soong/bp2build/a/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not created" + [[ -L out/soong/workspace/a/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not symlinked" mkdir -p b touch b/b.txt @@ -519,8 +521,8 @@ filegroup { EOF GENERATE_BAZEL_FILES=1 run_soong - [[ -e out/soong/bp2build/b/BUILD ]] || fail "a/BUILD not created" - [[ -L out/soong/workspace/b/BUILD ]] || fail "a/BUILD not symlinked" + [[ -e out/soong/bp2build/b/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not created" + [[ -L out/soong/workspace/b/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not symlinked" } function test_bp2build_null_build { @@ -551,11 +553,11 @@ filegroup { EOF GENERATE_BAZEL_FILES=1 run_soong - grep -q a1.txt out/soong/bp2build/a/BUILD || fail "a1.txt not in BUILD file" + grep -q a1.txt "out/soong/bp2build/a/${GENERATED_BUILD_FILE_NAME}" || fail "a1.txt not in ${GENERATED_BUILD_FILE_NAME} file" touch a/a2.txt GENERATE_BAZEL_FILES=1 run_soong - grep -q a2.txt out/soong/bp2build/a/BUILD || fail "a2.txt not in BUILD file" + grep -q a2.txt "out/soong/bp2build/a/${GENERATED_BUILD_FILE_NAME}" || fail "a2.txt not in ${GENERATED_BUILD_FILE_NAME} file" } function test_dump_json_module_graph() { @@ -583,8 +585,8 @@ EOF GENERATE_BAZEL_FILES=1 run_soong [[ -e out/soong/workspace ]] || fail "Bazel workspace not created" [[ -d out/soong/workspace/a/b ]] || fail "module directory not a directory" - [[ -L out/soong/workspace/a/b/BUILD ]] || fail "BUILD file not symlinked" - [[ "$(readlink -f out/soong/workspace/a/b/BUILD)" =~ bp2build/a/b/BUILD$ ]] \ + [[ -L "out/soong/workspace/a/b/${GENERATED_BUILD_FILE_NAME}" ]] || fail "${GENERATED_BUILD_FILE_NAME} file not symlinked" + [[ "$(readlink -f out/soong/workspace/a/b/${GENERATED_BUILD_FILE_NAME})" =~ "bp2build/a/b/${GENERATED_BUILD_FILE_NAME}"$ ]] \ || fail "BUILD files symlinked at the wrong place" [[ -L out/soong/workspace/a/b/b.txt ]] || fail "a/b/b.txt not symlinked" [[ -L out/soong/workspace/a/a.txt ]] || fail "a/b/a.txt not symlinked" @@ -616,7 +618,7 @@ function test_bp2build_build_file_precedence { mkdir -p a touch a/a.txt - touch a/BUILD + touch a/${GENERATED_BUILD_FILE_NAME} cat > a/Android.bp < a/Android.bp < b/Android.bp <