diff --git a/android/neverallow.go b/android/neverallow.go index 8d2f77848..16578b271 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -109,6 +109,9 @@ func createLibcoreRules() []*rule { neverallow(). notIn(coreLibraryProjects...). with("no_standard_libs", "true"), + neverallow(). + notIn(coreLibraryProjects...). + with("sdk_version", "none"), } return rules diff --git a/android/neverallow_test.go b/android/neverallow_test.go index eea7a3915..31995166a 100644 --- a/android/neverallow_test.go +++ b/android/neverallow_test.go @@ -189,6 +189,37 @@ var neverallowTests = []struct { }`), }, }, + { + name: "sdk_version: \"none\" inside core libraries", + fs: map[string][]byte{ + "libcore/Blueprints": []byte(` + java_library { + name: "inside_core_libraries", + sdk_version: "none", + }`), + }, + }, + { + name: "sdk_version: \"none\" outside core libraries", + fs: map[string][]byte{ + "Blueprints": []byte(` + java_library { + name: "outside_core_libraries", + sdk_version: "none", + }`), + }, + expectedError: "module \"outside_core_libraries\": violates neverallow", + }, + { + name: "sdk_version: \"current\"", + fs: map[string][]byte{ + "Blueprints": []byte(` + java_library { + name: "outside_core_libraries", + sdk_version: "current", + }`), + }, + }, // java_library_host rule tests { name: "java_library_host with no_standard_libs: true", @@ -277,6 +308,7 @@ func (p *mockCcLibraryModule) GenerateAndroidBuildActions(ModuleContext) { type mockJavaLibraryProperties struct { Libs []string No_standard_libs *bool + Sdk_version *string } type mockJavaLibraryModule struct { diff --git a/java/java.go b/java/java.go index 82f799e83..c42ca28e8 100644 --- a/java/java.go +++ b/java/java.go @@ -682,7 +682,7 @@ func getLinkType(m *Module, name string) (ret linkType, stubs bool) { return javaSdk, true case ver == "current": return javaSdk, false - case ver == "": + case ver == "" || ver == "none": return javaPlatform, false default: if _, err := strconv.Atoi(ver); err != nil { @@ -860,7 +860,7 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sd var ret string v := sdkContext.sdkVersion() // For PDK builds, use the latest SDK version instead of "current" - if ctx.Config().IsPdkBuild() && (v == "" || v == "current") { + if ctx.Config().IsPdkBuild() && (v == "" || v == "none" || v == "current") { sdkVersions := ctx.Config().Get(sdkVersionsKey).([]int) latestSdkVersion := 0 if len(sdkVersions) > 0 { @@ -879,7 +879,7 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sd ret = "1.7" } else if ctx.Device() && sdk <= 29 || !ctx.Config().TargetOpenJDK9() { ret = "1.8" - } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel { + } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdkContext.sdkVersion() != "none" && sdk == android.FutureApiLevel { // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current" ret = "1.8" } else { diff --git a/java/java_test.go b/java/java_test.go index f04bbe440..af091a638 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -842,6 +842,19 @@ func TestExcludeFileGroupInSrcs(t *testing.T) { } } +func TestJavaLibrary(t *testing.T) { + config := testConfig(nil) + ctx := testContext(config, "", map[string][]byte{ + "libcore/Android.bp": []byte(` + java_library { + name: "core", + sdk_version: "none", + system_modules: "none", + }`), + }) + run(t, ctx, config) +} + func TestJavaSdkLibrary(t *testing.T) { ctx := testJava(t, ` droiddoc_template { diff --git a/java/sdk.go b/java/sdk.go index 76d36f6bd..9dfb38bf4 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -54,7 +54,7 @@ type sdkContext interface { func sdkVersionOrDefault(ctx android.BaseModuleContext, v string) string { switch v { - case "", "current", "system_current", "test_current", "core_current": + case "", "none", "current", "system_current", "test_current", "core_current": return ctx.Config().DefaultAppTargetSdk() default: return v @@ -65,7 +65,7 @@ func sdkVersionOrDefault(ctx android.BaseModuleContext, v string) string { // it returns android.FutureApiLevel (10000). func sdkVersionToNumber(ctx android.BaseModuleContext, v string) (int, error) { switch v { - case "", "current", "test_current", "system_current", "core_current": + case "", "none", "current", "test_current", "system_current", "core_current": return ctx.Config().DefaultAppTargetSdkInt(), nil default: n := android.GetNumericSdkVersion(v) @@ -187,7 +187,7 @@ func decodeSdkDep(ctx android.BaseModuleContext, sdkContext sdkContext) sdkDep { } } - if ctx.Config().UnbundledBuildUsePrebuiltSdks() && v != "" { + if ctx.Config().UnbundledBuildUsePrebuiltSdks() && v != "" && v != "none" { return toPrebuilt(v) } @@ -201,6 +201,10 @@ func decodeSdkDep(ctx android.BaseModuleContext, sdkContext sdkContext) sdkDep { noStandardLibs: sdkContext.noStandardLibs(), noFrameworksLibs: sdkContext.noFrameworkLibs(), } + case "none": + return sdkDep{ + noStandardLibs: true, + } case "current": return toModule("android_stubs_current", "framework-res", sdkFrameworkAidlPath(ctx)) case "system_current": diff --git a/java/sdk_library.go b/java/sdk_library.go index 05c7e814d..01531c5c6 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -402,19 +402,22 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc } }{} + sdkVersion := module.sdkVersion(apiScope) sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) + if !sdkDep.hasStandardLibs() { + sdkVersion = "none" + } props.Name = proptools.StringPtr(module.stubsName(apiScope)) // sources are generated from the droiddoc props.Srcs = []string{":" + module.docsName(apiScope)} - props.Sdk_version = proptools.StringPtr(module.sdkVersion(apiScope)) + props.Sdk_version = proptools.StringPtr(sdkVersion) props.Libs = module.sdkLibraryProperties.Stub_only_libs // Unbundled apps will use the prebult one from /prebuilts/sdk if mctx.Config().UnbundledBuildUsePrebuiltSdks() { props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false) } props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) - props.No_standard_libs = proptools.BoolPtr(!sdkDep.hasStandardLibs()) props.System_modules = module.Library.Module.deviceProperties.System_modules props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags @@ -444,13 +447,13 @@ func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiS Srcs_lib *string Srcs_lib_whitelist_dirs []string Srcs_lib_whitelist_pkgs []string + Sdk_version *string Libs []string Arg_files []string Args *string Api_tag_name *string Api_filename *string Removed_api_filename *string - No_standard_libs *bool Java_version *string Merge_annotations_dirs []string Merge_inclusion_annotations_dirs []string @@ -466,10 +469,15 @@ func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiS }{} sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) + sdkVersion := "" + if !sdkDep.hasStandardLibs() { + sdkVersion = "none" + } props.Name = proptools.StringPtr(module.docsName(apiScope)) props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...) props.Srcs = append(props.Srcs, module.sdkLibraryProperties.Api_srcs...) + props.Sdk_version = proptools.StringPtr(sdkVersion) props.Installable = proptools.BoolPtr(false) // A droiddoc module has only one Libs property and doesn't distinguish between // shared libs and static libs. So we need to add both of these libs to Libs property. @@ -477,7 +485,6 @@ func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiS props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...) props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs - props.No_standard_libs = proptools.BoolPtr(!sdkDep.hasStandardLibs()) props.Java_version = module.Library.Module.properties.Java_version props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs @@ -598,7 +605,7 @@ func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) { func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths { var api, v string - if sdkVersion == "" { + if sdkVersion == "" || sdkVersion == "none" { api = "system" v = "current" } else if strings.Contains(sdkVersion, "_") { diff --git a/java/sdk_test.go b/java/sdk_test.go index 23d7a98be..1efe83b74 100644 --- a/java/sdk_test.go +++ b/java/sdk_test.go @@ -113,7 +113,7 @@ func TestClasspath(t *testing.T) { }, { - name: "nostdlib", + name: "nostdlib - no_standard_libs: true", properties: `no_standard_libs: true, system_modules: "none"`, system: "none", bootclasspath: []string{`""`}, @@ -121,12 +121,28 @@ func TestClasspath(t *testing.T) { }, { - name: "nostdlib system_modules", + name: "nostdlib", + properties: `sdk_version: "none", system_modules: "none"`, + system: "none", + bootclasspath: []string{`""`}, + classpath: []string{}, + }, + { + + name: "nostdlib system_modules - no_standard_libs: true", properties: `no_standard_libs: true, system_modules: "core-platform-api-stubs-system-modules"`, system: "core-platform-api-stubs-system-modules", bootclasspath: []string{`""`}, classpath: []string{}, }, + { + + name: "nostdlib system_modules", + properties: `sdk_version: "none", system_modules: "core-platform-api-stubs-system-modules"`, + system: "core-platform-api-stubs-system-modules", + bootclasspath: []string{`""`}, + classpath: []string{}, + }, { name: "host default", @@ -145,11 +161,17 @@ func TestClasspath(t *testing.T) { bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"}, }, { - name: "host supported nostdlib", + name: "host supported nostdlib - no_standard_libs: true", host: android.Host, properties: `host_supported: true, no_standard_libs: true, system_modules: "none"`, classpath: []string{}, }, + { + name: "host supported nostdlib", + host: android.Host, + properties: `host_supported: true, sdk_version: "none", system_modules: "none"`, + classpath: []string{}, + }, { name: "unbundled sdk v25", diff --git a/java/testing.go b/java/testing.go index 4ab56c86a..98feb01b7 100644 --- a/java/testing.go +++ b/java/testing.go @@ -55,7 +55,7 @@ func GatherRequiredDepsForTest() string { java_library { name: "%s", srcs: ["a.java"], - no_standard_libs: true, + sdk_version: "none", system_modules: "core-platform-api-stubs-system-modules", } `, extra)