2015-07-09 22:57:48 +02: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 00:37:25 +02:00
|
|
|
package android
|
2015-07-09 22:57:48 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2015-11-25 02:53:15 +01:00
|
|
|
"runtime"
|
2015-07-09 22:57:48 +02:00
|
|
|
"strings"
|
|
|
|
|
2021-11-24 04:02:08 +01:00
|
|
|
"android/soong/bazel"
|
|
|
|
|
2015-07-09 22:57:48 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-03-07 16:46:33 +01:00
|
|
|
registerVariableBuildComponents(InitRegistrationContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerVariableBuildComponents(ctx RegistrationContext) {
|
|
|
|
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
2020-02-07 02:01:55 +01:00
|
|
|
ctx.BottomUp("variable", VariableMutator).Parallel()
|
2016-10-12 23:38:15 +02:00
|
|
|
})
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
|
|
|
|
2021-03-07 16:46:33 +01:00
|
|
|
var PrepareForTestWithVariables = FixtureRegisterWithContext(registerVariableBuildComponents)
|
|
|
|
|
2015-07-09 22:57:48 +02:00
|
|
|
type variableProperties struct {
|
|
|
|
Product_variables struct {
|
2015-09-17 01:48:54 +02:00
|
|
|
Platform_sdk_version struct {
|
|
|
|
Asflags []string
|
2017-05-08 22:43:00 +02:00
|
|
|
Cflags []string
|
2021-07-14 06:52:04 +02:00
|
|
|
Cmd *string
|
2015-09-17 01:48:54 +02:00
|
|
|
}
|
2015-12-02 01:31:16 +01:00
|
|
|
|
2021-08-10 00:44:44 +02:00
|
|
|
Platform_sdk_version_or_codename struct {
|
|
|
|
Java_resource_dirs []string
|
|
|
|
}
|
|
|
|
|
2021-08-27 18:35:40 +02:00
|
|
|
Platform_sdk_extension_version struct {
|
|
|
|
Cmd *string
|
|
|
|
}
|
|
|
|
|
2021-07-14 06:52:04 +02:00
|
|
|
Platform_version_name struct {
|
|
|
|
Base_dir *string
|
|
|
|
}
|
|
|
|
|
2015-12-02 01:31:16 +01: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-05 23:27:55 +01:00
|
|
|
|
2023-02-09 02:47:59 +01:00
|
|
|
// similar to `Unbundled_build`, but `Always_use_prebuilt_sdks` means that it uses prebuilt
|
|
|
|
// sdk specifically.
|
|
|
|
Always_use_prebuilt_sdks struct {
|
|
|
|
Enabled *bool `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
|
2016-03-01 23:08:42 +01:00
|
|
|
Malloc_not_svelte struct {
|
2019-12-16 18:55:10 +01: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"`
|
2021-09-24 09:07:53 +02:00
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Header_libs []string `android:"arch_variant"`
|
2018-09-01 01:56:05 +02:00
|
|
|
} `android:"arch_variant"`
|
2016-05-13 03:04:18 +02:00
|
|
|
|
2020-04-29 23:57:30 +02: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 03:04:18 +02:00
|
|
|
Safestack struct {
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2016-07-12 23:57:40 +02:00
|
|
|
|
2016-07-26 02:42:18 +02:00
|
|
|
Binder32bit struct {
|
|
|
|
Cflags []string
|
|
|
|
}
|
2016-09-22 23:49:10 +02:00
|
|
|
|
2017-05-04 22:57:05 +02:00
|
|
|
Override_rs_driver struct {
|
|
|
|
Cflags []string
|
|
|
|
}
|
|
|
|
|
2017-12-13 23:06:20 +01: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
|
|
|
|
}
|
|
|
|
|
2023-06-02 00:31:52 +02:00
|
|
|
Build_from_text_stub struct {
|
|
|
|
Static_libs []string
|
|
|
|
Exclude_static_libs []string
|
|
|
|
}
|
|
|
|
|
2016-12-08 18:46:35 +01: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-22 23:49:10 +02:00
|
|
|
Debuggable struct {
|
2019-04-02 03:37:36 +02:00
|
|
|
Cflags []string
|
|
|
|
Cppflags []string
|
|
|
|
Init_rc []string
|
|
|
|
Required []string
|
|
|
|
Host_required []string
|
|
|
|
Target_required []string
|
2020-10-20 07:01:29 +02:00
|
|
|
Strip struct {
|
|
|
|
All *bool
|
|
|
|
Keep_symbols *bool
|
|
|
|
Keep_symbols_and_debug_frame *bool
|
|
|
|
}
|
2021-06-24 05:01:13 +02:00
|
|
|
Static_libs []string
|
|
|
|
Whole_static_libs []string
|
|
|
|
Shared_libs []string
|
2021-08-30 11:43:19 +02:00
|
|
|
|
|
|
|
Cmdline []string
|
2022-01-07 11:17:29 +01:00
|
|
|
|
2021-09-23 21:49:54 +02:00
|
|
|
Srcs []string
|
|
|
|
Exclude_srcs []string
|
2023-08-15 20:59:24 +02:00
|
|
|
Cmd *string
|
2016-09-22 23:49:10 +02:00
|
|
|
}
|
2016-12-08 18:46:35 +01:00
|
|
|
|
2022-01-11 08:44:21 +01:00
|
|
|
// eng is true for -eng builds, and can be used to turn on additional heavyweight debugging
|
2016-12-08 18:46:35 +01:00
|
|
|
// features.
|
|
|
|
Eng struct {
|
|
|
|
Cflags []string
|
|
|
|
Cppflags []string
|
2018-07-11 20:01:59 +02:00
|
|
|
Lto struct {
|
|
|
|
Never *bool
|
|
|
|
}
|
2018-10-27 08:58:42 +02:00
|
|
|
Sanitize struct {
|
|
|
|
Address *bool
|
|
|
|
}
|
2019-06-21 14:58:27 +02:00
|
|
|
Optimize struct {
|
|
|
|
Enabled *bool
|
|
|
|
}
|
2016-12-08 18:46:35 +01:00
|
|
|
}
|
2017-05-05 22:37:11 +02:00
|
|
|
|
2017-08-23 23:58:37 +02:00
|
|
|
Uml struct {
|
|
|
|
Cppflags []string
|
|
|
|
}
|
2017-11-27 10:14:46 +01:00
|
|
|
|
|
|
|
Arc struct {
|
2020-12-18 01:53:26 +01:00
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
2021-03-04 17:56:40 +01:00
|
|
|
Header_libs []string `android:"arch_variant"`
|
2020-12-18 01:53:26 +01: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 16:00:18 +02:00
|
|
|
|
2020-01-27 22:26:42 +01:00
|
|
|
Native_coverage struct {
|
2020-02-06 01:23:21 +01:00
|
|
|
Src *string `android:"arch_variant"`
|
2020-01-27 22:26:42 +01:00
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2023-07-07 00:03:58 +02:00
|
|
|
|
|
|
|
// release_aidl_use_unfrozen is "true" when a device can
|
|
|
|
// use the unfrozen versions of AIDL interfaces.
|
|
|
|
Release_aidl_use_unfrozen struct {
|
|
|
|
Cflags []string
|
|
|
|
Cmd *string
|
|
|
|
}
|
2015-12-02 01:31:16 +01:00
|
|
|
} `android:"arch_variant"`
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
|
|
|
|
2020-02-07 01:57:45 +01:00
|
|
|
var defaultProductVariables interface{} = variableProperties{}
|
2015-07-09 22:57:48 +02:00
|
|
|
|
2023-04-22 02:37:11 +02:00
|
|
|
type ProductVariables struct {
|
2016-05-11 09:27:49 +02:00
|
|
|
// Suffix to add to generated Makefiles
|
|
|
|
Make_suffix *string `json:",omitempty"`
|
|
|
|
|
2020-02-22 01:55:46 +01:00
|
|
|
BuildId *string `json:",omitempty"`
|
|
|
|
BuildNumberFile *string `json:",omitempty"`
|
2018-01-11 01:06:12 +01:00
|
|
|
|
2019-04-03 07:56:43 +02:00
|
|
|
Platform_version_name *string `json:",omitempty"`
|
|
|
|
Platform_sdk_version *int `json:",omitempty"`
|
|
|
|
Platform_sdk_codename *string `json:",omitempty"`
|
2021-08-10 00:44:44 +02:00
|
|
|
Platform_sdk_version_or_codename *string `json:",omitempty"`
|
2019-04-03 07:56:43 +02:00
|
|
|
Platform_sdk_final *bool `json:",omitempty"`
|
2021-08-27 18:35:40 +02:00
|
|
|
Platform_sdk_extension_version *int `json:",omitempty"`
|
2022-02-16 17:15:10 +01:00
|
|
|
Platform_base_sdk_extension_version *int `json:",omitempty"`
|
2019-04-03 07:56:43 +02:00
|
|
|
Platform_version_active_codenames []string `json:",omitempty"`
|
2023-03-27 22:34:01 +02:00
|
|
|
Platform_version_all_preview_codenames []string `json:",omitempty"`
|
2019-04-03 07:56:43 +02:00
|
|
|
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"`
|
2022-04-25 11:23:58 +02:00
|
|
|
Platform_version_last_stable *string `json:",omitempty"`
|
2022-06-21 03:13:42 +02:00
|
|
|
Platform_version_known_codenames *string `json:",omitempty"`
|
2018-01-15 07:05:10 +01:00
|
|
|
|
2020-08-06 16:00:37 +02:00
|
|
|
DeviceName *string `json:",omitempty"`
|
2022-03-21 20:34:02 +01:00
|
|
|
DeviceProduct *string `json:",omitempty"`
|
2020-08-06 16:00:37 +02:00
|
|
|
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"`
|
2023-04-07 19:35:35 +02:00
|
|
|
DeviceMaxPageSizeSupported *string `json:",omitempty"`
|
2023-12-04 23:51:20 +01:00
|
|
|
DeviceNoBionicPageSizeMacro *bool `json:",omitempty"`
|
2019-01-31 23:31:51 +01:00
|
|
|
|
2023-11-29 09:58:16 +01:00
|
|
|
VendorApiLevel *string `json:",omitempty"`
|
|
|
|
|
2020-12-11 22:36:29 +01:00
|
|
|
RecoverySnapshotVersion *string `json:",omitempty"`
|
|
|
|
|
2019-01-31 23:31:51 +01:00
|
|
|
DeviceSecondaryArch *string `json:",omitempty"`
|
|
|
|
DeviceSecondaryArchVariant *string `json:",omitempty"`
|
|
|
|
DeviceSecondaryCpuVariant *string `json:",omitempty"`
|
|
|
|
DeviceSecondaryAbi []string `json:",omitempty"`
|
2015-09-17 23:33:42 +02:00
|
|
|
|
2019-07-11 10:23:53 +02: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 12:39:31 +01:00
|
|
|
|
2015-09-17 23:33:42 +02:00
|
|
|
HostArch *string `json:",omitempty"`
|
|
|
|
HostSecondaryArch *string `json:",omitempty"`
|
2021-07-24 00:23:07 +02:00
|
|
|
HostMusl *bool `json:",omitempty"`
|
2015-11-25 02:53:15 +01:00
|
|
|
|
|
|
|
CrossHost *string `json:",omitempty"`
|
|
|
|
CrossHostArch *string `json:",omitempty"`
|
|
|
|
CrossHostSecondaryArch *string `json:",omitempty"`
|
2015-12-02 01:31:16 +01:00
|
|
|
|
2021-02-19 04:11:51 +01:00
|
|
|
DeviceResourceOverlays []string `json:",omitempty"`
|
|
|
|
ProductResourceOverlays []string `json:",omitempty"`
|
|
|
|
EnforceRROTargets []string `json:",omitempty"`
|
2019-01-31 23:31:51 +01:00
|
|
|
EnforceRROExcludedOverlays []string `json:",omitempty"`
|
2017-10-31 01:32:15 +01:00
|
|
|
|
2019-01-31 23:31:51 +01:00
|
|
|
AAPTCharacteristics *string `json:",omitempty"`
|
|
|
|
AAPTConfig []string `json:",omitempty"`
|
|
|
|
AAPTPreferredConfig *string `json:",omitempty"`
|
|
|
|
AAPTPrebuiltDPI []string `json:",omitempty"`
|
2017-10-31 01:32:15 +01:00
|
|
|
|
2022-08-12 14:36:25 +02:00
|
|
|
DefaultAppCertificate *string `json:",omitempty"`
|
|
|
|
MainlineSepolicyDevCertificates *string `json:",omitempty"`
|
2017-12-02 02:16:02 +01:00
|
|
|
|
2017-10-31 01:32:15 +01:00
|
|
|
AppsDefaultVersionName *string `json:",omitempty"`
|
|
|
|
|
2021-11-24 04:02:08 +01:00
|
|
|
Allow_missing_dependencies *bool `json:",omitempty"`
|
|
|
|
Unbundled_build *bool `json:",omitempty"`
|
|
|
|
Unbundled_build_apps []string `json:",omitempty"`
|
|
|
|
Unbundled_build_image *bool `json:",omitempty"`
|
|
|
|
Always_use_prebuilt_sdks *bool `json:",omitempty"`
|
|
|
|
Skip_boot_jars_check *bool `json:",omitempty"`
|
|
|
|
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"`
|
2023-06-02 00:31:52 +02:00
|
|
|
Build_from_text_stub *bool `json:",omitempty"`
|
2016-01-06 23:41:07 +01:00
|
|
|
|
2018-11-20 04:59:08 +01:00
|
|
|
Check_elf_files *bool `json:",omitempty"`
|
|
|
|
|
2018-10-05 23:20:06 +02:00
|
|
|
UncompressPrivAppDex *bool `json:",omitempty"`
|
|
|
|
ModulesLoadedByPrivilegedModules []string `json:",omitempty"`
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2021-07-21 15:23:52 +02:00
|
|
|
BootJars ConfiguredJarList `json:",omitempty"`
|
|
|
|
ApexBootJars ConfiguredJarList `json:",omitempty"`
|
2018-12-21 16:54:16 +01:00
|
|
|
|
2019-01-31 23:31:51 +01:00
|
|
|
IntegerOverflowExcludePaths []string `json:",omitempty"`
|
2017-07-13 23:46:05 +02:00
|
|
|
|
2019-01-31 23:31:51 +01:00
|
|
|
EnableCFI *bool `json:",omitempty"`
|
|
|
|
CFIExcludePaths []string `json:",omitempty"`
|
|
|
|
CFIIncludePaths []string `json:",omitempty"`
|
2017-10-31 10:26:14 +01:00
|
|
|
|
2019-02-01 17:42:56 +01:00
|
|
|
DisableScudo *bool `json:",omitempty"`
|
|
|
|
|
2021-01-06 01:41:26 +01:00
|
|
|
MemtagHeapExcludePaths []string `json:",omitempty"`
|
|
|
|
MemtagHeapAsyncIncludePaths []string `json:",omitempty"`
|
|
|
|
MemtagHeapSyncIncludePaths []string `json:",omitempty"`
|
|
|
|
|
2023-03-17 06:17:22 +01:00
|
|
|
HWASanIncludePaths []string `json:",omitempty"`
|
2023-08-22 19:51:44 +02:00
|
|
|
HWASanExcludePaths []string `json:",omitempty"`
|
2023-03-17 06:17:22 +01:00
|
|
|
|
2019-06-25 09:47:17 +02:00
|
|
|
VendorPath *string `json:",omitempty"`
|
|
|
|
OdmPath *string `json:",omitempty"`
|
|
|
|
ProductPath *string `json:",omitempty"`
|
|
|
|
SystemExtPath *string `json:",omitempty"`
|
2016-12-06 02:16:02 +01:00
|
|
|
|
2016-09-27 00:45:04 +02:00
|
|
|
ClangTidy *bool `json:",omitempty"`
|
|
|
|
TidyChecks *string `json:",omitempty"`
|
|
|
|
|
2020-06-09 14:07:36 +02:00
|
|
|
JavaCoveragePaths []string `json:",omitempty"`
|
|
|
|
JavaCoverageExcludePaths []string `json:",omitempty"`
|
|
|
|
|
2022-01-27 07:14:32 +01:00
|
|
|
GcovCoverage *bool `json:",omitempty"`
|
|
|
|
ClangCoverage *bool `json:",omitempty"`
|
|
|
|
NativeCoveragePaths []string `json:",omitempty"`
|
|
|
|
NativeCoverageExcludePaths []string `json:",omitempty"`
|
|
|
|
ClangCoverageContinuousMode *bool `json:",omitempty"`
|
2017-02-10 01:16:31 +01:00
|
|
|
|
2020-06-17 02:51:46 +02:00
|
|
|
// Set by NewConfig
|
2021-05-12 20:51:49 +02:00
|
|
|
Native_coverage *bool `json:",omitempty"`
|
2020-06-17 02:51:46 +02:00
|
|
|
|
2016-11-02 22:34:39 +01:00
|
|
|
SanitizeHost []string `json:",omitempty"`
|
|
|
|
SanitizeDevice []string `json:",omitempty"`
|
2017-06-28 18:10:48 +02:00
|
|
|
SanitizeDeviceDiag []string `json:",omitempty"`
|
2016-11-02 22:34:39 +01:00
|
|
|
SanitizeDeviceArch []string `json:",omitempty"`
|
2016-12-19 22:44:41 +01:00
|
|
|
|
|
|
|
ArtUseReadBarrier *bool `json:",omitempty"`
|
2016-12-09 00:45:07 +01:00
|
|
|
|
|
|
|
BtConfigIncludeDir *string `json:",omitempty"`
|
2017-05-04 22:57:05 +02:00
|
|
|
|
|
|
|
Override_rs_driver *string `json:",omitempty"`
|
2017-07-03 06:18:12 +02: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 04:10:28 +01:00
|
|
|
|
|
|
|
ExtraVndkVersions []string `json:",omitempty"`
|
2017-11-30 01:47:17 +01:00
|
|
|
|
|
|
|
NamespacesToExport []string `json:",omitempty"`
|
2018-01-30 08:11:42 +01:00
|
|
|
|
2022-11-01 20:33:51 +01:00
|
|
|
PgoAdditionalProfileDirs []string `json:",omitempty"`
|
2018-03-26 21:41:18 +02:00
|
|
|
|
2019-05-14 11:52:49 +02:00
|
|
|
VndkUseCoreVariant *bool `json:",omitempty"`
|
|
|
|
VndkSnapshotBuildArtifacts *bool `json:",omitempty"`
|
2018-11-13 05:19:56 +01:00
|
|
|
|
2021-01-06 15:06:52 +01:00
|
|
|
DirectedVendorSnapshot bool `json:",omitempty"`
|
|
|
|
VendorSnapshotModules map[string]bool `json:",omitempty"`
|
|
|
|
|
2021-02-09 16:44:30 +01:00
|
|
|
DirectedRecoverySnapshot bool `json:",omitempty"`
|
|
|
|
RecoverySnapshotModules map[string]bool `json:",omitempty"`
|
|
|
|
|
2021-02-24 19:49:43 +01:00
|
|
|
VendorSnapshotDirsIncluded []string `json:",omitempty"`
|
|
|
|
VendorSnapshotDirsExcluded []string `json:",omitempty"`
|
|
|
|
RecoverySnapshotDirsExcluded []string `json:",omitempty"`
|
|
|
|
RecoverySnapshotDirsIncluded []string `json:",omitempty"`
|
2021-08-10 22:42:03 +02:00
|
|
|
HostFakeSnapshotEnabled bool `json:",omitempty"`
|
2022-04-27 03:30:34 +02:00
|
|
|
|
|
|
|
MultitreeUpdateMeta bool `json:",omitempty"`
|
2021-02-24 19:49:43 +01:00
|
|
|
|
2023-08-31 09:49:59 +02:00
|
|
|
BoardVendorSepolicyDirs []string `json:",omitempty"`
|
|
|
|
BoardOdmSepolicyDirs []string `json:",omitempty"`
|
|
|
|
SystemExtPublicSepolicyDirs []string `json:",omitempty"`
|
|
|
|
SystemExtPrivateSepolicyDirs []string `json:",omitempty"`
|
|
|
|
BoardSepolicyM4Defs []string `json:",omitempty"`
|
2018-03-26 05:00:00 +02:00
|
|
|
|
2020-12-09 15:08:17 +01:00
|
|
|
BoardSepolicyVers *string `json:",omitempty"`
|
|
|
|
PlatformSepolicyVersion *string `json:",omitempty"`
|
2021-09-15 05:04:53 +02:00
|
|
|
TotSepolicyVersion *string `json:",omitempty"`
|
2020-12-09 15:08:17 +01:00
|
|
|
|
2022-02-14 15:10:51 +01:00
|
|
|
SystemExtSepolicyPrebuiltApiDir *string `json:",omitempty"`
|
|
|
|
ProductSepolicyPrebuiltApiDir *string `json:",omitempty"`
|
|
|
|
|
2022-01-07 01:11:23 +01:00
|
|
|
PlatformSepolicyCompatVersions []string `json:",omitempty"`
|
|
|
|
|
2018-03-26 21:41:18 +02:00
|
|
|
VendorVars map[string]map[string]string `json:",omitempty"`
|
2018-10-25 01:10:32 +02:00
|
|
|
|
2021-04-14 00:55:47 +02:00
|
|
|
Ndk_abis *bool `json:",omitempty"`
|
2018-11-07 18:50:25 +01:00
|
|
|
|
2023-01-11 15:15:43 +01:00
|
|
|
TrimmedApex *bool `json:",omitempty"`
|
2021-01-05 13:01:11 +01:00
|
|
|
ForceApexSymlinkOptimization *bool `json:",omitempty"`
|
|
|
|
CompressedApex *bool `json:",omitempty"`
|
|
|
|
Aml_abis *bool `json:",omitempty"`
|
2018-11-12 19:13:39 +01:00
|
|
|
|
|
|
|
DexpreoptGlobalConfig *string `json:",omitempty"`
|
2019-01-05 04:57:48 +01:00
|
|
|
|
2021-03-23 12:52:24 +01:00
|
|
|
WithDexpreopt bool `json:",omitempty"`
|
|
|
|
|
2023-07-12 17:51:48 +02:00
|
|
|
ManifestPackageNameOverrides []string `json:",omitempty"`
|
|
|
|
CertificateOverrides []string `json:",omitempty"`
|
|
|
|
PackageNameOverrides []string `json:",omitempty"`
|
|
|
|
ConfiguredJarLocationOverrides []string `json:",omitempty"`
|
2019-01-07 04:07:27 +01:00
|
|
|
|
2022-03-21 21:11:16 +01:00
|
|
|
ApexGlobalMinSdkVersionOverride *string `json:",omitempty"`
|
|
|
|
|
2019-01-07 04:07:27 +01:00
|
|
|
EnforceSystemCertificate *bool `json:",omitempty"`
|
2020-06-11 20:32:11 +02:00
|
|
|
EnforceSystemCertificateAllowList []string `json:",omitempty"`
|
2019-01-17 00:15:52 +01:00
|
|
|
|
2019-01-31 23:12:44 +01:00
|
|
|
ProductHiddenAPIStubs []string `json:",omitempty"`
|
|
|
|
ProductHiddenAPIStubsSystem []string `json:",omitempty"`
|
|
|
|
ProductHiddenAPIStubsTest []string `json:",omitempty"`
|
2019-04-10 21:27:35 +02: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 13:21:29 +02:00
|
|
|
ProductPublicSepolicyDirs []string `json:",omitempty"`
|
|
|
|
ProductPrivateSepolicyDirs []string `json:",omitempty"`
|
|
|
|
|
2019-04-18 19:08:46 +02:00
|
|
|
TargetFSConfigGen []string `json:",omitempty"`
|
2019-05-16 21:28:22 +02:00
|
|
|
|
2019-10-29 07:44:45 +01:00
|
|
|
EnforceProductPartitionInterface *bool `json:",omitempty"`
|
2019-12-05 08:27:44 +01:00
|
|
|
|
2020-10-19 10:25:58 +02:00
|
|
|
EnforceInterPartitionJavaSdkLibrary *bool `json:",omitempty"`
|
|
|
|
InterPartitionJavaLibraryAllowList []string `json:",omitempty"`
|
|
|
|
|
2020-01-22 01:12:26 +01:00
|
|
|
BoardUsesRecoveryAsBoot *bool `json:",omitempty"`
|
2020-07-29 18:51:57 +02:00
|
|
|
|
2020-08-05 23:36:09 +02:00
|
|
|
BoardKernelBinaries []string `json:",omitempty"`
|
|
|
|
BoardKernelModuleInterfaceVersions []string `json:",omitempty"`
|
2020-10-22 00:40:17 +02:00
|
|
|
|
|
|
|
BoardMoveRecoveryResourcesToVendorBoot *bool `json:",omitempty"`
|
2021-01-08 18:34:44 +01:00
|
|
|
|
|
|
|
PrebuiltHiddenApiDir *string `json:",omitempty"`
|
2020-12-21 14:53:05 +01:00
|
|
|
|
|
|
|
ShippingApiLevel *string `json:",omitempty"`
|
2021-02-03 10:16:46 +01:00
|
|
|
|
2023-09-06 02:48:11 +02:00
|
|
|
BuildBrokenPluginValidation []string `json:",omitempty"`
|
|
|
|
BuildBrokenClangAsFlags bool `json:",omitempty"`
|
|
|
|
BuildBrokenClangCFlags bool `json:",omitempty"`
|
|
|
|
BuildBrokenClangProperty bool `json:",omitempty"`
|
|
|
|
GenruleSandboxing *bool `json:",omitempty"`
|
|
|
|
BuildBrokenEnforceSyspropOwner bool `json:",omitempty"`
|
|
|
|
BuildBrokenTrebleSyspropNeverallow bool `json:",omitempty"`
|
|
|
|
BuildBrokenUsesSoongPython2Modules bool `json:",omitempty"`
|
|
|
|
BuildBrokenVendorPropertyNamespace bool `json:",omitempty"`
|
|
|
|
BuildBrokenIncorrectPartitionImages bool `json:",omitempty"`
|
|
|
|
BuildBrokenInputDirModules []string `json:",omitempty"`
|
2021-03-17 10:05:33 +01:00
|
|
|
|
2023-06-03 00:42:21 +02:00
|
|
|
BuildWarningBadOptionalUsesLibsAllowlist []string `json:",omitempty"`
|
|
|
|
|
2021-04-03 01:45:24 +02:00
|
|
|
BuildDebugfsRestrictionsEnabled bool `json:",omitempty"`
|
|
|
|
|
2021-03-17 10:05:33 +01:00
|
|
|
RequiresInsecureExecmemForSwiftshader bool `json:",omitempty"`
|
|
|
|
|
|
|
|
SelinuxIgnoreNeverallows bool `json:",omitempty"`
|
|
|
|
|
2023-07-07 00:03:58 +02:00
|
|
|
Release_aidl_use_unfrozen *bool `json:",omitempty"`
|
|
|
|
|
2021-09-15 05:04:53 +02:00
|
|
|
SepolicyFreezeTestExtraDirs []string `json:",omitempty"`
|
|
|
|
SepolicyFreezeTestExtraPrebuiltDirs []string `json:",omitempty"`
|
2021-10-12 09:47:43 +02:00
|
|
|
|
|
|
|
GenerateAidlNdkPlatformBackend bool `json:",omitempty"`
|
2022-07-14 08:16:52 +02:00
|
|
|
|
|
|
|
IgnorePrefer32OnDevice bool `json:",omitempty"`
|
2022-11-08 19:42:16 +01:00
|
|
|
|
2023-02-21 17:50:29 +01:00
|
|
|
IncludeTags []string `json:",omitempty"`
|
|
|
|
SourceRootDirs []string `json:",omitempty"`
|
2023-03-10 04:07:19 +01:00
|
|
|
|
|
|
|
AfdoProfiles []string `json:",omitempty"`
|
2023-05-04 18:06:06 +02:00
|
|
|
|
|
|
|
ProductManufacturer string `json:",omitempty"`
|
|
|
|
ProductBrand string `json:",omitempty"`
|
|
|
|
BuildVersionTags []string `json:",omitempty"`
|
2023-05-09 17:14:14 +02:00
|
|
|
|
2023-10-13 05:31:27 +02:00
|
|
|
ReleaseVersion string `json:",omitempty"`
|
|
|
|
ReleaseAconfigValueSets []string `json:",omitempty"`
|
2023-07-06 09:43:44 +02:00
|
|
|
|
2023-08-10 23:47:40 +02:00
|
|
|
ReleaseAconfigFlagDefaultPermission string `json:",omitempty"`
|
|
|
|
|
2023-10-06 09:01:22 +02:00
|
|
|
ReleaseDefaultModuleBuildFromSource *bool `json:",omitempty"`
|
|
|
|
|
2023-07-06 09:43:44 +02:00
|
|
|
KeepVndk *bool `json:",omitempty"`
|
2023-08-25 14:29:46 +02:00
|
|
|
|
|
|
|
CheckVendorSeappViolations *bool `json:",omitempty"`
|
2023-09-15 00:16:58 +02:00
|
|
|
|
2023-09-21 01:01:18 +02:00
|
|
|
// PartitionVarsForBazelMigrationOnlyDoNotUse are extra variables that are used to define the
|
|
|
|
// partition images. They should not be read from soong modules.
|
|
|
|
PartitionVarsForBazelMigrationOnlyDoNotUse PartitionVariables `json:",omitempty"`
|
2023-09-20 03:02:18 +02:00
|
|
|
|
|
|
|
NextReleaseHideFlaggedApi *bool `json:",omitempty"`
|
2023-09-27 00:32:08 +02:00
|
|
|
|
|
|
|
Release_expose_flagged_api *bool `json:",omitempty"`
|
2023-10-25 16:53:58 +02:00
|
|
|
|
|
|
|
BuildFlags map[string]string `json:",omitempty"`
|
2023-11-16 20:07:04 +01:00
|
|
|
|
|
|
|
BuildFromSourceStub *bool `json:",omitempty"`
|
2023-09-21 01:01:18 +02:00
|
|
|
}
|
|
|
|
|
2023-10-13 20:32:14 +02:00
|
|
|
type PartitionQualifiedVariablesType struct {
|
|
|
|
BuildingImage bool `json:",omitempty"`
|
|
|
|
BoardErofsCompressor string `json:",omitempty"`
|
|
|
|
BoardErofsCompressHints string `json:",omitempty"`
|
|
|
|
BoardErofsPclusterSize string `json:",omitempty"`
|
|
|
|
BoardExtfsInodeCount string `json:",omitempty"`
|
|
|
|
BoardExtfsRsvPct string `json:",omitempty"`
|
|
|
|
BoardF2fsSloadCompressFlags string `json:",omitempty"`
|
|
|
|
BoardFileSystemCompress string `json:",omitempty"`
|
|
|
|
BoardFileSystemType string `json:",omitempty"`
|
|
|
|
BoardJournalSize string `json:",omitempty"`
|
|
|
|
BoardPartitionReservedSize string `json:",omitempty"`
|
|
|
|
BoardPartitionSize string `json:",omitempty"`
|
|
|
|
BoardSquashfsBlockSize string `json:",omitempty"`
|
|
|
|
BoardSquashfsCompressor string `json:",omitempty"`
|
|
|
|
BoardSquashfsCompressorOpt string `json:",omitempty"`
|
|
|
|
BoardSquashfsDisable4kAlign string `json:",omitempty"`
|
|
|
|
ProductBaseFsPath string `json:",omitempty"`
|
|
|
|
ProductHeadroom string `json:",omitempty"`
|
|
|
|
ProductVerityPartition string `json:",omitempty"`
|
|
|
|
|
|
|
|
BoardAvbAddHashtreeFooterArgs string `json:",omitempty"`
|
|
|
|
BoardAvbKeyPath string `json:",omitempty"`
|
|
|
|
BoardAvbAlgorithm string `json:",omitempty"`
|
|
|
|
BoardAvbRollbackIndex string `json:",omitempty"`
|
|
|
|
BoardAvbRollbackIndexLocation string `json:",omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-09-21 01:01:18 +02:00
|
|
|
type PartitionVariables struct {
|
|
|
|
ProductDirectory string `json:",omitempty"`
|
2023-10-13 20:32:14 +02:00
|
|
|
PartitionQualifiedVariables map[string]PartitionQualifiedVariablesType
|
|
|
|
TargetUserimagesUseExt2 bool `json:",omitempty"`
|
|
|
|
TargetUserimagesUseExt3 bool `json:",omitempty"`
|
|
|
|
TargetUserimagesUseExt4 bool `json:",omitempty"`
|
2023-09-21 01:01:18 +02:00
|
|
|
|
|
|
|
TargetUserimagesSparseExtDisabled bool `json:",omitempty"`
|
|
|
|
TargetUserimagesSparseErofsDisabled bool `json:",omitempty"`
|
|
|
|
TargetUserimagesSparseSquashfsDisabled bool `json:",omitempty"`
|
|
|
|
TargetUserimagesSparseF2fsDisabled bool `json:",omitempty"`
|
|
|
|
|
2023-11-24 07:58:50 +01:00
|
|
|
BoardErofsCompressor string `json:",omitempty"`
|
|
|
|
BoardErofsCompressorHints string `json:",omitempty"`
|
|
|
|
BoardErofsPclusterSize string `json:",omitempty"`
|
|
|
|
BoardErofsShareDupBlocks string `json:",omitempty"`
|
|
|
|
BoardErofsUseLegacyCompression string `json:",omitempty"`
|
|
|
|
BoardExt4ShareDupBlocks string `json:",omitempty"`
|
|
|
|
BoardFlashLogicalBlockSize string `json:",omitempty"`
|
|
|
|
BoardFlashEraseBlockSize string `json:",omitempty"`
|
|
|
|
BoardUsesRecoveryAsBoot bool `json:",omitempty"`
|
|
|
|
ProductUseDynamicPartitionSize bool `json:",omitempty"`
|
|
|
|
CopyImagesForTargetFilesZip bool `json:",omitempty"`
|
2023-09-27 22:44:40 +02:00
|
|
|
|
|
|
|
BoardAvbEnable bool `json:",omitempty"`
|
2023-10-13 20:32:14 +02:00
|
|
|
|
|
|
|
ProductPackages []string `json:",omitempty"`
|
2015-09-16 22:53:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func boolPtr(v bool) *bool {
|
|
|
|
return &v
|
2015-08-27 22:28:01 +02:00
|
|
|
}
|
|
|
|
|
2015-09-17 01:48:54 +02:00
|
|
|
func intPtr(v int) *int {
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
|
2015-09-17 23:33:42 +02:00
|
|
|
func stringPtr(v string) *string {
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
|
2023-04-22 02:37:11 +02:00
|
|
|
func (v *ProductVariables) SetDefaultConfig() {
|
|
|
|
*v = ProductVariables{
|
2020-02-22 01:55:46 +01:00
|
|
|
BuildNumberFile: stringPtr("build_number.txt"),
|
2019-04-07 18:41:44 +02:00
|
|
|
|
2023-03-27 22:34:01 +02:00
|
|
|
Platform_version_name: stringPtr("S"),
|
|
|
|
Platform_base_sdk_extension_version: intPtr(30),
|
|
|
|
Platform_sdk_version: intPtr(30),
|
|
|
|
Platform_sdk_codename: stringPtr("S"),
|
|
|
|
Platform_sdk_final: boolPtr(false),
|
|
|
|
Platform_version_active_codenames: []string{"S"},
|
|
|
|
Platform_version_all_preview_codenames: []string{"S"},
|
|
|
|
Platform_vndk_version: stringPtr("S"),
|
2017-11-13 23:34:56 +01:00
|
|
|
|
2023-12-04 23:51:20 +01:00
|
|
|
HostArch: stringPtr("x86_64"),
|
|
|
|
HostSecondaryArch: stringPtr("x86"),
|
|
|
|
DeviceName: stringPtr("generic_arm64"),
|
|
|
|
DeviceProduct: stringPtr("aosp_arm-eng"),
|
|
|
|
DeviceArch: stringPtr("arm64"),
|
|
|
|
DeviceArchVariant: stringPtr("armv8-a"),
|
|
|
|
DeviceCpuVariant: stringPtr("generic"),
|
|
|
|
DeviceAbi: []string{"arm64-v8a"},
|
|
|
|
DeviceSecondaryArch: stringPtr("arm"),
|
|
|
|
DeviceSecondaryArchVariant: stringPtr("armv8-a"),
|
|
|
|
DeviceSecondaryCpuVariant: stringPtr("generic"),
|
|
|
|
DeviceSecondaryAbi: []string{"armeabi-v7a", "armeabi"},
|
|
|
|
DeviceMaxPageSizeSupported: stringPtr("4096"),
|
|
|
|
DeviceNoBionicPageSizeMacro: boolPtr(false),
|
2017-10-31 01:32:15 +01:00
|
|
|
|
2019-01-31 23:31:51 +01:00
|
|
|
AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
|
2017-10-31 01:32:15 +01:00
|
|
|
AAPTPreferredConfig: stringPtr("xhdpi"),
|
|
|
|
AAPTCharacteristics: stringPtr("nosdcard"),
|
2019-01-31 23:31:51 +01:00
|
|
|
AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"},
|
2017-10-31 01:32:15 +01:00
|
|
|
|
2020-04-29 23:57:30 +02:00
|
|
|
Malloc_not_svelte: boolPtr(true),
|
2020-07-30 22:38:49 +02:00
|
|
|
Malloc_zero_contents: boolPtr(true),
|
2020-04-29 23:57:30 +02:00
|
|
|
Malloc_pattern_fill_contents: boolPtr(false),
|
|
|
|
Safestack: boolPtr(false),
|
2023-01-11 15:15:43 +01:00
|
|
|
TrimmedApex: boolPtr(false),
|
2023-06-02 00:31:52 +02:00
|
|
|
Build_from_text_stub: boolPtr(false),
|
2021-03-17 13:34:30 +01:00
|
|
|
|
2021-07-21 15:23:52 +02:00
|
|
|
BootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
|
|
|
|
ApexBootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
|
2015-08-27 22:28:01 +02:00
|
|
|
}
|
2015-11-25 02:53:15 +01:00
|
|
|
|
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
v.CrossHost = stringPtr("windows")
|
|
|
|
v.CrossHostArch = stringPtr("x86")
|
2016-02-04 08:16:33 +01:00
|
|
|
v.CrossHostSecondaryArch = stringPtr("x86_64")
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
|
|
|
|
2023-12-04 18:35:15 +01:00
|
|
|
func (this *ProductVariables) GetBuildFlagBool(flag string) bool {
|
|
|
|
val, ok := this.BuildFlags[flag]
|
|
|
|
if !ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return val == "true"
|
|
|
|
}
|
|
|
|
|
2021-03-24 15:14:47 +01:00
|
|
|
// ProductConfigContext requires the access to the Module to get product config properties.
|
|
|
|
type ProductConfigContext interface {
|
|
|
|
Module() Module
|
|
|
|
}
|
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
// ProductConfigOrSoongConfigProperty represents either a soong config variable + its value
|
|
|
|
// or a product config variable. You can get both a ConfigurationAxis and a SelectKey from it
|
|
|
|
// for use in bazel attributes. ProductVariableProperties() will return a map from properties ->
|
|
|
|
// this interface -> property structs for use in bp2build converters
|
|
|
|
type ProductConfigOrSoongConfigProperty interface {
|
|
|
|
// Name of the product variable or soong config variable
|
|
|
|
Name() string
|
|
|
|
// AlwaysEmit returns true for soong config variables but false for product variables. This
|
|
|
|
// is intended to indicate if we need to always emit empty lists in the select statements.
|
|
|
|
AlwaysEmit() bool
|
|
|
|
// ConfigurationAxis returns the bazel.ConfigurationAxis that represents this variable. The
|
|
|
|
// configuration axis will change depending on the variable and whether it's arch/os variant
|
|
|
|
// as well.
|
|
|
|
ConfigurationAxis() bazel.ConfigurationAxis
|
|
|
|
// SelectKey returns a string that represents the key of a select branch, however, it is not
|
|
|
|
// actually the real label written out to the build file.
|
|
|
|
// this.ConfigurationAxis().SelectKey(this.SelectKey()) will give the actual label.
|
|
|
|
SelectKey() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProductConfigProperty represents a product config variable, and if it is arch-variant or not.
|
2021-03-24 15:14:47 +01:00
|
|
|
type ProductConfigProperty struct {
|
2021-11-02 17:43:57 +01:00
|
|
|
// The name of the product variable, e.g. "safestack", "malloc_not_svelte",
|
|
|
|
// "board"
|
2023-04-26 19:52:24 +02:00
|
|
|
name string
|
2021-11-02 17:43:57 +01:00
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
arch string
|
|
|
|
}
|
2021-11-02 17:43:57 +01:00
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
func (p ProductConfigProperty) Name() string {
|
|
|
|
return p.name
|
|
|
|
}
|
2022-06-09 20:52:05 +02:00
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
func (p ProductConfigProperty) AlwaysEmit() bool {
|
|
|
|
return false
|
2021-03-24 15:14:47 +01:00
|
|
|
}
|
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
func (p ProductConfigProperty) ConfigurationAxis() bazel.ConfigurationAxis {
|
|
|
|
return bazel.ProductVariableConfigurationAxis(p.arch != "", p.name+"__"+p.arch)
|
2021-11-17 13:14:41 +01:00
|
|
|
}
|
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
func (p ProductConfigProperty) SelectKey() string {
|
|
|
|
if p.arch == "" {
|
|
|
|
return strings.ToLower(p.name)
|
2021-11-02 17:43:57 +01:00
|
|
|
} else {
|
2023-04-26 19:52:24 +02:00
|
|
|
return strings.ToLower(p.name + "-" + p.arch)
|
2021-11-02 17:43:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
// SoongConfigProperty represents a soong config variable, its value if it's a string variable,
|
|
|
|
// and if it's dependent on the OS or not
|
|
|
|
type SoongConfigProperty struct {
|
|
|
|
name string
|
|
|
|
namespace string
|
|
|
|
// Can be an empty string for bool/value soong config variables
|
|
|
|
value string
|
|
|
|
// If there is a target: field inside a soong config property struct, the os that it selects
|
|
|
|
// on will be represented here.
|
|
|
|
os string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p SoongConfigProperty) Name() string {
|
|
|
|
return p.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p SoongConfigProperty) AlwaysEmit() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p SoongConfigProperty) ConfigurationAxis() bazel.ConfigurationAxis {
|
|
|
|
return bazel.ProductVariableConfigurationAxis(false, p.namespace+"__"+p.name+"__"+p.os)
|
|
|
|
}
|
|
|
|
|
2021-11-15 13:28:43 +01:00
|
|
|
// SelectKey returns the literal string that represents this variable in a BUILD
|
|
|
|
// select statement.
|
2023-04-26 19:52:24 +02:00
|
|
|
func (p SoongConfigProperty) SelectKey() string {
|
|
|
|
// p.value being conditions_default can happen with or without a desired os. When not using
|
|
|
|
// an os, we want to emit literally just //conditions:default in the select statement, but
|
|
|
|
// when using an os, we want to emit namespace__name__conditions_default__os, so that
|
|
|
|
// the branch is only taken if the variable is not set, and we're on the desired os.
|
|
|
|
// ConfigurationAxis#SelectKey will map the conditions_default result of this function to
|
|
|
|
// //conditions:default.
|
|
|
|
if p.value == bazel.ConditionsDefaultConfigKey && p.os == "" {
|
2021-11-15 13:28:43 +01:00
|
|
|
return bazel.ConditionsDefaultConfigKey
|
|
|
|
}
|
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
parts := []string{p.namespace, p.name}
|
|
|
|
if p.value != "" && p.value != bazel.ConditionsDefaultSelectKey {
|
|
|
|
parts = append(parts, p.value)
|
2021-11-15 13:28:43 +01:00
|
|
|
}
|
2023-04-26 19:52:24 +02:00
|
|
|
if p.os != "" {
|
|
|
|
parts = append(parts, p.os)
|
2022-01-07 21:39:21 +01:00
|
|
|
}
|
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
// e.g. acme__feature1, android__board__soc_a, my_namespace__my_variables__my_value__my_os
|
|
|
|
return strings.ToLower(strings.Join(parts, "__"))
|
2021-11-15 13:28:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ProductConfigProperties is a map of maps to group property values according
|
|
|
|
// their property name and the product config variable they're set under.
|
|
|
|
//
|
|
|
|
// The outer map key is the name of the property, like "cflags".
|
|
|
|
//
|
|
|
|
// The inner map key is a ProductConfigProperty, which is a struct of product
|
|
|
|
// variable name, namespace, and the "full configuration" of the product
|
|
|
|
// variable.
|
|
|
|
//
|
|
|
|
// e.g. product variable name: board, namespace: acme, full config: vendor_chip_foo
|
|
|
|
//
|
|
|
|
// The value of the map is the interface{} representing the value of the
|
|
|
|
// property, like ["-DDEFINES"] for cflags.
|
2023-04-26 19:52:24 +02:00
|
|
|
type ProductConfigProperties map[string]map[ProductConfigOrSoongConfigProperty]interface{}
|
2021-03-24 15:14:47 +01:00
|
|
|
|
2021-11-02 17:43:57 +01:00
|
|
|
func (p *ProductConfigProperties) AddProductConfigProperty(
|
2023-04-26 19:52:24 +02:00
|
|
|
propertyName, productVariableName, arch string, propertyValue interface{}) {
|
2021-11-02 17:43:57 +01:00
|
|
|
|
2021-11-15 13:28:43 +01:00
|
|
|
productConfigProp := ProductConfigProperty{
|
2023-04-26 19:52:24 +02:00
|
|
|
name: productVariableName, // e.g. size, feature1, feature2, FEATURE3, board
|
|
|
|
arch: arch, // e.g. "", x86, arm64
|
|
|
|
}
|
|
|
|
|
|
|
|
p.AddEitherProperty(propertyName, productConfigProp, propertyValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ProductConfigProperties) AddSoongConfigProperty(
|
|
|
|
propertyName, namespace, variableName, value, os string, propertyValue interface{}) {
|
|
|
|
|
|
|
|
soongConfigProp := SoongConfigProperty{
|
|
|
|
namespace: namespace,
|
|
|
|
name: variableName, // e.g. size, feature1, feature2, FEATURE3, board
|
|
|
|
value: value,
|
|
|
|
os: os, // e.g. android, linux_x86
|
|
|
|
}
|
|
|
|
|
|
|
|
p.AddEitherProperty(propertyName, soongConfigProp, propertyValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ProductConfigProperties) AddEitherProperty(
|
|
|
|
propertyName string, key ProductConfigOrSoongConfigProperty, propertyValue interface{}) {
|
|
|
|
if (*p)[propertyName] == nil {
|
|
|
|
(*p)[propertyName] = make(map[ProductConfigOrSoongConfigProperty]interface{})
|
2021-11-02 17:43:57 +01:00
|
|
|
}
|
2021-11-15 13:28:43 +01:00
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
if existing, ok := (*p)[propertyName][key]; ok {
|
2021-11-17 11:57:35 +01:00
|
|
|
switch dst := existing.(type) {
|
|
|
|
case []string:
|
2023-04-26 19:52:24 +02:00
|
|
|
src, ok := propertyValue.([]string)
|
|
|
|
if !ok {
|
|
|
|
panic("Conflicting types")
|
2021-11-17 11:57:35 +01:00
|
|
|
}
|
2023-04-26 19:52:24 +02:00
|
|
|
dst = append(dst, src...)
|
|
|
|
(*p)[propertyName][key] = dst
|
2021-11-17 11:57:35 +01:00
|
|
|
default:
|
2023-07-28 03:31:15 +02:00
|
|
|
if existing != propertyValue {
|
|
|
|
panic(fmt.Errorf("TODO: handle merging value %#v", existing))
|
|
|
|
}
|
2021-11-17 11:57:35 +01:00
|
|
|
}
|
|
|
|
} else {
|
2023-04-26 19:52:24 +02:00
|
|
|
(*p)[propertyName][key] = propertyValue
|
2021-11-17 11:57:35 +01:00
|
|
|
}
|
2021-11-02 17:43:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// maybeExtractConfigVarProp attempts to read this value as a config var struct
|
|
|
|
// wrapped by interfaces and ptrs. If it's not the right type, the second return
|
|
|
|
// value is false.
|
|
|
|
func maybeExtractConfigVarProp(v reflect.Value) (reflect.Value, bool) {
|
|
|
|
if v.Kind() == reflect.Interface {
|
|
|
|
// The conditions_default value can be either
|
|
|
|
// 1) an ptr to an interface of a struct (bool config variables and product variables)
|
|
|
|
// 2) an interface of 1) (config variables with nested structs, like string vars)
|
|
|
|
v = v.Elem()
|
|
|
|
}
|
|
|
|
if v.Kind() != reflect.Ptr {
|
|
|
|
return v, false
|
|
|
|
}
|
|
|
|
v = reflect.Indirect(v)
|
|
|
|
if v.Kind() == reflect.Interface {
|
|
|
|
// Extract the struct from the interface
|
|
|
|
v = v.Elem()
|
|
|
|
}
|
|
|
|
|
|
|
|
if !v.IsValid() {
|
|
|
|
return v, false
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.Kind() != reflect.Struct {
|
|
|
|
return v, false
|
|
|
|
}
|
|
|
|
return v, true
|
|
|
|
}
|
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
func (productConfigProperties *ProductConfigProperties) AddProductConfigProperties(variableValues reflect.Value, arch string) {
|
2021-11-02 17:43:57 +01:00
|
|
|
// Example of product_variables:
|
|
|
|
//
|
|
|
|
// product_variables: {
|
|
|
|
// malloc_not_svelte: {
|
|
|
|
// shared_libs: ["malloc_not_svelte_shared_lib"],
|
|
|
|
// whole_static_libs: ["malloc_not_svelte_whole_static_lib"],
|
|
|
|
// exclude_static_libs: [
|
|
|
|
// "malloc_not_svelte_static_lib_excludes",
|
|
|
|
// "malloc_not_svelte_whole_static_lib_excludes",
|
|
|
|
// ],
|
|
|
|
// },
|
|
|
|
// },
|
2023-04-26 19:52:24 +02:00
|
|
|
|
|
|
|
for i := 0; i < variableValues.NumField(); i++ {
|
|
|
|
// e.g. Platform_sdk_version, Unbundled_build, Malloc_not_svelte, etc.
|
|
|
|
productVariableName := variableValues.Type().Field(i).Name
|
|
|
|
|
|
|
|
variableValue := variableValues.Field(i)
|
|
|
|
// Check if any properties were set for the module
|
|
|
|
if variableValue.IsZero() {
|
|
|
|
// e.g. feature1: {}, malloc_not_svelte: {}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for j := 0; j < variableValue.NumField(); j++ {
|
|
|
|
property := variableValue.Field(j)
|
|
|
|
// e.g. Asflags, Cflags, Enabled, etc.
|
|
|
|
propertyName := variableValue.Type().Field(j).Name
|
|
|
|
if property.Kind() != reflect.Interface {
|
|
|
|
productConfigProperties.AddProductConfigProperty(propertyName, productVariableName, arch, property.Interface())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-09-19 14:41:14 +02:00
|
|
|
func (productConfigProperties *ProductConfigProperties) AddSoongConfigProperties(namespace string, soongConfigVariablesStruct reflect.Value) error {
|
2021-11-02 17:43:57 +01:00
|
|
|
//
|
|
|
|
// Example of soong_config_variables:
|
|
|
|
//
|
|
|
|
// soong_config_variables: {
|
|
|
|
// feature1: {
|
2023-04-26 19:52:24 +02:00
|
|
|
// conditions_default: {
|
2021-11-02 17:43:57 +01:00
|
|
|
// ...
|
|
|
|
// },
|
|
|
|
// cflags: ...
|
|
|
|
// },
|
|
|
|
// feature2: {
|
|
|
|
// cflags: ...
|
2023-04-26 19:52:24 +02:00
|
|
|
// conditions_default: {
|
2021-11-02 17:43:57 +01:00
|
|
|
// ...
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// board: {
|
|
|
|
// soc_a: {
|
|
|
|
// ...
|
|
|
|
// },
|
2023-04-26 19:52:24 +02:00
|
|
|
// soc_b: {
|
2021-11-02 17:43:57 +01:00
|
|
|
// ...
|
|
|
|
// },
|
|
|
|
// soc_c: {},
|
|
|
|
// conditions_default: {
|
|
|
|
// ...
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// }
|
2023-04-26 19:52:24 +02:00
|
|
|
for i := 0; i < soongConfigVariablesStruct.NumField(); i++ {
|
|
|
|
// e.g. feature1, feature2, board
|
|
|
|
variableName := soongConfigVariablesStruct.Type().Field(i).Name
|
|
|
|
variableStruct := soongConfigVariablesStruct.Field(i)
|
2021-03-24 15:14:47 +01:00
|
|
|
// Check if any properties were set for the module
|
2023-04-26 19:52:24 +02:00
|
|
|
if variableStruct.IsZero() {
|
|
|
|
// e.g. feature1: {}
|
2021-03-24 15:14:47 +01:00
|
|
|
continue
|
|
|
|
}
|
2021-11-02 17:43:57 +01:00
|
|
|
|
|
|
|
// Unlike product variables, config variables require a few more
|
|
|
|
// indirections to extract the struct from the reflect.Value.
|
2023-04-26 19:52:24 +02:00
|
|
|
if v, ok := maybeExtractConfigVarProp(variableStruct); ok {
|
|
|
|
variableStruct = v
|
2023-05-24 04:27:44 +02:00
|
|
|
} else if !v.IsValid() {
|
|
|
|
// Skip invalid variables which may not used, else leads to panic
|
|
|
|
continue
|
2021-11-02 17:43:57 +01:00
|
|
|
}
|
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
for j := 0; j < variableStruct.NumField(); j++ {
|
|
|
|
propertyOrStruct := variableStruct.Field(j)
|
|
|
|
// propertyOrValueName can either be:
|
|
|
|
// - A property, like: Asflags, Cflags, Enabled, etc.
|
|
|
|
// - A soong config string variable's value, like soc_a, soc_b, soc_c in the example above
|
|
|
|
// - "conditions_default"
|
|
|
|
propertyOrValueName := variableStruct.Type().Field(j).Name
|
2022-12-21 20:47:18 +01:00
|
|
|
|
2021-03-24 15:14:47 +01:00
|
|
|
// If the property wasn't set, no need to pass it along
|
2023-04-26 19:52:24 +02:00
|
|
|
if propertyOrStruct.IsZero() {
|
2021-03-24 15:14:47 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
if v, ok := maybeExtractConfigVarProp(propertyOrStruct); ok {
|
2021-11-02 17:43:57 +01:00
|
|
|
// The field is a struct, which is used by:
|
|
|
|
// 1) soong_config_string_variables
|
|
|
|
//
|
|
|
|
// soc_a: {
|
|
|
|
// cflags: ...,
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// soc_b: {
|
|
|
|
// cflags: ...,
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// 2) conditions_default structs for all soong config variable types.
|
|
|
|
//
|
|
|
|
// conditions_default: {
|
|
|
|
// cflags: ...,
|
|
|
|
// static_libs: ...
|
|
|
|
// }
|
2023-04-26 19:52:24 +02:00
|
|
|
//
|
|
|
|
// This means that propertyOrValueName is either conditions_default, or a soong
|
|
|
|
// config string variable's value.
|
2021-11-02 17:43:57 +01:00
|
|
|
field := v
|
2022-12-21 20:47:18 +01:00
|
|
|
// Iterate over fields of this struct prop.
|
2021-11-02 17:43:57 +01:00
|
|
|
for k := 0; k < field.NumField(); k++ {
|
2022-12-21 20:47:18 +01:00
|
|
|
// For product variables, zero values are irrelevant; however, for soong config variables,
|
|
|
|
// empty values are relevant because there can also be a conditions default which is not
|
|
|
|
// applied for empty variables.
|
|
|
|
if field.Field(k).IsZero() && namespace == "" {
|
2021-11-02 17:43:57 +01:00
|
|
|
continue
|
|
|
|
}
|
2023-04-26 19:52:24 +02:00
|
|
|
|
|
|
|
propertyName := field.Type().Field(k).Name
|
|
|
|
if propertyName == "Target" {
|
|
|
|
productConfigProperties.AddSoongConfigPropertiesFromTargetStruct(namespace, variableName, proptools.PropertyNameForField(propertyOrValueName), field.Field(k))
|
|
|
|
} else if propertyName == "Arch" || propertyName == "Multilib" {
|
2023-09-19 14:41:14 +02:00
|
|
|
return fmt.Errorf("Arch/Multilib are not currently supported in soong config variable structs")
|
2023-04-26 19:52:24 +02:00
|
|
|
} else {
|
|
|
|
productConfigProperties.AddSoongConfigProperty(propertyName, namespace, variableName, proptools.PropertyNameForField(propertyOrValueName), "", field.Field(k).Interface())
|
|
|
|
}
|
2021-11-02 17:43:57 +01:00
|
|
|
}
|
2023-04-26 19:52:24 +02:00
|
|
|
} else if propertyOrStruct.Kind() != reflect.Interface {
|
2021-11-17 13:14:41 +01:00
|
|
|
// If not an interface, then this is not a conditions_default or
|
2023-04-26 19:52:24 +02:00
|
|
|
// a struct prop. That is, this is a bool/value config variable.
|
|
|
|
if propertyOrValueName == "Target" {
|
|
|
|
productConfigProperties.AddSoongConfigPropertiesFromTargetStruct(namespace, variableName, "", propertyOrStruct)
|
|
|
|
} else if propertyOrValueName == "Arch" || propertyOrValueName == "Multilib" {
|
2023-09-19 14:41:14 +02:00
|
|
|
return fmt.Errorf("Arch/Multilib are not currently supported in soong config variable structs")
|
2023-04-26 19:52:24 +02:00
|
|
|
} else {
|
|
|
|
productConfigProperties.AddSoongConfigProperty(propertyOrValueName, namespace, variableName, "", "", propertyOrStruct.Interface())
|
|
|
|
}
|
2021-06-02 22:02:22 +02:00
|
|
|
}
|
2021-03-24 15:14:47 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-19 14:41:14 +02:00
|
|
|
return nil
|
2021-03-24 15:14:47 +01:00
|
|
|
}
|
|
|
|
|
2023-04-26 19:52:24 +02:00
|
|
|
func (productConfigProperties *ProductConfigProperties) AddSoongConfigPropertiesFromTargetStruct(namespace, soongConfigVariableName string, soongConfigVariableValue string, targetStruct reflect.Value) {
|
|
|
|
// targetStruct will be a struct with fields like "android", "host", "arm", "x86",
|
|
|
|
// "android_arm", etc. The values of each of those fields will be a regular property struct.
|
|
|
|
for i := 0; i < targetStruct.NumField(); i++ {
|
|
|
|
targetFieldName := targetStruct.Type().Field(i).Name
|
|
|
|
archOrOsSpecificStruct := targetStruct.Field(i)
|
|
|
|
for j := 0; j < archOrOsSpecificStruct.NumField(); j++ {
|
|
|
|
property := archOrOsSpecificStruct.Field(j)
|
|
|
|
// e.g. Asflags, Cflags, Enabled, etc.
|
|
|
|
propertyName := archOrOsSpecificStruct.Type().Field(j).Name
|
|
|
|
|
|
|
|
if targetFieldName == "Android" {
|
|
|
|
productConfigProperties.AddSoongConfigProperty(propertyName, namespace, soongConfigVariableName, soongConfigVariableValue, "android", property.Interface())
|
|
|
|
} else if targetFieldName == "Host" {
|
|
|
|
for _, os := range osTypeList {
|
|
|
|
if os.Class == Host {
|
|
|
|
productConfigProperties.AddSoongConfigProperty(propertyName, namespace, soongConfigVariableName, soongConfigVariableValue, os.Name, property.Interface())
|
|
|
|
}
|
|
|
|
}
|
2023-07-28 01:01:06 +02:00
|
|
|
} else if !archOrOsSpecificStruct.IsZero() {
|
2023-04-26 19:52:24 +02:00
|
|
|
// One problem with supporting additional fields is that if multiple branches of
|
|
|
|
// "target" overlap, we don't want them to be in the same select statement (aka
|
|
|
|
// configuration axis). "android" and "host" are disjoint, so it's ok that we only
|
|
|
|
// have 2 axes right now. (soongConfigVariables and soongConfigVariablesPlusOs)
|
|
|
|
panic("TODO: support other target types in soong config variable structs: " + targetFieldName)
|
|
|
|
}
|
|
|
|
}
|
2021-11-17 11:57:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 02:01:55 +01:00
|
|
|
func VariableMutator(mctx BottomUpMutatorContext) {
|
2016-05-19 00:37:25 +02:00
|
|
|
var module Module
|
2015-07-09 22:57:48 +02:00
|
|
|
var ok bool
|
2016-05-19 00:37:25 +02:00
|
|
|
if module, ok = mctx.Module().(Module); !ok {
|
2015-07-09 22:57:48 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: depend on config variable, create variants, propagate variants up tree
|
|
|
|
a := module.base()
|
2019-09-25 07:19:02 +02:00
|
|
|
|
|
|
|
if a.variableProperties == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
variableValues := reflect.ValueOf(a.variableProperties).Elem().FieldByName("Product_variables")
|
2015-07-09 22:57:48 +02:00
|
|
|
|
2021-01-20 20:27:32 +01:00
|
|
|
productVariables := reflect.ValueOf(mctx.Config().productVariables)
|
|
|
|
|
2015-07-09 22:57:48 +02:00
|
|
|
for i := 0; i < variableValues.NumField(); i++ {
|
|
|
|
variableValue := variableValues.Field(i)
|
2015-08-27 22:28:01 +02:00
|
|
|
name := variableValues.Type().Field(i).Name
|
|
|
|
property := "product_variables." + proptools.PropertyNameForField(name)
|
|
|
|
|
2015-09-16 22:53:42 +02:00
|
|
|
// Check that the variable was set for the product
|
2021-01-20 20:27:32 +01:00
|
|
|
val := productVariables.FieldByName(name)
|
2015-09-16 22:53:42 +02: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-09 22:57:48 +02:00
|
|
|
|
2015-09-16 22:53:42 +02:00
|
|
|
// Check if any properties were set for the module
|
2020-02-07 01:57:45 +01:00
|
|
|
if variableValue.IsZero() {
|
2015-09-16 22:53:42 +02:00
|
|
|
continue
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
2015-09-16 22:53:42 +02:00
|
|
|
a.setVariableProperties(mctx, property, variableValue, val.Interface())
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-07 01:57:04 +02:00
|
|
|
func (m *ModuleBase) setVariableProperties(ctx BottomUpMutatorContext,
|
2015-07-09 22:57:48 +02:00
|
|
|
prefix string, productVariablePropertyValue reflect.Value, variableValue interface{}) {
|
|
|
|
|
2017-05-06 01:16:24 +02:00
|
|
|
printfIntoProperties(ctx, prefix, productVariablePropertyValue, variableValue)
|
2015-07-09 22:57:48 +02:00
|
|
|
|
2022-01-06 05:42:33 +01:00
|
|
|
err := proptools.AppendMatchingProperties(m.GetProperties(),
|
2015-10-29 01:23:31 +01: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-09 22:57:48 +02:00
|
|
|
}
|
|
|
|
|
2017-05-06 01:16:24 +02: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-09 22:57:48 +02:00
|
|
|
for i := 0; i < productVariablePropertyValue.NumField(); i++ {
|
|
|
|
propertyValue := productVariablePropertyValue.Field(i)
|
2015-12-03 00:24:38 +01:00
|
|
|
kind := propertyValue.Kind()
|
|
|
|
if kind == reflect.Ptr {
|
|
|
|
if propertyValue.IsNil() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
propertyValue = propertyValue.Elem()
|
|
|
|
}
|
2015-07-09 22:57:48 +02:00
|
|
|
switch propertyValue.Kind() {
|
|
|
|
case reflect.String:
|
2017-05-06 01:16:24 +02:00
|
|
|
err := printfIntoProperty(propertyValue, variableValue)
|
|
|
|
if err != nil {
|
|
|
|
printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err)
|
|
|
|
}
|
2015-07-09 22:57:48 +02:00
|
|
|
case reflect.Slice:
|
|
|
|
for j := 0; j < propertyValue.Len(); j++ {
|
2017-05-06 01:16:24 +02:00
|
|
|
err := printfIntoProperty(propertyValue.Index(j), variableValue)
|
|
|
|
if err != nil {
|
|
|
|
printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err)
|
|
|
|
}
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
2015-12-03 00:24:38 +01:00
|
|
|
case reflect.Bool:
|
|
|
|
// Nothing
|
2015-07-09 22:57:48 +02:00
|
|
|
case reflect.Struct:
|
2017-05-06 01:16:24 +02:00
|
|
|
printfIntoProperties(ctx, prefix, propertyValue, variableValue)
|
2015-07-09 22:57:48 +02:00
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("unsupported field kind %q", propertyValue.Kind()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-06 01:16:24 +02:00
|
|
|
func printfIntoProperty(propertyValue reflect.Value, variableValue interface{}) error {
|
2015-07-09 22:57:48 +02:00
|
|
|
s := propertyValue.String()
|
2017-05-06 01:16:24 +02: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-09 22:57:48 +02:00
|
|
|
if strings.Contains(s, "%d") {
|
|
|
|
switch v := variableValue.(type) {
|
|
|
|
case int:
|
2017-05-06 01:16:24 +02:00
|
|
|
// Nothing
|
2015-07-09 22:57:48 +02:00
|
|
|
case bool:
|
|
|
|
if v {
|
2017-05-06 01:16:24 +02:00
|
|
|
variableValue = 1
|
|
|
|
} else {
|
|
|
|
variableValue = 0
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
|
|
|
default:
|
2017-05-06 01:16:24 +02: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-09 22:57:48 +02:00
|
|
|
}
|
2017-05-06 01:16:24 +02:00
|
|
|
} else {
|
|
|
|
return fmt.Errorf("unsupported %% in product variable property")
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
2017-05-06 01:16:24 +02:00
|
|
|
|
|
|
|
propertyValue.Set(reflect.ValueOf(fmt.Sprintf(s, variableValue)))
|
|
|
|
|
|
|
|
return nil
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
2019-09-25 07:19:02 +02: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 02:01:55 +01: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 07:19:02 +02: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
|
|
|
|
}
|
|
|
|
}
|