Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 16 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 17 | // This is the primary location to write and read all configuration values and |
| 18 | // product variables necessary for soong_build's operation. |
| 19 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 20 | import ( |
Colin Cross | 31a6745 | 2023-11-02 16:57:08 -0700 | [diff] [blame] | 21 | "android/soong/shared" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 22 | "encoding/json" |
| 23 | "fmt" |
| 24 | "os" |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 25 | "path/filepath" |
Sam Delmerico | 5c32bbf | 2022-01-20 20:15:02 +0000 | [diff] [blame] | 26 | "reflect" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 27 | "runtime" |
Inseob Kim | 60c32f0 | 2020-12-21 22:53:05 +0900 | [diff] [blame] | 28 | "strconv" |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 29 | "strings" |
Colin Cross | c1e86a3 | 2015-04-15 12:33:28 -0700 | [diff] [blame] | 30 | "sync" |
Cole Faust | d92430e | 2024-02-07 01:02:04 +0000 | [diff] [blame] | 31 | "unicode" |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 32 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 33 | "github.com/google/blueprint" |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 34 | "github.com/google/blueprint/bootstrap" |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 35 | "github.com/google/blueprint/pathtools" |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 36 | "github.com/google/blueprint/proptools" |
Colin Cross | 9d34f35 | 2019-11-22 16:03:51 -0800 | [diff] [blame] | 37 | |
| 38 | "android/soong/android/soongconfig" |
Liz Kammer | 09f947d | 2021-05-12 14:51:49 -0400 | [diff] [blame] | 39 | "android/soong/bazel" |
Colin Cross | 77cdcfd | 2021-03-12 11:28:25 -0800 | [diff] [blame] | 40 | "android/soong/remoteexec" |
Liz Kammer | 72beb34 | 2022-02-03 08:42:10 -0500 | [diff] [blame] | 41 | "android/soong/starlark_fmt" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 42 | ) |
| 43 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 44 | // Bool re-exports proptools.Bool for the android package. |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 45 | var Bool = proptools.Bool |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 46 | |
| 47 | // String re-exports proptools.String for the android package. |
Jack He | 8cc7143 | 2016-12-08 15:45:07 -0800 | [diff] [blame] | 48 | var String = proptools.String |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 49 | |
| 50 | // StringDefault re-exports proptools.StringDefault for the android package. |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 51 | var StringDefault = proptools.StringDefault |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 52 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 53 | // FutureApiLevelInt is a placeholder constant for unreleased API levels. |
Dan Albert | 0b176c8 | 2020-07-23 16:43:25 -0700 | [diff] [blame] | 54 | const FutureApiLevelInt = 10000 |
| 55 | |
Spandan Das | 15da588 | 2023-03-02 23:36:39 +0000 | [diff] [blame] | 56 | // PrivateApiLevel represents the api level of SdkSpecPrivate (sdk_version: "") |
| 57 | // This api_level exists to differentiate user-provided "" from "current" sdk_version |
| 58 | // The differentiation is necessary to enable different validation rules for these two possible values. |
| 59 | var PrivateApiLevel = ApiLevel{ |
| 60 | value: "current", // The value is current since aidl expects `current` as the default (TestAidlFlagsWithMinSdkVersion) |
| 61 | number: FutureApiLevelInt + 1, // This is used to differentiate it from FutureApiLevel |
| 62 | isPreview: true, |
| 63 | } |
| 64 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 65 | // FutureApiLevel represents unreleased API levels. |
Dan Albert | 0b176c8 | 2020-07-23 16:43:25 -0700 | [diff] [blame] | 66 | var FutureApiLevel = ApiLevel{ |
| 67 | value: "current", |
| 68 | number: FutureApiLevelInt, |
| 69 | isPreview: true, |
| 70 | } |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 71 | |
Jingwen Chen | c4d91bc | 2020-11-24 22:59:26 -0500 | [diff] [blame] | 72 | // The product variables file name, containing product config from Kati. |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 73 | const productVariablesFileName = "soong.variables" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 74 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 75 | // A Config object represents the entire build configuration for Android. |
Colin Cross | c3c0a49 | 2015-04-10 15:43:55 -0700 | [diff] [blame] | 76 | type Config struct { |
| 77 | *config |
| 78 | } |
| 79 | |
Chris Parsons | ad87601 | 2022-08-20 14:48:32 -0400 | [diff] [blame] | 80 | type SoongBuildMode int |
| 81 | |
Sasha Smundak | af5ca92 | 2022-12-12 21:23:34 -0800 | [diff] [blame] | 82 | type CmdArgs struct { |
| 83 | bootstrap.Args |
Kiyoung Kim | a37d9ba | 2023-04-19 13:13:45 +0900 | [diff] [blame] | 84 | RunGoTests bool |
| 85 | OutDir string |
| 86 | SoongOutDir string |
| 87 | SoongVariables string |
Sasha Smundak | af5ca92 | 2022-12-12 21:23:34 -0800 | [diff] [blame] | 88 | |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 89 | BazelQueryViewDir string |
| 90 | ModuleGraphFile string |
| 91 | ModuleActionsFile string |
| 92 | DocFile string |
Sasha Smundak | af5ca92 | 2022-12-12 21:23:34 -0800 | [diff] [blame] | 93 | |
LaMont Jones | 52a7243 | 2023-03-09 18:19:35 +0000 | [diff] [blame] | 94 | MultitreeBuild bool |
| 95 | |
Jihoon Kang | 2a929ad | 2023-06-08 19:02:07 +0000 | [diff] [blame] | 96 | BuildFromSourceStub bool |
MarkDacek | f47e142 | 2023-04-19 16:47:36 +0000 | [diff] [blame] | 97 | |
| 98 | EnsureAllowlistIntegrity bool |
Sasha Smundak | af5ca92 | 2022-12-12 21:23:34 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Chris Parsons | ad87601 | 2022-08-20 14:48:32 -0400 | [diff] [blame] | 101 | // Build modes that soong_build can run as. |
| 102 | const ( |
| 103 | // Don't use bazel at all during module analysis. |
| 104 | AnalysisNoBazel SoongBuildMode = iota |
| 105 | |
Chris Parsons | ad87601 | 2022-08-20 14:48:32 -0400 | [diff] [blame] | 106 | // Generate BUILD files which faithfully represent the dependency graph of |
| 107 | // blueprint modules. Individual BUILD targets will not, however, faitfhully |
| 108 | // express build semantics. |
| 109 | GenerateQueryView |
| 110 | |
| 111 | // Create a JSON representation of the module graph and exit. |
| 112 | GenerateModuleGraph |
| 113 | |
| 114 | // Generate a documentation file for module type definitions and exit. |
| 115 | GenerateDocFile |
Chris Parsons | ad87601 | 2022-08-20 14:48:32 -0400 | [diff] [blame] | 116 | ) |
| 117 | |
Lukacs T. Berki | b078ade | 2021-08-31 10:42:08 +0200 | [diff] [blame] | 118 | // SoongOutDir returns the build output directory for the configuration. |
Lukacs T. Berki | 9f6c24a | 2021-08-26 15:07:24 +0200 | [diff] [blame] | 119 | func (c Config) SoongOutDir() string { |
| 120 | return c.soongOutDir |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Colin Cross | 31a6745 | 2023-11-02 16:57:08 -0700 | [diff] [blame] | 123 | // tempDir returns the path to out/soong/.temp, which is cleared at the beginning of every build. |
| 124 | func (c Config) tempDir() string { |
| 125 | return shared.TempDirForOutDir(c.soongOutDir) |
| 126 | } |
| 127 | |
Lukacs T. Berki | 9f6c24a | 2021-08-26 15:07:24 +0200 | [diff] [blame] | 128 | func (c Config) OutDir() string { |
Lukacs T. Berki | d6cee7e | 2021-09-01 16:25:51 +0200 | [diff] [blame] | 129 | return c.outDir |
Lukacs T. Berki | 89e9a16 | 2021-03-12 08:31:32 +0100 | [diff] [blame] | 130 | } |
| 131 | |
Lukacs T. Berki | ea1a31c | 2021-09-02 09:58:09 +0200 | [diff] [blame] | 132 | func (c Config) RunGoTests() bool { |
| 133 | return c.runGoTests |
| 134 | } |
| 135 | |
Lukacs T. Berki | 5f6cb1d | 2021-03-17 15:03:14 +0100 | [diff] [blame] | 136 | func (c Config) DebugCompilation() bool { |
| 137 | return false // Never compile Go code in the main build for debugging |
| 138 | } |
| 139 | |
Lukacs T. Berki | ea1a31c | 2021-09-02 09:58:09 +0200 | [diff] [blame] | 140 | func (c Config) Subninjas() []string { |
| 141 | return []string{} |
| 142 | } |
| 143 | |
| 144 | func (c Config) PrimaryBuilderInvocations() []bootstrap.PrimaryBuilderInvocation { |
| 145 | return []bootstrap.PrimaryBuilderInvocation{} |
| 146 | } |
| 147 | |
Paul Duffin | 7413558 | 2022-10-06 11:01:59 +0100 | [diff] [blame] | 148 | // RunningInsideUnitTest returns true if this code is being run as part of a Soong unit test. |
| 149 | func (c Config) RunningInsideUnitTest() bool { |
| 150 | return c.config.TestProductVariables != nil |
| 151 | } |
| 152 | |
Pratyush | faec4db | 2023-07-20 11:19:04 +0000 | [diff] [blame] | 153 | // DisableHiddenApiChecks returns true if hiddenapi checks have been disabled. |
Alyssa Ketpreechasawat | 7daf278 | 2023-11-01 13:58:39 +0000 | [diff] [blame] | 154 | // For 'eng' target variant hiddenapi checks are disabled by default for performance optimisation, |
Pratyush | faec4db | 2023-07-20 11:19:04 +0000 | [diff] [blame] | 155 | // but can be enabled by setting environment variable ENABLE_HIDDENAPI_FLAGS=true. |
| 156 | // For other target variants hiddenapi check are enabled by default but can be disabled by |
| 157 | // setting environment variable UNSAFE_DISABLE_HIDDENAPI_FLAGS=true. |
| 158 | // If both ENABLE_HIDDENAPI_FLAGS=true and UNSAFE_DISABLE_HIDDENAPI_FLAGS=true, then |
| 159 | // ENABLE_HIDDENAPI_FLAGS=true will be triggered and hiddenapi checks will be considered enabled. |
| 160 | func (c Config) DisableHiddenApiChecks() bool { |
| 161 | return !c.IsEnvTrue("ENABLE_HIDDENAPI_FLAGS") && |
| 162 | (c.IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") || |
Alyssa Ketpreechasawat | 7daf278 | 2023-11-01 13:58:39 +0000 | [diff] [blame] | 163 | Bool(c.productVariables.Eng)) |
| 164 | } |
| 165 | |
| 166 | // DisableVerifyOverlaps returns true if verify_overlaps is skipped. |
| 167 | // Mismatch in version of apexes and module SDK is required for mainline prebuilts to work in |
| 168 | // trunk stable. |
| 169 | // Thus, verify_overlaps is disabled when RELEASE_DEFAULT_MODULE_BUILD_FROM_SOURCE is set to false. |
| 170 | // TODO(b/308174018): Re-enable verify_overlaps for both builr from source/mainline prebuilts. |
| 171 | func (c Config) DisableVerifyOverlaps() bool { |
| 172 | return c.IsEnvTrue("DISABLE_VERIFY_OVERLAPS") || !c.ReleaseDefaultModuleBuildFromSource() |
Pratyush | faec4db | 2023-07-20 11:19:04 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Juan Yescas | 05d4d90 | 2023-04-07 10:35:35 -0700 | [diff] [blame] | 175 | // MaxPageSizeSupported returns the max page size supported by the device. This |
| 176 | // value will define the ELF segment alignment for binaries (executables and |
| 177 | // shared libraries). |
| 178 | func (c Config) MaxPageSizeSupported() string { |
| 179 | return String(c.config.productVariables.DeviceMaxPageSizeSupported) |
| 180 | } |
| 181 | |
Vilas Bhat | b3d2d22 | 2023-12-04 22:51:20 +0000 | [diff] [blame] | 182 | // NoBionicPageSizeMacro returns true when AOSP is page size agnostic. |
| 183 | // This means that the bionic's macro PAGE_SIZE won't be defined. |
| 184 | // Returns false when AOSP is NOT page size agnostic. |
| 185 | // This means that bionic's macro PAGE_SIZE is defined. |
| 186 | func (c Config) NoBionicPageSizeMacro() bool { |
| 187 | return Bool(c.config.productVariables.DeviceNoBionicPageSizeMacro) |
Juan Yescas | 0106560 | 2023-08-09 08:34:37 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 190 | // The release version passed to aconfig, derived from RELEASE_VERSION |
| 191 | func (c Config) ReleaseVersion() string { |
| 192 | return c.config.productVariables.ReleaseVersion |
| 193 | } |
| 194 | |
Yu Liu | 2cc802a | 2023-09-05 17:19:45 -0700 | [diff] [blame] | 195 | // The aconfig value set passed to aconfig, derived from RELEASE_VERSION |
Yu Liu | eebb259 | 2023-10-12 20:31:27 -0700 | [diff] [blame] | 196 | func (c Config) ReleaseAconfigValueSets() []string { |
Yu Liu | 95572ff | 2023-12-07 16:38:45 -0800 | [diff] [blame] | 197 | return c.config.productVariables.ReleaseAconfigValueSets |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Zhi Dou | 3f65a41 | 2023-08-10 21:47:40 +0000 | [diff] [blame] | 200 | // The flag default permission value passed to aconfig |
| 201 | // derived from RELEASE_ACONFIG_FLAG_DEFAULT_PERMISSION |
| 202 | func (c Config) ReleaseAconfigFlagDefaultPermission() string { |
| 203 | return c.config.productVariables.ReleaseAconfigFlagDefaultPermission |
| 204 | } |
| 205 | |
Alyssa Ketpreechasawat | 34ab879 | 2023-10-06 07:01:22 +0000 | [diff] [blame] | 206 | // The flag indicating behavior for the tree wrt building modules or using prebuilts |
| 207 | // derived from RELEASE_DEFAULT_MODULE_BUILD_FROM_SOURCE |
| 208 | func (c Config) ReleaseDefaultModuleBuildFromSource() bool { |
| 209 | return c.config.productVariables.ReleaseDefaultModuleBuildFromSource == nil || |
| 210 | Bool(c.config.productVariables.ReleaseDefaultModuleBuildFromSource) |
| 211 | } |
| 212 | |
Jihoon Kang | 5919815 | 2024-02-06 22:43:18 +0000 | [diff] [blame] | 213 | // Enables flagged apis annotated with READ_WRITE aconfig flags to be included in the stubs |
| 214 | // and hiddenapi flags so that they are accessible at runtime |
| 215 | func (c Config) ReleaseExportRuntimeApis() bool { |
| 216 | return c.config.productVariables.GetBuildFlagBool("RELEASE_EXPORT_RUNTIME_APIS") |
| 217 | } |
| 218 | |
Aleksei Vetrov | 146e982 | 2023-11-24 19:54:26 +0000 | [diff] [blame] | 219 | // Enables ABI monitoring of NDK libraries |
| 220 | func (c Config) ReleaseNdkAbiMonitored() bool { |
| 221 | return c.config.productVariables.GetBuildFlagBool("RELEASE_NDK_ABI_MONITORED") |
| 222 | } |
| 223 | |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 224 | func (c Config) ReleaseHiddenApiExportableStubs() bool { |
Jihoon Kang | b36fc54 | 2024-02-22 19:35:26 +0000 | [diff] [blame^] | 225 | return c.config.productVariables.GetBuildFlagBool("RELEASE_HIDDEN_API_EXPORTABLE_STUBS") || |
| 226 | Bool(c.config.productVariables.HiddenapiExportableStubs) |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 229 | // A DeviceConfig object represents the configuration for a particular device |
| 230 | // being built. For now there will only be one of these, but in the future there |
| 231 | // may be multiple devices being built. |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 232 | type DeviceConfig struct { |
| 233 | *deviceConfig |
| 234 | } |
| 235 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 236 | // VendorConfig represents the configuration for vendor-specific behavior. |
Colin Cross | 9d34f35 | 2019-11-22 16:03:51 -0800 | [diff] [blame] | 237 | type VendorConfig soongconfig.SoongConfig |
Dan Willemsen | 0fe7866 | 2018-03-26 12:41:18 -0700 | [diff] [blame] | 238 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 239 | // Definition of general build configuration for soong_build. Some of these |
Jingwen Chen | c4d91bc | 2020-11-24 22:59:26 -0500 | [diff] [blame] | 240 | // product configuration values are read from Kati-generated soong.variables. |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 241 | type config struct { |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 242 | // Options configurable with soong.variables |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 243 | productVariables ProductVariables |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 244 | |
Dan Willemsen | 674dc7f | 2018-03-12 18:06:05 -0700 | [diff] [blame] | 245 | // Only available on configs created by TestConfig |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 246 | TestProductVariables *ProductVariables |
Dan Willemsen | 674dc7f | 2018-03-12 18:06:05 -0700 | [diff] [blame] | 247 | |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 248 | ProductVariablesFileName string |
| 249 | |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 250 | // BuildOS stores the OsType for the OS that the build is running on. |
| 251 | BuildOS OsType |
| 252 | |
| 253 | // BuildArch stores the ArchType for the CPU that the build is running on. |
| 254 | BuildArch ArchType |
| 255 | |
Jaewoong Jung | 642916f | 2020-10-09 17:25:15 -0700 | [diff] [blame] | 256 | Targets map[OsType][]Target |
| 257 | BuildOSTarget Target // the Target for tools run on the build machine |
| 258 | BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine |
| 259 | AndroidCommonTarget Target // the Target for common modules for the Android device |
| 260 | AndroidFirstDeviceTarget Target // the first Target for modules for the Android device |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 261 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 262 | // multilibConflicts for an ArchType is true if there is earlier configured |
| 263 | // device architecture with the same multilib value. |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 264 | multilibConflicts map[ArchType]bool |
| 265 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 266 | deviceConfig *deviceConfig |
| 267 | |
Lukacs T. Berki | d6cee7e | 2021-09-01 16:25:51 +0200 | [diff] [blame] | 268 | outDir string // The output directory (usually out/) |
| 269 | soongOutDir string |
Chris Parsons | 8f232a2 | 2020-06-23 17:37:05 -0400 | [diff] [blame] | 270 | moduleListFile string // the path to the file which lists blueprint files to parse. |
Colin Cross | c1e86a3 | 2015-04-15 12:33:28 -0700 | [diff] [blame] | 271 | |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 272 | runGoTests bool |
Lukacs T. Berki | ea1a31c | 2021-09-02 09:58:09 +0200 | [diff] [blame] | 273 | |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 274 | env map[string]string |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 275 | envLock sync.Mutex |
| 276 | envDeps map[string]string |
| 277 | envFrozen bool |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 278 | |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 279 | // Changes behavior based on whether Kati runs after soong_build, or if soong_build |
| 280 | // runs standalone. |
| 281 | katiEnabled bool |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 282 | |
Colin Cross | 32616ed | 2017-09-05 21:56:44 -0700 | [diff] [blame] | 283 | captureBuild bool // true for tests, saves build parameters for each module |
| 284 | ignoreEnvironment bool // true for tests, returns empty from all Getenv calls |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 285 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 286 | fs pathtools.FileSystem |
| 287 | mockBpList string |
| 288 | |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 289 | BuildMode SoongBuildMode |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 290 | |
LaMont Jones | 52a7243 | 2023-03-09 18:19:35 +0000 | [diff] [blame] | 291 | // If MultitreeBuild is true then this is one inner tree of a multitree |
| 292 | // build directed by the multitree orchestrator. |
| 293 | MultitreeBuild bool |
| 294 | |
Colin Cross | 5e6a797 | 2020-06-07 16:56:32 -0700 | [diff] [blame] | 295 | // If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error |
| 296 | // in tests when a path doesn't exist. |
Pedro Loureiro | 5d190cc | 2021-02-15 15:41:33 +0000 | [diff] [blame] | 297 | TestAllowNonExistentPaths bool |
Colin Cross | 5e6a797 | 2020-06-07 16:56:32 -0700 | [diff] [blame] | 298 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 299 | // The list of files that when changed, must invalidate soong_build to |
| 300 | // regenerate build.ninja. |
Colin Cross | 1212929 | 2020-10-29 18:23:58 -0700 | [diff] [blame] | 301 | ninjaFileDepsSet sync.Map |
| 302 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 303 | OncePer |
MarkDacek | ff851b8 | 2022-04-21 18:33:17 +0000 | [diff] [blame] | 304 | |
Jihoon Kang | 2a929ad | 2023-06-08 19:02:07 +0000 | [diff] [blame] | 305 | // If buildFromSourceStub is true then the Java API stubs are |
| 306 | // built from the source Java files, not the signature text files. |
| 307 | buildFromSourceStub bool |
MarkDacek | f47e142 | 2023-04-19 16:47:36 +0000 | [diff] [blame] | 308 | |
| 309 | // If ensureAllowlistIntegrity is true, then the presence of any allowlisted |
| 310 | // modules that aren't mixed-built for at least one variant will cause a build |
| 311 | // failure |
| 312 | ensureAllowlistIntegrity bool |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 313 | |
| 314 | // List of Api libraries that contribute to Api surfaces. |
| 315 | apiLibraries map[string]struct{} |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | type deviceConfig struct { |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 319 | config *config |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 320 | OncePer |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 323 | type jsonConfigurable interface { |
Colin Cross | 2738597 | 2015-09-18 10:57:10 -0700 | [diff] [blame] | 324 | SetDefaultConfig() |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 325 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 326 | |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 327 | func loadConfig(config *config) error { |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 328 | return loadFromConfigFile(&config.productVariables, absolutePath(config.ProductVariablesFileName)) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Cole Faust | d92430e | 2024-02-07 01:02:04 +0000 | [diff] [blame] | 331 | // Checks if the string is a valid go identifier. This is equivalent to blueprint's definition |
| 332 | // of an identifier, so it will match the same identifiers as those that can be used in bp files. |
| 333 | func isGoIdentifier(ident string) bool { |
| 334 | for i, r := range ident { |
| 335 | valid := r == '_' || unicode.IsLetter(r) || unicode.IsDigit(r) && i > 0 |
| 336 | if !valid { |
| 337 | return false |
| 338 | } |
| 339 | } |
| 340 | return len(ident) > 0 |
| 341 | } |
| 342 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 343 | // loadFromConfigFile loads and decodes configuration options from a JSON file |
| 344 | // in the current working directory. |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 345 | func loadFromConfigFile(configurable *ProductVariables, filename string) error { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 346 | // Try to open the file |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 347 | configFileReader, err := os.Open(filename) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 348 | defer configFileReader.Close() |
| 349 | if os.IsNotExist(err) { |
| 350 | // Need to create a file, so that blueprint & ninja don't get in |
| 351 | // a dependency tracking loop. |
| 352 | // Make a file-configurable-options with defaults, write it out using |
| 353 | // a json writer. |
Colin Cross | 2738597 | 2015-09-18 10:57:10 -0700 | [diff] [blame] | 354 | configurable.SetDefaultConfig() |
| 355 | err = saveToConfigFile(configurable, filename) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 356 | if err != nil { |
| 357 | return err |
| 358 | } |
Colin Cross | 15cd21a | 2018-02-27 11:26:02 -0800 | [diff] [blame] | 359 | } else if err != nil { |
| 360 | return fmt.Errorf("config file: could not open %s: %s", filename, err.Error()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 361 | } else { |
| 362 | // Make a decoder for it |
| 363 | jsonDecoder := json.NewDecoder(configFileReader) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 364 | err = jsonDecoder.Decode(configurable) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 365 | if err != nil { |
Colin Cross | 15cd21a | 2018-02-27 11:26:02 -0800 | [diff] [blame] | 366 | return fmt.Errorf("config file: %s did not parse correctly: %s", filename, err.Error()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
Liz Kammer | 09f947d | 2021-05-12 14:51:49 -0400 | [diff] [blame] | 370 | if Bool(configurable.GcovCoverage) && Bool(configurable.ClangCoverage) { |
| 371 | return fmt.Errorf("GcovCoverage and ClangCoverage cannot both be set") |
| 372 | } |
| 373 | |
| 374 | configurable.Native_coverage = proptools.BoolPtr( |
| 375 | Bool(configurable.GcovCoverage) || |
| 376 | Bool(configurable.ClangCoverage)) |
| 377 | |
Cole Faust | d92430e | 2024-02-07 01:02:04 +0000 | [diff] [blame] | 378 | // The go scanner's definition of identifiers is c-style identifiers, but allowing unicode's |
| 379 | // definition of letters and digits. This is the same scanner that blueprint uses, so it |
| 380 | // will allow the same identifiers as are valid in bp files. |
| 381 | for namespace := range configurable.VendorVars { |
| 382 | if !isGoIdentifier(namespace) { |
| 383 | return fmt.Errorf("soong config namespaces must be valid identifiers: %q", namespace) |
| 384 | } |
| 385 | for variable := range configurable.VendorVars[namespace] { |
| 386 | if !isGoIdentifier(variable) { |
| 387 | return fmt.Errorf("soong config variables must be valid identifiers: %q", variable) |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
Yuntao Xu | 402e9b0 | 2021-08-09 15:44:44 -0700 | [diff] [blame] | 392 | // when Platform_sdk_final is true (or PLATFORM_VERSION_CODENAME is REL), use Platform_sdk_version; |
| 393 | // if false (pre-released version, for example), use Platform_sdk_codename. |
| 394 | if Bool(configurable.Platform_sdk_final) { |
| 395 | if configurable.Platform_sdk_version != nil { |
| 396 | configurable.Platform_sdk_version_or_codename = |
| 397 | proptools.StringPtr(strconv.Itoa(*(configurable.Platform_sdk_version))) |
| 398 | } else { |
| 399 | return fmt.Errorf("Platform_sdk_version cannot be pointed by a NULL pointer") |
| 400 | } |
| 401 | } else { |
| 402 | configurable.Platform_sdk_version_or_codename = |
| 403 | proptools.StringPtr(String(configurable.Platform_sdk_codename)) |
| 404 | } |
| 405 | |
Liz Kammer | 09f947d | 2021-05-12 14:51:49 -0400 | [diff] [blame] | 406 | return saveToBazelConfigFile(configurable, filepath.Dir(filename)) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 407 | } |
| 408 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 409 | // atomically writes the config file in case two copies of soong_build are running simultaneously |
| 410 | // (for example, docs generation and ninja manifest generation) |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 411 | func saveToConfigFile(config *ProductVariables, filename string) error { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 412 | data, err := json.MarshalIndent(&config, "", " ") |
| 413 | if err != nil { |
| 414 | return fmt.Errorf("cannot marshal config data: %s", err.Error()) |
| 415 | } |
| 416 | |
Sasha Smundak | af5ca92 | 2022-12-12 21:23:34 -0800 | [diff] [blame] | 417 | f, err := os.CreateTemp(filepath.Dir(filename), "config") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 418 | if err != nil { |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 419 | return fmt.Errorf("cannot create empty config file %s: %s", filename, err.Error()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 420 | } |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 421 | defer os.Remove(f.Name()) |
| 422 | defer f.Close() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 423 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 424 | _, err = f.Write(data) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 425 | if err != nil { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 426 | return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error()) |
| 427 | } |
| 428 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 429 | _, err = f.WriteString("\n") |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 430 | if err != nil { |
| 431 | return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 434 | f.Close() |
| 435 | os.Rename(f.Name(), filename) |
| 436 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 437 | return nil |
| 438 | } |
| 439 | |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 440 | type productVariableStarlarkRepresentation struct { |
| 441 | soongType string |
| 442 | selectable bool |
| 443 | archVariant bool |
| 444 | } |
| 445 | |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 446 | func saveToBazelConfigFile(config *ProductVariables, outDir string) error { |
Liz Kammer | 09f947d | 2021-05-12 14:51:49 -0400 | [diff] [blame] | 447 | dir := filepath.Join(outDir, bazel.SoongInjectionDirName, "product_config") |
| 448 | err := createDirIfNonexistent(dir, os.ModePerm) |
| 449 | if err != nil { |
| 450 | return fmt.Errorf("Could not create dir %s: %s", dir, err) |
| 451 | } |
| 452 | |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 453 | allProductVariablesType := reflect.TypeOf((*ProductVariables)(nil)).Elem() |
| 454 | productVariablesInfo := make(map[string]productVariableStarlarkRepresentation) |
Sam Delmerico | 5c32bbf | 2022-01-20 20:15:02 +0000 | [diff] [blame] | 455 | p := variableProperties{} |
| 456 | t := reflect.TypeOf(p.Product_variables) |
| 457 | for i := 0; i < t.NumField(); i++ { |
| 458 | f := t.Field(i) |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 459 | archVariant := proptools.HasTag(f, "android", "arch_variant") |
| 460 | if mainProductVariablesStructField, ok := allProductVariablesType.FieldByName(f.Name); ok { |
| 461 | productVariablesInfo[f.Name] = productVariableStarlarkRepresentation{ |
| 462 | soongType: stringRepresentationOfSimpleType(mainProductVariablesStructField.Type), |
| 463 | selectable: true, |
| 464 | archVariant: archVariant, |
| 465 | } |
| 466 | } else { |
| 467 | panic("Unknown variable " + f.Name) |
Sam Delmerico | 5c32bbf | 2022-01-20 20:15:02 +0000 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
Cole Faust | eb644cf | 2023-04-11 13:48:17 -0700 | [diff] [blame] | 471 | err = pathtools.WriteFileIfChanged(filepath.Join(dir, "product_variable_constants.bzl"), []byte(fmt.Sprintf(` |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 472 | # product_var_constant_info is a map of product variables to information about them. The fields are: |
| 473 | # - soongType: The type of the product variable as it appears in soong's ProductVariables struct. |
| 474 | # examples are string, bool, int, *bool, *string, []string, etc. This may be an overly |
| 475 | # conservative estimation of the type, for example a *bool could oftentimes just be a |
| 476 | # bool that defaults to false. |
| 477 | # - selectable: if this product variable can be selected on in Android.bp/build files. This means |
| 478 | # it's listed in the "variableProperties" soong struct. Currently all variables in |
| 479 | # this list are selectable because we only need the selectable ones at the moment, |
| 480 | # but the list may be expanded later. |
| 481 | # - archVariant: If the variable is tagged as arch variant in the "variableProperties" struct. |
| 482 | product_var_constant_info = %s |
| 483 | product_var_constraints = [k for k, v in product_var_constant_info.items() if v.selectable] |
| 484 | arch_variant_product_var_constraints = [k for k, v in product_var_constant_info.items() if v.selectable and v.archVariant] |
| 485 | `, starlark_fmt.PrintAny(productVariablesInfo, 0))), 0644) |
Cole Faust | eb644cf | 2023-04-11 13:48:17 -0700 | [diff] [blame] | 486 | if err != nil { |
| 487 | return fmt.Errorf("Could not write .bzl config file %s", err) |
| 488 | } |
Chris Parsons | 0008cf8 | 2023-02-03 18:45:43 -0500 | [diff] [blame] | 489 | err = pathtools.WriteFileIfChanged(filepath.Join(dir, "BUILD"), |
| 490 | []byte(bazel.GeneratedBazelFileWarning), 0644) |
Liz Kammer | 09f947d | 2021-05-12 14:51:49 -0400 | [diff] [blame] | 491 | if err != nil { |
| 492 | return fmt.Errorf("Could not write BUILD config file %s", err) |
| 493 | } |
| 494 | |
| 495 | return nil |
| 496 | } |
| 497 | |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 498 | func stringRepresentationOfSimpleType(ty reflect.Type) string { |
| 499 | switch ty.Kind() { |
| 500 | case reflect.String: |
| 501 | return "string" |
| 502 | case reflect.Bool: |
| 503 | return "bool" |
| 504 | case reflect.Int: |
| 505 | return "int" |
| 506 | case reflect.Slice: |
| 507 | return "[]" + stringRepresentationOfSimpleType(ty.Elem()) |
| 508 | case reflect.Pointer: |
| 509 | return "*" + stringRepresentationOfSimpleType(ty.Elem()) |
| 510 | default: |
| 511 | panic("unimplemented type: " + ty.Kind().String()) |
| 512 | } |
| 513 | } |
| 514 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 515 | // NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that |
| 516 | // use the android package. |
Lukacs T. Berki | d6cee7e | 2021-09-01 16:25:51 +0200 | [diff] [blame] | 517 | func NullConfig(outDir, soongOutDir string) Config { |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 518 | return Config{ |
| 519 | config: &config{ |
Lukacs T. Berki | d6cee7e | 2021-09-01 16:25:51 +0200 | [diff] [blame] | 520 | outDir: outDir, |
Lukacs T. Berki | 9f6c24a | 2021-08-26 15:07:24 +0200 | [diff] [blame] | 521 | soongOutDir: soongOutDir, |
| 522 | fs: pathtools.OsFs, |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 523 | }, |
| 524 | } |
| 525 | } |
| 526 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 527 | // NewConfig creates a new Config object. The srcDir argument specifies the path |
| 528 | // to the root source directory. It also loads the config file, if found. |
Sasha Smundak | af5ca92 | 2022-12-12 21:23:34 -0800 | [diff] [blame] | 529 | func NewConfig(cmdArgs CmdArgs, availableEnv map[string]string) (Config, error) { |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 530 | // Make a config with default options. |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 531 | config := &config{ |
Kiyoung Kim | a37d9ba | 2023-04-19 13:13:45 +0900 | [diff] [blame] | 532 | ProductVariablesFileName: cmdArgs.SoongVariables, |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 533 | |
Lukacs T. Berki | 53b2f36 | 2021-04-12 14:04:24 +0200 | [diff] [blame] | 534 | env: availableEnv, |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 535 | |
Sasha Smundak | af5ca92 | 2022-12-12 21:23:34 -0800 | [diff] [blame] | 536 | outDir: cmdArgs.OutDir, |
| 537 | soongOutDir: cmdArgs.SoongOutDir, |
| 538 | runGoTests: cmdArgs.RunGoTests, |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 539 | multilibConflicts: make(map[ArchType]bool), |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 540 | |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 541 | moduleListFile: cmdArgs.ModuleListFile, |
| 542 | fs: pathtools.NewOsFs(absSrcDir), |
Chris Parsons | 9402ca8 | 2023-02-23 17:28:06 -0500 | [diff] [blame] | 543 | |
LaMont Jones | 52a7243 | 2023-03-09 18:19:35 +0000 | [diff] [blame] | 544 | MultitreeBuild: cmdArgs.MultitreeBuild, |
Jihoon Kang | 1bff034 | 2023-01-17 20:40:22 +0000 | [diff] [blame] | 545 | |
Jihoon Kang | 2a929ad | 2023-06-08 19:02:07 +0000 | [diff] [blame] | 546 | buildFromSourceStub: cmdArgs.BuildFromSourceStub, |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 547 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 548 | |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 549 | config.deviceConfig = &deviceConfig{ |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 550 | config: config, |
| 551 | } |
| 552 | |
Liz Kammer | 7941b30 | 2020-07-28 13:27:34 -0700 | [diff] [blame] | 553 | // Soundness check of the build and source directories. This won't catch strange |
| 554 | // configurations with symlinks, but at least checks the obvious case. |
Sasha Smundak | af5ca92 | 2022-12-12 21:23:34 -0800 | [diff] [blame] | 555 | absBuildDir, err := filepath.Abs(cmdArgs.SoongOutDir) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 556 | if err != nil { |
| 557 | return Config{}, err |
| 558 | } |
| 559 | |
Lukacs T. Berki | f7e36d8 | 2021-08-16 17:05:09 +0200 | [diff] [blame] | 560 | absSrcDir, err := filepath.Abs(".") |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 561 | if err != nil { |
| 562 | return Config{}, err |
| 563 | } |
| 564 | |
| 565 | if strings.HasPrefix(absSrcDir, absBuildDir) { |
| 566 | return Config{}, fmt.Errorf("Build dir must not contain source directory") |
| 567 | } |
| 568 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 569 | // Load any configurable options from the configuration file |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 570 | err = loadConfig(config) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 571 | if err != nil { |
Colin Cross | c3c0a49 | 2015-04-10 15:43:55 -0700 | [diff] [blame] | 572 | return Config{}, err |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 573 | } |
| 574 | |
Sasha Smundak | af5ca92 | 2022-12-12 21:23:34 -0800 | [diff] [blame] | 575 | KatiEnabledMarkerFile := filepath.Join(cmdArgs.SoongOutDir, ".soong.kati_enabled") |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 576 | if _, err := os.Stat(absolutePath(KatiEnabledMarkerFile)); err == nil { |
| 577 | config.katiEnabled = true |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 578 | } |
| 579 | |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 580 | determineBuildOS(config) |
| 581 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 582 | // Sets up the map of target OSes to the finer grained compilation targets |
| 583 | // that are configured from the product variables. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 584 | targets, err := decodeTargetProductVariables(config) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 585 | if err != nil { |
| 586 | return Config{}, err |
| 587 | } |
| 588 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 589 | // Make the CommonOS OsType available for all products. |
| 590 | targets[CommonOS] = []Target{commonTargetMap[CommonOS.Name]} |
| 591 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 592 | var archConfig []archConfig |
Jingwen Chen | c4d91bc | 2020-11-24 22:59:26 -0500 | [diff] [blame] | 593 | if config.NdkAbis() { |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 594 | archConfig = getNdkAbisConfig() |
Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 595 | } else if config.AmlAbis() { |
| 596 | archConfig = getAmlAbisConfig() |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | if archConfig != nil { |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 600 | androidTargets, err := decodeAndroidArchSettings(archConfig) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 601 | if err != nil { |
| 602 | return Config{}, err |
| 603 | } |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 604 | targets[Android] = androidTargets |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 605 | } |
| 606 | |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 607 | multilib := make(map[string]bool) |
| 608 | for _, target := range targets[Android] { |
| 609 | if seen := multilib[target.Arch.ArchType.Multilib]; seen { |
| 610 | config.multilibConflicts[target.Arch.ArchType] = true |
| 611 | } |
| 612 | multilib[target.Arch.ArchType.Multilib] = true |
| 613 | } |
| 614 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 615 | // Map of OS to compilation targets. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 616 | config.Targets = targets |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 617 | |
| 618 | // Compilation targets for host tools. |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 619 | config.BuildOSTarget = config.Targets[config.BuildOS][0] |
| 620 | config.BuildOSCommonTarget = getCommonTargets(config.Targets[config.BuildOS])[0] |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 621 | |
| 622 | // Compilation targets for Android. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 623 | if len(config.Targets[Android]) > 0 { |
| 624 | config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0] |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 625 | config.AndroidFirstDeviceTarget = FirstTarget(config.Targets[Android], "lib64", "lib32")[0] |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 626 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 627 | |
Usta Shrestha | cae3bfa | 2022-12-21 11:44:26 -0500 | [diff] [blame] | 628 | setBuildMode := func(arg string, mode SoongBuildMode) { |
| 629 | if arg != "" { |
| 630 | if config.BuildMode != AnalysisNoBazel { |
| 631 | fmt.Fprintf(os.Stderr, "buildMode is already set, illegal argument: %s", arg) |
| 632 | os.Exit(1) |
| 633 | } |
| 634 | config.BuildMode = mode |
| 635 | } |
Sasha Smundak | af5ca92 | 2022-12-12 21:23:34 -0800 | [diff] [blame] | 636 | } |
Usta Shrestha | cae3bfa | 2022-12-21 11:44:26 -0500 | [diff] [blame] | 637 | setBuildMode(cmdArgs.BazelQueryViewDir, GenerateQueryView) |
Usta Shrestha | cae3bfa | 2022-12-21 11:44:26 -0500 | [diff] [blame] | 638 | setBuildMode(cmdArgs.ModuleGraphFile, GenerateModuleGraph) |
| 639 | setBuildMode(cmdArgs.DocFile, GenerateDocFile) |
MarkDacek | d06db5d | 2022-11-29 00:47:59 +0000 | [diff] [blame] | 640 | |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 641 | // TODO(b/276958307): Replace the hardcoded list to a sdk_library local prop. |
| 642 | config.apiLibraries = map[string]struct{}{ |
| 643 | "android.net.ipsec.ike": {}, |
| 644 | "art.module.public.api": {}, |
| 645 | "conscrypt.module.public.api": {}, |
| 646 | "framework-adservices": {}, |
| 647 | "framework-appsearch": {}, |
| 648 | "framework-bluetooth": {}, |
| 649 | "framework-connectivity": {}, |
| 650 | "framework-connectivity-t": {}, |
| 651 | "framework-graphics": {}, |
Mark White | 387a658 | 2023-08-06 00:20:47 +0000 | [diff] [blame] | 652 | "framework-location": {}, |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 653 | "framework-media": {}, |
| 654 | "framework-mediaprovider": {}, |
Roshan Pius | 92307ff | 2023-11-13 17:16:35 -0800 | [diff] [blame] | 655 | "framework-nfc": {}, |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 656 | "framework-ondevicepersonalization": {}, |
Alyssa Ketpreechasawat | 9f63436 | 2023-11-08 16:03:53 +0000 | [diff] [blame] | 657 | "framework-pdf": {}, |
Nishant Panwar | 0ce9465 | 2024-02-10 09:02:15 +0000 | [diff] [blame] | 658 | "framework-pdf-v": {}, |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 659 | "framework-permission": {}, |
| 660 | "framework-permission-s": {}, |
| 661 | "framework-scheduling": {}, |
| 662 | "framework-sdkextensions": {}, |
| 663 | "framework-statsd": {}, |
| 664 | "framework-sdksandbox": {}, |
| 665 | "framework-tethering": {}, |
| 666 | "framework-uwb": {}, |
| 667 | "framework-virtualization": {}, |
| 668 | "framework-wifi": {}, |
| 669 | "i18n.module.public.api": {}, |
| 670 | } |
| 671 | |
Jihoon Kang | c1b04d6 | 2023-11-16 19:07:04 +0000 | [diff] [blame] | 672 | config.productVariables.Build_from_text_stub = boolPtr(config.BuildFromTextStub()) |
| 673 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 674 | return Config{config}, err |
| 675 | } |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 676 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 677 | // mockFileSystem replaces all reads with accesses to the provided map of |
| 678 | // filenames to contents stored as a byte slice. |
| 679 | func (c *config) mockFileSystem(bp string, fs map[string][]byte) { |
| 680 | mockFS := map[string][]byte{} |
| 681 | |
| 682 | if _, exists := mockFS["Android.bp"]; !exists { |
| 683 | mockFS["Android.bp"] = []byte(bp) |
| 684 | } |
| 685 | |
| 686 | for k, v := range fs { |
| 687 | mockFS[k] = v |
| 688 | } |
| 689 | |
| 690 | // no module list file specified; find every file named Blueprints or Android.bp |
| 691 | pathsToParse := []string{} |
| 692 | for candidate := range mockFS { |
| 693 | base := filepath.Base(candidate) |
Lukacs T. Berki | b838b0a | 2021-09-02 11:46:24 +0200 | [diff] [blame] | 694 | if base == "Android.bp" { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 695 | pathsToParse = append(pathsToParse, candidate) |
| 696 | } |
| 697 | } |
| 698 | if len(pathsToParse) < 1 { |
| 699 | panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", mockFS)) |
| 700 | } |
| 701 | mockFS[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n")) |
| 702 | |
| 703 | c.fs = pathtools.MockFs(mockFS) |
| 704 | c.mockBpList = blueprint.MockModuleListFile |
| 705 | } |
| 706 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 707 | func (c *config) SetAllowMissingDependencies() { |
| 708 | c.productVariables.Allow_missing_dependencies = proptools.BoolPtr(true) |
| 709 | } |
| 710 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 711 | // BlueprintToolLocation returns the directory containing build system tools |
| 712 | // from Blueprint, like soong_zip and merge_zips. |
Lukacs T. Berki | a806e41 | 2021-09-01 08:57:48 +0200 | [diff] [blame] | 713 | func (c *config) HostToolDir() string { |
Colin Cross | acfcc1f | 2021-10-25 15:40:32 -0700 | [diff] [blame] | 714 | if c.KatiEnabled() { |
| 715 | return filepath.Join(c.outDir, "host", c.PrebuiltOS(), "bin") |
| 716 | } else { |
| 717 | return filepath.Join(c.soongOutDir, "host", c.PrebuiltOS(), "bin") |
| 718 | } |
Dan Willemsen | c2aa4a9 | 2016-05-26 15:13:03 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Dan Willemsen | 60e62f0 | 2018-11-16 21:05:32 -0800 | [diff] [blame] | 721 | func (c *config) HostToolPath(ctx PathContext, tool string) Path { |
Cole Faust | 3b703f3 | 2023-10-16 13:30:51 -0700 | [diff] [blame] | 722 | path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "bin", tool) |
Colin Cross | 790ef35 | 2021-10-25 19:15:55 -0700 | [diff] [blame] | 723 | return path |
Dan Willemsen | 60e62f0 | 2018-11-16 21:05:32 -0800 | [diff] [blame] | 724 | } |
| 725 | |
Colin Cross | 790ef35 | 2021-10-25 19:15:55 -0700 | [diff] [blame] | 726 | func (c *config) HostJNIToolPath(ctx PathContext, lib string) Path { |
Martin Stjernholm | 7260d06 | 2019-12-09 21:47:14 +0000 | [diff] [blame] | 727 | ext := ".so" |
| 728 | if runtime.GOOS == "darwin" { |
| 729 | ext = ".dylib" |
| 730 | } |
Cole Faust | 3b703f3 | 2023-10-16 13:30:51 -0700 | [diff] [blame] | 731 | path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "lib64", lib+ext) |
Colin Cross | 790ef35 | 2021-10-25 19:15:55 -0700 | [diff] [blame] | 732 | return path |
Martin Stjernholm | 7260d06 | 2019-12-09 21:47:14 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Colin Cross | ae5330a | 2021-11-03 13:31:22 -0700 | [diff] [blame] | 735 | func (c *config) HostJavaToolPath(ctx PathContext, tool string) Path { |
Cole Faust | 3b703f3 | 2023-10-16 13:30:51 -0700 | [diff] [blame] | 736 | path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "framework", tool) |
Colin Cross | 3e3eda6 | 2021-11-04 10:22:51 -0700 | [diff] [blame] | 737 | return path |
| 738 | } |
| 739 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 740 | func (c *config) HostCcSharedLibPath(ctx PathContext, lib string) Path { |
| 741 | libDir := "lib" |
| 742 | if ctx.Config().BuildArch.Multilib == "lib64" { |
| 743 | libDir = "lib64" |
| 744 | } |
Cole Faust | 3b703f3 | 2023-10-16 13:30:51 -0700 | [diff] [blame] | 745 | return pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, libDir, lib+".so") |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 746 | } |
| 747 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 748 | // PrebuiltOS returns the name of the host OS used in prebuilts directories. |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 749 | func (c *config) PrebuiltOS() string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 750 | switch runtime.GOOS { |
| 751 | case "linux": |
| 752 | return "linux-x86" |
| 753 | case "darwin": |
| 754 | return "darwin-x86" |
| 755 | default: |
| 756 | panic("Unknown GOOS") |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | // GoRoot returns the path to the root directory of the Go toolchain. |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 761 | func (c *config) GoRoot() string { |
Lukacs T. Berki | f7e36d8 | 2021-08-16 17:05:09 +0200 | [diff] [blame] | 762 | return fmt.Sprintf("prebuilts/go/%s", c.PrebuiltOS()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 763 | } |
| 764 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 765 | // PrebuiltBuildTool returns the path to a tool in the prebuilts directory containing |
| 766 | // checked-in tools, like Kati, Ninja or Toybox, for the current host OS. |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 767 | func (c *config) PrebuiltBuildTool(ctx PathContext, tool string) Path { |
| 768 | return PathForSource(ctx, "prebuilts/build-tools", c.PrebuiltOS(), "bin", tool) |
| 769 | } |
| 770 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 771 | // CpPreserveSymlinksFlags returns the host-specific flag for the cp(1) command |
| 772 | // to preserve symlinks. |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 773 | func (c *config) CpPreserveSymlinksFlags() string { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 774 | switch runtime.GOOS { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 775 | case "darwin": |
| 776 | return "-R" |
| 777 | case "linux": |
| 778 | return "-d" |
| 779 | default: |
| 780 | return "" |
| 781 | } |
| 782 | } |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 783 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 784 | func (c *config) Getenv(key string) string { |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 785 | var val string |
| 786 | var exists bool |
Colin Cross | c1e86a3 | 2015-04-15 12:33:28 -0700 | [diff] [blame] | 787 | c.envLock.Lock() |
Colin Cross | c0d58b4 | 2017-02-06 15:40:41 -0800 | [diff] [blame] | 788 | defer c.envLock.Unlock() |
| 789 | if c.envDeps == nil { |
| 790 | c.envDeps = make(map[string]string) |
| 791 | } |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 792 | if val, exists = c.envDeps[key]; !exists { |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 793 | if c.envFrozen { |
| 794 | panic("Cannot access new environment variables after envdeps are frozen") |
| 795 | } |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 796 | val, _ = c.env[key] |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 797 | c.envDeps[key] = val |
| 798 | } |
| 799 | return val |
| 800 | } |
| 801 | |
Colin Cross | 99d7c23 | 2016-11-23 16:52:04 -0800 | [diff] [blame] | 802 | func (c *config) GetenvWithDefault(key string, defaultValue string) string { |
| 803 | ret := c.Getenv(key) |
| 804 | if ret == "" { |
| 805 | return defaultValue |
| 806 | } |
| 807 | return ret |
| 808 | } |
| 809 | |
| 810 | func (c *config) IsEnvTrue(key string) bool { |
| 811 | value := c.Getenv(key) |
| 812 | return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true" |
| 813 | } |
| 814 | |
| 815 | func (c *config) IsEnvFalse(key string) bool { |
| 816 | value := c.Getenv(key) |
| 817 | return value == "0" || value == "n" || value == "no" || value == "off" || value == "false" |
| 818 | } |
| 819 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 820 | // EnvDeps returns the environment variables this build depends on. The first |
| 821 | // call to this function blocks future reads from the environment. |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 822 | func (c *config) EnvDeps() map[string]string { |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 823 | c.envLock.Lock() |
Colin Cross | c0d58b4 | 2017-02-06 15:40:41 -0800 | [diff] [blame] | 824 | defer c.envLock.Unlock() |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 825 | c.envFrozen = true |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 826 | return c.envDeps |
| 827 | } |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 828 | |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 829 | func (c *config) KatiEnabled() bool { |
| 830 | return c.katiEnabled |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 831 | } |
| 832 | |
Cole Faust | 11edf55 | 2023-10-13 11:32:14 -0700 | [diff] [blame] | 833 | func (c *config) ProductVariables() ProductVariables { |
| 834 | return c.productVariables |
| 835 | } |
| 836 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 837 | func (c *config) BuildId() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 838 | return String(c.productVariables.BuildId) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 839 | } |
| 840 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 841 | // BuildNumberFile returns the path to a text file containing metadata |
| 842 | // representing the current build's number. |
| 843 | // |
| 844 | // Rules that want to reference the build number should read from this file |
| 845 | // without depending on it. They will run whenever their other dependencies |
| 846 | // require them to run and get the current build number. This ensures they don't |
| 847 | // rebuild on every incremental build when the build number changes. |
Colin Cross | 2a2e0db | 2020-02-21 16:55:46 -0800 | [diff] [blame] | 848 | func (c *config) BuildNumberFile(ctx PathContext) Path { |
| 849 | return PathForOutput(ctx, String(c.productVariables.BuildNumberFile)) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 850 | } |
| 851 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 852 | // DeviceName returns the name of the current device target. |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 853 | // TODO: take an AndroidModuleContext to select the device name for multi-device builds |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 854 | func (c *config) DeviceName() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 855 | return *c.productVariables.DeviceName |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Trevor Radcliffe | 90727f4 | 2022-03-21 19:34:02 +0000 | [diff] [blame] | 858 | // DeviceProduct returns the current product target. There could be multiple of |
| 859 | // these per device type. |
| 860 | // |
Chris Parsons | ef615e5 | 2022-08-18 22:04:11 -0400 | [diff] [blame] | 861 | // NOTE: Do not base conditional logic on this value. It may break product inheritance. |
Trevor Radcliffe | 90727f4 | 2022-03-21 19:34:02 +0000 | [diff] [blame] | 862 | func (c *config) DeviceProduct() string { |
| 863 | return *c.productVariables.DeviceProduct |
| 864 | } |
| 865 | |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 866 | // HasDeviceProduct returns if the build has a product. A build will not |
| 867 | // necessarily have a product when --skip-config is passed to soong, like it is |
| 868 | // in prebuilts/build-tools/build-prebuilts.sh |
| 869 | func (c *config) HasDeviceProduct() bool { |
| 870 | return c.productVariables.DeviceProduct != nil |
| 871 | } |
| 872 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 873 | func (c *config) DeviceResourceOverlays() []string { |
| 874 | return c.productVariables.DeviceResourceOverlays |
| 875 | } |
| 876 | |
| 877 | func (c *config) ProductResourceOverlays() []string { |
| 878 | return c.productVariables.ProductResourceOverlays |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Colin Cross | bfd347d | 2018-05-09 11:11:35 -0700 | [diff] [blame] | 881 | func (c *config) PlatformVersionName() string { |
| 882 | return String(c.productVariables.Platform_version_name) |
| 883 | } |
| 884 | |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 885 | func (c *config) PlatformSdkVersion() ApiLevel { |
| 886 | return uncheckedFinalApiLevel(*c.productVariables.Platform_sdk_version) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Cole Faust | 37d27c4 | 2023-04-12 10:27:45 -0700 | [diff] [blame] | 889 | func (c *config) RawPlatformSdkVersion() *int { |
| 890 | return c.productVariables.Platform_sdk_version |
| 891 | } |
| 892 | |
Mu-Le Lee | 5e04753 | 2022-07-27 02:32:03 +0000 | [diff] [blame] | 893 | func (c *config) PlatformSdkFinal() bool { |
| 894 | return Bool(c.productVariables.Platform_sdk_final) |
| 895 | } |
| 896 | |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 897 | func (c *config) PlatformSdkCodename() string { |
| 898 | return String(c.productVariables.Platform_sdk_codename) |
| 899 | } |
| 900 | |
Anton Hansson | 97d0bae | 2022-02-16 16:15:10 +0000 | [diff] [blame] | 901 | func (c *config) PlatformSdkExtensionVersion() int { |
| 902 | return *c.productVariables.Platform_sdk_extension_version |
| 903 | } |
| 904 | |
| 905 | func (c *config) PlatformBaseSdkExtensionVersion() int { |
| 906 | return *c.productVariables.Platform_base_sdk_extension_version |
| 907 | } |
| 908 | |
Colin Cross | 092c9da | 2019-04-02 22:56:43 -0700 | [diff] [blame] | 909 | func (c *config) PlatformSecurityPatch() string { |
| 910 | return String(c.productVariables.Platform_security_patch) |
| 911 | } |
| 912 | |
| 913 | func (c *config) PlatformPreviewSdkVersion() string { |
| 914 | return String(c.productVariables.Platform_preview_sdk_version) |
| 915 | } |
| 916 | |
| 917 | func (c *config) PlatformMinSupportedTargetSdkVersion() string { |
| 918 | return String(c.productVariables.Platform_min_supported_target_sdk_version) |
| 919 | } |
| 920 | |
| 921 | func (c *config) PlatformBaseOS() string { |
| 922 | return String(c.productVariables.Platform_base_os) |
| 923 | } |
| 924 | |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 925 | func (c *config) PlatformVersionLastStable() string { |
| 926 | return String(c.productVariables.Platform_version_last_stable) |
| 927 | } |
| 928 | |
Jiyong Park | 3707384 | 2022-06-21 10:13:42 +0900 | [diff] [blame] | 929 | func (c *config) PlatformVersionKnownCodenames() string { |
| 930 | return String(c.productVariables.Platform_version_known_codenames) |
| 931 | } |
| 932 | |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 933 | func (c *config) MinSupportedSdkVersion() ApiLevel { |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 934 | return uncheckedFinalApiLevel(21) |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | func (c *config) FinalApiLevels() []ApiLevel { |
| 938 | var levels []ApiLevel |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 939 | for i := 1; i <= c.PlatformSdkVersion().FinalOrFutureInt(); i++ { |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 940 | levels = append(levels, uncheckedFinalApiLevel(i)) |
| 941 | } |
| 942 | return levels |
| 943 | } |
| 944 | |
| 945 | func (c *config) PreviewApiLevels() []ApiLevel { |
| 946 | var levels []ApiLevel |
Dan Albert | f93ea13 | 2023-10-05 20:40:46 +0000 | [diff] [blame] | 947 | i := 0 |
| 948 | for _, codename := range c.PlatformVersionActiveCodenames() { |
| 949 | if codename == "REL" { |
| 950 | continue |
| 951 | } |
| 952 | |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 953 | levels = append(levels, ApiLevel{ |
| 954 | value: codename, |
| 955 | number: i, |
| 956 | isPreview: true, |
| 957 | }) |
Dan Albert | f93ea13 | 2023-10-05 20:40:46 +0000 | [diff] [blame] | 958 | i++ |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 959 | } |
| 960 | return levels |
| 961 | } |
| 962 | |
satayev | cca4ab7 | 2021-11-30 12:33:55 +0000 | [diff] [blame] | 963 | func (c *config) LatestPreviewApiLevel() ApiLevel { |
| 964 | level := NoneApiLevel |
| 965 | for _, l := range c.PreviewApiLevels() { |
| 966 | if l.GreaterThan(level) { |
| 967 | level = l |
| 968 | } |
| 969 | } |
| 970 | return level |
| 971 | } |
| 972 | |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 973 | func (c *config) AllSupportedApiLevels() []ApiLevel { |
| 974 | var levels []ApiLevel |
| 975 | levels = append(levels, c.FinalApiLevels()...) |
| 976 | return append(levels, c.PreviewApiLevels()...) |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 979 | // DefaultAppTargetSdk returns the API level that platform apps are targeting. |
| 980 | // This converts a codename to the exact ApiLevel it represents. |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 981 | func (c *config) DefaultAppTargetSdk(ctx EarlyModuleContext) ApiLevel { |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 982 | if Bool(c.productVariables.Platform_sdk_final) { |
| 983 | return c.PlatformSdkVersion() |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 984 | } |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 985 | codename := c.PlatformSdkCodename() |
Jiyong Park | 3a00e3d | 2023-03-27 17:39:48 +0900 | [diff] [blame] | 986 | hostOnlyBuild := c.productVariables.DeviceArch == nil |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 987 | if codename == "" { |
Jiyong Park | 3a00e3d | 2023-03-27 17:39:48 +0900 | [diff] [blame] | 988 | // There are some host-only builds (those are invoked by build-prebuilts.sh) which |
| 989 | // don't set platform sdk codename. Platform sdk codename makes sense only when we |
| 990 | // are building the platform. So we don't enforce the below panic for the host-only |
| 991 | // builds. |
| 992 | if hostOnlyBuild { |
| 993 | return NoneApiLevel |
| 994 | } |
| 995 | panic("Platform_sdk_codename must be set") |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 996 | } |
| 997 | if codename == "REL" { |
| 998 | panic("Platform_sdk_codename should not be REL when Platform_sdk_final is true") |
| 999 | } |
| 1000 | return ApiLevelOrPanic(ctx, codename) |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 1003 | func (c *config) AppsDefaultVersionName() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1004 | return String(c.productVariables.AppsDefaultVersionName) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 1005 | } |
| 1006 | |
Dan Albert | 31384de | 2017-07-28 12:39:46 -0700 | [diff] [blame] | 1007 | // Codenames that are active in the current lunch target. |
| 1008 | func (c *config) PlatformVersionActiveCodenames() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1009 | return c.productVariables.Platform_version_active_codenames |
Dan Albert | 31384de | 2017-07-28 12:39:46 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Dan Albert | 8c7a994 | 2023-03-27 20:34:01 +0000 | [diff] [blame] | 1012 | // All unreleased codenames. |
| 1013 | func (c *config) PlatformVersionAllPreviewCodenames() []string { |
| 1014 | return c.productVariables.Platform_version_all_preview_codenames |
| 1015 | } |
| 1016 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 1017 | func (c *config) ProductAAPTConfig() []string { |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1018 | return c.productVariables.AAPTConfig |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 1021 | func (c *config) ProductAAPTPreferredConfig() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1022 | return String(c.productVariables.AAPTPreferredConfig) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 1025 | func (c *config) ProductAAPTCharacteristics() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1026 | return String(c.productVariables.AAPTCharacteristics) |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | func (c *config) ProductAAPTPrebuiltDPI() []string { |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1030 | return c.productVariables.AAPTPrebuiltDPI |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1033 | func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1034 | defaultCert := String(c.productVariables.DefaultAppCertificate) |
Colin Cross | 61ae0b7 | 2017-12-01 17:16:02 -0800 | [diff] [blame] | 1035 | if defaultCert != "" { |
| 1036 | return PathForSource(ctx, filepath.Dir(defaultCert)) |
Colin Cross | 61ae0b7 | 2017-12-01 17:16:02 -0800 | [diff] [blame] | 1037 | } |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 1038 | return PathForSource(ctx, "build/make/target/product/security") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 1041 | func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1042 | defaultCert := String(c.productVariables.DefaultAppCertificate) |
Colin Cross | 61ae0b7 | 2017-12-01 17:16:02 -0800 | [diff] [blame] | 1043 | if defaultCert != "" { |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 1044 | return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8") |
Colin Cross | 61ae0b7 | 2017-12-01 17:16:02 -0800 | [diff] [blame] | 1045 | } |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 1046 | defaultDir := c.DefaultAppCertificateDir(ctx) |
| 1047 | return defaultDir.Join(ctx, "testkey.x509.pem"), defaultDir.Join(ctx, "testkey.pk8") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 1048 | } |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 1049 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1050 | func (c *config) ApexKeyDir(ctx ModuleContext) SourcePath { |
| 1051 | // TODO(b/121224311): define another variable such as TARGET_APEX_KEY_OVERRIDE |
| 1052 | defaultCert := String(c.productVariables.DefaultAppCertificate) |
Dan Willemsen | 412160e | 2019-04-09 21:36:26 -0700 | [diff] [blame] | 1053 | if defaultCert == "" || filepath.Dir(defaultCert) == "build/make/target/product/security" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1054 | // When defaultCert is unset or is set to the testkeys path, use the APEX keys |
| 1055 | // that is under the module dir |
Colin Cross | 07e5161 | 2019-03-05 12:46:40 -0800 | [diff] [blame] | 1056 | return pathForModuleSrc(ctx) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1057 | } |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 1058 | // If not, APEX keys are under the specified directory |
| 1059 | return PathForSource(ctx, filepath.Dir(defaultCert)) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1060 | } |
| 1061 | |
Inseob Kim | 80fa798 | 2022-08-12 21:36:25 +0900 | [diff] [blame] | 1062 | // Certificate for the NetworkStack sepolicy context |
| 1063 | func (c *config) MainlineSepolicyDevCertificatesDir(ctx ModuleContext) SourcePath { |
| 1064 | cert := String(c.productVariables.MainlineSepolicyDevCertificates) |
| 1065 | if cert != "" { |
| 1066 | return PathForSource(ctx, cert) |
| 1067 | } |
| 1068 | return c.DefaultAppCertificateDir(ctx) |
| 1069 | } |
| 1070 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 1071 | // AllowMissingDependencies configures Blueprint/Soong to not fail when modules |
| 1072 | // are configured to depend on non-existent modules. Note that this does not |
| 1073 | // affect missing input dependencies at the Ninja level. |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 1074 | func (c *config) AllowMissingDependencies() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1075 | return Bool(c.productVariables.Allow_missing_dependencies) |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 1076 | } |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1077 | |
Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 1078 | // Returns true if a full platform source tree cannot be assumed. |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 1079 | func (c *config) UnbundledBuild() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1080 | return Bool(c.productVariables.Unbundled_build) |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
Martin Stjernholm | fd9eb4b | 2020-06-17 01:13:15 +0100 | [diff] [blame] | 1083 | // Returns true if building apps that aren't bundled with the platform. |
| 1084 | // UnbundledBuild() is always true when this is true. |
| 1085 | func (c *config) UnbundledBuildApps() bool { |
Cole Faust | 701ca25 | 2021-11-23 19:02:08 -0800 | [diff] [blame] | 1086 | return len(c.productVariables.Unbundled_build_apps) > 0 |
Martin Stjernholm | fd9eb4b | 2020-06-17 01:13:15 +0100 | [diff] [blame] | 1087 | } |
| 1088 | |
Jeongik Cha | 4b073cd | 2021-06-08 11:35:00 +0900 | [diff] [blame] | 1089 | // Returns true if building image that aren't bundled with the platform. |
| 1090 | // UnbundledBuild() is always true when this is true. |
| 1091 | func (c *config) UnbundledBuildImage() bool { |
| 1092 | return Bool(c.productVariables.Unbundled_build_image) |
| 1093 | } |
| 1094 | |
Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 1095 | // Returns true if building modules against prebuilt SDKs. |
| 1096 | func (c *config) AlwaysUsePrebuiltSdks() bool { |
| 1097 | return Bool(c.productVariables.Always_use_prebuilt_sdks) |
Colin Cross | 1f367bf | 2018-12-18 22:46:24 -0800 | [diff] [blame] | 1098 | } |
| 1099 | |
Colin Cross | 126a25c | 2017-10-31 13:55:34 -0700 | [diff] [blame] | 1100 | func (c *config) MinimizeJavaDebugInfo() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1101 | return Bool(c.productVariables.MinimizeJavaDebugInfo) && !Bool(c.productVariables.Eng) |
Colin Cross | 126a25c | 2017-10-31 13:55:34 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Colin Cross | ed064c0 | 2018-09-05 16:28:13 -0700 | [diff] [blame] | 1104 | func (c *config) Debuggable() bool { |
| 1105 | return Bool(c.productVariables.Debuggable) |
| 1106 | } |
| 1107 | |
Jaewoong Jung | 1d6eb68 | 2018-11-29 15:08:44 -0800 | [diff] [blame] | 1108 | func (c *config) Eng() bool { |
| 1109 | return Bool(c.productVariables.Eng) |
| 1110 | } |
| 1111 | |
Colin Cross | c53c37f | 2021-12-08 15:42:22 -0800 | [diff] [blame] | 1112 | // DevicePrimaryArchType returns the ArchType for the first configured device architecture, or |
| 1113 | // Common if there are no device architectures. |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 1114 | func (c *config) DevicePrimaryArchType() ArchType { |
Colin Cross | c53c37f | 2021-12-08 15:42:22 -0800 | [diff] [blame] | 1115 | if androidTargets := c.Targets[Android]; len(androidTargets) > 0 { |
| 1116 | return androidTargets[0].Arch.ArchType |
| 1117 | } |
| 1118 | return Common |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 1119 | } |
| 1120 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1121 | func (c *config) SanitizeHost() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1122 | return append([]string(nil), c.productVariables.SanitizeHost...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | func (c *config) SanitizeDevice() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1126 | return append([]string(nil), c.productVariables.SanitizeDevice...) |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 1129 | func (c *config) SanitizeDeviceDiag() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1130 | return append([]string(nil), c.productVariables.SanitizeDeviceDiag...) |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 1133 | func (c *config) SanitizeDeviceArch() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1134 | return append([]string(nil), c.productVariables.SanitizeDeviceArch...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1135 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1136 | |
Vishwath Mohan | 1b017a7 | 2017-01-19 13:54:55 -0800 | [diff] [blame] | 1137 | func (c *config) EnableCFI() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1138 | if c.productVariables.EnableCFI == nil { |
Vishwath Mohan | c32c3eb | 2017-01-24 14:20:54 -0800 | [diff] [blame] | 1139 | return true |
Vishwath Mohan | c32c3eb | 2017-01-24 14:20:54 -0800 | [diff] [blame] | 1140 | } |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 1141 | return *c.productVariables.EnableCFI |
Vishwath Mohan | 1b017a7 | 2017-01-19 13:54:55 -0800 | [diff] [blame] | 1142 | } |
| 1143 | |
Kostya Kortchinsky | d5275c8 | 2019-02-01 08:42:56 -0800 | [diff] [blame] | 1144 | func (c *config) DisableScudo() bool { |
| 1145 | return Bool(c.productVariables.DisableScudo) |
| 1146 | } |
| 1147 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1148 | func (c *config) Android64() bool { |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1149 | for _, t := range c.Targets[Android] { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1150 | if t.Arch.ArchType.Multilib == "lib64" { |
| 1151 | return true |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | return false |
| 1156 | } |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 1157 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 1158 | func (c *config) UseGoma() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1159 | return Bool(c.productVariables.UseGoma) |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
Ramy Medhat | bbf2567 | 2019-07-17 12:30:04 +0000 | [diff] [blame] | 1162 | func (c *config) UseRBE() bool { |
| 1163 | return Bool(c.productVariables.UseRBE) |
| 1164 | } |
| 1165 | |
Ramy Medhat | 8ea054a | 2020-01-27 14:19:44 -0500 | [diff] [blame] | 1166 | func (c *config) UseRBEJAVAC() bool { |
| 1167 | return Bool(c.productVariables.UseRBEJAVAC) |
| 1168 | } |
| 1169 | |
| 1170 | func (c *config) UseRBER8() bool { |
| 1171 | return Bool(c.productVariables.UseRBER8) |
| 1172 | } |
| 1173 | |
| 1174 | func (c *config) UseRBED8() bool { |
| 1175 | return Bool(c.productVariables.UseRBED8) |
| 1176 | } |
| 1177 | |
Colin Cross | 8b8bec3 | 2019-11-15 13:18:43 -0800 | [diff] [blame] | 1178 | func (c *config) UseRemoteBuild() bool { |
| 1179 | return c.UseGoma() || c.UseRBE() |
| 1180 | } |
| 1181 | |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 1182 | func (c *config) RunErrorProne() bool { |
| 1183 | return c.IsEnvTrue("RUN_ERROR_PRONE") |
| 1184 | } |
| 1185 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 1186 | // XrefCorpusName returns the Kythe cross-reference corpus name. |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 1187 | func (c *config) XrefCorpusName() string { |
| 1188 | return c.Getenv("XREF_CORPUS") |
| 1189 | } |
| 1190 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 1191 | // XrefCuEncoding returns the compilation unit encoding to use for Kythe code |
| 1192 | // xrefs. Can be 'json' (default), 'proto' or 'all'. |
Sasha Smundak | 6c2d4f9 | 2020-01-09 17:34:23 -0800 | [diff] [blame] | 1193 | func (c *config) XrefCuEncoding() string { |
| 1194 | if enc := c.Getenv("KYTHE_KZIP_ENCODING"); enc != "" { |
| 1195 | return enc |
| 1196 | } |
| 1197 | return "json" |
| 1198 | } |
| 1199 | |
Sasha Smundak | b0addaf | 2021-02-16 10:39:40 -0800 | [diff] [blame] | 1200 | // XrefCuJavaSourceMax returns the maximum number of the Java source files |
| 1201 | // in a single compilation unit |
| 1202 | const xrefJavaSourceFileMaxDefault = "1000" |
| 1203 | |
| 1204 | func (c Config) XrefCuJavaSourceMax() string { |
| 1205 | v := c.Getenv("KYTHE_JAVA_SOURCE_BATCH_SIZE") |
| 1206 | if v == "" { |
| 1207 | return xrefJavaSourceFileMaxDefault |
| 1208 | } |
| 1209 | if _, err := strconv.ParseUint(v, 0, 0); err != nil { |
| 1210 | fmt.Fprintf(os.Stderr, |
| 1211 | "bad KYTHE_JAVA_SOURCE_BATCH_SIZE value: %s, will use %s", |
| 1212 | err, xrefJavaSourceFileMaxDefault) |
| 1213 | return xrefJavaSourceFileMaxDefault |
| 1214 | } |
| 1215 | return v |
| 1216 | |
| 1217 | } |
| 1218 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 1219 | func (c *config) EmitXrefRules() bool { |
| 1220 | return c.XrefCorpusName() != "" |
| 1221 | } |
| 1222 | |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 1223 | func (c *config) ClangTidy() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1224 | return Bool(c.productVariables.ClangTidy) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | func (c *config) TidyChecks() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1228 | if c.productVariables.TidyChecks == nil { |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 1229 | return "" |
| 1230 | } |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1231 | return *c.productVariables.TidyChecks |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
Colin Cross | 0f4e0d6 | 2016-07-27 10:56:55 -0700 | [diff] [blame] | 1234 | func (c *config) LibartImgHostBaseAddress() string { |
| 1235 | return "0x60000000" |
| 1236 | } |
| 1237 | |
| 1238 | func (c *config) LibartImgDeviceBaseAddress() string { |
Elliott Hughes | da3a071 | 2020-03-06 16:55:28 -0800 | [diff] [blame] | 1239 | return "0x70000000" |
Colin Cross | 0f4e0d6 | 2016-07-27 10:56:55 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
Hiroshi Yamauchi | e2a1063 | 2016-12-19 13:44:41 -0800 | [diff] [blame] | 1242 | func (c *config) ArtUseReadBarrier() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1243 | return Bool(c.productVariables.ArtUseReadBarrier) |
Hiroshi Yamauchi | e2a1063 | 2016-12-19 13:44:41 -0800 | [diff] [blame] | 1244 | } |
| 1245 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 1246 | // Enforce Runtime Resource Overlays for a module. RROs supersede static RROs, |
| 1247 | // but some modules still depend on it. |
| 1248 | // |
| 1249 | // More info: https://source.android.com/devices/architecture/rros |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 1250 | func (c *config) EnforceRROForModule(name string) bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1251 | enforceList := c.productVariables.EnforceRROTargets |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 1252 | |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1253 | if len(enforceList) > 0 { |
Yo Chiang | 4ebd06a | 2019-10-01 13:13:41 +0800 | [diff] [blame] | 1254 | if InList("*", enforceList) { |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 1255 | return true |
| 1256 | } |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1257 | return InList(name, enforceList) |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 1258 | } |
| 1259 | return false |
| 1260 | } |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 1261 | func (c *config) EnforceRROExcludedOverlay(path string) bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1262 | excluded := c.productVariables.EnforceRROExcludedOverlays |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1263 | if len(excluded) > 0 { |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 1264 | return HasAnyPrefix(path, excluded) |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 1265 | } |
| 1266 | return false |
| 1267 | } |
| 1268 | |
| 1269 | func (c *config) ExportedNamespaces() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1270 | return append([]string(nil), c.productVariables.NamespacesToExport...) |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
Sam Delmerico | 98a7329 | 2023-02-21 11:50:29 -0500 | [diff] [blame] | 1273 | func (c *config) SourceRootDirs() []string { |
| 1274 | return c.productVariables.SourceRootDirs |
| 1275 | } |
| 1276 | |
Spandan Das | c576383 | 2022-11-08 18:42:16 +0000 | [diff] [blame] | 1277 | func (c *config) IncludeTags() []string { |
| 1278 | return c.productVariables.IncludeTags |
| 1279 | } |
| 1280 | |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 1281 | func (c *config) HostStaticBinaries() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1282 | return Bool(c.productVariables.HostStaticBinaries) |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 1285 | func (c *config) UncompressPrivAppDex() bool { |
| 1286 | return Bool(c.productVariables.UncompressPrivAppDex) |
| 1287 | } |
| 1288 | |
| 1289 | func (c *config) ModulesLoadedByPrivilegedModules() []string { |
| 1290 | return c.productVariables.ModulesLoadedByPrivilegedModules |
| 1291 | } |
| 1292 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 1293 | // DexpreoptGlobalConfigPath returns the path to the dexpreopt.config file in |
| 1294 | // the output directory, if it was created during the product configuration |
| 1295 | // phase by Kati. |
Jingwen Chen | ebb0b57 | 2020-11-02 00:24:57 -0500 | [diff] [blame] | 1296 | func (c *config) DexpreoptGlobalConfigPath(ctx PathContext) OptionalPath { |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 1297 | if c.productVariables.DexpreoptGlobalConfig == nil { |
Jingwen Chen | ebb0b57 | 2020-11-02 00:24:57 -0500 | [diff] [blame] | 1298 | return OptionalPathForPath(nil) |
| 1299 | } |
| 1300 | return OptionalPathForPath( |
| 1301 | pathForBuildToolDep(ctx, *c.productVariables.DexpreoptGlobalConfig)) |
| 1302 | } |
| 1303 | |
Jingwen Chen | c711fec | 2020-11-22 23:52:50 -0500 | [diff] [blame] | 1304 | // DexpreoptGlobalConfig returns the raw byte contents of the dexpreopt global |
| 1305 | // configuration. Since the configuration file was created by Kati during |
| 1306 | // product configuration (externally of soong_build), it's not tracked, so we |
| 1307 | // also manually add a Ninja file dependency on the configuration file to the |
| 1308 | // rule that creates the main build.ninja file. This ensures that build.ninja is |
| 1309 | // regenerated correctly if dexpreopt.config changes. |
Jingwen Chen | ebb0b57 | 2020-11-02 00:24:57 -0500 | [diff] [blame] | 1310 | func (c *config) DexpreoptGlobalConfig(ctx PathContext) ([]byte, error) { |
| 1311 | path := c.DexpreoptGlobalConfigPath(ctx) |
| 1312 | if !path.Valid() { |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 1313 | return nil, nil |
| 1314 | } |
Jingwen Chen | ebb0b57 | 2020-11-02 00:24:57 -0500 | [diff] [blame] | 1315 | ctx.AddNinjaFileDeps(path.String()) |
Sasha Smundak | af5ca92 | 2022-12-12 21:23:34 -0800 | [diff] [blame] | 1316 | return os.ReadFile(absolutePath(path.String())) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1317 | } |
| 1318 | |
Inseob Kim | 7b85eeb | 2021-03-23 20:52:24 +0900 | [diff] [blame] | 1319 | func (c *deviceConfig) WithDexpreopt() bool { |
| 1320 | return c.config.productVariables.WithDexpreopt |
| 1321 | } |
| 1322 | |
Colin Cross | 662d614 | 2022-11-03 20:38:01 -0700 | [diff] [blame] | 1323 | func (c *config) FrameworksBaseDirExists(ctx PathGlobContext) bool { |
Colin Cross | 5a756a6 | 2021-03-16 16:34:46 -0700 | [diff] [blame] | 1324 | return ExistentPathForSource(ctx, "frameworks", "base", "Android.bp").Valid() |
David Brazdil | 91b4e3e | 2019-01-23 21:04:05 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 1327 | func (c *config) VndkSnapshotBuildArtifacts() bool { |
| 1328 | return Bool(c.productVariables.VndkSnapshotBuildArtifacts) |
| 1329 | } |
| 1330 | |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1331 | func (c *config) HasMultilibConflict(arch ArchType) bool { |
| 1332 | return c.multilibConflicts[arch] |
| 1333 | } |
| 1334 | |
Sasha Smundak | af5ca92 | 2022-12-12 21:23:34 -0800 | [diff] [blame] | 1335 | func (c *config) PrebuiltHiddenApiDir(_ PathContext) string { |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 1336 | return String(c.productVariables.PrebuiltHiddenApiDir) |
| 1337 | } |
| 1338 | |
Kiyoung Kim | e623c58 | 2023-07-06 16:43:44 +0900 | [diff] [blame] | 1339 | func (c *config) IsVndkDeprecated() bool { |
| 1340 | return !Bool(c.productVariables.KeepVndk) |
| 1341 | } |
| 1342 | |
Justin Yun | 41cbb5e | 2023-11-29 17:58:16 +0900 | [diff] [blame] | 1343 | func (c *config) VendorApiLevel() string { |
| 1344 | return String(c.productVariables.VendorApiLevel) |
| 1345 | } |
| 1346 | |
Hsin-Yi Chen | 2c4a977 | 2024-02-05 17:37:27 +0800 | [diff] [blame] | 1347 | func (c *config) PrevVendorApiLevel() string { |
| 1348 | vendorApiLevel, err := strconv.Atoi(c.VendorApiLevel()) |
| 1349 | if err != nil { |
| 1350 | panic(fmt.Errorf("Cannot parse vendor API level %s to an integer: %s", |
| 1351 | c.VendorApiLevel(), err)) |
| 1352 | } |
| 1353 | if vendorApiLevel < 202404 || vendorApiLevel%100 != 4 { |
| 1354 | panic("Unknown vendor API level " + c.VendorApiLevel()) |
| 1355 | } |
| 1356 | // The version before trunk stable is 34. |
| 1357 | if vendorApiLevel == 202404 { |
| 1358 | return "34" |
| 1359 | } |
| 1360 | return strconv.Itoa(vendorApiLevel - 100) |
| 1361 | } |
| 1362 | |
Yi-Yo Chiang | 88960aa | 2024-01-19 15:02:29 +0800 | [diff] [blame] | 1363 | func (c *config) VendorApiLevelFrozen() bool { |
| 1364 | return c.productVariables.GetBuildFlagBool("RELEASE_BOARD_API_LEVEL_FROZEN") |
| 1365 | } |
| 1366 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 1367 | func (c *deviceConfig) Arches() []Arch { |
| 1368 | var arches []Arch |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1369 | for _, target := range c.config.Targets[Android] { |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 1370 | arches = append(arches, target.Arch) |
| 1371 | } |
| 1372 | return arches |
| 1373 | } |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 1374 | |
Jayant Chowdhary | 34ce67d | 2018-03-08 11:00:50 -0800 | [diff] [blame] | 1375 | func (c *deviceConfig) BinderBitness() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1376 | is32BitBinder := c.config.productVariables.Binder32bit |
Jayant Chowdhary | 34ce67d | 2018-03-08 11:00:50 -0800 | [diff] [blame] | 1377 | if is32BitBinder != nil && *is32BitBinder { |
| 1378 | return "32" |
| 1379 | } |
| 1380 | return "64" |
| 1381 | } |
| 1382 | |
Dan Willemsen | 4353bc4 | 2016-12-05 17:16:02 -0800 | [diff] [blame] | 1383 | func (c *deviceConfig) VendorPath() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1384 | if c.config.productVariables.VendorPath != nil { |
| 1385 | return *c.config.productVariables.VendorPath |
Dan Willemsen | 4353bc4 | 2016-12-05 17:16:02 -0800 | [diff] [blame] | 1386 | } |
| 1387 | return "vendor" |
| 1388 | } |
| 1389 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 1390 | func (c *deviceConfig) VndkVersion() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1391 | return String(c.config.productVariables.DeviceVndkVersion) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 1392 | } |
| 1393 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 1394 | func (c *deviceConfig) RecoverySnapshotVersion() string { |
| 1395 | return String(c.config.productVariables.RecoverySnapshotVersion) |
| 1396 | } |
| 1397 | |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1398 | func (c *deviceConfig) CurrentApiLevelForVendorModules() string { |
| 1399 | return StringDefault(c.config.productVariables.DeviceCurrentApiLevelForVendorModules, "current") |
| 1400 | } |
| 1401 | |
Justin Yun | 8fe1212 | 2017-12-07 17:18:15 +0900 | [diff] [blame] | 1402 | func (c *deviceConfig) PlatformVndkVersion() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1403 | return String(c.config.productVariables.Platform_vndk_version) |
Justin Yun | 8fe1212 | 2017-12-07 17:18:15 +0900 | [diff] [blame] | 1404 | } |
| 1405 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 1406 | func (c *deviceConfig) ExtraVndkVersions() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1407 | return c.config.productVariables.ExtraVndkVersions |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 1408 | } |
Jack He | 8cc7143 | 2016-12-08 15:45:07 -0800 | [diff] [blame] | 1409 | |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 1410 | func (c *deviceConfig) VndkUseCoreVariant() bool { |
Kiyoung Kim | 03b6cba | 2023-10-06 14:12:43 +0900 | [diff] [blame] | 1411 | return Bool(c.config.productVariables.VndkUseCoreVariant) && Bool(c.config.productVariables.KeepVndk) |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 1412 | } |
| 1413 | |
Jiyong Park | 1a5d7b1 | 2018-01-15 15:05:10 +0900 | [diff] [blame] | 1414 | func (c *deviceConfig) SystemSdkVersions() []string { |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1415 | return c.config.productVariables.DeviceSystemSdkVersions |
Jiyong Park | 1a5d7b1 | 2018-01-15 15:05:10 +0900 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | func (c *deviceConfig) PlatformSystemSdkVersions() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1419 | return c.config.productVariables.Platform_systemsdk_versions |
Jiyong Park | 1a5d7b1 | 2018-01-15 15:05:10 +0900 | [diff] [blame] | 1420 | } |
| 1421 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1422 | func (c *deviceConfig) OdmPath() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1423 | if c.config.productVariables.OdmPath != nil { |
| 1424 | return *c.config.productVariables.OdmPath |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1425 | } |
| 1426 | return "odm" |
| 1427 | } |
| 1428 | |
Jaekyun Seok | 5cfbfbb | 2018-01-10 19:00:15 +0900 | [diff] [blame] | 1429 | func (c *deviceConfig) ProductPath() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1430 | if c.config.productVariables.ProductPath != nil { |
| 1431 | return *c.config.productVariables.ProductPath |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1432 | } |
Jaekyun Seok | 5cfbfbb | 2018-01-10 19:00:15 +0900 | [diff] [blame] | 1433 | return "product" |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1434 | } |
| 1435 | |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1436 | func (c *deviceConfig) SystemExtPath() string { |
| 1437 | if c.config.productVariables.SystemExtPath != nil { |
| 1438 | return *c.config.productVariables.SystemExtPath |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1439 | } |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1440 | return "system_ext" |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1441 | } |
| 1442 | |
Jack He | 8cc7143 | 2016-12-08 15:45:07 -0800 | [diff] [blame] | 1443 | func (c *deviceConfig) BtConfigIncludeDir() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1444 | return String(c.config.productVariables.BtConfigIncludeDir) |
Jack He | 8cc7143 | 2016-12-08 15:45:07 -0800 | [diff] [blame] | 1445 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1446 | |
Jiyong Park | d773eb3 | 2017-07-03 13:18:12 +0900 | [diff] [blame] | 1447 | func (c *deviceConfig) DeviceKernelHeaderDirs() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1448 | return c.config.productVariables.DeviceKernelHeaders |
Jiyong Park | d773eb3 | 2017-07-03 13:18:12 +0900 | [diff] [blame] | 1449 | } |
| 1450 | |
Roland Levillain | ada1270 | 2020-06-09 13:07:36 +0100 | [diff] [blame] | 1451 | // JavaCoverageEnabledForPath returns whether Java code coverage is enabled for |
| 1452 | // path. Coverage is enabled by default when the product variable |
| 1453 | // JavaCoveragePaths is empty. If JavaCoveragePaths is not empty, coverage is |
| 1454 | // enabled for any path which is part of this variable (and not part of the |
| 1455 | // JavaCoverageExcludePaths product variable). Value "*" in JavaCoveragePaths |
| 1456 | // represents any path. |
| 1457 | func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool { |
| 1458 | coverage := false |
Chris Gross | 2f74869 | 2020-06-24 20:36:59 +0000 | [diff] [blame] | 1459 | if len(c.config.productVariables.JavaCoveragePaths) == 0 || |
Roland Levillain | ada1270 | 2020-06-09 13:07:36 +0100 | [diff] [blame] | 1460 | InList("*", c.config.productVariables.JavaCoveragePaths) || |
| 1461 | HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) { |
| 1462 | coverage = true |
| 1463 | } |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1464 | if coverage && len(c.config.productVariables.JavaCoverageExcludePaths) > 0 { |
Roland Levillain | ada1270 | 2020-06-09 13:07:36 +0100 | [diff] [blame] | 1465 | if HasAnyPrefix(path, c.config.productVariables.JavaCoverageExcludePaths) { |
| 1466 | coverage = false |
| 1467 | } |
| 1468 | } |
| 1469 | return coverage |
| 1470 | } |
| 1471 | |
Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 1472 | // Returns true if gcov or clang coverage is enabled. |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1473 | func (c *deviceConfig) NativeCoverageEnabled() bool { |
Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 1474 | return Bool(c.config.productVariables.GcovCoverage) || |
| 1475 | Bool(c.config.productVariables.ClangCoverage) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1476 | } |
| 1477 | |
Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 1478 | func (c *deviceConfig) ClangCoverageEnabled() bool { |
| 1479 | return Bool(c.config.productVariables.ClangCoverage) |
| 1480 | } |
| 1481 | |
Pirama Arumuga Nainar | b37ae58 | 2022-01-26 22:14:32 -0800 | [diff] [blame] | 1482 | func (c *deviceConfig) ClangCoverageContinuousMode() bool { |
| 1483 | return Bool(c.config.productVariables.ClangCoverageContinuousMode) |
| 1484 | } |
| 1485 | |
Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 1486 | func (c *deviceConfig) GcovCoverageEnabled() bool { |
| 1487 | return Bool(c.config.productVariables.GcovCoverage) |
| 1488 | } |
| 1489 | |
Roland Levillain | 4f5297b | 2020-06-09 12:44:06 +0100 | [diff] [blame] | 1490 | // NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native |
| 1491 | // code coverage is enabled for path. By default, coverage is not enabled for a |
| 1492 | // given path unless it is part of the NativeCoveragePaths product variable (and |
| 1493 | // not part of the NativeCoverageExcludePaths product variable). Value "*" in |
| 1494 | // NativeCoveragePaths represents any path. |
| 1495 | func (c *deviceConfig) NativeCoverageEnabledForPath(path string) bool { |
Ryan Campbell | 469a18a | 2017-02-27 09:01:54 -0800 | [diff] [blame] | 1496 | coverage := false |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1497 | if len(c.config.productVariables.NativeCoveragePaths) > 0 { |
Roland Levillain | 4f5297b | 2020-06-09 12:44:06 +0100 | [diff] [blame] | 1498 | if InList("*", c.config.productVariables.NativeCoveragePaths) || HasAnyPrefix(path, c.config.productVariables.NativeCoveragePaths) { |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 1499 | coverage = true |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1500 | } |
| 1501 | } |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1502 | if coverage && len(c.config.productVariables.NativeCoverageExcludePaths) > 0 { |
Yi Kong | fd07ed2 | 2023-02-16 17:42:27 +0900 | [diff] [blame] | 1503 | // Workaround coverage boot failure. |
| 1504 | // http://b/269981180 |
| 1505 | if strings.HasPrefix(path, "external/protobuf") { |
| 1506 | coverage = false |
| 1507 | } |
Roland Levillain | 4f5297b | 2020-06-09 12:44:06 +0100 | [diff] [blame] | 1508 | if HasAnyPrefix(path, c.config.productVariables.NativeCoverageExcludePaths) { |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 1509 | coverage = false |
Ryan Campbell | 469a18a | 2017-02-27 09:01:54 -0800 | [diff] [blame] | 1510 | } |
| 1511 | } |
| 1512 | return coverage |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1513 | } |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 1514 | |
Pirama Arumuga Nainar | 4954080 | 2018-01-29 23:11:42 -0800 | [diff] [blame] | 1515 | func (c *deviceConfig) PgoAdditionalProfileDirs() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1516 | return c.config.productVariables.PgoAdditionalProfileDirs |
Pirama Arumuga Nainar | 4954080 | 2018-01-29 23:11:42 -0800 | [diff] [blame] | 1517 | } |
| 1518 | |
Vinh Tran | 44cb78c | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 1519 | // AfdoProfile returns fully qualified path associated to the given module name |
Colin Cross | d38feb0 | 2024-01-23 16:38:06 -0800 | [diff] [blame] | 1520 | func (c *deviceConfig) AfdoProfile(name string) (string, error) { |
Vinh Tran | 44cb78c | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 1521 | for _, afdoProfile := range c.config.productVariables.AfdoProfiles { |
| 1522 | split := strings.Split(afdoProfile, ":") |
| 1523 | if len(split) != 3 { |
Colin Cross | d38feb0 | 2024-01-23 16:38:06 -0800 | [diff] [blame] | 1524 | return "", fmt.Errorf("AFDO_PROFILES has invalid value: %s. "+ |
Vinh Tran | 44cb78c | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 1525 | "The expected format is <module>:<fully-qualified-path-to-fdo_profile>", afdoProfile) |
| 1526 | } |
| 1527 | if split[0] == name { |
Colin Cross | d38feb0 | 2024-01-23 16:38:06 -0800 | [diff] [blame] | 1528 | return strings.Join([]string{split[1], split[2]}, ":"), nil |
Vinh Tran | 44cb78c | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 1529 | } |
| 1530 | } |
Colin Cross | d38feb0 | 2024-01-23 16:38:06 -0800 | [diff] [blame] | 1531 | return "", nil |
Vinh Tran | 44cb78c | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 1532 | } |
| 1533 | |
Tri Vo | 35a5143 | 2018-03-25 20:00:00 -0700 | [diff] [blame] | 1534 | func (c *deviceConfig) VendorSepolicyDirs() []string { |
| 1535 | return c.config.productVariables.BoardVendorSepolicyDirs |
| 1536 | } |
| 1537 | |
| 1538 | func (c *deviceConfig) OdmSepolicyDirs() []string { |
| 1539 | return c.config.productVariables.BoardOdmSepolicyDirs |
| 1540 | } |
| 1541 | |
Felix | a20a875 | 2020-05-17 18:28:35 +0200 | [diff] [blame] | 1542 | func (c *deviceConfig) SystemExtPublicSepolicyDirs() []string { |
| 1543 | return c.config.productVariables.SystemExtPublicSepolicyDirs |
Tri Vo | 35a5143 | 2018-03-25 20:00:00 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Felix | a20a875 | 2020-05-17 18:28:35 +0200 | [diff] [blame] | 1546 | func (c *deviceConfig) SystemExtPrivateSepolicyDirs() []string { |
| 1547 | return c.config.productVariables.SystemExtPrivateSepolicyDirs |
Tri Vo | 35a5143 | 2018-03-25 20:00:00 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
Inseob Kim | 0866b00 | 2019-04-15 20:21:29 +0900 | [diff] [blame] | 1550 | func (c *deviceConfig) SepolicyM4Defs() []string { |
| 1551 | return c.config.productVariables.BoardSepolicyM4Defs |
| 1552 | } |
| 1553 | |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 1554 | func (c *deviceConfig) OverrideManifestPackageNameFor(name string) (manifestName string, overridden bool) { |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1555 | return findOverrideValue(c.config.productVariables.ManifestPackageNameOverrides, name, |
| 1556 | "invalid override rule %q in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES should be <module_name>:<manifest_name>") |
| 1557 | } |
| 1558 | |
| 1559 | func (c *deviceConfig) OverrideCertificateFor(name string) (certificatePath string, overridden bool) { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 1560 | return findOverrideValue(c.config.productVariables.CertificateOverrides, name, |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1561 | "invalid override rule %q in PRODUCT_CERTIFICATE_OVERRIDES should be <module_name>:<certificate_module_name>") |
| 1562 | } |
| 1563 | |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1564 | func (c *deviceConfig) OverridePackageNameFor(name string) string { |
| 1565 | newName, overridden := findOverrideValue( |
| 1566 | c.config.productVariables.PackageNameOverrides, |
| 1567 | name, |
| 1568 | "invalid override rule %q in PRODUCT_PACKAGE_NAME_OVERRIDES should be <module_name>:<package_name>") |
| 1569 | if overridden { |
| 1570 | return newName |
| 1571 | } |
| 1572 | return name |
| 1573 | } |
| 1574 | |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1575 | func findOverrideValue(overrides []string, name string, errorMsg string) (newValue string, overridden bool) { |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 1576 | if overrides == nil || len(overrides) == 0 { |
| 1577 | return "", false |
| 1578 | } |
| 1579 | for _, o := range overrides { |
| 1580 | split := strings.Split(o, ":") |
| 1581 | if len(split) != 2 { |
| 1582 | // This shouldn't happen as this is first checked in make, but just in case. |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1583 | panic(fmt.Errorf(errorMsg, o)) |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 1584 | } |
| 1585 | if matchPattern(split[0], name) { |
| 1586 | return substPattern(split[0], split[1], name), true |
| 1587 | } |
| 1588 | } |
| 1589 | return "", false |
| 1590 | } |
| 1591 | |
Albert Martin | eefabcf | 2022-03-21 20:11:16 +0000 | [diff] [blame] | 1592 | func (c *deviceConfig) ApexGlobalMinSdkVersionOverride() string { |
| 1593 | return String(c.config.productVariables.ApexGlobalMinSdkVersionOverride) |
| 1594 | } |
| 1595 | |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 1596 | func (c *config) IntegerOverflowDisabledForPath(path string) bool { |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1597 | if len(c.productVariables.IntegerOverflowExcludePaths) == 0 { |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 1598 | return false |
| 1599 | } |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 1600 | return HasAnyPrefix(path, c.productVariables.IntegerOverflowExcludePaths) |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 1601 | } |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 1602 | |
| 1603 | func (c *config) CFIDisabledForPath(path string) bool { |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1604 | if len(c.productVariables.CFIExcludePaths) == 0 { |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 1605 | return false |
| 1606 | } |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 1607 | return HasAnyPrefix(path, c.productVariables.CFIExcludePaths) |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | func (c *config) CFIEnabledForPath(path string) bool { |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1611 | if len(c.productVariables.CFIIncludePaths) == 0 { |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 1612 | return false |
| 1613 | } |
Evgenii Stepanov | 779b64e | 2021-04-09 14:33:10 -0700 | [diff] [blame] | 1614 | return HasAnyPrefix(path, c.productVariables.CFIIncludePaths) && !c.CFIDisabledForPath(path) |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 1615 | } |
Colin Cross | e15ddaf | 2017-12-04 11:24:31 -0800 | [diff] [blame] | 1616 | |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 1617 | func (c *config) MemtagHeapDisabledForPath(path string) bool { |
| 1618 | if len(c.productVariables.MemtagHeapExcludePaths) == 0 { |
| 1619 | return false |
| 1620 | } |
| 1621 | return HasAnyPrefix(path, c.productVariables.MemtagHeapExcludePaths) |
| 1622 | } |
| 1623 | |
| 1624 | func (c *config) MemtagHeapAsyncEnabledForPath(path string) bool { |
| 1625 | if len(c.productVariables.MemtagHeapAsyncIncludePaths) == 0 { |
| 1626 | return false |
| 1627 | } |
Evgenii Stepanov | 779b64e | 2021-04-09 14:33:10 -0700 | [diff] [blame] | 1628 | return HasAnyPrefix(path, c.productVariables.MemtagHeapAsyncIncludePaths) && !c.MemtagHeapDisabledForPath(path) |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | func (c *config) MemtagHeapSyncEnabledForPath(path string) bool { |
| 1632 | if len(c.productVariables.MemtagHeapSyncIncludePaths) == 0 { |
| 1633 | return false |
| 1634 | } |
Evgenii Stepanov | 779b64e | 2021-04-09 14:33:10 -0700 | [diff] [blame] | 1635 | return HasAnyPrefix(path, c.productVariables.MemtagHeapSyncIncludePaths) && !c.MemtagHeapDisabledForPath(path) |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 1636 | } |
| 1637 | |
Tomislav Novak | f734f00 | 2023-08-22 10:51:44 -0700 | [diff] [blame] | 1638 | func (c *config) HWASanDisabledForPath(path string) bool { |
| 1639 | if len(c.productVariables.HWASanExcludePaths) == 0 { |
| 1640 | return false |
| 1641 | } |
| 1642 | return HasAnyPrefix(path, c.productVariables.HWASanExcludePaths) |
| 1643 | } |
| 1644 | |
Hang Lu | a98aab9 | 2023-03-17 13:17:22 +0800 | [diff] [blame] | 1645 | func (c *config) HWASanEnabledForPath(path string) bool { |
| 1646 | if len(c.productVariables.HWASanIncludePaths) == 0 { |
| 1647 | return false |
| 1648 | } |
Tomislav Novak | f734f00 | 2023-08-22 10:51:44 -0700 | [diff] [blame] | 1649 | return HasAnyPrefix(path, c.productVariables.HWASanIncludePaths) && !c.HWASanDisabledForPath(path) |
Hang Lu | a98aab9 | 2023-03-17 13:17:22 +0800 | [diff] [blame] | 1650 | } |
| 1651 | |
Dan Willemsen | 0fe7866 | 2018-03-26 12:41:18 -0700 | [diff] [blame] | 1652 | func (c *config) VendorConfig(name string) VendorConfig { |
Colin Cross | 9d34f35 | 2019-11-22 16:03:51 -0800 | [diff] [blame] | 1653 | return soongconfig.Config(c.productVariables.VendorVars[name]) |
Dan Willemsen | 0fe7866 | 2018-03-26 12:41:18 -0700 | [diff] [blame] | 1654 | } |
| 1655 | |
Colin Cross | 395f2cf | 2018-10-24 16:10:32 -0700 | [diff] [blame] | 1656 | func (c *config) NdkAbis() bool { |
| 1657 | return Bool(c.productVariables.Ndk_abis) |
| 1658 | } |
| 1659 | |
Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 1660 | func (c *config) AmlAbis() bool { |
| 1661 | return Bool(c.productVariables.Aml_abis) |
| 1662 | } |
| 1663 | |
Jiyong Park | 4da0797 | 2021-01-05 21:01:11 +0900 | [diff] [blame] | 1664 | func (c *config) ForceApexSymlinkOptimization() bool { |
| 1665 | return Bool(c.productVariables.ForceApexSymlinkOptimization) |
| 1666 | } |
| 1667 | |
Sasha Smundak | fe9a5b8 | 2022-07-27 14:51:45 -0700 | [diff] [blame] | 1668 | func (c *config) ApexCompressionEnabled() bool { |
| 1669 | return Bool(c.productVariables.CompressedApex) && !c.UnbundledBuildApps() |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
Dennis Shen | e2ed70c | 2023-01-11 14:15:43 +0000 | [diff] [blame] | 1672 | func (c *config) ApexTrimEnabled() bool { |
| 1673 | return Bool(c.productVariables.TrimmedApex) |
| 1674 | } |
| 1675 | |
Jeongik Cha | c946414 | 2019-01-07 12:07:27 +0900 | [diff] [blame] | 1676 | func (c *config) EnforceSystemCertificate() bool { |
| 1677 | return Bool(c.productVariables.EnforceSystemCertificate) |
| 1678 | } |
| 1679 | |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 1680 | func (c *config) EnforceSystemCertificateAllowList() []string { |
| 1681 | return c.productVariables.EnforceSystemCertificateAllowList |
Jeongik Cha | c946414 | 2019-01-07 12:07:27 +0900 | [diff] [blame] | 1682 | } |
| 1683 | |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1684 | func (c *config) EnforceProductPartitionInterface() bool { |
| 1685 | return Bool(c.productVariables.EnforceProductPartitionInterface) |
| 1686 | } |
| 1687 | |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 1688 | func (c *config) EnforceInterPartitionJavaSdkLibrary() bool { |
| 1689 | return Bool(c.productVariables.EnforceInterPartitionJavaSdkLibrary) |
| 1690 | } |
| 1691 | |
| 1692 | func (c *config) InterPartitionJavaLibraryAllowList() []string { |
| 1693 | return c.productVariables.InterPartitionJavaLibraryAllowList |
| 1694 | } |
| 1695 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 1696 | func (c *config) ProductHiddenAPIStubs() []string { |
| 1697 | return c.productVariables.ProductHiddenAPIStubs |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1698 | } |
| 1699 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 1700 | func (c *config) ProductHiddenAPIStubsSystem() []string { |
| 1701 | return c.productVariables.ProductHiddenAPIStubsSystem |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1702 | } |
| 1703 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 1704 | func (c *config) ProductHiddenAPIStubsTest() []string { |
| 1705 | return c.productVariables.ProductHiddenAPIStubsTest |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1706 | } |
Dan Willemsen | 71c7460 | 2019-04-10 12:27:35 -0700 | [diff] [blame] | 1707 | |
Dan Willemsen | 54879d1 | 2019-04-18 10:08:46 -0700 | [diff] [blame] | 1708 | func (c *deviceConfig) TargetFSConfigGen() []string { |
Dan Willemsen | 71c7460 | 2019-04-10 12:27:35 -0700 | [diff] [blame] | 1709 | return c.config.productVariables.TargetFSConfigGen |
| 1710 | } |
Inseob Kim | 0866b00 | 2019-04-15 20:21:29 +0900 | [diff] [blame] | 1711 | |
| 1712 | func (c *config) ProductPublicSepolicyDirs() []string { |
| 1713 | return c.productVariables.ProductPublicSepolicyDirs |
| 1714 | } |
| 1715 | |
| 1716 | func (c *config) ProductPrivateSepolicyDirs() []string { |
| 1717 | return c.productVariables.ProductPrivateSepolicyDirs |
| 1718 | } |
| 1719 | |
Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 1720 | func (c *config) TargetMultitreeUpdateMeta() bool { |
| 1721 | return c.productVariables.MultitreeUpdateMeta |
| 1722 | } |
| 1723 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 1724 | func (c *deviceConfig) DeviceArch() string { |
| 1725 | return String(c.config.productVariables.DeviceArch) |
| 1726 | } |
| 1727 | |
| 1728 | func (c *deviceConfig) DeviceArchVariant() string { |
| 1729 | return String(c.config.productVariables.DeviceArchVariant) |
| 1730 | } |
| 1731 | |
| 1732 | func (c *deviceConfig) DeviceSecondaryArch() string { |
| 1733 | return String(c.config.productVariables.DeviceSecondaryArch) |
| 1734 | } |
| 1735 | |
| 1736 | func (c *deviceConfig) DeviceSecondaryArchVariant() string { |
| 1737 | return String(c.config.productVariables.DeviceSecondaryArchVariant) |
| 1738 | } |
Yifan Hong | 82db735 | 2020-01-21 16:12:26 -0800 | [diff] [blame] | 1739 | |
| 1740 | func (c *deviceConfig) BoardUsesRecoveryAsBoot() bool { |
| 1741 | return Bool(c.config.productVariables.BoardUsesRecoveryAsBoot) |
| 1742 | } |
Yifan Hong | 97365ee | 2020-07-29 09:51:57 -0700 | [diff] [blame] | 1743 | |
| 1744 | func (c *deviceConfig) BoardKernelBinaries() []string { |
| 1745 | return c.config.productVariables.BoardKernelBinaries |
| 1746 | } |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1747 | |
Yifan Hong | 42bef8d | 2020-08-05 14:36:09 -0700 | [diff] [blame] | 1748 | func (c *deviceConfig) BoardKernelModuleInterfaceVersions() []string { |
| 1749 | return c.config.productVariables.BoardKernelModuleInterfaceVersions |
| 1750 | } |
| 1751 | |
Yifan Hong | dd8dacc | 2020-10-21 15:40:17 -0700 | [diff] [blame] | 1752 | func (c *deviceConfig) BoardMoveRecoveryResourcesToVendorBoot() bool { |
| 1753 | return Bool(c.config.productVariables.BoardMoveRecoveryResourcesToVendorBoot) |
| 1754 | } |
| 1755 | |
Inseob Kim | 16ebd5a | 2020-12-09 23:08:17 +0900 | [diff] [blame] | 1756 | func (c *deviceConfig) PlatformSepolicyVersion() string { |
| 1757 | return String(c.config.productVariables.PlatformSepolicyVersion) |
| 1758 | } |
| 1759 | |
Inseob Kim | 843f664 | 2022-01-07 09:11:23 +0900 | [diff] [blame] | 1760 | func (c *deviceConfig) PlatformSepolicyCompatVersions() []string { |
| 1761 | return c.config.productVariables.PlatformSepolicyCompatVersions |
| 1762 | } |
| 1763 | |
Inseob Kim | 16ebd5a | 2020-12-09 23:08:17 +0900 | [diff] [blame] | 1764 | func (c *deviceConfig) BoardSepolicyVers() string { |
Inseob Kim | 0c4eec8 | 2021-03-22 22:33:40 +0900 | [diff] [blame] | 1765 | if ver := String(c.config.productVariables.BoardSepolicyVers); ver != "" { |
| 1766 | return ver |
| 1767 | } |
| 1768 | return c.PlatformSepolicyVersion() |
Inseob Kim | 16ebd5a | 2020-12-09 23:08:17 +0900 | [diff] [blame] | 1769 | } |
| 1770 | |
Inseob Kim | 1a0afcc | 2022-02-14 23:10:51 +0900 | [diff] [blame] | 1771 | func (c *deviceConfig) SystemExtSepolicyPrebuiltApiDir() string { |
| 1772 | return String(c.config.productVariables.SystemExtSepolicyPrebuiltApiDir) |
| 1773 | } |
| 1774 | |
| 1775 | func (c *deviceConfig) ProductSepolicyPrebuiltApiDir() string { |
| 1776 | return String(c.config.productVariables.ProductSepolicyPrebuiltApiDir) |
| 1777 | } |
| 1778 | |
| 1779 | func (c *deviceConfig) IsPartnerTrebleSepolicyTestEnabled() bool { |
| 1780 | return c.SystemExtSepolicyPrebuiltApiDir() != "" || c.ProductSepolicyPrebuiltApiDir() != "" |
| 1781 | } |
| 1782 | |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 1783 | func (c *deviceConfig) DirectedVendorSnapshot() bool { |
| 1784 | return c.config.productVariables.DirectedVendorSnapshot |
| 1785 | } |
| 1786 | |
| 1787 | func (c *deviceConfig) VendorSnapshotModules() map[string]bool { |
| 1788 | return c.config.productVariables.VendorSnapshotModules |
| 1789 | } |
| 1790 | |
Jose Galmes | 4c6895e | 2021-02-09 07:44:30 -0800 | [diff] [blame] | 1791 | func (c *deviceConfig) DirectedRecoverySnapshot() bool { |
| 1792 | return c.config.productVariables.DirectedRecoverySnapshot |
| 1793 | } |
| 1794 | |
| 1795 | func (c *deviceConfig) RecoverySnapshotModules() map[string]bool { |
| 1796 | return c.config.productVariables.RecoverySnapshotModules |
| 1797 | } |
| 1798 | |
Justin DeMartino | 383bfb3 | 2021-02-24 10:49:43 -0800 | [diff] [blame] | 1799 | func createDirsMap(previous map[string]bool, dirs []string) (map[string]bool, error) { |
| 1800 | var ret = make(map[string]bool) |
| 1801 | for _, dir := range dirs { |
| 1802 | clean := filepath.Clean(dir) |
| 1803 | if previous[clean] || ret[clean] { |
| 1804 | return nil, fmt.Errorf("Duplicate entry %s", dir) |
| 1805 | } |
| 1806 | ret[clean] = true |
| 1807 | } |
| 1808 | return ret, nil |
| 1809 | } |
| 1810 | |
| 1811 | func (c *deviceConfig) createDirsMapOnce(onceKey OnceKey, previous map[string]bool, dirs []string) map[string]bool { |
| 1812 | dirMap := c.Once(onceKey, func() interface{} { |
| 1813 | ret, err := createDirsMap(previous, dirs) |
| 1814 | if err != nil { |
| 1815 | panic(fmt.Errorf("%s: %w", onceKey.key, err)) |
| 1816 | } |
| 1817 | return ret |
| 1818 | }) |
| 1819 | if dirMap == nil { |
| 1820 | return nil |
| 1821 | } |
| 1822 | return dirMap.(map[string]bool) |
| 1823 | } |
| 1824 | |
| 1825 | var vendorSnapshotDirsExcludedKey = NewOnceKey("VendorSnapshotDirsExcludedMap") |
| 1826 | |
| 1827 | func (c *deviceConfig) VendorSnapshotDirsExcludedMap() map[string]bool { |
| 1828 | return c.createDirsMapOnce(vendorSnapshotDirsExcludedKey, nil, |
| 1829 | c.config.productVariables.VendorSnapshotDirsExcluded) |
| 1830 | } |
| 1831 | |
| 1832 | var vendorSnapshotDirsIncludedKey = NewOnceKey("VendorSnapshotDirsIncludedMap") |
| 1833 | |
| 1834 | func (c *deviceConfig) VendorSnapshotDirsIncludedMap() map[string]bool { |
| 1835 | excludedMap := c.VendorSnapshotDirsExcludedMap() |
| 1836 | return c.createDirsMapOnce(vendorSnapshotDirsIncludedKey, excludedMap, |
| 1837 | c.config.productVariables.VendorSnapshotDirsIncluded) |
| 1838 | } |
| 1839 | |
| 1840 | var recoverySnapshotDirsExcludedKey = NewOnceKey("RecoverySnapshotDirsExcludedMap") |
| 1841 | |
| 1842 | func (c *deviceConfig) RecoverySnapshotDirsExcludedMap() map[string]bool { |
| 1843 | return c.createDirsMapOnce(recoverySnapshotDirsExcludedKey, nil, |
| 1844 | c.config.productVariables.RecoverySnapshotDirsExcluded) |
| 1845 | } |
| 1846 | |
| 1847 | var recoverySnapshotDirsIncludedKey = NewOnceKey("RecoverySnapshotDirsIncludedMap") |
| 1848 | |
| 1849 | func (c *deviceConfig) RecoverySnapshotDirsIncludedMap() map[string]bool { |
| 1850 | excludedMap := c.RecoverySnapshotDirsExcludedMap() |
| 1851 | return c.createDirsMapOnce(recoverySnapshotDirsIncludedKey, excludedMap, |
| 1852 | c.config.productVariables.RecoverySnapshotDirsIncluded) |
| 1853 | } |
| 1854 | |
Rob Seymour | 925aa09 | 2021-08-10 20:42:03 +0000 | [diff] [blame] | 1855 | func (c *deviceConfig) HostFakeSnapshotEnabled() bool { |
| 1856 | return c.config.productVariables.HostFakeSnapshotEnabled |
| 1857 | } |
| 1858 | |
Inseob Kim | 60c32f0 | 2020-12-21 22:53:05 +0900 | [diff] [blame] | 1859 | func (c *deviceConfig) ShippingApiLevel() ApiLevel { |
| 1860 | if c.config.productVariables.ShippingApiLevel == nil { |
| 1861 | return NoneApiLevel |
| 1862 | } |
| 1863 | apiLevel, _ := strconv.Atoi(*c.config.productVariables.ShippingApiLevel) |
| 1864 | return uncheckedFinalApiLevel(apiLevel) |
| 1865 | } |
| 1866 | |
Liz Kammer | 33cc80e | 2023-05-18 18:20:28 +0000 | [diff] [blame] | 1867 | func (c *deviceConfig) BuildBrokenPluginValidation() []string { |
| 1868 | return c.config.productVariables.BuildBrokenPluginValidation |
| 1869 | } |
| 1870 | |
Alix Espino | ef47e54 | 2022-09-14 19:10:51 +0000 | [diff] [blame] | 1871 | func (c *deviceConfig) BuildBrokenClangAsFlags() bool { |
| 1872 | return c.config.productVariables.BuildBrokenClangAsFlags |
| 1873 | } |
| 1874 | |
| 1875 | func (c *deviceConfig) BuildBrokenClangCFlags() bool { |
| 1876 | return c.config.productVariables.BuildBrokenClangCFlags |
| 1877 | } |
| 1878 | |
Alix | b5f6d9e | 2022-04-20 23:00:58 +0000 | [diff] [blame] | 1879 | func (c *deviceConfig) BuildBrokenClangProperty() bool { |
| 1880 | return c.config.productVariables.BuildBrokenClangProperty |
| 1881 | } |
| 1882 | |
Inseob Kim | 67e5add19 | 2021-03-17 18:05:33 +0900 | [diff] [blame] | 1883 | func (c *deviceConfig) BuildBrokenEnforceSyspropOwner() bool { |
| 1884 | return c.config.productVariables.BuildBrokenEnforceSyspropOwner |
| 1885 | } |
| 1886 | |
| 1887 | func (c *deviceConfig) BuildBrokenTrebleSyspropNeverallow() bool { |
| 1888 | return c.config.productVariables.BuildBrokenTrebleSyspropNeverallow |
| 1889 | } |
| 1890 | |
Cole Faust | edc4c50 | 2022-09-09 19:39:25 -0700 | [diff] [blame] | 1891 | func (c *deviceConfig) BuildBrokenUsesSoongPython2Modules() bool { |
| 1892 | return c.config.productVariables.BuildBrokenUsesSoongPython2Modules |
| 1893 | } |
| 1894 | |
Hridya Valsaraju | 5a5c7d5 | 2021-04-02 16:45:24 -0700 | [diff] [blame] | 1895 | func (c *deviceConfig) BuildDebugfsRestrictionsEnabled() bool { |
| 1896 | return c.config.productVariables.BuildDebugfsRestrictionsEnabled |
| 1897 | } |
| 1898 | |
Inseob Kim | 0cac7b4 | 2021-02-03 18:16:46 +0900 | [diff] [blame] | 1899 | func (c *deviceConfig) BuildBrokenVendorPropertyNamespace() bool { |
| 1900 | return c.config.productVariables.BuildBrokenVendorPropertyNamespace |
| 1901 | } |
| 1902 | |
Liz Kammer | 619be46 | 2022-01-28 15:13:39 -0500 | [diff] [blame] | 1903 | func (c *deviceConfig) BuildBrokenInputDir(name string) bool { |
| 1904 | return InList(name, c.config.productVariables.BuildBrokenInputDirModules) |
| 1905 | } |
| 1906 | |
Jiyong Park | 3bb9924 | 2024-01-04 23:21:26 +0000 | [diff] [blame] | 1907 | func (c *deviceConfig) BuildBrokenDontCheckSystemSdk() bool { |
| 1908 | return c.config.productVariables.BuildBrokenDontCheckSystemSdk |
| 1909 | } |
| 1910 | |
Jiakai Zhang | 48203e3 | 2023-06-02 23:42:21 +0100 | [diff] [blame] | 1911 | func (c *config) BuildWarningBadOptionalUsesLibsAllowlist() []string { |
| 1912 | return c.productVariables.BuildWarningBadOptionalUsesLibsAllowlist |
| 1913 | } |
| 1914 | |
Yu Liu | 6a7940c | 2023-05-09 17:12:22 -0700 | [diff] [blame] | 1915 | func (c *deviceConfig) GenruleSandboxing() bool { |
| 1916 | return Bool(c.config.productVariables.GenruleSandboxing) |
Vinh Tran | 140d588 | 2022-06-10 14:23:27 -0400 | [diff] [blame] | 1917 | } |
| 1918 | |
Inseob Kim | 67e5add19 | 2021-03-17 18:05:33 +0900 | [diff] [blame] | 1919 | func (c *deviceConfig) RequiresInsecureExecmemForSwiftshader() bool { |
| 1920 | return c.config.productVariables.RequiresInsecureExecmemForSwiftshader |
| 1921 | } |
| 1922 | |
Devin Moore | c381e10 | 2023-07-06 22:03:58 +0000 | [diff] [blame] | 1923 | func (c *deviceConfig) Release_aidl_use_unfrozen() bool { |
| 1924 | return Bool(c.config.productVariables.Release_aidl_use_unfrozen) |
| 1925 | } |
| 1926 | |
Inseob Kim | 67e5add19 | 2021-03-17 18:05:33 +0900 | [diff] [blame] | 1927 | func (c *config) SelinuxIgnoreNeverallows() bool { |
| 1928 | return c.productVariables.SelinuxIgnoreNeverallows |
| 1929 | } |
| 1930 | |
Inseob Kim | a10ef27 | 2021-09-15 03:04:53 +0000 | [diff] [blame] | 1931 | func (c *deviceConfig) SepolicyFreezeTestExtraDirs() []string { |
| 1932 | return c.config.productVariables.SepolicyFreezeTestExtraDirs |
| 1933 | } |
| 1934 | |
| 1935 | func (c *deviceConfig) SepolicyFreezeTestExtraPrebuiltDirs() []string { |
| 1936 | return c.config.productVariables.SepolicyFreezeTestExtraPrebuiltDirs |
| 1937 | } |
| 1938 | |
Jiyong Park | d163d4d | 2021-10-12 16:47:43 +0900 | [diff] [blame] | 1939 | func (c *deviceConfig) GenerateAidlNdkPlatformBackend() bool { |
| 1940 | return c.config.productVariables.GenerateAidlNdkPlatformBackend |
| 1941 | } |
| 1942 | |
Christopher Ferris | 98f1022 | 2022-07-13 23:16:52 -0700 | [diff] [blame] | 1943 | func (c *config) IgnorePrefer32OnDevice() bool { |
| 1944 | return c.productVariables.IgnorePrefer32OnDevice |
| 1945 | } |
| 1946 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1947 | func (c *config) BootJars() []string { |
| 1948 | return c.Once(earlyBootJarsKey, func() interface{} { |
Paul Duffin | 69d1fb1 | 2020-10-23 21:14:20 +0100 | [diff] [blame] | 1949 | list := c.productVariables.BootJars.CopyOfJars() |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 1950 | return append(list, c.productVariables.ApexBootJars.CopyOfJars()...) |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1951 | }).([]string) |
| 1952 | } |
Paul Duffin | 9a89a2a | 2020-10-28 19:20:06 +0000 | [diff] [blame] | 1953 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 1954 | func (c *config) NonApexBootJars() ConfiguredJarList { |
Paul Duffin | 9a89a2a | 2020-10-28 19:20:06 +0000 | [diff] [blame] | 1955 | return c.productVariables.BootJars |
| 1956 | } |
| 1957 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 1958 | func (c *config) ApexBootJars() ConfiguredJarList { |
| 1959 | return c.productVariables.ApexBootJars |
Paul Duffin | 9a89a2a | 2020-10-28 19:20:06 +0000 | [diff] [blame] | 1960 | } |
Colin Cross | 77cdcfd | 2021-03-12 11:28:25 -0800 | [diff] [blame] | 1961 | |
| 1962 | func (c *config) RBEWrapper() string { |
| 1963 | return c.GetenvWithDefault("RBE_WRAPPER", remoteexec.DefaultWrapperPath) |
| 1964 | } |
Colin Cross | 9b698b6 | 2021-12-22 09:55:32 -0800 | [diff] [blame] | 1965 | |
| 1966 | // UseHostMusl returns true if the host target has been configured to build against musl libc. |
| 1967 | func (c *config) UseHostMusl() bool { |
| 1968 | return Bool(c.productVariables.HostMusl) |
| 1969 | } |
MarkDacek | ff851b8 | 2022-04-21 18:33:17 +0000 | [diff] [blame] | 1970 | |
Spandan Das | 9e93d3d | 2023-03-08 05:47:29 +0000 | [diff] [blame] | 1971 | // ApiSurfaces directory returns the source path inside the api_surfaces repo |
| 1972 | // (relative to workspace root). |
| 1973 | func (c *config) ApiSurfacesDir(s ApiSurface, version string) string { |
| 1974 | return filepath.Join( |
| 1975 | "build", |
| 1976 | "bazel", |
| 1977 | "api_surfaces", |
| 1978 | s.String(), |
| 1979 | version) |
| 1980 | } |
Jihoon Kang | 1bff034 | 2023-01-17 20:40:22 +0000 | [diff] [blame] | 1981 | |
Jihoon Kang | 1975d3e | 2023-10-16 23:24:11 +0000 | [diff] [blame] | 1982 | func (c *config) JavaCoverageEnabled() bool { |
| 1983 | return c.IsEnvTrue("EMMA_INSTRUMENT") || c.IsEnvTrue("EMMA_INSTRUMENT_STATIC") || c.IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") |
| 1984 | } |
| 1985 | |
Jihoon Kang | c1b04d6 | 2023-11-16 19:07:04 +0000 | [diff] [blame] | 1986 | func (c *deviceConfig) BuildFromSourceStub() bool { |
| 1987 | return Bool(c.config.productVariables.BuildFromSourceStub) |
| 1988 | } |
| 1989 | |
Jihoon Kang | 1bff034 | 2023-01-17 20:40:22 +0000 | [diff] [blame] | 1990 | func (c *config) BuildFromTextStub() bool { |
Jihoon Kang | 1975d3e | 2023-10-16 23:24:11 +0000 | [diff] [blame] | 1991 | // TODO: b/302320354 - Remove the coverage build specific logic once the |
| 1992 | // robust solution for handling native properties in from-text stub build |
| 1993 | // is implemented. |
Jihoon Kang | c1b04d6 | 2023-11-16 19:07:04 +0000 | [diff] [blame] | 1994 | return !c.buildFromSourceStub && |
| 1995 | !c.JavaCoverageEnabled() && |
| 1996 | !c.deviceConfig.BuildFromSourceStub() |
Jihoon Kang | 1bff034 | 2023-01-17 20:40:22 +0000 | [diff] [blame] | 1997 | } |
Spandan Das | 4deab28 | 2023-03-30 17:06:32 +0000 | [diff] [blame] | 1998 | |
| 1999 | func (c *config) SetBuildFromTextStub(b bool) { |
Jihoon Kang | 2a929ad | 2023-06-08 19:02:07 +0000 | [diff] [blame] | 2000 | c.buildFromSourceStub = !b |
Jihoon Kang | cbcad7c | 2023-06-01 22:31:52 +0000 | [diff] [blame] | 2001 | c.productVariables.Build_from_text_stub = boolPtr(b) |
Spandan Das | 4deab28 | 2023-03-30 17:06:32 +0000 | [diff] [blame] | 2002 | } |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2003 | |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2004 | func (c *config) SetApiLibraries(libs []string) { |
| 2005 | c.apiLibraries = make(map[string]struct{}) |
| 2006 | for _, lib := range libs { |
| 2007 | c.apiLibraries[lib] = struct{}{} |
| 2008 | } |
| 2009 | } |
| 2010 | |
| 2011 | func (c *config) GetApiLibraries() map[string]struct{} { |
| 2012 | return c.apiLibraries |
| 2013 | } |
Inseob Kim | 5bac3b6 | 2023-08-25 21:29:46 +0900 | [diff] [blame] | 2014 | |
| 2015 | func (c *deviceConfig) CheckVendorSeappViolations() bool { |
| 2016 | return Bool(c.config.productVariables.CheckVendorSeappViolations) |
| 2017 | } |
Jihoon Kang | cfbc407 | 2023-09-20 01:02:18 +0000 | [diff] [blame] | 2018 | |
Inseob Kim | e4e85d5 | 2023-10-25 23:53:58 +0900 | [diff] [blame] | 2019 | func (c *config) GetBuildFlag(name string) (string, bool) { |
| 2020 | val, ok := c.productVariables.BuildFlags[name] |
| 2021 | return val, ok |
| 2022 | } |
Spandan Das | e3fcb41 | 2023-10-26 20:48:02 +0000 | [diff] [blame] | 2023 | |
Colin Cross | 8f1b033 | 2024-01-25 13:39:06 -0800 | [diff] [blame] | 2024 | func (c *config) UseResourceProcessorByDefault() bool { |
| 2025 | return c.productVariables.GetBuildFlagBool("RELEASE_USE_RESOURCE_PROCESSOR_BY_DEFAULT") |
| 2026 | } |
| 2027 | |
Spandan Das | e3fcb41 | 2023-10-26 20:48:02 +0000 | [diff] [blame] | 2028 | var ( |
| 2029 | mainlineApexContributionBuildFlags = []string{ |
| 2030 | "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", |
| 2031 | "RELEASE_APEX_CONTRIBUTIONS_APPSEARCH", |
| 2032 | "RELEASE_APEX_CONTRIBUTIONS_ART", |
| 2033 | "RELEASE_APEX_CONTRIBUTIONS_BLUETOOTH", |
| 2034 | "RELEASE_APEX_CONTRIBUTIONS_CONFIGINFRASTRUCTURE", |
| 2035 | "RELEASE_APEX_CONTRIBUTIONS_CONNECTIVITY", |
| 2036 | "RELEASE_APEX_CONTRIBUTIONS_CONSCRYPT", |
| 2037 | "RELEASE_APEX_CONTRIBUTIONS_CRASHRECOVERY", |
| 2038 | "RELEASE_APEX_CONTRIBUTIONS_DEVICELOCK", |
| 2039 | "RELEASE_APEX_CONTRIBUTIONS_HEALTHFITNESS", |
| 2040 | "RELEASE_APEX_CONTRIBUTIONS_IPSEC", |
| 2041 | "RELEASE_APEX_CONTRIBUTIONS_MEDIA", |
| 2042 | "RELEASE_APEX_CONTRIBUTIONS_MEDIAPROVIDER", |
| 2043 | "RELEASE_APEX_CONTRIBUTIONS_ONDEVICEPERSONALIZATION", |
| 2044 | "RELEASE_APEX_CONTRIBUTIONS_PERMISSION", |
| 2045 | "RELEASE_APEX_CONTRIBUTIONS_REMOTEKEYPROVISIONING", |
| 2046 | "RELEASE_APEX_CONTRIBUTIONS_SCHEDULING", |
| 2047 | "RELEASE_APEX_CONTRIBUTIONS_SDKEXTENSIONS", |
| 2048 | "RELEASE_APEX_CONTRIBUTIONS_STATSD", |
| 2049 | "RELEASE_APEX_CONTRIBUTIONS_UWB", |
| 2050 | "RELEASE_APEX_CONTRIBUTIONS_WIFI", |
| 2051 | } |
| 2052 | ) |
| 2053 | |
| 2054 | // Returns the list of _selected_ apex_contributions |
| 2055 | // Each mainline module will have one entry in the list |
| 2056 | func (c *config) AllApexContributions() []string { |
| 2057 | ret := []string{} |
| 2058 | for _, f := range mainlineApexContributionBuildFlags { |
| 2059 | if val, exists := c.GetBuildFlag(f); exists && val != "" { |
| 2060 | ret = append(ret, val) |
| 2061 | } |
| 2062 | } |
| 2063 | return ret |
| 2064 | } |
Spandan Das | 8ab28dd | 2024-02-17 03:31:45 +0000 | [diff] [blame] | 2065 | |
| 2066 | func (c *config) BuildIgnoreApexContributionContents() []string { |
| 2067 | return c.productVariables.BuildIgnoreApexContributionContents |
| 2068 | } |