diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/dex.go | 11 | ||||
-rw-r--r-- | java/droidstubs.go | 25 | ||||
-rw-r--r-- | java/droidstubs_test.go | 24 | ||||
-rw-r--r-- | java/java.go | 32 | ||||
-rw-r--r-- | java/java_test.go | 14 | ||||
-rw-r--r-- | java/sdk_library.go | 2 |
6 files changed, 96 insertions, 12 deletions
diff --git a/java/dex.go b/java/dex.go index 971da925e..b6fe10982 100644 --- a/java/dex.go +++ b/java/dex.go @@ -90,6 +90,7 @@ type dexer struct { // list of extra proguard flag files extraProguardFlagFiles android.Paths proguardDictionary android.OptionalPath + proguardConfiguration android.OptionalPath proguardUsageZip android.OptionalPath providesTransitiveHeaderJars @@ -133,17 +134,18 @@ var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8", var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8", blueprint.RuleParams{ Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + - `rm -f "$outDict" && rm -rf "${outUsageDir}" && ` + + `rm -f "$outDict" && rm -f "$outConfig" && rm -rf "${outUsageDir}" && ` + `mkdir -p $$(dirname ${outUsage}) && ` + `mkdir -p $$(dirname $tmpJar) && ` + `${config.Zip2ZipCmd} -i $in -o $tmpJar -x '**/*.dex' && ` + `$r8Template${config.R8Cmd} ${config.R8Flags} -injars $tmpJar --output $outDir ` + `--no-data-resources ` + `-printmapping ${outDict} ` + + `--pg-conf-output ${outConfig} ` + `-printusage ${outUsage} ` + `--deps-file ${out}.d ` + `$r8Flags && ` + - `touch "${outDict}" "${outUsage}" && ` + + `touch "${outDict}" "${outConfig}" "${outUsage}" && ` + `${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` + `rm -rf ${outUsageDir} && ` + `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` + @@ -179,7 +181,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8", ExecStrategy: "${config.RER8ExecStrategy}", Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, }, - }, []string{"outDir", "outDict", "outUsage", "outUsageZip", "outUsageDir", + }, []string{"outDir", "outDict", "outConfig", "outUsage", "outUsageZip", "outUsageDir", "r8Flags", "zipFlags", "tmpJar", "mergeZipsFlags"}, []string{"implicits"}) func (d *dexer) dexCommonFlags(ctx android.ModuleContext, @@ -370,6 +372,8 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi if useR8 { proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary") d.proguardDictionary = android.OptionalPathForPath(proguardDictionary) + proguardConfiguration := android.PathForModuleOut(ctx, "proguard_configuration") + d.proguardConfiguration = android.OptionalPathForPath(proguardConfiguration) proguardUsageDir := android.PathForModuleOut(ctx, "proguard_usage") proguardUsage := proguardUsageDir.Join(ctx, ctx.Namespace().Path, android.ModuleNameWithPossibleOverride(ctx), "unused.txt") @@ -382,6 +386,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi "r8Flags": strings.Join(append(commonFlags, r8Flags...), " "), "zipFlags": zipFlags, "outDict": proguardDictionary.String(), + "outConfig": proguardConfiguration.String(), "outUsageDir": proguardUsageDir.String(), "outUsage": proguardUsage.String(), "outUsageZip": proguardUsageZip.String(), diff --git a/java/droidstubs.go b/java/droidstubs.go index 4bbe70ac4..7ea8d305a 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -148,6 +148,10 @@ type DroidstubsProperties struct { // path or filegroup to file defining extension an SDK name <-> numerical ID mapping and // what APIs exist in which SDKs; passed to metalava via --sdk-extensions-info Extensions_info_file *string `android:"path"` + + // API surface of this module. If set, the module contributes to an API surface. + // For the full list of available API surfaces, refer to soong/android/sdk_version.go + Api_surface *string } // Used by xsd_config @@ -178,6 +182,10 @@ func DroidstubsFactory() android.Module { &module.Javadoc.properties) InitDroiddocModule(module, android.HostAndDeviceSupported) + + module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { + module.createApiContribution(ctx) + }) return module } @@ -862,6 +870,23 @@ func (d *Droidstubs) ConvertWithApiBp2build(ctx android.TopDownMutatorContext) { }, attrs) } +func (d *Droidstubs) createApiContribution(ctx android.DefaultableHookContext) { + api_file := d.properties.Check_api.Current.Api_file + api_surface := d.properties.Api_surface + + props := struct { + Name *string + Api_surface *string + Api_file *string + }{} + + props.Name = proptools.StringPtr(d.Name() + ".api.contribution") + props.Api_surface = api_surface + props.Api_file = api_file + + ctx.CreateModule(ApiContributionFactory, &props) +} + // TODO (b/262014796): Export the API contributions of CorePlatformApi // A map to populate the api surface of a droidstub from a substring appearing in its name // This map assumes that droidstubs (either checked-in or created by java_sdk_library) diff --git a/java/droidstubs_test.go b/java/droidstubs_test.go index ef2e6dc8a..6c2293746 100644 --- a/java/droidstubs_test.go +++ b/java/droidstubs_test.go @@ -346,3 +346,27 @@ func TestApiSurfaceFromDroidStubsName(t *testing.T) { android.AssertStringEquals(t, tc.desc, tc.expectedApiSurface, bazelApiSurfaceName(tc.name)) } } + +func TestDroidStubsApiContributionGeneration(t *testing.T) { + ctx, _ := testJavaWithFS(t, ` + droidstubs { + name: "foo", + srcs: ["A/a.java"], + api_surface: "public", + check_api: { + current: { + api_file: "A/current.txt", + removed_api_file: "A/removed.txt", + } + } + } + `, + map[string][]byte{ + "A/a.java": nil, + "A/current.txt": nil, + "A/removed.txt": nil, + }, + ) + + ctx.ModuleForTests("foo.api.contribution", "") +} diff --git a/java/java.go b/java/java.go index 7078cc38f..659f98a7c 100644 --- a/java/java.go +++ b/java/java.go @@ -1594,7 +1594,11 @@ type JavaApiImportInfo struct { var JavaApiImportProvider = blueprint.NewProvider(JavaApiImportInfo{}) func (ap *JavaApiContribution) GenerateAndroidBuildActions(ctx android.ModuleContext) { - apiFile := android.PathForModuleSrc(ctx, String(ap.properties.Api_file)) + var apiFile android.Path = nil + if apiFileString := ap.properties.Api_file; apiFileString != nil { + apiFile = android.PathForModuleSrc(ctx, String(apiFileString)) + } + ctx.SetProvider(JavaApiImportProvider, JavaApiImportInfo{ ApiFile: apiFile, }) @@ -1725,7 +1729,11 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { switch tag { case javaApiContributionTag: provider := ctx.OtherModuleProvider(dep, JavaApiImportProvider).(JavaApiImportInfo) - srcFiles = append(srcFiles, android.PathForSource(ctx, provider.ApiFile.String())) + providerApiFile := provider.ApiFile + if providerApiFile == nil { + ctx.ModuleErrorf("Error: %s has an empty api file.", dep.Name()) + } + srcFiles = append(srcFiles, android.PathForSource(ctx, providerApiFile.String())) case libTag: provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo) classPaths = append(classPaths, provider.HeaderJars...) @@ -2595,7 +2603,7 @@ type bp2BuildJavaInfo struct { // to be returned to the calling function. func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) (*javaCommonAttributes, *bp2BuildJavaInfo) { var srcs bazel.LabelListAttribute - var deps bazel.LabelList + var deps bazel.LabelListAttribute var staticDeps bazel.LabelList archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{}) @@ -2701,11 +2709,17 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) Javacopts: bazel.MakeStringListAttribute(javacopts), } - if m.properties.Libs != nil { - for _, d := range m.properties.Libs { - neverlinkLabel := android.BazelLabelForModuleDepSingle(ctx, d) - neverlinkLabel.Label = neverlinkLabel.Label + "-neverlink" - deps.Add(&neverlinkLabel) + for axis, configToProps := range archVariantProps { + for config, _props := range configToProps { + if archProps, ok := _props.(*CommonProperties); ok { + var libLabels []bazel.Label + for _, d := range archProps.Libs { + neverlinkLabel := android.BazelLabelForModuleDepSingle(ctx, d) + neverlinkLabel.Label = neverlinkLabel.Label + "-neverlink" + libLabels = append(libLabels, neverlinkLabel) + } + deps.SetSelectValue(axis, config, bazel.MakeLabelList(libLabels)) + } } } @@ -2723,7 +2737,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) staticDeps.Add(protoDepLabel) depLabels := &javaDependencyLabels{} - depLabels.Deps = bazel.MakeLabelListAttribute(deps) + depLabels.Deps = deps depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps) bp2BuildInfo := &bp2BuildJavaInfo{ diff --git a/java/java_test.go b/java/java_test.go index ae77842a5..04a112c0a 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1840,6 +1840,20 @@ func TestDeviceBinaryWrapperGeneration(t *testing.T) { }`) } +func TestJavaApiContributionEmptyApiFile(t *testing.T) { + testJavaError(t, + "Error: foo has an empty api file.", + `java_api_contribution { + name: "foo", + } + java_api_library { + name: "bar", + api_surface: "public", + api_contributions: ["foo"], + } + `) +} + func TestJavaApiLibraryAndProviderLink(t *testing.T) { provider_bp_a := ` java_api_contribution { diff --git a/java/sdk_library.go b/java/sdk_library.go index 3b64bf733..b87236596 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1599,6 +1599,7 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC Srcs []string Installable *bool Sdk_version *string + Api_surface *string System_modules *string Libs []string Output_javadoc_comments *bool @@ -1638,6 +1639,7 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC props.Srcs = append(props.Srcs, module.properties.Srcs...) props.Srcs = append(props.Srcs, module.sdkLibraryProperties.Api_srcs...) props.Sdk_version = module.deviceProperties.Sdk_version + props.Api_surface = &apiScope.name props.System_modules = module.deviceProperties.System_modules props.Installable = proptools.BoolPtr(false) // A droiddoc module has only one Libs property and doesn't distinguish between |