Merge changes I88ee9709,If2ea3fde,I657fbcde,I585a8861 am: e8412c4e7a am: fed3551805 am: 2a27960bd6

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1873694

Change-Id: I4b4bb783d5226a309fcdd9e2d2dc4a0c782b423f
This commit is contained in:
Paul Duffin
2021-10-29 20:30:29 +00:00
committed by Automerger Merge Worker
4 changed files with 217 additions and 47 deletions

View File

@@ -157,7 +157,7 @@ func (s SdkSpec) UsePrebuilt(ctx EarlyModuleContext) bool {
return ctx.Config().AlwaysUsePrebuiltSdks() return ctx.Config().AlwaysUsePrebuiltSdks()
} else if !s.ApiLevel.IsPreview() { } else if !s.ApiLevel.IsPreview() {
// validation check // validation check
if s.Kind != SdkPublic && s.Kind != SdkSystem && s.Kind != SdkTest && s.Kind != SdkModule { if s.Kind != SdkPublic && s.Kind != SdkSystem && s.Kind != SdkTest && s.Kind != SdkModule && s.Kind != SdkSystemServer {
panic(fmt.Errorf("prebuilt SDK is not not available for SdkKind=%q", s.Kind)) panic(fmt.Errorf("prebuilt SDK is not not available for SdkKind=%q", s.Kind))
return false return false
} }

View File

@@ -116,13 +116,13 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext)
} }
} }
toModule := func(modules []string, res string, aidl android.Path) sdkDep { toModule := func(systemModules string, module string, aidl android.Path) sdkDep {
return sdkDep{ return sdkDep{
useModule: true, useModule: true,
bootclasspath: append(modules, config.DefaultLambdaStubsLibrary), bootclasspath: []string{module, config.DefaultLambdaStubsLibrary},
systemModules: "core-current-stubs-system-modules", systemModules: systemModules,
java9Classpath: modules, java9Classpath: []string{module},
frameworkResModule: res, frameworkResModule: "framework-res",
aidl: android.OptionalPathForPath(aidl), aidl: android.OptionalPathForPath(aidl),
} }
} }
@@ -161,11 +161,11 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext)
noFrameworksLibs: true, noFrameworksLibs: true,
} }
case android.SdkPublic: case android.SdkPublic:
return toModule([]string{"android_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx)) return toModule("core-current-stubs-system-modules", "android_stubs_current", sdkFrameworkAidlPath(ctx))
case android.SdkSystem: case android.SdkSystem:
return toModule([]string{"android_system_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx)) return toModule("core-current-stubs-system-modules", "android_system_stubs_current", sdkFrameworkAidlPath(ctx))
case android.SdkTest: case android.SdkTest:
return toModule([]string{"android_test_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx)) return toModule("core-current-stubs-system-modules", "android_test_stubs_current", sdkFrameworkAidlPath(ctx))
case android.SdkCore: case android.SdkCore:
return sdkDep{ return sdkDep{
useModule: true, useModule: true,
@@ -175,24 +175,10 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext)
} }
case android.SdkModule: case android.SdkModule:
// TODO(146757305): provide .apk and .aidl that have more APIs for modules // TODO(146757305): provide .apk and .aidl that have more APIs for modules
return sdkDep{ return toModule("core-module-lib-stubs-system-modules", "android_module_lib_stubs_current", nonUpdatableFrameworkAidlPath(ctx))
useModule: true,
bootclasspath: []string{"android_module_lib_stubs_current", config.DefaultLambdaStubsLibrary},
systemModules: "core-module-lib-stubs-system-modules",
java9Classpath: []string{"android_module_lib_stubs_current"},
frameworkResModule: "framework-res",
aidl: android.OptionalPathForPath(nonUpdatableFrameworkAidlPath(ctx)),
}
case android.SdkSystemServer: case android.SdkSystemServer:
// TODO(146757305): provide .apk and .aidl that have more APIs for modules // TODO(146757305): provide .apk and .aidl that have more APIs for modules
return sdkDep{ return toModule("core-module-lib-stubs-system-modules", "android_system_server_stubs_current", sdkFrameworkAidlPath(ctx))
useModule: true,
bootclasspath: []string{"android_system_server_stubs_current", config.DefaultLambdaStubsLibrary},
systemModules: "core-module-lib-stubs-system-modules",
java9Classpath: []string{"android_system_server_stubs_current"},
frameworkResModule: "framework-res",
aidl: android.OptionalPathForPath(sdkFrameworkAidlPath(ctx)),
}
default: default:
panic(fmt.Errorf("invalid sdk %q", sdkVersion.Raw)) panic(fmt.Errorf("invalid sdk %q", sdkVersion.Raw))
} }

View File

@@ -25,27 +25,36 @@ import (
"android/soong/java/config" "android/soong/java/config"
) )
type classpathTestCase struct {
name string
unbundled bool
moduleType string
host android.OsClass
properties string
// for java 8
bootclasspath []string
java8classpath []string
// for java 9
system string
java9classpath []string
forces8 bool // if set, javac will always be called with java 8 arguments
aidl string
// Indicates how this test case is affected by the setting of Always_use_prebuilt_sdks.
//
// If this is nil then the test case is unaffected by the setting of Always_use_prebuilt_sdks.
// Otherwise, the test case can only be used when
// Always_use_prebuilt_sdks=*forAlwaysUsePrebuiltSdks.
forAlwaysUsePrebuiltSdks *bool
}
func TestClasspath(t *testing.T) { func TestClasspath(t *testing.T) {
const frameworkAidl = "-I" + defaultJavaDir + "/framework/aidl" const frameworkAidl = "-I" + defaultJavaDir + "/framework/aidl"
var classpathTestcases = []struct { var classpathTestcases = []classpathTestCase{
name string
unbundled bool
moduleType string
host android.OsClass
properties string
// for java 8
bootclasspath []string
java8classpath []string
// for java 9
system string
java9classpath []string
forces8 bool // if set, javac will always be called with java 8 arguments
aidl string
}{
{ {
name: "default", name: "default",
bootclasspath: config.StableCorePlatformBootclasspathLibraries, bootclasspath: config.StableCorePlatformBootclasspathLibraries,
@@ -91,6 +100,8 @@ func TestClasspath(t *testing.T) {
aidl: "-pprebuilts/sdk/30/public/framework.aidl", aidl: "-pprebuilts/sdk/30/public/framework.aidl",
}, },
{ {
// Test case only applies when Always_use_prebuilt_sdks=false (the default).
forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
name: "current", name: "current",
properties: `sdk_version: "current",`, properties: `sdk_version: "current",`,
@@ -100,6 +111,20 @@ func TestClasspath(t *testing.T) {
aidl: "-pout/soong/framework.aidl", aidl: "-pout/soong/framework.aidl",
}, },
{ {
// Test case only applies when Always_use_prebuilt_sdks=true.
forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
name: "current",
properties: `sdk_version: "current",`,
bootclasspath: []string{`""`},
system: "sdk_public_current_system_modules",
java8classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/current/public/framework.aidl",
},
{
// Test case only applies when Always_use_prebuilt_sdks=false (the default).
forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
name: "system_current", name: "system_current",
properties: `sdk_version: "system_current",`, properties: `sdk_version: "system_current",`,
@@ -109,7 +134,18 @@ func TestClasspath(t *testing.T) {
aidl: "-pout/soong/framework.aidl", aidl: "-pout/soong/framework.aidl",
}, },
{ {
// Test case only applies when Always_use_prebuilt_sdks=true.
forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
name: "system_current",
properties: `sdk_version: "system_current",`,
bootclasspath: []string{`""`},
system: "sdk_public_current_system_modules",
java8classpath: []string{"prebuilts/sdk/current/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/current/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/current/public/framework.aidl",
},
{
name: "system_29", name: "system_29",
properties: `sdk_version: "system_29",`, properties: `sdk_version: "system_29",`,
bootclasspath: []string{`""`}, bootclasspath: []string{`""`},
@@ -118,7 +154,6 @@ func TestClasspath(t *testing.T) {
aidl: "-pprebuilts/sdk/29/public/framework.aidl", aidl: "-pprebuilts/sdk/29/public/framework.aidl",
}, },
{ {
name: "system_30", name: "system_30",
properties: `sdk_version: "system_30",`, properties: `sdk_version: "system_30",`,
bootclasspath: []string{`""`}, bootclasspath: []string{`""`},
@@ -128,6 +163,8 @@ func TestClasspath(t *testing.T) {
aidl: "-pprebuilts/sdk/30/public/framework.aidl", aidl: "-pprebuilts/sdk/30/public/framework.aidl",
}, },
{ {
// Test case only applies when Always_use_prebuilt_sdks=false (the default).
forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
name: "test_current", name: "test_current",
properties: `sdk_version: "test_current",`, properties: `sdk_version: "test_current",`,
@@ -137,12 +174,47 @@ func TestClasspath(t *testing.T) {
aidl: "-pout/soong/framework.aidl", aidl: "-pout/soong/framework.aidl",
}, },
{ {
// Test case only applies when Always_use_prebuilt_sdks=true.
forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
name: "test_current",
properties: `sdk_version: "test_current",`,
bootclasspath: []string{`""`},
system: "sdk_public_current_system_modules",
java8classpath: []string{"prebuilts/sdk/current/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/current/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/current/public/framework.aidl",
},
{
name: "test_30",
properties: `sdk_version: "test_30",`,
bootclasspath: []string{`""`},
system: "sdk_public_30_system_modules",
java8classpath: []string{"prebuilts/sdk/30/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/30/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/30/public/framework.aidl",
},
{
// Test case only applies when Always_use_prebuilt_sdks=false (the default).
forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
name: "core_current", name: "core_current",
properties: `sdk_version: "core_current",`, properties: `sdk_version: "core_current",`,
bootclasspath: []string{"core.current.stubs", "core-lambda-stubs"}, bootclasspath: []string{"core.current.stubs", "core-lambda-stubs"},
system: "core-current-stubs-system-modules", system: "core-current-stubs-system-modules",
}, },
{
// Test case only applies when Always_use_prebuilt_sdks=true.
forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
name: "core_current",
properties: `sdk_version: "core_current",`,
bootclasspath: []string{`""`},
system: "sdk_public_current_system_modules",
java8classpath: []string{"prebuilts/sdk/current/core/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/current/core/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/current/public/framework.aidl",
},
{ {
name: "nostdlib", name: "nostdlib",
@@ -214,8 +286,10 @@ func TestClasspath(t *testing.T) {
java9classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, java9classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/current/public/framework.aidl", aidl: "-pprebuilts/sdk/current/public/framework.aidl",
}, },
{ {
// Test case only applies when Always_use_prebuilt_sdks=false (the default).
forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
name: "module_current", name: "module_current",
properties: `sdk_version: "module_current",`, properties: `sdk_version: "module_current",`,
bootclasspath: []string{"android_module_lib_stubs_current", "core-lambda-stubs"}, bootclasspath: []string{"android_module_lib_stubs_current", "core-lambda-stubs"},
@@ -224,6 +298,48 @@ func TestClasspath(t *testing.T) {
aidl: "-pout/soong/framework_non_updatable.aidl", aidl: "-pout/soong/framework_non_updatable.aidl",
}, },
{ {
// Test case only applies when Always_use_prebuilt_sdks=true.
forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
name: "module_current",
properties: `sdk_version: "module_current",`,
bootclasspath: []string{`""`},
system: "sdk_public_current_system_modules",
java8classpath: []string{"prebuilts/sdk/current/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/current/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/current/public/framework.aidl",
},
{
name: "module_30",
properties: `sdk_version: "module_30",`,
bootclasspath: []string{`""`},
system: "sdk_public_30_system_modules",
java8classpath: []string{"prebuilts/sdk/30/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/30/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/30/public/framework.aidl",
},
{
name: "module_31",
properties: `sdk_version: "module_31",`,
bootclasspath: []string{`""`},
system: "sdk_public_31_system_modules",
java8classpath: []string{"prebuilts/sdk/31/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/31/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/31/public/framework.aidl",
},
{
name: "module_32",
properties: `sdk_version: "module_32",`,
bootclasspath: []string{`""`},
system: "sdk_public_32_system_modules",
java8classpath: []string{"prebuilts/sdk/32/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/32/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/32/public/framework.aidl",
},
{
// Test case only applies when Always_use_prebuilt_sdks=false (the default).
forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
name: "system_server_current", name: "system_server_current",
properties: `sdk_version: "system_server_current",`, properties: `sdk_version: "system_server_current",`,
bootclasspath: []string{"android_system_server_stubs_current", "core-lambda-stubs"}, bootclasspath: []string{"android_system_server_stubs_current", "core-lambda-stubs"},
@@ -231,9 +347,62 @@ func TestClasspath(t *testing.T) {
java9classpath: []string{"android_system_server_stubs_current"}, java9classpath: []string{"android_system_server_stubs_current"},
aidl: "-pout/soong/framework.aidl", aidl: "-pout/soong/framework.aidl",
}, },
{
// Test case only applies when Always_use_prebuilt_sdks=true.
forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
name: "system_server_current",
properties: `sdk_version: "system_server_current",`,
bootclasspath: []string{`""`},
system: "sdk_public_current_system_modules",
java8classpath: []string{"prebuilts/sdk/current/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/current/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/current/public/framework.aidl",
},
{
name: "system_server_30",
properties: `sdk_version: "system_server_30",`,
bootclasspath: []string{`""`},
system: "sdk_public_30_system_modules",
java8classpath: []string{"prebuilts/sdk/30/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/30/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/30/public/framework.aidl",
},
{
name: "system_server_31",
properties: `sdk_version: "system_server_31",`,
bootclasspath: []string{`""`},
system: "sdk_public_31_system_modules",
java8classpath: []string{"prebuilts/sdk/31/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/31/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/31/public/framework.aidl",
},
{
name: "system_server_32",
properties: `sdk_version: "system_server_32",`,
bootclasspath: []string{`""`},
system: "sdk_public_32_system_modules",
java8classpath: []string{"prebuilts/sdk/32/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
java9classpath: []string{"prebuilts/sdk/32/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/32/public/framework.aidl",
},
} }
t.Run("basic", func(t *testing.T) {
testClasspathTestCases(t, classpathTestcases, false)
})
t.Run("Always_use_prebuilt_sdks=true", func(t *testing.T) {
testClasspathTestCases(t, classpathTestcases, true)
})
}
func testClasspathTestCases(t *testing.T, classpathTestcases []classpathTestCase, alwaysUsePrebuiltSdks bool) {
for _, testcase := range classpathTestcases { for _, testcase := range classpathTestcases {
if testcase.forAlwaysUsePrebuiltSdks != nil && *testcase.forAlwaysUsePrebuiltSdks != alwaysUsePrebuiltSdks {
continue
}
t.Run(testcase.name, func(t *testing.T) { t.Run(testcase.name, func(t *testing.T) {
moduleType := "java_library" moduleType := "java_library"
if testcase.moduleType != "" { if testcase.moduleType != "" {
@@ -299,7 +468,9 @@ func TestClasspath(t *testing.T) {
system = "--system=none" system = "--system=none"
} else if testcase.system != "" { } else if testcase.system != "" {
dir := "" dir := ""
if strings.HasPrefix(testcase.system, "sdk_public_") { // If the system modules name starts with sdk_ then it is a prebuilt module and so comes
// from the prebuilt directory.
if strings.HasPrefix(testcase.system, "sdk_") {
dir = "prebuilts/sdk" dir = "prebuilts/sdk"
} else { } else {
dir = defaultJavaDir dir = defaultJavaDir
@@ -351,11 +522,20 @@ func TestClasspath(t *testing.T) {
android.AssertPathsRelativeToTopEquals(t, "implicits", deps, javac.Implicits) android.AssertPathsRelativeToTopEquals(t, "implicits", deps, javac.Implicits)
} }
preparer := android.NullFixturePreparer
if alwaysUsePrebuiltSdks {
preparer = android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
})
}
fixtureFactory := android.GroupFixturePreparers( fixtureFactory := android.GroupFixturePreparers(
prepareForJavaTest, prepareForJavaTest,
FixtureWithPrebuiltApis(map[string][]string{ FixtureWithPrebuiltApis(map[string][]string{
"29": {}, "29": {},
"30": {}, "30": {},
"31": {},
"32": {},
"current": {}, "current": {},
}), }),
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
@@ -369,6 +549,7 @@ func TestClasspath(t *testing.T) {
env["ANDROID_JAVA8_HOME"] = "jdk8" env["ANDROID_JAVA8_HOME"] = "jdk8"
} }
}), }),
preparer,
) )
// Test with legacy javac -source 1.8 -target 1.8 // Test with legacy javac -source 1.8 -target 1.8

View File

@@ -181,6 +181,9 @@ func prebuiltApisFilesForLibs(apiLevels []string, sdkLibs []string) map[string][
} }
} }
} }
if level == "current" {
fs["prebuilts/sdk/current/core/android.jar"] = nil
}
fs[fmt.Sprintf("prebuilts/sdk/%s/public/framework.aidl", level)] = nil fs[fmt.Sprintf("prebuilts/sdk/%s/public/framework.aidl", level)] = nil
} }
return fs return fs