bp2build: refactor BazelTargetModule naming boilerplate.

This CL replaces the "__bp2build__" name prefix boilerplate with a props
creation function, and centralizes the prefixing in there.

Test: TH
Test: soong tests
Change-Id: Ic963199ab60dcce0d3361abff111cfa9acd4c21b
diff --git a/android/filegroup.go b/android/filegroup.go
index 98d0eaf..674a196 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -57,12 +57,7 @@
 		Srcs: BazelLabelForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs),
 	}
 
-	// Can we automate this?
-	name := "__bp2build__" + fg.Name()
-	props := bazel.BazelTargetModuleProperties{
-		Name:       &name,
-		Rule_class: "filegroup",
-	}
+	props := bazel.NewBazelTargetModuleProperties(fg.Name(), "filegroup", "")
 
 	ctx.CreateBazelTargetModule(BazelFileGroupFactory, props, attrs)
 }
diff --git a/android/mutator.go b/android/mutator.go
index 91753d1..c387193 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -16,7 +16,9 @@
 
 import (
 	"android/soong/bazel"
+	"fmt"
 	"reflect"
+	"strings"
 
 	"github.com/google/blueprint"
 	"github.com/google/blueprint/proptools"
@@ -513,6 +515,14 @@
 	factory ModuleFactory,
 	bazelProps bazel.BazelTargetModuleProperties,
 	attrs interface{}) BazelTargetModule {
+	if !strings.HasPrefix(*bazelProps.Name, bazel.BazelTargetModuleNamePrefix) {
+		panic(fmt.Errorf(
+			"bp2build error: the bazel target module name must start with '%s': %s",
+			bazel.BazelTargetModuleNamePrefix,
+			*bazelProps.Name,
+		))
+	}
+
 	return t.CreateModule(factory, &bazelProps, attrs).(BazelTargetModule)
 }