diff options
Diffstat (limited to 'api')
| -rw-r--r-- | api/Android.bp | 4 | ||||
| -rw-r--r-- | api/StubLibraries.bp | 178 | ||||
| -rw-r--r-- | api/api.go | 88 | ||||
| -rw-r--r-- | api/api_test.go | 12 | 
4 files changed, 244 insertions, 38 deletions
diff --git a/api/Android.bp b/api/Android.bp index f5bafe8bf8da..c16bce5a1aea 100644 --- a/api/Android.bp +++ b/api/Android.bp @@ -60,14 +60,14 @@ python_test_host {  metalava_cmd = "$(location metalava)"  // Silence reflection warnings. See b/168689341  metalava_cmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED " -metalava_cmd += " --quiet --no-banner --format=v2 " +metalava_cmd += " --quiet "  genrule {      name: "current-api-xml",      tools: ["metalava"],      srcs: [":frameworks-base-api-current.txt"],      out: ["current.api"], -    cmd: metalava_cmd + "-convert2xmlnostrip $(in) $(out)", +    cmd: metalava_cmd + "signature-to-jdiff $(in) $(out)",      visibility: ["//visibility:public"],  } diff --git a/api/StubLibraries.bp b/api/StubLibraries.bp index f08745b5cd2c..9a0053f8add6 100644 --- a/api/StubLibraries.bp +++ b/api/StubLibraries.bp @@ -213,30 +213,106 @@ java_defaults {      system_modules: "none",      java_version: "1.8",      compile_dex: true, -    defaults_visibility: ["//visibility:private"],      visibility: ["//visibility:public"],  }  java_defaults { -    name: "android-non-updatable_defaults_stubs_current", -    libs: ["stub-annotations"], -    static_libs: ["framework-res-package-jar"], // Export package of framework-res +    name: "android-non-updatable_defaults",      sdk_version: "none",      system_modules: "none",      java_version: "1.8",      compile_dex: true, +} + +java_defaults { +    name: "android-non-updatable_from_source_defaults", +    libs: ["stub-annotations"], +    static_libs: ["framework-res-package-jar"], // Export package of framework-res      dist: {          targets: ["sdk"],          tag: ".jar",          dest: "android-non-updatable.jar",      }, -    defaults_visibility: ["//visibility:private"], -    visibility: ["//visibility:private"],  }  java_library {      name: "android-non-updatable.stubs", -    defaults: ["android-non-updatable_defaults_stubs_current"], +    defaults: ["android-non-updatable_defaults"], +    static_libs: [ +        "android-non-updatable.stubs.from-source", +    ], +    product_variables: { +        build_from_text_stub: { +            static_libs: [ +                "android-non-updatable.stubs.from-text", +            ], +            exclude_static_libs: [ +                "android-non-updatable.stubs.from-source", +            ], +        }, +    }, +} + +java_library { +    name: "android-non-updatable.stubs.system", +    defaults: ["android-non-updatable_defaults"], +    static_libs: [ +        "android-non-updatable.stubs.system.from-source", +    ], +    product_variables: { +        build_from_text_stub: { +            static_libs: [ +                "android-non-updatable.stubs.system.from-text", +            ], +            exclude_static_libs: [ +                "android-non-updatable.stubs.system.from-source", +            ], +        }, +    }, +} + +java_library { +    name: "android-non-updatable.stubs.module_lib", +    defaults: ["android-non-updatable_defaults"], +    static_libs: [ +        "android-non-updatable.stubs.module_lib.from-source", +    ], +    product_variables: { +        build_from_text_stub: { +            static_libs: [ +                "android-non-updatable.stubs.module_lib.from-text", +            ], +            exclude_static_libs: [ +                "android-non-updatable.stubs.module_lib.from-source", +            ], +        }, +    }, +} + +java_library { +    name: "android-non-updatable.stubs.test", +    defaults: ["android-non-updatable_defaults"], +    static_libs: [ +        "android-non-updatable.stubs.test.from-source", +    ], +    product_variables: { +        build_from_text_stub: { +            static_libs: [ +                "android-non-updatable.stubs.test.from-text", +            ], +            exclude_static_libs: [ +                "android-non-updatable.stubs.test.from-source", +            ], +        }, +    }, +} + +java_library { +    name: "android-non-updatable.stubs.from-source", +    defaults: [ +        "android-non-updatable_defaults", +        "android-non-updatable_from_source_defaults", +    ],      srcs: [":api-stubs-docs-non-updatable"],      libs: ["all-modules-public-stubs"],      dist: { @@ -245,8 +321,11 @@ java_library {  }  java_library { -    name: "android-non-updatable.stubs.system", -    defaults: ["android-non-updatable_defaults_stubs_current"], +    name: "android-non-updatable.stubs.system.from-source", +    defaults: [ +        "android-non-updatable_defaults", +        "android-non-updatable_from_source_defaults", +    ],      srcs: [":system-api-stubs-docs-non-updatable"],      libs: ["all-modules-system-stubs"],      dist: { @@ -255,8 +334,11 @@ java_library {  }  java_library { -    name: "android-non-updatable.stubs.module_lib", -    defaults: ["android-non-updatable_defaults_stubs_current"], +    name: "android-non-updatable.stubs.module_lib.from-source", +    defaults: [ +        "android-non-updatable_defaults", +        "android-non-updatable_from_source_defaults", +    ],      srcs: [":module-lib-api-stubs-docs-non-updatable"],      libs: [          "sdk_module-lib_current_framework-tethering", @@ -273,8 +355,11 @@ java_library {  }  java_library { -    name: "android-non-updatable.stubs.test", -    defaults: ["android-non-updatable_defaults_stubs_current"], +    name: "android-non-updatable.stubs.test.from-source", +    defaults: [ +        "android-non-updatable_defaults", +        "android-non-updatable_from_source_defaults", +    ],      srcs: [":test-api-stubs-docs-non-updatable"],      libs: ["all-modules-system-stubs"],      dist: { @@ -283,6 +368,57 @@ java_library {  }  java_defaults { +    name: "android-non-updatable_from_text_defaults", +    static_libs: ["framework-res-package-jar"], +    libs: ["stub-annotations"], +} + +java_api_library { +    name: "android-non-updatable.stubs.from-text", +    api_surface: "public", +    api_files: [ +        ":non-updatable-current.txt", +    ], +    defaults: ["android-non-updatable_from_text_defaults"], +    full_api_surface_stub: "android_stubs_current.from-text", +} + +java_api_library { +    name: "android-non-updatable.stubs.system.from-text", +    api_surface: "system", +    api_files: [ +        ":non-updatable-current.txt", +        ":non-updatable-system-current.txt", +    ], +    defaults: ["android-non-updatable_from_text_defaults"], +    full_api_surface_stub: "android_system_stubs_current.from-text", +} + +java_api_library { +    name: "android-non-updatable.stubs.test.from-text", +    api_surface: "test", +    api_files: [ +        ":non-updatable-current.txt", +        ":non-updatable-system-current.txt", +        ":non-updatable-test-current.txt", +    ], +    defaults: ["android-non-updatable_from_text_defaults"], +    full_api_surface_stub: "android_test_stubs_current.from-text", +} + +java_api_library { +    name: "android-non-updatable.stubs.module_lib.from-text", +    api_surface: "module_lib", +    api_files: [ +        ":non-updatable-current.txt", +        ":non-updatable-system-current.txt", +        ":non-updatable-module-lib-current.txt", +    ], +    defaults: ["android-non-updatable_from_text_defaults"], +    full_api_surface_stub: "android_module_lib_stubs_current_full.from-text", +} + +java_defaults {      name: "android_stubs_dists_default",      dist: {          targets: ["sdk"], @@ -293,7 +429,7 @@ java_defaults {  }  java_library { -    name: "android_stubs_current", +    name: "android_stubs_current.from-source",      static_libs: [          "all-modules-public-stubs",          "android-non-updatable.stubs", @@ -303,7 +439,7 @@ java_library {  }  java_library { -    name: "android_system_stubs_current", +    name: "android_system_stubs_current.from-source",      static_libs: [          "all-modules-system-stubs",          "android-non-updatable.stubs.system", @@ -327,7 +463,7 @@ java_library {  }  java_library { -    name: "android_test_stubs_current", +    name: "android_test_stubs_current.from-source",      static_libs: [          // Updatable modules do not have test APIs, but we want to include their SystemApis, like we          // include the SystemApi of framework-non-updatable-sources. @@ -347,7 +483,7 @@ java_library {  }  java_library { -    name: "android_module_lib_stubs_current", +    name: "android_module_lib_stubs_current.from-source",      defaults: [          "android.jar_defaults",          "android_stubs_dists_default", @@ -363,7 +499,7 @@ java_library {  }  java_library { -    name: "android_system_server_stubs_current", +    name: "android_system_server_stubs_current.from-source",      defaults: [          "android.jar_defaults",          "android_stubs_dists_default", @@ -371,7 +507,7 @@ java_library {      srcs: [":services-non-updatable-stubs"],      installable: false,      static_libs: [ -        "android_module_lib_stubs_current", +        "android_module_lib_stubs_current.from-source",      ],      dist: {          dir: "apistubs/android/system-server", @@ -402,7 +538,6 @@ java_library {  java_genrule {      name: "android_stubs_private_hjar", -    visibility: ["//visibility:private"],      srcs: [":android_stubs_private_jar{.hjar}"],      out: ["android_stubs_private.jar"],      cmd: "cp $(in) $(out)", @@ -411,7 +546,6 @@ java_genrule {  java_library {      name: "android_stubs_private",      defaults: ["android_stubs_dists_default"], -    visibility: ["//visibility:private"],      sdk_version: "none",      system_modules: "none",      static_libs: ["android_stubs_private_hjar"], @@ -422,7 +556,6 @@ java_library {  java_genrule {      name: "android_stubs_private_framework_aidl", -    visibility: ["//visibility:private"],      tools: ["sdkparcelables"],      srcs: [":android_stubs_private"],      out: ["framework.aidl"], @@ -586,7 +719,6 @@ droidstubs {          "metalava-manual",      ],      args: priv_apps, -    visibility: ["//visibility:private"],  }  java_library { diff --git a/api/api.go b/api/api.go index 09c238336a39..e09be03cd51d 100644 --- a/api/api.go +++ b/api/api.go @@ -15,7 +15,9 @@  package api  import ( +	"fmt"  	"sort" +	"strings"  	"github.com/google/blueprint/proptools" @@ -94,6 +96,7 @@ type libraryProps struct {  	Sdk_version *string  	Static_libs []string  	Visibility  []string +	Defaults    []string  }  type fgProps struct { @@ -102,6 +105,14 @@ type fgProps struct {  	Visibility []string  } +type defaultsProps struct { +	Name                *string +	Api_surface         *string +	Api_contributions   []string +	Defaults_visibility []string +	Previous_api        *string +} +  type Bazel_module struct {  	Bp2build_available *bool  } @@ -135,7 +146,7 @@ func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {  	metalavaCmd := "$(location metalava)"  	// Silence reflection warnings. See b/168689341  	metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED " -	metalavaCmd += " --quiet --no-banner --format=v2 " +	metalavaCmd += " --quiet merge-signatures --format=v2 "  	filename := txt.TxtFilename  	if txt.Scope != "public" { @@ -145,7 +156,7 @@ func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {  	props.Name = proptools.StringPtr(ctx.ModuleName() + "-" + filename)  	props.Tools = []string{"metalava"}  	props.Out = []string{filename} -	props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --api $(out)") +	props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")  	props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)  	props.Dists = []android.Dist{  		{ @@ -164,26 +175,26 @@ func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {  }  func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) { -	for _, i := range []struct{ +	for _, i := range []struct {  		name    string  		tag     string  		modules []string  	}{  		{ -			name: "all-modules-public-annotations", -			tag:  "{.public.annotations.zip}", +			name:    "all-modules-public-annotations", +			tag:     "{.public.annotations.zip}",  			modules: modules,  		}, { -			name: "all-modules-system-annotations", -			tag:  "{.system.annotations.zip}", +			name:    "all-modules-system-annotations", +			tag:     "{.system.annotations.zip}",  			modules: modules,  		}, { -			name: "all-modules-module-lib-annotations", -			tag:  "{.module-lib.annotations.zip}", +			name:    "all-modules-module-lib-annotations", +			tag:     "{.module-lib.annotations.zip}",  			modules: modules,  		}, { -			name: "all-modules-system-server-annotations", -			tag:  "{.system-server.annotations.zip}", +			name:    "all-modules-system-server-annotations", +			tag:     "{.system-server.annotations.zip}",  			modules: system_server_modules,  		},  	} { @@ -329,6 +340,55 @@ func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_  	}  } +func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) { +	defaultsSdkKinds := []android.SdkKind{ +		android.SdkPublic, android.SdkSystem, android.SdkModule, +	} +	for _, sdkKind := range defaultsSdkKinds { +		props := defaultsProps{} +		props.Name = proptools.StringPtr( +			sdkKind.DefaultJavaLibraryName() + "_contributions") +		if sdkKind == android.SdkModule { +			props.Name = proptools.StringPtr( +				sdkKind.DefaultJavaLibraryName() + "_contributions_full") +		} +		props.Api_surface = proptools.StringPtr(sdkKind.String()) +		apiSuffix := "" +		if sdkKind != android.SdkPublic { +			apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_") +		} +		props.Api_contributions = transformArray( +			modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix)) +		props.Defaults_visibility = []string{"//visibility:public"} +		props.Previous_api = proptools.StringPtr(":android.api.public.latest") +		ctx.CreateModule(java.DefaultsFactory, &props) +	} +} + +func createFullApiLibraries(ctx android.LoadHookContext) { +	javaLibraryNames := []string{ +		"android_stubs_current", +		"android_system_stubs_current", +		"android_test_stubs_current", +		"android_module_lib_stubs_current", +		"android_system_server_stubs_current", +	} + +	for _, libraryName := range javaLibraryNames { +		props := libraryProps{} +		props.Name = proptools.StringPtr(libraryName) +		staticLib := libraryName + ".from-source" +		if ctx.Config().BuildFromTextStub() { +			staticLib = libraryName + ".from-text" +		} +		props.Static_libs = []string{staticLib} +		props.Defaults = []string{"android.jar_defaults"} +		props.Visibility = []string{"//visibility:public"} + +		ctx.CreateModule(java.LibraryFactory, &props) +	} +} +  func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {  	bootclasspath := a.properties.Bootclasspath  	system_server_classpath := a.properties.System_server_classpath @@ -347,6 +407,10 @@ func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {  	createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)  	createPublicStubsSourceFilegroup(ctx, bootclasspath) + +	createApiContributionDefaults(ctx, bootclasspath) + +	createFullApiLibraries(ctx)  }  func combinedApisModuleFactory() android.Module { @@ -374,7 +438,7 @@ func (a *CombinedApis) ConvertWithBp2build(ctx android.TopDownMutatorContext) {  		"system-server": "-system-server-current.txt",  	} -	for scopeName, suffix := range scopeToSuffix{ +	for scopeName, suffix := range scopeToSuffix {  		name := a.Name() + suffix  		var scope bazel.StringAttribute diff --git a/api/api_test.go b/api/api_test.go index 15b695ca0d36..1f4c2af32493 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -19,6 +19,7 @@ import (  	"android/soong/android"  	"android/soong/bp2build" +	"android/soong/java"  )  func runCombinedApisTestCaseWithRegistrationCtxFunc(t *testing.T, tc bp2build.Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) { @@ -30,7 +31,9 @@ func runCombinedApisTestCaseWithRegistrationCtxFunc(t *testing.T, tc bp2build.Bp  func runCombinedApisTestCase(t *testing.T, tc bp2build.Bp2buildTestCase) {  	t.Helper() -	runCombinedApisTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {}) +	runCombinedApisTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) { +		ctx.RegisterModuleType("java_defaults", java.DefaultsFactory) +	})  }  func TestCombinedApisGeneral(t *testing.T) { @@ -42,6 +45,13 @@ func TestCombinedApisGeneral(t *testing.T) {      system_server_classpath: ["ssc"],  }  `, +		Filesystem: map[string]string{ +			"a/Android.bp": ` +			java_defaults { +				name: "android.jar_defaults", +			} +			`, +		},  		ExpectedBazelTargets: []string{  			bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-current.txt", bp2build.AttrNameToString{  				"scope": `"public"`,  |