diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 66 |
1 files changed, 58 insertions, 8 deletions
diff --git a/java/java.go b/java/java.go index 35fd7c2b8..bc240508b 100644 --- a/java/java.go +++ b/java/java.go @@ -1664,6 +1664,8 @@ type ApiLibrary struct { extractedSrcJar android.WritablePath // .dex of stubs, used for hiddenapi processing dexJarFile OptionalDexJarPath + + validationPaths android.Paths } type JavaApiLibraryProperties struct { @@ -1699,6 +1701,12 @@ type JavaApiLibraryProperties struct { // The jar will also be passed to metalava as a classpath to // generate compilable stubs. System_modules *string + + // If true, the module runs validation on the API signature files provided + // by the modules passed via api_contributions by checking if the files are + // in sync with the source Java files. However, the environment variable + // DISABLE_STUB_VALIDATION has precedence over this property. + Enable_validation *bool } func ApiLibraryFactory() android.Module { @@ -1787,6 +1795,12 @@ func (al *ApiLibrary) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBui } } +func (al *ApiLibrary) addValidation(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, validationPaths android.Paths) { + for _, validationPath := range validationPaths { + cmd.Validation(validationPath) + } +} + // This method extracts the stub class files from the stub jar file provided // from full_api_surface_stub module instead of compiling the srcjar generated from invoking metalava. // This method is used because metalava can generate compilable from-text stubs only when @@ -1823,8 +1837,28 @@ func (al *ApiLibrary) extractApiSrcs(ctx android.ModuleContext, rule *android.Ru func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { apiContributions := al.properties.Api_contributions + addValidations := !ctx.Config().IsEnvTrue("DISABLE_STUB_VALIDATION") && + proptools.BoolDefault(al.properties.Enable_validation, true) for _, apiContributionName := range apiContributions { ctx.AddDependency(ctx.Module(), javaApiContributionTag, apiContributionName) + + // Add the java_api_contribution module generating droidstubs module + // as dependency when validation adding conditions are met and + // the java_api_contribution module name has ".api.contribution" suffix. + // All droidstubs-generated modules possess the suffix in the name, + // but there is no such guarantee for tests. + if addValidations { + if strings.HasSuffix(apiContributionName, ".api.contribution") { + ctx.AddDependency(ctx.Module(), metalavaCurrentApiTimestampTag, strings.TrimSuffix(apiContributionName, ".api.contribution")) + } else { + ctx.ModuleErrorf("Validation is enabled for module %s but a "+ + "current timestamp provider is not found for the api "+ + "contribution %s", + ctx.ModuleName(), + apiContributionName, + ) + } + } } ctx.AddVariationDependencies(nil, libTag, al.properties.Libs...) ctx.AddVariationDependencies(nil, staticLibTag, al.properties.Static_libs...) @@ -1862,8 +1896,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { android.PathForModuleOut(ctx, "metalava.sbox.textproto")). SandboxInputs() - var stubsDir android.OptionalPath - stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, "metalava", "stubsDir")) + stubsDir := android.OptionalPathForPath(android.PathForModuleOut(ctx, "metalava", "stubsDir")) rule.Command().Text("rm -rf").Text(stubsDir.String()) rule.Command().Text("mkdir -p").Text(stubsDir.String()) @@ -1895,6 +1928,10 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { case systemModulesTag: module := dep.(SystemModulesProvider) systemModulesPaths = append(systemModulesPaths, module.HeaderJars()...) + case metalavaCurrentApiTimestampTag: + if currentApiTimestampProvider, ok := dep.(currentApiTimestampProvider); ok { + al.validationPaths = append(al.validationPaths, currentApiTimestampProvider.CurrentApiTimestamp()) + } } }) @@ -1918,6 +1955,8 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { cmd.FlagWithInput("--migrate-nullness ", previousApi) } + al.addValidation(ctx, cmd, al.validationPaths) + al.stubsSrcJar = android.PathForModuleOut(ctx, "metalava", ctx.ModuleName()+"-"+"stubs.srcjar") al.stubsJarWithoutStaticLibs = android.PathForModuleOut(ctx, "metalava", "stubs.jar") al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), fmt.Sprintf("%s.jar", ctx.ModuleName())) @@ -2775,7 +2814,7 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module, type javaResourcesAttributes struct { Resources bazel.LabelListAttribute Resource_strip_prefix *string - Additional_resources bazel.LabelListAttribute + Additional_resources bazel.LabelListAttribute `blueprint:"mutated"` } func (m *Library) getResourceFilegroupStripPrefix(ctx android.Bp2buildMutatorContext, resourceFilegroup string) (*string, bool) { @@ -2877,6 +2916,7 @@ type javaCommonAttributes struct { Sdk_version bazel.StringAttribute Java_version bazel.StringAttribute Errorprone_force_enable bazel.BoolAttribute + Javac_shard_size *int64 } type javaDependencyLabels struct { @@ -2935,8 +2975,8 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{}) for axis, configToProps := range archVariantProps { - for config, _props := range configToProps { - if archProps, ok := _props.(*CommonProperties); ok { + for config, p := range configToProps { + if archProps, ok := p.(*CommonProperties); ok { archSrcs := android.BazelLabelForModuleSrcExcludes(ctx, archProps.Srcs, archProps.Exclude_srcs) srcs.SetSelectValue(axis, config, archSrcs) if archProps.Jarjar_rules != nil { @@ -2946,6 +2986,11 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext } } } + srcs.Append( + bazel.MakeLabelListAttribute( + android.BazelLabelForModuleSrcExcludes(ctx, + m.properties.Openjdk9.Srcs, + m.properties.Exclude_srcs))) srcs.ResolveExcludes() javaSrcPartition := "java" @@ -3029,8 +3074,9 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext plugins := bazel.MakeLabelListAttribute( android.BazelLabelForModuleDeps(ctx, m.properties.Plugins), ) - if m.properties.Javacflags != nil { - javacopts = bazel.MakeStringListAttribute(m.properties.Javacflags) + if m.properties.Javacflags != nil || m.properties.Openjdk9.Javacflags != nil { + javacopts = bazel.MakeStringListAttribute( + append(append([]string{}, m.properties.Javacflags...), m.properties.Openjdk9.Javacflags...)) } epEnabled := m.properties.Errorprone.Enabled @@ -3046,14 +3092,17 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext javacopts.Append(bazel.MakeStringListAttribute([]string{"-XepDisableAllChecks"})) } + resourcesAttrs := m.convertJavaResourcesAttributes(ctx) + commonAttrs := &javaCommonAttributes{ Srcs: javaSrcs, - javaResourcesAttributes: m.convertJavaResourcesAttributes(ctx), + javaResourcesAttributes: resourcesAttrs, Plugins: plugins, Javacopts: javacopts, Java_version: bazel.StringAttribute{Value: m.properties.Java_version}, Sdk_version: bazel.StringAttribute{Value: m.deviceProperties.Sdk_version}, Errorprone_force_enable: errorproneForceEnable, + Javac_shard_size: m.properties.Javac_shard_size, } for axis, configToProps := range archVariantProps { @@ -3071,6 +3120,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext } depLabels := &javaDependencyLabels{} + deps.Append(resourcesAttrs.Additional_resources) depLabels.Deps = deps for axis, configToProps := range archVariantProps { |