Loading android/neverallow.go +3 −0 Original line number Diff line number Diff line Loading @@ -108,6 +108,9 @@ func createLibcoreRules() []*rule { neverallow(). notIn(coreLibraryProjects...). with("no_standard_libs", "true"), neverallow(). notIn(coreLibraryProjects...). with("sdk_version", "none"), } return rules Loading android/neverallow_test.go +32 −0 Original line number Diff line number Diff line Loading @@ -178,6 +178,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", Loading Loading @@ -266,6 +297,7 @@ func (p *mockCcLibraryModule) GenerateAndroidBuildActions(ModuleContext) { type mockJavaLibraryProperties struct { Libs []string No_standard_libs *bool Sdk_version *string } type mockJavaLibraryModule struct { Loading java/java.go +3 −3 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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 { Loading @@ -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 { Loading java/java_test.go +13 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading java/sdk.go +7 −3 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) Loading Loading @@ -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) } Loading @@ -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": Loading Loading
android/neverallow.go +3 −0 Original line number Diff line number Diff line Loading @@ -108,6 +108,9 @@ func createLibcoreRules() []*rule { neverallow(). notIn(coreLibraryProjects...). with("no_standard_libs", "true"), neverallow(). notIn(coreLibraryProjects...). with("sdk_version", "none"), } return rules Loading
android/neverallow_test.go +32 −0 Original line number Diff line number Diff line Loading @@ -178,6 +178,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", Loading Loading @@ -266,6 +297,7 @@ func (p *mockCcLibraryModule) GenerateAndroidBuildActions(ModuleContext) { type mockJavaLibraryProperties struct { Libs []string No_standard_libs *bool Sdk_version *string } type mockJavaLibraryModule struct { Loading
java/java.go +3 −3 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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 { Loading @@ -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 { Loading
java/java_test.go +13 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading
java/sdk.go +7 −3 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) Loading Loading @@ -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) } Loading @@ -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": Loading