summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/Android.bp67
-rw-r--r--java/aar.go18
-rwxr-xr-xjava/app.go118
-rw-r--r--java/app_test.go13
-rw-r--r--java/config/Android.bp15
-rw-r--r--java/config/config.go5
-rw-r--r--java/device_host_converter.go10
-rw-r--r--java/dexpreopt.go14
-rw-r--r--java/dexpreopt_bootjars.go24
-rw-r--r--java/dexpreopt_bootjars_test.go2
-rw-r--r--java/droiddoc.go38
-rw-r--r--java/hiddenapi_singleton.go4
-rw-r--r--java/java.go221
-rw-r--r--java/java_test.go112
-rw-r--r--java/lint.go355
-rw-r--r--java/lint_defaults.txt78
-rw-r--r--java/plugin.go6
-rw-r--r--java/robolectric.go4
-rw-r--r--java/sdk.go49
-rw-r--r--java/sdk_library.go246
-rw-r--r--java/sdk_test.go8
-rw-r--r--java/testing.go86
22 files changed, 1153 insertions, 340 deletions
diff --git a/java/Android.bp b/java/Android.bp
new file mode 100644
index 000000000..1fda7f71d
--- /dev/null
+++ b/java/Android.bp
@@ -0,0 +1,67 @@
+bootstrap_go_package {
+ name: "soong-java",
+ pkgPath: "android/soong/java",
+ deps: [
+ "blueprint",
+ "blueprint-pathtools",
+ "soong",
+ "soong-android",
+ "soong-cc",
+ "soong-dexpreopt",
+ "soong-genrule",
+ "soong-java-config",
+ "soong-remoteexec",
+ "soong-tradefed",
+ ],
+ srcs: [
+ "aapt2.go",
+ "aar.go",
+ "android_manifest.go",
+ "android_resources.go",
+ "androidmk.go",
+ "app_builder.go",
+ "app.go",
+ "builder.go",
+ "device_host_converter.go",
+ "dex.go",
+ "dexpreopt.go",
+ "dexpreopt_bootjars.go",
+ "dexpreopt_config.go",
+ "droiddoc.go",
+ "gen.go",
+ "genrule.go",
+ "hiddenapi.go",
+ "hiddenapi_singleton.go",
+ "jacoco.go",
+ "java.go",
+ "jdeps.go",
+ "java_resources.go",
+ "kotlin.go",
+ "lint.go",
+ "platform_compat_config.go",
+ "plugin.go",
+ "prebuilt_apis.go",
+ "proto.go",
+ "robolectric.go",
+ "sdk.go",
+ "sdk_library.go",
+ "support_libraries.go",
+ "sysprop.go",
+ "system_modules.go",
+ "testing.go",
+ "tradefed.go",
+ ],
+ testSrcs: [
+ "androidmk_test.go",
+ "app_test.go",
+ "device_host_converter_test.go",
+ "dexpreopt_test.go",
+ "dexpreopt_bootjars_test.go",
+ "java_test.go",
+ "jdeps_test.go",
+ "kotlin_test.go",
+ "plugin_test.go",
+ "sdk_test.go",
+ ],
+ pluginFor: ["soong_build"],
+}
diff --git a/java/aar.go b/java/aar.go
index c8daf835b..074ead470 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -102,6 +102,7 @@ type aapt struct {
sdkLibraries []string
hasNoCode bool
LoggingParent string
+ resourceFiles android.Paths
splitNames []string
splits []split
@@ -275,6 +276,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
var compiledResDirs []android.Paths
for _, dir := range resDirs {
+ a.resourceFiles = append(a.resourceFiles, dir.files...)
compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths())
}
@@ -473,6 +475,10 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
// apps manifests are handled by aapt, don't let Module see them
a.properties.Manifest = nil
+ a.linter.mergedManifest = a.aapt.mergedManifestFile
+ a.linter.manifest = a.aapt.manifestPath
+ a.linter.resources = a.aapt.resourceFiles
+
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles,
a.proguardOptionsFile)
@@ -506,15 +512,13 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
func AndroidLibraryFactory() android.Module {
module := &AndroidLibrary{}
+ module.Module.addHostAndDeviceProperties()
module.AddProperties(
- &module.Module.properties,
- &module.Module.deviceProperties,
- &module.Module.dexpreoptProperties,
- &module.Module.protoProperties,
&module.aaptProperties,
&module.androidLibraryProperties)
module.androidLibraryProperties.BuildAAR = true
+ module.Module.linter.library = true
android.InitApexModule(module)
InitJavaModule(module, android.DeviceSupported)
@@ -730,7 +734,11 @@ func (a *AARImport) ImplementationAndResourcesJars() android.Paths {
return android.Paths{a.classpathFile}
}
-func (a *AARImport) DexJar() android.Path {
+func (a *AARImport) DexJarBuildPath() android.Path {
+ return nil
+}
+
+func (a *AARImport) DexJarInstallPath() android.Path {
return nil
}
diff --git a/java/app.go b/java/app.go
index a45ab6f99..4bb292ddf 100755
--- a/java/app.go
+++ b/java/app.go
@@ -28,6 +28,7 @@ import (
"android/soong/android"
"android/soong/cc"
+ "android/soong/dexpreopt"
"android/soong/tradefed"
)
@@ -96,6 +97,14 @@ func (as *AndroidAppSet) Privileged() bool {
return Bool(as.properties.Privileged)
}
+func (as *AndroidAppSet) OutputFile() android.Path {
+ return as.packedOutput
+}
+
+func (as *AndroidAppSet) MasterFile() string {
+ return as.masterFile
+}
+
var TargetCpuAbi = map[string]string{
"arm": "ARMEABI_V7A",
"arm64": "ARM64_V8A",
@@ -120,11 +129,11 @@ func SupportedAbis(ctx android.ModuleContext) []string {
}
func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- as.packedOutput = android.PathForModuleOut(ctx, "extracted.zip")
+ as.packedOutput = android.PathForModuleOut(ctx, ctx.ModuleName()+".zip")
// We are assuming here that the master file in the APK
// set has `.apk` suffix. If it doesn't the build will fail.
// APK sets containing APEX files are handled elsewhere.
- as.masterFile = ctx.ModuleName() + ".apk"
+ as.masterFile = as.BaseModuleName() + ".apk"
screenDensities := "all"
if dpis := ctx.Config().ProductAAPTPrebuiltDPI(); len(dpis) > 0 {
screenDensities = strings.ToUpper(strings.Join(dpis, ","))
@@ -145,26 +154,17 @@ func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext)
"stem": ctx.ModuleName(),
},
})
- // TODO(asmundak): add this (it's wrong now, will cause copying extracted.zip)
- /*
- var installDir android.InstallPath
- if Bool(as.properties.Privileged) {
- installDir = android.PathForModuleInstall(ctx, "priv-app", as.BaseModuleName())
- } else if ctx.InstallInTestcases() {
- installDir = android.PathForModuleInstall(ctx, as.BaseModuleName(), ctx.DeviceConfig().DeviceArch())
- } else {
- installDir = android.PathForModuleInstall(ctx, "app", as.BaseModuleName())
- }
- ctx.InstallFile(installDir, as.masterFile", as.packedOutput)
- */
}
// android_app_set extracts a set of APKs based on the target device
// configuration and installs this set as "split APKs".
-// The set will always contain `base-master.apk` and every APK built
-// to the target device. All density-specific APK will be included, too,
-// unless PRODUCT_APPT_PREBUILT_DPI is defined (should contain comma-sepearated
-// list of density names (LDPI, MDPI, HDPI, etc.)
+// The extracted set always contains 'master' APK whose name is
+// _module_name_.apk and every split APK matching target device.
+// The extraction of the density-specific splits depends on
+// PRODUCT_AAPT_PREBUILT_DPI variable. If present (its value should
+// be a list density names: LDPI, MDPI, HDPI, etc.), only listed
+// splits will be extracted. Otherwise all density-specific splits
+// will be extracted.
func AndroidApkSetFactory() android.Module {
module := &AndroidAppSet{}
module.AddProperties(&module.properties)
@@ -335,7 +335,7 @@ type Certificate struct {
presigned bool
}
-var presignedCertificate = Certificate{presigned: true}
+var PresignedCertificate = Certificate{presigned: true}
func (c Certificate) AndroidMkString() string {
if c.presigned {
@@ -445,8 +445,11 @@ func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVer
return
}
dep, _ := m.(*cc.Module)
- jniSdkVersion, err := android.ApiStrToNum(ctx, dep.SdkVersion())
- if err != nil || int(minSdkVersion) < jniSdkVersion {
+ // The domain of cc.sdk_version is "current" and <number>
+ // We can rely on sdkSpec to convert it to <number> so that "current" is handled
+ // properly regardless of sdk finalization.
+ jniSdkVersion, err := sdkSpecFrom(dep.SdkVersion()).effectiveVersion(ctx)
+ if err != nil || 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
@@ -688,9 +691,9 @@ func processMainCert(m android.ModuleBase, certPropValue string, certificates []
systemCertPath := ctx.Config().DefaultAppCertificateDir(ctx).String()
if strings.HasPrefix(certPath, systemCertPath) {
enforceSystemCert := ctx.Config().EnforceSystemCertificate()
- whitelist := ctx.Config().EnforceSystemCertificateWhitelist()
+ allowed := ctx.Config().EnforceSystemCertificateAllowList()
- if enforceSystemCert && !inList(m.Name(), whitelist) {
+ if enforceSystemCert && !inList(m.Name(), allowed) {
ctx.PropertyErrorf("certificate", "The module in product partition cannot be signed with certificate in system.")
}
}
@@ -739,6 +742,10 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
a.proguardBuildActions(ctx)
+ a.linter.mergedManifest = a.aapt.mergedManifestFile
+ a.linter.manifest = a.aapt.manifestPath
+ a.linter.resources = a.aapt.resourceFiles
+
dexJarFile := a.dexBuildActions(ctx)
jniLibs, certificateDeps := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
@@ -960,20 +967,13 @@ func AndroidAppFactory() android.Module {
module.Module.properties.Instrument = true
module.Module.properties.Installable = proptools.BoolPtr(true)
+ module.addHostAndDeviceProperties()
module.AddProperties(
- &module.Module.properties,
- &module.Module.deviceProperties,
- &module.Module.dexpreoptProperties,
- &module.Module.protoProperties,
&module.aaptProperties,
&module.appProperties,
&module.overridableAppProperties,
&module.usesLibrary.usesLibraryProperties)
- module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
- return class == android.Device && ctx.Config().DevicePrefer32BitApps()
- })
-
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
android.InitDefaultableModule(module)
android.InitOverridableModule(module, &module.appProperties.Overrides)
@@ -1083,12 +1083,10 @@ func AndroidTestFactory() android.Module {
module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
module.appProperties.AlwaysPackageNativeLibs = true
module.Module.dexpreopter.isTest = true
+ module.Module.linter.test = true
+ module.addHostAndDeviceProperties()
module.AddProperties(
- &module.Module.properties,
- &module.Module.deviceProperties,
- &module.Module.dexpreoptProperties,
- &module.Module.protoProperties,
&module.aaptProperties,
&module.appProperties,
&module.appTestProperties,
@@ -1135,12 +1133,10 @@ func AndroidTestHelperAppFactory() android.Module {
module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
module.appProperties.AlwaysPackageNativeLibs = true
module.Module.dexpreopter.isTest = true
+ module.Module.linter.test = true
+ module.addHostAndDeviceProperties()
module.AddProperties(
- &module.Module.properties,
- &module.Module.deviceProperties,
- &module.Module.dexpreoptProperties,
- &module.Module.protoProperties,
&module.aaptProperties,
&module.appProperties,
&module.appTestHelperAppProperties,
@@ -1186,7 +1182,7 @@ type OverrideAndroidApp struct {
android.OverrideModuleBase
}
-func (i *OverrideAndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+func (i *OverrideAndroidApp) GenerateAndroidBuildActions(_ android.ModuleContext) {
// All the overrides happen in the base module.
// TODO(jungjw): Check the base module type.
}
@@ -1207,7 +1203,7 @@ type OverrideAndroidTest struct {
android.OverrideModuleBase
}
-func (i *OverrideAndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+func (i *OverrideAndroidTest) GenerateAndroidBuildActions(_ android.ModuleContext) {
// All the overrides happen in the base module.
// TODO(jungjw): Check the base module type.
}
@@ -1229,7 +1225,7 @@ type OverrideRuntimeResourceOverlay struct {
android.OverrideModuleBase
}
-func (i *OverrideRuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+func (i *OverrideRuntimeResourceOverlay) GenerateAndroidBuildActions(_ android.ModuleContext) {
// All the overrides happen in the base module.
// TODO(jungjw): Check the base module type.
}
@@ -1474,7 +1470,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext
// Sign or align the package if package has not been preprocessed
if a.preprocessed {
a.outputFile = srcApk
- a.certificate = presignedCertificate
+ a.certificate = PresignedCertificate
} else if !Bool(a.properties.Presigned) {
// If the certificate property is empty at this point, default_dev_cert must be set to true.
// Which makes processMainCert's behavior for the empty cert string WAI.
@@ -1494,7 +1490,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext
alignedApk := android.PathForModuleOut(ctx, "zip-aligned", apkFilename)
TransformZipAlign(ctx, alignedApk, dexOutput)
a.outputFile = alignedApk
- a.certificate = presignedCertificate
+ a.certificate = PresignedCertificate
}
// TODO: Optionally compress the output apk.
@@ -1552,7 +1548,7 @@ func (a *AndroidAppImport) Privileged() bool {
return Bool(a.properties.Privileged)
}
-func (a *AndroidAppImport) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
+func (a *AndroidAppImport) DepIsInSameApex(_ android.BaseModuleContext, _ android.Module) bool {
// android_app_import might have extra dependencies via uses_libs property.
// Don't track the dependency as we don't automatically add those libraries
// to the classpath. It should be explicitly added to java_libs property of APEX
@@ -1875,24 +1871,36 @@ func (u *usesLibrary) presentOptionalUsesLibs(ctx android.BaseModuleContext) []s
return optionalUsesLibs
}
-// usesLibraryPaths returns a map of module names of shared library dependencies to the paths to their dex jars.
-func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) map[string]android.Path {
- usesLibPaths := make(map[string]android.Path)
+// usesLibraryPaths returns a map of module names of shared library dependencies to the paths
+// to their dex jars on host and on device.
+func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) dexpreopt.LibraryPaths {
+ usesLibPaths := make(dexpreopt.LibraryPaths)
if !ctx.Config().UnbundledBuild() {
ctx.VisitDirectDepsWithTag(usesLibTag, func(m android.Module) {
+ dep := ctx.OtherModuleName(m)
if lib, ok := m.(Dependency); ok {
- if dexJar := lib.DexJar(); dexJar != nil {
- usesLibPaths[ctx.OtherModuleName(m)] = dexJar
+ buildPath := lib.DexJarBuildPath()
+ if buildPath == nil {
+ ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must"+
+ " produce a dex jar, does it have installable: true?", dep)
+ return
+ }
+
+ var devicePath string
+ installPath := lib.DexJarInstallPath()
+ if installPath == nil {
+ devicePath = filepath.Join("/system/framework", dep+".jar")
} else {
- ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must produce a dex jar, does it have installable: true?",
- ctx.OtherModuleName(m))
+ devicePath = android.InstallPathToOnDevicePath(ctx, installPath.(android.InstallPath))
}
+
+ usesLibPaths[dep] = &dexpreopt.LibraryPath{buildPath, devicePath}
} else if ctx.Config().AllowMissingDependencies() {
- ctx.AddMissingDependencies([]string{ctx.OtherModuleName(m)})
+ ctx.AddMissingDependencies([]string{dep})
} else {
- ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be a java library",
- ctx.OtherModuleName(m))
+ ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be "+
+ "a java library", dep)
}
})
}
diff --git a/java/app_test.go b/java/app_test.go
index eb583bea6..e45ba70d5 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -149,7 +149,7 @@ func TestAndroidAppSet(t *testing.T) {
prerelease: true,
}`)
module := ctx.ModuleForTests("foo", "android_common")
- const packedSplitApks = "extracted.zip"
+ const packedSplitApks = "foo.zip"
params := module.Output(packedSplitApks)
if params.Rule == nil {
t.Errorf("expected output %s is missing", packedSplitApks)
@@ -218,7 +218,7 @@ func TestAndroidAppSet_Variants(t *testing.T) {
ctx := testContext()
run(t, ctx, config)
module := ctx.ModuleForTests("foo", "android_common")
- const packedSplitApks = "extracted.zip"
+ const packedSplitApks = "foo.zip"
params := module.Output(packedSplitApks)
for k, v := range test.expected {
if actual := params.Args[k]; actual != v {
@@ -2657,7 +2657,7 @@ func TestCodelessApp(t *testing.T) {
}
func TestEmbedNotice(t *testing.T) {
- ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
+ ctx, _ := testJavaWithFS(t, cc.GatherRequiredDepsForTest(android.Android)+`
android_app {
name: "foo",
srcs: ["a.java"],
@@ -2713,7 +2713,12 @@ func TestEmbedNotice(t *testing.T) {
srcs: ["b.java"],
notice: "TOOL_NOTICE",
}
- `)
+ `, map[string][]byte{
+ "APP_NOTICE": nil,
+ "GENRULE_NOTICE": nil,
+ "LIB_NOTICE": nil,
+ "TOOL_NOTICE": nil,
+ })
// foo has NOTICE files to process, and embed_notices is true.
foo := ctx.ModuleForTests("foo", "android_common")
diff --git a/java/config/Android.bp b/java/config/Android.bp
new file mode 100644
index 000000000..198352187
--- /dev/null
+++ b/java/config/Android.bp
@@ -0,0 +1,15 @@
+bootstrap_go_package {
+ name: "soong-java-config",
+ pkgPath: "android/soong/java/config",
+ deps: [
+ "blueprint-proptools",
+ "soong-android",
+ "soong-remoteexec",
+ ],
+ srcs: [
+ "config.go",
+ "error_prone.go",
+ "kotlin.go",
+ "makevars.go",
+ ],
+}
diff --git a/java/config/config.go b/java/config/config.go
index edaed2a10..bb5be3aca 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -28,8 +28,9 @@ import (
var (
pctx = android.NewPackageContext("android/soong/java/config")
- DefaultBootclasspathLibraries = []string{"core.platform.api.stubs", "core-lambda-stubs"}
- DefaultSystemModules = "core-platform-api-stubs-system-modules"
+ // TODO(b/157640067): Don't depend on the legacy API by default in the long term.
+ DefaultBootclasspathLibraries = []string{"legacy.core.platform.api.stubs", "core-lambda-stubs"}
+ DefaultSystemModules = "legacy-core-platform-api-stubs-system-modules"
DefaultLibraries = []string{"ext", "framework"}
DefaultLambdaStubsLibrary = "core-lambda-stubs"
SdkLambdaStubsPath = "prebuilts/sdk/tools/core-lambda-stubs.jar"
diff --git a/java/device_host_converter.go b/java/device_host_converter.go
index b40ab9316..9191a8321 100644
--- a/java/device_host_converter.go
+++ b/java/device_host_converter.go
@@ -51,7 +51,7 @@ type DeviceForHost struct {
// java_device_for_host makes the classes.jar output of a device java_library module available to host
// java_library modules.
//
-// It is rarely necessary, and its usage is restricted to a few whitelisted projects.
+// It is rarely necessary, and its usage is restricted to a few allowed projects.
func DeviceForHostFactory() android.Module {
module := &DeviceForHost{}
@@ -68,7 +68,7 @@ type HostForDevice struct {
// java_host_for_device makes the classes.jar output of a host java_library module available to device
// java_library modules.
//
-// It is rarely necessary, and its usage is restricted to a few whitelisted projects.
+// It is rarely necessary, and its usage is restricted to a few allowed projects.
func HostForDeviceFactory() android.Module {
module := &HostForDevice{}
@@ -150,7 +150,11 @@ func (d *DeviceHostConverter) ImplementationAndResourcesJars() android.Paths {
return d.implementationAndResourceJars
}
-func (d *DeviceHostConverter) DexJar() android.Path {
+func (d *DeviceHostConverter) DexJarBuildPath() android.Path {
+ return nil
+}
+
+func (d *DeviceHostConverter) DexJarInstallPath() android.Path {
return nil
}
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index 4725b0781..7f1afd667 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -37,7 +37,7 @@ type dexpreopter struct {
usesLibs []string
optionalUsesLibs []string
enforceUsesLibs bool
- libraryPaths map[string]android.Path
+ libraryPaths dexpreopt.LibraryPaths
builtInstalled string
}
@@ -77,10 +77,6 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool {
return true
}
- if ctx.Config().UnbundledBuild() {
- return true
- }
-
if d.isTest {
return true
}
@@ -197,10 +193,10 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
ProfileIsTextListing: profileIsTextListing,
ProfileBootListing: profileBootListing,
- EnforceUsesLibraries: d.enforceUsesLibs,
- PresentOptionalUsesLibraries: d.optionalUsesLibs,
- UsesLibraries: d.usesLibs,
- LibraryPaths: d.libraryPaths,
+ EnforceUsesLibraries: d.enforceUsesLibs,
+ OptionalUsesLibraries: d.optionalUsesLibs,
+ UsesLibraries: d.usesLibs,
+ LibraryPaths: d.libraryPaths,
Archs: archs,
DexPreoptImages: images,
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go
index ed61d4bd3..41205598e 100644
--- a/java/dexpreopt_bootjars.go
+++ b/java/dexpreopt_bootjars.go
@@ -179,15 +179,7 @@ func RegisterDexpreoptBootJarsComponents(ctx android.RegistrationContext) {
}
func skipDexpreoptBootJars(ctx android.PathContext) bool {
- if dexpreopt.GetGlobalConfig(ctx).DisablePreopt {
- return true
- }
-
- if ctx.Config().UnbundledBuild() {
- return true
- }
-
- return false
+ return dexpreopt.GetGlobalConfig(ctx).DisablePreopt
}
type dexpreoptBootJars struct {
@@ -255,7 +247,7 @@ func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, modul
return -1, nil
}
- jar, hasJar := module.(interface{ DexJar() android.Path })
+ jar, hasJar := module.(interface{ DexJarBuildPath() android.Path })
if !hasJar {
return -1, nil
}
@@ -296,7 +288,7 @@ func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, modul
panic("unknown boot image: " + image.name)
}
- return index, jar.DexJar()
+ return index, jar.DexJarBuildPath()
}
// buildBootImage takes a bootImageConfig, creates rules to build it, and returns the image.
@@ -340,10 +332,12 @@ func buildBootImage(ctx android.SingletonContext, image *bootImageConfig) *bootI
bootFrameworkProfileRule(ctx, image, missingDeps)
updatableBcpPackagesRule(ctx, image, missingDeps)
- var allFiles android.Paths
+ var zipFiles android.Paths
for _, variant := range image.variants {
files := buildBootImageVariant(ctx, variant, profile, missingDeps)
- allFiles = append(allFiles, files.Paths()...)
+ if variant.target.Os == android.Android {
+ zipFiles = append(zipFiles, files.Paths()...)
+ }
}
if image.zip != nil {
@@ -351,8 +345,8 @@ func buildBootImage(ctx android.SingletonContext, image *bootImageConfig) *bootI
rule.Command().
BuiltTool(ctx, "soong_zip").
FlagWithOutput("-o ", image.zip).
- FlagWithArg("-C ", image.dir.String()).
- FlagWithInputList("-f ", allFiles, " -f ")
+ FlagWithArg("-C ", image.dir.Join(ctx, android.Android.String()).String()).
+ FlagWithInputList("-f ", zipFiles, " -f ")
rule.Build(pctx, ctx, "zip_"+image.name, "zip "+image.name+" image")
}
diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go
index e9704dc2a..9670c7f4b 100644
--- a/java/dexpreopt_bootjars_test.go
+++ b/java/dexpreopt_bootjars_test.go
@@ -118,7 +118,7 @@ func TestDexpreoptBootZip(t *testing.T) {
ctx := android.PathContextForTesting(testConfig(nil, "", nil))
expectedInputs := []string{}
- for _, target := range dexpreoptTargets(ctx) {
+ for _, target := range ctx.Config().Targets[android.Android] {
for _, ext := range []string{".art", ".oat", ".vdex"} {
for _, jar := range []string{"foo", "bar", "baz"} {
expectedInputs = append(expectedInputs,
diff --git a/java/droiddoc.go b/java/droiddoc.go
index 3eab841b7..5cb70e4cd 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -1224,6 +1224,21 @@ func DroidstubsHostFactory() android.Module {
return module
}
+func (d *Droidstubs) OutputFiles(tag string) (android.Paths, error) {
+ switch tag {
+ case "":
+ return android.Paths{d.stubsSrcJar}, nil
+ case ".docs.zip":
+ return android.Paths{d.docZip}, nil
+ case ".annotations.zip":
+ return android.Paths{d.annotationsZip}, nil
+ case ".api_versions.xml":
+ return android.Paths{d.apiVersionsXml}, nil
+ default:
+ return nil, fmt.Errorf("unsupported module reference tag %q", tag)
+ }
+}
+
func (d *Droidstubs) ApiFilePath() android.Path {
return d.apiFilePath
}
@@ -1335,13 +1350,10 @@ func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.Ru
d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
- if len(d.properties.Merge_annotations_dirs) == 0 {
- ctx.PropertyErrorf("merge_annotations_dirs",
- "has to be non-empty if annotations was enabled!")
+ if len(d.properties.Merge_annotations_dirs) != 0 {
+ d.mergeAnnoDirFlags(ctx, cmd)
}
- d.mergeAnnoDirFlags(ctx, cmd)
-
// TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
FlagWithArg("--hide ", "SuperfluousPrefix").
@@ -1428,10 +1440,9 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi
rule.HighMem()
cmd := rule.Command()
- rspFile := ""
+ var implicitsRsp android.WritablePath
if len(implicits) > 0 {
- implicitsRsp := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"implicits.rsp")
- rspFile = implicitsRsp.String()
+ implicitsRsp = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"implicits.rsp")
impRule := android.NewRuleBuilder()
impCmd := impRule.Command()
// A dummy action that copies the ninja generated rsp file to a new location. This allows us to
@@ -1458,10 +1469,10 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi
inputs = append(inputs, strings.Split(v, ",")...)
}
cmd.Text((&remoteexec.REParams{
- Labels: map[string]string{"type": "compile", "lang": "java", "compiler": "metalava"},
+ Labels: map[string]string{"type": "compile", "lang": "java", "compiler": "metalava", "shallow": "true"},
ExecStrategy: execStrategy,
Inputs: inputs,
- RSPFile: rspFile,
+ RSPFile: implicitsRsp.String(),
ToolchainInputs: []string{config.JavaCmd(ctx).String()},
Platform: map[string]string{remoteexec.PoolKey: pool},
}).NoVarTemplate(ctx.Config()))
@@ -1472,7 +1483,12 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi
FlagWithArg("-encoding ", "UTF-8").
FlagWithArg("-source ", javaVersion.String()).
FlagWithRspFileInputList("@", srcs).
- FlagWithInput("@", srcJarList)
+ FlagWithInput("@", srcJarList).
+ FlagWithOutput("--strict-input-files:warn ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt"))
+
+ if implicitsRsp != nil {
+ cmd.FlagWithArg("--strict-input-files-exempt ", "@"+implicitsRsp.String())
+ }
if len(bootclasspath) > 0 {
cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
diff --git a/java/hiddenapi_singleton.go b/java/hiddenapi_singleton.go
index c7f7cbdfe..bff591cb0 100644
--- a/java/hiddenapi_singleton.go
+++ b/java/hiddenapi_singleton.go
@@ -116,7 +116,7 @@ func stubFlagsRule(ctx android.SingletonContext) {
// Core Platform API stubs
corePlatformStubModules := []string{
- "core.platform.api.stubs",
+ "legacy.core.platform.api.stubs",
}
// Allow products to define their own stubs for custom product jars that apps can use.
@@ -147,7 +147,7 @@ func stubFlagsRule(ctx android.SingletonContext) {
name := ctx.ModuleName(module)
for moduleList, pathList := range moduleListToPathList {
if i := android.IndexList(name, *moduleList); i != -1 {
- pathList[i] = j.DexJar()
+ pathList[i] = j.DexJarBuildPath()
}
}
}
diff --git a/java/java.go b/java/java.go
index 76bfa86d6..97a674745 100644
--- a/java/java.go
+++ b/java/java.go
@@ -471,6 +471,7 @@ type Module struct {
hiddenAPI
dexpreopter
+ linter
// list of the xref extraction files
kytheFiles android.Paths
@@ -481,6 +482,22 @@ type Module struct {
modulePaths []string
}
+func (j *Module) addHostProperties() {
+ j.AddProperties(
+ &j.properties,
+ &j.protoProperties,
+ )
+}
+
+func (j *Module) addHostAndDeviceProperties() {
+ j.addHostProperties()
+ j.AddProperties(
+ &j.deviceProperties,
+ &j.dexpreoptProperties,
+ &j.linter.properties,
+ )
+}
+
func (j *Module) OutputFiles(tag string) (android.Paths, error) {
switch tag {
case "":
@@ -496,12 +513,18 @@ func (j *Module) OutputFiles(tag string) (android.Paths, error) {
var _ android.OutputFileProducer = (*Module)(nil)
-type Dependency interface {
+// Methods that need to be implemented for a module that is added to apex java_libs property.
+type ApexDependency interface {
HeaderJars() android.Paths
+ ImplementationAndResourcesJars() android.Paths
+}
+
+type Dependency interface {
+ ApexDependency
ImplementationJars() android.Paths
ResourceJars() android.Paths
- ImplementationAndResourcesJars() android.Paths
- DexJar() android.Path
+ DexJarBuildPath() android.Path
+ DexJarInstallPath() android.Path
AidlIncludeDirs() android.Paths
ExportedSdkLibs() []string
ExportedPlugins() (android.Paths, []string)
@@ -600,7 +623,9 @@ type jniLib struct {
}
func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
- return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
+ return j.properties.Instrument &&
+ ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") &&
+ ctx.DeviceConfig().JavaCoverageEnabledForPath(ctx.ModuleDir())
}
func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
@@ -609,6 +634,21 @@ func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
ctx.Config().UnbundledBuild())
}
+func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool {
+ // Force enable the instrumentation for java code that is built for APEXes ...
+ // except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent
+ // doesn't make sense) or framework libraries (e.g. libraries found in the InstrumentFrameworkModules list) unless EMMA_INSTRUMENT_FRAMEWORK is true.
+ isJacocoAgent := ctx.ModuleName() == "jacocoagent"
+ if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !isJacocoAgent && !j.IsForPlatform() {
+ if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
+ return true
+ } else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
+ return true
+ }
+ }
+ return false
+}
+
func (j *Module) sdkVersion() sdkSpec {
return sdkSpecFrom(String(j.deviceProperties.Sdk_version))
}
@@ -836,41 +876,47 @@ type linkTypeContext interface {
}
func (m *Module) getLinkType(name string) (ret linkType, stubs bool) {
- ver := m.sdkVersion()
- switch {
- case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
- name == "stub-annotations" || name == "private-stub-annotations-jar" ||
- name == "core-lambda-stubs" || name == "core-generated-annotation-stubs":
+ switch name {
+ case "core.current.stubs", "legacy.core.platform.api.stubs", "stable.core.platform.api.stubs",
+ "stub-annotations", "private-stub-annotations-jar",
+ "core-lambda-stubs", "core-generated-annotation-stubs":
return javaCore, true
- case ver.kind == sdkCore:
- return javaCore, false
- case name == "android_system_stubs_current":
+ case "android_stubs_current":
+ return javaSdk, true
+ case "android_system_stubs_current":
return javaSystem, true
- case ver.kind == sdkSystem:
- return javaSystem, false
- case name == "android_test_stubs_current":
+ case "android_module_lib_stubs_current":
+ return javaModule, true
+ case "android_system_server_stubs_current":
+ return javaSystemServer, true
+ case "android_test_stubs_current":
return javaSystem, true
- case ver.kind == sdkTest:
- return javaPlatform, false
- case name == "android_stubs_current":
- return javaSdk, true
- case ver.kind == sdkPublic:
+ }
+
+ if stub, linkType := moduleStubLinkType(name); stub {
+ return linkType, true
+ }
+
+ ver := m.sdkVersion()
+ switch ver.kind {
+ case sdkCore:
+ return javaCore, false
+ case sdkSystem:
+ return javaSystem, false
+ case sdkPublic:
return javaSdk, false
- case name == "android_module_lib_stubs_current":
- return javaModule, true
- case ver.kind == sdkModule:
+ case sdkModule:
return javaModule, false
- case name == "android_system_server_stubs_current":
- return javaSystemServer, true
- case ver.kind == sdkSystemServer:
+ case sdkSystemServer:
return javaSystemServer, false
- case ver.kind == sdkPrivate || ver.kind == sdkNone || ver.kind == sdkCorePlatform:
+ case sdkPrivate, sdkNone, sdkCorePlatform, sdkTest:
return javaPlatform, false
- case !ver.valid():
+ }
+
+ if !ver.valid() {
panic(fmt.Errorf("sdk_version is invalid. got %q", ver.raw))
- default:
- return javaSdk, false
}
+ return javaSdk, false
}
func checkLinkType(ctx android.ModuleContext, from *Module, to linkTypeContext, tag dependencyTag) {
@@ -1143,9 +1189,9 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
if flags.javaVersion.usesJavaModules() {
javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
}
- if ctx.Config().MinimizeJavaDebugInfo() {
- // Override the -g flag passed globally to remove local variable debug info to reduce
- // disk and memory usage.
+ if ctx.Config().MinimizeJavaDebugInfo() && !ctx.Host() {
+ // For non-host binaries, override the -g flag passed globally to remove
+ // local variable debug info to reduce disk and memory usage.
javacFlags = append(javacFlags, "-g:source,lines")
}
javacFlags = append(javacFlags, "-Xlint:-dep-ann")
@@ -1536,11 +1582,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
j.headerJarFile = j.implementationJarFile
}
- // Force enable the instrumentation for java code that is built for APEXes ...
- // except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent
- // doesn't make sense)
- isJacocoAgent := ctx.ModuleName() == "jacocoagent"
- if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !isJacocoAgent && !j.IsForPlatform() {
+ if j.shouldInstrumentInApex(ctx) {
j.properties.Instrument = true
}
@@ -1614,6 +1656,28 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
outputFile = implementationAndResourcesJar
}
+ if ctx.Device() {
+ lintSDKVersionString := func(sdkSpec sdkSpec) string {
+ if v := sdkSpec.version; v.isNumbered() {
+ return v.String()
+ } else {
+ return ctx.Config().DefaultAppTargetSdk()
+ }
+ }
+
+ j.linter.name = ctx.ModuleName()
+ j.linter.srcs = srcFiles
+ j.linter.srcJars = srcJars
+ j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...)
+ j.linter.classes = j.implementationJarFile
+ j.linter.minSdkVersion = lintSDKVersionString(j.minSdkVersion())
+ j.linter.targetSdkVersion = lintSDKVersionString(j.targetSdkVersion())
+ j.linter.compileSdkVersion = lintSDKVersionString(j.sdkVersion())
+ j.linter.javaLanguageLevel = flags.javaVersion.String()
+ j.linter.kotlinLanguageLevel = "1.3"
+ j.linter.lint(ctx)
+ }
+
ctx.CheckbuildFile(outputFile)
// Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
@@ -1739,10 +1803,14 @@ func (j *Module) ImplementationJars() android.Paths {
return android.Paths{j.implementationJarFile}
}
-func (j *Module) DexJar() android.Path {
+func (j *Module) DexJarBuildPath() android.Path {
return j.dexJarFile
}
+func (j *Module) DexJarInstallPath() android.Path {
+ return j.installFile
+}
+
func (j *Module) ResourceJars() android.Paths {
if j.resourceJar == nil {
return nil
@@ -2022,12 +2090,8 @@ var javaHeaderLibsSdkMemberType android.SdkMemberType = &librarySdkMemberType{
func LibraryFactory() android.Module {
module := &Library{}
- module.AddProperties(
- &module.Module.properties,
- &module.Module.deviceProperties,
- &module.Module.dexpreoptProperties,
- &module.Module.protoProperties,
- &module.libraryProperties)
+ module.addHostAndDeviceProperties()
+ module.AddProperties(&module.libraryProperties)
module.initModuleAndImport(&module.ModuleBase)
@@ -2049,9 +2113,7 @@ func LibraryStaticFactory() android.Module {
func LibraryHostFactory() android.Module {
module := &Library{}
- module.AddProperties(
- &module.Module.properties,
- &module.Module.protoProperties)
+ module.addHostProperties()
module.Module.properties.Installable = proptools.BoolPtr(true)
@@ -2219,15 +2281,12 @@ func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext,
func TestFactory() android.Module {
module := &Test{}
- module.AddProperties(
- &module.Module.properties,
- &module.Module.deviceProperties,
- &module.Module.dexpreoptProperties,
- &module.Module.protoProperties,
- &module.testProperties)
+ module.addHostAndDeviceProperties()
+ module.AddProperties(&module.testProperties)
module.Module.properties.Installable = proptools.BoolPtr(true)
module.Module.dexpreopter.isTest = true
+ module.Module.linter.test = true
InitJavaModule(module, android.HostAndDeviceSupported)
return module
@@ -2237,15 +2296,12 @@ func TestFactory() android.Module {
func TestHelperLibraryFactory() android.Module {
module := &TestHelperLibrary{}
- module.AddProperties(
- &module.Module.properties,
- &module.Module.deviceProperties,
- &module.Module.dexpreoptProperties,
- &module.Module.protoProperties,
- &module.testHelperLibraryProperties)
+ module.addHostAndDeviceProperties()
+ module.AddProperties(&module.testHelperLibraryProperties)
module.Module.properties.Installable = proptools.BoolPtr(true)
module.Module.dexpreopter.isTest = true
+ module.Module.linter.test = true
InitJavaModule(module, android.HostAndDeviceSupported)
return module
@@ -2283,10 +2339,8 @@ func JavaTestImportFactory() android.Module {
func TestHostFactory() android.Module {
module := &Test{}
- module.AddProperties(
- &module.Module.properties,
- &module.Module.protoProperties,
- &module.testProperties)
+ module.addHostProperties()
+ module.AddProperties(&module.testProperties)
module.Module.properties.Installable = proptools.BoolPtr(true)
@@ -2370,12 +2424,8 @@ func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
func BinaryFactory() android.Module {
module := &Binary{}
- module.AddProperties(
- &module.Module.properties,
- &module.Module.deviceProperties,
- &module.Module.dexpreoptProperties,
- &module.Module.protoProperties,
- &module.binaryProperties)
+ module.addHostAndDeviceProperties()
+ module.AddProperties(&module.binaryProperties)
module.Module.properties.Installable = proptools.BoolPtr(true)
@@ -2391,10 +2441,8 @@ func BinaryFactory() android.Module {
func BinaryHostFactory() android.Module {
module := &Binary{}
- module.AddProperties(
- &module.Module.properties,
- &module.Module.protoProperties,
- &module.binaryProperties)
+ module.addHostProperties()
+ module.AddProperties(&module.binaryProperties)
module.Module.properties.Installable = proptools.BoolPtr(true)
@@ -2565,7 +2613,11 @@ func (j *Import) ImplementationAndResourcesJars() android.Paths {
return android.Paths{j.combinedClasspathFile}
}
-func (j *Import) DexJar() android.Path {
+func (j *Import) DexJarBuildPath() android.Path {
+ return nil
+}
+
+func (j *Import) DexJarInstallPath() android.Path {
return nil
}
@@ -2691,6 +2743,10 @@ func (j *DexImport) Stem() string {
return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
}
+func (a *DexImport) JacocoReportClassesFile() android.Path {
+ return nil
+}
+
func (j *DexImport) IsInstallable() bool {
return true
}
@@ -2744,11 +2800,13 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.maybeStrippedDexJarFile = dexOutputFile
- ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
- j.Stem()+".jar", dexOutputFile)
+ if j.IsForPlatform() {
+ ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
+ j.Stem()+".jar", dexOutputFile)
+ }
}
-func (j *DexImport) DexJar() android.Path {
+func (j *DexImport) DexJarBuildPath() android.Path {
return j.dexJarFile
}
@@ -2831,6 +2889,7 @@ func DefaultsFactory() android.Module {
&DexImportProperties{},
&android.ApexProperties{},
&RuntimeResourceOverlayProperties{},
+ &LintProperties{},
)
android.InitDefaultsModule(module)
@@ -2853,11 +2912,7 @@ func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonC
})
// TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets
if len(xrefTargets) > 0 {
- ctx.Build(pctx, android.BuildParams{
- Rule: blueprint.Phony,
- Output: android.PathForPhony(ctx, "xref_java"),
- Inputs: xrefTargets,
- })
+ ctx.Phony("xref_java", xrefTargets...)
}
}
diff --git a/java/java_test.go b/java/java_test.go
index 8ea34d975..1d07e7001 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -142,9 +142,14 @@ func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config
return ctx, config
}
+func testJavaWithFS(t *testing.T, bp string, fs map[string][]byte) (*android.TestContext, android.Config) {
+ t.Helper()
+ return testJavaWithConfig(t, testConfig(nil, bp, fs))
+}
+
func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) {
t.Helper()
- return testJavaWithConfig(t, testConfig(nil, bp, nil))
+ return testJavaWithFS(t, bp, nil)
}
func testJavaWithConfig(t *testing.T, config android.Config) (*android.TestContext, android.Config) {
@@ -461,7 +466,41 @@ func TestBinary(t *testing.T) {
t.Errorf("expected binary wrapper implicits [%q], got %v",
barJar, barWrapperDeps)
}
+}
+func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) {
+ bp := `
+ java_library {
+ name: "target_library",
+ srcs: ["a.java"],
+ }
+
+ java_binary_host {
+ name: "host_binary",
+ srcs: ["b.java"],
+ }
+ `
+ config := testConfig(nil, bp, nil)
+ config.TestProductVariables.MinimizeJavaDebugInfo = proptools.BoolPtr(true)
+
+ ctx, _ := testJavaWithConfig(t, config)
+
+ // first, sanity check that the -g flag is added to target modules
+ targetLibrary := ctx.ModuleForTests("target_library", "android_common")
+ targetJavaFlags := targetLibrary.Module().VariablesForTests()["javacFlags"]
+ if !strings.Contains(targetJavaFlags, "-g:source,lines") {
+ t.Errorf("target library javac flags %v should contain "+
+ "-g:source,lines override with MinimizeJavaDebugInfo", targetJavaFlags)
+ }
+
+ // check that -g is not overridden for host modules
+ buildOS := android.BuildOs.String()
+ hostBinary := ctx.ModuleForTests("host_binary", buildOS+"_common")
+ hostJavaFlags := hostBinary.Module().VariablesForTests()["javacFlags"]
+ if strings.Contains(hostJavaFlags, "-g:source,lines") {
+ t.Errorf("java_binary_host javac flags %v should not have "+
+ "-g:source,lines override with MinimizeJavaDebugInfo", hostJavaFlags)
+ }
}
func TestPrebuilts(t *testing.T) {
@@ -740,7 +779,7 @@ func TestResources(t *testing.T) {
for _, test := range table {
t.Run(test.name, func(t *testing.T) {
- ctx, _ := testJava(t, `
+ ctx, _ := testJavaWithFS(t, `
java_library {
name: "foo",
srcs: [
@@ -750,7 +789,13 @@ func TestResources(t *testing.T) {
],
`+test.prop+`,
}
- `+test.extra)
+ `+test.extra,
+ map[string][]byte{
+ "java-res/a/a": nil,
+ "java-res/b/b": nil,
+ "java-res2/a": nil,
+ },
+ )
foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar")
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
@@ -769,7 +814,7 @@ func TestResources(t *testing.T) {
}
func TestIncludeSrcs(t *testing.T) {
- ctx, _ := testJava(t, `
+ ctx, _ := testJavaWithFS(t, `
java_library {
name: "foo",
srcs: [
@@ -790,7 +835,11 @@ func TestIncludeSrcs(t *testing.T) {
java_resource_dirs: ["java-res"],
include_srcs: true,
}
- `)
+ `, map[string][]byte{
+ "java-res/a/a": nil,
+ "java-res/b/b": nil,
+ "java-res2/a": nil,
+ })
// Test a library with include_srcs: true
foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar")
@@ -832,7 +881,7 @@ func TestIncludeSrcs(t *testing.T) {
}
func TestGeneratedSources(t *testing.T) {
- ctx, _ := testJava(t, `
+ ctx, _ := testJavaWithFS(t, `
java_library {
name: "foo",
srcs: [
@@ -847,7 +896,10 @@ func TestGeneratedSources(t *testing.T) {
tool_files: ["java-res/a"],
out: ["gen.java"],
}
- `)
+ `, map[string][]byte{
+ "a.java": nil,
+ "b.java": nil,
+ })
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
genrule := ctx.ModuleForTests("gen", "").Rule("generator")
@@ -932,7 +984,7 @@ func TestSharding(t *testing.T) {
}
func TestDroiddoc(t *testing.T) {
- ctx, _ := testJava(t, `
+ ctx, _ := testJavaWithFS(t, `
droiddoc_exported_dir {
name: "droiddoc-templates-sdk",
path: ".",
@@ -945,7 +997,7 @@ func TestDroiddoc(t *testing.T) {
droiddoc {
name: "bar-doc",
srcs: [
- "bar-doc/*.java",
+ "bar-doc/a.java",
"bar-doc/IFoo.aidl",
":bar-doc-aidl-srcs",
],
@@ -963,7 +1015,11 @@ func TestDroiddoc(t *testing.T) {
todo_file: "libcore-docs-todo.html",
args: "-offlinemode -title \"libcore\"",
}
- `)
+ `,
+ map[string][]byte{
+ "bar-doc/a.java": nil,
+ "bar-doc/b.java": nil,
+ })
barDoc := ctx.ModuleForTests("bar-doc", "android_common").Rule("javadoc")
var javaSrcs []string
@@ -989,7 +1045,7 @@ func TestDroidstubsWithSystemModules(t *testing.T) {
droidstubs {
name: "stubs-source-system-modules",
srcs: [
- "bar-doc/*.java",
+ "bar-doc/a.java",
],
sdk_version: "none",
system_modules: "source-system-modules",
@@ -1010,7 +1066,7 @@ func TestDroidstubsWithSystemModules(t *testing.T) {
droidstubs {
name: "stubs-prebuilt-system-modules",
srcs: [
- "bar-doc/*.java",
+ "bar-doc/a.java",
],
sdk_version: "none",
system_modules: "prebuilt-system-modules",
@@ -1426,6 +1482,38 @@ func TestJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) {
`)
}
+func TestJavaSdkLibrary_ModuleLib(t *testing.T) {
+ testJava(t, `
+ java_sdk_library {
+ name: "foo",
+ srcs: ["a.java", "b.java"],
+ api_packages: ["foo"],
+ system: {
+ enabled: true,
+ },
+ module_lib: {
+ enabled: true,
+ },
+ }
+ `)
+}
+
+func TestJavaSdkLibrary_SystemServer(t *testing.T) {
+ testJava(t, `
+ java_sdk_library {
+ name: "foo",
+ srcs: ["a.java", "b.java"],
+ api_packages: ["foo"],
+ system: {
+ enabled: true,
+ },
+ system_server: {
+ enabled: true,
+ },
+ }
+ `)
+}
+
func TestJavaSdkLibrary_MissingScope(t *testing.T) {
testJavaError(t, `requires api scope module-lib from foo but it only has \[\] available`, `
java_sdk_library {
diff --git a/java/lint.go b/java/lint.go
new file mode 100644
index 000000000..441e110cd
--- /dev/null
+++ b/java/lint.go
@@ -0,0 +1,355 @@
+// Copyright 2020 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 java
+
+import (
+ "fmt"
+ "sort"
+
+ "android/soong/android"
+)
+
+type LintProperties struct {
+ // Controls for running Android Lint on the module.
+ Lint struct {
+
+ // If true, run Android Lint on the module. Defaults to true.
+ Enabled *bool
+
+ // Flags to pass to the Android Lint tool.
+ Flags []string
+
+ // Checks that should be treated as fatal.
+ Fatal_checks []string
+
+ // Checks that should be treated as errors.
+ Error_checks []string
+
+ // Checks that should be treated as warnings.
+ Warning_checks []string
+
+ // Checks that should be skipped.
+ Disabled_checks []string
+ }
+}
+
+type linter struct {
+ name string
+ manifest android.Path
+ mergedManifest android.Path
+ srcs android.Paths
+ srcJars android.Paths
+ resources android.Paths
+ classpath android.Paths
+ classes android.Path
+ extraLintCheckJars android.Paths
+ test bool
+ library bool
+ minSdkVersion string
+ targetSdkVersion string
+ compileSdkVersion string
+ javaLanguageLevel string
+ kotlinLanguageLevel string
+ outputs lintOutputs
+ properties LintProperties
+}
+
+type lintOutputs struct {
+ html android.ModuleOutPath
+ text android.ModuleOutPath
+ xml android.ModuleOutPath
+}
+
+func (l *linter) enabled() bool {
+ return BoolDefault(l.properties.Lint.Enabled, true)
+}
+
+func (l *linter) writeLintProjectXML(ctx android.ModuleContext,
+ rule *android.RuleBuilder) (projectXMLPath, configXMLPath, cacheDir android.WritablePath, deps android.Paths) {
+
+ var resourcesList android.WritablePath
+ if len(l.resources) > 0 {
+ // The list of resources may be too long to put on the command line, but
+ // we can't use the rsp file because it is already being used for srcs.
+ // Insert a second rule to write out the list of resources to a file.
+ resourcesList = android.PathForModuleOut(ctx, "lint", "resources.list")
+ resListRule := android.NewRuleBuilder()
+ resListRule.Command().Text("cp").FlagWithRspFileInputList("", l.resources).Output(resourcesList)
+ resListRule.Build(pctx, ctx, "lint_resources_list", "lint resources list")
+ deps = append(deps, l.resources...)
+ }
+
+ projectXMLPath = android.PathForModuleOut(ctx, "lint", "project.xml")
+ // Lint looks for a lint.xml file next to the project.xml file, give it one.
+ configXMLPath = android.PathForModuleOut(ctx, "lint", "lint.xml")
+ cacheDir = android.PathForModuleOut(ctx, "lint", "cache")
+
+ srcJarDir := android.PathForModuleOut(ctx, "lint-srcjars")
+ srcJarList := zipSyncCmd(ctx, rule, srcJarDir, l.srcJars)
+
+ cmd := rule.Command().
+ BuiltTool(ctx, "lint-project-xml").
+ FlagWithOutput("--project_out ", projectXMLPath).
+ FlagWithOutput("--config_out ", configXMLPath).
+ FlagWithArg("--name ", ctx.ModuleName())
+
+ if l.library {
+ cmd.Flag("--library")
+ }
+ if l.test {
+ cmd.Flag("--test")
+ }
+ if l.manifest != nil {
+ deps = append(deps, l.manifest)
+ cmd.FlagWithArg("--manifest ", l.manifest.String())
+ }
+ if l.mergedManifest != nil {
+ deps = append(deps, l.mergedManifest)
+ cmd.FlagWithArg("--merged_manifest ", l.mergedManifest.String())
+ }
+
+ // TODO(ccross): some of the files in l.srcs are generated sources and should be passed to
+ // lint separately.
+ cmd.FlagWithRspFileInputList("--srcs ", l.srcs)
+ deps = append(deps, l.srcs...)
+
+ cmd.FlagWithInput("--generated_srcs ", srcJarList)
+ deps = append(deps, l.srcJars...)
+
+ if resourcesList != nil {
+ cmd.FlagWithInput("--resources ", resourcesList)
+ }
+
+ if l.classes != nil {
+ deps = append(deps, l.classes)
+ cmd.FlagWithArg("--classes ", l.classes.String())
+ }
+
+ cmd.FlagForEachArg("--classpath ", l.classpath.Strings())
+ deps = append(deps, l.classpath...)
+
+ cmd.FlagForEachArg("--extra_checks_jar ", l.extraLintCheckJars.Strings())
+ deps = append(deps, l.extraLintCheckJars...)
+
+ // The cache tag in project.xml is relative to the project.xml file.
+ cmd.FlagWithArg("--cache_dir ", "cache")
+
+ cmd.FlagWithInput("@",
+ android.PathForSource(ctx, "build/soong/java/lint_defaults.txt"))
+
+ cmd.FlagForEachArg("--disable_check ", l.properties.Lint.Disabled_checks)
+ cmd.FlagForEachArg("--warning_check ", l.properties.Lint.Warning_checks)
+ cmd.FlagForEachArg("--error_check ", l.properties.Lint.Error_checks)
+ cmd.FlagForEachArg("--fatal_check ", l.properties.Lint.Fatal_checks)
+
+ return projectXMLPath, configXMLPath, cacheDir, deps
+}
+
+// generateManifest adds a command to the rule to write a dummy manifest cat contains the
+// minSdkVersion and targetSdkVersion for modules (like java_library) that don't have a manifest.
+func (l *linter) generateManifest(ctx android.ModuleContext, rule *android.RuleBuilder) android.Path {
+ manifestPath := android.PathForModuleOut(ctx, "lint", "AndroidManifest.xml")
+
+ rule.Command().Text("(").
+ Text(`echo "<?xml version='1.0' encoding='utf-8'?>" &&`).
+ Text(`echo "<manifest xmlns:android='http://schemas.android.com/apk/res/android'" &&`).
+ Text(`echo " android:versionCode='1' android:versionName='1' >" &&`).
+ Textf(`echo " <uses-sdk android:minSdkVersion='%s' android:targetSdkVersion='%s'/>" &&`,
+ l.minSdkVersion, l.targetSdkVersion).
+ Text(`echo "</manifest>"`).
+ Text(") >").Output(manifestPath)
+
+ return manifestPath
+}
+
+func (l *linter) lint(ctx android.ModuleContext) {
+ if !l.enabled() {
+ return
+ }
+
+ rule := android.NewRuleBuilder()
+
+ if l.manifest == nil {
+ manifest := l.generateManifest(ctx, rule)
+ l.manifest = manifest
+ }
+
+ projectXML, lintXML, cacheDir, deps := l.writeLintProjectXML(ctx, rule)
+
+ l.outputs.html = android.PathForModuleOut(ctx, "lint-report.html")
+ l.outputs.text = android.PathForModuleOut(ctx, "lint-report.txt")
+ l.outputs.xml = android.PathForModuleOut(ctx, "lint-report.xml")
+
+ rule.Command().Text("rm -rf").Flag(cacheDir.String())
+ rule.Command().Text("mkdir -p").Flag(cacheDir.String())
+
+ rule.Command().
+ Text("(").
+ Flag("JAVA_OPTS=-Xmx2048m").
+ FlagWithInput("SDK_ANNOTATIONS=", annotationsZipPath(ctx)).
+ FlagWithInput("LINT_OPTS=-DLINT_API_DATABASE=", apiVersionsXmlPath(ctx)).
+ Tool(android.PathForSource(ctx, "prebuilts/cmdline-tools/tools/bin/lint")).
+ Implicit(android.PathForSource(ctx, "prebuilts/cmdline-tools/tools/lib/lint-classpath.jar")).
+ Flag("--quiet").
+ FlagWithInput("--project ", projectXML).
+ FlagWithInput("--config ", lintXML).
+ FlagWithOutput("--html ", l.outputs.html).
+ FlagWithOutput("--text ", l.outputs.text).
+ FlagWithOutput("--xml ", l.outputs.xml).
+ FlagWithArg("--compile-sdk-version ", l.compileSdkVersion).
+ FlagWithArg("--java-language-level ", l.javaLanguageLevel).
+ FlagWithArg("--kotlin-language-level ", l.kotlinLanguageLevel).
+ FlagWithArg("--url ", fmt.Sprintf(".=.,%s=out", android.PathForOutput(ctx).String())).
+ Flag("--exitcode").
+ Flags(l.properties.Lint.Flags).
+ Implicits(deps).
+ Text("|| (").Text("cat").Input(l.outputs.text).Text("; exit 7)").
+ Text(")")
+
+ rule.Command().Text("rm -rf").Flag(cacheDir.String())
+
+ rule.Build(pctx, ctx, "lint", "lint")
+}
+
+func (l *linter) lintOutputs() *lintOutputs {
+ return &l.outputs
+}
+
+type lintOutputIntf interface {
+ lintOutputs() *lintOutputs
+}
+
+var _ lintOutputIntf = (*linter)(nil)
+
+type lintSingleton struct {
+ htmlZip android.WritablePath
+ textZip android.WritablePath
+ xmlZip android.WritablePath
+}
+
+func (l *lintSingleton) GenerateBuildActions(ctx android.SingletonContext) {
+ l.generateLintReportZips(ctx)
+ l.copyLintDependencies(ctx)
+}
+
+func (l *lintSingleton) copyLintDependencies(ctx android.SingletonContext) {
+ if ctx.Config().UnbundledBuild() {
+ return
+ }
+
+ var frameworkDocStubs android.Module
+ ctx.VisitAllModules(func(m android.Module) {
+ if ctx.ModuleName(m) == "framework-doc-stubs" {
+ if frameworkDocStubs == nil {
+ frameworkDocStubs = m
+ } else {
+ ctx.Errorf("lint: multiple framework-doc-stubs modules found: %s and %s",
+ ctx.ModuleSubDir(m), ctx.ModuleSubDir(frameworkDocStubs))
+ }
+ }
+ })
+
+ if frameworkDocStubs == nil {
+ if !ctx.Config().AllowMissingDependencies() {
+ ctx.Errorf("lint: missing framework-doc-stubs")
+ }
+ return
+ }
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.Cp,
+ Input: android.OutputFileForModule(ctx, frameworkDocStubs, ".annotations.zip"),
+ Output: annotationsZipPath(ctx),
+ })
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.Cp,
+ Input: android.OutputFileForModule(ctx, frameworkDocStubs, ".api_versions.xml"),
+ Output: apiVersionsXmlPath(ctx),
+ })
+}
+
+func annotationsZipPath(ctx android.PathContext) android.WritablePath {
+ return android.PathForOutput(ctx, "lint", "annotations.zip")
+}
+
+func apiVersionsXmlPath(ctx android.PathContext) android.WritablePath {
+ return android.PathForOutput(ctx, "lint", "api_versions.xml")
+}
+
+func (l *lintSingleton) generateLintReportZips(ctx android.SingletonContext) {
+ var outputs []*lintOutputs
+ var dirs []string
+ ctx.VisitAllModules(func(m android.Module) {
+ if ctx.Config().EmbeddedInMake() && !m.ExportedToMake() {
+ return
+ }
+
+ if apex, ok := m.(android.ApexModule); ok && apex.NotAvailableForPlatform() && apex.IsForPlatform() {
+ // There are stray platform variants of modules in apexes that are not available for
+ // the platform, and they sometimes can't be built. Don't depend on them.
+ return
+ }
+
+ if l, ok := m.(lintOutputIntf); ok {
+ outputs = append(outputs, l.lintOutputs())
+ }
+ })
+
+ dirs = android.SortedUniqueStrings(dirs)
+
+ zip := func(outputPath android.WritablePath, get func(*lintOutputs) android.Path) {
+ var paths android.Paths
+
+ for _, output := range outputs {
+ paths = append(paths, get(output))
+ }
+
+ sort.Slice(paths, func(i, j int) bool {
+ return paths[i].String() < paths[j].String()
+ })
+
+ rule := android.NewRuleBuilder()
+
+ rule.Command().BuiltTool(ctx, "soong_zip").
+ FlagWithOutput("-o ", outputPath).
+ FlagWithArg("-C ", android.PathForIntermediates(ctx).String()).
+ FlagWithRspFileInputList("-l ", paths)
+
+ rule.Build(pctx, ctx, outputPath.Base(), outputPath.Base())
+ }
+
+ l.htmlZip = android.PathForOutput(ctx, "lint-report-html.zip")
+ zip(l.htmlZip, func(l *lintOutputs) android.Path { return l.html })
+
+ l.textZip = android.PathForOutput(ctx, "lint-report-text.zip")
+ zip(l.textZip, func(l *lintOutputs) android.Path { return l.text })
+
+ l.xmlZip = android.PathForOutput(ctx, "lint-report-xml.zip")
+ zip(l.xmlZip, func(l *lintOutputs) android.Path { return l.xml })
+
+ ctx.Phony("lint-check", l.htmlZip, l.textZip, l.xmlZip)
+}
+
+func (l *lintSingleton) MakeVars(ctx android.MakeVarsContext) {
+ ctx.DistForGoal("lint-check", l.htmlZip, l.textZip, l.xmlZip)
+}
+
+var _ android.SingletonMakeVarsProvider = (*lintSingleton)(nil)
+
+func init() {
+ android.RegisterSingletonType("lint",
+ func() android.Singleton { return &lintSingleton{} })
+}
diff --git a/java/lint_defaults.txt b/java/lint_defaults.txt
new file mode 100644
index 000000000..0786b7c00
--- /dev/null
+++ b/java/lint_defaults.txt
@@ -0,0 +1,78 @@
+# Treat LintError as fatal to catch invocation errors
+--fatal_check LintError
+
+# Downgrade existing errors to warnings
+--warning_check AppCompatResource # 55 occurences in 10 modules
+--warning_check AppLinkUrlError # 111 occurences in 53 modules
+--warning_check BlockedPrivateApi # 2 occurences in 2 modules
+--warning_check ByteOrderMark # 2 occurences in 2 modules
+--warning_check DuplicateActivity # 3 occurences in 3 modules
+--warning_check DuplicateDefinition # 3623 occurences in 48 modules
+--warning_check DuplicateIds # 207 occurences in 22 modules
+--warning_check EllipsizeMaxLines # 12 occurences in 7 modules
+--warning_check ExtraTranslation # 21276 occurences in 27 modules
+--warning_check FontValidationError # 4 occurences in 1 modules
+--warning_check FullBackupContent # 16 occurences in 1 modules
+--warning_check GetContentDescriptionOverride # 3 occurences in 2 modules
+--warning_check HalfFloat # 31 occurences in 1 modules
+--warning_check HardcodedDebugMode # 99 occurences in 95 modules
+--warning_check ImpliedQuantity # 703 occurences in 27 modules
+--warning_check ImpliedTouchscreenHardware # 4 occurences in 4 modules
+--warning_check IncludeLayoutParam # 11 occurences in 6 modules
+--warning_check Instantiatable # 145 occurences in 19 modules
+--warning_check InvalidPermission # 6 occurences in 4 modules
+--warning_check InvalidUsesTagAttribute # 6 occurences in 2 modules
+--warning_check InvalidWakeLockTag # 111 occurences in 37 modules
+--warning_check JavascriptInterface # 3 occurences in 2 modules
+--warning_check LibraryCustomView # 9 occurences in 4 modules
+--warning_check LogTagMismatch # 81 occurences in 13 modules
+--warning_check LongLogTag # 249 occurences in 12 modules
+--warning_check MenuTitle # 5 occurences in 4 modules
+--warning_check MissingClass # 537 occurences in 141 modules
+--warning_check MissingConstraints # 39 occurences in 10 modules
+--warning_check MissingDefaultResource # 1257 occurences in 40 modules
+--warning_check MissingIntentFilterForMediaSearch # 1 occurences in 1 modules
+--warning_check MissingLeanbackLauncher # 3 occurences in 3 modules
+--warning_check MissingLeanbackSupport # 2 occurences in 2 modules
+--warning_check MissingOnPlayFromSearch # 1 occurences in 1 modules
+--warning_check MissingPermission # 2071 occurences in 150 modules
+--warning_check MissingPrefix # 46 occurences in 41 modules
+--warning_check MissingQuantity # 100 occurences in 1 modules
+--warning_check MissingSuperCall # 121 occurences in 36 modules
+--warning_check MissingTvBanner # 3 occurences in 3 modules
+--warning_check NamespaceTypo # 3 occurences in 3 modules
+--warning_check NetworkSecurityConfig # 46 occurences in 12 modules
+--warning_check NewApi # 1996 occurences in 122 modules
+--warning_check NotSibling # 15 occurences in 10 modules
+--warning_check ObjectAnimatorBinding # 14 occurences in 5 modules
+--warning_check OnClick # 49 occurences in 21 modules
+--warning_check Orientation # 77 occurences in 19 modules
+--warning_check Override # 385 occurences in 36 modules
+--warning_check ParcelCreator # 23 occurences in 2 modules
+--warning_check ProtectedPermissions # 2413 occurences in 381 modules
+--warning_check Range # 80 occurences in 28 modules
+--warning_check RecyclerView # 1 occurences in 1 modules
+--warning_check ReferenceType # 4 occurences in 1 modules
+--warning_check ResourceAsColor # 19 occurences in 14 modules
+--warning_check RequiredSize # 52 occurences in 13 modules
+--warning_check ResAuto # 3 occurences in 1 modules
+--warning_check ResourceCycle # 37 occurences in 10 modules
+--warning_check ResourceType # 137 occurences in 36 modules
+--warning_check RestrictedApi # 28 occurences in 5 modules
+--warning_check RtlCompat # 9 occurences in 6 modules
+--warning_check ServiceCast # 3 occurences in 1 modules
+--warning_check SoonBlockedPrivateApi # 5 occurences in 3 modules
+--warning_check StringFormatInvalid # 148 occurences in 11 modules
+--warning_check StringFormatMatches # 4800 occurences in 30 modules
+--warning_check UnknownId # 8 occurences in 7 modules
+--warning_check ValidFragment # 12 occurences in 5 modules
+--warning_check ValidRestrictions # 5 occurences in 1 modules
+--warning_check WebViewLayout # 3 occurences in 1 modules
+--warning_check WrongCall # 21 occurences in 3 modules
+--warning_check WrongConstant # 894 occurences in 126 modules
+--warning_check WrongManifestParent # 10 occurences in 4 modules
+--warning_check WrongThread # 14 occurences in 6 modules
+--warning_check WrongViewCast # 1 occurences in 1 modules
+
+# TODO(b/158390965): remove this when lint doesn't crash
+--disable_check HardcodedDebugMode
diff --git a/java/plugin.go b/java/plugin.go
index a5e8292e7..947c28626 100644
--- a/java/plugin.go
+++ b/java/plugin.go
@@ -24,10 +24,8 @@ func init() {
func PluginFactory() android.Module {
module := &Plugin{}
- module.AddProperties(
- &module.Module.properties,
- &module.Module.protoProperties,
- &module.pluginProperties)
+ module.addHostProperties()
+ module.AddProperties(&module.pluginProperties)
InitJavaModule(module, android.HostSupported)
return module
diff --git a/java/robolectric.go b/java/robolectric.go
index 3195615ff..c6b07a17e 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -215,13 +215,13 @@ func (r *robolectricTest) writeTestRunner(w io.Writer, module, name string, test
func RobolectricTestFactory() android.Module {
module := &robolectricTest{}
+ module.addHostProperties()
module.AddProperties(
- &module.Module.properties,
&module.Module.deviceProperties,
- &module.Module.protoProperties,
&module.robolectricProperties)
module.Module.dexpreopter.isTest = true
+ module.Module.linter.test = true
InitJavaModule(module, android.DeviceSupported)
return module
diff --git a/java/sdk.go b/java/sdk.go
index 9310f7846..2a08f329e 100644
--- a/java/sdk.go
+++ b/java/sdk.go
@@ -35,6 +35,7 @@ func init() {
var sdkVersionsKey = android.NewOnceKey("sdkVersionsKey")
var sdkFrameworkAidlPathKey = android.NewOnceKey("sdkFrameworkAidlPathKey")
+var nonUpdatableFrameworkAidlPathKey = android.NewOnceKey("nonUpdatableFrameworkAidlPathKey")
var apiFingerprintPathKey = android.NewOnceKey("apiFingerprintPathKey")
type sdkContext interface {
@@ -447,7 +448,7 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep
return toModule([]string{"core.current.stubs"}, "", nil)
case sdkModule:
// TODO(146757305): provide .apk and .aidl that have more APIs for modules
- return toModule([]string{"android_module_lib_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx))
+ return toModule([]string{"android_module_lib_stubs_current"}, "framework-res", nonUpdatableFrameworkAidlPath(ctx))
case sdkSystemServer:
// TODO(146757305): provide .apk and .aidl that have more APIs for modules
return toModule([]string{"android_system_server_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx))
@@ -506,6 +507,7 @@ func (sdkSingleton) GenerateBuildActions(ctx android.SingletonContext) {
}
createSdkFrameworkAidl(ctx)
+ createNonUpdatableFrameworkAidl(ctx)
createAPIFingerprint(ctx)
}
@@ -517,6 +519,31 @@ func createSdkFrameworkAidl(ctx android.SingletonContext) {
"android_system_stubs_current",
}
+ combinedAidl := sdkFrameworkAidlPath(ctx)
+ tempPath := combinedAidl.ReplaceExtension(ctx, "aidl.tmp")
+
+ rule := createFrameworkAidl(stubsModules, tempPath, ctx)
+
+ commitChangeForRestat(rule, tempPath, combinedAidl)
+
+ rule.Build(pctx, ctx, "framework_aidl", "generate framework.aidl")
+}
+
+// Creates a version of framework.aidl for the non-updatable part of the platform.
+func createNonUpdatableFrameworkAidl(ctx android.SingletonContext) {
+ stubsModules := []string{"android_module_lib_stubs_current"}
+
+ combinedAidl := nonUpdatableFrameworkAidlPath(ctx)
+ tempPath := combinedAidl.ReplaceExtension(ctx, "aidl.tmp")
+
+ rule := createFrameworkAidl(stubsModules, tempPath, ctx)
+
+ commitChangeForRestat(rule, tempPath, combinedAidl)
+
+ rule.Build(pctx, ctx, "framework_non_updatable_aidl", "generate framework_non_updatable.aidl")
+}
+
+func createFrameworkAidl(stubsModules []string, path android.OutputPath, ctx android.SingletonContext) *android.RuleBuilder {
stubsJars := make([]android.Paths, len(stubsModules))
ctx.VisitAllModules(func(module android.Module) {
@@ -536,8 +563,7 @@ func createSdkFrameworkAidl(ctx android.SingletonContext) {
if ctx.Config().AllowMissingDependencies() {
missingDeps = append(missingDeps, stubsModules[i])
} else {
- ctx.Errorf("failed to find dex jar path for module %q",
- stubsModules[i])
+ ctx.Errorf("failed to find dex jar path for module %q", stubsModules[i])
}
}
}
@@ -561,20 +587,15 @@ func createSdkFrameworkAidl(ctx android.SingletonContext) {
}
}
- combinedAidl := sdkFrameworkAidlPath(ctx)
- tempPath := combinedAidl.ReplaceExtension(ctx, "aidl.tmp")
-
rule.Command().
- Text("rm -f").Output(tempPath)
+ Text("rm -f").Output(path)
rule.Command().
Text("cat").
Inputs(aidls).
Text("| sort -u >").
- Output(tempPath)
+ Output(path)
- commitChangeForRestat(rule, tempPath, combinedAidl)
-
- rule.Build(pctx, ctx, "framework_aidl", "generate framework.aidl")
+ return rule
}
func sdkFrameworkAidlPath(ctx android.PathContext) android.OutputPath {
@@ -583,6 +604,12 @@ func sdkFrameworkAidlPath(ctx android.PathContext) android.OutputPath {
}).(android.OutputPath)
}
+func nonUpdatableFrameworkAidlPath(ctx android.PathContext) android.OutputPath {
+ return ctx.Config().Once(nonUpdatableFrameworkAidlPathKey, func() interface{} {
+ return android.PathForOutput(ctx, "framework_non_updatable.aidl")
+ }).(android.OutputPath)
+}
+
// Create api_fingerprint.txt
func createAPIFingerprint(ctx android.SingletonContext) {
out := ApiFingerprintPath(ctx)
diff --git a/java/sdk_library.go b/java/sdk_library.go
index c4d257f20..7ce0912e9 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -264,7 +264,7 @@ var (
apiScopeModuleLib = initApiScope(&apiScope{
name: "module-lib",
extends: apiScopeSystem,
- // Module_lib scope is disabled by default in legacy mode.
+ // The module-lib scope is disabled by default in legacy mode.
//
// Enabling this would break existing usages.
legacyEnabledStatus: func(module *SdkLibrary) bool {
@@ -280,11 +280,34 @@ var (
"--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES\\)",
},
})
+ apiScopeSystemServer = initApiScope(&apiScope{
+ name: "system-server",
+ extends: apiScopePublic,
+ // The system-server scope is disabled by default in legacy mode.
+ //
+ // Enabling this would break existing usages.
+ legacyEnabledStatus: func(module *SdkLibrary) bool {
+ return false
+ },
+ scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
+ return &module.sdkLibraryProperties.System_server
+ },
+ apiFilePrefix: "system-server-",
+ moduleSuffix: ".system_server",
+ sdkVersion: "system_server_current",
+ droidstubsArgs: []string{
+ "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.SYSTEM_SERVER\\) ",
+ "--hide-annotation android.annotation.Hide",
+ // com.android.* classes are okay in this interface"
+ "--hide InternalClasses",
+ },
+ })
allApiScopes = apiScopes{
apiScopePublic,
apiScopeSystem,
apiScopeTest,
apiScopeModuleLib,
+ apiScopeSystemServer,
}
)
@@ -429,12 +452,18 @@ type sdkLibraryProperties struct {
// In non-legacy mode the test api scope is disabled by default.
Test ApiScopeProperties
- // The properties specific to the module_lib api scope
+ // The properties specific to the module-lib api scope
//
- // Unless explicitly specified by using test.enabled the module_lib api scope is
+ // Unless explicitly specified by using test.enabled the module-lib api scope is
// disabled by default.
Module_lib ApiScopeProperties
+ // The properties specific to the system-server api scope
+ //
+ // Unless explicitly specified by using test.enabled the module-lib api scope is
+ // disabled by default.
+ System_server ApiScopeProperties
+
// Determines if the stubs are preferred over the implementation library
// for linking, even when the client doesn't specify sdk_version. When this
// is set to true, such clients are provided with the widest API surface that
@@ -600,6 +629,16 @@ func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android
return true
}
+// Module name of the runtime implementation library
+func (c *commonToSdkLibraryAndImport) implLibraryModuleName() string {
+ return c.moduleBase.BaseModuleName() + ".impl"
+}
+
+// Module name of the XML file for the lib
+func (c *commonToSdkLibraryAndImport) xmlPermissionsModuleName() string {
+ return c.moduleBase.BaseModuleName() + sdkXmlFileSuffix
+}
+
// Name of the java_library module that compiles the stubs source.
func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string {
return c.namingScheme.stubsLibraryModuleName(apiScope, c.moduleBase.BaseModuleName())
@@ -743,6 +782,8 @@ func (c *commonToSdkLibraryAndImport) selectHeaderJarsForSdkVersion(ctx android.
apiScope = apiScopeModuleLib
case sdkTest:
apiScope = apiScopeTest
+ case sdkSystemServer:
+ apiScope = apiScopeSystemServer
default:
apiScope = apiScopePublic
}
@@ -827,7 +868,7 @@ type SdkLibraryComponentDependency interface {
var _ SdkLibraryComponentDependency = (*Library)(nil)
var _ SdkLibraryComponentDependency = (*Import)(nil)
var _ SdkLibraryComponentDependency = (*SdkLibrary)(nil)
-var _ SdkLibraryComponentDependency = (*sdkLibraryImport)(nil)
+var _ SdkLibraryComponentDependency = (*SdkLibraryImport)(nil)
// Provides access to sdk_version related header and implentation jars.
type SdkLibraryDependency interface {
@@ -913,16 +954,24 @@ func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext)
return generatedScopes
}
-var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"}
+type sdkLibraryComponentTag struct {
+ blueprint.BaseDependencyTag
+ name string
+}
+
+// Mark this tag so dependencies that use it are excluded from visibility enforcement.
+func (t sdkLibraryComponentTag) ExcludeFromVisibilityEnforcement() {}
+
+var xmlPermissionsFileTag = sdkLibraryComponentTag{name: "xml-permissions-file"}
func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool {
- if dt, ok := depTag.(dependencyTag); ok {
+ if dt, ok := depTag.(sdkLibraryComponentTag); ok {
return dt == xmlPermissionsFileTag
}
return false
}
-var implLibraryTag = dependencyTag{name: "impl-library"}
+var implLibraryTag = sdkLibraryComponentTag{name: "impl-library"}
func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
for _, apiScope := range module.getGeneratedApiScopes(ctx) {
@@ -947,7 +996,7 @@ func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
if module.sharedLibrary() {
// Add dependency to the rule for generating the xml permissions file
- ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlFileName())
+ ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlPermissionsModuleName())
}
// Only add the deps for the library if it is actually going to be built.
@@ -994,20 +1043,10 @@ func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
}
entriesList := module.Library.AndroidMkEntries()
entries := &entriesList[0]
- entries.Required = append(entries.Required, module.xmlFileName())
+ entries.Required = append(entries.Required, module.xmlPermissionsModuleName())
return entriesList
}
-// Module name of the runtime implementation library
-func (module *SdkLibrary) implLibraryModuleName() string {
- return module.BaseModuleName() + ".impl"
-}
-
-// Module name of the XML file for the lib
-func (module *SdkLibrary) xmlFileName() string {
- return module.BaseModuleName() + sdkXmlFileSuffix
-}
-
// The dist path of the stub artifacts
func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string {
if module.ModuleBase.Owner() != "" {
@@ -1059,6 +1098,7 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext)
&module.protoProperties,
&module.deviceProperties,
&module.dexpreoptProperties,
+ &module.linter.properties,
&props,
module.sdkComponentPropertiesForChildLibrary(),
}
@@ -1113,7 +1153,9 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext
props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
props.Openjdk9.Srcs = module.properties.Openjdk9.Srcs
props.Openjdk9.Javacflags = module.properties.Openjdk9.Javacflags
- props.Java_version = module.properties.Java_version
+ // We compile the stubs for 1.8 in line with the main android.jar stubs, and potential
+ // interop with older developer tools that don't support 1.9.
+ props.Java_version = proptools.StringPtr("1.8")
if module.deviceProperties.Compile_dex != nil {
props.Compile_dex = module.deviceProperties.Compile_dex
}
@@ -1296,7 +1338,7 @@ func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) {
Lib_name *string
Apex_available []string
}{
- Name: proptools.StringPtr(module.xmlFileName()),
+ Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
Apex_available: module.ApexProperties.Apex_available,
}
@@ -1344,7 +1386,7 @@ func getApexNameForModule(module android.Module) string {
//
// If either this or the other module are on the platform then this will return
// false.
-func (module *SdkLibrary) withinSameApexAs(other android.Module) bool {
+func withinSameApexAs(module android.ApexModule, other android.Module) bool {
name := module.ApexName()
return name != "" && getApexNameForModule(other) == name
}
@@ -1365,7 +1407,7 @@ func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkS
// Only allow access to the implementation library in the following condition:
// * No sdk_version specified on the referencing module.
// * The referencing module is in the same apex as this.
- if sdkVersion.kind == sdkPrivate || module.withinSameApexAs(ctx.Module()) {
+ if sdkVersion.kind == sdkPrivate || withinSameApexAs(module, ctx.Module()) {
if headerJars {
return module.HeaderJars()
} else {
@@ -1502,13 +1544,8 @@ func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookCont
}
func (module *SdkLibrary) InitSdkLibraryProperties() {
- module.AddProperties(
- &module.sdkLibraryProperties,
- &module.properties,
- &module.dexpreoptProperties,
- &module.deviceProperties,
- &module.protoProperties,
- )
+ module.addHostAndDeviceProperties()
+ module.AddProperties(&module.sdkLibraryProperties)
module.initSdkLibraryComponent(&module.ModuleBase)
@@ -1575,6 +1612,24 @@ func (s *frameworkModulesNamingScheme) apiModuleName(scope *apiScope, baseName s
var _ sdkLibraryComponentNamingScheme = (*frameworkModulesNamingScheme)(nil)
+func moduleStubLinkType(name string) (stub bool, ret linkType) {
+ // This suffix-based approach is fragile and could potentially mis-trigger.
+ // TODO(b/155164730): Clean this up when modules no longer reference sdk_lib stubs directly.
+ if strings.HasSuffix(name, ".stubs.public") || strings.HasSuffix(name, "-stubs-publicapi") {
+ return true, javaSdk
+ }
+ if strings.HasSuffix(name, ".stubs.system") || strings.HasSuffix(name, "-stubs-systemapi") {
+ return true, javaSystem
+ }
+ if strings.HasSuffix(name, ".stubs.module_lib") || strings.HasSuffix(name, "-stubs-module_libs_api") {
+ return true, javaModule
+ }
+ if strings.HasSuffix(name, ".stubs.test") {
+ return true, javaSystem
+ }
+ return false, javaPlatform
+}
+
// java_sdk_library is a special Java library that provides optional platform APIs to apps.
// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
// are linked against to, 2) droiddoc module that internally generates API stubs source files,
@@ -1651,7 +1706,7 @@ type sdkLibraryImportProperties struct {
Libs []string
}
-type sdkLibraryImport struct {
+type SdkLibraryImport struct {
android.ModuleBase
android.DefaultableModuleBase
prebuilt android.Prebuilt
@@ -1664,9 +1719,17 @@ type sdkLibraryImport struct {
scopeProperties map[*apiScope]*sdkLibraryScopeProperties
commonToSdkLibraryAndImport
+
+ // The reference to the implementation library created by the source module.
+ // Is nil if the source module does not exist.
+ implLibraryModule *Library
+
+ // The reference to the xml permissions module created by the source module.
+ // Is nil if the source module does not exist.
+ xmlPermissionsFileModule *sdkLibraryXml
}
-var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
+var _ SdkLibraryDependency = (*SdkLibraryImport)(nil)
// The type of a structure that contains a field of type sdkLibraryScopeProperties
// for each apiscope in allApiScopes, e.g. something like:
@@ -1708,7 +1771,7 @@ func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProp
// java_sdk_library_import imports a prebuilt java_sdk_library.
func sdkLibraryImportFactory() android.Module {
- module := &sdkLibraryImport{}
+ module := &SdkLibraryImport{}
allScopeProperties, scopeToProperties := createPropertiesInstance()
module.scopeProperties = scopeToProperties
@@ -1730,15 +1793,15 @@ func sdkLibraryImportFactory() android.Module {
return module
}
-func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
+func (module *SdkLibraryImport) Prebuilt() *android.Prebuilt {
return &module.prebuilt
}
-func (module *sdkLibraryImport) Name() string {
+func (module *SdkLibraryImport) Name() string {
return module.prebuilt.Name(module.ModuleBase.Name())
}
-func (module *sdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) {
+func (module *SdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) {
// If the build is configured to use prebuilts then force this to be preferred.
if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
@@ -1763,7 +1826,7 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.DefaultableHo
*javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
}
-func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
+func (module *SdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
// Creates a java import for the jar with ".stubs" suffix
props := struct {
Name *string
@@ -1785,7 +1848,7 @@ func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.Defaultabl
mctx.CreateModule(ImportFactory, &props, module.sdkComponentPropertiesForChildLibrary())
}
-func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
+func (module *SdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
props := struct {
Name *string
Srcs []string
@@ -1799,7 +1862,7 @@ func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.Defaulta
props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
}
-func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
+func (module *SdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
for apiScope, scopeProperties := range module.scopeProperties {
if len(scopeProperties.Jars) == 0 {
continue
@@ -1813,13 +1876,35 @@ func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext)
ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope))
}
}
+
+ implName := module.implLibraryModuleName()
+ if ctx.OtherModuleExists(implName) {
+ ctx.AddVariationDependencies(nil, implLibraryTag, implName)
+
+ xmlPermissionsModuleName := module.xmlPermissionsModuleName()
+ if module.sharedLibrary() && ctx.OtherModuleExists(xmlPermissionsModuleName) {
+ // Add dependency to the rule for generating the xml permissions file
+ ctx.AddDependency(module, xmlPermissionsFileTag, xmlPermissionsModuleName)
+ }
+ }
+}
+
+func (module *SdkLibraryImport) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool {
+ depTag := mctx.OtherModuleDependencyTag(dep)
+ if depTag == xmlPermissionsFileTag {
+ return true
+ }
+
+ // None of the other dependencies of the java_sdk_library_import are in the same apex
+ // as the one that references this module.
+ return false
}
-func (module *sdkLibraryImport) OutputFiles(tag string) (android.Paths, error) {
+func (module *SdkLibraryImport) OutputFiles(tag string) (android.Paths, error) {
return module.commonOutputFiles(tag)
}
-func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// Record the paths to the prebuilt stubs library and stubs source.
ctx.VisitDirectDeps(func(to android.Module) {
tag := ctx.OtherModuleDependencyTag(to)
@@ -1832,6 +1917,18 @@ func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo
// Extract information from the dependency. The exact information extracted
// is determined by the nature of the dependency which is determined by the tag.
scopeTag.extractDepInfo(ctx, to, scopePaths)
+ } else if tag == implLibraryTag {
+ if implLibrary, ok := to.(*Library); ok {
+ module.implLibraryModule = implLibrary
+ } else {
+ ctx.ModuleErrorf("implementation library must be of type *java.Library but was %T", to)
+ }
+ } else if tag == xmlPermissionsFileTag {
+ if xmlPermissionsFileModule, ok := to.(*sdkLibraryXml); ok {
+ module.xmlPermissionsFileModule = xmlPermissionsFileModule
+ } else {
+ ctx.ModuleErrorf("xml permissions file module must be of type *sdkLibraryXml but was %T", to)
+ }
}
})
@@ -1847,20 +1944,75 @@ func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo
}
}
-func (module *sdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
+func (module *SdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths {
+
+ // For consistency with SdkLibrary make the implementation jar available to libraries that
+ // are within the same APEX.
+ implLibraryModule := module.implLibraryModule
+ if implLibraryModule != nil && withinSameApexAs(module, ctx.Module()) {
+ if headerJars {
+ return implLibraryModule.HeaderJars()
+ } else {
+ return implLibraryModule.ImplementationJars()
+ }
+ }
+
return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion)
}
// to satisfy SdkLibraryDependency interface
-func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
+func (module *SdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
// This module is just a wrapper for the prebuilt stubs.
- return module.sdkJars(ctx, sdkVersion)
+ return module.sdkJars(ctx, sdkVersion, true)
}
// to satisfy SdkLibraryDependency interface
-func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
+func (module *SdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
// This module is just a wrapper for the stubs.
- return module.sdkJars(ctx, sdkVersion)
+ return module.sdkJars(ctx, sdkVersion, false)
+}
+
+// to satisfy apex.javaDependency interface
+func (module *SdkLibraryImport) DexJarBuildPath() android.Path {
+ if module.implLibraryModule == nil {
+ return nil
+ } else {
+ return module.implLibraryModule.DexJarBuildPath()
+ }
+}
+
+// to satisfy apex.javaDependency interface
+func (module *SdkLibraryImport) JacocoReportClassesFile() android.Path {
+ if module.implLibraryModule == nil {
+ return nil
+ } else {
+ return module.implLibraryModule.JacocoReportClassesFile()
+ }
+}
+
+// to satisfy apex.javaDependency interface
+func (module *SdkLibraryImport) Stem() string {
+ return module.BaseModuleName()
+}
+
+var _ ApexDependency = (*SdkLibraryImport)(nil)
+
+// to satisfy java.ApexDependency interface
+func (module *SdkLibraryImport) HeaderJars() android.Paths {
+ if module.implLibraryModule == nil {
+ return nil
+ } else {
+ return module.implLibraryModule.HeaderJars()
+ }
+}
+
+// to satisfy java.ApexDependency interface
+func (module *SdkLibraryImport) ImplementationAndResourcesJars() android.Paths {
+ if module.implLibraryModule == nil {
+ return nil
+ } else {
+ return module.implLibraryModule.ImplementationAndResourcesJars()
+ }
}
//
@@ -2083,7 +2235,7 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo
if properties.RemovedApiFile != nil {
removedApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"-removed.txt")
- ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, removedApiSnapshotPath)
+ ctx.SnapshotBuilder().CopyToSnapshot(properties.RemovedApiFile, removedApiSnapshotPath)
scopeSet.AddProperty("removed_api", removedApiSnapshotPath)
}
diff --git a/java/sdk_test.go b/java/sdk_test.go
index fb8646313..e5d322c58 100644
--- a/java/sdk_test.go
+++ b/java/sdk_test.go
@@ -156,9 +156,9 @@ func TestClasspath(t *testing.T) {
{
name: "nostdlib system_modules",
- properties: `sdk_version: "none", system_modules: "core-platform-api-stubs-system-modules"`,
- system: "core-platform-api-stubs-system-modules",
- bootclasspath: []string{"core-platform-api-stubs-system-modules-lib"},
+ properties: `sdk_version: "none", system_modules: "legacy-core-platform-api-stubs-system-modules"`,
+ system: "legacy-core-platform-api-stubs-system-modules",
+ bootclasspath: []string{"legacy-core-platform-api-stubs-system-modules-lib"},
java8classpath: []string{},
},
{
@@ -252,7 +252,7 @@ func TestClasspath(t *testing.T) {
bootclasspath: []string{"android_module_lib_stubs_current", "core-lambda-stubs"},
system: "core-current-stubs-system-modules",
java9classpath: []string{"android_module_lib_stubs_current"},
- aidl: "-p" + buildDir + "/framework.aidl",
+ aidl: "-p" + buildDir + "/framework_non_updatable.aidl",
},
{
name: "system_server_current",
diff --git a/java/testing.go b/java/testing.go
index faf4d32b4..6fc10dae3 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -25,35 +25,12 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
bp += GatherRequiredDepsForTest()
mockFS := map[string][]byte{
- "a.java": nil,
- "b.java": nil,
- "c.java": nil,
- "b.kt": nil,
- "a.jar": nil,
- "b.jar": nil,
- "c.jar": nil,
- "APP_NOTICE": nil,
- "GENRULE_NOTICE": nil,
- "LIB_NOTICE": nil,
- "TOOL_NOTICE": nil,
- "AndroidTest.xml": nil,
- "java-res/a/a": nil,
- "java-res/b/b": nil,
- "java-res2/a": nil,
- "java-fg/a.java": nil,
- "java-fg/b.java": nil,
- "java-fg/c.java": nil,
"api/current.txt": nil,
"api/removed.txt": nil,
"api/system-current.txt": nil,
"api/system-removed.txt": nil,
"api/test-current.txt": nil,
"api/test-removed.txt": nil,
- "framework/aidl/a.aidl": nil,
- "aidl/foo/IFoo.aidl": nil,
- "aidl/bar/IBar.aidl": nil,
- "assets_a/a": nil,
- "assets_b/b": nil,
"prebuilts/sdk/14/public/android.jar": nil,
"prebuilts/sdk/14/public/framework.aidl": nil,
@@ -104,44 +81,12 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
"prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
"prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "30", "current"],}`),
- "prebuilts/apk/app.apk": nil,
- "prebuilts/apk/app_arm.apk": nil,
- "prebuilts/apk/app_arm64.apk": nil,
- "prebuilts/apk/app_xhdpi.apk": nil,
- "prebuilts/apk/app_xxhdpi.apk": nil,
-
- "prebuilts/apks/app.apks": nil,
-
- // For framework-res, which is an implicit dependency for framework
- "AndroidManifest.xml": nil,
- "build/make/target/product/security/testkey": nil,
-
- "build/soong/scripts/jar-wrapper.sh": nil,
-
- "build/make/core/verify_uses_libraries.sh": nil,
-
- "build/make/core/proguard.flags": nil,
- "build/make/core/proguard_basic_keeps.flags": nil,
-
- "jdk8/jre/lib/jce.jar": nil,
- "jdk8/jre/lib/rt.jar": nil,
- "jdk8/lib/tools.jar": nil,
-
- "bar-doc/a.java": nil,
- "bar-doc/b.java": nil,
- "bar-doc/IFoo.aidl": nil,
- "bar-doc/IBar.aidl": nil,
- "bar-doc/known_oj_tags.txt": nil,
- "external/doclava/templates-sdk": nil,
-
- "cert/new_cert.x509.pem": nil,
- "cert/new_cert.pk8": nil,
- "lineage.bin": nil,
-
- "testdata/data": nil,
-
- "stubs-sources/foo/Foo.java": nil,
- "stubs/sources/foo/Foo.java": nil,
+ // For java_sdk_library
+ "api/module-lib-current.txt": nil,
+ "api/module-lib-removed.txt": nil,
+ "api/system-server-current.txt": nil,
+ "api/system-server-removed.txt": nil,
+ "build/soong/scripts/gen-java-current-api-files.sh": nil,
}
cc.GatherRequiredFilesForTest(mockFS)
@@ -173,7 +118,8 @@ func GatherRequiredDepsForTest() string {
"android_module_lib_stubs_current",
"android_system_server_stubs_current",
"core.current.stubs",
- "core.platform.api.stubs",
+ "legacy.core.platform.api.stubs",
+ "stable.core.platform.api.stubs",
"kotlin-stdlib",
"kotlin-stdlib-jdk7",
"kotlin-stdlib-jdk8",
@@ -186,7 +132,7 @@ func GatherRequiredDepsForTest() string {
name: "%s",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "core-platform-api-stubs-system-modules",
+ system_modules: "legacy-core-platform-api-stubs-system-modules",
}
`, extra)
}
@@ -196,7 +142,7 @@ func GatherRequiredDepsForTest() string {
name: "framework",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "core-platform-api-stubs-system-modules",
+ system_modules: "legacy-core-platform-api-stubs-system-modules",
aidl: {
export_include_dirs: ["framework/aidl"],
},
@@ -211,7 +157,7 @@ func GatherRequiredDepsForTest() string {
name: "android.hidl.base-V1.0-java",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "core-platform-api-stubs-system-modules",
+ system_modules: "legacy-core-platform-api-stubs-system-modules",
installable: true,
}
@@ -219,7 +165,7 @@ func GatherRequiredDepsForTest() string {
name: "android.hidl.manager-V1.0-java",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "core-platform-api-stubs-system-modules",
+ system_modules: "legacy-core-platform-api-stubs-system-modules",
installable: true,
}
@@ -227,7 +173,7 @@ func GatherRequiredDepsForTest() string {
name: "org.apache.http.legacy",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "core-platform-api-stubs-system-modules",
+ system_modules: "legacy-core-platform-api-stubs-system-modules",
installable: true,
}
@@ -235,7 +181,7 @@ func GatherRequiredDepsForTest() string {
name: "android.test.base",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "core-platform-api-stubs-system-modules",
+ system_modules: "legacy-core-platform-api-stubs-system-modules",
installable: true,
}
@@ -243,14 +189,14 @@ func GatherRequiredDepsForTest() string {
name: "android.test.mock",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "core-platform-api-stubs-system-modules",
+ system_modules: "legacy-core-platform-api-stubs-system-modules",
installable: true,
}
`
systemModules := []string{
"core-current-stubs-system-modules",
- "core-platform-api-stubs-system-modules",
+ "legacy-core-platform-api-stubs-system-modules",
}
for _, extra := range systemModules {