2015-07-10 04:57:48 +08:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
package android
|
2015-07-10 04:57:48 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2015-11-25 09:53:15 +08:00
|
|
|
"runtime"
|
2015-07-10 04:57:48 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-03-07 23:46:33 +08:00
|
|
|
registerVariableBuildComponents(InitRegistrationContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerVariableBuildComponents(ctx RegistrationContext) {
|
|
|
|
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
2020-02-07 09:01:55 +08:00
|
|
|
ctx.BottomUp("variable", VariableMutator).Parallel()
|
2016-10-13 05:38:15 +08:00
|
|
|
})
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
|
|
|
|
2021-03-07 23:46:33 +08:00
|
|
|
var PrepareForTestWithVariables = FixtureRegisterWithContext(registerVariableBuildComponents)
|
|
|
|
|
2015-07-10 04:57:48 +08:00
|
|
|
type variableProperties struct {
|
|
|
|
Product_variables struct {
|
2015-09-17 07:48:54 +08:00
|
|
|
Platform_sdk_version struct {
|
|
|
|
Asflags []string
|
2017-05-09 04:43:00 +08:00
|
|
|
Cflags []string
|
2015-09-17 07:48:54 +08:00
|
|
|
}
|
2022-11-18 15:13:12 +08:00
|
|
|
Star_kylin_non_aosk struct {
|
|
|
|
Cppflags []string
|
|
|
|
}
|
2015-12-02 08:31:16 +08:00
|
|
|
|
|
|
|
// unbundled_build is a catch-all property to annotate modules that don't build in one or
|
|
|
|
// more unbundled branches, usually due to dependencies missing from the manifest.
|
|
|
|
Unbundled_build struct {
|
|
|
|
Enabled *bool `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2016-01-06 06:27:55 +08:00
|
|
|
|
2016-03-02 06:08:42 +08:00
|
|
|
Malloc_not_svelte struct {
|
2019-12-17 01:55:10 +08:00
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
Exclude_static_libs []string `android:"arch_variant"`
|
2018-09-01 07:56:05 +08:00
|
|
|
} `android:"arch_variant"`
|
2016-05-13 09:04:18 +08:00
|
|
|
|
2020-04-30 05:57:30 +08:00
|
|
|
Malloc_zero_contents struct {
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
|
|
|
|
Malloc_pattern_fill_contents struct {
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
|
2016-05-13 09:04:18 +08:00
|
|
|
Safestack struct {
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2016-07-13 05:57:40 +08:00
|
|
|
|
2016-07-26 08:42:18 +08:00
|
|
|
Binder32bit struct {
|
|
|
|
Cflags []string
|
|
|
|
}
|
2016-09-23 05:49:10 +08:00
|
|
|
|
2017-05-05 04:57:05 +08:00
|
|
|
Override_rs_driver struct {
|
|
|
|
Cflags []string
|
|
|
|
}
|
|
|
|
|
2017-12-14 06:06:20 +08:00
|
|
|
// treble_linker_namespaces is true when the system/vendor linker namespace separation is
|
|
|
|
// enabled.
|
|
|
|
Treble_linker_namespaces struct {
|
|
|
|
Cflags []string
|
|
|
|
}
|
|
|
|
// enforce_vintf_manifest is true when a device is required to have a vintf manifest.
|
|
|
|
Enforce_vintf_manifest struct {
|
|
|
|
Cflags []string
|
|
|
|
}
|
|
|
|
|
2016-12-09 01:46:35 +08:00
|
|
|
// debuggable is true for eng and userdebug builds, and can be used to turn on additional
|
|
|
|
// debugging features that don't significantly impact runtime behavior. userdebug builds
|
|
|
|
// are used for dogfooding and performance testing, and should be as similar to user builds
|
|
|
|
// as possible.
|
2016-09-23 05:49:10 +08:00
|
|
|
Debuggable struct {
|
2019-04-02 09:37:36 +08:00
|
|
|
Cflags []string
|
|
|
|
Cppflags []string
|
|
|
|
Init_rc []string
|
|
|
|
Required []string
|
|
|
|
Host_required []string
|
|
|
|
Target_required []string
|
2020-10-20 13:01:29 +08:00
|
|
|
Strip struct {
|
|
|
|
All *bool
|
|
|
|
Keep_symbols *bool
|
|
|
|
Keep_symbols_and_debug_frame *bool
|
|
|
|
}
|
2021-09-24 03:49:54 +08:00
|
|
|
Srcs []string
|
|
|
|
Exclude_srcs []string
|
2016-09-23 05:49:10 +08:00
|
|
|
}
|
2016-12-09 01:46:35 +08:00
|
|
|
|
|
|
|
// eng is true for -eng builds, and can be used to turn on additionaly heavyweight debugging
|
|
|
|
// features.
|
|
|
|
Eng struct {
|
|
|
|
Cflags []string
|
|
|
|
Cppflags []string
|
2018-07-12 02:01:59 +08:00
|
|
|
Lto struct {
|
|
|
|
Never *bool
|
|
|
|
}
|
2018-10-27 14:58:42 +08:00
|
|
|
Sanitize struct {
|
|
|
|
Address *bool
|
|
|
|
}
|
2019-06-21 20:58:27 +08:00
|
|
|
Optimize struct {
|
|
|
|
Enabled *bool
|
|
|
|
}
|
2016-12-09 01:46:35 +08:00
|
|
|
}
|
2017-05-06 04:37:11 +08:00
|
|
|
|
|
|
|
Pdk struct {
|
2017-10-18 04:55:02 +08:00
|
|
|
Enabled *bool `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2017-08-24 05:58:37 +08:00
|
|
|
|
|
|
|
Uml struct {
|
|
|
|
Cppflags []string
|
|
|
|
}
|
2017-11-27 17:14:46 +08:00
|
|
|
|
|
|
|
Arc struct {
|
2020-12-18 08:53:26 +08:00
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
2021-03-05 00:56:40 +08:00
|
|
|
Header_libs []string `android:"arch_variant"`
|
2020-12-18 08:53:26 +08:00
|
|
|
Include_dirs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2019-08-13 22:00:18 +08:00
|
|
|
|
|
|
|
Flatten_apex struct {
|
|
|
|
Enabled *bool
|
|
|
|
}
|
2019-10-30 02:00:15 +08:00
|
|
|
|
2020-01-28 05:26:42 +08:00
|
|
|
Native_coverage struct {
|
2020-02-06 08:23:21 +08:00
|
|
|
Src *string `android:"arch_variant"`
|
2020-01-28 05:26:42 +08:00
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2015-12-02 08:31:16 +08:00
|
|
|
} `android:"arch_variant"`
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
|
|
|
|
2020-02-07 08:57:45 +08:00
|
|
|
var defaultProductVariables interface{} = variableProperties{}
|
2015-07-10 04:57:48 +08:00
|
|
|
|
2015-08-28 04:28:01 +08:00
|
|
|
type productVariables struct {
|
2016-05-11 15:27:49 +08:00
|
|
|
// Suffix to add to generated Makefiles
|
|
|
|
Make_suffix *string `json:",omitempty"`
|
|
|
|
|
2020-02-22 08:55:46 +08:00
|
|
|
BuildId *string `json:",omitempty"`
|
|
|
|
BuildNumberFile *string `json:",omitempty"`
|
2018-01-11 08:06:12 +08:00
|
|
|
|
2019-04-03 13:56:43 +08:00
|
|
|
Platform_version_name *string `json:",omitempty"`
|
|
|
|
Platform_sdk_version *int `json:",omitempty"`
|
2022-11-18 15:13:12 +08:00
|
|
|
Star_kylin_non_aosk *bool `json:",omitempty"`
|
2019-04-03 13:56:43 +08:00
|
|
|
Platform_sdk_codename *string `json:",omitempty"`
|
|
|
|
Platform_sdk_final *bool `json:",omitempty"`
|
|
|
|
Platform_version_active_codenames []string `json:",omitempty"`
|
|
|
|
Platform_vndk_version *string `json:",omitempty"`
|
|
|
|
Platform_systemsdk_versions []string `json:",omitempty"`
|
|
|
|
Platform_security_patch *string `json:",omitempty"`
|
|
|
|
Platform_preview_sdk_version *string `json:",omitempty"`
|
|
|
|
Platform_min_supported_target_sdk_version *string `json:",omitempty"`
|
|
|
|
Platform_base_os *string `json:",omitempty"`
|
2018-01-15 14:05:10 +08:00
|
|
|
|
2020-08-06 22:00:37 +08:00
|
|
|
DeviceName *string `json:",omitempty"`
|
|
|
|
DeviceArch *string `json:",omitempty"`
|
|
|
|
DeviceArchVariant *string `json:",omitempty"`
|
|
|
|
DeviceCpuVariant *string `json:",omitempty"`
|
|
|
|
DeviceAbi []string `json:",omitempty"`
|
|
|
|
DeviceVndkVersion *string `json:",omitempty"`
|
|
|
|
DeviceCurrentApiLevelForVendorModules *string `json:",omitempty"`
|
|
|
|
DeviceSystemSdkVersions []string `json:",omitempty"`
|
2019-02-01 06:31:51 +08:00
|
|
|
|
2020-12-12 05:36:29 +08:00
|
|
|
RecoverySnapshotVersion *string `json:",omitempty"`
|
|
|
|
|
2019-02-01 06:31:51 +08:00
|
|
|
DeviceSecondaryArch *string `json:",omitempty"`
|
|
|
|
DeviceSecondaryArchVariant *string `json:",omitempty"`
|
|
|
|
DeviceSecondaryCpuVariant *string `json:",omitempty"`
|
|
|
|
DeviceSecondaryAbi []string `json:",omitempty"`
|
2015-09-18 05:33:42 +08:00
|
|
|
|
2019-07-11 16:23:53 +08:00
|
|
|
NativeBridgeArch *string `json:",omitempty"`
|
|
|
|
NativeBridgeArchVariant *string `json:",omitempty"`
|
|
|
|
NativeBridgeCpuVariant *string `json:",omitempty"`
|
|
|
|
NativeBridgeAbi []string `json:",omitempty"`
|
|
|
|
NativeBridgeRelativePath *string `json:",omitempty"`
|
|
|
|
|
|
|
|
NativeBridgeSecondaryArch *string `json:",omitempty"`
|
|
|
|
NativeBridgeSecondaryArchVariant *string `json:",omitempty"`
|
|
|
|
NativeBridgeSecondaryCpuVariant *string `json:",omitempty"`
|
|
|
|
NativeBridgeSecondaryAbi []string `json:",omitempty"`
|
|
|
|
NativeBridgeSecondaryRelativePath *string `json:",omitempty"`
|
2019-03-26 19:39:31 +08:00
|
|
|
|
2015-09-18 05:33:42 +08:00
|
|
|
HostArch *string `json:",omitempty"`
|
|
|
|
HostSecondaryArch *string `json:",omitempty"`
|
2015-11-25 09:53:15 +08:00
|
|
|
|
|
|
|
CrossHost *string `json:",omitempty"`
|
|
|
|
CrossHostArch *string `json:",omitempty"`
|
|
|
|
CrossHostSecondaryArch *string `json:",omitempty"`
|
2015-12-02 08:31:16 +08:00
|
|
|
|
2021-02-19 11:11:51 +08:00
|
|
|
DeviceResourceOverlays []string `json:",omitempty"`
|
|
|
|
ProductResourceOverlays []string `json:",omitempty"`
|
|
|
|
EnforceRROTargets []string `json:",omitempty"`
|
2019-02-01 06:31:51 +08:00
|
|
|
EnforceRROExcludedOverlays []string `json:",omitempty"`
|
2017-10-31 08:32:15 +08:00
|
|
|
|
2019-02-01 06:31:51 +08:00
|
|
|
AAPTCharacteristics *string `json:",omitempty"`
|
|
|
|
AAPTConfig []string `json:",omitempty"`
|
|
|
|
AAPTPreferredConfig *string `json:",omitempty"`
|
|
|
|
AAPTPrebuiltDPI []string `json:",omitempty"`
|
2017-10-31 08:32:15 +08:00
|
|
|
|
2017-12-02 09:16:02 +08:00
|
|
|
DefaultAppCertificate *string `json:",omitempty"`
|
|
|
|
|
2017-10-31 08:32:15 +08:00
|
|
|
AppsDefaultVersionName *string `json:",omitempty"`
|
|
|
|
|
2020-07-08 00:09:23 +08:00
|
|
|
Allow_missing_dependencies *bool `json:",omitempty"`
|
|
|
|
Unbundled_build *bool `json:",omitempty"`
|
|
|
|
Unbundled_build_apps *bool `json:",omitempty"`
|
|
|
|
Always_use_prebuilt_sdks *bool `json:",omitempty"`
|
2020-10-29 03:20:06 +08:00
|
|
|
Skip_boot_jars_check *bool `json:",omitempty"`
|
2020-07-08 00:09:23 +08:00
|
|
|
Malloc_not_svelte *bool `json:",omitempty"`
|
|
|
|
Malloc_zero_contents *bool `json:",omitempty"`
|
|
|
|
Malloc_pattern_fill_contents *bool `json:",omitempty"`
|
|
|
|
Safestack *bool `json:",omitempty"`
|
|
|
|
HostStaticBinaries *bool `json:",omitempty"`
|
|
|
|
Binder32bit *bool `json:",omitempty"`
|
|
|
|
UseGoma *bool `json:",omitempty"`
|
|
|
|
UseRBE *bool `json:",omitempty"`
|
|
|
|
UseRBEJAVAC *bool `json:",omitempty"`
|
|
|
|
UseRBER8 *bool `json:",omitempty"`
|
|
|
|
UseRBED8 *bool `json:",omitempty"`
|
|
|
|
Debuggable *bool `json:",omitempty"`
|
|
|
|
Eng *bool `json:",omitempty"`
|
|
|
|
Treble_linker_namespaces *bool `json:",omitempty"`
|
|
|
|
Enforce_vintf_manifest *bool `json:",omitempty"`
|
|
|
|
Uml *bool `json:",omitempty"`
|
|
|
|
Arc *bool `json:",omitempty"`
|
|
|
|
MinimizeJavaDebugInfo *bool `json:",omitempty"`
|
2016-01-07 06:41:07 +08:00
|
|
|
|
2018-11-20 11:59:08 +08:00
|
|
|
Check_elf_files *bool `json:",omitempty"`
|
|
|
|
|
2018-10-06 05:20:06 +08:00
|
|
|
UncompressPrivAppDex *bool `json:",omitempty"`
|
|
|
|
ModulesLoadedByPrivilegedModules []string `json:",omitempty"`
|
2018-11-13 02:13:39 +08:00
|
|
|
|
2020-10-24 04:14:20 +08:00
|
|
|
BootJars ConfiguredJarList `json:",omitempty"`
|
|
|
|
UpdatableBootJars ConfiguredJarList `json:",omitempty"`
|
2018-12-21 23:54:16 +08:00
|
|
|
|
2019-02-01 06:31:51 +08:00
|
|
|
IntegerOverflowExcludePaths []string `json:",omitempty"`
|
2017-07-14 05:46:05 +08:00
|
|
|
|
2019-02-01 06:31:51 +08:00
|
|
|
EnableCFI *bool `json:",omitempty"`
|
|
|
|
CFIExcludePaths []string `json:",omitempty"`
|
|
|
|
CFIIncludePaths []string `json:",omitempty"`
|
2017-10-31 17:26:14 +08:00
|
|
|
|
2019-02-02 00:42:56 +08:00
|
|
|
DisableScudo *bool `json:",omitempty"`
|
|
|
|
|
2021-01-06 08:41:26 +08:00
|
|
|
MemtagHeapExcludePaths []string `json:",omitempty"`
|
|
|
|
MemtagHeapAsyncIncludePaths []string `json:",omitempty"`
|
|
|
|
MemtagHeapSyncIncludePaths []string `json:",omitempty"`
|
|
|
|
|
2019-06-25 15:47:17 +08:00
|
|
|
VendorPath *string `json:",omitempty"`
|
|
|
|
OdmPath *string `json:",omitempty"`
|
|
|
|
ProductPath *string `json:",omitempty"`
|
|
|
|
SystemExtPath *string `json:",omitempty"`
|
2016-12-06 09:16:02 +08:00
|
|
|
|
2016-09-27 06:45:04 +08:00
|
|
|
ClangTidy *bool `json:",omitempty"`
|
|
|
|
TidyChecks *string `json:",omitempty"`
|
|
|
|
|
2020-04-08 08:22:26 +08:00
|
|
|
SamplingPGO *bool `json:",omitempty"`
|
2020-03-20 15:22:27 +08:00
|
|
|
|
2020-06-09 20:07:36 +08:00
|
|
|
JavaCoveragePaths []string `json:",omitempty"`
|
|
|
|
JavaCoverageExcludePaths []string `json:",omitempty"`
|
|
|
|
|
2020-06-17 08:51:46 +08:00
|
|
|
GcovCoverage *bool `json:",omitempty"`
|
2020-06-09 19:44:06 +08:00
|
|
|
ClangCoverage *bool `json:",omitempty"`
|
|
|
|
NativeCoveragePaths []string `json:",omitempty"`
|
|
|
|
NativeCoverageExcludePaths []string `json:",omitempty"`
|
2017-02-10 08:16:31 +08:00
|
|
|
|
2020-06-17 08:51:46 +08:00
|
|
|
// Set by NewConfig
|
|
|
|
Native_coverage *bool
|
|
|
|
|
2016-11-03 05:34:39 +08:00
|
|
|
SanitizeHost []string `json:",omitempty"`
|
|
|
|
SanitizeDevice []string `json:",omitempty"`
|
2017-06-29 00:10:48 +08:00
|
|
|
SanitizeDeviceDiag []string `json:",omitempty"`
|
2016-11-03 05:34:39 +08:00
|
|
|
SanitizeDeviceArch []string `json:",omitempty"`
|
2016-12-20 05:44:41 +08:00
|
|
|
|
|
|
|
ArtUseReadBarrier *bool `json:",omitempty"`
|
2016-12-09 07:45:07 +08:00
|
|
|
|
|
|
|
BtConfigIncludeDir *string `json:",omitempty"`
|
2017-05-05 04:57:05 +08:00
|
|
|
|
|
|
|
Override_rs_driver *string `json:",omitempty"`
|
2017-07-03 12:18:12 +08:00
|
|
|
|
2019-01-17 04:06:11 +08:00
|
|
|
Fuchsia *bool `json:",omitempty"`
|
|
|
|
|
2017-07-03 12:18:12 +08:00
|
|
|
DeviceKernelHeaders []string `json:",omitempty"`
|
Install VNDK snapshot libraries for system build
When BOARD_VNDK_VERSION := <VNDK version>, or
PRODUCT_EXTRA_VNDK_VERSIONS includes the needed <VNDK version> list,
the prebuilt VNDK libs in prebuilts/vndk/ directory will be
installed.
Each prebuilt VNDK module uses "vndk_prebuilt_shared" for shared
VNDK/VNDK-SP libs.
Following is the sample configuration of a vndk snapshot module:
vndk_prebuilt_shared {
name: "libfoo",
version: "27",
vendor_available: true,
vndk: {
enabled: true,
},
arch: {
arm64: {
srcs: ["arm/lib64/libfoo.so"],
},
arm: {
srcs: ["arm/lib/libfoo.so"],
},
},
}
The Android.bp for the snapshot modules will be auto-generated by a
script.
Bug: 38304393
Bug: 65377115
Bug: 68123344
Test: set BOARD_VNDK_VERSION := 27
copy a snapshot for v27
build with make command
Change-Id: Ib93107530dbabb4a24583f4d6e4f0c513c9adfec
2017-11-17 11:10:28 +08:00
|
|
|
|
|
|
|
ExtraVndkVersions []string `json:",omitempty"`
|
2017-11-30 08:47:17 +08:00
|
|
|
|
|
|
|
NamespacesToExport []string `json:",omitempty"`
|
2018-01-30 15:11:42 +08:00
|
|
|
|
|
|
|
PgoAdditionalProfileDirs []string `json:",omitempty"`
|
2018-03-27 03:41:18 +08:00
|
|
|
|
2019-05-14 17:52:49 +08:00
|
|
|
VndkUseCoreVariant *bool `json:",omitempty"`
|
|
|
|
VndkSnapshotBuildArtifacts *bool `json:",omitempty"`
|
2018-11-13 12:19:56 +08:00
|
|
|
|
2021-01-06 22:06:52 +08:00
|
|
|
DirectedVendorSnapshot bool `json:",omitempty"`
|
|
|
|
VendorSnapshotModules map[string]bool `json:",omitempty"`
|
|
|
|
|
2021-02-09 23:44:30 +08:00
|
|
|
DirectedRecoverySnapshot bool `json:",omitempty"`
|
|
|
|
RecoverySnapshotModules map[string]bool `json:",omitempty"`
|
|
|
|
|
2021-02-25 02:49:43 +08:00
|
|
|
VendorSnapshotDirsIncluded []string `json:",omitempty"`
|
|
|
|
VendorSnapshotDirsExcluded []string `json:",omitempty"`
|
|
|
|
RecoverySnapshotDirsExcluded []string `json:",omitempty"`
|
|
|
|
RecoverySnapshotDirsIncluded []string `json:",omitempty"`
|
|
|
|
|
2018-05-21 05:34:48 +08:00
|
|
|
BoardVendorSepolicyDirs []string `json:",omitempty"`
|
|
|
|
BoardOdmSepolicyDirs []string `json:",omitempty"`
|
2020-12-09 22:08:17 +08:00
|
|
|
BoardReqdMaskPolicy []string `json:",omitempty"`
|
2020-05-18 00:28:35 +08:00
|
|
|
SystemExtPublicSepolicyDirs []string `json:",omitempty"`
|
|
|
|
SystemExtPrivateSepolicyDirs []string `json:",omitempty"`
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I49206e656564206d6f7265206361666665696e65
2019-04-15 19:21:29 +08:00
|
|
|
BoardSepolicyM4Defs []string `json:",omitempty"`
|
2018-03-26 11:00:00 +08:00
|
|
|
|
2020-12-09 22:08:17 +08:00
|
|
|
BoardSepolicyVers *string `json:",omitempty"`
|
|
|
|
PlatformSepolicyVersion *string `json:",omitempty"`
|
|
|
|
|
2018-03-27 03:41:18 +08:00
|
|
|
VendorVars map[string]map[string]string `json:",omitempty"`
|
2018-10-25 07:10:32 +08:00
|
|
|
|
2021-04-14 06:55:47 +08:00
|
|
|
Ndk_abis *bool `json:",omitempty"`
|
2018-11-08 01:50:25 +08:00
|
|
|
|
2021-01-05 20:01:11 +08:00
|
|
|
Flatten_apex *bool `json:",omitempty"`
|
|
|
|
ForceApexSymlinkOptimization *bool `json:",omitempty"`
|
|
|
|
CompressedApex *bool `json:",omitempty"`
|
|
|
|
Aml_abis *bool `json:",omitempty"`
|
2018-11-13 02:13:39 +08:00
|
|
|
|
|
|
|
DexpreoptGlobalConfig *string `json:",omitempty"`
|
2019-01-05 11:57:48 +08:00
|
|
|
|
2021-03-23 19:52:24 +08:00
|
|
|
WithDexpreopt bool `json:",omitempty"`
|
|
|
|
|
2019-01-05 11:57:48 +08:00
|
|
|
ManifestPackageNameOverrides []string `json:",omitempty"`
|
2019-01-19 06:27:16 +08:00
|
|
|
CertificateOverrides []string `json:",omitempty"`
|
2019-01-24 08:27:47 +08:00
|
|
|
PackageNameOverrides []string `json:",omitempty"`
|
2019-01-07 11:07:27 +08:00
|
|
|
|
|
|
|
EnforceSystemCertificate *bool `json:",omitempty"`
|
2020-06-12 02:32:11 +08:00
|
|
|
EnforceSystemCertificateAllowList []string `json:",omitempty"`
|
2019-01-17 07:15:52 +08:00
|
|
|
|
2019-02-01 06:12:44 +08:00
|
|
|
ProductHiddenAPIStubs []string `json:",omitempty"`
|
|
|
|
ProductHiddenAPIStubsSystem []string `json:",omitempty"`
|
|
|
|
ProductHiddenAPIStubsTest []string `json:",omitempty"`
|
2019-04-11 03:27:35 +08:00
|
|
|
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I49206e656564206d6f7265206361666665696e65
2019-04-15 19:21:29 +08:00
|
|
|
ProductPublicSepolicyDirs []string `json:",omitempty"`
|
|
|
|
ProductPrivateSepolicyDirs []string `json:",omitempty"`
|
|
|
|
|
2019-11-18 18:52:14 +08:00
|
|
|
ProductVndkVersion *string `json:",omitempty"`
|
|
|
|
|
2019-04-19 01:08:46 +08:00
|
|
|
TargetFSConfigGen []string `json:",omitempty"`
|
2019-05-17 03:28:22 +08:00
|
|
|
|
|
|
|
MissingUsesLibraries []string `json:",omitempty"`
|
2019-10-29 14:44:45 +08:00
|
|
|
|
|
|
|
EnforceProductPartitionInterface *bool `json:",omitempty"`
|
2019-12-05 15:27:44 +08:00
|
|
|
|
2020-10-19 16:25:58 +08:00
|
|
|
EnforceInterPartitionJavaSdkLibrary *bool `json:",omitempty"`
|
|
|
|
InterPartitionJavaLibraryAllowList []string `json:",omitempty"`
|
|
|
|
|
2019-12-05 15:27:44 +08:00
|
|
|
InstallExtraFlattenedApexes *bool `json:",omitempty"`
|
2020-01-22 08:12:26 +08:00
|
|
|
|
|
|
|
BoardUsesRecoveryAsBoot *bool `json:",omitempty"`
|
2020-07-30 00:51:57 +08:00
|
|
|
|
2020-08-06 05:36:09 +08:00
|
|
|
BoardKernelBinaries []string `json:",omitempty"`
|
|
|
|
BoardKernelModuleInterfaceVersions []string `json:",omitempty"`
|
2020-10-22 06:40:17 +08:00
|
|
|
|
|
|
|
BoardMoveRecoveryResourcesToVendorBoot *bool `json:",omitempty"`
|
2021-01-09 01:34:44 +08:00
|
|
|
|
|
|
|
PrebuiltHiddenApiDir *string `json:",omitempty"`
|
2020-12-21 21:53:05 +08:00
|
|
|
|
|
|
|
ShippingApiLevel *string `json:",omitempty"`
|
2021-02-03 17:16:46 +08:00
|
|
|
|
2021-03-17 17:05:33 +08:00
|
|
|
BuildBrokenEnforceSyspropOwner bool `json:",omitempty"`
|
|
|
|
BuildBrokenTrebleSyspropNeverallow bool `json:",omitempty"`
|
2021-02-03 17:16:46 +08:00
|
|
|
BuildBrokenVendorPropertyNamespace bool `json:",omitempty"`
|
2021-03-17 17:05:33 +08:00
|
|
|
|
2021-04-03 07:45:24 +08:00
|
|
|
BuildDebugfsRestrictionsEnabled bool `json:",omitempty"`
|
|
|
|
|
2021-03-17 17:05:33 +08:00
|
|
|
RequiresInsecureExecmemForSwiftshader bool `json:",omitempty"`
|
|
|
|
|
|
|
|
SelinuxIgnoreNeverallows bool `json:",omitempty"`
|
|
|
|
|
|
|
|
SepolicySplit bool `json:",omitempty"`
|
2015-09-17 04:53:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func boolPtr(v bool) *bool {
|
|
|
|
return &v
|
2015-08-28 04:28:01 +08:00
|
|
|
}
|
|
|
|
|
2015-09-17 07:48:54 +08:00
|
|
|
func intPtr(v int) *int {
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:33:42 +08:00
|
|
|
func stringPtr(v string) *string {
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
|
2015-09-19 01:57:10 +08:00
|
|
|
func (v *productVariables) SetDefaultConfig() {
|
|
|
|
*v = productVariables{
|
2020-02-22 08:55:46 +08:00
|
|
|
BuildNumberFile: stringPtr("build_number.txt"),
|
2019-04-08 00:41:44 +08:00
|
|
|
|
2020-09-25 12:44:51 +08:00
|
|
|
Platform_version_name: stringPtr("S"),
|
|
|
|
Platform_sdk_version: intPtr(30),
|
|
|
|
Platform_sdk_codename: stringPtr("S"),
|
2019-04-08 00:41:44 +08:00
|
|
|
Platform_sdk_final: boolPtr(false),
|
2020-09-25 12:44:51 +08:00
|
|
|
Platform_version_active_codenames: []string{"S"},
|
|
|
|
Platform_vndk_version: stringPtr("S"),
|
2017-11-14 06:34:56 +08:00
|
|
|
|
2015-09-18 05:33:42 +08:00
|
|
|
HostArch: stringPtr("x86_64"),
|
|
|
|
HostSecondaryArch: stringPtr("x86"),
|
2017-11-14 06:34:56 +08:00
|
|
|
DeviceName: stringPtr("generic_arm64"),
|
2015-09-18 05:33:42 +08:00
|
|
|
DeviceArch: stringPtr("arm64"),
|
2016-03-30 13:06:05 +08:00
|
|
|
DeviceArchVariant: stringPtr("armv8-a"),
|
2017-11-14 06:34:56 +08:00
|
|
|
DeviceCpuVariant: stringPtr("generic"),
|
2019-02-01 06:31:51 +08:00
|
|
|
DeviceAbi: []string{"arm64-v8a"},
|
2015-09-18 05:33:42 +08:00
|
|
|
DeviceSecondaryArch: stringPtr("arm"),
|
2017-11-14 06:34:56 +08:00
|
|
|
DeviceSecondaryArchVariant: stringPtr("armv8-a"),
|
|
|
|
DeviceSecondaryCpuVariant: stringPtr("generic"),
|
2019-02-01 06:31:51 +08:00
|
|
|
DeviceSecondaryAbi: []string{"armeabi-v7a", "armeabi"},
|
2017-10-31 08:32:15 +08:00
|
|
|
|
2019-02-01 06:31:51 +08:00
|
|
|
AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
|
2017-10-31 08:32:15 +08:00
|
|
|
AAPTPreferredConfig: stringPtr("xhdpi"),
|
|
|
|
AAPTCharacteristics: stringPtr("nosdcard"),
|
2019-02-01 06:31:51 +08:00
|
|
|
AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"},
|
2017-10-31 08:32:15 +08:00
|
|
|
|
2020-04-30 05:57:30 +08:00
|
|
|
Malloc_not_svelte: boolPtr(true),
|
2020-07-31 04:38:49 +08:00
|
|
|
Malloc_zero_contents: boolPtr(true),
|
2020-04-30 05:57:30 +08:00
|
|
|
Malloc_pattern_fill_contents: boolPtr(false),
|
|
|
|
Safestack: boolPtr(false),
|
2021-03-17 20:34:30 +08:00
|
|
|
|
|
|
|
BootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
|
|
|
|
UpdatableBootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
|
2015-08-28 04:28:01 +08:00
|
|
|
}
|
2015-11-25 09:53:15 +08:00
|
|
|
|
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
v.CrossHost = stringPtr("windows")
|
|
|
|
v.CrossHostArch = stringPtr("x86")
|
2016-02-04 15:16:33 +08:00
|
|
|
v.CrossHostSecondaryArch = stringPtr("x86_64")
|
2015-11-25 09:53:15 +08:00
|
|
|
}
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
|
|
|
|
2021-03-24 22:14:47 +08:00
|
|
|
// ProductConfigContext requires the access to the Module to get product config properties.
|
|
|
|
type ProductConfigContext interface {
|
|
|
|
Module() Module
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProductConfigProperty contains the information for a single property (may be a struct) paired
|
|
|
|
// with the appropriate ProductConfigVariable.
|
|
|
|
type ProductConfigProperty struct {
|
|
|
|
ProductConfigVariable string
|
|
|
|
Property interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProductConfigProperties is a map of property name to a slice of ProductConfigProperty such that
|
|
|
|
// all it all product variable-specific versions of a property are easily accessed together
|
|
|
|
type ProductConfigProperties map[string][]ProductConfigProperty
|
|
|
|
|
|
|
|
// ProductVariableProperties returns a ProductConfigProperties containing only the properties which
|
|
|
|
// have been set for the module in the given context.
|
|
|
|
func ProductVariableProperties(ctx ProductConfigContext) ProductConfigProperties {
|
|
|
|
module := ctx.Module()
|
|
|
|
moduleBase := module.base()
|
|
|
|
|
|
|
|
productConfigProperties := ProductConfigProperties{}
|
|
|
|
|
|
|
|
if moduleBase.variableProperties == nil {
|
|
|
|
return productConfigProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
variableValues := reflect.ValueOf(moduleBase.variableProperties).Elem().FieldByName("Product_variables")
|
|
|
|
for i := 0; i < variableValues.NumField(); i++ {
|
|
|
|
variableValue := variableValues.Field(i)
|
|
|
|
// Check if any properties were set for the module
|
|
|
|
if variableValue.IsZero() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// e.g. Platform_sdk_version, Unbundled_build, Malloc_not_svelte, etc.
|
|
|
|
productVariableName := variableValues.Type().Field(i).Name
|
|
|
|
for j := 0; j < variableValue.NumField(); j++ {
|
|
|
|
property := variableValue.Field(j)
|
|
|
|
// If the property wasn't set, no need to pass it along
|
|
|
|
if property.IsZero() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// e.g. Asflags, Cflags, Enabled, etc.
|
|
|
|
propertyName := variableValue.Type().Field(j).Name
|
|
|
|
productConfigProperties[propertyName] = append(productConfigProperties[propertyName],
|
|
|
|
ProductConfigProperty{
|
|
|
|
ProductConfigVariable: productVariableName,
|
|
|
|
Property: property.Interface(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return productConfigProperties
|
|
|
|
}
|
|
|
|
|
2020-02-07 09:01:55 +08:00
|
|
|
func VariableMutator(mctx BottomUpMutatorContext) {
|
2016-05-19 06:37:25 +08:00
|
|
|
var module Module
|
2015-07-10 04:57:48 +08:00
|
|
|
var ok bool
|
2016-05-19 06:37:25 +08:00
|
|
|
if module, ok = mctx.Module().(Module); !ok {
|
2015-07-10 04:57:48 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: depend on config variable, create variants, propagate variants up tree
|
|
|
|
a := module.base()
|
2019-09-25 13:19:02 +08:00
|
|
|
|
|
|
|
if a.variableProperties == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
variableValues := reflect.ValueOf(a.variableProperties).Elem().FieldByName("Product_variables")
|
2015-07-10 04:57:48 +08:00
|
|
|
|
2021-01-21 03:27:32 +08:00
|
|
|
productVariables := reflect.ValueOf(mctx.Config().productVariables)
|
|
|
|
|
2015-07-10 04:57:48 +08:00
|
|
|
for i := 0; i < variableValues.NumField(); i++ {
|
|
|
|
variableValue := variableValues.Field(i)
|
2015-08-28 04:28:01 +08:00
|
|
|
name := variableValues.Type().Field(i).Name
|
|
|
|
property := "product_variables." + proptools.PropertyNameForField(name)
|
|
|
|
|
2015-09-17 04:53:42 +08:00
|
|
|
// Check that the variable was set for the product
|
2021-01-21 03:27:32 +08:00
|
|
|
val := productVariables.FieldByName(name)
|
2015-09-17 04:53:42 +08:00
|
|
|
if !val.IsValid() || val.Kind() != reflect.Ptr || val.IsNil() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
val = val.Elem()
|
|
|
|
|
|
|
|
// For bools, check that the value is true
|
|
|
|
if val.Kind() == reflect.Bool && val.Bool() == false {
|
|
|
|
continue
|
|
|
|
}
|
2015-07-10 04:57:48 +08:00
|
|
|
|
2015-09-17 04:53:42 +08:00
|
|
|
// Check if any properties were set for the module
|
2020-02-07 08:57:45 +08:00
|
|
|
if variableValue.IsZero() {
|
2015-09-17 04:53:42 +08:00
|
|
|
continue
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
2015-09-17 04:53:42 +08:00
|
|
|
a.setVariableProperties(mctx, property, variableValue, val.Interface())
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-07 07:57:04 +08:00
|
|
|
func (m *ModuleBase) setVariableProperties(ctx BottomUpMutatorContext,
|
2015-07-10 04:57:48 +08:00
|
|
|
prefix string, productVariablePropertyValue reflect.Value, variableValue interface{}) {
|
|
|
|
|
2017-05-06 07:16:24 +08:00
|
|
|
printfIntoProperties(ctx, prefix, productVariablePropertyValue, variableValue)
|
2015-07-10 04:57:48 +08:00
|
|
|
|
2019-06-07 07:57:04 +08:00
|
|
|
err := proptools.AppendMatchingProperties(m.generalProperties,
|
2015-10-29 08:23:31 +08:00
|
|
|
productVariablePropertyValue.Addr().Interface(), nil)
|
|
|
|
if err != nil {
|
|
|
|
if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
|
|
|
|
ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
|
|
|
|
} else {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
|
|
|
|
2017-05-06 07:16:24 +08:00
|
|
|
func printfIntoPropertiesError(ctx BottomUpMutatorContext, prefix string,
|
|
|
|
productVariablePropertyValue reflect.Value, i int, err error) {
|
|
|
|
|
|
|
|
field := productVariablePropertyValue.Type().Field(i).Name
|
|
|
|
property := prefix + "." + proptools.PropertyNameForField(field)
|
|
|
|
ctx.PropertyErrorf(property, "%s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func printfIntoProperties(ctx BottomUpMutatorContext, prefix string,
|
|
|
|
productVariablePropertyValue reflect.Value, variableValue interface{}) {
|
|
|
|
|
2015-07-10 04:57:48 +08:00
|
|
|
for i := 0; i < productVariablePropertyValue.NumField(); i++ {
|
|
|
|
propertyValue := productVariablePropertyValue.Field(i)
|
2015-12-03 07:24:38 +08:00
|
|
|
kind := propertyValue.Kind()
|
|
|
|
if kind == reflect.Ptr {
|
|
|
|
if propertyValue.IsNil() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
propertyValue = propertyValue.Elem()
|
|
|
|
}
|
2015-07-10 04:57:48 +08:00
|
|
|
switch propertyValue.Kind() {
|
|
|
|
case reflect.String:
|
2017-05-06 07:16:24 +08:00
|
|
|
err := printfIntoProperty(propertyValue, variableValue)
|
|
|
|
if err != nil {
|
|
|
|
printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err)
|
|
|
|
}
|
2015-07-10 04:57:48 +08:00
|
|
|
case reflect.Slice:
|
|
|
|
for j := 0; j < propertyValue.Len(); j++ {
|
2017-05-06 07:16:24 +08:00
|
|
|
err := printfIntoProperty(propertyValue.Index(j), variableValue)
|
|
|
|
if err != nil {
|
|
|
|
printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err)
|
|
|
|
}
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
2015-12-03 07:24:38 +08:00
|
|
|
case reflect.Bool:
|
|
|
|
// Nothing
|
2015-07-10 04:57:48 +08:00
|
|
|
case reflect.Struct:
|
2017-05-06 07:16:24 +08:00
|
|
|
printfIntoProperties(ctx, prefix, propertyValue, variableValue)
|
2015-07-10 04:57:48 +08:00
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("unsupported field kind %q", propertyValue.Kind()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-06 07:16:24 +08:00
|
|
|
func printfIntoProperty(propertyValue reflect.Value, variableValue interface{}) error {
|
2015-07-10 04:57:48 +08:00
|
|
|
s := propertyValue.String()
|
2017-05-06 07:16:24 +08:00
|
|
|
|
|
|
|
count := strings.Count(s, "%")
|
|
|
|
if count == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if count > 1 {
|
|
|
|
return fmt.Errorf("product variable properties only support a single '%%'")
|
|
|
|
}
|
|
|
|
|
2015-07-10 04:57:48 +08:00
|
|
|
if strings.Contains(s, "%d") {
|
|
|
|
switch v := variableValue.(type) {
|
|
|
|
case int:
|
2017-05-06 07:16:24 +08:00
|
|
|
// Nothing
|
2015-07-10 04:57:48 +08:00
|
|
|
case bool:
|
|
|
|
if v {
|
2017-05-06 07:16:24 +08:00
|
|
|
variableValue = 1
|
|
|
|
} else {
|
|
|
|
variableValue = 0
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
|
|
|
default:
|
2017-05-06 07:16:24 +08:00
|
|
|
return fmt.Errorf("unsupported type %T for %%d", variableValue)
|
|
|
|
}
|
|
|
|
} else if strings.Contains(s, "%s") {
|
|
|
|
switch variableValue.(type) {
|
|
|
|
case string:
|
|
|
|
// Nothing
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("unsupported type %T for %%s", variableValue)
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
2017-05-06 07:16:24 +08:00
|
|
|
} else {
|
|
|
|
return fmt.Errorf("unsupported %% in product variable property")
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
2017-05-06 07:16:24 +08:00
|
|
|
|
|
|
|
propertyValue.Set(reflect.ValueOf(fmt.Sprintf(s, variableValue)))
|
|
|
|
|
|
|
|
return nil
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
2019-09-25 13:19:02 +08:00
|
|
|
|
|
|
|
var variablePropTypeMap OncePer
|
|
|
|
|
|
|
|
// sliceToTypeArray takes a slice of property structs and returns a reflection created array containing the
|
|
|
|
// reflect.Types of each property struct. The result can be used as a key in a map.
|
|
|
|
func sliceToTypeArray(s []interface{}) interface{} {
|
|
|
|
// Create an array using reflection whose length is the length of the input slice
|
|
|
|
ret := reflect.New(reflect.ArrayOf(len(s), reflect.TypeOf(reflect.TypeOf(0)))).Elem()
|
|
|
|
for i, e := range s {
|
|
|
|
ret.Index(i).Set(reflect.ValueOf(reflect.TypeOf(e)))
|
|
|
|
}
|
|
|
|
return ret.Interface()
|
|
|
|
}
|
|
|
|
|
2020-02-07 09:01:55 +08:00
|
|
|
func initProductVariableModule(m Module) {
|
|
|
|
base := m.base()
|
|
|
|
|
|
|
|
// Allow tests to override the default product variables
|
|
|
|
if base.variableProperties == nil {
|
|
|
|
base.variableProperties = defaultProductVariables
|
|
|
|
}
|
|
|
|
// Filter the product variables properties to the ones that exist on this module
|
|
|
|
base.variableProperties = createVariableProperties(m.GetProperties(), base.variableProperties)
|
|
|
|
if base.variableProperties != nil {
|
|
|
|
m.AddProperties(base.variableProperties)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 13:19:02 +08:00
|
|
|
// createVariableProperties takes the list of property structs for a module and returns a property struct that
|
|
|
|
// contains the product variable properties that exist in the property structs, or nil if there are none. It
|
|
|
|
// caches the result.
|
|
|
|
func createVariableProperties(moduleTypeProps []interface{}, productVariables interface{}) interface{} {
|
|
|
|
// Convert the moduleTypeProps to an array of reflect.Types that can be used as a key in the OncePer.
|
|
|
|
key := sliceToTypeArray(moduleTypeProps)
|
|
|
|
|
|
|
|
// Use the variablePropTypeMap OncePer to cache the result for each set of property struct types.
|
|
|
|
typ, _ := variablePropTypeMap.Once(NewCustomOnceKey(key), func() interface{} {
|
|
|
|
// Compute the filtered property struct type.
|
|
|
|
return createVariablePropertiesType(moduleTypeProps, productVariables)
|
|
|
|
}).(reflect.Type)
|
|
|
|
|
|
|
|
if typ == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new pointer to a filtered property struct.
|
|
|
|
return reflect.New(typ).Interface()
|
|
|
|
}
|
|
|
|
|
|
|
|
// createVariablePropertiesType creates a new type that contains only the product variable properties that exist in
|
|
|
|
// a list of property structs.
|
|
|
|
func createVariablePropertiesType(moduleTypeProps []interface{}, productVariables interface{}) reflect.Type {
|
|
|
|
typ, _ := proptools.FilterPropertyStruct(reflect.TypeOf(productVariables),
|
|
|
|
func(field reflect.StructField, prefix string) (bool, reflect.StructField) {
|
|
|
|
// Filter function, returns true if the field should be in the resulting struct
|
|
|
|
if prefix == "" {
|
|
|
|
// Keep the top level Product_variables field
|
|
|
|
return true, field
|
|
|
|
}
|
|
|
|
_, rest := splitPrefix(prefix)
|
|
|
|
if rest == "" {
|
|
|
|
// Keep the 2nd level field (i.e. Product_variables.Eng)
|
|
|
|
return true, field
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strip off the first 2 levels of the prefix
|
|
|
|
_, prefix = splitPrefix(rest)
|
|
|
|
|
|
|
|
for _, p := range moduleTypeProps {
|
|
|
|
if fieldExistsByNameRecursive(reflect.TypeOf(p).Elem(), prefix, field.Name) {
|
|
|
|
// Keep any fields that exist in one of the property structs
|
|
|
|
return true, field
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, field
|
|
|
|
})
|
|
|
|
return typ
|
|
|
|
}
|
|
|
|
|
|
|
|
func splitPrefix(prefix string) (first, rest string) {
|
|
|
|
index := strings.IndexByte(prefix, '.')
|
|
|
|
if index == -1 {
|
|
|
|
return prefix, ""
|
|
|
|
}
|
|
|
|
return prefix[:index], prefix[index+1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
func fieldExistsByNameRecursive(t reflect.Type, prefix, name string) bool {
|
|
|
|
if t.Kind() != reflect.Struct {
|
|
|
|
panic(fmt.Errorf("fieldExistsByNameRecursive can only be called on a reflect.Struct"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if prefix != "" {
|
|
|
|
split := strings.SplitN(prefix, ".", 2)
|
|
|
|
firstPrefix := split[0]
|
|
|
|
rest := ""
|
|
|
|
if len(split) > 1 {
|
|
|
|
rest = split[1]
|
|
|
|
}
|
|
|
|
f, exists := t.FieldByName(firstPrefix)
|
|
|
|
if !exists {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
ft := f.Type
|
|
|
|
if ft.Kind() == reflect.Ptr {
|
|
|
|
ft = ft.Elem()
|
|
|
|
}
|
|
|
|
if ft.Kind() != reflect.Struct {
|
|
|
|
panic(fmt.Errorf("field %q in %q is not a struct", firstPrefix, t))
|
|
|
|
}
|
|
|
|
return fieldExistsByNameRecursive(ft, rest, name)
|
|
|
|
} else {
|
|
|
|
_, exists := t.FieldByName(name)
|
|
|
|
return exists
|
|
|
|
}
|
|
|
|
}
|