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/build_conversion.go b/bp2build/build_conversion.go
index 49b9144..ee162b2 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -64,7 +64,16 @@
// BazelTargets is a typedef for a slice of BazelTarget objects.
type BazelTargets []BazelTarget
-// sort a list of BazelTargets in-place by name
+func (targets BazelTargets) packageRule() *BazelTarget {
+ for _, target := range targets {
+ if target.ruleClass == "package" {
+ return &target
+ }
+ }
+ return nil
+}
+
+// sort a list of BazelTargets in-place, by name, and by generated/handcrafted types.
func (targets BazelTargets) sort() {
sort.Slice(targets, func(i, j int) bool {
return targets[i].name < targets[j].name
@@ -77,7 +86,9 @@
func (targets BazelTargets) String() string {
var res string
for i, target := range targets {
- res += target.content
+ if target.ruleClass != "package" {
+ res += target.content
+ }
if i != len(targets)-1 {
res += "\n\n"
}