Move bazel.Properties to a BazelModuleBase

This allows more direct access to the bazel label and whether the module
is bp2build available.

Test: go test *
Change-Id: I23375835d20fa53d7d94127b2dc2d5bb20487bfb
diff --git a/android/Android.bp b/android/Android.bp
index 00139d8..a8fa53a 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -22,6 +22,7 @@
         "api_levels.go",
         "arch.go",
         "arch_list.go",
+        "bazel.go",
         "bazel_handler.go",
         "config.go",
         "csuite_config.go",
diff --git a/android/bazel.go b/android/bazel.go
new file mode 100644
index 0000000..9939bd5
--- /dev/null
+++ b/android/bazel.go
@@ -0,0 +1,57 @@
+// Copyright 2021 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android
+
+import "android/soong/bazel"
+
+// BazelModuleBase contains the property structs with metadata for modules which can be converted to
+// Bazel.
+type BazelModuleBase struct {
+	bazelProperties bazel.Properties
+}
+
+// Bazelable is specifies the interface for modules that can be converted to Bazel.
+type Bazelable interface {
+	bazelProps() *bazel.Properties
+	GetBazelLabel() string
+	ConvertWithBp2build() bool
+}
+
+// BazelModule is a lightweight wrapper interface around Module for Bazel-convertible modules.
+type BazelModule interface {
+	Module
+	Bazelable
+}
+
+// InitBazelModule is a wrapper function that decorates a BazelModule with Bazel-conversion
+// properties.
+func InitBazelModule(module BazelModule) {
+	module.AddProperties(module.bazelProps())
+}
+
+// bazelProps returns the Bazel properties for the given BazelModuleBase.
+func (b *BazelModuleBase) bazelProps() *bazel.Properties {
+	return &b.bazelProperties
+}
+
+// GetBazelLabel returns the Bazel label for the given BazelModuleBase.
+func (b *BazelModuleBase) GetBazelLabel() string {
+	return b.bazelProperties.Bazel_module.Label
+}
+
+// ConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build.
+func (b *BazelModuleBase) ConvertWithBp2build() bool {
+	return b.bazelProperties.Bazel_module.Bp2build_available
+}
diff --git a/android/filegroup.go b/android/filegroup.go
index 674a196..f75076f 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -49,7 +49,7 @@
 
 func FilegroupBp2Build(ctx TopDownMutatorContext) {
 	fg, ok := ctx.Module().(*fileGroup)
-	if !ok || !fg.properties.Bazel_module.Bp2build_available {
+	if !ok || !fg.ConvertWithBp2build() {
 		return
 	}
 
@@ -77,13 +77,11 @@
 	// Create a make variable with the specified name that contains the list of files in the
 	// filegroup, relative to the root of the source tree.
 	Export_to_make_var *string
-
-	// Properties for Bazel migration purposes.
-	bazel.Properties
 }
 
 type fileGroup struct {
 	ModuleBase
+	BazelModuleBase
 	properties fileGroupProperties
 	srcs       Paths
 }
@@ -97,6 +95,7 @@
 	module := &fileGroup{}
 	module.AddProperties(&module.properties)
 	InitAndroidModule(module)
+	InitBazelModule(module)
 	return module
 }
 
diff --git a/bp2build/testing.go b/bp2build/testing.go
index 9774915..a87fd7a 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -25,10 +25,9 @@
 
 type customModule struct {
 	android.ModuleBase
+	android.BazelModuleBase
 
 	props customProps
-
-	bazelProps bazel.Properties
 }
 
 // OutputFiles is needed because some instances of this module use dist with a
@@ -44,7 +43,7 @@
 func customModuleFactoryBase() android.Module {
 	module := &customModule{}
 	module.AddProperties(&module.props)
-	module.AddProperties(&module.bazelProps)
+	android.InitBazelModule(module)
 	return module
 }
 
@@ -127,7 +126,7 @@
 
 func customBp2BuildMutator(ctx android.TopDownMutatorContext) {
 	if m, ok := ctx.Module().(*customModule); ok {
-		if !m.bazelProps.Bazel_module.Bp2build_available {
+		if !m.ConvertWithBp2build() {
 			return
 		}
 
@@ -146,7 +145,7 @@
 // module to target.
 func customBp2BuildMutatorFromStarlark(ctx android.TopDownMutatorContext) {
 	if m, ok := ctx.Module().(*customModule); ok {
-		if !m.bazelProps.Bazel_module.Bp2build_available {
+		if !m.ConvertWithBp2build() {
 			return
 		}
 
diff --git a/cc/cc.go b/cc/cc.go
index 6c1469f..11d8718 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -28,7 +28,6 @@
 	"github.com/google/blueprint/proptools"
 
 	"android/soong/android"
-	"android/soong/bazel"
 	"android/soong/cc/config"
 	"android/soong/genrule"
 )
@@ -365,8 +364,6 @@
 	// can depend on libraries that are not exported by the APEXes and use private symbols
 	// from the exported libraries.
 	Test_for []string
-
-	bazel.Properties
 }
 
 type VendorProperties struct {
@@ -765,6 +762,7 @@
 	android.DefaultableModuleBase
 	android.ApexModuleBase
 	android.SdkBase
+	android.BazelModuleBase
 
 	Properties       BaseProperties
 	VendorProperties VendorProperties
@@ -1054,6 +1052,7 @@
 	}
 
 	android.InitAndroidArchModule(c, c.hod, c.multilib)
+	android.InitBazelModule(c)
 	android.InitApexModule(c)
 	android.InitSdkAwareModule(c)
 	android.InitDefaultableModule(c)
diff --git a/cc/library_headers.go b/cc/library_headers.go
index e5a5557..5b61832 100644
--- a/cc/library_headers.go
+++ b/cc/library_headers.go
@@ -86,7 +86,7 @@
 		return
 	}
 
-	if !module.Properties.Bazel_module.Bp2build_available {
+	if !module.ConvertWithBp2build() {
 		return
 	}
 
diff --git a/cc/object.go b/cc/object.go
index d92e110..8f0a310 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -118,7 +118,7 @@
 // Bazel equivalent target, plus any necessary include deps for the cc_object.
 func ObjectBp2Build(ctx android.TopDownMutatorContext) {
 	m, ok := ctx.Module().(*Module)
-	if !ok || !m.Properties.Bazel_module.Bp2build_available {
+	if !ok || !m.ConvertWithBp2build() {
 		return
 	}
 
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 9fa6c48..25ad1b6 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -124,14 +124,12 @@
 
 	// input files to exclude
 	Exclude_srcs []string `android:"path,arch_variant"`
-
-	// Properties for Bazel migration purposes.
-	bazel.Properties
 }
 
 type Module struct {
 	android.ModuleBase
 	android.DefaultableModuleBase
+	android.BazelModuleBase
 	android.ApexModuleBase
 
 	// For other packages to make their own genrules with extra
@@ -519,7 +517,7 @@
 
 	g.outputFiles = outputFiles.Paths()
 
-	bazelModuleLabel := g.properties.Bazel_module.Label
+	bazelModuleLabel := g.GetBazelLabel()
 	bazelActionsUsed := false
 	if ctx.Config().BazelContext.BazelEnabled() && len(bazelModuleLabel) > 0 {
 		bazelActionsUsed = g.generateBazelBuildActions(ctx, bazelModuleLabel)
@@ -771,6 +769,7 @@
 	m := NewGenRule()
 	android.InitAndroidModule(m)
 	android.InitDefaultableModule(m)
+	android.InitBazelModule(m)
 	return m
 }
 
@@ -800,7 +799,7 @@
 
 func GenruleBp2Build(ctx android.TopDownMutatorContext) {
 	m, ok := ctx.Module().(*Module)
-	if !ok || !m.properties.Bazel_module.Bp2build_available {
+	if !ok || !m.ConvertWithBp2build() {
 		return
 	}
 
diff --git a/sh/sh_binary.go b/sh/sh_binary.go
index 58f8cf6..5aa2450 100644
--- a/sh/sh_binary.go
+++ b/sh/sh_binary.go
@@ -84,9 +84,6 @@
 
 	// Make this module available when building for recovery.
 	Recovery_available *bool
-
-	// Properties for Bazel migration purposes.
-	bazel.Properties
 }
 
 type TestProperties struct {
@@ -132,6 +129,7 @@
 
 type ShBinary struct {
 	android.ModuleBase
+	android.BazelModuleBase
 
 	properties shBinaryProperties
 
@@ -427,6 +425,7 @@
 
 func InitShBinaryModule(s *ShBinary) {
 	s.AddProperties(&s.properties)
+	android.InitBazelModule(s)
 }
 
 // sh_binary is for a shell script or batch file to be installed as an
@@ -504,7 +503,7 @@
 
 func ShBinaryBp2Build(ctx android.TopDownMutatorContext) {
 	m, ok := ctx.Module().(*ShBinary)
-	if !ok || !m.properties.Bazel_module.Bp2build_available {
+	if !ok || !m.ConvertWithBp2build() {
 		return
 	}