diff --git a/apex/apex_test.go b/apex/apex_test.go index 4a6aecfdf..7c82b0562 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -259,6 +259,7 @@ func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*andr java.RegisterSystemModulesBuildComponents(ctx) java.RegisterAppBuildComponents(ctx) java.RegisterSdkLibraryBuildComponents(ctx) + java.RegisterPrebuiltApisBuildComponents(ctx) ctx.RegisterSingletonType("apex_keys_text", apexKeysTextFactory) ctx.RegisterModuleType("bpf", bpf.BpfFactory) @@ -4994,6 +4995,11 @@ var filesForSdkLibrary = map[string][]byte{ "api/test-current.txt": nil, "api/test-removed.txt": nil, + "100/public/api/foo.txt": nil, + "100/public/api/foo-removed.txt": nil, + "100/system/api/foo.txt": nil, + "100/system/api/foo-removed.txt": nil, + // For java_sdk_library_import "a.jar": nil, } @@ -5018,6 +5024,11 @@ func TestJavaSDKLibrary(t *testing.T) { api_packages: ["foo"], apex_available: [ "myapex" ], } + + prebuilt_apis { + name: "sdk", + api_dirs: ["100"], + } `, withFiles(filesForSdkLibrary)) // java_sdk_library installs both impl jar and permission XML @@ -5061,6 +5072,11 @@ func TestJavaSDKLibrary_WithinApex(t *testing.T) { sdk_version: "none", system_modules: "none", } + + prebuilt_apis { + name: "sdk", + api_dirs: ["100"], + } `, withFiles(filesForSdkLibrary)) // java_sdk_library installs both impl jar and permission XML @@ -5107,6 +5123,11 @@ func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { sdk_version: "none", system_modules: "none", } + + prebuilt_apis { + name: "sdk", + api_dirs: ["100"], + } `, withFiles(filesForSdkLibrary)) // java_sdk_library installs both impl jar and permission XML @@ -5123,7 +5144,11 @@ func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { } func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { - ctx, _ := testApex(t, ``, + ctx, _ := testApex(t, ` + prebuilt_apis { + name: "sdk", + api_dirs: ["100"], + }`, withFiles(map[string][]byte{ "apex/a.java": nil, "apex/apex_manifest.json": nil, @@ -5190,7 +5215,7 @@ func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { }, } `), - }), + }), withFiles(filesForSdkLibrary), ) // java_sdk_library installs both impl jar and permission XML diff --git a/java/java_test.go b/java/java_test.go index f7cf03f4d..48d6062fd 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -83,12 +83,11 @@ func testContext(config android.Config) *android.TestContext { ctx.RegisterModuleType("python_binary_host", python.PythonBinaryHostFactory) RegisterDocsBuildComponents(ctx) RegisterStubsBuildComponents(ctx) + RegisterPrebuiltApisBuildComponents(ctx) RegisterSdkLibraryBuildComponents(ctx) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) ctx.PreArchMutators(android.RegisterComponentsMutator) - RegisterPrebuiltApisBuildComponents(ctx) - ctx.PreDepsMutators(python.RegisterPythonPreDepsMutators) ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(ctx.Context, OverlaySingletonFactory)) @@ -1813,7 +1812,7 @@ func TestJavaSdkLibrary(t *testing.T) { func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) { ctx, _ := testJava(t, ` java_sdk_library { - name: "sdk_lib", + name: "sdklib", srcs: ["a.java"], impl_only_libs: ["foo"], stub_only_libs: ["bar"], @@ -1830,13 +1829,13 @@ func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) { } `) - for _, implName := range []string{"sdk_lib", "sdk_lib.impl"} { + for _, implName := range []string{"sdklib", "sdklib.impl"} { implJavacCp := ctx.ModuleForTests(implName, "android_common").Rule("javac").Args["classpath"] if !strings.Contains(implJavacCp, "/foo.jar") || strings.Contains(implJavacCp, "/bar.jar") { t.Errorf("%v javac classpath %v does not contain foo and not bar", implName, implJavacCp) } } - stubName := apiScopePublic.stubsLibraryModuleName("sdk_lib") + stubName := apiScopePublic.stubsLibraryModuleName("sdklib") stubsJavacCp := ctx.ModuleForTests(stubName, "android_common").Rule("javac").Args["classpath"] if strings.Contains(stubsJavacCp, "/foo.jar") || !strings.Contains(stubsJavacCp, "/bar.jar") { t.Errorf("stubs javac classpath %v does not contain bar and not foo", stubsJavacCp) diff --git a/java/sdk_library.go b/java/sdk_library.go index 2e10f9c71..c6a9527b6 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -453,6 +453,10 @@ type sdkLibraryProperties struct { // * Removed API specification filegroup -> -removed.api..latest Dist_stem *string + // A compatibility mode that allows historical API-tracking files to not exist. + // Do not use. + Unsafe_ignore_missing_latest_api bool + // indicates whether system and test apis should be generated. Generate_system_and_test_apis bool `blueprint:"mutated"` @@ -1352,6 +1356,8 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC // check against the not-yet-release API props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) + // TODO(b/176092454): change true to module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api + props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true) if !apiScope.unstable { // check against the latest released API @@ -1359,7 +1365,6 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC props.Check_api.Last_released.Api_file = latestApiFilegroupName props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( module.latestRemovedApiFilegroupName(apiScope)) - props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true) if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) { // Enable api lint. diff --git a/java/testing.go b/java/testing.go index ab1312178..fc4e4775b 100644 --- a/java/testing.go +++ b/java/testing.go @@ -39,59 +39,8 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string "api/test-current.txt": nil, "api/test-removed.txt": nil, - "prebuilts/sdk/14/public/android.jar": nil, - "prebuilts/sdk/14/public/framework.aidl": nil, - "prebuilts/sdk/14/system/android.jar": nil, - "prebuilts/sdk/17/public/android.jar": nil, - "prebuilts/sdk/17/public/framework.aidl": nil, - "prebuilts/sdk/17/system/android.jar": nil, - "prebuilts/sdk/28/public/android.jar": nil, - "prebuilts/sdk/28/public/framework.aidl": nil, - "prebuilts/sdk/28/system/android.jar": nil, - "prebuilts/sdk/29/public/android.jar": nil, - "prebuilts/sdk/29/public/framework.aidl": nil, - "prebuilts/sdk/29/system/android.jar": nil, - "prebuilts/sdk/29/system/foo.jar": nil, - "prebuilts/sdk/30/public/android.jar": nil, - "prebuilts/sdk/30/public/framework.aidl": nil, - "prebuilts/sdk/30/system/android.jar": nil, - "prebuilts/sdk/30/system/foo.jar": nil, - "prebuilts/sdk/30/module-lib/android.jar": nil, - "prebuilts/sdk/30/module-lib/foo.jar": nil, - "prebuilts/sdk/30/public/core-for-system-modules.jar": nil, - "prebuilts/sdk/current/core/android.jar": nil, - "prebuilts/sdk/current/public/android.jar": nil, - "prebuilts/sdk/current/public/framework.aidl": nil, - "prebuilts/sdk/current/public/core.jar": nil, - "prebuilts/sdk/current/public/core-for-system-modules.jar": nil, - "prebuilts/sdk/current/system/android.jar": nil, - "prebuilts/sdk/current/test/android.jar": nil, - "prebuilts/sdk/28/public/api/foo.txt": nil, - "prebuilts/sdk/28/system/api/foo.txt": nil, - "prebuilts/sdk/28/test/api/foo.txt": nil, - "prebuilts/sdk/28/public/api/foo-removed.txt": nil, - "prebuilts/sdk/28/system/api/foo-removed.txt": nil, - "prebuilts/sdk/28/test/api/foo-removed.txt": nil, - "prebuilts/sdk/28/public/api/bar.txt": nil, - "prebuilts/sdk/28/system/api/bar.txt": nil, - "prebuilts/sdk/28/test/api/bar.txt": nil, - "prebuilts/sdk/28/public/api/bar-removed.txt": nil, - "prebuilts/sdk/28/system/api/bar-removed.txt": nil, - "prebuilts/sdk/28/test/api/bar-removed.txt": nil, - "prebuilts/sdk/30/public/api/foo.txt": nil, - "prebuilts/sdk/30/system/api/foo.txt": nil, - "prebuilts/sdk/30/test/api/foo.txt": nil, - "prebuilts/sdk/30/public/api/foo-removed.txt": nil, - "prebuilts/sdk/30/system/api/foo-removed.txt": nil, - "prebuilts/sdk/30/test/api/foo-removed.txt": nil, - "prebuilts/sdk/30/public/api/bar.txt": nil, - "prebuilts/sdk/30/system/api/bar.txt": nil, - "prebuilts/sdk/30/test/api/bar.txt": nil, - "prebuilts/sdk/30/public/api/bar-removed.txt": nil, - "prebuilts/sdk/30/system/api/bar-removed.txt": nil, - "prebuilts/sdk/30/test/api/bar-removed.txt": nil, - "prebuilts/sdk/tools/core-lambda-stubs.jar": nil, - "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "30", "current"], imports_sdk_version: "none", imports_compile_dex:true,}`), + "prebuilts/sdk/tools/core-lambda-stubs.jar": nil, + "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "30", "current"], imports_sdk_version: "none", imports_compile_dex:true,}`), "bin.py": nil, python.StubTemplateHost: []byte(`PYTHON_BINARY = '%interpreter%' @@ -104,6 +53,16 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string "api/system-server-removed.txt": nil, } + levels := []string{"14", "28", "29", "30", "current"} + libs := []string{ + "android", "foo", "bar", "sdklib", "barney", "betty", "foo-shared_library", + "foo-no_shared_library", "core-for-system-modules", "quuz", "qux", "fred", + "runtime-library", + } + for k, v := range prebuiltApisFilesForLibs(levels, libs) { + mockFS[k] = v + } + cc.GatherRequiredFilesForTest(mockFS) for k, v := range fs { @@ -121,6 +80,21 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string return config } +func prebuiltApisFilesForLibs(apiLevels []string, sdkLibs []string) map[string][]byte { + fs := make(map[string][]byte) + for _, level := range apiLevels { + for _, lib := range sdkLibs { + for _, scope := range []string{"public", "system", "module-lib", "system-server", "test"} { + fs[fmt.Sprintf("prebuilts/sdk/%s/%s/%s.jar", level, scope, lib)] = nil + fs[fmt.Sprintf("prebuilts/sdk/%s/%s/api/%s.txt", level, scope, lib)] = nil + fs[fmt.Sprintf("prebuilts/sdk/%s/%s/api/%s-removed.txt", level, scope, lib)] = nil + } + } + fs[fmt.Sprintf("prebuilts/sdk/%s/public/framework.aidl", level)] = nil + } + return fs +} + func GatherRequiredDepsForTest() string { var bp string diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index b44f66e85..d989c5be9 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -44,6 +44,14 @@ func testSdkWithJava(t *testing.T, bp string) *testSdkResult { "api/system-server-removed.txt": nil, "build/soong/scripts/gen-java-current-api-files.sh": nil, "docs/known_doctags": nil, + "100/public/api/myjavalib.txt": nil, + "100/public/api/myjavalib-removed.txt": nil, + "100/system/api/myjavalib.txt": nil, + "100/system/api/myjavalib-removed.txt": nil, + "100/module-lib/api/myjavalib.txt": nil, + "100/module-lib/api/myjavalib-removed.txt": nil, + "100/system-server/api/myjavalib.txt": nil, + "100/system-server/api/myjavalib-removed.txt": nil, } // for java_sdk_library tests @@ -84,6 +92,10 @@ java_import { name: "framework", sdk_version: "none", } +prebuilt_apis { + name: "sdk", + api_dirs: ["100"], +} ` + bp return testSdkWithFs(t, bp, fs) diff --git a/sdk/testing.go b/sdk/testing.go index 91aa879d0..38755a9e6 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -110,6 +110,7 @@ func testSdkContext(bp string, fs map[string][]byte, extraOsTypes []android.OsTy java.RegisterJavaBuildComponents(ctx) java.RegisterAppBuildComponents(ctx) java.RegisterSdkLibraryBuildComponents(ctx) + java.RegisterPrebuiltApisBuildComponents(ctx) java.RegisterStubsBuildComponents(ctx) java.RegisterSystemModulesBuildComponents(ctx)