summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2019-06-11 12:31:14 +0100
committer Paul Duffin <paulduffin@google.com> 2019-06-13 19:15:10 +0100
commit52d398a84197053a624c13a0bc1cfb78df996966 (patch)
treed65ee1085e8111e36abc2f1d42b1400de1434d61
parent250e6198d45d7d29bea4c121d42afc8cb6a672d9 (diff)
Add sdk_version:"none" to replace no_standard_libs:true
Where possible this duplicates any tests that use no_standard_libs:true with ones that use sdk_version:"none". If not possible (e.g. in the default targets included in java/testing.go) it switches some to use sdk_version:"none" to ensure that there is no regression in the behavior of no_standard_libs:true. Follow up changes will switch all usages of no_standard_libs:true over to use sdk_version:"none" at which point no_standard_libs will be removed. Bug: 134566750 Test: m droid Change-Id: I5f0fd3daa980f6b223abe454cba7f25a97a39d7a
-rw-r--r--android/neverallow.go3
-rw-r--r--android/neverallow_test.go32
-rw-r--r--java/java.go6
-rw-r--r--java/java_test.go13
-rw-r--r--java/sdk.go10
-rw-r--r--java/sdk_library.go17
-rw-r--r--java/sdk_test.go28
-rw-r--r--java/testing.go2
8 files changed, 96 insertions, 15 deletions
diff --git a/android/neverallow.go b/android/neverallow.go
index ecff62d05..f75138991 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -108,6 +108,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 9c43d53e6..62c5142d2 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -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",
@@ -266,6 +297,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 4c8367bb9..cecc8dacd 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,7 +121,15 @@ 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{`""`},
@@ -129,6 +137,14 @@ func TestClasspath(t *testing.T) {
},
{
+ 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",
moduleType: "java_library_host",
properties: ``,
@@ -145,12 +161,18 @@ 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",
unbundled: true,
diff --git a/java/testing.go b/java/testing.go
index a9d4670fc..7cd187164 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -54,7 +54,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)