a1b9372ef7
This includes the JSON graph generator and bp2build. Before: GENERATE_BAZEL_FILES=1 m nothing GENERATE_JSON_MODULE_GRAPH=1 m nothing Now: m json-module-graph m bp2build They can now also be combined with other targets or each other. The longer-term goal is to run "m queryview" and "m soong_docs" using the same infrastructure. There are two alternate approaches: 1. Call soong_build from within the main Ninja invocation. This requires two sequential soong_build invocations and is thus slower. 2. Do everything requested in the same soong_build invocation. This would be faster, but one AFAIU can't tell Ninja that multiple possible actions can build the same output so that doesn't work. (1) is somewhat more desirable because soong_docs seems to be built from build/make/core/main.mk ; I assume that that can be worked around although I haven't checked where the output of "m soong_docs" goes. Test: Presubmits. Change-Id: If5ba36490d9f3f60733e6d6be9286eb2b67c3ff5
117 lines
3.4 KiB
Bash
Executable file
117 lines
3.4 KiB
Bash
Executable file
#!/bin/bash -eu
|
|
|
|
set -o pipefail
|
|
|
|
# Test that bp2build and Bazel can play nicely together
|
|
|
|
source "$(dirname "$0")/lib.sh"
|
|
|
|
readonly GENERATED_BUILD_FILE_NAME="BUILD.bazel"
|
|
|
|
function test_bp2build_null_build() {
|
|
setup
|
|
run_soong bp2build
|
|
local output_mtime1=$(stat -c "%y" out/soong/.bootstrap/bp2build_workspace_marker)
|
|
|
|
run_soong bp2build
|
|
local output_mtime2=$(stat -c "%y" out/soong/.bootstrap/bp2build_workspace_marker)
|
|
|
|
if [[ "$output_mtime1" != "$output_mtime2" ]]; then
|
|
fail "Output bp2build marker file changed on null build"
|
|
fi
|
|
}
|
|
|
|
test_bp2build_null_build
|
|
|
|
function test_bp2build_null_build_with_globs() {
|
|
setup
|
|
|
|
mkdir -p foo/bar
|
|
cat > foo/bar/Android.bp <<'EOF'
|
|
filegroup {
|
|
name: "globs",
|
|
srcs: ["*.txt"],
|
|
}
|
|
EOF
|
|
touch foo/bar/a.txt foo/bar/b.txt
|
|
|
|
run_soong bp2build
|
|
local output_mtime1=$(stat -c "%y" out/soong/.bootstrap/bp2build_workspace_marker)
|
|
|
|
run_soong bp2build
|
|
local output_mtime2=$(stat -c "%y" out/soong/.bootstrap/bp2build_workspace_marker)
|
|
|
|
if [[ "$output_mtime1" != "$output_mtime2" ]]; then
|
|
fail "Output bp2build marker file changed on null build"
|
|
fi
|
|
}
|
|
|
|
test_bp2build_null_build_with_globs
|
|
|
|
function test_bp2build_generates_all_buildfiles {
|
|
setup
|
|
create_mock_bazel
|
|
|
|
mkdir -p foo/convertible_soong_module
|
|
cat > foo/convertible_soong_module/Android.bp <<'EOF'
|
|
genrule {
|
|
name: "the_answer",
|
|
cmd: "echo '42' > $(out)",
|
|
out: [
|
|
"the_answer.txt",
|
|
],
|
|
bazel_module: {
|
|
bp2build_available: true,
|
|
},
|
|
}
|
|
EOF
|
|
|
|
mkdir -p foo/unconvertible_soong_module
|
|
cat > foo/unconvertible_soong_module/Android.bp <<'EOF'
|
|
genrule {
|
|
name: "not_the_answer",
|
|
cmd: "echo '43' > $(out)",
|
|
out: [
|
|
"not_the_answer.txt",
|
|
],
|
|
bazel_module: {
|
|
bp2build_available: false,
|
|
},
|
|
}
|
|
EOF
|
|
|
|
run_soong bp2build
|
|
|
|
if [[ ! -f "./out/soong/workspace/foo/convertible_soong_module/${GENERATED_BUILD_FILE_NAME}" ]]; then
|
|
fail "./out/soong/workspace/foo/convertible_soong_module/${GENERATED_BUILD_FILE_NAME} was not generated"
|
|
fi
|
|
|
|
if [[ ! -f "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}" ]]; then
|
|
fail "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME} was not generated"
|
|
fi
|
|
|
|
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/${GENERATED_BUILD_FILE_NAME}"
|
|
fi
|
|
|
|
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/${GENERATED_BUILD_FILE_NAME}"
|
|
fi
|
|
|
|
if ! grep "filegroup" "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}"; then
|
|
fail "missing filegroup in unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}"
|
|
fi
|
|
|
|
# NOTE: We don't actually use the extra BUILD file for anything here
|
|
run_bazel build --package_path=out/soong/workspace //foo/...
|
|
|
|
local the_answer_file="bazel-out/k8-fastbuild/bin/foo/convertible_soong_module/the_answer.txt"
|
|
if [[ ! -f "${the_answer_file}" ]]; then
|
|
fail "Expected '${the_answer_file}' to be generated, but was missing"
|
|
fi
|
|
if ! grep 42 "${the_answer_file}"; then
|
|
fail "Expected to find 42 in '${the_answer_file}'"
|
|
fi
|
|
}
|
|
|
|
test_bp2build_generates_all_buildfiles
|