Merge "Add signing certificate lineage support to soong"
diff --git a/android/module.go b/android/module.go
index e2b7dd3..7e64f0a 100644
--- a/android/module.go
+++ b/android/module.go
@@ -898,6 +898,13 @@
return Bool(m.commonProperties.System_ext_specific)
}
+// RequiresStableAPIs returns true if the module will be installed to a partition that may
+// be updated separately from the system image.
+func (m *ModuleBase) RequiresStableAPIs(ctx BaseModuleContext) bool {
+ return m.SocSpecific() || m.DeviceSpecific() ||
+ (m.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface())
+}
+
func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
partition := "system"
if m.SocSpecific() {
diff --git a/android/prebuilt.go b/android/prebuilt.go
index 82745a4..ee4a13a 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -69,6 +69,10 @@
p.properties.Prefer = proptools.BoolPtr(true)
}
+func (p *Prebuilt) Prefer() bool {
+ return proptools.Bool(p.properties.Prefer)
+}
+
// The below source-related functions and the srcs, src fields are based on an assumption that
// prebuilt modules have a static source property at the moment. Currently there is only one
// exception, android_app_import, which chooses a source file depending on the product's DPI
diff --git a/android/visibility.go b/android/visibility.go
index 2cb0023..5aa7f3f 100644
--- a/android/visibility.go
+++ b/android/visibility.go
@@ -140,7 +140,7 @@
}
func (r packageRule) String() string {
- return fmt.Sprintf("//%s:__pkg__", r.pkg)
+ return fmt.Sprintf("//%s", r.pkg) // :__pkg__ is the default, so skip it.
}
// A subpackagesRule is a visibility rule that matches modules in a specific package (i.e.
@@ -496,6 +496,13 @@
rule := effectiveVisibilityRules(ctx.Config(), qualified)
+ // Modules are implicitly visible to other modules in the same package,
+ // without checking the visibility rules. Here we need to add that visibility
+ // explicitly.
+ if rule != nil && !rule.matches(qualified) {
+ rule = append(rule, packageRule{dir})
+ }
+
return rule.Strings()
}
diff --git a/apex/androidmk.go b/apex/androidmk.go
index 2c5407c..5774809 100644
--- a/apex/androidmk.go
+++ b/apex/androidmk.go
@@ -120,6 +120,9 @@
if len(fi.symlinks) > 0 {
fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
}
+ if len(fi.dataPaths) > 0 {
+ fmt.Println(w, "LOCAL_TEST_DATA :=", strings.Join(cc.AndroidMkDataPaths(fi.dataPaths), " "))
+ }
if fi.module != nil && len(fi.module.NoticeFiles()) > 0 {
fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", strings.Join(fi.module.NoticeFiles().Strings(), " "))
diff --git a/apex/apex.go b/apex/apex.go
index fa71ffa..9525ff2 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -251,7 +251,6 @@
"libtextclassifier_hash_static",
"libtflite_static",
"libutf",
- "libz_current",
"tensorflow_headers",
}
//
@@ -1214,6 +1213,7 @@
module android.Module
// list of symlinks that will be created in installDir that point to this apexFile
symlinks []string
+ dataPaths android.Paths
transitiveDep bool
moduleDir string
@@ -1249,16 +1249,20 @@
return af.builtFile != nil && af.builtFile.String() != ""
}
+func (af *apexFile) apexRelativePath(path string) string {
+ return filepath.Join(af.installDir, path)
+}
+
// Path() returns path of this apex file relative to the APEX root
func (af *apexFile) Path() string {
- return filepath.Join(af.installDir, af.builtFile.Base())
+ return af.apexRelativePath(af.builtFile.Base())
}
// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
func (af *apexFile) SymlinkPaths() []string {
var ret []string
for _, symlink := range af.symlinks {
- ret = append(ret, filepath.Join(af.installDir, symlink))
+ ret = append(ret, af.apexRelativePath(symlink))
}
return ret
}
@@ -1664,6 +1668,7 @@
fileToCopy := cc.OutputFile().Path()
af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
af.symlinks = cc.Symlinks()
+ af.dataPaths = cc.DataPaths()
return af
}
diff --git a/apex/apex_test.go b/apex/apex_test.go
index dc69862..021c3e2 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -180,6 +180,8 @@
"build/make/core/proguard.flags": nil,
"build/make/core/proguard_basic_keeps.flags": nil,
"dummy.txt": nil,
+ "baz": nil,
+ "bar/baz": nil,
}
cc.GatherRequiredFilesForTest(fs)
@@ -3267,6 +3269,14 @@
private_key: "testkey.pem",
}
+ filegroup {
+ name: "fg",
+ srcs: [
+ "baz",
+ "bar/baz"
+ ],
+ }
+
cc_test {
name: "mytest",
gtest: false,
@@ -3276,6 +3286,7 @@
system_shared_libs: [],
static_executable: true,
stl: "none",
+ data: [":fg"],
}
cc_library {
@@ -3308,6 +3319,10 @@
ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
+ //Ensure that test data are copied into apex.
+ ensureContains(t, copyCmds, "image.apex/bin/test/baz")
+ ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz")
+
// Ensure that test deps built with `test_per_src` are copied into apex.
ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
diff --git a/apex/builder.go b/apex/builder.go
index ca24f2c..47ae501 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -350,6 +350,19 @@
symlinkDest := android.PathForModuleOut(ctx, "image"+suffix, symlinkPath).String()
copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest)
}
+ for _, d := range fi.dataPaths {
+ // TODO(eakammer): This is now the third repetition of ~this logic for test paths, refactoring should be possible
+ relPath := d.Rel()
+ dataPath := d.String()
+ if !strings.HasSuffix(dataPath, relPath) {
+ panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath))
+ }
+
+ dataDest := android.PathForModuleOut(ctx, "image"+suffix, fi.apexRelativePath(relPath)).String()
+
+ copyCommands = append(copyCommands, "cp -f "+d.String()+" "+dataDest)
+ implicitInputs = append(implicitInputs, d)
+ }
}
// TODO(jiyong): use RuleBuilder
@@ -406,6 +419,9 @@
pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
executablePaths = append(executablePaths, pathInApex)
+ for _, d := range f.dataPaths {
+ readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.Rel()))
+ }
for _, s := range f.symlinks {
executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
}
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 671adb5..3ce1a89 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -149,7 +149,7 @@
return []android.AndroidMkEntries{entries}
}
-func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, entries *android.AndroidMkEntries) {
+func AndroidMkDataPaths(data android.Paths) []string {
var testFiles []string
for _, d := range data {
rel := d.Rel()
@@ -160,6 +160,11 @@
path = strings.TrimSuffix(path, rel)
testFiles = append(testFiles, path+":"+rel)
}
+ return testFiles
+}
+
+func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, entries *android.AndroidMkEntries) {
+ testFiles := AndroidMkDataPaths(data)
if len(testFiles) > 0 {
entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
entries.AddStrings("LOCAL_TEST_DATA", testFiles...)
diff --git a/cc/cc.go b/cc/cc.go
index 02c4879..fbd5bdf 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1395,6 +1395,15 @@
return ok && test.isAllTestsVariation()
}
+func (c *Module) DataPaths() android.Paths {
+ if p, ok := c.installer.(interface {
+ dataPaths() android.Paths
+ }); ok {
+ return p.dataPaths()
+ }
+ return nil
+}
+
func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
// Returns the name suffix for product and vendor variants. If the VNDK version is not
// "current", it will append the VNDK version to the name suffix.
diff --git a/cc/config/global.go b/cc/config/global.go
index 1dd8a2d..4f3f25e 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -162,7 +162,7 @@
// http://b/131390872
// Automatically initialize any uninitialized stack variables.
- // Prefer zero-init if multiple options are set.
+ // Prefer zero-init if both options are set.
if ctx.Config().IsEnvTrue("AUTO_ZERO_INITIALIZE") {
flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang")
} else if ctx.Config().IsEnvTrue("AUTO_PATTERN_INITIALIZE") {
@@ -170,8 +170,8 @@
} else if ctx.Config().IsEnvTrue("AUTO_UNINITIALIZE") {
flags = append(flags, "-ftrivial-auto-var-init=uninitialized")
} else {
- // Default to zero initialization.
- flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang")
+ // Default to pattern initialization.
+ flags = append(flags, "-ftrivial-auto-var-init=pattern")
}
return strings.Join(flags, " ")
diff --git a/cc/test.go b/cc/test.go
index 95abfbf..2439c94 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -160,6 +160,10 @@
return test.baseCompiler.Properties.Srcs
}
+func (test *testBinary) dataPaths() android.Paths {
+ return test.data
+}
+
func (test *testBinary) isAllTestsVariation() bool {
stem := test.binaryDecorator.Properties.Stem
return stem != nil && *stem == ""
diff --git a/java/app.go b/java/app.go
index 2fea4a0..a81a061 100755
--- a/java/app.go
+++ b/java/app.go
@@ -252,7 +252,10 @@
// If the app builds against an Android SDK use the SDK variant of JNI dependencies
// unless jni_uses_platform_apis is set.
- if (usesSDK && !Bool(a.appProperties.Jni_uses_platform_apis)) ||
+ // Don't require the SDK variant for apps that are shipped on vendor, etc., as they already
+ // have stable APIs through the VNDK.
+ if (usesSDK && !a.RequiresStableAPIs(ctx) &&
+ !Bool(a.appProperties.Jni_uses_platform_apis)) ||
Bool(a.appProperties.Jni_uses_sdk_apis) {
variation = append(variation, blueprint.Variation{Mutator: "sdk", Variation: "sdk"})
}
@@ -289,19 +292,47 @@
}
func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
- if Bool(a.appProperties.Updatable) {
+ if Bool(a.appProperties.Updatable) || a.ApexModuleBase.Updatable() {
if !a.sdkVersion().stable() {
ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.sdkVersion())
}
if String(a.deviceProperties.Min_sdk_version) == "" {
ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.")
}
+ if minSdkVersion, err := a.minSdkVersion().effectiveVersion(ctx); err == nil {
+ a.checkJniLibsSdkVersion(ctx, minSdkVersion)
+ } else {
+ ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
+ }
}
a.checkPlatformAPI(ctx)
a.checkSdkVersions(ctx)
}
+// If an updatable APK sets min_sdk_version, min_sdk_vesion of JNI libs should match with it.
+// This check is enforced for "updatable" APKs (including APK-in-APEX).
+// b/155209650: until min_sdk_version is properly supported, use sdk_version instead.
+// because, sdk_version is overridden by min_sdk_version (if set as smaller)
+// and linkType is checked with dependencies so we can be sure that the whole dependency tree
+// will meet the requirements.
+func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVersion sdkVersion) {
+ // It's enough to check direct JNI deps' sdk_version because all transitive deps from JNI deps are checked in cc.checkLinkType()
+ ctx.VisitDirectDeps(func(m android.Module) {
+ if !IsJniDepTag(ctx.OtherModuleDependencyTag(m)) {
+ return
+ }
+ dep, _ := m.(*cc.Module)
+ jniSdkVersion, err := android.ApiStrToNum(ctx, dep.SdkVersion())
+ if err != nil || int(minSdkVersion) < jniSdkVersion {
+ ctx.OtherModuleErrorf(dep, "sdk_version(%v) is higher than min_sdk_version(%v) of the containing android_app(%v)",
+ dep.SdkVersion(), minSdkVersion, ctx.ModuleName())
+ return
+ }
+
+ })
+}
+
// Returns true if the native libraries should be stored in the APK uncompressed and the
// extractNativeLibs application flag should be set to false in the manifest.
func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool {
@@ -587,7 +618,7 @@
dexJarFile := a.dexBuildActions(ctx)
- jniLibs, certificateDeps := collectAppDeps(ctx, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
+ jniLibs, certificateDeps := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
jniJarFile := a.jniBuildActions(jniLibs, ctx)
if ctx.Failed() {
@@ -629,12 +660,25 @@
a.buildAppDependencyInfo(ctx)
}
-func collectAppDeps(ctx android.ModuleContext, shouldCollectRecursiveNativeDeps bool,
+type appDepsInterface interface {
+ sdkVersion() sdkSpec
+ minSdkVersion() sdkSpec
+ RequiresStableAPIs(ctx android.BaseModuleContext) bool
+}
+
+func collectAppDeps(ctx android.ModuleContext, app appDepsInterface,
+ shouldCollectRecursiveNativeDeps bool,
checkNativeSdkVersion bool) ([]jniLib, []Certificate) {
+
var jniLibs []jniLib
var certificates []Certificate
seenModulePaths := make(map[string]bool)
+ if checkNativeSdkVersion {
+ checkNativeSdkVersion = app.sdkVersion().specified() &&
+ app.sdkVersion().kind != sdkCorePlatform && !app.RequiresStableAPIs(ctx)
+ }
+
ctx.WalkDeps(func(module android.Module, parent android.Module) bool {
otherName := ctx.OtherModuleName(module)
tag := ctx.OtherModuleDependencyTag(module)
@@ -652,16 +696,9 @@
}
seenModulePaths[path.String()] = true
- if checkNativeSdkVersion {
- if app, ok := ctx.Module().(interface{ sdkVersion() sdkSpec }); ok {
- if app.sdkVersion().specified() &&
- app.sdkVersion().kind != sdkCorePlatform &&
- dep.SdkVersion() == "" {
- ctx.PropertyErrorf("jni_libs",
- "JNI dependency %q uses platform APIs, but this module does not",
- otherName)
- }
- }
+ if checkNativeSdkVersion && dep.SdkVersion() == "" {
+ ctx.PropertyErrorf("jni_libs", "JNI dependency %q uses platform APIs, but this module does not",
+ otherName)
}
if lib.Valid() {
@@ -1251,7 +1288,7 @@
ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set")
}
- _, certificates := collectAppDeps(ctx, false, false)
+ _, certificates := collectAppDeps(ctx, a, false, false)
// TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK
// TODO: LOCAL_PACKAGE_SPLITS
@@ -1377,6 +1414,14 @@
return false
}
+func (a *AndroidAppImport) sdkVersion() sdkSpec {
+ return sdkSpecFrom("")
+}
+
+func (a *AndroidAppImport) minSdkVersion() sdkSpec {
+ return sdkSpecFrom("")
+}
+
func createVariantGroupType(variants []string, variantGroupName string) reflect.Type {
props := reflect.TypeOf((*AndroidAppImportProperties)(nil))
@@ -1562,7 +1607,7 @@
r.aapt.buildActions(ctx, r, aaptLinkFlags...)
// Sign the built package
- _, certificates := collectAppDeps(ctx, false, false)
+ _, certificates := collectAppDeps(ctx, r, false, false)
certificates = processMainCert(r.ModuleBase, String(r.properties.Certificate), certificates, ctx)
signed := android.PathForModuleOut(ctx, "signed", r.Name()+".apk")
SignAppPackage(ctx, signed, r.aapt.exportPackage, certificates, nil)
diff --git a/java/app_test.go b/java/app_test.go
index 1067c27..45dab62 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -385,6 +385,127 @@
}
}
+func TestUpdatableApps_JniLibsShouldShouldSupportMinSdkVersion(t *testing.T) {
+ testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
+ android_app {
+ name: "foo",
+ srcs: ["a.java"],
+ updatable: true,
+ sdk_version: "current",
+ min_sdk_version: "current",
+ jni_libs: ["libjni"],
+ }
+
+ cc_library {
+ name: "libjni",
+ stl: "none",
+ system_shared_libs: [],
+ sdk_version: "current",
+ }
+ `)
+}
+
+func TestUpdatableApps_JniLibShouldBeBuiltAgainstMinSdkVersion(t *testing.T) {
+ bp := cc.GatherRequiredDepsForTest(android.Android) + `
+ android_app {
+ name: "foo",
+ srcs: ["a.java"],
+ updatable: true,
+ sdk_version: "current",
+ min_sdk_version: "29",
+ jni_libs: ["libjni"],
+ }
+
+ cc_library {
+ name: "libjni",
+ stl: "none",
+ system_shared_libs: [],
+ sdk_version: "29",
+ }
+
+ ndk_prebuilt_object {
+ name: "ndk_crtbegin_so.29",
+ sdk_version: "29",
+ }
+
+ ndk_prebuilt_object {
+ name: "ndk_crtend_so.29",
+ sdk_version: "29",
+ }
+ `
+ fs := map[string][]byte{
+ "prebuilts/ndk/current/platforms/android-29/arch-arm64/usr/lib/crtbegin_so.o": nil,
+ "prebuilts/ndk/current/platforms/android-29/arch-arm64/usr/lib/crtend_so.o": nil,
+ "prebuilts/ndk/current/platforms/android-29/arch-arm/usr/lib/crtbegin_so.o": nil,
+ "prebuilts/ndk/current/platforms/android-29/arch-arm/usr/lib/crtend_so.o": nil,
+ }
+
+ ctx, _ := testJavaWithConfig(t, testConfig(nil, bp, fs))
+
+ inputs := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared").Description("link").Implicits
+ var crtbeginFound, crtendFound bool
+ for _, input := range inputs {
+ switch input.String() {
+ case "prebuilts/ndk/current/platforms/android-29/arch-arm64/usr/lib/crtbegin_so.o":
+ crtbeginFound = true
+ case "prebuilts/ndk/current/platforms/android-29/arch-arm64/usr/lib/crtend_so.o":
+ crtendFound = true
+ }
+ }
+ if !crtbeginFound || !crtendFound {
+ t.Error("should link with ndk_crtbegin_so.29 and ndk_crtend_so.29")
+ }
+}
+
+func TestUpdatableApps_ErrorIfJniLibDoesntSupportMinSdkVersion(t *testing.T) {
+ bp := cc.GatherRequiredDepsForTest(android.Android) + `
+ android_app {
+ name: "foo",
+ srcs: ["a.java"],
+ updatable: true,
+ sdk_version: "current",
+ min_sdk_version: "29", // this APK should support 29
+ jni_libs: ["libjni"],
+ }
+
+ cc_library {
+ name: "libjni",
+ stl: "none",
+ sdk_version: "current",
+ }
+ `
+ testJavaError(t, `"libjni" .*: sdk_version\(current\) is higher than min_sdk_version\(29\)`, bp)
+}
+
+func TestUpdatableApps_ErrorIfDepSdkVersionIsHigher(t *testing.T) {
+ bp := cc.GatherRequiredDepsForTest(android.Android) + `
+ android_app {
+ name: "foo",
+ srcs: ["a.java"],
+ updatable: true,
+ sdk_version: "current",
+ min_sdk_version: "29", // this APK should support 29
+ jni_libs: ["libjni"],
+ }
+
+ cc_library {
+ name: "libjni",
+ stl: "none",
+ shared_libs: ["libbar"],
+ system_shared_libs: [],
+ sdk_version: "27",
+ }
+
+ cc_library {
+ name: "libbar",
+ stl: "none",
+ system_shared_libs: [],
+ sdk_version: "current",
+ }
+ `
+ testJavaError(t, `"libjni" .*: links "libbar" built against newer API version "current"`, bp)
+}
+
func TestResourceDirs(t *testing.T) {
testCases := []struct {
name string
@@ -1144,25 +1265,44 @@
platform_apis: true,
jni_uses_sdk_apis: true,
}
+
+ cc_library {
+ name: "libvendorjni",
+ system_shared_libs: [],
+ stl: "none",
+ vendor: true,
+ }
+
+ android_test {
+ name: "app_vendor",
+ jni_libs: ["libvendorjni"],
+ sdk_version: "current",
+ vendor: true,
+ }
`)
testCases := []struct {
- name string
- sdkJNI bool
+ name string
+ sdkJNI bool
+ vendorJNI bool
}{
- {"app_platform", false},
- {"app_sdk", true},
- {"app_force_platform", false},
- {"app_force_sdk", true},
+ {name: "app_platform"},
+ {name: "app_sdk", sdkJNI: true},
+ {name: "app_force_platform"},
+ {name: "app_force_sdk", sdkJNI: true},
+ {name: "app_vendor", vendorJNI: true},
}
+ platformJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_shared").
+ Output("libjni.so").Output.String()
+ sdkJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared").
+ Output("libjni.so").Output.String()
+ vendorJNI := ctx.ModuleForTests("libvendorjni", "android_arm64_armv8-a_shared").
+ Output("libvendorjni.so").Output.String()
+
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
app := ctx.ModuleForTests(test.name, "android_common")
- platformJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_shared").
- Output("libjni.so").Output.String()
- sdkJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared").
- Output("libjni.so").Output.String()
jniLibZip := app.MaybeOutput("jnilibs.zip")
if len(jniLibZip.Implicits) != 1 {
@@ -1174,6 +1314,10 @@
if gotJNI != sdkJNI {
t.Errorf("expected SDK JNI library %q, got %q", sdkJNI, gotJNI)
}
+ } else if test.vendorJNI {
+ if gotJNI != vendorJNI {
+ t.Errorf("expected platform JNI library %q, got %q", vendorJNI, gotJNI)
+ }
} else {
if gotJNI != platformJNI {
t.Errorf("expected platform JNI library %q, got %q", platformJNI, gotJNI)
diff --git a/java/java.go b/java/java.go
index de38b26..17b963f 100644
--- a/java/java.go
+++ b/java/java.go
@@ -95,8 +95,7 @@
}
func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
- if j.SocSpecific() || j.DeviceSpecific() ||
- (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
+ if j.RequiresStableAPIs(ctx) {
if sc, ok := ctx.Module().(sdkContext); ok {
if !sc.sdkVersion().specified() {
ctx.PropertyErrorf("sdk_version",
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 2650ab3..7e81c1e 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -92,6 +92,9 @@
// The name of the field in the dynamically created structure.
fieldName string
+ // The name of the property in the java_sdk_library_import
+ propertyName string
+
// The tag to use to depend on the stubs library module.
stubsTag scopeDependencyTag
@@ -142,7 +145,8 @@
// Initialize a scope, creating and adding appropriate dependency tags
func initApiScope(scope *apiScope) *apiScope {
name := scope.name
- scope.fieldName = proptools.FieldNameForProperty(name)
+ scope.propertyName = strings.ReplaceAll(name, "-", "_")
+ scope.fieldName = proptools.FieldNameForProperty(scope.propertyName)
scope.stubsTag = scopeDependencyTag{
name: name + "-stubs",
apiScope: scope,
@@ -253,7 +257,7 @@
unstable: true,
})
apiScopeModuleLib = initApiScope(&apiScope{
- name: "module_lib",
+ name: "module-lib",
extends: apiScopeSystem,
// Module_lib scope is disabled by default in legacy mode.
//
@@ -1448,22 +1452,23 @@
} else if module.SystemExtSpecific() {
props.System_ext_specific = proptools.BoolPtr(true)
}
- // If the build should use prebuilt sdks then set prefer to true on the stubs library.
- // That will cause the prebuilt version of the stubs to override the source version.
- if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
- props.Prefer = proptools.BoolPtr(true)
- }
+ // The imports are preferred if the java_sdk_library_import is preferred.
+ props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
mctx.CreateModule(ImportFactory, &props)
}
func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
props := struct {
- Name *string
- Srcs []string
+ Name *string
+ Srcs []string
+ Prefer *bool
}{}
props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope))
props.Srcs = scopeProperties.Stub_srcs
mctx.CreateModule(PrebuiltStubsSourcesFactory, &props)
+
+ // The stubs source is preferred if the java_sdk_library_import is preferred.
+ props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
}
func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
@@ -1667,6 +1672,9 @@
// The Java stubs source files.
Stub_srcs []string
+
+ // The naming scheme.
+ Naming_scheme *string
}
type scopeProperties struct {
@@ -1696,12 +1704,17 @@
}
s.Libs = sdk.properties.Libs
+ s.Naming_scheme = sdk.commonProperties.Naming_scheme
}
func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
+ if s.Naming_scheme != nil {
+ propertySet.AddProperty("naming_scheme", proptools.String(s.Naming_scheme))
+ }
+
for _, apiScope := range allApiScopes {
if properties, ok := s.Scopes[apiScope]; ok {
- scopeSet := propertySet.AddPropertySet(apiScope.name)
+ scopeSet := propertySet.AddPropertySet(apiScope.propertyName)
scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name)
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index 436fd9d..bbd6384 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -1328,10 +1328,10 @@
sdk_version: "system_current",
},
module_lib: {
- jars: ["sdk_library/module_lib/myjavalib-stubs.jar"],
- stub_srcs: ["sdk_library/module_lib/myjavalib_stub_sources"],
- current_api: "sdk_library/module_lib/myjavalib.txt",
- removed_api: "sdk_library/module_lib/myjavalib-removed.txt",
+ jars: ["sdk_library/module-lib/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/module-lib/myjavalib_stub_sources"],
+ current_api: "sdk_library/module-lib/myjavalib.txt",
+ removed_api: "sdk_library/module-lib/myjavalib-removed.txt",
sdk_version: "module_current",
},
}
@@ -1355,10 +1355,10 @@
sdk_version: "system_current",
},
module_lib: {
- jars: ["sdk_library/module_lib/myjavalib-stubs.jar"],
- stub_srcs: ["sdk_library/module_lib/myjavalib_stub_sources"],
- current_api: "sdk_library/module_lib/myjavalib.txt",
- removed_api: "sdk_library/module_lib/myjavalib-removed.txt",
+ jars: ["sdk_library/module-lib/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/module-lib/myjavalib_stub_sources"],
+ current_api: "sdk_library/module-lib/myjavalib.txt",
+ removed_api: "sdk_library/module-lib/myjavalib-removed.txt",
sdk_version: "module_current",
},
}
@@ -1375,14 +1375,81 @@
.intermediates/myjavalib.stubs.system/android_common/javac/myjavalib.stubs.system.jar -> sdk_library/system/myjavalib-stubs.jar
.intermediates/myjavalib.stubs.source.system/android_common/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib.txt
.intermediates/myjavalib.stubs.source.system/android_common/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib-removed.txt
-.intermediates/myjavalib.stubs.module_lib/android_common/javac/myjavalib.stubs.module_lib.jar -> sdk_library/module_lib/myjavalib-stubs.jar
-.intermediates/myjavalib.api.module_lib/android_common/myjavalib.api.module_lib_api.txt -> sdk_library/module_lib/myjavalib.txt
-.intermediates/myjavalib.api.module_lib/android_common/myjavalib.api.module_lib_api.txt -> sdk_library/module_lib/myjavalib-removed.txt
+.intermediates/myjavalib.stubs.module_lib/android_common/javac/myjavalib.stubs.module_lib.jar -> sdk_library/module-lib/myjavalib-stubs.jar
+.intermediates/myjavalib.api.module_lib/android_common/myjavalib.api.module_lib_api.txt -> sdk_library/module-lib/myjavalib.txt
+.intermediates/myjavalib.api.module_lib/android_common/myjavalib.api.module_lib_api.txt -> sdk_library/module-lib/myjavalib-removed.txt
`),
checkMergeZips(
".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip",
- ".intermediates/mysdk/common_os/tmp/sdk_library/module_lib/myjavalib_stub_sources.zip",
+ ".intermediates/mysdk/common_os/tmp/sdk_library/module-lib/myjavalib_stub_sources.zip",
+ ),
+ )
+}
+
+func TestSnapshotWithJavaSdkLibrary_NamingScheme(t *testing.T) {
+ result := testSdkWithJava(t, `
+ sdk {
+ name: "mysdk",
+ java_sdk_libs: ["myjavalib"],
+ }
+
+ java_sdk_library {
+ name: "myjavalib",
+ apex_available: ["//apex_available:anyapex"],
+ srcs: ["Test.java"],
+ sdk_version: "current",
+ naming_scheme: "framework-modules",
+ public: {
+ enabled: true,
+ },
+ }
+ `)
+
+ result.CheckSnapshot("mysdk", "",
+ checkAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_sdk_library_import {
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
+ apex_available: ["//apex_available:anyapex"],
+ naming_scheme: "framework-modules",
+ public: {
+ jars: ["sdk_library/public/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
+ current_api: "sdk_library/public/myjavalib.txt",
+ removed_api: "sdk_library/public/myjavalib-removed.txt",
+ sdk_version: "current",
+ },
+}
+
+java_sdk_library_import {
+ name: "myjavalib",
+ prefer: false,
+ apex_available: ["//apex_available:anyapex"],
+ naming_scheme: "framework-modules",
+ public: {
+ jars: ["sdk_library/public/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
+ current_api: "sdk_library/public/myjavalib.txt",
+ removed_api: "sdk_library/public/myjavalib-removed.txt",
+ sdk_version: "current",
+ },
+}
+
+sdk_snapshot {
+ name: "mysdk@current",
+ java_sdk_libs: ["mysdk_myjavalib@current"],
+}
+`),
+ checkAllCopyRules(`
+.intermediates/myjavalib-stubs-publicapi/android_common/javac/myjavalib-stubs-publicapi.jar -> sdk_library/public/myjavalib-stubs.jar
+.intermediates/myjavalib-stubs-srcs-publicapi/android_common/myjavalib-stubs-srcs-publicapi_api.txt -> sdk_library/public/myjavalib.txt
+.intermediates/myjavalib-stubs-srcs-publicapi/android_common/myjavalib-stubs-srcs-publicapi_api.txt -> sdk_library/public/myjavalib-removed.txt
+`),
+ checkMergeZips(
+ ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
),
)
}
diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go
index ae1a492..9bbf410 100644
--- a/sdk/sdk_test.go
+++ b/sdk/sdk_test.go
@@ -155,14 +155,20 @@
java_import {
name: "mysdk_myjavalib@current",
sdk_member_name: "myjavalib",
- visibility: ["//other/foo:__pkg__"],
+ visibility: [
+ "//other/foo",
+ "//package",
+ ],
jars: ["java/myjavalib.jar"],
}
java_import {
name: "myjavalib",
prefer: false,
- visibility: ["//other/foo:__pkg__"],
+ visibility: [
+ "//other/foo",
+ "//package",
+ ],
jars: ["java/myjavalib.jar"],
}
@@ -183,21 +189,27 @@
java_import {
name: "mysdk_mydefaultedjavalib@current",
sdk_member_name: "mydefaultedjavalib",
- visibility: ["//other/bar:__pkg__"],
+ visibility: [
+ "//other/bar",
+ "//package",
+ ],
jars: ["java/mydefaultedjavalib.jar"],
}
java_import {
name: "mydefaultedjavalib",
prefer: false,
- visibility: ["//other/bar:__pkg__"],
+ visibility: [
+ "//other/bar",
+ "//package",
+ ],
jars: ["java/mydefaultedjavalib.jar"],
}
sdk_snapshot {
name: "mysdk@current",
visibility: [
- "//other/foo:__pkg__",
+ "//other/foo",
"//package:__subpackages__",
],
java_header_libs: [