Implement bp2build for the `package` module
* We are interested mostly in the conversion the `default_applicable_licenses`
attribute, as `default_visibility` cannot be handled until every module's
`visibility` is handled.
* Several referenced license modules had to be manually enabled for
conversion, and likewise a few trivial Android.bp containing only
package and license modules.
* As Bazel allows only a single `package` rule, the package rules in a
manually converted BUILD.bazel files were removed (in
external/protobuf and prebuilts/clang/host/linux-x86 trees).
* The converted package rule is emitted before the `load` statements per
Bazel documentation.
Bug: 190817312
Test: treehugger
Change-Id: If8bf6fee1580177de3bb402923615bcd48923ed2
diff --git a/bp2build/conversion.go b/bp2build/conversion.go
index 731b17e..b6190c6 100644
--- a/bp2build/conversion.go
+++ b/bp2build/conversion.go
@@ -96,10 +96,14 @@
# This file was automatically generated by bp2build for the Bazel migration project.
# Feel free to edit or test it, but do *not* check it into your version control system.
`
-
- // Hardcode the default visibility.
- content += "package(default_visibility = [\"//visibility:public\"])\n"
content += targets.LoadStatements()
+ content += "\n\n"
+ // Get package rule from the handcrafted BUILD file, otherwise emit the default one.
+ prText := "package(default_visibility = [\"//visibility:public\"])\n"
+ if pr := targets.packageRule(); pr != nil {
+ prText = pr.content
+ }
+ content += prText
} else if mode == QueryView {
content = soongModuleLoad
}
@@ -160,7 +164,7 @@
// internal to Soong only, and these fields do not have PkgPath.
return true
}
- // fields with tag `blueprint:"mutated"` are exported to enable modification in mutators, etc
+ // fields with tag `blueprint:"mutated"` are exported to enable modification in mutators, etc.
// but cannot be set in a .bp file
if proptools.HasTag(field, "blueprint", "mutated") {
return true