blob: ef8bb66691a352a54ba85275c5ab5b7c3a3f480f [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// 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 Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
Jingwen Chenc711fec2020-11-22 23:52:50 -050017// This is the primary location to write and read all configuration values and
18// product variables necessary for soong_build's operation.
19
Colin Cross3f40fa42015-01-30 17:27:36 -080020import (
Colin Cross31a67452023-11-02 16:57:08 -070021 "android/soong/shared"
Colin Cross3f40fa42015-01-30 17:27:36 -080022 "encoding/json"
23 "fmt"
24 "os"
Colin Cross35cec122015-04-02 14:37:16 -070025 "path/filepath"
Sam Delmerico5c32bbf2022-01-20 20:15:02 +000026 "reflect"
Colin Cross3f40fa42015-01-30 17:27:36 -080027 "runtime"
Inseob Kim60c32f02020-12-21 22:53:05 +090028 "strconv"
Dan Willemsen34cc69e2015-09-23 15:26:20 -070029 "strings"
Colin Crossc1e86a32015-04-15 12:33:28 -070030 "sync"
Colin Cross6ff51382015-12-17 16:39:19 -080031
Colin Cross98be1bb2019-12-13 20:41:13 -080032 "github.com/google/blueprint"
Colin Crosse87040b2017-12-11 15:52:26 -080033 "github.com/google/blueprint/bootstrap"
Colin Cross98be1bb2019-12-13 20:41:13 -080034 "github.com/google/blueprint/pathtools"
Colin Cross6ff51382015-12-17 16:39:19 -080035 "github.com/google/blueprint/proptools"
Colin Cross9d34f352019-11-22 16:03:51 -080036
37 "android/soong/android/soongconfig"
Liz Kammer09f947d2021-05-12 14:51:49 -040038 "android/soong/bazel"
Colin Cross77cdcfd2021-03-12 11:28:25 -080039 "android/soong/remoteexec"
Liz Kammer72beb342022-02-03 08:42:10 -050040 "android/soong/starlark_fmt"
Colin Cross3f40fa42015-01-30 17:27:36 -080041)
42
Jingwen Chenc711fec2020-11-22 23:52:50 -050043// Bool re-exports proptools.Bool for the android package.
Colin Cross6ff51382015-12-17 16:39:19 -080044var Bool = proptools.Bool
Jingwen Chenc711fec2020-11-22 23:52:50 -050045
46// String re-exports proptools.String for the android package.
Jack He8cc71432016-12-08 15:45:07 -080047var String = proptools.String
Jingwen Chenc711fec2020-11-22 23:52:50 -050048
49// StringDefault re-exports proptools.StringDefault for the android package.
Jeongik Cha219141c2020-08-06 23:00:37 +090050var StringDefault = proptools.StringDefault
Jiyong Park6a927c42020-01-21 02:03:43 +090051
Jingwen Chenc711fec2020-11-22 23:52:50 -050052// FutureApiLevelInt is a placeholder constant for unreleased API levels.
Dan Albert0b176c82020-07-23 16:43:25 -070053const FutureApiLevelInt = 10000
54
Spandan Das15da5882023-03-02 23:36:39 +000055// PrivateApiLevel represents the api level of SdkSpecPrivate (sdk_version: "")
56// This api_level exists to differentiate user-provided "" from "current" sdk_version
57// The differentiation is necessary to enable different validation rules for these two possible values.
58var PrivateApiLevel = ApiLevel{
59 value: "current", // The value is current since aidl expects `current` as the default (TestAidlFlagsWithMinSdkVersion)
60 number: FutureApiLevelInt + 1, // This is used to differentiate it from FutureApiLevel
61 isPreview: true,
62}
63
Jingwen Chenc711fec2020-11-22 23:52:50 -050064// FutureApiLevel represents unreleased API levels.
Dan Albert0b176c82020-07-23 16:43:25 -070065var FutureApiLevel = ApiLevel{
66 value: "current",
67 number: FutureApiLevelInt,
68 isPreview: true,
69}
Colin Cross6ff51382015-12-17 16:39:19 -080070
Jingwen Chenc4d91bc2020-11-24 22:59:26 -050071// The product variables file name, containing product config from Kati.
Dan Willemsen87b17d12015-07-14 00:39:06 -070072const productVariablesFileName = "soong.variables"
Colin Cross3f40fa42015-01-30 17:27:36 -080073
Colin Cross9272ade2016-08-17 15:24:12 -070074// A Config object represents the entire build configuration for Android.
Colin Crossc3c0a492015-04-10 15:43:55 -070075type Config struct {
76 *config
77}
78
Chris Parsonsad876012022-08-20 14:48:32 -040079type SoongBuildMode int
80
Sasha Smundakaf5ca922022-12-12 21:23:34 -080081type CmdArgs struct {
82 bootstrap.Args
Kiyoung Kima37d9ba2023-04-19 13:13:45 +090083 RunGoTests bool
84 OutDir string
85 SoongOutDir string
86 SoongVariables string
Sasha Smundakaf5ca922022-12-12 21:23:34 -080087
Colin Crossb63d7b32023-12-07 16:54:51 -080088 BazelQueryViewDir string
89 ModuleGraphFile string
90 ModuleActionsFile string
91 DocFile string
Sasha Smundakaf5ca922022-12-12 21:23:34 -080092
LaMont Jones52a72432023-03-09 18:19:35 +000093 MultitreeBuild bool
94
Jihoon Kang2a929ad2023-06-08 19:02:07 +000095 BuildFromSourceStub bool
MarkDacekf47e1422023-04-19 16:47:36 +000096
97 EnsureAllowlistIntegrity bool
Sasha Smundakaf5ca922022-12-12 21:23:34 -080098}
99
Chris Parsonsad876012022-08-20 14:48:32 -0400100// Build modes that soong_build can run as.
101const (
102 // Don't use bazel at all during module analysis.
103 AnalysisNoBazel SoongBuildMode = iota
104
Chris Parsonsad876012022-08-20 14:48:32 -0400105 // Generate BUILD files which faithfully represent the dependency graph of
106 // blueprint modules. Individual BUILD targets will not, however, faitfhully
107 // express build semantics.
108 GenerateQueryView
109
110 // Create a JSON representation of the module graph and exit.
111 GenerateModuleGraph
112
113 // Generate a documentation file for module type definitions and exit.
114 GenerateDocFile
Chris Parsonsad876012022-08-20 14:48:32 -0400115)
116
Lukacs T. Berkib078ade2021-08-31 10:42:08 +0200117// SoongOutDir returns the build output directory for the configuration.
Lukacs T. Berki9f6c24a2021-08-26 15:07:24 +0200118func (c Config) SoongOutDir() string {
119 return c.soongOutDir
Jeff Gastonefc1b412017-03-29 17:29:06 -0700120}
121
Colin Cross31a67452023-11-02 16:57:08 -0700122// tempDir returns the path to out/soong/.temp, which is cleared at the beginning of every build.
123func (c Config) tempDir() string {
124 return shared.TempDirForOutDir(c.soongOutDir)
125}
126
Lukacs T. Berki9f6c24a2021-08-26 15:07:24 +0200127func (c Config) OutDir() string {
Lukacs T. Berkid6cee7e2021-09-01 16:25:51 +0200128 return c.outDir
Lukacs T. Berki89e9a162021-03-12 08:31:32 +0100129}
130
Lukacs T. Berkiea1a31c2021-09-02 09:58:09 +0200131func (c Config) RunGoTests() bool {
132 return c.runGoTests
133}
134
Lukacs T. Berki5f6cb1d2021-03-17 15:03:14 +0100135func (c Config) DebugCompilation() bool {
136 return false // Never compile Go code in the main build for debugging
137}
138
Lukacs T. Berkiea1a31c2021-09-02 09:58:09 +0200139func (c Config) Subninjas() []string {
140 return []string{}
141}
142
143func (c Config) PrimaryBuilderInvocations() []bootstrap.PrimaryBuilderInvocation {
144 return []bootstrap.PrimaryBuilderInvocation{}
145}
146
Paul Duffin74135582022-10-06 11:01:59 +0100147// RunningInsideUnitTest returns true if this code is being run as part of a Soong unit test.
148func (c Config) RunningInsideUnitTest() bool {
149 return c.config.TestProductVariables != nil
150}
151
Pratyushfaec4db2023-07-20 11:19:04 +0000152// DisableHiddenApiChecks returns true if hiddenapi checks have been disabled.
Alyssa Ketpreechasawat7daf2782023-11-01 13:58:39 +0000153// For 'eng' target variant hiddenapi checks are disabled by default for performance optimisation,
Pratyushfaec4db2023-07-20 11:19:04 +0000154// but can be enabled by setting environment variable ENABLE_HIDDENAPI_FLAGS=true.
155// For other target variants hiddenapi check are enabled by default but can be disabled by
156// setting environment variable UNSAFE_DISABLE_HIDDENAPI_FLAGS=true.
157// If both ENABLE_HIDDENAPI_FLAGS=true and UNSAFE_DISABLE_HIDDENAPI_FLAGS=true, then
158// ENABLE_HIDDENAPI_FLAGS=true will be triggered and hiddenapi checks will be considered enabled.
159func (c Config) DisableHiddenApiChecks() bool {
160 return !c.IsEnvTrue("ENABLE_HIDDENAPI_FLAGS") &&
161 (c.IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") ||
Alyssa Ketpreechasawat7daf2782023-11-01 13:58:39 +0000162 Bool(c.productVariables.Eng))
163}
164
165// DisableVerifyOverlaps returns true if verify_overlaps is skipped.
166// Mismatch in version of apexes and module SDK is required for mainline prebuilts to work in
167// trunk stable.
168// Thus, verify_overlaps is disabled when RELEASE_DEFAULT_MODULE_BUILD_FROM_SOURCE is set to false.
169// TODO(b/308174018): Re-enable verify_overlaps for both builr from source/mainline prebuilts.
170func (c Config) DisableVerifyOverlaps() bool {
171 return c.IsEnvTrue("DISABLE_VERIFY_OVERLAPS") || !c.ReleaseDefaultModuleBuildFromSource()
Pratyushfaec4db2023-07-20 11:19:04 +0000172}
173
Juan Yescas05d4d902023-04-07 10:35:35 -0700174// MaxPageSizeSupported returns the max page size supported by the device. This
175// value will define the ELF segment alignment for binaries (executables and
176// shared libraries).
177func (c Config) MaxPageSizeSupported() string {
178 return String(c.config.productVariables.DeviceMaxPageSizeSupported)
179}
180
Vilas Bhatb3d2d222023-12-04 22:51:20 +0000181// NoBionicPageSizeMacro returns true when AOSP is page size agnostic.
182// This means that the bionic's macro PAGE_SIZE won't be defined.
183// Returns false when AOSP is NOT page size agnostic.
184// This means that bionic's macro PAGE_SIZE is defined.
185func (c Config) NoBionicPageSizeMacro() bool {
186 return Bool(c.config.productVariables.DeviceNoBionicPageSizeMacro)
Juan Yescas01065602023-08-09 08:34:37 -0700187}
188
Joe Onoratofee845a2023-05-09 08:14:14 -0700189// The release version passed to aconfig, derived from RELEASE_VERSION
190func (c Config) ReleaseVersion() string {
191 return c.config.productVariables.ReleaseVersion
192}
193
Yu Liu2cc802a2023-09-05 17:19:45 -0700194// The aconfig value set passed to aconfig, derived from RELEASE_VERSION
Yu Liueebb2592023-10-12 20:31:27 -0700195func (c Config) ReleaseAconfigValueSets() []string {
Yu Liu95572ff2023-12-07 16:38:45 -0800196 return c.config.productVariables.ReleaseAconfigValueSets
Joe Onoratofee845a2023-05-09 08:14:14 -0700197}
198
Zhi Dou3f65a412023-08-10 21:47:40 +0000199// The flag default permission value passed to aconfig
200// derived from RELEASE_ACONFIG_FLAG_DEFAULT_PERMISSION
201func (c Config) ReleaseAconfigFlagDefaultPermission() string {
202 return c.config.productVariables.ReleaseAconfigFlagDefaultPermission
203}
204
Alyssa Ketpreechasawat34ab8792023-10-06 07:01:22 +0000205// The flag indicating behavior for the tree wrt building modules or using prebuilts
206// derived from RELEASE_DEFAULT_MODULE_BUILD_FROM_SOURCE
207func (c Config) ReleaseDefaultModuleBuildFromSource() bool {
208 return c.config.productVariables.ReleaseDefaultModuleBuildFromSource == nil ||
209 Bool(c.config.productVariables.ReleaseDefaultModuleBuildFromSource)
210}
211
Aleksei Vetrov146e9822023-11-24 19:54:26 +0000212// Enables ABI monitoring of NDK libraries
213func (c Config) ReleaseNdkAbiMonitored() bool {
214 return c.config.productVariables.GetBuildFlagBool("RELEASE_NDK_ABI_MONITORED")
215}
216
Jihoon Kangbd093452023-12-26 19:08:01 +0000217func (c Config) ReleaseHiddenApiExportableStubs() bool {
218 return c.config.productVariables.GetBuildFlagBool("RELEASE_HIDDEN_API_EXPORTABLE_STUBS")
219}
220
Jingwen Chenc711fec2020-11-22 23:52:50 -0500221// A DeviceConfig object represents the configuration for a particular device
222// being built. For now there will only be one of these, but in the future there
223// may be multiple devices being built.
Colin Cross9272ade2016-08-17 15:24:12 -0700224type DeviceConfig struct {
225 *deviceConfig
226}
227
Jingwen Chenc711fec2020-11-22 23:52:50 -0500228// VendorConfig represents the configuration for vendor-specific behavior.
Colin Cross9d34f352019-11-22 16:03:51 -0800229type VendorConfig soongconfig.SoongConfig
Dan Willemsen0fe78662018-03-26 12:41:18 -0700230
Jingwen Chenc711fec2020-11-22 23:52:50 -0500231// Definition of general build configuration for soong_build. Some of these
Jingwen Chenc4d91bc2020-11-24 22:59:26 -0500232// product configuration values are read from Kati-generated soong.variables.
Colin Cross1332b002015-04-07 17:11:30 -0700233type config struct {
Jingwen Chenc711fec2020-11-22 23:52:50 -0500234 // Options configurable with soong.variables
Cole Faustf8231dd2023-04-21 17:37:11 -0700235 productVariables ProductVariables
Colin Cross3f40fa42015-01-30 17:27:36 -0800236
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700237 // Only available on configs created by TestConfig
Cole Faustf8231dd2023-04-21 17:37:11 -0700238 TestProductVariables *ProductVariables
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700239
Dan Willemsen87b17d12015-07-14 00:39:06 -0700240 ProductVariablesFileName string
241
Colin Cross0c66bc62021-07-20 09:47:41 -0700242 // BuildOS stores the OsType for the OS that the build is running on.
243 BuildOS OsType
244
245 // BuildArch stores the ArchType for the CPU that the build is running on.
246 BuildArch ArchType
247
Jaewoong Jung642916f2020-10-09 17:25:15 -0700248 Targets map[OsType][]Target
249 BuildOSTarget Target // the Target for tools run on the build machine
250 BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine
251 AndroidCommonTarget Target // the Target for common modules for the Android device
252 AndroidFirstDeviceTarget Target // the first Target for modules for the Android device
Dan Willemsen218f6562015-07-08 18:13:11 -0700253
Jingwen Chenc711fec2020-11-22 23:52:50 -0500254 // multilibConflicts for an ArchType is true if there is earlier configured
255 // device architecture with the same multilib value.
Colin Cross3b19f5d2019-09-17 14:45:31 -0700256 multilibConflicts map[ArchType]bool
257
Colin Cross9272ade2016-08-17 15:24:12 -0700258 deviceConfig *deviceConfig
259
Lukacs T. Berkid6cee7e2021-09-01 16:25:51 +0200260 outDir string // The output directory (usually out/)
261 soongOutDir string
Chris Parsons8f232a22020-06-23 17:37:05 -0400262 moduleListFile string // the path to the file which lists blueprint files to parse.
Colin Crossc1e86a32015-04-15 12:33:28 -0700263
Lukacs T. Berkie1df43f2021-09-08 15:31:14 +0200264 runGoTests bool
Lukacs T. Berkiea1a31c2021-09-02 09:58:09 +0200265
Colin Cross6ccbc912017-10-10 23:07:38 -0700266 env map[string]string
Dan Willemsene7680ba2015-09-11 17:06:19 -0700267 envLock sync.Mutex
268 envDeps map[string]string
269 envFrozen bool
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800270
Jingwen Chencda22c92020-11-23 00:22:30 -0500271 // Changes behavior based on whether Kati runs after soong_build, or if soong_build
272 // runs standalone.
273 katiEnabled bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700274
Colin Cross32616ed2017-09-05 21:56:44 -0700275 captureBuild bool // true for tests, saves build parameters for each module
276 ignoreEnvironment bool // true for tests, returns empty from all Getenv calls
Colin Crosscec81712017-07-13 14:43:27 -0700277
Colin Cross98be1bb2019-12-13 20:41:13 -0800278 fs pathtools.FileSystem
279 mockBpList string
280
Colin Crossb63d7b32023-12-07 16:54:51 -0800281 BuildMode SoongBuildMode
Jingwen Chen12b4c272021-03-10 02:05:59 -0500282
LaMont Jones52a72432023-03-09 18:19:35 +0000283 // If MultitreeBuild is true then this is one inner tree of a multitree
284 // build directed by the multitree orchestrator.
285 MultitreeBuild bool
286
Colin Cross5e6a7972020-06-07 16:56:32 -0700287 // If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error
288 // in tests when a path doesn't exist.
Pedro Loureiro5d190cc2021-02-15 15:41:33 +0000289 TestAllowNonExistentPaths bool
Colin Cross5e6a7972020-06-07 16:56:32 -0700290
Jingwen Chenc711fec2020-11-22 23:52:50 -0500291 // The list of files that when changed, must invalidate soong_build to
292 // regenerate build.ninja.
Colin Cross12129292020-10-29 18:23:58 -0700293 ninjaFileDepsSet sync.Map
294
Colin Cross9272ade2016-08-17 15:24:12 -0700295 OncePer
MarkDacekff851b82022-04-21 18:33:17 +0000296
Jihoon Kang2a929ad2023-06-08 19:02:07 +0000297 // If buildFromSourceStub is true then the Java API stubs are
298 // built from the source Java files, not the signature text files.
299 buildFromSourceStub bool
MarkDacekf47e1422023-04-19 16:47:36 +0000300
301 // If ensureAllowlistIntegrity is true, then the presence of any allowlisted
302 // modules that aren't mixed-built for at least one variant will cause a build
303 // failure
304 ensureAllowlistIntegrity bool
Jihoon Kang1c92c3e2023-03-23 17:44:51 +0000305
306 // List of Api libraries that contribute to Api surfaces.
307 apiLibraries map[string]struct{}
Colin Cross9272ade2016-08-17 15:24:12 -0700308}
309
310type deviceConfig struct {
Dan Willemsen00269f22017-07-06 16:59:48 -0700311 config *config
Colin Cross9272ade2016-08-17 15:24:12 -0700312 OncePer
Colin Cross3f40fa42015-01-30 17:27:36 -0800313}
314
Colin Cross485e5722015-08-27 13:28:01 -0700315type jsonConfigurable interface {
Colin Cross27385972015-09-18 10:57:10 -0700316 SetDefaultConfig()
Colin Cross485e5722015-08-27 13:28:01 -0700317}
Colin Cross3f40fa42015-01-30 17:27:36 -0800318
Colin Cross485e5722015-08-27 13:28:01 -0700319func loadConfig(config *config) error {
Colin Cross988414c2020-01-11 01:11:46 +0000320 return loadFromConfigFile(&config.productVariables, absolutePath(config.ProductVariablesFileName))
Colin Cross485e5722015-08-27 13:28:01 -0700321}
322
Jingwen Chenc711fec2020-11-22 23:52:50 -0500323// loadFromConfigFile loads and decodes configuration options from a JSON file
324// in the current working directory.
Cole Faustf8231dd2023-04-21 17:37:11 -0700325func loadFromConfigFile(configurable *ProductVariables, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800326 // Try to open the file
Colin Cross485e5722015-08-27 13:28:01 -0700327 configFileReader, err := os.Open(filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800328 defer configFileReader.Close()
329 if os.IsNotExist(err) {
330 // Need to create a file, so that blueprint & ninja don't get in
331 // a dependency tracking loop.
332 // Make a file-configurable-options with defaults, write it out using
333 // a json writer.
Colin Cross27385972015-09-18 10:57:10 -0700334 configurable.SetDefaultConfig()
335 err = saveToConfigFile(configurable, filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800336 if err != nil {
337 return err
338 }
Colin Cross15cd21a2018-02-27 11:26:02 -0800339 } else if err != nil {
340 return fmt.Errorf("config file: could not open %s: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800341 } else {
342 // Make a decoder for it
343 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700344 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800345 if err != nil {
Colin Cross15cd21a2018-02-27 11:26:02 -0800346 return fmt.Errorf("config file: %s did not parse correctly: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800347 }
348 }
349
Liz Kammer09f947d2021-05-12 14:51:49 -0400350 if Bool(configurable.GcovCoverage) && Bool(configurable.ClangCoverage) {
351 return fmt.Errorf("GcovCoverage and ClangCoverage cannot both be set")
352 }
353
354 configurable.Native_coverage = proptools.BoolPtr(
355 Bool(configurable.GcovCoverage) ||
356 Bool(configurable.ClangCoverage))
357
Yuntao Xu402e9b02021-08-09 15:44:44 -0700358 // when Platform_sdk_final is true (or PLATFORM_VERSION_CODENAME is REL), use Platform_sdk_version;
359 // if false (pre-released version, for example), use Platform_sdk_codename.
360 if Bool(configurable.Platform_sdk_final) {
361 if configurable.Platform_sdk_version != nil {
362 configurable.Platform_sdk_version_or_codename =
363 proptools.StringPtr(strconv.Itoa(*(configurable.Platform_sdk_version)))
364 } else {
365 return fmt.Errorf("Platform_sdk_version cannot be pointed by a NULL pointer")
366 }
367 } else {
368 configurable.Platform_sdk_version_or_codename =
369 proptools.StringPtr(String(configurable.Platform_sdk_codename))
370 }
371
Liz Kammer09f947d2021-05-12 14:51:49 -0400372 return saveToBazelConfigFile(configurable, filepath.Dir(filename))
Colin Cross3f40fa42015-01-30 17:27:36 -0800373}
374
Colin Crossd8f20142016-11-03 09:43:26 -0700375// atomically writes the config file in case two copies of soong_build are running simultaneously
376// (for example, docs generation and ninja manifest generation)
Cole Faustf8231dd2023-04-21 17:37:11 -0700377func saveToConfigFile(config *ProductVariables, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800378 data, err := json.MarshalIndent(&config, "", " ")
379 if err != nil {
380 return fmt.Errorf("cannot marshal config data: %s", err.Error())
381 }
382
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800383 f, err := os.CreateTemp(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800384 if err != nil {
Jingwen Chenc711fec2020-11-22 23:52:50 -0500385 return fmt.Errorf("cannot create empty config file %s: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800386 }
Colin Crossd8f20142016-11-03 09:43:26 -0700387 defer os.Remove(f.Name())
388 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800389
Colin Crossd8f20142016-11-03 09:43:26 -0700390 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800391 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700392 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
393 }
394
Colin Crossd8f20142016-11-03 09:43:26 -0700395 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700396 if err != nil {
397 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800398 }
399
Colin Crossd8f20142016-11-03 09:43:26 -0700400 f.Close()
401 os.Rename(f.Name(), filename)
402
Colin Cross3f40fa42015-01-30 17:27:36 -0800403 return nil
404}
405
Cole Faust87c0c332023-07-31 12:10:12 -0700406type productVariableStarlarkRepresentation struct {
407 soongType string
408 selectable bool
409 archVariant bool
410}
411
Cole Faustf8231dd2023-04-21 17:37:11 -0700412func saveToBazelConfigFile(config *ProductVariables, outDir string) error {
Liz Kammer09f947d2021-05-12 14:51:49 -0400413 dir := filepath.Join(outDir, bazel.SoongInjectionDirName, "product_config")
414 err := createDirIfNonexistent(dir, os.ModePerm)
415 if err != nil {
416 return fmt.Errorf("Could not create dir %s: %s", dir, err)
417 }
418
Cole Faust87c0c332023-07-31 12:10:12 -0700419 allProductVariablesType := reflect.TypeOf((*ProductVariables)(nil)).Elem()
420 productVariablesInfo := make(map[string]productVariableStarlarkRepresentation)
Sam Delmerico5c32bbf2022-01-20 20:15:02 +0000421 p := variableProperties{}
422 t := reflect.TypeOf(p.Product_variables)
423 for i := 0; i < t.NumField(); i++ {
424 f := t.Field(i)
Cole Faust87c0c332023-07-31 12:10:12 -0700425 archVariant := proptools.HasTag(f, "android", "arch_variant")
426 if mainProductVariablesStructField, ok := allProductVariablesType.FieldByName(f.Name); ok {
427 productVariablesInfo[f.Name] = productVariableStarlarkRepresentation{
428 soongType: stringRepresentationOfSimpleType(mainProductVariablesStructField.Type),
429 selectable: true,
430 archVariant: archVariant,
431 }
432 } else {
433 panic("Unknown variable " + f.Name)
Sam Delmerico5c32bbf2022-01-20 20:15:02 +0000434 }
435 }
436
Cole Fausteb644cf2023-04-11 13:48:17 -0700437 err = pathtools.WriteFileIfChanged(filepath.Join(dir, "product_variable_constants.bzl"), []byte(fmt.Sprintf(`
Cole Faust87c0c332023-07-31 12:10:12 -0700438# product_var_constant_info is a map of product variables to information about them. The fields are:
439# - soongType: The type of the product variable as it appears in soong's ProductVariables struct.
440# examples are string, bool, int, *bool, *string, []string, etc. This may be an overly
441# conservative estimation of the type, for example a *bool could oftentimes just be a
442# bool that defaults to false.
443# - selectable: if this product variable can be selected on in Android.bp/build files. This means
444# it's listed in the "variableProperties" soong struct. Currently all variables in
445# this list are selectable because we only need the selectable ones at the moment,
446# but the list may be expanded later.
447# - archVariant: If the variable is tagged as arch variant in the "variableProperties" struct.
448product_var_constant_info = %s
449product_var_constraints = [k for k, v in product_var_constant_info.items() if v.selectable]
450arch_variant_product_var_constraints = [k for k, v in product_var_constant_info.items() if v.selectable and v.archVariant]
451`, starlark_fmt.PrintAny(productVariablesInfo, 0))), 0644)
Cole Fausteb644cf2023-04-11 13:48:17 -0700452 if err != nil {
453 return fmt.Errorf("Could not write .bzl config file %s", err)
454 }
Chris Parsons0008cf82023-02-03 18:45:43 -0500455 err = pathtools.WriteFileIfChanged(filepath.Join(dir, "BUILD"),
456 []byte(bazel.GeneratedBazelFileWarning), 0644)
Liz Kammer09f947d2021-05-12 14:51:49 -0400457 if err != nil {
458 return fmt.Errorf("Could not write BUILD config file %s", err)
459 }
460
461 return nil
462}
463
Cole Faust87c0c332023-07-31 12:10:12 -0700464func stringRepresentationOfSimpleType(ty reflect.Type) string {
465 switch ty.Kind() {
466 case reflect.String:
467 return "string"
468 case reflect.Bool:
469 return "bool"
470 case reflect.Int:
471 return "int"
472 case reflect.Slice:
473 return "[]" + stringRepresentationOfSimpleType(ty.Elem())
474 case reflect.Pointer:
475 return "*" + stringRepresentationOfSimpleType(ty.Elem())
476 default:
477 panic("unimplemented type: " + ty.Kind().String())
478 }
479}
480
Colin Cross988414c2020-01-11 01:11:46 +0000481// NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that
482// use the android package.
Lukacs T. Berkid6cee7e2021-09-01 16:25:51 +0200483func NullConfig(outDir, soongOutDir string) Config {
Colin Cross988414c2020-01-11 01:11:46 +0000484 return Config{
485 config: &config{
Lukacs T. Berkid6cee7e2021-09-01 16:25:51 +0200486 outDir: outDir,
Lukacs T. Berki9f6c24a2021-08-26 15:07:24 +0200487 soongOutDir: soongOutDir,
488 fs: pathtools.OsFs,
Colin Cross988414c2020-01-11 01:11:46 +0000489 },
490 }
491}
492
Jingwen Chenc711fec2020-11-22 23:52:50 -0500493// NewConfig creates a new Config object. The srcDir argument specifies the path
494// to the root source directory. It also loads the config file, if found.
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800495func NewConfig(cmdArgs CmdArgs, availableEnv map[string]string) (Config, error) {
Jingwen Chenc711fec2020-11-22 23:52:50 -0500496 // Make a config with default options.
Colin Cross9272ade2016-08-17 15:24:12 -0700497 config := &config{
Kiyoung Kima37d9ba2023-04-19 13:13:45 +0900498 ProductVariablesFileName: cmdArgs.SoongVariables,
Dan Willemsen87b17d12015-07-14 00:39:06 -0700499
Lukacs T. Berki53b2f362021-04-12 14:04:24 +0200500 env: availableEnv,
Colin Cross6ccbc912017-10-10 23:07:38 -0700501
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800502 outDir: cmdArgs.OutDir,
503 soongOutDir: cmdArgs.SoongOutDir,
504 runGoTests: cmdArgs.RunGoTests,
Lukacs T. Berkie1df43f2021-09-08 15:31:14 +0200505 multilibConflicts: make(map[ArchType]bool),
Colin Cross98be1bb2019-12-13 20:41:13 -0800506
Colin Crossb63d7b32023-12-07 16:54:51 -0800507 moduleListFile: cmdArgs.ModuleListFile,
508 fs: pathtools.NewOsFs(absSrcDir),
Chris Parsons9402ca82023-02-23 17:28:06 -0500509
LaMont Jones52a72432023-03-09 18:19:35 +0000510 MultitreeBuild: cmdArgs.MultitreeBuild,
Jihoon Kang1bff0342023-01-17 20:40:22 +0000511
Jihoon Kang2a929ad2023-06-08 19:02:07 +0000512 buildFromSourceStub: cmdArgs.BuildFromSourceStub,
Colin Cross68f55102015-03-25 14:43:57 -0700513 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800514
Dan Willemsen00269f22017-07-06 16:59:48 -0700515 config.deviceConfig = &deviceConfig{
Colin Cross9272ade2016-08-17 15:24:12 -0700516 config: config,
517 }
518
Liz Kammer7941b302020-07-28 13:27:34 -0700519 // Soundness check of the build and source directories. This won't catch strange
520 // configurations with symlinks, but at least checks the obvious case.
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800521 absBuildDir, err := filepath.Abs(cmdArgs.SoongOutDir)
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700522 if err != nil {
523 return Config{}, err
524 }
525
Lukacs T. Berkif7e36d82021-08-16 17:05:09 +0200526 absSrcDir, err := filepath.Abs(".")
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700527 if err != nil {
528 return Config{}, err
529 }
530
531 if strings.HasPrefix(absSrcDir, absBuildDir) {
532 return Config{}, fmt.Errorf("Build dir must not contain source directory")
533 }
534
Colin Cross3f40fa42015-01-30 17:27:36 -0800535 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700536 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800537 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700538 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800539 }
540
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800541 KatiEnabledMarkerFile := filepath.Join(cmdArgs.SoongOutDir, ".soong.kati_enabled")
Jingwen Chencda22c92020-11-23 00:22:30 -0500542 if _, err := os.Stat(absolutePath(KatiEnabledMarkerFile)); err == nil {
543 config.katiEnabled = true
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800544 }
545
Colin Cross0c66bc62021-07-20 09:47:41 -0700546 determineBuildOS(config)
547
Jingwen Chenc711fec2020-11-22 23:52:50 -0500548 // Sets up the map of target OSes to the finer grained compilation targets
549 // that are configured from the product variables.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700550 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700551 if err != nil {
552 return Config{}, err
553 }
554
Paul Duffin1356d8c2020-02-25 19:26:33 +0000555 // Make the CommonOS OsType available for all products.
556 targets[CommonOS] = []Target{commonTargetMap[CommonOS.Name]}
557
Dan Albert4098deb2016-10-19 14:04:41 -0700558 var archConfig []archConfig
Jingwen Chenc4d91bc2020-11-24 22:59:26 -0500559 if config.NdkAbis() {
Dan Albert4098deb2016-10-19 14:04:41 -0700560 archConfig = getNdkAbisConfig()
Martin Stjernholmc1ecc432019-11-15 15:00:31 +0000561 } else if config.AmlAbis() {
562 archConfig = getAmlAbisConfig()
Dan Albert4098deb2016-10-19 14:04:41 -0700563 }
564
565 if archConfig != nil {
Liz Kammerb7f33662022-02-28 14:16:16 -0500566 androidTargets, err := decodeAndroidArchSettings(archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800567 if err != nil {
568 return Config{}, err
569 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700570 targets[Android] = androidTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800571 }
572
Colin Cross3b19f5d2019-09-17 14:45:31 -0700573 multilib := make(map[string]bool)
574 for _, target := range targets[Android] {
575 if seen := multilib[target.Arch.ArchType.Multilib]; seen {
576 config.multilibConflicts[target.Arch.ArchType] = true
577 }
578 multilib[target.Arch.ArchType.Multilib] = true
579 }
580
Jingwen Chenc711fec2020-11-22 23:52:50 -0500581 // Map of OS to compilation targets.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700582 config.Targets = targets
Jingwen Chenc711fec2020-11-22 23:52:50 -0500583
584 // Compilation targets for host tools.
Colin Cross0c66bc62021-07-20 09:47:41 -0700585 config.BuildOSTarget = config.Targets[config.BuildOS][0]
586 config.BuildOSCommonTarget = getCommonTargets(config.Targets[config.BuildOS])[0]
Jingwen Chenc711fec2020-11-22 23:52:50 -0500587
588 // Compilation targets for Android.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700589 if len(config.Targets[Android]) > 0 {
590 config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
Sam Delmericocc271e22022-06-01 15:45:02 +0000591 config.AndroidFirstDeviceTarget = FirstTarget(config.Targets[Android], "lib64", "lib32")[0]
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700592 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700593
Usta Shresthacae3bfa2022-12-21 11:44:26 -0500594 setBuildMode := func(arg string, mode SoongBuildMode) {
595 if arg != "" {
596 if config.BuildMode != AnalysisNoBazel {
597 fmt.Fprintf(os.Stderr, "buildMode is already set, illegal argument: %s", arg)
598 os.Exit(1)
599 }
600 config.BuildMode = mode
601 }
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800602 }
Usta Shresthacae3bfa2022-12-21 11:44:26 -0500603 setBuildMode(cmdArgs.BazelQueryViewDir, GenerateQueryView)
Usta Shresthacae3bfa2022-12-21 11:44:26 -0500604 setBuildMode(cmdArgs.ModuleGraphFile, GenerateModuleGraph)
605 setBuildMode(cmdArgs.DocFile, GenerateDocFile)
MarkDacekd06db5d2022-11-29 00:47:59 +0000606
Jihoon Kang1c92c3e2023-03-23 17:44:51 +0000607 // TODO(b/276958307): Replace the hardcoded list to a sdk_library local prop.
608 config.apiLibraries = map[string]struct{}{
609 "android.net.ipsec.ike": {},
610 "art.module.public.api": {},
611 "conscrypt.module.public.api": {},
612 "framework-adservices": {},
613 "framework-appsearch": {},
614 "framework-bluetooth": {},
615 "framework-connectivity": {},
616 "framework-connectivity-t": {},
617 "framework-graphics": {},
Mark White387a6582023-08-06 00:20:47 +0000618 "framework-location": {},
Jihoon Kang1c92c3e2023-03-23 17:44:51 +0000619 "framework-media": {},
620 "framework-mediaprovider": {},
Roshan Pius92307ff2023-11-13 17:16:35 -0800621 "framework-nfc": {},
Jihoon Kang1c92c3e2023-03-23 17:44:51 +0000622 "framework-ondevicepersonalization": {},
Alyssa Ketpreechasawat9f634362023-11-08 16:03:53 +0000623 "framework-pdf": {},
Jihoon Kang1c92c3e2023-03-23 17:44:51 +0000624 "framework-permission": {},
625 "framework-permission-s": {},
626 "framework-scheduling": {},
627 "framework-sdkextensions": {},
628 "framework-statsd": {},
629 "framework-sdksandbox": {},
630 "framework-tethering": {},
631 "framework-uwb": {},
632 "framework-virtualization": {},
633 "framework-wifi": {},
634 "i18n.module.public.api": {},
635 }
636
Jihoon Kangc1b04d62023-11-16 19:07:04 +0000637 config.productVariables.Build_from_text_stub = boolPtr(config.BuildFromTextStub())
638
Jingwen Chenc711fec2020-11-22 23:52:50 -0500639 return Config{config}, err
640}
Colin Cross988414c2020-01-11 01:11:46 +0000641
Colin Cross98be1bb2019-12-13 20:41:13 -0800642// mockFileSystem replaces all reads with accesses to the provided map of
643// filenames to contents stored as a byte slice.
644func (c *config) mockFileSystem(bp string, fs map[string][]byte) {
645 mockFS := map[string][]byte{}
646
647 if _, exists := mockFS["Android.bp"]; !exists {
648 mockFS["Android.bp"] = []byte(bp)
649 }
650
651 for k, v := range fs {
652 mockFS[k] = v
653 }
654
655 // no module list file specified; find every file named Blueprints or Android.bp
656 pathsToParse := []string{}
657 for candidate := range mockFS {
658 base := filepath.Base(candidate)
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200659 if base == "Android.bp" {
Colin Cross98be1bb2019-12-13 20:41:13 -0800660 pathsToParse = append(pathsToParse, candidate)
661 }
662 }
663 if len(pathsToParse) < 1 {
664 panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", mockFS))
665 }
666 mockFS[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n"))
667
668 c.fs = pathtools.MockFs(mockFS)
669 c.mockBpList = blueprint.MockModuleListFile
670}
671
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +0100672func (c *config) SetAllowMissingDependencies() {
673 c.productVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
674}
675
Jingwen Chenc711fec2020-11-22 23:52:50 -0500676// BlueprintToolLocation returns the directory containing build system tools
677// from Blueprint, like soong_zip and merge_zips.
Lukacs T. Berkia806e412021-09-01 08:57:48 +0200678func (c *config) HostToolDir() string {
Colin Crossacfcc1f2021-10-25 15:40:32 -0700679 if c.KatiEnabled() {
680 return filepath.Join(c.outDir, "host", c.PrebuiltOS(), "bin")
681 } else {
682 return filepath.Join(c.soongOutDir, "host", c.PrebuiltOS(), "bin")
683 }
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700684}
685
Dan Willemsen60e62f02018-11-16 21:05:32 -0800686func (c *config) HostToolPath(ctx PathContext, tool string) Path {
Cole Faust3b703f32023-10-16 13:30:51 -0700687 path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "bin", tool)
Colin Cross790ef352021-10-25 19:15:55 -0700688 return path
Dan Willemsen60e62f02018-11-16 21:05:32 -0800689}
690
Colin Cross790ef352021-10-25 19:15:55 -0700691func (c *config) HostJNIToolPath(ctx PathContext, lib string) Path {
Martin Stjernholm7260d062019-12-09 21:47:14 +0000692 ext := ".so"
693 if runtime.GOOS == "darwin" {
694 ext = ".dylib"
695 }
Cole Faust3b703f32023-10-16 13:30:51 -0700696 path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "lib64", lib+ext)
Colin Cross790ef352021-10-25 19:15:55 -0700697 return path
Martin Stjernholm7260d062019-12-09 21:47:14 +0000698}
699
Colin Crossae5330a2021-11-03 13:31:22 -0700700func (c *config) HostJavaToolPath(ctx PathContext, tool string) Path {
Cole Faust3b703f32023-10-16 13:30:51 -0700701 path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "framework", tool)
Colin Cross3e3eda62021-11-04 10:22:51 -0700702 return path
703}
704
Vinh Tran09581952023-05-16 16:03:20 -0400705func (c *config) HostCcSharedLibPath(ctx PathContext, lib string) Path {
706 libDir := "lib"
707 if ctx.Config().BuildArch.Multilib == "lib64" {
708 libDir = "lib64"
709 }
Cole Faust3b703f32023-10-16 13:30:51 -0700710 return pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, libDir, lib+".so")
Vinh Tran09581952023-05-16 16:03:20 -0400711}
712
Jingwen Chenc711fec2020-11-22 23:52:50 -0500713// PrebuiltOS returns the name of the host OS used in prebuilts directories.
Colin Cross1332b002015-04-07 17:11:30 -0700714func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800715 switch runtime.GOOS {
716 case "linux":
717 return "linux-x86"
718 case "darwin":
719 return "darwin-x86"
720 default:
721 panic("Unknown GOOS")
722 }
723}
724
725// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700726func (c *config) GoRoot() string {
Lukacs T. Berkif7e36d82021-08-16 17:05:09 +0200727 return fmt.Sprintf("prebuilts/go/%s", c.PrebuiltOS())
Colin Cross3f40fa42015-01-30 17:27:36 -0800728}
729
Jingwen Chenc711fec2020-11-22 23:52:50 -0500730// PrebuiltBuildTool returns the path to a tool in the prebuilts directory containing
731// checked-in tools, like Kati, Ninja or Toybox, for the current host OS.
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700732func (c *config) PrebuiltBuildTool(ctx PathContext, tool string) Path {
733 return PathForSource(ctx, "prebuilts/build-tools", c.PrebuiltOS(), "bin", tool)
734}
735
Jingwen Chenc711fec2020-11-22 23:52:50 -0500736// CpPreserveSymlinksFlags returns the host-specific flag for the cp(1) command
737// to preserve symlinks.
Colin Cross1332b002015-04-07 17:11:30 -0700738func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700739 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800740 case "darwin":
741 return "-R"
742 case "linux":
743 return "-d"
744 default:
745 return ""
746 }
747}
Colin Cross68f55102015-03-25 14:43:57 -0700748
Colin Cross1332b002015-04-07 17:11:30 -0700749func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700750 var val string
751 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700752 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800753 defer c.envLock.Unlock()
754 if c.envDeps == nil {
755 c.envDeps = make(map[string]string)
756 }
Colin Cross68f55102015-03-25 14:43:57 -0700757 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700758 if c.envFrozen {
759 panic("Cannot access new environment variables after envdeps are frozen")
760 }
Colin Cross6ccbc912017-10-10 23:07:38 -0700761 val, _ = c.env[key]
Colin Cross68f55102015-03-25 14:43:57 -0700762 c.envDeps[key] = val
763 }
764 return val
765}
766
Colin Cross99d7c232016-11-23 16:52:04 -0800767func (c *config) GetenvWithDefault(key string, defaultValue string) string {
768 ret := c.Getenv(key)
769 if ret == "" {
770 return defaultValue
771 }
772 return ret
773}
774
775func (c *config) IsEnvTrue(key string) bool {
776 value := c.Getenv(key)
777 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
778}
779
780func (c *config) IsEnvFalse(key string) bool {
781 value := c.Getenv(key)
782 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
783}
784
Jingwen Chenc711fec2020-11-22 23:52:50 -0500785// EnvDeps returns the environment variables this build depends on. The first
786// call to this function blocks future reads from the environment.
Colin Cross1332b002015-04-07 17:11:30 -0700787func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700788 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800789 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700790 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700791 return c.envDeps
792}
Colin Cross35cec122015-04-02 14:37:16 -0700793
Jingwen Chencda22c92020-11-23 00:22:30 -0500794func (c *config) KatiEnabled() bool {
795 return c.katiEnabled
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800796}
797
Cole Faust11edf552023-10-13 11:32:14 -0700798func (c *config) ProductVariables() ProductVariables {
799 return c.productVariables
800}
801
Nan Zhang581fd212018-01-10 16:06:12 -0800802func (c *config) BuildId() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800803 return String(c.productVariables.BuildId)
Nan Zhang581fd212018-01-10 16:06:12 -0800804}
805
Jingwen Chenc711fec2020-11-22 23:52:50 -0500806// BuildNumberFile returns the path to a text file containing metadata
807// representing the current build's number.
808//
809// Rules that want to reference the build number should read from this file
810// without depending on it. They will run whenever their other dependencies
811// require them to run and get the current build number. This ensures they don't
812// rebuild on every incremental build when the build number changes.
Colin Cross2a2e0db2020-02-21 16:55:46 -0800813func (c *config) BuildNumberFile(ctx PathContext) Path {
814 return PathForOutput(ctx, String(c.productVariables.BuildNumberFile))
Nan Zhang581fd212018-01-10 16:06:12 -0800815}
816
Jingwen Chenc711fec2020-11-22 23:52:50 -0500817// DeviceName returns the name of the current device target.
Colin Cross35cec122015-04-02 14:37:16 -0700818// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700819func (c *config) DeviceName() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800820 return *c.productVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700821}
822
Trevor Radcliffe90727f42022-03-21 19:34:02 +0000823// DeviceProduct returns the current product target. There could be multiple of
824// these per device type.
825//
Chris Parsonsef615e52022-08-18 22:04:11 -0400826// NOTE: Do not base conditional logic on this value. It may break product inheritance.
Trevor Radcliffe90727f42022-03-21 19:34:02 +0000827func (c *config) DeviceProduct() string {
828 return *c.productVariables.DeviceProduct
829}
830
Cole Faustb85d1a12022-11-08 18:14:01 -0800831// HasDeviceProduct returns if the build has a product. A build will not
832// necessarily have a product when --skip-config is passed to soong, like it is
833// in prebuilts/build-tools/build-prebuilts.sh
834func (c *config) HasDeviceProduct() bool {
835 return c.productVariables.DeviceProduct != nil
836}
837
Anton Hansson53c88442019-03-18 15:53:16 +0000838func (c *config) DeviceResourceOverlays() []string {
839 return c.productVariables.DeviceResourceOverlays
840}
841
842func (c *config) ProductResourceOverlays() []string {
843 return c.productVariables.ProductResourceOverlays
Colin Cross30e076a2015-04-13 13:58:27 -0700844}
845
Colin Crossbfd347d2018-05-09 11:11:35 -0700846func (c *config) PlatformVersionName() string {
847 return String(c.productVariables.Platform_version_name)
848}
849
Dan Albert4f378d72020-07-23 17:32:15 -0700850func (c *config) PlatformSdkVersion() ApiLevel {
851 return uncheckedFinalApiLevel(*c.productVariables.Platform_sdk_version)
Colin Cross30e076a2015-04-13 13:58:27 -0700852}
853
Cole Faust37d27c42023-04-12 10:27:45 -0700854func (c *config) RawPlatformSdkVersion() *int {
855 return c.productVariables.Platform_sdk_version
856}
857
Mu-Le Lee5e047532022-07-27 02:32:03 +0000858func (c *config) PlatformSdkFinal() bool {
859 return Bool(c.productVariables.Platform_sdk_final)
860}
861
Colin Crossd09b0b62018-04-18 11:06:47 -0700862func (c *config) PlatformSdkCodename() string {
863 return String(c.productVariables.Platform_sdk_codename)
864}
865
Anton Hansson97d0bae2022-02-16 16:15:10 +0000866func (c *config) PlatformSdkExtensionVersion() int {
867 return *c.productVariables.Platform_sdk_extension_version
868}
869
870func (c *config) PlatformBaseSdkExtensionVersion() int {
871 return *c.productVariables.Platform_base_sdk_extension_version
872}
873
Colin Cross092c9da2019-04-02 22:56:43 -0700874func (c *config) PlatformSecurityPatch() string {
875 return String(c.productVariables.Platform_security_patch)
876}
877
878func (c *config) PlatformPreviewSdkVersion() string {
879 return String(c.productVariables.Platform_preview_sdk_version)
880}
881
882func (c *config) PlatformMinSupportedTargetSdkVersion() string {
883 return String(c.productVariables.Platform_min_supported_target_sdk_version)
884}
885
886func (c *config) PlatformBaseOS() string {
887 return String(c.productVariables.Platform_base_os)
888}
889
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900890func (c *config) PlatformVersionLastStable() string {
891 return String(c.productVariables.Platform_version_last_stable)
892}
893
Jiyong Park37073842022-06-21 10:13:42 +0900894func (c *config) PlatformVersionKnownCodenames() string {
895 return String(c.productVariables.Platform_version_known_codenames)
896}
897
Dan Albert1a246272020-07-06 14:49:35 -0700898func (c *config) MinSupportedSdkVersion() ApiLevel {
Dan Albert6bfb6bb2022-08-17 20:11:57 +0000899 return uncheckedFinalApiLevel(21)
Dan Albert1a246272020-07-06 14:49:35 -0700900}
901
902func (c *config) FinalApiLevels() []ApiLevel {
903 var levels []ApiLevel
Dan Albert4f378d72020-07-23 17:32:15 -0700904 for i := 1; i <= c.PlatformSdkVersion().FinalOrFutureInt(); i++ {
Dan Albert1a246272020-07-06 14:49:35 -0700905 levels = append(levels, uncheckedFinalApiLevel(i))
906 }
907 return levels
908}
909
910func (c *config) PreviewApiLevels() []ApiLevel {
911 var levels []ApiLevel
Dan Albertf93ea132023-10-05 20:40:46 +0000912 i := 0
913 for _, codename := range c.PlatformVersionActiveCodenames() {
914 if codename == "REL" {
915 continue
916 }
917
Dan Albert1a246272020-07-06 14:49:35 -0700918 levels = append(levels, ApiLevel{
919 value: codename,
920 number: i,
921 isPreview: true,
922 })
Dan Albertf93ea132023-10-05 20:40:46 +0000923 i++
Dan Albert1a246272020-07-06 14:49:35 -0700924 }
925 return levels
926}
927
satayevcca4ab72021-11-30 12:33:55 +0000928func (c *config) LatestPreviewApiLevel() ApiLevel {
929 level := NoneApiLevel
930 for _, l := range c.PreviewApiLevels() {
931 if l.GreaterThan(level) {
932 level = l
933 }
934 }
935 return level
936}
937
Dan Albert1a246272020-07-06 14:49:35 -0700938func (c *config) AllSupportedApiLevels() []ApiLevel {
939 var levels []ApiLevel
940 levels = append(levels, c.FinalApiLevels()...)
941 return append(levels, c.PreviewApiLevels()...)
Dan Albertf5415d72017-08-17 16:19:59 -0700942}
943
Jingwen Chenc711fec2020-11-22 23:52:50 -0500944// DefaultAppTargetSdk returns the API level that platform apps are targeting.
945// This converts a codename to the exact ApiLevel it represents.
Dan Albert4f378d72020-07-23 17:32:15 -0700946func (c *config) DefaultAppTargetSdk(ctx EarlyModuleContext) ApiLevel {
Colin Crossd09b0b62018-04-18 11:06:47 -0700947 if Bool(c.productVariables.Platform_sdk_final) {
948 return c.PlatformSdkVersion()
Colin Crossd09b0b62018-04-18 11:06:47 -0700949 }
Jingwen Chenc711fec2020-11-22 23:52:50 -0500950 codename := c.PlatformSdkCodename()
Jiyong Park3a00e3d2023-03-27 17:39:48 +0900951 hostOnlyBuild := c.productVariables.DeviceArch == nil
Jingwen Chenc711fec2020-11-22 23:52:50 -0500952 if codename == "" {
Jiyong Park3a00e3d2023-03-27 17:39:48 +0900953 // There are some host-only builds (those are invoked by build-prebuilts.sh) which
954 // don't set platform sdk codename. Platform sdk codename makes sense only when we
955 // are building the platform. So we don't enforce the below panic for the host-only
956 // builds.
957 if hostOnlyBuild {
958 return NoneApiLevel
959 }
960 panic("Platform_sdk_codename must be set")
Jingwen Chenc711fec2020-11-22 23:52:50 -0500961 }
962 if codename == "REL" {
963 panic("Platform_sdk_codename should not be REL when Platform_sdk_final is true")
964 }
965 return ApiLevelOrPanic(ctx, codename)
Colin Crossd09b0b62018-04-18 11:06:47 -0700966}
967
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800968func (c *config) AppsDefaultVersionName() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800969 return String(c.productVariables.AppsDefaultVersionName)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800970}
971
Dan Albert31384de2017-07-28 12:39:46 -0700972// Codenames that are active in the current lunch target.
973func (c *config) PlatformVersionActiveCodenames() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800974 return c.productVariables.Platform_version_active_codenames
Dan Albert31384de2017-07-28 12:39:46 -0700975}
976
Dan Albert8c7a9942023-03-27 20:34:01 +0000977// All unreleased codenames.
978func (c *config) PlatformVersionAllPreviewCodenames() []string {
979 return c.productVariables.Platform_version_all_preview_codenames
980}
981
Colin Crossface4e42017-10-30 17:32:15 -0700982func (c *config) ProductAAPTConfig() []string {
Colin Crossa74ca042019-01-31 14:31:51 -0800983 return c.productVariables.AAPTConfig
Colin Cross30e076a2015-04-13 13:58:27 -0700984}
985
Colin Crossface4e42017-10-30 17:32:15 -0700986func (c *config) ProductAAPTPreferredConfig() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800987 return String(c.productVariables.AAPTPreferredConfig)
Colin Cross30e076a2015-04-13 13:58:27 -0700988}
989
Colin Crossface4e42017-10-30 17:32:15 -0700990func (c *config) ProductAAPTCharacteristics() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800991 return String(c.productVariables.AAPTCharacteristics)
Colin Crossface4e42017-10-30 17:32:15 -0700992}
993
994func (c *config) ProductAAPTPrebuiltDPI() []string {
Colin Crossa74ca042019-01-31 14:31:51 -0800995 return c.productVariables.AAPTPrebuiltDPI
Colin Cross30e076a2015-04-13 13:58:27 -0700996}
997
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700998func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800999 defaultCert := String(c.productVariables.DefaultAppCertificate)
Colin Cross61ae0b72017-12-01 17:16:02 -08001000 if defaultCert != "" {
1001 return PathForSource(ctx, filepath.Dir(defaultCert))
Colin Cross61ae0b72017-12-01 17:16:02 -08001002 }
Jingwen Chenc711fec2020-11-22 23:52:50 -05001003 return PathForSource(ctx, "build/make/target/product/security")
Colin Cross30e076a2015-04-13 13:58:27 -07001004}
1005
Colin Crosse1731a52017-12-14 11:22:55 -08001006func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001007 defaultCert := String(c.productVariables.DefaultAppCertificate)
Colin Cross61ae0b72017-12-01 17:16:02 -08001008 if defaultCert != "" {
Colin Crosse1731a52017-12-14 11:22:55 -08001009 return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -08001010 }
Jingwen Chenc711fec2020-11-22 23:52:50 -05001011 defaultDir := c.DefaultAppCertificateDir(ctx)
1012 return defaultDir.Join(ctx, "testkey.x509.pem"), defaultDir.Join(ctx, "testkey.pk8")
Colin Cross30e076a2015-04-13 13:58:27 -07001013}
Colin Cross6ff51382015-12-17 16:39:19 -08001014
Jiyong Park9335a262018-12-24 11:31:58 +09001015func (c *config) ApexKeyDir(ctx ModuleContext) SourcePath {
1016 // TODO(b/121224311): define another variable such as TARGET_APEX_KEY_OVERRIDE
1017 defaultCert := String(c.productVariables.DefaultAppCertificate)
Dan Willemsen412160e2019-04-09 21:36:26 -07001018 if defaultCert == "" || filepath.Dir(defaultCert) == "build/make/target/product/security" {
Jiyong Park9335a262018-12-24 11:31:58 +09001019 // When defaultCert is unset or is set to the testkeys path, use the APEX keys
1020 // that is under the module dir
Colin Cross07e51612019-03-05 12:46:40 -08001021 return pathForModuleSrc(ctx)
Jiyong Park9335a262018-12-24 11:31:58 +09001022 }
Jingwen Chenc711fec2020-11-22 23:52:50 -05001023 // If not, APEX keys are under the specified directory
1024 return PathForSource(ctx, filepath.Dir(defaultCert))
Jiyong Park9335a262018-12-24 11:31:58 +09001025}
1026
Inseob Kim80fa7982022-08-12 21:36:25 +09001027// Certificate for the NetworkStack sepolicy context
1028func (c *config) MainlineSepolicyDevCertificatesDir(ctx ModuleContext) SourcePath {
1029 cert := String(c.productVariables.MainlineSepolicyDevCertificates)
1030 if cert != "" {
1031 return PathForSource(ctx, cert)
1032 }
1033 return c.DefaultAppCertificateDir(ctx)
1034}
1035
Jingwen Chenc711fec2020-11-22 23:52:50 -05001036// AllowMissingDependencies configures Blueprint/Soong to not fail when modules
1037// are configured to depend on non-existent modules. Note that this does not
1038// affect missing input dependencies at the Ninja level.
Colin Cross6ff51382015-12-17 16:39:19 -08001039func (c *config) AllowMissingDependencies() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001040 return Bool(c.productVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -08001041}
Dan Willemsen322acaf2016-01-12 23:07:05 -08001042
Jeongik Cha816a23a2020-07-08 01:09:23 +09001043// Returns true if a full platform source tree cannot be assumed.
Colin Crossfc3674a2017-09-18 17:41:52 -07001044func (c *config) UnbundledBuild() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001045 return Bool(c.productVariables.Unbundled_build)
Colin Crossfc3674a2017-09-18 17:41:52 -07001046}
1047
Martin Stjernholmfd9eb4b2020-06-17 01:13:15 +01001048// Returns true if building apps that aren't bundled with the platform.
1049// UnbundledBuild() is always true when this is true.
1050func (c *config) UnbundledBuildApps() bool {
Cole Faust701ca252021-11-23 19:02:08 -08001051 return len(c.productVariables.Unbundled_build_apps) > 0
Martin Stjernholmfd9eb4b2020-06-17 01:13:15 +01001052}
1053
Jeongik Cha4b073cd2021-06-08 11:35:00 +09001054// Returns true if building image that aren't bundled with the platform.
1055// UnbundledBuild() is always true when this is true.
1056func (c *config) UnbundledBuildImage() bool {
1057 return Bool(c.productVariables.Unbundled_build_image)
1058}
1059
Jeongik Cha816a23a2020-07-08 01:09:23 +09001060// Returns true if building modules against prebuilt SDKs.
1061func (c *config) AlwaysUsePrebuiltSdks() bool {
1062 return Bool(c.productVariables.Always_use_prebuilt_sdks)
Colin Cross1f367bf2018-12-18 22:46:24 -08001063}
1064
Colin Cross126a25c2017-10-31 13:55:34 -07001065func (c *config) MinimizeJavaDebugInfo() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001066 return Bool(c.productVariables.MinimizeJavaDebugInfo) && !Bool(c.productVariables.Eng)
Colin Cross126a25c2017-10-31 13:55:34 -07001067}
1068
Colin Crossed064c02018-09-05 16:28:13 -07001069func (c *config) Debuggable() bool {
1070 return Bool(c.productVariables.Debuggable)
1071}
1072
Jaewoong Jung1d6eb682018-11-29 15:08:44 -08001073func (c *config) Eng() bool {
1074 return Bool(c.productVariables.Eng)
1075}
1076
Colin Crossc53c37f2021-12-08 15:42:22 -08001077// DevicePrimaryArchType returns the ArchType for the first configured device architecture, or
1078// Common if there are no device architectures.
Jiyong Park8d52f862018-07-07 18:02:07 +09001079func (c *config) DevicePrimaryArchType() ArchType {
Colin Crossc53c37f2021-12-08 15:42:22 -08001080 if androidTargets := c.Targets[Android]; len(androidTargets) > 0 {
1081 return androidTargets[0].Arch.ArchType
1082 }
1083 return Common
Jiyong Park8d52f862018-07-07 18:02:07 +09001084}
1085
Colin Cross16b23492016-01-06 14:41:07 -08001086func (c *config) SanitizeHost() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001087 return append([]string(nil), c.productVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -08001088}
1089
1090func (c *config) SanitizeDevice() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001091 return append([]string(nil), c.productVariables.SanitizeDevice...)
Colin Cross23ae82a2016-11-02 14:34:39 -07001092}
1093
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -07001094func (c *config) SanitizeDeviceDiag() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001095 return append([]string(nil), c.productVariables.SanitizeDeviceDiag...)
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -07001096}
1097
Colin Cross23ae82a2016-11-02 14:34:39 -07001098func (c *config) SanitizeDeviceArch() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001099 return append([]string(nil), c.productVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -08001100}
Colin Crossa1ad8d12016-06-01 17:09:44 -07001101
Vishwath Mohan1b017a72017-01-19 13:54:55 -08001102func (c *config) EnableCFI() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001103 if c.productVariables.EnableCFI == nil {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -08001104 return true
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -08001105 }
Jingwen Chenc711fec2020-11-22 23:52:50 -05001106 return *c.productVariables.EnableCFI
Vishwath Mohan1b017a72017-01-19 13:54:55 -08001107}
1108
Kostya Kortchinskyd5275c82019-02-01 08:42:56 -08001109func (c *config) DisableScudo() bool {
1110 return Bool(c.productVariables.DisableScudo)
1111}
1112
Colin Crossa1ad8d12016-06-01 17:09:44 -07001113func (c *config) Android64() bool {
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001114 for _, t := range c.Targets[Android] {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001115 if t.Arch.ArchType.Multilib == "lib64" {
1116 return true
1117 }
1118 }
1119
1120 return false
1121}
Colin Cross9272ade2016-08-17 15:24:12 -07001122
Colin Cross9d45bb72016-08-29 16:14:13 -07001123func (c *config) UseGoma() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001124 return Bool(c.productVariables.UseGoma)
Colin Cross9d45bb72016-08-29 16:14:13 -07001125}
1126
Ramy Medhatbbf25672019-07-17 12:30:04 +00001127func (c *config) UseRBE() bool {
1128 return Bool(c.productVariables.UseRBE)
1129}
1130
Ramy Medhat8ea054a2020-01-27 14:19:44 -05001131func (c *config) UseRBEJAVAC() bool {
1132 return Bool(c.productVariables.UseRBEJAVAC)
1133}
1134
1135func (c *config) UseRBER8() bool {
1136 return Bool(c.productVariables.UseRBER8)
1137}
1138
1139func (c *config) UseRBED8() bool {
1140 return Bool(c.productVariables.UseRBED8)
1141}
1142
Colin Cross8b8bec32019-11-15 13:18:43 -08001143func (c *config) UseRemoteBuild() bool {
1144 return c.UseGoma() || c.UseRBE()
1145}
1146
Colin Cross66548102018-06-19 22:47:35 -07001147func (c *config) RunErrorProne() bool {
1148 return c.IsEnvTrue("RUN_ERROR_PRONE")
1149}
1150
Jingwen Chenc711fec2020-11-22 23:52:50 -05001151// XrefCorpusName returns the Kythe cross-reference corpus name.
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001152func (c *config) XrefCorpusName() string {
1153 return c.Getenv("XREF_CORPUS")
1154}
1155
Jingwen Chenc711fec2020-11-22 23:52:50 -05001156// XrefCuEncoding returns the compilation unit encoding to use for Kythe code
1157// xrefs. Can be 'json' (default), 'proto' or 'all'.
Sasha Smundak6c2d4f92020-01-09 17:34:23 -08001158func (c *config) XrefCuEncoding() string {
1159 if enc := c.Getenv("KYTHE_KZIP_ENCODING"); enc != "" {
1160 return enc
1161 }
1162 return "json"
1163}
1164
Sasha Smundakb0addaf2021-02-16 10:39:40 -08001165// XrefCuJavaSourceMax returns the maximum number of the Java source files
1166// in a single compilation unit
1167const xrefJavaSourceFileMaxDefault = "1000"
1168
1169func (c Config) XrefCuJavaSourceMax() string {
1170 v := c.Getenv("KYTHE_JAVA_SOURCE_BATCH_SIZE")
1171 if v == "" {
1172 return xrefJavaSourceFileMaxDefault
1173 }
1174 if _, err := strconv.ParseUint(v, 0, 0); err != nil {
1175 fmt.Fprintf(os.Stderr,
1176 "bad KYTHE_JAVA_SOURCE_BATCH_SIZE value: %s, will use %s",
1177 err, xrefJavaSourceFileMaxDefault)
1178 return xrefJavaSourceFileMaxDefault
1179 }
1180 return v
1181
1182}
1183
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001184func (c *config) EmitXrefRules() bool {
1185 return c.XrefCorpusName() != ""
1186}
1187
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001188func (c *config) ClangTidy() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001189 return Bool(c.productVariables.ClangTidy)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001190}
1191
1192func (c *config) TidyChecks() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001193 if c.productVariables.TidyChecks == nil {
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001194 return ""
1195 }
Dan Willemsen45133ac2018-03-09 21:22:06 -08001196 return *c.productVariables.TidyChecks
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001197}
1198
Colin Cross0f4e0d62016-07-27 10:56:55 -07001199func (c *config) LibartImgHostBaseAddress() string {
1200 return "0x60000000"
1201}
1202
1203func (c *config) LibartImgDeviceBaseAddress() string {
Elliott Hughesda3a0712020-03-06 16:55:28 -08001204 return "0x70000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -07001205}
1206
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -08001207func (c *config) ArtUseReadBarrier() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001208 return Bool(c.productVariables.ArtUseReadBarrier)
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -08001209}
1210
Jingwen Chenc711fec2020-11-22 23:52:50 -05001211// Enforce Runtime Resource Overlays for a module. RROs supersede static RROs,
1212// but some modules still depend on it.
1213//
1214// More info: https://source.android.com/devices/architecture/rros
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001215func (c *config) EnforceRROForModule(name string) bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001216 enforceList := c.productVariables.EnforceRROTargets
Jeongik Chacee5ba92021-02-19 12:11:51 +09001217
Roland Levillainf6cc2612020-07-09 16:58:14 +01001218 if len(enforceList) > 0 {
Yo Chiang4ebd06a2019-10-01 13:13:41 +08001219 if InList("*", enforceList) {
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001220 return true
1221 }
Colin Crossa74ca042019-01-31 14:31:51 -08001222 return InList(name, enforceList)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001223 }
1224 return false
1225}
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001226func (c *config) EnforceRROExcludedOverlay(path string) bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001227 excluded := c.productVariables.EnforceRROExcludedOverlays
Roland Levillainf6cc2612020-07-09 16:58:14 +01001228 if len(excluded) > 0 {
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001229 return HasAnyPrefix(path, excluded)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001230 }
1231 return false
1232}
1233
1234func (c *config) ExportedNamespaces() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001235 return append([]string(nil), c.productVariables.NamespacesToExport...)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001236}
1237
Sam Delmerico98a73292023-02-21 11:50:29 -05001238func (c *config) SourceRootDirs() []string {
1239 return c.productVariables.SourceRootDirs
1240}
1241
Spandan Dasc5763832022-11-08 18:42:16 +00001242func (c *config) IncludeTags() []string {
1243 return c.productVariables.IncludeTags
1244}
1245
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001246func (c *config) HostStaticBinaries() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001247 return Bool(c.productVariables.HostStaticBinaries)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001248}
1249
Colin Cross5a0dcd52018-10-05 14:20:06 -07001250func (c *config) UncompressPrivAppDex() bool {
1251 return Bool(c.productVariables.UncompressPrivAppDex)
1252}
1253
1254func (c *config) ModulesLoadedByPrivilegedModules() []string {
1255 return c.productVariables.ModulesLoadedByPrivilegedModules
1256}
1257
Jingwen Chenc711fec2020-11-22 23:52:50 -05001258// DexpreoptGlobalConfigPath returns the path to the dexpreopt.config file in
1259// the output directory, if it was created during the product configuration
1260// phase by Kati.
Jingwen Chenebb0b572020-11-02 00:24:57 -05001261func (c *config) DexpreoptGlobalConfigPath(ctx PathContext) OptionalPath {
Colin Cross988414c2020-01-11 01:11:46 +00001262 if c.productVariables.DexpreoptGlobalConfig == nil {
Jingwen Chenebb0b572020-11-02 00:24:57 -05001263 return OptionalPathForPath(nil)
1264 }
1265 return OptionalPathForPath(
1266 pathForBuildToolDep(ctx, *c.productVariables.DexpreoptGlobalConfig))
1267}
1268
Jingwen Chenc711fec2020-11-22 23:52:50 -05001269// DexpreoptGlobalConfig returns the raw byte contents of the dexpreopt global
1270// configuration. Since the configuration file was created by Kati during
1271// product configuration (externally of soong_build), it's not tracked, so we
1272// also manually add a Ninja file dependency on the configuration file to the
1273// rule that creates the main build.ninja file. This ensures that build.ninja is
1274// regenerated correctly if dexpreopt.config changes.
Jingwen Chenebb0b572020-11-02 00:24:57 -05001275func (c *config) DexpreoptGlobalConfig(ctx PathContext) ([]byte, error) {
1276 path := c.DexpreoptGlobalConfigPath(ctx)
1277 if !path.Valid() {
Colin Cross988414c2020-01-11 01:11:46 +00001278 return nil, nil
1279 }
Jingwen Chenebb0b572020-11-02 00:24:57 -05001280 ctx.AddNinjaFileDeps(path.String())
Sasha Smundakaf5ca922022-12-12 21:23:34 -08001281 return os.ReadFile(absolutePath(path.String()))
Colin Cross43f08db2018-11-12 10:13:39 -08001282}
1283
Inseob Kim7b85eeb2021-03-23 20:52:24 +09001284func (c *deviceConfig) WithDexpreopt() bool {
1285 return c.config.productVariables.WithDexpreopt
1286}
1287
Colin Cross662d6142022-11-03 20:38:01 -07001288func (c *config) FrameworksBaseDirExists(ctx PathGlobContext) bool {
Colin Cross5a756a62021-03-16 16:34:46 -07001289 return ExistentPathForSource(ctx, "frameworks", "base", "Android.bp").Valid()
David Brazdil91b4e3e2019-01-23 21:04:05 +00001290}
1291
Inseob Kimae553032019-05-14 18:52:49 +09001292func (c *config) VndkSnapshotBuildArtifacts() bool {
1293 return Bool(c.productVariables.VndkSnapshotBuildArtifacts)
1294}
1295
Colin Cross3b19f5d2019-09-17 14:45:31 -07001296func (c *config) HasMultilibConflict(arch ArchType) bool {
1297 return c.multilibConflicts[arch]
1298}
1299
Sasha Smundakaf5ca922022-12-12 21:23:34 -08001300func (c *config) PrebuiltHiddenApiDir(_ PathContext) string {
Bill Peckhambae47492021-01-08 09:34:44 -08001301 return String(c.productVariables.PrebuiltHiddenApiDir)
1302}
1303
Kiyoung Kime623c582023-07-06 16:43:44 +09001304func (c *config) IsVndkDeprecated() bool {
1305 return !Bool(c.productVariables.KeepVndk)
1306}
1307
Justin Yun41cbb5e2023-11-29 17:58:16 +09001308func (c *config) VendorApiLevel() string {
1309 return String(c.productVariables.VendorApiLevel)
1310}
1311
Hsin-Yi Chen2c4a9772024-02-05 17:37:27 +08001312func (c *config) PrevVendorApiLevel() string {
1313 vendorApiLevel, err := strconv.Atoi(c.VendorApiLevel())
1314 if err != nil {
1315 panic(fmt.Errorf("Cannot parse vendor API level %s to an integer: %s",
1316 c.VendorApiLevel(), err))
1317 }
1318 if vendorApiLevel < 202404 || vendorApiLevel%100 != 4 {
1319 panic("Unknown vendor API level " + c.VendorApiLevel())
1320 }
1321 // The version before trunk stable is 34.
1322 if vendorApiLevel == 202404 {
1323 return "34"
1324 }
1325 return strconv.Itoa(vendorApiLevel - 100)
1326}
1327
Yi-Yo Chiang88960aa2024-01-19 15:02:29 +08001328func (c *config) VendorApiLevelFrozen() bool {
1329 return c.productVariables.GetBuildFlagBool("RELEASE_BOARD_API_LEVEL_FROZEN")
1330}
1331
Colin Cross9272ade2016-08-17 15:24:12 -07001332func (c *deviceConfig) Arches() []Arch {
1333 var arches []Arch
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001334 for _, target := range c.config.Targets[Android] {
Colin Cross9272ade2016-08-17 15:24:12 -07001335 arches = append(arches, target.Arch)
1336 }
1337 return arches
1338}
Dan Willemsend2ede872016-11-18 14:54:24 -08001339
Jayant Chowdhary34ce67d2018-03-08 11:00:50 -08001340func (c *deviceConfig) BinderBitness() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001341 is32BitBinder := c.config.productVariables.Binder32bit
Jayant Chowdhary34ce67d2018-03-08 11:00:50 -08001342 if is32BitBinder != nil && *is32BitBinder {
1343 return "32"
1344 }
1345 return "64"
1346}
1347
Dan Willemsen4353bc42016-12-05 17:16:02 -08001348func (c *deviceConfig) VendorPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001349 if c.config.productVariables.VendorPath != nil {
1350 return *c.config.productVariables.VendorPath
Dan Willemsen4353bc42016-12-05 17:16:02 -08001351 }
1352 return "vendor"
1353}
1354
Justin Yun71549282017-11-17 12:10:28 +09001355func (c *deviceConfig) VndkVersion() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001356 return String(c.config.productVariables.DeviceVndkVersion)
Justin Yun71549282017-11-17 12:10:28 +09001357}
1358
Jose Galmes6f843bc2020-12-11 13:36:29 -08001359func (c *deviceConfig) RecoverySnapshotVersion() string {
1360 return String(c.config.productVariables.RecoverySnapshotVersion)
1361}
1362
Jeongik Cha219141c2020-08-06 23:00:37 +09001363func (c *deviceConfig) CurrentApiLevelForVendorModules() string {
1364 return StringDefault(c.config.productVariables.DeviceCurrentApiLevelForVendorModules, "current")
1365}
1366
Justin Yun8fe12122017-12-07 17:18:15 +09001367func (c *deviceConfig) PlatformVndkVersion() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001368 return String(c.config.productVariables.Platform_vndk_version)
Justin Yun8fe12122017-12-07 17:18:15 +09001369}
1370
Justin Yun71549282017-11-17 12:10:28 +09001371func (c *deviceConfig) ExtraVndkVersions() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001372 return c.config.productVariables.ExtraVndkVersions
Dan Willemsend2ede872016-11-18 14:54:24 -08001373}
Jack He8cc71432016-12-08 15:45:07 -08001374
Vic Yangefd249e2018-11-12 20:19:56 -08001375func (c *deviceConfig) VndkUseCoreVariant() bool {
Kiyoung Kim03b6cba2023-10-06 14:12:43 +09001376 return Bool(c.config.productVariables.VndkUseCoreVariant) && Bool(c.config.productVariables.KeepVndk)
Vic Yangefd249e2018-11-12 20:19:56 -08001377}
1378
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001379func (c *deviceConfig) SystemSdkVersions() []string {
Colin Crossa74ca042019-01-31 14:31:51 -08001380 return c.config.productVariables.DeviceSystemSdkVersions
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001381}
1382
1383func (c *deviceConfig) PlatformSystemSdkVersions() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001384 return c.config.productVariables.Platform_systemsdk_versions
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001385}
1386
Jiyong Park2db76922017-11-08 16:03:48 +09001387func (c *deviceConfig) OdmPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001388 if c.config.productVariables.OdmPath != nil {
1389 return *c.config.productVariables.OdmPath
Jiyong Park2db76922017-11-08 16:03:48 +09001390 }
1391 return "odm"
1392}
1393
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +09001394func (c *deviceConfig) ProductPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001395 if c.config.productVariables.ProductPath != nil {
1396 return *c.config.productVariables.ProductPath
Jiyong Park2db76922017-11-08 16:03:48 +09001397 }
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +09001398 return "product"
Jiyong Park2db76922017-11-08 16:03:48 +09001399}
1400
Justin Yund5f6c822019-06-25 16:47:17 +09001401func (c *deviceConfig) SystemExtPath() string {
1402 if c.config.productVariables.SystemExtPath != nil {
1403 return *c.config.productVariables.SystemExtPath
Dario Frenifd05a742018-05-29 13:28:54 +01001404 }
Justin Yund5f6c822019-06-25 16:47:17 +09001405 return "system_ext"
Dario Frenifd05a742018-05-29 13:28:54 +01001406}
1407
Jack He8cc71432016-12-08 15:45:07 -08001408func (c *deviceConfig) BtConfigIncludeDir() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001409 return String(c.config.productVariables.BtConfigIncludeDir)
Jack He8cc71432016-12-08 15:45:07 -08001410}
Dan Willemsen581341d2017-02-09 16:16:31 -08001411
Jiyong Parkd773eb32017-07-03 13:18:12 +09001412func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001413 return c.config.productVariables.DeviceKernelHeaders
Jiyong Parkd773eb32017-07-03 13:18:12 +09001414}
1415
Roland Levillainada12702020-06-09 13:07:36 +01001416// JavaCoverageEnabledForPath returns whether Java code coverage is enabled for
1417// path. Coverage is enabled by default when the product variable
1418// JavaCoveragePaths is empty. If JavaCoveragePaths is not empty, coverage is
1419// enabled for any path which is part of this variable (and not part of the
1420// JavaCoverageExcludePaths product variable). Value "*" in JavaCoveragePaths
1421// represents any path.
1422func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool {
1423 coverage := false
Chris Gross2f748692020-06-24 20:36:59 +00001424 if len(c.config.productVariables.JavaCoveragePaths) == 0 ||
Roland Levillainada12702020-06-09 13:07:36 +01001425 InList("*", c.config.productVariables.JavaCoveragePaths) ||
1426 HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) {
1427 coverage = true
1428 }
Roland Levillainf6cc2612020-07-09 16:58:14 +01001429 if coverage && len(c.config.productVariables.JavaCoverageExcludePaths) > 0 {
Roland Levillainada12702020-06-09 13:07:36 +01001430 if HasAnyPrefix(path, c.config.productVariables.JavaCoverageExcludePaths) {
1431 coverage = false
1432 }
1433 }
1434 return coverage
1435}
1436
Colin Cross1a6acd42020-06-16 17:51:46 -07001437// Returns true if gcov or clang coverage is enabled.
Dan Willemsen581341d2017-02-09 16:16:31 -08001438func (c *deviceConfig) NativeCoverageEnabled() bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001439 return Bool(c.config.productVariables.GcovCoverage) ||
1440 Bool(c.config.productVariables.ClangCoverage)
Dan Willemsen581341d2017-02-09 16:16:31 -08001441}
1442
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001443func (c *deviceConfig) ClangCoverageEnabled() bool {
1444 return Bool(c.config.productVariables.ClangCoverage)
1445}
1446
Pirama Arumuga Nainarb37ae582022-01-26 22:14:32 -08001447func (c *deviceConfig) ClangCoverageContinuousMode() bool {
1448 return Bool(c.config.productVariables.ClangCoverageContinuousMode)
1449}
1450
Colin Cross1a6acd42020-06-16 17:51:46 -07001451func (c *deviceConfig) GcovCoverageEnabled() bool {
1452 return Bool(c.config.productVariables.GcovCoverage)
1453}
1454
Roland Levillain4f5297b2020-06-09 12:44:06 +01001455// NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native
1456// code coverage is enabled for path. By default, coverage is not enabled for a
1457// given path unless it is part of the NativeCoveragePaths product variable (and
1458// not part of the NativeCoverageExcludePaths product variable). Value "*" in
1459// NativeCoveragePaths represents any path.
1460func (c *deviceConfig) NativeCoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -08001461 coverage := false
Roland Levillainf6cc2612020-07-09 16:58:14 +01001462 if len(c.config.productVariables.NativeCoveragePaths) > 0 {
Roland Levillain4f5297b2020-06-09 12:44:06 +01001463 if InList("*", c.config.productVariables.NativeCoveragePaths) || HasAnyPrefix(path, c.config.productVariables.NativeCoveragePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -07001464 coverage = true
Dan Willemsen581341d2017-02-09 16:16:31 -08001465 }
1466 }
Roland Levillainf6cc2612020-07-09 16:58:14 +01001467 if coverage && len(c.config.productVariables.NativeCoverageExcludePaths) > 0 {
Yi Kongfd07ed22023-02-16 17:42:27 +09001468 // Workaround coverage boot failure.
1469 // http://b/269981180
1470 if strings.HasPrefix(path, "external/protobuf") {
1471 coverage = false
1472 }
Roland Levillain4f5297b2020-06-09 12:44:06 +01001473 if HasAnyPrefix(path, c.config.productVariables.NativeCoverageExcludePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -07001474 coverage = false
Ryan Campbell469a18a2017-02-27 09:01:54 -08001475 }
1476 }
1477 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -08001478}
Ivan Lozano5f595532017-07-13 14:46:05 -07001479
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -08001480func (c *deviceConfig) PgoAdditionalProfileDirs() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001481 return c.config.productVariables.PgoAdditionalProfileDirs
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -08001482}
1483
Vinh Tran44cb78c2023-03-09 22:07:19 -05001484// AfdoProfile returns fully qualified path associated to the given module name
1485func (c *deviceConfig) AfdoProfile(name string) (*string, error) {
1486 for _, afdoProfile := range c.config.productVariables.AfdoProfiles {
1487 split := strings.Split(afdoProfile, ":")
1488 if len(split) != 3 {
1489 return nil, fmt.Errorf("AFDO_PROFILES has invalid value: %s. "+
1490 "The expected format is <module>:<fully-qualified-path-to-fdo_profile>", afdoProfile)
1491 }
1492 if split[0] == name {
1493 return proptools.StringPtr(strings.Join([]string{split[1], split[2]}, ":")), nil
1494 }
1495 }
1496 return nil, nil
1497}
1498
Tri Vo35a51432018-03-25 20:00:00 -07001499func (c *deviceConfig) VendorSepolicyDirs() []string {
1500 return c.config.productVariables.BoardVendorSepolicyDirs
1501}
1502
1503func (c *deviceConfig) OdmSepolicyDirs() []string {
1504 return c.config.productVariables.BoardOdmSepolicyDirs
1505}
1506
Felixa20a8752020-05-17 18:28:35 +02001507func (c *deviceConfig) SystemExtPublicSepolicyDirs() []string {
1508 return c.config.productVariables.SystemExtPublicSepolicyDirs
Tri Vo35a51432018-03-25 20:00:00 -07001509}
1510
Felixa20a8752020-05-17 18:28:35 +02001511func (c *deviceConfig) SystemExtPrivateSepolicyDirs() []string {
1512 return c.config.productVariables.SystemExtPrivateSepolicyDirs
Tri Vo35a51432018-03-25 20:00:00 -07001513}
1514
Inseob Kim0866b002019-04-15 20:21:29 +09001515func (c *deviceConfig) SepolicyM4Defs() []string {
1516 return c.config.productVariables.BoardSepolicyM4Defs
1517}
1518
Jiyong Park7f67f482019-01-05 12:57:48 +09001519func (c *deviceConfig) OverrideManifestPackageNameFor(name string) (manifestName string, overridden bool) {
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001520 return findOverrideValue(c.config.productVariables.ManifestPackageNameOverrides, name,
1521 "invalid override rule %q in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES should be <module_name>:<manifest_name>")
1522}
1523
1524func (c *deviceConfig) OverrideCertificateFor(name string) (certificatePath string, overridden bool) {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001525 return findOverrideValue(c.config.productVariables.CertificateOverrides, name,
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001526 "invalid override rule %q in PRODUCT_CERTIFICATE_OVERRIDES should be <module_name>:<certificate_module_name>")
1527}
1528
Jaewoong Jung9d22a912019-01-23 16:27:47 -08001529func (c *deviceConfig) OverridePackageNameFor(name string) string {
1530 newName, overridden := findOverrideValue(
1531 c.config.productVariables.PackageNameOverrides,
1532 name,
1533 "invalid override rule %q in PRODUCT_PACKAGE_NAME_OVERRIDES should be <module_name>:<package_name>")
1534 if overridden {
1535 return newName
1536 }
1537 return name
1538}
1539
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001540func findOverrideValue(overrides []string, name string, errorMsg string) (newValue string, overridden bool) {
Jiyong Park7f67f482019-01-05 12:57:48 +09001541 if overrides == nil || len(overrides) == 0 {
1542 return "", false
1543 }
1544 for _, o := range overrides {
1545 split := strings.Split(o, ":")
1546 if len(split) != 2 {
1547 // This shouldn't happen as this is first checked in make, but just in case.
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001548 panic(fmt.Errorf(errorMsg, o))
Jiyong Park7f67f482019-01-05 12:57:48 +09001549 }
1550 if matchPattern(split[0], name) {
1551 return substPattern(split[0], split[1], name), true
1552 }
1553 }
1554 return "", false
1555}
1556
Albert Martineefabcf2022-03-21 20:11:16 +00001557func (c *deviceConfig) ApexGlobalMinSdkVersionOverride() string {
1558 return String(c.config.productVariables.ApexGlobalMinSdkVersionOverride)
1559}
1560
Ivan Lozano5f595532017-07-13 14:46:05 -07001561func (c *config) IntegerOverflowDisabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001562 if len(c.productVariables.IntegerOverflowExcludePaths) == 0 {
Ivan Lozano5f595532017-07-13 14:46:05 -07001563 return false
1564 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001565 return HasAnyPrefix(path, c.productVariables.IntegerOverflowExcludePaths)
Ivan Lozano5f595532017-07-13 14:46:05 -07001566}
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001567
1568func (c *config) CFIDisabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001569 if len(c.productVariables.CFIExcludePaths) == 0 {
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001570 return false
1571 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001572 return HasAnyPrefix(path, c.productVariables.CFIExcludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001573}
1574
1575func (c *config) CFIEnabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001576 if len(c.productVariables.CFIIncludePaths) == 0 {
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001577 return false
1578 }
Evgenii Stepanov779b64e2021-04-09 14:33:10 -07001579 return HasAnyPrefix(path, c.productVariables.CFIIncludePaths) && !c.CFIDisabledForPath(path)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001580}
Colin Crosse15ddaf2017-12-04 11:24:31 -08001581
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08001582func (c *config) MemtagHeapDisabledForPath(path string) bool {
1583 if len(c.productVariables.MemtagHeapExcludePaths) == 0 {
1584 return false
1585 }
1586 return HasAnyPrefix(path, c.productVariables.MemtagHeapExcludePaths)
1587}
1588
1589func (c *config) MemtagHeapAsyncEnabledForPath(path string) bool {
1590 if len(c.productVariables.MemtagHeapAsyncIncludePaths) == 0 {
1591 return false
1592 }
Evgenii Stepanov779b64e2021-04-09 14:33:10 -07001593 return HasAnyPrefix(path, c.productVariables.MemtagHeapAsyncIncludePaths) && !c.MemtagHeapDisabledForPath(path)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08001594}
1595
1596func (c *config) MemtagHeapSyncEnabledForPath(path string) bool {
1597 if len(c.productVariables.MemtagHeapSyncIncludePaths) == 0 {
1598 return false
1599 }
Evgenii Stepanov779b64e2021-04-09 14:33:10 -07001600 return HasAnyPrefix(path, c.productVariables.MemtagHeapSyncIncludePaths) && !c.MemtagHeapDisabledForPath(path)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08001601}
1602
Tomislav Novakf734f002023-08-22 10:51:44 -07001603func (c *config) HWASanDisabledForPath(path string) bool {
1604 if len(c.productVariables.HWASanExcludePaths) == 0 {
1605 return false
1606 }
1607 return HasAnyPrefix(path, c.productVariables.HWASanExcludePaths)
1608}
1609
Hang Lua98aab92023-03-17 13:17:22 +08001610func (c *config) HWASanEnabledForPath(path string) bool {
1611 if len(c.productVariables.HWASanIncludePaths) == 0 {
1612 return false
1613 }
Tomislav Novakf734f002023-08-22 10:51:44 -07001614 return HasAnyPrefix(path, c.productVariables.HWASanIncludePaths) && !c.HWASanDisabledForPath(path)
Hang Lua98aab92023-03-17 13:17:22 +08001615}
1616
Dan Willemsen0fe78662018-03-26 12:41:18 -07001617func (c *config) VendorConfig(name string) VendorConfig {
Colin Cross9d34f352019-11-22 16:03:51 -08001618 return soongconfig.Config(c.productVariables.VendorVars[name])
Dan Willemsen0fe78662018-03-26 12:41:18 -07001619}
1620
Colin Cross395f2cf2018-10-24 16:10:32 -07001621func (c *config) NdkAbis() bool {
1622 return Bool(c.productVariables.Ndk_abis)
1623}
1624
Martin Stjernholmc1ecc432019-11-15 15:00:31 +00001625func (c *config) AmlAbis() bool {
1626 return Bool(c.productVariables.Aml_abis)
1627}
1628
Jiyong Park4da07972021-01-05 21:01:11 +09001629func (c *config) ForceApexSymlinkOptimization() bool {
1630 return Bool(c.productVariables.ForceApexSymlinkOptimization)
1631}
1632
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001633func (c *config) ApexCompressionEnabled() bool {
1634 return Bool(c.productVariables.CompressedApex) && !c.UnbundledBuildApps()
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +00001635}
1636
Dennis Shene2ed70c2023-01-11 14:15:43 +00001637func (c *config) ApexTrimEnabled() bool {
1638 return Bool(c.productVariables.TrimmedApex)
1639}
1640
Jeongik Chac9464142019-01-07 12:07:27 +09001641func (c *config) EnforceSystemCertificate() bool {
1642 return Bool(c.productVariables.EnforceSystemCertificate)
1643}
1644
Colin Cross440e0d02020-06-11 11:32:11 -07001645func (c *config) EnforceSystemCertificateAllowList() []string {
1646 return c.productVariables.EnforceSystemCertificateAllowList
Jeongik Chac9464142019-01-07 12:07:27 +09001647}
1648
Jeongik Cha2cc570d2019-10-29 15:44:45 +09001649func (c *config) EnforceProductPartitionInterface() bool {
1650 return Bool(c.productVariables.EnforceProductPartitionInterface)
1651}
1652
JaeMan Parkff715562020-10-19 17:25:58 +09001653func (c *config) EnforceInterPartitionJavaSdkLibrary() bool {
1654 return Bool(c.productVariables.EnforceInterPartitionJavaSdkLibrary)
1655}
1656
1657func (c *config) InterPartitionJavaLibraryAllowList() []string {
1658 return c.productVariables.InterPartitionJavaLibraryAllowList
1659}
1660
Colin Crossf24a22a2019-01-31 14:12:44 -08001661func (c *config) ProductHiddenAPIStubs() []string {
1662 return c.productVariables.ProductHiddenAPIStubs
Colin Cross8faf8fc2019-01-16 15:15:52 -08001663}
1664
Colin Crossf24a22a2019-01-31 14:12:44 -08001665func (c *config) ProductHiddenAPIStubsSystem() []string {
1666 return c.productVariables.ProductHiddenAPIStubsSystem
Colin Cross8faf8fc2019-01-16 15:15:52 -08001667}
1668
Colin Crossf24a22a2019-01-31 14:12:44 -08001669func (c *config) ProductHiddenAPIStubsTest() []string {
1670 return c.productVariables.ProductHiddenAPIStubsTest
Colin Cross8faf8fc2019-01-16 15:15:52 -08001671}
Dan Willemsen71c74602019-04-10 12:27:35 -07001672
Dan Willemsen54879d12019-04-18 10:08:46 -07001673func (c *deviceConfig) TargetFSConfigGen() []string {
Dan Willemsen71c74602019-04-10 12:27:35 -07001674 return c.config.productVariables.TargetFSConfigGen
1675}
Inseob Kim0866b002019-04-15 20:21:29 +09001676
1677func (c *config) ProductPublicSepolicyDirs() []string {
1678 return c.productVariables.ProductPublicSepolicyDirs
1679}
1680
1681func (c *config) ProductPrivateSepolicyDirs() []string {
1682 return c.productVariables.ProductPrivateSepolicyDirs
1683}
1684
Inseob Kim5eb7ee92022-04-27 10:30:34 +09001685func (c *config) TargetMultitreeUpdateMeta() bool {
1686 return c.productVariables.MultitreeUpdateMeta
1687}
1688
Inseob Kim1f086e22019-05-09 13:29:15 +09001689func (c *deviceConfig) DeviceArch() string {
1690 return String(c.config.productVariables.DeviceArch)
1691}
1692
1693func (c *deviceConfig) DeviceArchVariant() string {
1694 return String(c.config.productVariables.DeviceArchVariant)
1695}
1696
1697func (c *deviceConfig) DeviceSecondaryArch() string {
1698 return String(c.config.productVariables.DeviceSecondaryArch)
1699}
1700
1701func (c *deviceConfig) DeviceSecondaryArchVariant() string {
1702 return String(c.config.productVariables.DeviceSecondaryArchVariant)
1703}
Yifan Hong82db7352020-01-21 16:12:26 -08001704
1705func (c *deviceConfig) BoardUsesRecoveryAsBoot() bool {
1706 return Bool(c.config.productVariables.BoardUsesRecoveryAsBoot)
1707}
Yifan Hong97365ee2020-07-29 09:51:57 -07001708
1709func (c *deviceConfig) BoardKernelBinaries() []string {
1710 return c.config.productVariables.BoardKernelBinaries
1711}
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001712
Yifan Hong42bef8d2020-08-05 14:36:09 -07001713func (c *deviceConfig) BoardKernelModuleInterfaceVersions() []string {
1714 return c.config.productVariables.BoardKernelModuleInterfaceVersions
1715}
1716
Yifan Hongdd8dacc2020-10-21 15:40:17 -07001717func (c *deviceConfig) BoardMoveRecoveryResourcesToVendorBoot() bool {
1718 return Bool(c.config.productVariables.BoardMoveRecoveryResourcesToVendorBoot)
1719}
1720
Inseob Kim16ebd5a2020-12-09 23:08:17 +09001721func (c *deviceConfig) PlatformSepolicyVersion() string {
1722 return String(c.config.productVariables.PlatformSepolicyVersion)
1723}
1724
Inseob Kima10ef272021-09-15 03:04:53 +00001725func (c *deviceConfig) TotSepolicyVersion() string {
1726 return String(c.config.productVariables.TotSepolicyVersion)
1727}
1728
Inseob Kim843f6642022-01-07 09:11:23 +09001729func (c *deviceConfig) PlatformSepolicyCompatVersions() []string {
1730 return c.config.productVariables.PlatformSepolicyCompatVersions
1731}
1732
Inseob Kim16ebd5a2020-12-09 23:08:17 +09001733func (c *deviceConfig) BoardSepolicyVers() string {
Inseob Kim0c4eec82021-03-22 22:33:40 +09001734 if ver := String(c.config.productVariables.BoardSepolicyVers); ver != "" {
1735 return ver
1736 }
1737 return c.PlatformSepolicyVersion()
Inseob Kim16ebd5a2020-12-09 23:08:17 +09001738}
1739
Inseob Kim1a0afcc2022-02-14 23:10:51 +09001740func (c *deviceConfig) SystemExtSepolicyPrebuiltApiDir() string {
1741 return String(c.config.productVariables.SystemExtSepolicyPrebuiltApiDir)
1742}
1743
1744func (c *deviceConfig) ProductSepolicyPrebuiltApiDir() string {
1745 return String(c.config.productVariables.ProductSepolicyPrebuiltApiDir)
1746}
1747
1748func (c *deviceConfig) IsPartnerTrebleSepolicyTestEnabled() bool {
1749 return c.SystemExtSepolicyPrebuiltApiDir() != "" || c.ProductSepolicyPrebuiltApiDir() != ""
1750}
1751
Inseob Kim7cf14652021-01-06 23:06:52 +09001752func (c *deviceConfig) DirectedVendorSnapshot() bool {
1753 return c.config.productVariables.DirectedVendorSnapshot
1754}
1755
1756func (c *deviceConfig) VendorSnapshotModules() map[string]bool {
1757 return c.config.productVariables.VendorSnapshotModules
1758}
1759
Jose Galmes4c6895e2021-02-09 07:44:30 -08001760func (c *deviceConfig) DirectedRecoverySnapshot() bool {
1761 return c.config.productVariables.DirectedRecoverySnapshot
1762}
1763
1764func (c *deviceConfig) RecoverySnapshotModules() map[string]bool {
1765 return c.config.productVariables.RecoverySnapshotModules
1766}
1767
Justin DeMartino383bfb32021-02-24 10:49:43 -08001768func createDirsMap(previous map[string]bool, dirs []string) (map[string]bool, error) {
1769 var ret = make(map[string]bool)
1770 for _, dir := range dirs {
1771 clean := filepath.Clean(dir)
1772 if previous[clean] || ret[clean] {
1773 return nil, fmt.Errorf("Duplicate entry %s", dir)
1774 }
1775 ret[clean] = true
1776 }
1777 return ret, nil
1778}
1779
1780func (c *deviceConfig) createDirsMapOnce(onceKey OnceKey, previous map[string]bool, dirs []string) map[string]bool {
1781 dirMap := c.Once(onceKey, func() interface{} {
1782 ret, err := createDirsMap(previous, dirs)
1783 if err != nil {
1784 panic(fmt.Errorf("%s: %w", onceKey.key, err))
1785 }
1786 return ret
1787 })
1788 if dirMap == nil {
1789 return nil
1790 }
1791 return dirMap.(map[string]bool)
1792}
1793
1794var vendorSnapshotDirsExcludedKey = NewOnceKey("VendorSnapshotDirsExcludedMap")
1795
1796func (c *deviceConfig) VendorSnapshotDirsExcludedMap() map[string]bool {
1797 return c.createDirsMapOnce(vendorSnapshotDirsExcludedKey, nil,
1798 c.config.productVariables.VendorSnapshotDirsExcluded)
1799}
1800
1801var vendorSnapshotDirsIncludedKey = NewOnceKey("VendorSnapshotDirsIncludedMap")
1802
1803func (c *deviceConfig) VendorSnapshotDirsIncludedMap() map[string]bool {
1804 excludedMap := c.VendorSnapshotDirsExcludedMap()
1805 return c.createDirsMapOnce(vendorSnapshotDirsIncludedKey, excludedMap,
1806 c.config.productVariables.VendorSnapshotDirsIncluded)
1807}
1808
1809var recoverySnapshotDirsExcludedKey = NewOnceKey("RecoverySnapshotDirsExcludedMap")
1810
1811func (c *deviceConfig) RecoverySnapshotDirsExcludedMap() map[string]bool {
1812 return c.createDirsMapOnce(recoverySnapshotDirsExcludedKey, nil,
1813 c.config.productVariables.RecoverySnapshotDirsExcluded)
1814}
1815
1816var recoverySnapshotDirsIncludedKey = NewOnceKey("RecoverySnapshotDirsIncludedMap")
1817
1818func (c *deviceConfig) RecoverySnapshotDirsIncludedMap() map[string]bool {
1819 excludedMap := c.RecoverySnapshotDirsExcludedMap()
1820 return c.createDirsMapOnce(recoverySnapshotDirsIncludedKey, excludedMap,
1821 c.config.productVariables.RecoverySnapshotDirsIncluded)
1822}
1823
Rob Seymour925aa092021-08-10 20:42:03 +00001824func (c *deviceConfig) HostFakeSnapshotEnabled() bool {
1825 return c.config.productVariables.HostFakeSnapshotEnabled
1826}
1827
Inseob Kim60c32f02020-12-21 22:53:05 +09001828func (c *deviceConfig) ShippingApiLevel() ApiLevel {
1829 if c.config.productVariables.ShippingApiLevel == nil {
1830 return NoneApiLevel
1831 }
1832 apiLevel, _ := strconv.Atoi(*c.config.productVariables.ShippingApiLevel)
1833 return uncheckedFinalApiLevel(apiLevel)
1834}
1835
Liz Kammer33cc80e2023-05-18 18:20:28 +00001836func (c *deviceConfig) BuildBrokenPluginValidation() []string {
1837 return c.config.productVariables.BuildBrokenPluginValidation
1838}
1839
Alix Espinoef47e542022-09-14 19:10:51 +00001840func (c *deviceConfig) BuildBrokenClangAsFlags() bool {
1841 return c.config.productVariables.BuildBrokenClangAsFlags
1842}
1843
1844func (c *deviceConfig) BuildBrokenClangCFlags() bool {
1845 return c.config.productVariables.BuildBrokenClangCFlags
1846}
1847
Alixb5f6d9e2022-04-20 23:00:58 +00001848func (c *deviceConfig) BuildBrokenClangProperty() bool {
1849 return c.config.productVariables.BuildBrokenClangProperty
1850}
1851
Inseob Kim67e5add192021-03-17 18:05:33 +09001852func (c *deviceConfig) BuildBrokenEnforceSyspropOwner() bool {
1853 return c.config.productVariables.BuildBrokenEnforceSyspropOwner
1854}
1855
1856func (c *deviceConfig) BuildBrokenTrebleSyspropNeverallow() bool {
1857 return c.config.productVariables.BuildBrokenTrebleSyspropNeverallow
1858}
1859
Cole Faustedc4c502022-09-09 19:39:25 -07001860func (c *deviceConfig) BuildBrokenUsesSoongPython2Modules() bool {
1861 return c.config.productVariables.BuildBrokenUsesSoongPython2Modules
1862}
1863
Hridya Valsaraju5a5c7d52021-04-02 16:45:24 -07001864func (c *deviceConfig) BuildDebugfsRestrictionsEnabled() bool {
1865 return c.config.productVariables.BuildDebugfsRestrictionsEnabled
1866}
1867
Inseob Kim0cac7b42021-02-03 18:16:46 +09001868func (c *deviceConfig) BuildBrokenVendorPropertyNamespace() bool {
1869 return c.config.productVariables.BuildBrokenVendorPropertyNamespace
1870}
1871
Liz Kammer619be462022-01-28 15:13:39 -05001872func (c *deviceConfig) BuildBrokenInputDir(name string) bool {
1873 return InList(name, c.config.productVariables.BuildBrokenInputDirModules)
1874}
1875
Jiyong Park3bb99242024-01-04 23:21:26 +00001876func (c *deviceConfig) BuildBrokenDontCheckSystemSdk() bool {
1877 return c.config.productVariables.BuildBrokenDontCheckSystemSdk
1878}
1879
Jiakai Zhang48203e32023-06-02 23:42:21 +01001880func (c *config) BuildWarningBadOptionalUsesLibsAllowlist() []string {
1881 return c.productVariables.BuildWarningBadOptionalUsesLibsAllowlist
1882}
1883
Yu Liu6a7940c2023-05-09 17:12:22 -07001884func (c *deviceConfig) GenruleSandboxing() bool {
1885 return Bool(c.config.productVariables.GenruleSandboxing)
Vinh Tran140d5882022-06-10 14:23:27 -04001886}
1887
Inseob Kim67e5add192021-03-17 18:05:33 +09001888func (c *deviceConfig) RequiresInsecureExecmemForSwiftshader() bool {
1889 return c.config.productVariables.RequiresInsecureExecmemForSwiftshader
1890}
1891
Devin Moorec381e102023-07-06 22:03:58 +00001892func (c *deviceConfig) Release_aidl_use_unfrozen() bool {
1893 return Bool(c.config.productVariables.Release_aidl_use_unfrozen)
1894}
1895
Inseob Kim67e5add192021-03-17 18:05:33 +09001896func (c *config) SelinuxIgnoreNeverallows() bool {
1897 return c.productVariables.SelinuxIgnoreNeverallows
1898}
1899
Inseob Kima10ef272021-09-15 03:04:53 +00001900func (c *deviceConfig) SepolicyFreezeTestExtraDirs() []string {
1901 return c.config.productVariables.SepolicyFreezeTestExtraDirs
1902}
1903
1904func (c *deviceConfig) SepolicyFreezeTestExtraPrebuiltDirs() []string {
1905 return c.config.productVariables.SepolicyFreezeTestExtraPrebuiltDirs
1906}
1907
Jiyong Parkd163d4d2021-10-12 16:47:43 +09001908func (c *deviceConfig) GenerateAidlNdkPlatformBackend() bool {
1909 return c.config.productVariables.GenerateAidlNdkPlatformBackend
1910}
1911
Christopher Ferris98f10222022-07-13 23:16:52 -07001912func (c *config) IgnorePrefer32OnDevice() bool {
1913 return c.productVariables.IgnorePrefer32OnDevice
1914}
1915
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001916func (c *config) BootJars() []string {
1917 return c.Once(earlyBootJarsKey, func() interface{} {
Paul Duffin69d1fb12020-10-23 21:14:20 +01001918 list := c.productVariables.BootJars.CopyOfJars()
satayevd604b212021-07-21 14:23:52 +01001919 return append(list, c.productVariables.ApexBootJars.CopyOfJars()...)
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001920 }).([]string)
1921}
Paul Duffin9a89a2a2020-10-28 19:20:06 +00001922
satayevd604b212021-07-21 14:23:52 +01001923func (c *config) NonApexBootJars() ConfiguredJarList {
Paul Duffin9a89a2a2020-10-28 19:20:06 +00001924 return c.productVariables.BootJars
1925}
1926
satayevd604b212021-07-21 14:23:52 +01001927func (c *config) ApexBootJars() ConfiguredJarList {
1928 return c.productVariables.ApexBootJars
Paul Duffin9a89a2a2020-10-28 19:20:06 +00001929}
Colin Cross77cdcfd2021-03-12 11:28:25 -08001930
1931func (c *config) RBEWrapper() string {
1932 return c.GetenvWithDefault("RBE_WRAPPER", remoteexec.DefaultWrapperPath)
1933}
Colin Cross9b698b62021-12-22 09:55:32 -08001934
1935// UseHostMusl returns true if the host target has been configured to build against musl libc.
1936func (c *config) UseHostMusl() bool {
1937 return Bool(c.productVariables.HostMusl)
1938}
MarkDacekff851b82022-04-21 18:33:17 +00001939
Spandan Das9e93d3d2023-03-08 05:47:29 +00001940// ApiSurfaces directory returns the source path inside the api_surfaces repo
1941// (relative to workspace root).
1942func (c *config) ApiSurfacesDir(s ApiSurface, version string) string {
1943 return filepath.Join(
1944 "build",
1945 "bazel",
1946 "api_surfaces",
1947 s.String(),
1948 version)
1949}
Jihoon Kang1bff0342023-01-17 20:40:22 +00001950
Jihoon Kang1975d3e2023-10-16 23:24:11 +00001951func (c *config) JavaCoverageEnabled() bool {
1952 return c.IsEnvTrue("EMMA_INSTRUMENT") || c.IsEnvTrue("EMMA_INSTRUMENT_STATIC") || c.IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK")
1953}
1954
Jihoon Kangc1b04d62023-11-16 19:07:04 +00001955func (c *deviceConfig) BuildFromSourceStub() bool {
1956 return Bool(c.config.productVariables.BuildFromSourceStub)
1957}
1958
Jihoon Kang1bff0342023-01-17 20:40:22 +00001959func (c *config) BuildFromTextStub() bool {
Jihoon Kang1975d3e2023-10-16 23:24:11 +00001960 // TODO: b/302320354 - Remove the coverage build specific logic once the
1961 // robust solution for handling native properties in from-text stub build
1962 // is implemented.
Jihoon Kangc1b04d62023-11-16 19:07:04 +00001963 return !c.buildFromSourceStub &&
1964 !c.JavaCoverageEnabled() &&
1965 !c.deviceConfig.BuildFromSourceStub()
Jihoon Kang1bff0342023-01-17 20:40:22 +00001966}
Spandan Das4deab282023-03-30 17:06:32 +00001967
1968func (c *config) SetBuildFromTextStub(b bool) {
Jihoon Kang2a929ad2023-06-08 19:02:07 +00001969 c.buildFromSourceStub = !b
Jihoon Kangcbcad7c2023-06-01 22:31:52 +00001970 c.productVariables.Build_from_text_stub = boolPtr(b)
Spandan Das4deab282023-03-30 17:06:32 +00001971}
Jihoon Kang1c92c3e2023-03-23 17:44:51 +00001972
Jihoon Kang1c92c3e2023-03-23 17:44:51 +00001973func (c *config) SetApiLibraries(libs []string) {
1974 c.apiLibraries = make(map[string]struct{})
1975 for _, lib := range libs {
1976 c.apiLibraries[lib] = struct{}{}
1977 }
1978}
1979
1980func (c *config) GetApiLibraries() map[string]struct{} {
1981 return c.apiLibraries
1982}
Inseob Kim5bac3b62023-08-25 21:29:46 +09001983
1984func (c *deviceConfig) CheckVendorSeappViolations() bool {
1985 return Bool(c.config.productVariables.CheckVendorSeappViolations)
1986}
Jihoon Kangcfbc4072023-09-20 01:02:18 +00001987
Inseob Kime4e85d52023-10-25 23:53:58 +09001988func (c *config) GetBuildFlag(name string) (string, bool) {
1989 val, ok := c.productVariables.BuildFlags[name]
1990 return val, ok
1991}
Spandan Dase3fcb412023-10-26 20:48:02 +00001992
Colin Cross8f1b0332024-01-25 13:39:06 -08001993func (c *config) UseResourceProcessorByDefault() bool {
1994 return c.productVariables.GetBuildFlagBool("RELEASE_USE_RESOURCE_PROCESSOR_BY_DEFAULT")
1995}
1996
Spandan Dase3fcb412023-10-26 20:48:02 +00001997var (
1998 mainlineApexContributionBuildFlags = []string{
1999 "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES",
2000 "RELEASE_APEX_CONTRIBUTIONS_APPSEARCH",
2001 "RELEASE_APEX_CONTRIBUTIONS_ART",
2002 "RELEASE_APEX_CONTRIBUTIONS_BLUETOOTH",
2003 "RELEASE_APEX_CONTRIBUTIONS_CONFIGINFRASTRUCTURE",
2004 "RELEASE_APEX_CONTRIBUTIONS_CONNECTIVITY",
2005 "RELEASE_APEX_CONTRIBUTIONS_CONSCRYPT",
2006 "RELEASE_APEX_CONTRIBUTIONS_CRASHRECOVERY",
2007 "RELEASE_APEX_CONTRIBUTIONS_DEVICELOCK",
2008 "RELEASE_APEX_CONTRIBUTIONS_HEALTHFITNESS",
2009 "RELEASE_APEX_CONTRIBUTIONS_IPSEC",
2010 "RELEASE_APEX_CONTRIBUTIONS_MEDIA",
2011 "RELEASE_APEX_CONTRIBUTIONS_MEDIAPROVIDER",
2012 "RELEASE_APEX_CONTRIBUTIONS_ONDEVICEPERSONALIZATION",
2013 "RELEASE_APEX_CONTRIBUTIONS_PERMISSION",
2014 "RELEASE_APEX_CONTRIBUTIONS_REMOTEKEYPROVISIONING",
2015 "RELEASE_APEX_CONTRIBUTIONS_SCHEDULING",
2016 "RELEASE_APEX_CONTRIBUTIONS_SDKEXTENSIONS",
2017 "RELEASE_APEX_CONTRIBUTIONS_STATSD",
2018 "RELEASE_APEX_CONTRIBUTIONS_UWB",
2019 "RELEASE_APEX_CONTRIBUTIONS_WIFI",
2020 }
2021)
2022
2023// Returns the list of _selected_ apex_contributions
2024// Each mainline module will have one entry in the list
2025func (c *config) AllApexContributions() []string {
2026 ret := []string{}
2027 for _, f := range mainlineApexContributionBuildFlags {
2028 if val, exists := c.GetBuildFlag(f); exists && val != "" {
2029 ret = append(ret, val)
2030 }
2031 }
2032 return ret
2033}