diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/androidmk_test.go | 33 | ||||
| -rwxr-xr-x | java/app.go | 2 | ||||
| -rw-r--r-- | java/droiddoc.go | 87 | ||||
| -rw-r--r-- | java/sdk_library.go | 14 |
4 files changed, 96 insertions, 40 deletions
diff --git a/java/androidmk_test.go b/java/androidmk_test.go index 7daa6244f..d471fb7d5 100644 --- a/java/androidmk_test.go +++ b/java/androidmk_test.go @@ -169,3 +169,36 @@ func TestDistWithTag(t *testing.T) { t.Errorf("did not expect explicit DistFile, got %v", without_tag_entries[0].DistFile) } } + +func TestJavaSdkLibrary_RequireXmlPermissionFile(t *testing.T) { + ctx, config := testJava(t, ` + java_sdk_library { + name: "foo-shared_library", + srcs: ["a.java"], + } + java_sdk_library { + name: "foo-no_shared_library", + srcs: ["a.java"], + shared_library: false, + } + `) + + // Verify the existence of internal modules + ctx.ModuleForTests("foo-shared_library.xml", "android_common") + + testCases := []struct { + moduleName string + expected []string + }{ + {"foo-shared_library", []string{"foo-shared_library.xml"}}, + {"foo-no_shared_library", nil}, + } + for _, tc := range testCases { + mod := ctx.ModuleForTests(tc.moduleName, "android_common").Module() + entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0] + actual := entries.EntryMap["LOCAL_REQUIRED_MODULES"] + if !reflect.DeepEqual(tc.expected, actual) { + t.Errorf("Unexpected required modules - expected: %q, actual: %q", tc.expected, actual) + } + } +} diff --git a/java/app.go b/java/app.go index 1d2c58227..c568516eb 100755 --- a/java/app.go +++ b/java/app.go @@ -151,7 +151,7 @@ func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) "allow-prereleased": strconv.FormatBool(proptools.Bool(as.properties.Prerelease)), "screen-densities": screenDensities, "sdk-version": ctx.Config().PlatformSdkVersion(), - "stem": ctx.ModuleName(), + "stem": as.BaseModuleName(), }, }) } diff --git a/java/droiddoc.go b/java/droiddoc.go index 5cb70e4cd..a0b7edfea 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -121,6 +121,10 @@ type JavadocProperties struct { // names of the output files used in args that will be generated Out []string + + // If set, metalava is sandboxed to only read files explicitly specified on the command + // line. Defaults to false. + Sandbox *bool } type ApiToCheck struct { @@ -1415,7 +1419,7 @@ func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *a } func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { - if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() { + if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() && d.apiFile != nil { if d.apiFile.String() == "" { ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.") } @@ -1435,41 +1439,25 @@ func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleB } func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths, - srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths, implicits android.Paths) *android.RuleBuilderCommand { + srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths, implicitsRsp android.WritablePath, sandbox bool) *android.RuleBuilderCommand { // Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel. rule.HighMem() cmd := rule.Command() - - var implicitsRsp android.WritablePath - if len(implicits) > 0 { - 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 - // add a large number of inputs to a file without exceeding bash command length limits (which - // would happen if we use the WriteFile rule). The cp is needed because RuleBuilder sets the - // rsp file to be ${output}.rsp. - impCmd.Text("cp").FlagWithRspFileInputList("", implicits).Output(implicitsRsp) - impRule.Build(pctx, ctx, "implicitsGen", "implicits generation") - cmd.Implicits(implicits) - cmd.Implicit(implicitsRsp) - } if ctx.Config().IsEnvTrue("RBE_METALAVA") { rule.Remoteable(android.RemoteRuleSupports{RBE: true}) - execStrategy := remoteexec.LocalExecStrategy - if v := ctx.Config().Getenv("RBE_METALAVA_EXEC_STRATEGY"); v != "" { - execStrategy = v - } - pool := "metalava" - if v := ctx.Config().Getenv("RBE_METALAVA_POOL"); v != "" { - pool = v + pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "metalava") + execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy) + labels := map[string]string{"type": "compile", "lang": "java", "compiler": "metalava"} + if !sandbox { + execStrategy = remoteexec.LocalExecStrategy + labels["shallow"] = "true" } inputs := []string{android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "metalava.jar").String()} if v := ctx.Config().Getenv("RBE_METALAVA_INPUTS"); v != "" { inputs = append(inputs, strings.Split(v, ",")...) } cmd.Text((&remoteexec.REParams{ - Labels: map[string]string{"type": "compile", "lang": "java", "compiler": "metalava", "shallow": "true"}, + Labels: labels, ExecStrategy: execStrategy, Inputs: inputs, RSPFile: implicitsRsp.String(), @@ -1483,8 +1471,17 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi FlagWithArg("-encoding ", "UTF-8"). FlagWithArg("-source ", javaVersion.String()). FlagWithRspFileInputList("@", srcs). - FlagWithInput("@", srcJarList). - FlagWithOutput("--strict-input-files:warn ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt")) + FlagWithInput("@", srcJarList) + + if javaHome := ctx.Config().Getenv("ANDROID_JAVA_HOME"); javaHome != "" { + cmd.Implicit(android.PathForSource(ctx, javaHome)) + } + + if sandbox { + cmd.FlagWithOutput("--strict-input-files ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt")) + } else { + cmd.FlagWithOutput("--strict-input-files:warn ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt")) + } if implicitsRsp != nil { cmd.FlagWithArg("--strict-input-files-exempt ", "@"+implicitsRsp.String()) @@ -1534,8 +1531,12 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars) + implicitsRsp := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"implicits.rsp") + cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList, - deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths, d.Javadoc.implicits) + deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths, implicitsRsp, + Bool(d.Javadoc.properties.Sandbox)) + cmd.Implicits(d.Javadoc.implicits) d.stubsFlags(ctx, cmd, stubsDir) @@ -1654,6 +1655,16 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { cmd.FlagWithArg("--error-message:compatibility:released ", msg) } + impRule := android.NewRuleBuilder() + impCmd := impRule.Command() + // A dummy action that copies the ninja generated rsp file to a new location. This allows us to + // add a large number of inputs to a file without exceeding bash command length limits (which + // would happen if we use the WriteFile rule). The cp is needed because RuleBuilder sets the + // rsp file to be ${output}.rsp. + impCmd.Text("cp").FlagWithRspFileInputList("", cmd.GetImplicits()).Output(implicitsRsp) + impRule.Build(pctx, ctx, "implicitsGen", "implicits generation") + cmd.Implicit(implicitsRsp) + if generateStubs { rule.Command(). BuiltTool(ctx, "soong_zip"). @@ -1836,13 +1847,19 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { Flag("-XDignore.symbol.file"). FlagWithArg("-doclet ", "jdiff.JDiff"). FlagWithInput("-docletpath ", jdiff). - Flag("-quiet"). - FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())). - FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())). - Implicit(d.apiXmlFile). - FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())). - FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())). - Implicit(d.lastReleasedApiXmlFile) + Flag("-quiet") + + if d.apiXmlFile != nil { + cmd.FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())). + FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())). + Implicit(d.apiXmlFile) + } + + if d.lastReleasedApiXmlFile != nil { + cmd.FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())). + FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())). + Implicit(d.lastReleasedApiXmlFile) + } rule.Command(). BuiltTool(ctx, "soong_zip"). diff --git a/java/sdk_library.go b/java/sdk_library.go index cc51e3abe..676557e64 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1042,8 +1042,10 @@ func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { return nil } entriesList := module.Library.AndroidMkEntries() - entries := &entriesList[0] - entries.Required = append(entries.Required, module.xmlPermissionsModuleName()) + if module.sharedLibrary() { + entries := &entriesList[0] + entries.Required = append(entries.Required, module.xmlPermissionsModuleName()) + } return entriesList } @@ -2191,8 +2193,12 @@ func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMembe properties.Jars = jars properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope) properties.StubsSrcJar = paths.stubsSrcJar.Path() - properties.CurrentApiFile = paths.currentApiFilePath.Path() - properties.RemovedApiFile = paths.removedApiFilePath.Path() + if paths.currentApiFilePath.Valid() { + properties.CurrentApiFile = paths.currentApiFilePath.Path() + } + if paths.removedApiFilePath.Valid() { + properties.RemovedApiFile = paths.removedApiFilePath.Path() + } s.Scopes[apiScope] = properties } } |