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
|
|
|
"android/soong/android"
|
|
|
|
"log"
|
|
|
|
"os"
|
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
|
|
|
|
|
|
|
"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) {
|
2020-07-15 15:38:15 +02:00
|
|
|
if android.BuildOs != android.Linux {
|
|
|
|
// b/145598135 - Generating host snapshots for anything other than linux is not supported.
|
|
|
|
log.Printf("Skipping as sdk snapshot generation is only supported on %s not %s", android.Linux, android.BuildOs)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2019-11-30 10:24:33 +01:00
|
|
|
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,
|
2020-03-09 22:23:13 +01:00
|
|
|
apex_available: ["myapex"],
|
2019-10-15 08:20:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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__",
|
|
|
|
],
|
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),
|
|
|
|
})
|
|
|
|
|
2020-02-25 20:26:33 +01:00
|
|
|
result.CheckSnapshot("mysdk", "package",
|
2019-12-05 15:31:48 +01:00
|
|
|
checkAndroidBpContents(`
|
|
|
|
// This is auto-generated. DO NOT EDIT.
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "mysdk_myjavalib@current",
|
|
|
|
sdk_member_name: "myjavalib",
|
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: "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: "mysdk_mypublicjavalib@current",
|
|
|
|
sdk_member_name: "mypublicjavalib",
|
|
|
|
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: "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: "mysdk_mydefaultedjavalib@current",
|
|
|
|
sdk_member_name: "mydefaultedjavalib",
|
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"],
|
|
|
|
}
|
|
|
|
|
|
|
|
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: "mysdk_myprivatejavalib@current",
|
|
|
|
sdk_member_name: "myprivatejavalib",
|
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"],
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
sdk_snapshot {
|
|
|
|
name: "mysdk@current",
|
|
|
|
visibility: [
|
2020-05-13 02:54:21 +02:00
|
|
|
"//other/foo",
|
2019-12-05 15:31:48 +01:00
|
|
|
"//package:__subpackages__",
|
|
|
|
],
|
|
|
|
java_header_libs: [
|
|
|
|
"mysdk_myjavalib@current",
|
|
|
|
"mysdk_mypublicjavalib@current",
|
|
|
|
"mysdk_mydefaultedjavalib@current",
|
2020-05-13 23:11:40 +02:00
|
|
|
"mysdk_myprivatejavalib@current",
|
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",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:45:35 +01:00
|
|
|
func TestSDkInstall(t *testing.T) {
|
|
|
|
sdk := `
|
|
|
|
sdk {
|
|
|
|
name: "mysdk",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
result := testSdkWithFs(t, ``,
|
|
|
|
map[string][]byte{
|
|
|
|
"Android.bp": []byte(sdk),
|
|
|
|
})
|
|
|
|
|
|
|
|
result.CheckSnapshot("mysdk", "",
|
|
|
|
checkAllOtherCopyRules(`.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip`),
|
|
|
|
)
|
|
|
|
}
|
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)
|
|
|
|
|
|
|
|
h := TestHelper{t}
|
2020-04-30 19:08:29 +02:00
|
|
|
|
|
|
|
err := extractor.extractCommonProperties(common, structs)
|
|
|
|
h.AssertDeepEquals("unexpected error", nil, err)
|
|
|
|
|
2020-05-06 13:50:19 +02:00
|
|
|
h.AssertDeepEquals("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
|
|
|
|
2020-05-06 13:50:19 +02:00
|
|
|
h.AssertDeepEquals("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
|
|
|
|
2020-05-06 13:50:19 +02:00
|
|
|
h.AssertDeepEquals("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)
|
|
|
|
|
|
|
|
h := TestHelper{t}
|
|
|
|
|
|
|
|
err := extractor.extractCommonProperties(common, structs)
|
|
|
|
h.AssertErrorMessageEquals("unexpected error", `field "S_Common" is not tagged as "arch_variant" but has arch specific properties:
|
|
|
|
"struct-0" has value "should-be-but-is-not-common0"
|
|
|
|
"struct-1" has value "should-be-but-is-not-common1"`, err)
|
|
|
|
}
|