Merge changes I1ff171b9,Id64085d6
* changes: Add an integration test for API export from another bazel package Generate a BUILD file for every Android.bp file in api_bp2build workspace.
This commit is contained in:
@@ -136,7 +136,7 @@ func runQueryView(queryviewDir, queryviewMarker string, ctx *android.Context) {
|
||||
ctx.EventHandler.Begin("queryview")
|
||||
defer ctx.EventHandler.End("queryview")
|
||||
codegenContext := bp2build.NewCodegenContext(ctx.Config(), ctx, bp2build.QueryView, topDir)
|
||||
err := createBazelWorkspace(codegenContext, shared.JoinPath(topDir, queryviewDir))
|
||||
err := createBazelWorkspace(codegenContext, shared.JoinPath(topDir, queryviewDir), false)
|
||||
maybeQuit(err, "")
|
||||
touch(shared.JoinPath(topDir, queryviewMarker))
|
||||
}
|
||||
@@ -174,7 +174,28 @@ func runApiBp2build(ctx *android.Context, extraNinjaDeps []string) string {
|
||||
// Run codegen to generate BUILD files
|
||||
codegenContext := bp2build.NewCodegenContext(ctx.Config(), ctx, bp2build.ApiBp2build, topDir)
|
||||
absoluteApiBp2buildDir := shared.JoinPath(topDir, cmdlineArgs.BazelApiBp2buildDir)
|
||||
err := createBazelWorkspace(codegenContext, absoluteApiBp2buildDir)
|
||||
// Always generate bp2build_all_srcs filegroups in api_bp2build.
|
||||
// This is necessary to force each Android.bp file to create an equivalent BUILD file
|
||||
// and prevent package boundray issues.
|
||||
// e.g.
|
||||
// Source
|
||||
// f/b/Android.bp
|
||||
// java_library{
|
||||
// name: "foo",
|
||||
// api: "api/current.txt",
|
||||
// }
|
||||
//
|
||||
// f/b/api/Android.bp <- will cause package boundary issues
|
||||
//
|
||||
// Gen
|
||||
// f/b/BUILD
|
||||
// java_contribution{
|
||||
// name: "foo.contribution",
|
||||
// api: "//f/b/api:current.txt",
|
||||
// }
|
||||
//
|
||||
// If we don't generate f/b/api/BUILD, foo.contribution will be unbuildable.
|
||||
err := createBazelWorkspace(codegenContext, absoluteApiBp2buildDir, true)
|
||||
maybeQuit(err, "")
|
||||
ninjaDeps = append(ninjaDeps, codegenContext.AdditionalNinjaDeps()...)
|
||||
|
||||
|
@@ -25,11 +25,11 @@ import (
|
||||
)
|
||||
|
||||
// A helper function to generate a Read-only Bazel workspace in outDir
|
||||
func createBazelWorkspace(ctx *bp2build.CodegenContext, outDir string) error {
|
||||
func createBazelWorkspace(ctx *bp2build.CodegenContext, outDir string, generateFilegroups bool) error {
|
||||
os.RemoveAll(outDir)
|
||||
ruleShims := bp2build.CreateRuleShims(android.ModuleTypeFactories())
|
||||
|
||||
res, err := bp2build.GenerateBazelTargets(ctx, false)
|
||||
res, err := bp2build.GenerateBazelTargets(ctx, generateFilegroups)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@@ -343,4 +343,29 @@ function test_api_bp2build_empty_build() {
|
||||
run_bazel build --config=android --config=api_bp2build //:empty
|
||||
}
|
||||
|
||||
# Verify that an *_api_contribution target can refer to an api file from
|
||||
# another Bazel package.
|
||||
function test_api_export_from_another_bazel_package() {
|
||||
setup
|
||||
# Parent dir Android.bp
|
||||
mkdir -p foo
|
||||
cat > foo/Android.bp << 'EOF'
|
||||
cc_library {
|
||||
name: "libfoo",
|
||||
stubs: {
|
||||
symbol_file: "api/libfoo.map.txt",
|
||||
},
|
||||
}
|
||||
EOF
|
||||
# Child dir Android.bp
|
||||
mkdir -p foo/api
|
||||
cat > foo/api/Android.bp << 'EOF'
|
||||
package{}
|
||||
EOF
|
||||
touch foo/api/libfoo.map.txt
|
||||
# Run test
|
||||
run_soong api_bp2build
|
||||
run_bazel build --config=android --config=api_bp2build //foo:libfoo.contribution
|
||||
}
|
||||
|
||||
scan_and_run_tests
|
||||
|
Reference in New Issue
Block a user