Introduce module type 'sdk'
This change introduces a new module type named 'sdk'. It is a logical
group of prebuilt modules that together provide a context (e.g. APIs)
in which Mainline modules (such as APEXes) are built.
A prebuilt module (e.g. java_import) can join an sdk by adding it to the
sdk module as shown below:
sdk {
name: "mysdk#20",
java_libs: ["myjavalib_mysdk_20"],
}
java_import {
name: "myjavalib_mysdk_20",
srcs: ["myjavalib-v20.jar"],
sdk_member_name: "myjavalib",
}
sdk {
name: "mysdk#21",
java_libs: ["myjavalib_mysdk_21"],
}
java_import {
name: "myjavalib_mysdk_21",
srcs: ["myjavalib-v21.jar"],
sdk_member_name: "myjavalib",
}
java_library {
name: "myjavalib",
srcs: ["**/*/*.java"],
}
An APEX can specify the SDK(s) that it wants to build with via the new
'uses_sdks' property.
apex {
name: "myapex",
java_libs: ["libX", "libY"],
uses_sdks: ["mysdk#20"],
}
With this, libX, libY, and their transitive dependencies are all built
with the version 20 of myjavalib (the first java_import module) instead
of the other one (which is for version 21) and java_library having the
same name (which is for ToT).
Bug: 138182343
Test: m (sdk_test.go added)
Change-Id: I7e14c524a7d6a0d9f575fb20822080f39818c01e
2019-07-17 13:08:41 +02:00
|
|
|
// Copyright 2019 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package sdk
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-11-30 10:24:33 +01:00
|
|
|
// Needed in an _test.go file in this package to ensure tests run correctly, particularly in IDE.
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
runTestWithBuildDir(m)
|
Introduce module type 'sdk'
This change introduces a new module type named 'sdk'. It is a logical
group of prebuilt modules that together provide a context (e.g. APIs)
in which Mainline modules (such as APEXes) are built.
A prebuilt module (e.g. java_import) can join an sdk by adding it to the
sdk module as shown below:
sdk {
name: "mysdk#20",
java_libs: ["myjavalib_mysdk_20"],
}
java_import {
name: "myjavalib_mysdk_20",
srcs: ["myjavalib-v20.jar"],
sdk_member_name: "myjavalib",
}
sdk {
name: "mysdk#21",
java_libs: ["myjavalib_mysdk_21"],
}
java_import {
name: "myjavalib_mysdk_21",
srcs: ["myjavalib-v21.jar"],
sdk_member_name: "myjavalib",
}
java_library {
name: "myjavalib",
srcs: ["**/*/*.java"],
}
An APEX can specify the SDK(s) that it wants to build with via the new
'uses_sdks' property.
apex {
name: "myapex",
java_libs: ["libX", "libY"],
uses_sdks: ["mysdk#20"],
}
With this, libX, libY, and their transitive dependencies are all built
with the version 20 of myjavalib (the first java_import module) instead
of the other one (which is for version 21) and java_library having the
same name (which is for ToT).
Bug: 138182343
Test: m (sdk_test.go added)
Change-Id: I7e14c524a7d6a0d9f575fb20822080f39818c01e
2019-07-17 13:08:41 +02:00
|
|
|
}
|
|
|
|
|
2019-10-15 08:20:07 +02:00
|
|
|
func TestDepNotInRequiredSdks(t *testing.T) {
|
|
|
|
testSdkError(t, `module "myjavalib".*depends on "otherlib".*that isn't part of the required SDKs:.*`, `
|
|
|
|
sdk {
|
|
|
|
name: "mysdk",
|
2019-12-05 12:25:53 +01:00
|
|
|
java_header_libs: ["sdkmember"],
|
2019-10-15 08:20:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sdk_snapshot {
|
|
|
|
name: "mysdk@1",
|
2019-12-05 12:25:53 +01:00
|
|
|
java_header_libs: ["sdkmember_mysdk_1"],
|
2019-10-15 08:20:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "sdkmember",
|
|
|
|
prefer: false,
|
|
|
|
host_supported: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "sdkmember_mysdk_1",
|
|
|
|
sdk_member_name: "sdkmember",
|
|
|
|
host_supported: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myjavalib",
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
libs: [
|
|
|
|
"sdkmember",
|
|
|
|
"otherlib",
|
|
|
|
],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
compile_dex: true,
|
|
|
|
host_supported: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
// this lib is no in mysdk
|
|
|
|
java_library {
|
|
|
|
name: "otherlib",
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
compile_dex: true,
|
|
|
|
host_supported: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
java_libs: ["myjavalib"],
|
|
|
|
uses_sdks: ["mysdk@1"],
|
|
|
|
key: "myapex.key",
|
|
|
|
certificate: ":myapex.cert",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
2019-12-05 15:31:48 +01:00
|
|
|
|
|
|
|
// Ensure that prebuilt modules have the same effective visibility as the source
|
|
|
|
// modules.
|
|
|
|
func TestSnapshotVisibility(t *testing.T) {
|
|
|
|
packageBp := `
|
|
|
|
package {
|
|
|
|
default_visibility: ["//other/foo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
sdk {
|
|
|
|
name: "mysdk",
|
|
|
|
visibility: [
|
|
|
|
"//other/foo",
|
|
|
|
// This short form will be replaced with //package:__subpackages__ in the
|
|
|
|
// generated sdk_snapshot.
|
|
|
|
":__subpackages__",
|
|
|
|
],
|
|
|
|
java_header_libs: [
|
|
|
|
"myjavalib",
|
|
|
|
"mypublicjavalib",
|
|
|
|
"mydefaultedjavalib",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myjavalib",
|
|
|
|
// Uses package default visibility
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "mypublicjavalib",
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_defaults {
|
|
|
|
name: "myjavadefaults",
|
|
|
|
visibility: ["//other/bar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "mydefaultedjavalib",
|
|
|
|
defaults: ["myjavadefaults"],
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
result := testSdkWithFs(t, ``,
|
|
|
|
map[string][]byte{
|
|
|
|
"package/Test.java": nil,
|
|
|
|
"package/Android.bp": []byte(packageBp),
|
|
|
|
})
|
|
|
|
|
|
|
|
result.CheckSnapshot("mysdk", "android_common", "package",
|
|
|
|
checkAndroidBpContents(`
|
|
|
|
// This is auto-generated. DO NOT EDIT.
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "mysdk_myjavalib@current",
|
|
|
|
sdk_member_name: "myjavalib",
|
|
|
|
visibility: ["//other/foo:__pkg__"],
|
|
|
|
jars: ["java/myjavalib.jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "myjavalib",
|
|
|
|
prefer: false,
|
|
|
|
visibility: ["//other/foo:__pkg__"],
|
|
|
|
jars: ["java/myjavalib.jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "mysdk_mypublicjavalib@current",
|
|
|
|
sdk_member_name: "mypublicjavalib",
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
jars: ["java/mypublicjavalib.jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "mypublicjavalib",
|
|
|
|
prefer: false,
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
jars: ["java/mypublicjavalib.jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "mysdk_mydefaultedjavalib@current",
|
|
|
|
sdk_member_name: "mydefaultedjavalib",
|
|
|
|
visibility: ["//other/bar:__pkg__"],
|
|
|
|
jars: ["java/mydefaultedjavalib.jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "mydefaultedjavalib",
|
|
|
|
prefer: false,
|
|
|
|
visibility: ["//other/bar:__pkg__"],
|
|
|
|
jars: ["java/mydefaultedjavalib.jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
sdk_snapshot {
|
|
|
|
name: "mysdk@current",
|
|
|
|
visibility: [
|
|
|
|
"//other/foo:__pkg__",
|
|
|
|
"//package:__subpackages__",
|
|
|
|
],
|
|
|
|
java_header_libs: [
|
|
|
|
"mysdk_myjavalib@current",
|
|
|
|
"mysdk_mypublicjavalib@current",
|
|
|
|
"mysdk_mydefaultedjavalib@current",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`))
|
|
|
|
}
|