aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2020-05-12 11:50:28 +0100
committerPaul Duffin <paulduffin@google.com>2020-05-13 18:07:09 +0100
commit080f5ee6f2b5c35e589fb6140be1fecd213be346 (patch)
tree0d4307a69b5736c3514b16515465a7ee93939970
parent1f4ad0e44d6f18c2f0a686f94f945be3230d5551 (diff)
downloadbuild_soong-080f5ee6f2b5c35e589fb6140be1fecd213be346.tar.gz
build_soong-080f5ee6f2b5c35e589fb6140be1fecd213be346.tar.bz2
build_soong-080f5ee6f2b5c35e589fb6140be1fecd213be346.zip
java_sdk_library: Add sdk_version for API scopes
Allow the sdk_version against which the stubs for a scope are compiled to be specified in the module on a per scope basis. Bug: 155164730 Test: m nothing Merged-In: I5881e5ee7c2169c30f544882344a60a602dae917 Change-Id: I5881e5ee7c2169c30f544882344a60a602dae917 (cherry picked from commit 87a05a389d9edfa3b83d90aa4c08cb66a29e4caf)
-rw-r--r--java/java_test.go14
-rw-r--r--java/sdk_library.go21
-rw-r--r--sdk/java_sdk_test.go64
3 files changed, 98 insertions, 1 deletions
diff --git a/java/java_test.go b/java/java_test.go
index 72c4695d..01ddccfc 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -1247,6 +1247,20 @@ func TestJavaSdkLibrary_InvalidScopes(t *testing.T) {
`)
}
+func TestJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) {
+ testJava(t, `
+ java_sdk_library {
+ name: "foo",
+ srcs: ["a.java", "b.java"],
+ api_packages: ["foo"],
+ system: {
+ enabled: true,
+ sdk_version: "module_current",
+ },
+ }
+ `)
+}
+
var compilerFlagsTestCases = []struct {
in string
out bool
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 4a942649..2650ab3e 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -320,6 +320,22 @@ type ApiScopeProperties struct {
// Otherwise, if this is not set for any scope then the default behavior is
// scope specific so please refer to the scope specific property documentation.
Enabled *bool
+
+ // The sdk_version to use for building the stubs.
+ //
+ // If not specified then it will use an sdk_version determined as follows:
+ // 1) If the sdk_version specified on the java_sdk_library is none then this
+ // will be none. This is used for java_sdk_library instances that are used
+ // to create stubs that contribute to the core_current sdk version.
+ // 2) Otherwise, it is assumed that this library extends but does not contribute
+ // directly to a specific sdk_version and so this uses the sdk_version appropriate
+ // for the api scope. e.g. public will use sdk_version: current, system will use
+ // sdk_version: system_current, etc.
+ //
+ // This does not affect the sdk_version used for either generating the stubs source
+ // or the API file. They both have to use the same sdk_version as is used for
+ // compiling the implementation library.
+ Sdk_version *string
}
type sdkLibraryProperties struct {
@@ -701,6 +717,11 @@ func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string {
// Get the sdk version for use when compiling the stubs library.
func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string {
+ scopeProperties := module.scopeToProperties[apiScope]
+ if scopeProperties.Sdk_version != nil {
+ return proptools.String(scopeProperties.Sdk_version)
+ }
+
sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
if sdkDep.hasStandardLibs() {
// If building against a standard sdk then use the sdk version appropriate for the scope.
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index acacd97e..436fd9d2 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -1134,7 +1134,69 @@ sdk_snapshot {
)
}
-func TestSnapshotWithJavaSdkLibrary_ApiSurfaces(t *testing.T) {
+func TestSnapshotWithJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) {
+ result := testSdkWithJava(t, `
+ sdk {
+ name: "mysdk",
+ java_sdk_libs: ["myjavalib"],
+ }
+
+ java_sdk_library {
+ name: "myjavalib",
+ srcs: ["Test.java"],
+ sdk_version: "module_current",
+ public: {
+ enabled: true,
+ sdk_version: "module_current",
+ },
+ }
+ `)
+
+ result.CheckSnapshot("mysdk", "",
+ checkAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_sdk_library_import {
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
+ public: {
+ jars: ["sdk_library/public/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
+ current_api: "sdk_library/public/myjavalib.txt",
+ removed_api: "sdk_library/public/myjavalib-removed.txt",
+ sdk_version: "module_current",
+ },
+}
+
+java_sdk_library_import {
+ name: "myjavalib",
+ prefer: false,
+ public: {
+ jars: ["sdk_library/public/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
+ current_api: "sdk_library/public/myjavalib.txt",
+ removed_api: "sdk_library/public/myjavalib-removed.txt",
+ sdk_version: "module_current",
+ },
+}
+
+sdk_snapshot {
+ name: "mysdk@current",
+ java_sdk_libs: ["mysdk_myjavalib@current"],
+}
+`),
+ checkAllCopyRules(`
+.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
+.intermediates/myjavalib.stubs.source/android_common/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
+.intermediates/myjavalib.stubs.source/android_common/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib-removed.txt
+`),
+ checkMergeZips(
+ ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
+ ),
+ )
+}
+
+func TestSnapshotWithJavaSdkLibrary_ApiScopes(t *testing.T) {
result := testSdkWithJava(t, `
sdk {
name: "mysdk",