Merge "Update bp2build tests to use stubbed defs" into main
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index dcad55e..f35fe3d 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -142,6 +142,7 @@
"external/bzip2": Bp2BuildDefaultTrueRecursively,
"external/clang/lib": Bp2BuildDefaultTrue,
"external/conscrypt": Bp2BuildDefaultTrue,
+ "external/dexmaker": Bp2BuildDefaultTrueRecursively,
"external/e2fsprogs": Bp2BuildDefaultTrueRecursively,
"external/eigen": Bp2BuildDefaultTrueRecursively,
"external/erofs-utils": Bp2BuildDefaultTrueRecursively,
@@ -194,6 +195,7 @@
"external/lzma/C": Bp2BuildDefaultTrueRecursively,
"external/mdnsresponder": Bp2BuildDefaultTrueRecursively,
"external/minijail": Bp2BuildDefaultTrueRecursively,
+ "external/mockito": Bp2BuildDefaultTrueRecursively,
"external/musl": Bp2BuildDefaultTrueRecursively,
"external/objenesis": Bp2BuildDefaultTrueRecursively,
"external/openscreen": Bp2BuildDefaultTrueRecursively,
@@ -452,6 +454,7 @@
"tools/metalava": Bp2BuildDefaultTrueRecursively,
"tools/platform-compat/java/android/compat": Bp2BuildDefaultTrueRecursively,
"tools/platform-compat/java/androidprocessor": Bp2BuildDefaultTrueRecursively,
+ "tools/tradefederation/core/util_apps": Bp2BuildDefaultTrueRecursively,
"tools/tradefederation/prebuilts/filegroups": Bp2BuildDefaultTrueRecursively,
}
@@ -932,9 +935,7 @@
"androidx.test.annotation-nodeps",
// jni deps of an internal android_test (b/297405812)
- "libdexmakerjvmtiagent",
"libopenjdkjvmti_headers",
- "libstaticjvmtiagent",
// tradefed deps
"tradefed-protos",
@@ -1754,6 +1755,13 @@
"NanoAndroidTest",
"MtsLibnativehelperTestCases",
+ // Depends on androidx.test.rules
+ "DexmakerTests",
+ "dexmaker-tests-lib",
+ "dexmaker-mockmaker-tests",
+ "dexmaker-inline-mockmaker-tests",
+ "dexmaker-extended-mockmaker-tests",
+
// android_test_helper_app from allowlisted packages, but with unconverted deps
"SharedLibraryInfoTestApp",
}
diff --git a/android/config.go b/android/config.go
index 769d257..b3ff86b 100644
--- a/android/config.go
+++ b/android/config.go
@@ -2084,11 +2084,3 @@
func (c *deviceConfig) NextReleaseHideFlaggedApi() bool {
return Bool(c.config.productVariables.NextReleaseHideFlaggedApi)
}
-
-func (c *deviceConfig) ReleaseExposeFlaggedApi() bool {
- return Bool(c.config.productVariables.ReleaseExposeFlaggedApi)
-}
-
-func (c *deviceConfig) HideFlaggedApis() bool {
- return c.NextReleaseHideFlaggedApi() && !c.ReleaseExposeFlaggedApi()
-}
diff --git a/android/variable.go b/android/variable.go
index 516e69c..73a4b2c 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -490,8 +490,6 @@
PartitionVarsForBazelMigrationOnlyDoNotUse PartitionVariables `json:",omitempty"`
NextReleaseHideFlaggedApi *bool `json:",omitempty"`
-
- ReleaseExposeFlaggedApi *bool `json:",omitempty"`
}
type PartitionVariables struct {
@@ -516,6 +514,12 @@
ProductBaseFsPath string `json:",omitempty"`
ProductHeadroom string `json:",omitempty"`
ProductVerityPartition string `json:",omitempty"`
+
+ BoardAvbAddHashtreeFooterArgs string `json:",omitempty"`
+ BoardAvbKeyPath string `json:",omitempty"`
+ BoardAvbAlgorithm string `json:",omitempty"`
+ BoardAvbRollbackIndex string `json:",omitempty"`
+ BoardAvbRollbackIndexLocation string `json:",omitempty"`
}
TargetUserimagesUseExt2 bool `json:",omitempty"`
TargetUserimagesUseExt3 bool `json:",omitempty"`
@@ -538,6 +542,8 @@
BoardBuildGkiBootImageWithoutRamdisk bool `json:",omitempty"`
ProductUseDynamicPartitionSize bool `json:",omitempty"`
CopyImagesForTargetFilesZip bool `json:",omitempty"`
+
+ BoardAvbEnable bool `json:",omitempty"`
}
func boolPtr(v bool) *bool {
diff --git a/bp2build/aar_conversion_test.go b/bp2build/aar_conversion_test.go
index 0ca5c4e..57c38db 100644
--- a/bp2build/aar_conversion_test.go
+++ b/bp2build/aar_conversion_test.go
@@ -86,7 +86,7 @@
func TestConvertAndroidLibraryWithNoSources(t *testing.T) {
t.Helper()
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
- Description: "Android Library - modules with deps must have sources",
+ Description: "Android Library - modules will deps when there are no sources",
ModuleTypeUnderTest: "android_library",
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
Filesystem: map[string]string{
@@ -102,7 +102,18 @@
sdk_version: "current",
}
`,
- ExpectedBazelTargets: []string{},
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget(
+ "android_library",
+ "TestLib",
+ AttrNameToString{
+ "manifest": `"AndroidManifest.xml"`,
+ "resource_files": `["res/res.png"]`,
+ "sdk_version": `"current"`, // use as default
+ },
+ ),
+ MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
+ },
})
}
diff --git a/bp2build/bp2build_product_config.go b/bp2build/bp2build_product_config.go
index 091a5f3..3e00453 100644
--- a/bp2build/bp2build_product_config.go
+++ b/bp2build/bp2build_product_config.go
@@ -6,6 +6,7 @@
"os"
"path/filepath"
"reflect"
+ "sort"
"strings"
"android/soong/android"
@@ -28,6 +29,22 @@
target string
}
+func (l *bazelLabel) Less(other *bazelLabel) bool {
+ if l.repo < other.repo {
+ return true
+ }
+ if l.repo > other.repo {
+ return false
+ }
+ if l.pkg < other.pkg {
+ return true
+ }
+ if l.pkg > other.pkg {
+ return false
+ }
+ return l.target < other.target
+}
+
func (l *bazelLabel) String() string {
return fmt.Sprintf("@%s//%s:%s", l.repo, l.pkg, l.target)
}
@@ -229,9 +246,16 @@
mergedConvertedModulePathMap[k] = v
}
+ productLabels := make([]bazelLabel, 0, len(productLabelToVariables))
+ for k := range productLabelToVariables {
+ productLabels = append(productLabels, k)
+ }
+ sort.Slice(productLabels, func(i, j int) bool {
+ return productLabels[i].Less(&productLabels[j])
+ })
result.WriteString("platforms:\n")
- for productLabel, productVariables := range productLabelToVariables {
- platformMappingSingleProduct(productLabel, productVariables, soongConfigDefinitions, mergedConvertedModulePathMap, &result)
+ for _, productLabel := range productLabels {
+ platformMappingSingleProduct(productLabel, productLabelToVariables[productLabel], soongConfigDefinitions, mergedConvertedModulePathMap, &result)
}
return result.String(), nil
}
@@ -313,6 +337,8 @@
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:manifest_package_name_overrides=%s\n", strings.Join(productVariables.ManifestPackageNameOverrides, ",")))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:native_coverage=%t\n", proptools.Bool(productVariables.Native_coverage)))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_sdk_final=%t\n", proptools.Bool(productVariables.Platform_sdk_final)))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_security_patch=%s\n", proptools.String(productVariables.Platform_security_patch)))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_version_last_stable=%s\n", proptools.String(productVariables.Platform_version_last_stable)))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_version_name=%s\n", proptools.String(productVariables.Platform_version_name)))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_brand=%s\n", productVariables.ProductBrand))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_manufacturer=%s\n", productVariables.ProductManufacturer))
@@ -339,8 +365,9 @@
}
}
- for namespace, namespaceContents := range productVariables.VendorVars {
- for variable, value := range namespaceContents {
+ for _, namespace := range android.SortedKeys(productVariables.VendorVars) {
+ for _, variable := range android.SortedKeys(productVariables.VendorVars[namespace]) {
+ value := productVariables.VendorVars[namespace][variable]
key := namespace + "__" + variable
_, hasBool := soongConfigDefinitions.BoolVars[key]
_, hasString := soongConfigDefinitions.StringVars[key]
@@ -453,6 +480,7 @@
func createTargets(productLabelsToVariables map[bazelLabel]*android.ProductVariables, res map[string]BazelTargets) {
createGeneratedAndroidCertificateDirectories(productLabelsToVariables, res)
+ createAvbKeyFilegroups(productLabelsToVariables, res)
for label, variables := range productLabelsToVariables {
createSystemPartition(label, &variables.PartitionVarsForBazelMigrationOnlyDoNotUse, res)
}
@@ -487,10 +515,39 @@
}
}
+func createAvbKeyFilegroups(productLabelsToVariables map[bazelLabel]*android.ProductVariables, targets map[string]BazelTargets) {
+ var allAvbKeys []string
+ for _, productVariables := range productLabelsToVariables {
+ for _, partitionVariables := range productVariables.PartitionVarsForBazelMigrationOnlyDoNotUse.PartitionQualifiedVariables {
+ if partitionVariables.BoardAvbKeyPath != "" {
+ if !android.InList(partitionVariables.BoardAvbKeyPath, allAvbKeys) {
+ allAvbKeys = append(allAvbKeys, partitionVariables.BoardAvbKeyPath)
+ }
+ }
+ }
+ }
+ for _, key := range allAvbKeys {
+ dir := filepath.Dir(key)
+ name := filepath.Base(key)
+ content := fmt.Sprintf(`filegroup(
+ name = "%s_filegroup",
+ srcs = ["%s"],
+ visibility = ["//visibility:public"],
+)`, name, name)
+ targets[dir] = append(targets[dir], BazelTarget{
+ name: name + "_filegroup",
+ packageName: dir,
+ content: content,
+ ruleClass: "filegroup",
+ })
+ }
+}
+
func createSystemPartition(platformLabel bazelLabel, variables *android.PartitionVariables, targets map[string]BazelTargets) {
if !variables.PartitionQualifiedVariables["system"].BuildingImage {
return
}
+ qualifiedVariables := variables.PartitionQualifiedVariables["system"]
imageProps := generateImagePropDictionary(variables, "system")
imageProps["skip_fsck"] = "true"
@@ -503,6 +560,19 @@
properties.WriteRune('\n')
}
+ var extraProperties strings.Builder
+ if variables.BoardAvbEnable {
+ extraProperties.WriteString(" avb_enable = True,\n")
+ extraProperties.WriteString(fmt.Sprintf(" avb_add_hashtree_footer_args = %q,\n", qualifiedVariables.BoardAvbAddHashtreeFooterArgs))
+ keypath := qualifiedVariables.BoardAvbKeyPath
+ if keypath != "" {
+ extraProperties.WriteString(fmt.Sprintf(" avb_key = \"//%s:%s\",\n", filepath.Dir(keypath), filepath.Base(keypath)+"_filegroup"))
+ extraProperties.WriteString(fmt.Sprintf(" avb_algorithm = %q,\n", qualifiedVariables.BoardAvbAlgorithm))
+ extraProperties.WriteString(fmt.Sprintf(" avb_rollback_index = %s,\n", qualifiedVariables.BoardAvbRollbackIndex))
+ extraProperties.WriteString(fmt.Sprintf(" avb_rollback_index_location = %s,\n", qualifiedVariables.BoardAvbRollbackIndexLocation))
+ }
+ }
+
targets[platformLabel.pkg] = append(targets[platformLabel.pkg], BazelTarget{
name: "system_image",
packageName: platformLabel.pkg,
@@ -511,11 +581,13 @@
base_staging_dir = "//build/bazel/bazel_sandwich:system_staging_dir",
base_staging_dir_file_list = "//build/bazel/bazel_sandwich:system_staging_dir_file_list",
root_dir = "//build/bazel/bazel_sandwich:root_staging_dir",
+ selinux_file_contexts = "//build/bazel/bazel_sandwich:selinux_file_contexts",
image_properties = """
%s
""",
+%s
type = "system",
-)`, properties.String()),
+)`, properties.String(), extraProperties.String()),
ruleClass: "partition",
loads: []BazelLoad{{
file: "//build/bazel/rules/partitions:partition.bzl",
diff --git a/java/aar.go b/java/aar.go
index c0535a4..44496dc 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -1356,10 +1356,12 @@
if !commonAttrs.Srcs.IsEmpty() {
deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them
} else if !depLabels.Deps.IsEmpty() {
- ctx.MarkBp2buildUnconvertible(
- bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED,
- "Module has direct dependencies but no sources. Bazel will not allow this.")
- return
+ // android_library does not accept deps when there are no srcs because
+ // there is no compilation happening, but it accepts exports.
+ // The non-empty deps here are unnecessary as deps on the android_library
+ // since they aren't being propagated to any dependencies.
+ // So we can drop deps here.
+ deps = bazel.LabelListAttribute{}
}
name := a.Name()
props := AndroidLibraryBazelTargetModuleProperties()
diff --git a/java/base.go b/java/base.go
index fb7b95a..db237da 100644
--- a/java/base.go
+++ b/java/base.go
@@ -432,6 +432,9 @@
srcJarArgs []string
srcJarDeps android.Paths
+ // the source files of this module and all its static dependencies
+ transitiveSrcFiles *android.DepSet[android.Path]
+
// jar file containing implementation classes and resources including static library
// dependencies
implementationAndResourcesJar android.Path
@@ -1694,6 +1697,8 @@
j.linter.lint(ctx)
}
+ j.collectTransitiveSrcFiles(ctx, srcFiles)
+
ctx.CheckbuildFile(outputFile)
j.collectTransitiveAconfigFiles(ctx)
@@ -1708,6 +1713,7 @@
AidlIncludeDirs: j.exportAidlIncludeDirs,
SrcJarArgs: j.srcJarArgs,
SrcJarDeps: j.srcJarDeps,
+ TransitiveSrcFiles: j.transitiveSrcFiles,
ExportedPlugins: j.exportedPluginJars,
ExportedPluginClasses: j.exportedPluginClasses,
ExportedPluginDisableTurbine: j.exportedDisableTurbine,
@@ -2032,6 +2038,21 @@
return j.jacocoReportClassesFile
}
+func (j *Module) collectTransitiveSrcFiles(ctx android.ModuleContext, mine android.Paths) {
+ var fromDeps []*android.DepSet[android.Path]
+ ctx.VisitDirectDeps(func(module android.Module) {
+ tag := ctx.OtherModuleDependencyTag(module)
+ if tag == staticLibTag {
+ depInfo := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
+ if depInfo.TransitiveSrcFiles != nil {
+ fromDeps = append(fromDeps, depInfo.TransitiveSrcFiles)
+ }
+ }
+ })
+
+ j.transitiveSrcFiles = android.NewDepSet(android.POSTORDER, mine, fromDeps)
+}
+
func (j *Module) IsInstallable() bool {
return Bool(j.properties.Installable)
}
diff --git a/java/droidstubs.go b/java/droidstubs.go
index b059c0a..67a55bd 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -540,10 +540,6 @@
// See b/285312164 for more information.
cmd.FlagWithArg("--format-defaults ", "overloaded-method-order=source")
- if ctx.DeviceConfig().HideFlaggedApis() {
- cmd.FlagWithArg("--hide-annotation ", "android.annotation.FlaggedApi")
- }
-
return cmd
}
diff --git a/java/droidstubs_test.go b/java/droidstubs_test.go
index 3c25801..7a04d73 100644
--- a/java/droidstubs_test.go
+++ b/java/droidstubs_test.go
@@ -22,8 +22,6 @@
"testing"
"android/soong/android"
-
- "github.com/google/blueprint/proptools"
)
func TestDroidstubs(t *testing.T) {
@@ -405,35 +403,3 @@
ctx.ModuleForTests("bar", "android_common")
}
-
-func TestDroidstubsHideFlaggedApi(t *testing.T) {
- result := android.GroupFixturePreparers(
- prepareForJavaTest,
- android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
- variables.NextReleaseHideFlaggedApi = proptools.BoolPtr(true)
- variables.ReleaseExposeFlaggedApi = proptools.BoolPtr(false)
- }),
- android.FixtureMergeMockFs(map[string][]byte{
- "a/A.java": nil,
- "a/current.txt": nil,
- "a/removed.txt": nil,
- }),
- ).RunTestWithBp(t, `
- droidstubs {
- name: "foo",
- srcs: ["a/A.java"],
- api_surface: "public",
- check_api: {
- current: {
- api_file: "a/current.txt",
- removed_api_file: "a/removed.txt",
- }
- },
- }
- `)
-
- m := result.ModuleForTests("foo", "android_common")
- manifest := m.Output("metalava.sbox.textproto")
- cmdline := String(android.RuleBuilderSboxProtoForTests(t, manifest).Commands[0].Command)
- android.AssertStringDoesContain(t, "flagged api hide command not included", cmdline, "--hide-annotation android.annotation.FlaggedApi")
-}
diff --git a/java/java.go b/java/java.go
index bf692be..cac49a2 100644
--- a/java/java.go
+++ b/java/java.go
@@ -278,6 +278,9 @@
// SrcJarDeps is a list of paths to depend on when packaging the sources of this module.
SrcJarDeps android.Paths
+ // The source files of this module and all its transitive static dependencies.
+ TransitiveSrcFiles *android.DepSet[android.Path]
+
// ExportedPlugins is a list of paths that should be used as annotation processors for any
// module that depends on this module.
ExportedPlugins android.Paths
diff --git a/java/java_test.go b/java/java_test.go
index b555a95..d51604a 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -2263,6 +2263,28 @@
android.AssertStringDoesContain(t, "Command expected to contain full_api_surface_stub output jar", manifestCommand, "lib1.jar")
}
+func TestTransitiveSrcFiles(t *testing.T) {
+ ctx, _ := testJava(t, `
+ java_library {
+ name: "a",
+ srcs: ["a.java"],
+ }
+ java_library {
+ name: "b",
+ srcs: ["b.java"],
+ }
+ java_library {
+ name: "c",
+ srcs: ["c.java"],
+ libs: ["a"],
+ static_libs: ["b"],
+ }
+ `)
+ c := ctx.ModuleForTests("c", "android_common").Module()
+ transitiveSrcFiles := android.Paths(ctx.ModuleProvider(c, JavaInfoProvider).(JavaInfo).TransitiveSrcFiles.ToList())
+ android.AssertArrayString(t, "unexpected jar deps", []string{"b.java", "c.java"}, transitiveSrcFiles.Strings())
+}
+
func TestTradefedOptions(t *testing.T) {
result := PrepareForTestWithJavaBuildComponents.RunTestWithBp(t, `
java_test_host {
diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go
index ade7395..02a2298 100644
--- a/java/platform_bootclasspath.go
+++ b/java/platform_bootclasspath.go
@@ -57,6 +57,9 @@
// Path to the monolithic hiddenapi-unsupported.csv file.
hiddenAPIMetadataCSV android.OutputPath
+
+ // Path to a srcjar containing all the transitive sources of the bootclasspath.
+ srcjar android.OutputPath
}
type platformBootclasspathProperties struct {
@@ -95,6 +98,8 @@
return android.Paths{b.hiddenAPIIndexCSV}, nil
case "hiddenapi-metadata.csv":
return android.Paths{b.hiddenAPIMetadataCSV}, nil
+ case ".srcjar":
+ return android.Paths{b.srcjar}, nil
}
return nil, fmt.Errorf("unknown tag %s", tag)
@@ -173,6 +178,18 @@
allModules = append(allModules, apexModules...)
b.configuredModules = allModules
+ var transitiveSrcFiles android.Paths
+ for _, module := range allModules {
+ depInfo := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
+ if depInfo.TransitiveSrcFiles != nil {
+ transitiveSrcFiles = append(transitiveSrcFiles, depInfo.TransitiveSrcFiles.ToList()...)
+ }
+ }
+ jarArgs := resourcePathsToJarArgs(transitiveSrcFiles)
+ jarArgs = append(jarArgs, "-srcjar") // Move srcfiles to the right package
+ b.srcjar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-transitive.srcjar").OutputPath
+ TransformResourcesToJar(ctx, b.srcjar, jarArgs, transitiveSrcFiles)
+
// Gather all the fragments dependencies.
b.fragments = gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag)
diff --git a/java/platform_bootclasspath_test.go b/java/platform_bootclasspath_test.go
index ff2da4b..37ff639 100644
--- a/java/platform_bootclasspath_test.go
+++ b/java/platform_bootclasspath_test.go
@@ -81,6 +81,15 @@
RunTest(t)
})
+ fooSourceSrc := "source/a.java"
+ barSrc := "a.java"
+
+ checkSrcJarInputs := func(t *testing.T, result *android.TestResult, name string, expected []string) {
+ t.Helper()
+ srcjar := result.ModuleForTests(name, "android_common").Output(name + "-transitive.srcjar")
+ android.AssertStringDoesContain(t, "srcjar arg", srcjar.Args["jarArgs"], "-srcjar")
+ android.AssertArrayString(t, "srcjar inputs", expected, srcjar.Implicits.Strings())
+ }
t.Run("source", func(t *testing.T) {
result := android.GroupFixturePreparers(
preparer,
@@ -91,6 +100,10 @@
"platform:foo",
"platform:bar",
})
+ checkSrcJarInputs(t, result, "platform-bootclasspath", []string{
+ fooSourceSrc,
+ barSrc,
+ })
})
t.Run("prebuilt", func(t *testing.T) {
@@ -103,6 +116,10 @@
"platform:prebuilt_foo",
"platform:bar",
})
+ checkSrcJarInputs(t, result, "platform-bootclasspath", []string{
+ // TODO(b/151360309): This should also have the srcs for prebuilt_foo
+ barSrc,
+ })
})
t.Run("source+prebuilt - source preferred", func(t *testing.T) {
@@ -116,6 +133,10 @@
"platform:foo",
"platform:bar",
})
+ checkSrcJarInputs(t, result, "platform-bootclasspath", []string{
+ fooSourceSrc,
+ barSrc,
+ })
})
t.Run("source+prebuilt - prebuilt preferred", func(t *testing.T) {
@@ -129,6 +150,10 @@
"platform:prebuilt_foo",
"platform:bar",
})
+ checkSrcJarInputs(t, result, "platform-bootclasspath", []string{
+ // TODO(b/151360309): This should also have the srcs for prebuilt_foo
+ barSrc,
+ })
})
t.Run("dex import", func(t *testing.T) {
@@ -146,6 +171,10 @@
"platform:prebuilt_foo",
"platform:bar",
})
+ checkSrcJarInputs(t, result, "platform-bootclasspath", []string{
+ // TODO(b/151360309): This should also have the srcs for prebuilt_foo
+ barSrc,
+ })
})
}
diff --git a/rust/protobuf.go b/rust/protobuf.go
index c3aa8dc..2982efd 100644
--- a/rust/protobuf.go
+++ b/rust/protobuf.go
@@ -20,6 +20,7 @@
"android/soong/android"
"android/soong/bazel"
+ "android/soong/cc"
"github.com/google/blueprint/proptools"
)
@@ -59,14 +60,18 @@
// Use protobuf version 3.x. This will be deleted once we migrate all current users
// of protobuf off of 2.x.
Use_protobuf3 *bool
+
+ // List of exported include paths containing proto files for dependent rust_protobuf modules.
+ Exported_include_dirs []string
}
type protobufDecorator struct {
*BaseSourceProvider
- Properties ProtobufProperties
- protoNames []string
- grpcNames []string
+ Properties ProtobufProperties
+ protoNames []string
+ additionalCrates []string
+ grpcNames []string
grpcProtoFlags android.ProtoFlags
protoFlags android.ProtoFlags
@@ -184,6 +189,10 @@
// stemFile must be first here as the first path in BaseSourceProvider.OutputFiles is the library entry-point.
proto.BaseSourceProvider.OutputFiles = append(android.Paths{stemFile}, outputs.Paths()...)
+ ctx.SetProvider(cc.FlagExporterInfoProvider, cc.FlagExporterInfo{
+ IncludeDirs: android.PathsForModuleSrc(ctx, proto.Properties.Exported_include_dirs),
+ })
+
// mod_stem.rs is the entry-point for our library modules, so this is what we return.
return stemFile
}
@@ -192,10 +201,16 @@
lines := []string{
"// @Soong generated Source",
}
+
for _, protoName := range proto.protoNames {
lines = append(lines, fmt.Sprintf("pub mod %s;", protoName))
}
+ for _, crate := range proto.additionalCrates {
+ lines = append(lines, fmt.Sprintf("pub use %s::*;", crate))
+
+ }
+
for _, grpcName := range proto.grpcNames {
lines = append(lines, fmt.Sprintf("pub mod %s;", grpcName))
lines = append(lines, fmt.Sprintf("pub mod %s%s;", grpcName, grpcSuffix))
diff --git a/rust/protobuf_test.go b/rust/protobuf_test.go
index b723f3f..9dca029 100644
--- a/rust/protobuf_test.go
+++ b/rust/protobuf_test.go
@@ -118,6 +118,58 @@
}
}
+func TestRustProtobufInclude(t *testing.T) {
+ ctx := testRust(t, `
+ rust_protobuf {
+ name: "librust_proto",
+ protos: ["proto.proto"],
+ crate_name: "rust_proto",
+ source_stem: "proto",
+ use_protobuf3: true,
+ rustlibs: ["librust_exported_proto", "libfoo"],
+ }
+ rust_protobuf {
+ name: "librust_exported_proto",
+ protos: ["proto.proto"],
+ crate_name: "rust_exported_proto",
+ source_stem: "exported_proto",
+ use_protobuf3: true,
+ exported_include_dirs: ["proto"]
+ }
+ rust_library {
+ name: "libfoo",
+ crate_name: "foo",
+ srcs: ["foo.rs"],
+ }
+ `)
+ // Check that librust_exported_proto is added as additional crate to generate source.
+ librust_proto := ctx.ModuleForTests("librust_proto", "android_arm64_armv8-a_source").Module().(*Module).sourceProvider.(*protobufDecorator)
+ if !android.InList("rust_exported_proto", librust_proto.additionalCrates) {
+ t.Errorf("librust_proto should have librust_exported_proto included as an additional crate for generated source, instead got: %#v", librust_proto.additionalCrates)
+ }
+
+ // Make sure the default crates aren't being included.
+ if android.InList("std", librust_proto.additionalCrates) {
+ t.Errorf("librust_proto should not have included libstd as an additional crate for generated source, instead got: %#v", librust_proto.additionalCrates)
+ }
+ if android.InList("protobuf", librust_proto.additionalCrates) {
+ t.Errorf("librust_proto should not have included libprotobuf as an additional crate for generated source, instead got: %#v", librust_proto.additionalCrates)
+ }
+
+ // And make sure that non-protobuf crates aren't getting included either.
+ if android.InList("foo", librust_proto.additionalCrates) {
+ t.Errorf("librust_proto should not have included libfoo as an additional crate for generated source, instead got: %#v", librust_proto.additionalCrates)
+ }
+
+ // Check librust_proto args includes -Iproto
+ librust_proto_rule := ctx.ModuleForTests("librust_proto", "android_arm64_armv8-a_source").Output("proto.rs")
+ cmd := librust_proto_rule.RuleParams.Command
+ if w := "-Iproto"; !strings.Contains(cmd, w) {
+ t.Errorf("expected %q in %q", w, cmd)
+ }
+
+}
+
func TestRustGrpc(t *testing.T) {
ctx := testRust(t, `
rust_protobuf {
diff --git a/rust/rust.go b/rust/rust.go
index 250e398..49a7ff3 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -267,6 +267,15 @@
return false
}
+func (mod *Module) Source() bool {
+ if mod.compiler != nil {
+ if library, ok := mod.compiler.(libraryInterface); ok && mod.sourceProvider != nil {
+ return library.source()
+ }
+ }
+ return false
+}
+
func (mod *Module) RlibStd() bool {
if mod.compiler != nil {
if library, ok := mod.compiler.(libraryInterface); ok && library.rlib() {
@@ -1156,6 +1165,13 @@
return cc.MakeLibName(ctx, c, dep, depName)
}
+func collectIncludedProtos(mod *Module, dep *Module) {
+ if protoMod, ok := mod.sourceProvider.(*protobufDecorator); ok {
+ if _, ok := dep.sourceProvider.(*protobufDecorator); ok {
+ protoMod.additionalCrates = append(protoMod.additionalCrates, dep.CrateName())
+ }
+ }
+}
func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
var depPaths PathDeps
@@ -1268,6 +1284,11 @@
case procMacroDepTag:
directProcMacroDeps = append(directProcMacroDeps, rustDep)
mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
+
+ case sourceDepTag:
+ if _, ok := mod.sourceProvider.(*protobufDecorator); ok {
+ collectIncludedProtos(mod, rustDep)
+ }
}
transitiveAndroidMkSharedLibs = append(transitiveAndroidMkSharedLibs, rustDep.transitiveAndroidMkSharedLibs)
@@ -1308,7 +1329,14 @@
lib.exportLinkDirs(linkDir)
}
}
-
+ if depTag == sourceDepTag {
+ if _, ok := mod.sourceProvider.(*protobufDecorator); ok && mod.Source() {
+ if _, ok := rustDep.sourceProvider.(*protobufDecorator); ok {
+ exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
+ depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
+ }
+ }
+ }
} else if ccDep, ok := dep.(cc.LinkableInterface); ok {
//Handle C dependencies
makeLibName := cc.MakeLibName(ctx, mod, ccDep, depName)
@@ -1572,30 +1600,43 @@
}
// rustlibs
- if deps.Rustlibs != nil && !mod.compiler.Disabled() {
- autoDep := mod.compiler.(autoDeppable).autoDep(ctx)
- for _, lib := range deps.Rustlibs {
- if autoDep.depTag == rlibDepTag {
- // Handle the rlib deptag case
- addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations)
- } else {
- // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however.
- // Check for the existence of the dylib deptag variant. Select it if available,
- // otherwise select the rlib variant.
- autoDepVariations := append(commonDepVariations,
- blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation})
-
- replacementLib := cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Dylibs)
-
- if actx.OtherModuleDependencyVariantExists(autoDepVariations, replacementLib) {
- addDylibDependency(actx, lib, mod, &snapshotInfo, autoDepVariations, autoDep.depTag)
- } else {
- // If there's no dylib dependency available, try to add the rlib dependency instead.
+ if deps.Rustlibs != nil {
+ if !mod.compiler.Disabled() {
+ for _, lib := range deps.Rustlibs {
+ autoDep := mod.compiler.(autoDeppable).autoDep(ctx)
+ if autoDep.depTag == rlibDepTag {
+ // Handle the rlib deptag case
addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations)
+ } else {
+ // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however.
+ // Check for the existence of the dylib deptag variant. Select it if available,
+ // otherwise select the rlib variant.
+ autoDepVariations := append(commonDepVariations,
+ blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation})
+
+ replacementLib := cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Dylibs)
+
+ if actx.OtherModuleDependencyVariantExists(autoDepVariations, replacementLib) {
+ addDylibDependency(actx, lib, mod, &snapshotInfo, autoDepVariations, autoDep.depTag)
+ } else {
+ // If there's no dylib dependency available, try to add the rlib dependency instead.
+ addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations)
+ }
+ }
+ }
+ } else if _, ok := mod.sourceProvider.(*protobufDecorator); ok {
+ for _, lib := range deps.Rustlibs {
+ replacementLib := cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Dylibs)
+ srcProviderVariations := append(commonDepVariations,
+ blueprint.Variation{Mutator: "rust_libraries", Variation: "source"})
+
+ if actx.OtherModuleDependencyVariantExists(srcProviderVariations, replacementLib) {
+ actx.AddVariationDependencies(srcProviderVariations, sourceDepTag, lib)
}
}
}
}
+
// stdlibs
if deps.Stdlibs != nil {
if mod.compiler.stdLinkage(ctx) == RlibLinkage {
diff --git a/rust/toolchain_library.go b/rust/toolchain_library.go
index cb345a4..054104c 100644
--- a/rust/toolchain_library.go
+++ b/rust/toolchain_library.go
@@ -89,7 +89,7 @@
func rustSetToolchainSource(ctx android.LoadHookContext) {
if toolchainLib, ok := ctx.Module().(*Module).compiler.(*toolchainLibraryDecorator); ok {
- prefix := filepath.Join(config.HostPrebuiltTag(ctx.Config()), GetRustPrebuiltVersion(ctx))
+ prefix := filepath.Join("linux-x86", GetRustPrebuiltVersion(ctx))
versionedCrateRoot := path.Join(prefix, android.String(toolchainLib.Properties.Toolchain_crate_root))
versionedSrcs := make([]string, len(toolchainLib.Properties.Toolchain_srcs))
for i, src := range toolchainLib.Properties.Toolchain_srcs {