summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rwxr-xr-xjava/app.go13
-rw-r--r--java/droiddoc.go205
-rw-r--r--java/java.go2
-rw-r--r--java/sdk_library.go22
4 files changed, 121 insertions, 121 deletions
diff --git a/java/app.go b/java/app.go
index d25575c99..43bdc91de 100755
--- a/java/app.go
+++ b/java/app.go
@@ -80,10 +80,14 @@ type appProperties struct {
// list of native libraries that will be provided in or alongside the resulting jar
Jni_libs []string `android:"arch_variant"`
- // if true, allow JNI libraries that link against platform APIs even if this module sets
+ // if true, use JNI libraries that link against platform APIs even if this module sets
// sdk_version.
Jni_uses_platform_apis *bool
+ // if true, use JNI libraries that link against SDK APIs even if this module does not set
+ // sdk_version.
+ Jni_uses_sdk_apis *bool
+
// STL library to use for JNI libraries.
Stl *string `android:"arch_variant"`
@@ -234,7 +238,8 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
// If the app builds against an Android SDK use the SDK variant of JNI dependencies
// unless jni_uses_platform_apis is set.
if a.sdkVersion().specified() && a.sdkVersion().kind != sdkCorePlatform &&
- !Bool(a.appProperties.Jni_uses_platform_apis) {
+ !Bool(a.appProperties.Jni_uses_platform_apis) ||
+ Bool(a.appProperties.Jni_uses_sdk_apis) {
variation = append(variation, blueprint.Variation{Mutator: "sdk", Variation: "sdk"})
}
ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
@@ -714,6 +719,8 @@ func (a *AndroidApp) MarkAsCoverageVariant(coverage bool) {
a.appProperties.IsCoverageVariant = coverage
}
+func (a *AndroidApp) EnableCoverageIfNeeded() {}
+
var _ cc.Coverage = (*AndroidApp)(nil)
// android_app compiles sources and Android resources into an Android application package `.apk` file.
@@ -1391,6 +1398,8 @@ func AndroidTestImportFactory() android.Module {
module.processVariants(ctx)
})
+ module.dexpreopter.isTest = true
+
android.InitApexModule(module)
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
android.InitDefaultableModule(module)
diff --git a/java/droiddoc.go b/java/droiddoc.go
index 1c46a2b0d..879353d8b 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -1473,46 +1473,16 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
}
- if generateStubs {
- rule.Command().
- BuiltTool(ctx, "soong_zip").
- Flag("-write_if_changed").
- Flag("-jar").
- FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
- FlagWithArg("-C ", stubsDir.String()).
- FlagWithArg("-D ", stubsDir.String())
- }
-
- if Bool(d.properties.Write_sdk_values) {
- d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
- rule.Command().
- BuiltTool(ctx, "soong_zip").
- Flag("-write_if_changed").
- Flag("-d").
- FlagWithOutput("-o ", d.metadataZip).
- FlagWithArg("-C ", d.metadataDir.String()).
- FlagWithArg("-D ", d.metadataDir.String())
- }
+ // Add options for the other optional tasks: API-lint and check-released.
+ // We generate separate timestamp files for them.
- rule.Restat()
+ doApiLint := false
+ doCheckReleased := false
- zipSyncCleanupCmd(rule, srcJarDir)
-
- rule.Build(pctx, ctx, "metalava", "metalava")
-
- // Create rule for apicheck
+ // Add API lint options.
if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
- rule := android.NewRuleBuilder()
- rule.Command().Text("( true")
-
- srcJarDir := android.PathForModuleOut(ctx, "api_lint", "srcjars")
- srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
-
- cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
- deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
-
- cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
+ doApiLint = true
newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
if newSince.Valid() {
@@ -1521,35 +1491,39 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
cmd.Flag("--api-lint")
}
d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
- cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport)
-
- d.inclusionAnnotationsFlags(ctx, cmd)
- d.mergeAnnoDirFlags(ctx, cmd)
+ cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport) // TODO: Change to ":api-lint"
baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
- msg := `` +
+ // Note this string includes a special shell quote $' ... ', which decodes the "\n"s.
+ // However, because $' ... ' doesn't expand environmental variables, we can't just embed
+ // $PWD, so we have to terminate $'...', use "$PWD", then start $' ... ' again,
+ // which is why we have '"$PWD"$' in it.
+ //
+ // TODO: metalava also has a slightly different message hardcoded. Should we unify this
+ // message and metalava's one?
+ msg := `$'` + // Enclose with $' ... '
`************************************************************\n` +
`Your API changes are triggering API Lint warnings or errors.\n` +
`To make these errors go away, fix the code according to the\n` +
`error and/or warning messages above.\n` +
`\n` +
- `If it's not possible to do so, there are workarounds:\n` +
+ `If it is not possible to do so, there are workarounds:\n` +
`\n` +
- `1. You can suppress the errors with @SuppressLint(\"<id>\")\n`
+ `1. You can suppress the errors with @SuppressLint("<id>")\n`
if baselineFile.Valid() {
- cmd.FlagWithInput("--baseline ", baselineFile.Path())
- cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
+ cmd.FlagWithInput("--baseline:api-lint ", baselineFile.Path())
+ cmd.FlagWithOutput("--update-baseline:api-lint ", updatedBaselineOutput)
msg += fmt.Sprintf(``+
`2. You can update the baseline by executing the following\n`+
` command:\n`+
` cp \\ \n`+
- ` \"$PWD/%s\" \\ \n`+
- ` \"$PWD/%s\" \n`+
+ ` "'"$PWD"$'/%s" \\ \n`+
+ ` "'"$PWD"$'/%s" \n`+
` To submit the revised baseline.txt to the main Android\n`+
` repository, you will need approval.\n`, updatedBaselineOutput, baselineFile.Path())
} else {
@@ -1557,20 +1531,81 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
`2. You can add a baseline file of existing lint failures\n`+
` to the build rule of %s.\n`, d.Name())
}
- msg += `************************************************************\n`
+ // Note the message ends with a ' (single quote), to close the $' ... ' .
+ msg += `************************************************************\n'`
- zipSyncCleanupCmd(rule, srcJarDir)
+ cmd.FlagWithArg("--error-message:api-lint ", msg)
+ }
+
+ // Add "check released" options. (Detect incompatible API changes from the last public release)
+
+ if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
+ !ctx.Config().IsPdkBuild() {
+ doCheckReleased = true
+
+ if len(d.Javadoc.properties.Out) > 0 {
+ ctx.PropertyErrorf("out", "out property may not be combined with check_api")
+ }
+ apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
+ removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
+ baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
+ updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
+
+ d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
+
+ cmd.FlagWithInput("--check-compatibility:api:released ", apiFile)
+ cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
+
+ if baselineFile.Valid() {
+ cmd.FlagWithInput("--baseline:compatibility:released ", baselineFile.Path())
+ cmd.FlagWithOutput("--update-baseline:compatibility:released ", updatedBaselineOutput)
+ }
+
+ // Note this string includes quote ($' ... '), which decodes the "\n"s.
+ msg := `$'\n******************************\n` +
+ `You have tried to change the API from what has been previously released in\n` +
+ `an SDK. Please fix the errors listed above.\n` +
+ `******************************\n'`
+
+ cmd.FlagWithArg("--error-message:compatibility:released ", msg)
+ }
+
+ if generateStubs {
rule.Command().
- Text("touch").Output(d.apiLintTimestamp).
- Text(") || (").
- Text("echo").Flag("-e").Flag(`"` + msg + `"`).
- Text("; exit 38").
- Text(")")
+ BuiltTool(ctx, "soong_zip").
+ Flag("-write_if_changed").
+ Flag("-jar").
+ FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
+ FlagWithArg("-C ", stubsDir.String()).
+ FlagWithArg("-D ", stubsDir.String())
+ }
- rule.Build(pctx, ctx, "metalavaApiLint", "metalava API lint")
+ if Bool(d.properties.Write_sdk_values) {
+ d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
+ rule.Command().
+ BuiltTool(ctx, "soong_zip").
+ Flag("-write_if_changed").
+ Flag("-d").
+ FlagWithOutput("-o ", d.metadataZip).
+ FlagWithArg("-C ", d.metadataDir.String()).
+ FlagWithArg("-D ", d.metadataDir.String())
+ }
+ // TODO: We don't really need two separate API files, but this is a reminiscence of how
+ // we used to run metalava separately for API lint and the "last_released" check. Unify them.
+ if doApiLint {
+ rule.Command().Text("touch").Output(d.apiLintTimestamp)
}
+ if doCheckReleased {
+ rule.Command().Text("touch").Output(d.checkLastReleasedApiTimestamp)
+ }
+
+ rule.Restat()
+
+ zipSyncCleanupCmd(rule, srcJarDir)
+
+ rule.Build(pctx, ctx, "metalava", "metalava merged")
if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
!ctx.Config().IsPdkBuild() {
@@ -1584,7 +1619,7 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
if baselineFile.Valid() {
- ctx.PropertyErrorf("current API check can't have a baseline file. (module %s)", ctx.ModuleName())
+ ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName())
}
d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
@@ -1592,8 +1627,8 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
rule := android.NewRuleBuilder()
// Diff command line.
- // -F matches the closest "opening" line, such as "package xxx{"
- // and " public class Yyy {".
+ // -F matches the closest "opening" line, such as "package android {"
+ // and " public class Intent {".
diff := `diff -u -F '{ *$'`
rule.Command().Text("( true")
@@ -1652,60 +1687,6 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
}
- if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
- !ctx.Config().IsPdkBuild() {
-
- if len(d.Javadoc.properties.Out) > 0 {
- ctx.PropertyErrorf("out", "out property may not be combined with check_api")
- }
-
- apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
- removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
- baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
- updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
-
- d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
-
- rule := android.NewRuleBuilder()
-
- rule.Command().Text("( true")
-
- srcJarDir := android.PathForModuleOut(ctx, "last-apicheck", "srcjars")
- srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
-
- cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
- deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
-
- cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
- FlagWithInput("--check-compatibility:api:released ", apiFile)
-
- d.inclusionAnnotationsFlags(ctx, cmd)
-
- cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
-
- d.mergeAnnoDirFlags(ctx, cmd)
-
- if baselineFile.Valid() {
- cmd.FlagWithInput("--baseline ", baselineFile.Path())
- cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
- }
-
- zipSyncCleanupCmd(rule, srcJarDir)
-
- msg := `\n******************************\n` +
- `You have tried to change the API from what has been previously released in\n` +
- `an SDK. Please fix the errors listed above.\n` +
- `******************************\n`
- rule.Command().
- Text("touch").Output(d.checkLastReleasedApiTimestamp).
- Text(") || (").
- Text("echo").Flag("-e").Flag(`"` + msg + `"`).
- Text("; exit 38").
- Text(")")
-
- rule.Build(pctx, ctx, "metalavaLastApiCheck", "metalava check last API")
- }
-
if String(d.properties.Check_nullability_warnings) != "" {
if d.nullabilityWarningsFile == nil {
ctx.PropertyErrorf("check_nullability_warnings",
diff --git a/java/java.go b/java/java.go
index 472d3dac4..9d75c74c7 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1906,7 +1906,7 @@ func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMembe
type librarySdkMemberProperties struct {
android.SdkMemberPropertiesBase
- JarToExport android.Path
+ JarToExport android.Path `android:"arch_variant"`
AidlIncludeDirs android.Paths
}
diff --git a/java/sdk_library.go b/java/sdk_library.go
index d70f6320d..39c118d34 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -67,6 +67,9 @@ type apiScope struct {
// The name of the api scope, e.g. public, system, test
name string
+ // The api scope that this scope extends.
+ extends *apiScope
+
// The name of the field in the dynamically created structure.
fieldName string
@@ -134,6 +137,7 @@ var (
})
apiScopeSystem = initApiScope(&apiScope{
name: "system",
+ extends: apiScopePublic,
apiFilePrefix: "system-",
moduleSuffix: sdkSystemApiSuffix,
sdkVersion: "system_current",
@@ -141,6 +145,7 @@ var (
})
apiScopeTest = initApiScope(&apiScope{
name: "test",
+ extends: apiScopePublic,
apiFilePrefix: "test-",
moduleSuffix: sdkTestApiSuffix,
sdkVersion: "test_current",
@@ -382,7 +387,7 @@ func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string {
}
// Get the sdk version for use when compiling the stubs library.
-func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) string {
+func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) string {
sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
if sdkDep.hasStandardLibs() {
// If building against a standard sdk then use the sdk version appropriate for the scope.
@@ -402,7 +407,7 @@ func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) stri
}
// Creates a static java library that has API stubs
-func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) {
+func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) {
props := struct {
Name *string
Srcs []string
@@ -473,7 +478,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc
// Creates a droidstubs module that creates stubs source files from the given full source
// files
-func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiScope *apiScope) {
+func (module *SdkLibrary) createStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope) {
props := struct {
Name *string
Srcs []string
@@ -592,7 +597,7 @@ func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep an
}
// Creates the xml file that publicizes the runtime library
-func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
+func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) {
props := struct {
Name *string
Lib_name *string
@@ -713,7 +718,12 @@ func (module *SdkLibrary) getApiDir() string {
// For a java_sdk_library module, create internal modules for stubs, docs,
// runtime libs and xml file. If requested, the stubs and docs are created twice
// once for public API level and once for system API level
-func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
+func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) {
+ // If the module has been disabled then don't create any child modules.
+ if !module.Enabled() {
+ return
+ }
+
if len(module.Library.Module.properties.Srcs) == 0 {
mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
return
@@ -799,7 +809,7 @@ func SdkLibraryFactory() android.Module {
module.InitSdkLibraryProperties()
android.InitApexModule(module)
InitJavaModule(module, android.HostAndDeviceSupported)
- android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
+ module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { module.CreateInternalModules(ctx) })
return module
}