Have bp2build generate BUILD.bazel instead of generating BUILD.
Test: TH Change-Id: I465d29da96dd77c432890a38a56203e291b8ceed
This commit is contained in:
parent
f1d8819d7d
commit
413a7a97fb
4 changed files with 37 additions and 30 deletions
|
@ -19,7 +19,10 @@ var (
|
||||||
// be preferred for use within a Bazel build.
|
// be preferred for use within a Bazel build.
|
||||||
|
|
||||||
// The file name used for automatically generated files.
|
// The file name used for automatically generated files.
|
||||||
GeneratedBuildFileName = "BUILD"
|
GeneratedBuildFileName = "BUILD.bazel"
|
||||||
|
|
||||||
// The file name used for hand-crafted build targets.
|
// 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"
|
HandcraftedBuildFileName = "BUILD.bazel"
|
||||||
)
|
)
|
||||||
|
|
|
@ -29,7 +29,7 @@ func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) {
|
||||||
expectedFilePaths := []bazelFilepath{
|
expectedFilePaths := []bazelFilepath{
|
||||||
{
|
{
|
||||||
dir: "",
|
dir: "",
|
||||||
basename: "BUILD",
|
basename: "BUILD.bazel",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dir: "",
|
dir: "",
|
||||||
|
@ -37,7 +37,7 @@ func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dir: bazelRulesSubDir,
|
dir: bazelRulesSubDir,
|
||||||
basename: "BUILD",
|
basename: "BUILD.bazel",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dir: bazelRulesSubDir,
|
dir: bazelRulesSubDir,
|
||||||
|
@ -69,7 +69,7 @@ func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) {
|
||||||
|
|
||||||
if actualFile.Dir != expectedFile.dir || actualFile.Basename != expectedFile.basename {
|
if actualFile.Dir != expectedFile.dir || actualFile.Basename != expectedFile.basename {
|
||||||
t.Errorf("Did not find expected file %s/%s", actualFile.Dir, actualFile.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 != "" {
|
if actualFile.Contents != "" {
|
||||||
t.Errorf("Expected %s to have no content.", actualFile)
|
t.Errorf("Expected %s to have no content.", actualFile)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ set -o pipefail
|
||||||
|
|
||||||
source "$(dirname "$0")/lib.sh"
|
source "$(dirname "$0")/lib.sh"
|
||||||
|
|
||||||
|
readonly GENERATED_BUILD_FILE_NAME="BUILD.bazel"
|
||||||
|
|
||||||
function test_smoke {
|
function test_smoke {
|
||||||
setup
|
setup
|
||||||
run_soong
|
run_soong
|
||||||
|
@ -505,8 +507,8 @@ filegroup {
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
GENERATE_BAZEL_FILES=1 run_soong
|
GENERATE_BAZEL_FILES=1 run_soong
|
||||||
[[ -e out/soong/bp2build/a/BUILD ]] || fail "a/BUILD not created"
|
[[ -e out/soong/bp2build/a/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not created"
|
||||||
[[ -L out/soong/workspace/a/BUILD ]] || fail "a/BUILD not symlinked"
|
[[ -L out/soong/workspace/a/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not symlinked"
|
||||||
|
|
||||||
mkdir -p b
|
mkdir -p b
|
||||||
touch b/b.txt
|
touch b/b.txt
|
||||||
|
@ -519,8 +521,8 @@ filegroup {
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
GENERATE_BAZEL_FILES=1 run_soong
|
GENERATE_BAZEL_FILES=1 run_soong
|
||||||
[[ -e out/soong/bp2build/b/BUILD ]] || fail "a/BUILD not created"
|
[[ -e out/soong/bp2build/b/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not created"
|
||||||
[[ -L out/soong/workspace/b/BUILD ]] || fail "a/BUILD not symlinked"
|
[[ -L out/soong/workspace/b/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not symlinked"
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_bp2build_null_build {
|
function test_bp2build_null_build {
|
||||||
|
@ -551,11 +553,11 @@ filegroup {
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
GENERATE_BAZEL_FILES=1 run_soong
|
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
|
touch a/a2.txt
|
||||||
GENERATE_BAZEL_FILES=1 run_soong
|
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() {
|
function test_dump_json_module_graph() {
|
||||||
|
@ -583,8 +585,8 @@ EOF
|
||||||
GENERATE_BAZEL_FILES=1 run_soong
|
GENERATE_BAZEL_FILES=1 run_soong
|
||||||
[[ -e out/soong/workspace ]] || fail "Bazel workspace not created"
|
[[ -e out/soong/workspace ]] || fail "Bazel workspace not created"
|
||||||
[[ -d out/soong/workspace/a/b ]] || fail "module directory not a directory"
|
[[ -d out/soong/workspace/a/b ]] || fail "module directory not a directory"
|
||||||
[[ -L out/soong/workspace/a/b/BUILD ]] || fail "BUILD file not symlinked"
|
[[ -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/BUILD)" =~ bp2build/a/b/BUILD$ ]] \
|
[[ "$(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"
|
|| 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/b/b.txt ]] || fail "a/b/b.txt not symlinked"
|
||||||
[[ -L out/soong/workspace/a/a.txt ]] || fail "a/b/a.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
|
mkdir -p a
|
||||||
touch a/a.txt
|
touch a/a.txt
|
||||||
touch a/BUILD
|
touch a/${GENERATED_BUILD_FILE_NAME}
|
||||||
cat > a/Android.bp <<EOF
|
cat > a/Android.bp <<EOF
|
||||||
filegroup {
|
filegroup {
|
||||||
name: "a",
|
name: "a",
|
||||||
|
@ -626,15 +628,15 @@ filegroup {
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
GENERATE_BAZEL_FILES=1 run_soong
|
GENERATE_BAZEL_FILES=1 run_soong
|
||||||
[[ -L out/soong/workspace/a/BUILD ]] || fail "BUILD file not symlinked"
|
[[ -L "out/soong/workspace/a/${GENERATED_BUILD_FILE_NAME}" ]] || fail "${GENERATED_BUILD_FILE_NAME} file not symlinked"
|
||||||
[[ "$(readlink -f out/soong/workspace/a/BUILD)" =~ bp2build/a/BUILD$ ]] \
|
[[ "$(readlink -f out/soong/workspace/a/${GENERATED_BUILD_FILE_NAME})" =~ "bp2build/a/${GENERATED_BUILD_FILE_NAME}"$ ]] \
|
||||||
|| fail "BUILD files symlinked to the wrong place"
|
|| fail "${GENERATED_BUILD_FILE_NAME} files symlinked to the wrong place"
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_bp2build_reports_multiple_errors {
|
function test_bp2build_reports_multiple_errors {
|
||||||
setup
|
setup
|
||||||
|
|
||||||
mkdir -p a/BUILD
|
mkdir -p "a/${GENERATED_BUILD_FILE_NAME}"
|
||||||
touch a/a.txt
|
touch a/a.txt
|
||||||
cat > a/Android.bp <<EOF
|
cat > a/Android.bp <<EOF
|
||||||
filegroup {
|
filegroup {
|
||||||
|
@ -644,7 +646,7 @@ filegroup {
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
mkdir -p b/BUILD
|
mkdir -p "b/${GENERATED_BUILD_FILE_NAME}"
|
||||||
touch b/b.txt
|
touch b/b.txt
|
||||||
cat > b/Android.bp <<EOF
|
cat > b/Android.bp <<EOF
|
||||||
filegroup {
|
filegroup {
|
||||||
|
@ -658,8 +660,8 @@ EOF
|
||||||
fail "Build should have failed"
|
fail "Build should have failed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
grep -q "a/BUILD' exist" "$MOCK_TOP/errors" || fail "Error for a/BUILD not found"
|
grep -q "a/${GENERATED_BUILD_FILE_NAME}' exist" "$MOCK_TOP/errors" || fail "Error for a/${GENERATED_BUILD_FILE_NAME} not found"
|
||||||
grep -q "b/BUILD' exist" "$MOCK_TOP/errors" || fail "Error for b/BUILD not found"
|
grep -q "b/${GENERATED_BUILD_FILE_NAME}' exist" "$MOCK_TOP/errors" || fail "Error for b/${GENERATED_BUILD_FILE_NAME} not found"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_smoke
|
test_smoke
|
||||||
|
|
|
@ -6,6 +6,8 @@ set -o pipefail
|
||||||
|
|
||||||
source "$(dirname "$0")/lib.sh"
|
source "$(dirname "$0")/lib.sh"
|
||||||
|
|
||||||
|
readonly GENERATED_BUILD_FILE_NAME="BUILD.bazel"
|
||||||
|
|
||||||
function test_bp2build_generates_all_buildfiles {
|
function test_bp2build_generates_all_buildfiles {
|
||||||
setup
|
setup
|
||||||
create_mock_bazel
|
create_mock_bazel
|
||||||
|
@ -40,24 +42,24 @@ EOF
|
||||||
|
|
||||||
run_bp2build
|
run_bp2build
|
||||||
|
|
||||||
if [[ ! -f "./out/soong/workspace/foo/convertible_soong_module/BUILD" ]]; then
|
if [[ ! -f "./out/soong/workspace/foo/convertible_soong_module/${GENERATED_BUILD_FILE_NAME}" ]]; then
|
||||||
fail "./out/soong/workspace/foo/convertible_soong_module/BUILD was not generated"
|
fail "./out/soong/workspace/foo/convertible_soong_module/${GENERATED_BUILD_FILE_NAME} was not generated"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f "./out/soong/workspace/foo/unconvertible_soong_module/BUILD" ]]; then
|
if [[ ! -f "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}" ]]; then
|
||||||
fail "./out/soong/workspace/foo/unconvertible_soong_module/BUILD was not generated"
|
fail "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME} was not generated"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! grep "the_answer" "./out/soong/workspace/foo/convertible_soong_module/BUILD"; then
|
if ! grep "the_answer" "./out/soong/workspace/foo/convertible_soong_module/${GENERATED_BUILD_FILE_NAME}"; then
|
||||||
fail "missing BUILD target the_answer in convertible_soong_module/BUILD"
|
fail "missing BUILD target the_answer in convertible_soong_module/${GENERATED_BUILD_FILE_NAME}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if grep "not_the_answer" "./out/soong/workspace/foo/unconvertible_soong_module/BUILD"; then
|
if grep "not_the_answer" "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}"; then
|
||||||
fail "found unexpected BUILD target not_the_answer in unconvertible_soong_module/BUILD"
|
fail "found unexpected BUILD target not_the_answer in unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! grep "filegroup" "./out/soong/workspace/foo/unconvertible_soong_module/BUILD"; then
|
if ! grep "filegroup" "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}"; then
|
||||||
fail "missing filegroup in unconvertible_soong_module/BUILD"
|
fail "missing filegroup in unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# NOTE: We don't actually use the extra BUILD file for anything here
|
# NOTE: We don't actually use the extra BUILD file for anything here
|
||||||
|
|
Loading…
Reference in a new issue