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 (
|
2020-07-15 15:38:15 +02:00
|
|
|
"log"
|
|
|
|
"os"
|
2021-07-20 18:47:41 +02:00
|
|
|
"runtime"
|
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
|
|
|
"testing"
|
2020-03-10 23:17:04 +01:00
|
|
|
|
2021-07-20 18:47:41 +02:00
|
|
|
"android/soong/android"
|
2021-09-24 15:58:27 +02:00
|
|
|
"android/soong/java"
|
2021-07-20 18:47:41 +02:00
|
|
|
|
2020-03-10 23:17:04 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
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-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) {
|
2021-07-20 18:47:41 +02:00
|
|
|
if runtime.GOOS != "linux" {
|
2020-07-15 15:38:15 +02:00
|
|
|
// b/145598135 - Generating host snapshots for anything other than linux is not supported.
|
2021-07-20 18:47:41 +02:00
|
|
|
log.Printf("Skipping as sdk snapshot generation is only supported on linux not %s", runtime.GOOS)
|
2020-07-15 15:38:15 +02:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2021-03-18 02:47:31 +01:00
|
|
|
os.Exit(m.Run())
|
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-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__",
|
|
|
|
],
|
2020-09-29 17:01:08 +02:00
|
|
|
prebuilt_visibility: [
|
|
|
|
"//prebuilts/mysdk",
|
|
|
|
],
|
2019-12-05 15:31:48 +01:00
|
|
|
java_header_libs: [
|
|
|
|
"myjavalib",
|
|
|
|
"mypublicjavalib",
|
|
|
|
"mydefaultedjavalib",
|
2020-05-13 23:11:40 +02:00
|
|
|
"myprivatejavalib",
|
2019-12-05 15:31:48 +01:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myjavalib",
|
|
|
|
// Uses package default visibility
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
}
|
|
|
|
|
2020-02-19 17:10:09 +01:00
|
|
|
java_defaults {
|
|
|
|
name: "java-defaults",
|
2020-03-09 22:23:13 +01:00
|
|
|
visibility: ["//other/bar"],
|
2020-02-19 17:10:09 +01:00
|
|
|
}
|
|
|
|
|
2019-12-05 15:31:48 +01:00
|
|
|
java_library {
|
|
|
|
name: "mypublicjavalib",
|
2020-02-19 17:10:09 +01:00
|
|
|
defaults: ["java-defaults"],
|
2019-12-05 15:31:48 +01:00
|
|
|
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",
|
|
|
|
}
|
2020-05-13 23:11:40 +02:00
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myprivatejavalib",
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
visibility: ["//visibility:private"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
}
|
2019-12-05 15:31:48 +01:00
|
|
|
`
|
|
|
|
|
|
|
|
result := testSdkWithFs(t, ``,
|
|
|
|
map[string][]byte{
|
|
|
|
"package/Test.java": nil,
|
|
|
|
"package/Android.bp": []byte(packageBp),
|
|
|
|
})
|
|
|
|
|
2021-03-12 13:19:43 +01:00
|
|
|
CheckSnapshot(t, result, "mysdk", "package",
|
2019-12-05 15:31:48 +01:00
|
|
|
checkAndroidBpContents(`
|
|
|
|
// This is auto-generated. DO NOT EDIT.
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "myjavalib",
|
|
|
|
prefer: false,
|
2020-05-13 03:20:06 +02:00
|
|
|
visibility: [
|
|
|
|
"//other/foo",
|
|
|
|
"//package",
|
2020-09-29 17:01:08 +02:00
|
|
|
"//prebuilts/mysdk",
|
2020-05-13 03:20:06 +02:00
|
|
|
],
|
2020-11-03 01:11:09 +01:00
|
|
|
apex_available: ["//apex_available:platform"],
|
2019-12-05 15:31:48 +01:00
|
|
|
jars: ["java/myjavalib.jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "mypublicjavalib",
|
|
|
|
prefer: false,
|
|
|
|
visibility: ["//visibility:public"],
|
2020-11-03 01:11:09 +01:00
|
|
|
apex_available: ["//apex_available:platform"],
|
2019-12-05 15:31:48 +01:00
|
|
|
jars: ["java/mypublicjavalib.jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "mydefaultedjavalib",
|
|
|
|
prefer: false,
|
2020-05-13 03:20:06 +02:00
|
|
|
visibility: [
|
|
|
|
"//other/bar",
|
|
|
|
"//package",
|
2020-09-29 17:01:08 +02:00
|
|
|
"//prebuilts/mysdk",
|
2020-05-13 03:20:06 +02:00
|
|
|
],
|
2020-11-03 01:11:09 +01:00
|
|
|
apex_available: ["//apex_available:platform"],
|
2019-12-05 15:31:48 +01:00
|
|
|
jars: ["java/mydefaultedjavalib.jar"],
|
|
|
|
}
|
|
|
|
|
2020-05-13 23:11:40 +02:00
|
|
|
java_import {
|
|
|
|
name: "myprivatejavalib",
|
|
|
|
prefer: false,
|
2020-09-29 17:01:08 +02:00
|
|
|
visibility: [
|
|
|
|
"//package",
|
|
|
|
"//prebuilts/mysdk",
|
|
|
|
],
|
2020-11-03 01:11:09 +01:00
|
|
|
apex_available: ["//apex_available:platform"],
|
2020-05-13 23:11:40 +02:00
|
|
|
jars: ["java/myprivatejavalib.jar"],
|
|
|
|
}
|
2019-12-05 15:31:48 +01:00
|
|
|
`))
|
|
|
|
}
|
2020-02-27 14:45:35 +01:00
|
|
|
|
2020-09-29 17:01:08 +02:00
|
|
|
func TestPrebuiltVisibilityProperty_IsValidated(t *testing.T) {
|
|
|
|
testSdkError(t, `prebuilt_visibility: cannot mix "//visibility:private" with any other visibility rules`, `
|
|
|
|
sdk {
|
|
|
|
name: "mysdk",
|
|
|
|
prebuilt_visibility: [
|
|
|
|
"//foo",
|
|
|
|
"//visibility:private",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrebuiltVisibilityProperty_AddPrivate(t *testing.T) {
|
|
|
|
testSdkError(t, `prebuilt_visibility: "//visibility:private" does not widen the visibility`, `
|
|
|
|
sdk {
|
|
|
|
name: "mysdk",
|
|
|
|
prebuilt_visibility: [
|
|
|
|
"//visibility:private",
|
|
|
|
],
|
|
|
|
java_header_libs: [
|
|
|
|
"myjavalib",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myjavalib",
|
|
|
|
// Uses package default visibility
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2021-03-10 00:02:20 +01:00
|
|
|
func TestSdkInstall(t *testing.T) {
|
2020-02-27 14:45:35 +01:00
|
|
|
sdk := `
|
|
|
|
sdk {
|
|
|
|
name: "mysdk",
|
|
|
|
}
|
|
|
|
`
|
2021-03-10 00:02:20 +01:00
|
|
|
result := testSdkWithFs(t, sdk, nil)
|
2020-02-27 14:45:35 +01:00
|
|
|
|
2021-03-12 13:19:43 +01:00
|
|
|
CheckSnapshot(t, result, "mysdk", "",
|
2022-05-06 11:38:02 +02:00
|
|
|
checkAllOtherCopyRules(`
|
|
|
|
.intermediates/mysdk/common_os/mysdk-current.info -> mysdk-current.info
|
|
|
|
.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip
|
|
|
|
`))
|
2020-02-27 14:45:35 +01:00
|
|
|
}
|
2020-03-10 23:17:04 +01:00
|
|
|
|
|
|
|
type EmbeddedPropertiesStruct struct {
|
2020-05-06 11:23:19 +02:00
|
|
|
S_Embedded_Common string `android:"arch_variant"`
|
|
|
|
S_Embedded_Different string `android:"arch_variant"`
|
2020-03-10 23:17:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type testPropertiesStruct struct {
|
2020-05-06 13:35:38 +02:00
|
|
|
name string
|
2020-03-10 23:17:04 +01:00
|
|
|
private string
|
|
|
|
Public_Kept string `sdk:"keep"`
|
|
|
|
S_Common string
|
2020-05-06 11:23:19 +02:00
|
|
|
S_Different string `android:"arch_variant"`
|
2020-03-10 23:17:04 +01:00
|
|
|
A_Common []string
|
2020-05-06 11:23:19 +02:00
|
|
|
A_Different []string `android:"arch_variant"`
|
2020-03-10 23:17:04 +01:00
|
|
|
F_Common *bool
|
2020-05-06 11:23:19 +02:00
|
|
|
F_Different *bool `android:"arch_variant"`
|
2020-03-10 23:17:04 +01:00
|
|
|
EmbeddedPropertiesStruct
|
|
|
|
}
|
|
|
|
|
2020-04-30 16:48:31 +02:00
|
|
|
func (p *testPropertiesStruct) optimizableProperties() interface{} {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2020-05-06 13:35:38 +02:00
|
|
|
func (p *testPropertiesStruct) String() string {
|
|
|
|
return p.name
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ propertiesContainer = (*testPropertiesStruct)(nil)
|
|
|
|
|
2020-03-10 23:17:04 +01:00
|
|
|
func TestCommonValueOptimization(t *testing.T) {
|
2020-05-06 13:35:38 +02:00
|
|
|
common := &testPropertiesStruct{name: "common"}
|
2020-04-30 16:48:31 +02:00
|
|
|
structs := []propertiesContainer{
|
2020-03-10 23:17:04 +01:00
|
|
|
&testPropertiesStruct{
|
2020-05-06 13:35:38 +02:00
|
|
|
name: "struct-0",
|
2020-03-10 23:17:04 +01:00
|
|
|
private: "common",
|
|
|
|
Public_Kept: "common",
|
|
|
|
S_Common: "common",
|
|
|
|
S_Different: "upper",
|
|
|
|
A_Common: []string{"first", "second"},
|
|
|
|
A_Different: []string{"alpha", "beta"},
|
|
|
|
F_Common: proptools.BoolPtr(false),
|
|
|
|
F_Different: proptools.BoolPtr(false),
|
|
|
|
EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
|
|
|
|
S_Embedded_Common: "embedded_common",
|
|
|
|
S_Embedded_Different: "embedded_upper",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&testPropertiesStruct{
|
2020-05-06 13:35:38 +02:00
|
|
|
name: "struct-1",
|
2020-03-10 23:17:04 +01:00
|
|
|
private: "common",
|
|
|
|
Public_Kept: "common",
|
|
|
|
S_Common: "common",
|
|
|
|
S_Different: "lower",
|
|
|
|
A_Common: []string{"first", "second"},
|
|
|
|
A_Different: []string{"alpha", "delta"},
|
|
|
|
F_Common: proptools.BoolPtr(false),
|
|
|
|
F_Different: proptools.BoolPtr(true),
|
|
|
|
EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
|
|
|
|
S_Embedded_Common: "embedded_common",
|
|
|
|
S_Embedded_Different: "embedded_lower",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
extractor := newCommonValueExtractor(common)
|
|
|
|
|
2020-04-30 19:08:29 +02:00
|
|
|
err := extractor.extractCommonProperties(common, structs)
|
2021-03-12 13:19:43 +01:00
|
|
|
android.AssertDeepEquals(t, "unexpected error", nil, err)
|
2020-04-30 19:08:29 +02:00
|
|
|
|
2021-03-12 13:19:43 +01:00
|
|
|
android.AssertDeepEquals(t, "common properties not correct",
|
2020-03-10 23:17:04 +01:00
|
|
|
&testPropertiesStruct{
|
2020-05-06 13:35:38 +02:00
|
|
|
name: "common",
|
2020-03-10 23:17:04 +01:00
|
|
|
private: "",
|
|
|
|
Public_Kept: "",
|
|
|
|
S_Common: "common",
|
|
|
|
S_Different: "",
|
|
|
|
A_Common: []string{"first", "second"},
|
|
|
|
A_Different: []string(nil),
|
|
|
|
F_Common: proptools.BoolPtr(false),
|
|
|
|
F_Different: nil,
|
|
|
|
EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
|
|
|
|
S_Embedded_Common: "embedded_common",
|
|
|
|
S_Embedded_Different: "",
|
|
|
|
},
|
2020-05-06 13:50:19 +02:00
|
|
|
},
|
|
|
|
common)
|
2020-03-10 23:17:04 +01:00
|
|
|
|
2021-03-12 13:19:43 +01:00
|
|
|
android.AssertDeepEquals(t, "updated properties[0] not correct",
|
2020-03-10 23:17:04 +01:00
|
|
|
&testPropertiesStruct{
|
2020-05-06 13:35:38 +02:00
|
|
|
name: "struct-0",
|
2020-03-10 23:17:04 +01:00
|
|
|
private: "common",
|
|
|
|
Public_Kept: "common",
|
|
|
|
S_Common: "",
|
|
|
|
S_Different: "upper",
|
|
|
|
A_Common: nil,
|
|
|
|
A_Different: []string{"alpha", "beta"},
|
|
|
|
F_Common: nil,
|
|
|
|
F_Different: proptools.BoolPtr(false),
|
|
|
|
EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
|
|
|
|
S_Embedded_Common: "",
|
|
|
|
S_Embedded_Different: "embedded_upper",
|
|
|
|
},
|
2020-05-06 13:50:19 +02:00
|
|
|
},
|
|
|
|
structs[0])
|
2020-03-10 23:17:04 +01:00
|
|
|
|
2021-03-12 13:19:43 +01:00
|
|
|
android.AssertDeepEquals(t, "updated properties[1] not correct",
|
2020-03-10 23:17:04 +01:00
|
|
|
&testPropertiesStruct{
|
2020-05-06 13:35:38 +02:00
|
|
|
name: "struct-1",
|
2020-03-10 23:17:04 +01:00
|
|
|
private: "common",
|
|
|
|
Public_Kept: "common",
|
|
|
|
S_Common: "",
|
|
|
|
S_Different: "lower",
|
|
|
|
A_Common: nil,
|
|
|
|
A_Different: []string{"alpha", "delta"},
|
|
|
|
F_Common: nil,
|
|
|
|
F_Different: proptools.BoolPtr(true),
|
|
|
|
EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
|
|
|
|
S_Embedded_Common: "",
|
|
|
|
S_Embedded_Different: "embedded_lower",
|
|
|
|
},
|
2020-05-06 13:50:19 +02:00
|
|
|
},
|
|
|
|
structs[1])
|
2020-03-10 23:17:04 +01:00
|
|
|
}
|
2020-05-06 11:23:19 +02:00
|
|
|
|
|
|
|
func TestCommonValueOptimization_InvalidArchSpecificVariants(t *testing.T) {
|
|
|
|
common := &testPropertiesStruct{name: "common"}
|
|
|
|
structs := []propertiesContainer{
|
|
|
|
&testPropertiesStruct{
|
|
|
|
name: "struct-0",
|
|
|
|
S_Common: "should-be-but-is-not-common0",
|
|
|
|
},
|
|
|
|
&testPropertiesStruct{
|
|
|
|
name: "struct-1",
|
|
|
|
S_Common: "should-be-but-is-not-common1",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
extractor := newCommonValueExtractor(common)
|
|
|
|
|
|
|
|
err := extractor.extractCommonProperties(common, structs)
|
2021-03-12 13:19:43 +01:00
|
|
|
android.AssertErrorMessageEquals(t, "unexpected error", `field "S_Common" is not tagged as "arch_variant" but has arch specific properties:
|
2020-05-06 11:23:19 +02:00
|
|
|
"struct-0" has value "should-be-but-is-not-common0"
|
|
|
|
"struct-1" has value "should-be-but-is-not-common1"`, err)
|
|
|
|
}
|
2021-05-05 22:35:49 +02:00
|
|
|
|
|
|
|
// Ensure that sdk snapshot related environment variables work correctly.
|
|
|
|
func TestSnapshot_EnvConfiguration(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
sdk {
|
|
|
|
name: "mysdk",
|
|
|
|
java_header_libs: ["myjavalib"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myjavalib",
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
compile_dex: true,
|
|
|
|
host_supported: true,
|
|
|
|
}
|
|
|
|
`
|
|
|
|
preparer := android.GroupFixturePreparers(
|
|
|
|
prepareForSdkTestWithJava,
|
|
|
|
android.FixtureWithRootAndroidBp(bp),
|
|
|
|
)
|
|
|
|
|
|
|
|
checkZipFile := func(t *testing.T, result *android.TestResult, expected string) {
|
|
|
|
zipRule := result.ModuleForTests("mysdk", "common_os").Rule("SnapshotZipFiles")
|
|
|
|
android.AssertStringEquals(t, "snapshot zip file", expected, zipRule.Output.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("no env variables", func(t *testing.T) {
|
|
|
|
result := preparer.RunTest(t)
|
|
|
|
|
|
|
|
checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip")
|
|
|
|
|
|
|
|
CheckSnapshot(t, result, "mysdk", "",
|
|
|
|
checkAndroidBpContents(`
|
|
|
|
// This is auto-generated. DO NOT EDIT.
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "myjavalib",
|
|
|
|
prefer: false,
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
apex_available: ["//apex_available:platform"],
|
|
|
|
jars: ["java/myjavalib.jar"],
|
|
|
|
}
|
2021-05-05 22:36:04 +02:00
|
|
|
`),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("SOONG_SDK_SNAPSHOT_PREFER=true", func(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
preparer,
|
|
|
|
android.FixtureMergeEnv(map[string]string{
|
|
|
|
"SOONG_SDK_SNAPSHOT_PREFER": "true",
|
|
|
|
}),
|
|
|
|
).RunTest(t)
|
|
|
|
|
|
|
|
checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip")
|
|
|
|
|
|
|
|
CheckSnapshot(t, result, "mysdk", "",
|
|
|
|
checkAndroidBpContents(`
|
|
|
|
// This is auto-generated. DO NOT EDIT.
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "myjavalib",
|
|
|
|
prefer: true,
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
apex_available: ["//apex_available:platform"],
|
|
|
|
jars: ["java/myjavalib.jar"],
|
|
|
|
}
|
2021-07-06 18:18:42 +02:00
|
|
|
`),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR=module:build_from_source", func(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
preparer,
|
|
|
|
android.FixtureMergeEnv(map[string]string{
|
|
|
|
"SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR": "module:build_from_source",
|
|
|
|
}),
|
|
|
|
).RunTest(t)
|
|
|
|
|
|
|
|
checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip")
|
|
|
|
|
|
|
|
CheckSnapshot(t, result, "mysdk", "",
|
|
|
|
checkAndroidBpContents(`
|
|
|
|
// This is auto-generated. DO NOT EDIT.
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "myjavalib",
|
|
|
|
prefer: false,
|
|
|
|
use_source_config_var: {
|
|
|
|
config_namespace: "module",
|
|
|
|
var_name: "build_from_source",
|
|
|
|
},
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
apex_available: ["//apex_available:platform"],
|
|
|
|
jars: ["java/myjavalib.jar"],
|
|
|
|
}
|
2021-05-05 23:00:51 +02:00
|
|
|
`),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-09-24 15:58:27 +02:00
|
|
|
t.Run("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE=S", func(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForSdkTestWithJava,
|
|
|
|
java.PrepareForTestWithJavaDefaultModules,
|
|
|
|
java.PrepareForTestWithJavaSdkLibraryFiles,
|
|
|
|
java.FixtureWithLastReleaseApis("mysdklibrary"),
|
|
|
|
android.FixtureWithRootAndroidBp(`
|
|
|
|
sdk {
|
|
|
|
name: "mysdk",
|
|
|
|
bootclasspath_fragments: ["mybootclasspathfragment"],
|
|
|
|
}
|
|
|
|
|
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "mybootclasspathfragment",
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
contents: ["mysdklibrary"],
|
2022-03-31 16:42:30 +02:00
|
|
|
hidden_api: {
|
|
|
|
split_packages: ["*"],
|
|
|
|
},
|
2021-09-24 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library {
|
|
|
|
name: "mysdklibrary",
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
compile_dex: true,
|
|
|
|
public: {enabled: true},
|
|
|
|
permitted_packages: ["mysdklibrary"],
|
|
|
|
}
|
|
|
|
`),
|
|
|
|
android.FixtureMergeEnv(map[string]string{
|
|
|
|
"SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S",
|
|
|
|
}),
|
|
|
|
).RunTest(t)
|
|
|
|
|
|
|
|
CheckSnapshot(t, result, "mysdk", "",
|
2022-05-24 22:10:05 +02:00
|
|
|
checkAndroidBpContents(`
|
2021-09-24 15:58:27 +02:00
|
|
|
// This is auto-generated. DO NOT EDIT.
|
|
|
|
|
|
|
|
prebuilt_bootclasspath_fragment {
|
|
|
|
name: "mybootclasspathfragment",
|
|
|
|
prefer: false,
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
contents: ["mysdklibrary"],
|
|
|
|
hidden_api: {
|
|
|
|
annotation_flags: "hiddenapi/annotation-flags.csv",
|
|
|
|
metadata: "hiddenapi/metadata.csv",
|
|
|
|
index: "hiddenapi/index.csv",
|
2021-08-10 17:14:16 +02:00
|
|
|
stub_flags: "hiddenapi/stub-flags.csv",
|
|
|
|
all_flags: "hiddenapi/all-flags.csv",
|
2021-09-24 15:58:27 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library_import {
|
|
|
|
name: "mysdklibrary",
|
|
|
|
prefer: false,
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
apex_available: ["//apex_available:platform"],
|
|
|
|
shared_library: true,
|
|
|
|
compile_dex: true,
|
|
|
|
permitted_packages: ["mysdklibrary"],
|
|
|
|
public: {
|
|
|
|
jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
|
|
|
|
stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
|
|
|
|
current_api: "sdk_library/public/mysdklibrary.txt",
|
|
|
|
removed_api: "sdk_library/public/mysdklibrary-removed.txt",
|
|
|
|
sdk_version: "current",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`),
|
|
|
|
|
|
|
|
checkAllCopyRules(`
|
|
|
|
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv
|
|
|
|
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv
|
|
|
|
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv
|
2021-08-10 17:14:16 +02:00
|
|
|
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/stub-flags.csv -> hiddenapi/stub-flags.csv
|
|
|
|
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/all-flags.csv -> hiddenapi/all-flags.csv
|
2021-09-24 15:58:27 +02:00
|
|
|
.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar
|
|
|
|
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
|
|
|
|
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
|
|
|
|
`),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-05-05 22:35:49 +02:00
|
|
|
}
|