blob: 929350584b2b23358666a881bcf9ac0f6d2a72e2 [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 Cross3f40fa42015-01-30 17:27:36 -080021 "encoding/json"
22 "fmt"
23 "os"
Colin Cross35cec122015-04-02 14:37:16 -070024 "path/filepath"
Sam Delmerico5c32bbf2022-01-20 20:15:02 +000025 "reflect"
Colin Cross3f40fa42015-01-30 17:27:36 -080026 "runtime"
Inseob Kim60c32f02020-12-21 22:53:05 +090027 "strconv"
Dan Willemsen34cc69e2015-09-23 15:26:20 -070028 "strings"
Colin Crossc1e86a32015-04-15 12:33:28 -070029 "sync"
Colin Cross6ff51382015-12-17 16:39:19 -080030
Colin Cross98be1bb2019-12-13 20:41:13 -080031 "github.com/google/blueprint"
Colin Crosse87040b2017-12-11 15:52:26 -080032 "github.com/google/blueprint/bootstrap"
Colin Cross98be1bb2019-12-13 20:41:13 -080033 "github.com/google/blueprint/pathtools"
Colin Cross6ff51382015-12-17 16:39:19 -080034 "github.com/google/blueprint/proptools"
Colin Cross9d34f352019-11-22 16:03:51 -080035
36 "android/soong/android/soongconfig"
Liz Kammer09f947d2021-05-12 14:51:49 -040037 "android/soong/bazel"
Colin Cross77cdcfd2021-03-12 11:28:25 -080038 "android/soong/remoteexec"
Liz Kammer72beb342022-02-03 08:42:10 -050039 "android/soong/starlark_fmt"
Colin Cross3f40fa42015-01-30 17:27:36 -080040)
41
Jingwen Chenc711fec2020-11-22 23:52:50 -050042// Bool re-exports proptools.Bool for the android package.
Colin Cross6ff51382015-12-17 16:39:19 -080043var Bool = proptools.Bool
Jingwen Chenc711fec2020-11-22 23:52:50 -050044
45// String re-exports proptools.String for the android package.
Jack He8cc71432016-12-08 15:45:07 -080046var String = proptools.String
Jingwen Chenc711fec2020-11-22 23:52:50 -050047
48// StringDefault re-exports proptools.StringDefault for the android package.
Jeongik Cha219141c2020-08-06 23:00:37 +090049var StringDefault = proptools.StringDefault
Jiyong Park6a927c42020-01-21 02:03:43 +090050
Jingwen Chenc711fec2020-11-22 23:52:50 -050051// FutureApiLevelInt is a placeholder constant for unreleased API levels.
Dan Albert0b176c82020-07-23 16:43:25 -070052const FutureApiLevelInt = 10000
53
Spandan Das15da5882023-03-02 23:36:39 +000054// PrivateApiLevel represents the api level of SdkSpecPrivate (sdk_version: "")
55// This api_level exists to differentiate user-provided "" from "current" sdk_version
56// The differentiation is necessary to enable different validation rules for these two possible values.
57var PrivateApiLevel = ApiLevel{
58 value: "current", // The value is current since aidl expects `current` as the default (TestAidlFlagsWithMinSdkVersion)
59 number: FutureApiLevelInt + 1, // This is used to differentiate it from FutureApiLevel
60 isPreview: true,
61}
62
Jingwen Chenc711fec2020-11-22 23:52:50 -050063// FutureApiLevel represents unreleased API levels.
Dan Albert0b176c82020-07-23 16:43:25 -070064var FutureApiLevel = ApiLevel{
65 value: "current",
66 number: FutureApiLevelInt,
67 isPreview: true,
68}
Colin Cross6ff51382015-12-17 16:39:19 -080069
Jingwen Chenc4d91bc2020-11-24 22:59:26 -050070// The product variables file name, containing product config from Kati.
Dan Willemsen87b17d12015-07-14 00:39:06 -070071const productVariablesFileName = "soong.variables"
Colin Cross3f40fa42015-01-30 17:27:36 -080072
Colin Cross9272ade2016-08-17 15:24:12 -070073// A Config object represents the entire build configuration for Android.
Colin Crossc3c0a492015-04-10 15:43:55 -070074type Config struct {
75 *config
76}
77
Chris Parsonsad876012022-08-20 14:48:32 -040078type SoongBuildMode int
79
Sasha Smundakaf5ca922022-12-12 21:23:34 -080080type CmdArgs struct {
81 bootstrap.Args
Kiyoung Kima37d9ba2023-04-19 13:13:45 +090082 RunGoTests bool
83 OutDir string
84 SoongOutDir string
85 SoongVariables string
Sasha Smundakaf5ca922022-12-12 21:23:34 -080086
87 SymlinkForestMarker string
88 Bp2buildMarker string
89 BazelQueryViewDir string
Sasha Smundakaf5ca922022-12-12 21:23:34 -080090 ModuleGraphFile string
91 ModuleActionsFile string
92 DocFile string
93
LaMont Jones52a72432023-03-09 18:19:35 +000094 MultitreeBuild bool
95
Sasha Smundakaf5ca922022-12-12 21:23:34 -080096 BazelMode bool
Sasha Smundakaf5ca922022-12-12 21:23:34 -080097 BazelModeStaging bool
98 BazelForceEnabledModules string
Chris Parsons9402ca82023-02-23 17:28:06 -050099
100 UseBazelProxy bool
Jihoon Kang1bff0342023-01-17 20:40:22 +0000101
Jihoon Kang2a929ad2023-06-08 19:02:07 +0000102 BuildFromSourceStub bool
MarkDacekf47e1422023-04-19 16:47:36 +0000103
104 EnsureAllowlistIntegrity bool
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800105}
106
Chris Parsonsad876012022-08-20 14:48:32 -0400107// Build modes that soong_build can run as.
108const (
109 // Don't use bazel at all during module analysis.
110 AnalysisNoBazel SoongBuildMode = iota
111
Lukacs T. Berkic541cd22022-10-26 07:26:50 +0000112 // Symlink fores mode: merge two directory trees into a symlink forest
113 SymlinkForest
114
Chris Parsonsad876012022-08-20 14:48:32 -0400115 // Bp2build mode: Generate BUILD files from blueprint files and exit.
116 Bp2build
117
118 // Generate BUILD files which faithfully represent the dependency graph of
119 // blueprint modules. Individual BUILD targets will not, however, faitfhully
120 // express build semantics.
121 GenerateQueryView
122
123 // Create a JSON representation of the module graph and exit.
124 GenerateModuleGraph
125
126 // Generate a documentation file for module type definitions and exit.
127 GenerateDocFile
128
MarkDacekb78465d2022-10-18 20:10:16 +0000129 // Use bazel during analysis of a few allowlisted build modules. The allowlist
130 // is considered "staging, as these are modules being prepared to be released
131 // into prod mode shortly after.
132 BazelStagingMode
133
Chris Parsonsad876012022-08-20 14:48:32 -0400134 // Use bazel during analysis of build modules from an allowlist carefully
135 // curated by the build team to be proven stable.
Chris Parsonsad876012022-08-20 14:48:32 -0400136 BazelProdMode
137)
138
Lukacs T. Berkib078ade2021-08-31 10:42:08 +0200139// SoongOutDir returns the build output directory for the configuration.
Lukacs T. Berki9f6c24a2021-08-26 15:07:24 +0200140func (c Config) SoongOutDir() string {
141 return c.soongOutDir
Jeff Gastonefc1b412017-03-29 17:29:06 -0700142}
143
Lukacs T. Berki9f6c24a2021-08-26 15:07:24 +0200144func (c Config) OutDir() string {
Lukacs T. Berkid6cee7e2021-09-01 16:25:51 +0200145 return c.outDir
Lukacs T. Berki89e9a162021-03-12 08:31:32 +0100146}
147
Lukacs T. Berkiea1a31c2021-09-02 09:58:09 +0200148func (c Config) RunGoTests() bool {
149 return c.runGoTests
150}
151
Lukacs T. Berki5f6cb1d2021-03-17 15:03:14 +0100152func (c Config) DebugCompilation() bool {
153 return false // Never compile Go code in the main build for debugging
154}
155
Lukacs T. Berkiea1a31c2021-09-02 09:58:09 +0200156func (c Config) Subninjas() []string {
157 return []string{}
158}
159
160func (c Config) PrimaryBuilderInvocations() []bootstrap.PrimaryBuilderInvocation {
161 return []bootstrap.PrimaryBuilderInvocation{}
162}
163
Paul Duffin74135582022-10-06 11:01:59 +0100164// RunningInsideUnitTest returns true if this code is being run as part of a Soong unit test.
165func (c Config) RunningInsideUnitTest() bool {
166 return c.config.TestProductVariables != nil
167}
168
Pratyushfaec4db2023-07-20 11:19:04 +0000169// DisableHiddenApiChecks returns true if hiddenapi checks have been disabled.
Alyssa Ketpreechasawat7daf2782023-11-01 13:58:39 +0000170// For 'eng' target variant hiddenapi checks are disabled by default for performance optimisation,
Pratyushfaec4db2023-07-20 11:19:04 +0000171// but can be enabled by setting environment variable ENABLE_HIDDENAPI_FLAGS=true.
172// For other target variants hiddenapi check are enabled by default but can be disabled by
173// setting environment variable UNSAFE_DISABLE_HIDDENAPI_FLAGS=true.
174// If both ENABLE_HIDDENAPI_FLAGS=true and UNSAFE_DISABLE_HIDDENAPI_FLAGS=true, then
175// ENABLE_HIDDENAPI_FLAGS=true will be triggered and hiddenapi checks will be considered enabled.
176func (c Config) DisableHiddenApiChecks() bool {
177 return !c.IsEnvTrue("ENABLE_HIDDENAPI_FLAGS") &&
178 (c.IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") ||
Alyssa Ketpreechasawat7daf2782023-11-01 13:58:39 +0000179 Bool(c.productVariables.Eng))
180}
181
182// DisableVerifyOverlaps returns true if verify_overlaps is skipped.
183// Mismatch in version of apexes and module SDK is required for mainline prebuilts to work in
184// trunk stable.
185// Thus, verify_overlaps is disabled when RELEASE_DEFAULT_MODULE_BUILD_FROM_SOURCE is set to false.
186// TODO(b/308174018): Re-enable verify_overlaps for both builr from source/mainline prebuilts.
187func (c Config) DisableVerifyOverlaps() bool {
188 return c.IsEnvTrue("DISABLE_VERIFY_OVERLAPS") || !c.ReleaseDefaultModuleBuildFromSource()
Pratyushfaec4db2023-07-20 11:19:04 +0000189}
190
Juan Yescas05d4d902023-04-07 10:35:35 -0700191// MaxPageSizeSupported returns the max page size supported by the device. This
192// value will define the ELF segment alignment for binaries (executables and
193// shared libraries).
194func (c Config) MaxPageSizeSupported() string {
195 return String(c.config.productVariables.DeviceMaxPageSizeSupported)
196}
197
Vilas Bhatb3d2d222023-12-04 22:51:20 +0000198// NoBionicPageSizeMacro returns true when AOSP is page size agnostic.
199// This means that the bionic's macro PAGE_SIZE won't be defined.
200// Returns false when AOSP is NOT page size agnostic.
201// This means that bionic's macro PAGE_SIZE is defined.
202func (c Config) NoBionicPageSizeMacro() bool {
203 return Bool(c.config.productVariables.DeviceNoBionicPageSizeMacro)
Juan Yescas01065602023-08-09 08:34:37 -0700204}
205
Joe Onoratofee845a2023-05-09 08:14:14 -0700206// The release version passed to aconfig, derived from RELEASE_VERSION
207func (c Config) ReleaseVersion() string {
208 return c.config.productVariables.ReleaseVersion
209}
210
Yu Liu2cc802a2023-09-05 17:19:45 -0700211// The aconfig value set passed to aconfig, derived from RELEASE_VERSION
Yu Liueebb2592023-10-12 20:31:27 -0700212func (c Config) ReleaseAconfigValueSets() []string {
Yu Liu2cc802a2023-09-05 17:19:45 -0700213 // This logic to handle both Soong module name and bazel target is temporary in order to
Yu Liu855cfc22023-09-14 15:10:03 -0700214 // provide backward compatibility where aosp and internal both have the release
Yu Liu2cc802a2023-09-05 17:19:45 -0700215 // aconfig value set but can't be updated at the same time to use bazel target
Yu Liueebb2592023-10-12 20:31:27 -0700216 var valueSets []string
217 for _, valueSet := range c.config.productVariables.ReleaseAconfigValueSets {
218 value := strings.Split(valueSet, ":")
219 valueLen := len(value)
220 if valueLen > 2 {
221 // This shouldn't happen as this should be either a module name or a bazel target path.
222 panic(fmt.Errorf("config file: invalid value for release aconfig value sets: %s", valueSet))
223 }
224 if valueLen > 0 {
225 valueSets = append(valueSets, value[valueLen-1])
226 }
Yu Liu2cc802a2023-09-05 17:19:45 -0700227 }
Yu Liueebb2592023-10-12 20:31:27 -0700228 return valueSets
Joe Onoratofee845a2023-05-09 08:14:14 -0700229}
230
Zhi Dou3f65a412023-08-10 21:47:40 +0000231// The flag default permission value passed to aconfig
232// derived from RELEASE_ACONFIG_FLAG_DEFAULT_PERMISSION
233func (c Config) ReleaseAconfigFlagDefaultPermission() string {
234 return c.config.productVariables.ReleaseAconfigFlagDefaultPermission
235}
236
Alyssa Ketpreechasawat34ab8792023-10-06 07:01:22 +0000237// The flag indicating behavior for the tree wrt building modules or using prebuilts
238// derived from RELEASE_DEFAULT_MODULE_BUILD_FROM_SOURCE
239func (c Config) ReleaseDefaultModuleBuildFromSource() bool {
240 return c.config.productVariables.ReleaseDefaultModuleBuildFromSource == nil ||
241 Bool(c.config.productVariables.ReleaseDefaultModuleBuildFromSource)
242}
243
Aleksei Vetrov146e9822023-11-24 19:54:26 +0000244// Enables ABI monitoring of NDK libraries
245func (c Config) ReleaseNdkAbiMonitored() bool {
246 return c.config.productVariables.GetBuildFlagBool("RELEASE_NDK_ABI_MONITORED")
247}
248
Jingwen Chenc711fec2020-11-22 23:52:50 -0500249// A DeviceConfig object represents the configuration for a particular device
250// being built. For now there will only be one of these, but in the future there
251// may be multiple devices being built.
Colin Cross9272ade2016-08-17 15:24:12 -0700252type DeviceConfig struct {
253 *deviceConfig
254}
255
Jingwen Chenc711fec2020-11-22 23:52:50 -0500256// VendorConfig represents the configuration for vendor-specific behavior.
Colin Cross9d34f352019-11-22 16:03:51 -0800257type VendorConfig soongconfig.SoongConfig
Dan Willemsen0fe78662018-03-26 12:41:18 -0700258
Jingwen Chenc711fec2020-11-22 23:52:50 -0500259// Definition of general build configuration for soong_build. Some of these
Jingwen Chenc4d91bc2020-11-24 22:59:26 -0500260// product configuration values are read from Kati-generated soong.variables.
Colin Cross1332b002015-04-07 17:11:30 -0700261type config struct {
Jingwen Chenc711fec2020-11-22 23:52:50 -0500262 // Options configurable with soong.variables
Cole Faustf8231dd2023-04-21 17:37:11 -0700263 productVariables ProductVariables
Colin Cross3f40fa42015-01-30 17:27:36 -0800264
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700265 // Only available on configs created by TestConfig
Cole Faustf8231dd2023-04-21 17:37:11 -0700266 TestProductVariables *ProductVariables
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700267
Jingwen Chenc711fec2020-11-22 23:52:50 -0500268 // A specialized context object for Bazel/Soong mixed builds and migration
269 // purposes.
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400270 BazelContext BazelContext
271
Dan Willemsen87b17d12015-07-14 00:39:06 -0700272 ProductVariablesFileName string
273
Colin Cross0c66bc62021-07-20 09:47:41 -0700274 // BuildOS stores the OsType for the OS that the build is running on.
275 BuildOS OsType
276
277 // BuildArch stores the ArchType for the CPU that the build is running on.
278 BuildArch ArchType
279
Jaewoong Jung642916f2020-10-09 17:25:15 -0700280 Targets map[OsType][]Target
281 BuildOSTarget Target // the Target for tools run on the build machine
282 BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine
283 AndroidCommonTarget Target // the Target for common modules for the Android device
284 AndroidFirstDeviceTarget Target // the first Target for modules for the Android device
Dan Willemsen218f6562015-07-08 18:13:11 -0700285
Jingwen Chenc711fec2020-11-22 23:52:50 -0500286 // multilibConflicts for an ArchType is true if there is earlier configured
287 // device architecture with the same multilib value.
Colin Cross3b19f5d2019-09-17 14:45:31 -0700288 multilibConflicts map[ArchType]bool
289
Colin Cross9272ade2016-08-17 15:24:12 -0700290 deviceConfig *deviceConfig
291
Lukacs T. Berkid6cee7e2021-09-01 16:25:51 +0200292 outDir string // The output directory (usually out/)
293 soongOutDir string
Chris Parsons8f232a22020-06-23 17:37:05 -0400294 moduleListFile string // the path to the file which lists blueprint files to parse.
Colin Crossc1e86a32015-04-15 12:33:28 -0700295
Lukacs T. Berkie1df43f2021-09-08 15:31:14 +0200296 runGoTests bool
Lukacs T. Berkiea1a31c2021-09-02 09:58:09 +0200297
Colin Cross6ccbc912017-10-10 23:07:38 -0700298 env map[string]string
Dan Willemsene7680ba2015-09-11 17:06:19 -0700299 envLock sync.Mutex
300 envDeps map[string]string
301 envFrozen bool
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800302
Jingwen Chencda22c92020-11-23 00:22:30 -0500303 // Changes behavior based on whether Kati runs after soong_build, or if soong_build
304 // runs standalone.
305 katiEnabled bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700306
Colin Cross32616ed2017-09-05 21:56:44 -0700307 captureBuild bool // true for tests, saves build parameters for each module
308 ignoreEnvironment bool // true for tests, returns empty from all Getenv calls
Colin Crosscec81712017-07-13 14:43:27 -0700309
Colin Cross98be1bb2019-12-13 20:41:13 -0800310 fs pathtools.FileSystem
311 mockBpList string
312
Chris Parsonsad876012022-08-20 14:48:32 -0400313 BuildMode SoongBuildMode
Cole Faust324a92e2022-08-23 15:29:05 -0700314 Bp2buildPackageConfig Bp2BuildConversionAllowlist
Jingwen Chen01812022021-11-19 14:29:43 +0000315 Bp2buildSoongConfigDefinitions soongconfig.Bp2BuildSoongConfigDefinitions
Jingwen Chen12b4c272021-03-10 02:05:59 -0500316
LaMont Jones52a72432023-03-09 18:19:35 +0000317 // If MultitreeBuild is true then this is one inner tree of a multitree
318 // build directed by the multitree orchestrator.
319 MultitreeBuild bool
320
Colin Cross5e6a7972020-06-07 16:56:32 -0700321 // If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error
322 // in tests when a path doesn't exist.
Pedro Loureiro5d190cc2021-02-15 15:41:33 +0000323 TestAllowNonExistentPaths bool
Colin Cross5e6a7972020-06-07 16:56:32 -0700324
Jingwen Chenc711fec2020-11-22 23:52:50 -0500325 // The list of files that when changed, must invalidate soong_build to
326 // regenerate build.ninja.
Colin Cross12129292020-10-29 18:23:58 -0700327 ninjaFileDepsSet sync.Map
328
Colin Cross9272ade2016-08-17 15:24:12 -0700329 OncePer
MarkDacekff851b82022-04-21 18:33:17 +0000330
Chris Parsonsad876012022-08-20 14:48:32 -0400331 // These fields are only used for metrics collection. A module should be added
332 // to these maps only if its implementation supports Bazel handling in mixed
333 // builds. A module being in the "enabled" list indicates that there is a
334 // variant of that module for which bazel-handling actually took place.
335 // A module being in the "disabled" list indicates that there is a variant of
336 // that module for which bazel-handling was denied.
MarkDacekff851b82022-04-21 18:33:17 +0000337 mixedBuildsLock sync.Mutex
338 mixedBuildEnabledModules map[string]struct{}
339 mixedBuildDisabledModules map[string]struct{}
MarkDacekd06db5d2022-11-29 00:47:59 +0000340
341 // These are modules to be built with Bazel beyond the allowlisted/build-mode
342 // specified modules. They are passed via the command-line flag
343 // "--bazel-force-enabled-modules"
344 bazelForceEnabledModules map[string]struct{}
Chris Parsons9402ca82023-02-23 17:28:06 -0500345
Chris Parsons8152a942023-06-06 16:17:50 +0000346 // Names of Bazel targets as defined by BUILD files in the source tree,
347 // keyed by the directory in which they are defined.
348 bazelTargetsByDir map[string][]string
349
Chris Parsons9402ca82023-02-23 17:28:06 -0500350 // If true, for any requests to Bazel, communicate with a Bazel proxy using
351 // unix sockets, instead of spawning Bazel as a subprocess.
352 UseBazelProxy bool
Jihoon Kang1bff0342023-01-17 20:40:22 +0000353
Jihoon Kang2a929ad2023-06-08 19:02:07 +0000354 // If buildFromSourceStub is true then the Java API stubs are
355 // built from the source Java files, not the signature text files.
356 buildFromSourceStub bool
MarkDacekf47e1422023-04-19 16:47:36 +0000357
358 // If ensureAllowlistIntegrity is true, then the presence of any allowlisted
359 // modules that aren't mixed-built for at least one variant will cause a build
360 // failure
361 ensureAllowlistIntegrity bool
Jihoon Kang1c92c3e2023-03-23 17:44:51 +0000362
363 // List of Api libraries that contribute to Api surfaces.
364 apiLibraries map[string]struct{}
Colin Cross9272ade2016-08-17 15:24:12 -0700365}
366
367type deviceConfig struct {
Dan Willemsen00269f22017-07-06 16:59:48 -0700368 config *config
Colin Cross9272ade2016-08-17 15:24:12 -0700369 OncePer
Colin Cross3f40fa42015-01-30 17:27:36 -0800370}
371
Colin Cross485e5722015-08-27 13:28:01 -0700372type jsonConfigurable interface {
Colin Cross27385972015-09-18 10:57:10 -0700373 SetDefaultConfig()
Colin Cross485e5722015-08-27 13:28:01 -0700374}
Colin Cross3f40fa42015-01-30 17:27:36 -0800375
Colin Cross485e5722015-08-27 13:28:01 -0700376func loadConfig(config *config) error {
Colin Cross988414c2020-01-11 01:11:46 +0000377 return loadFromConfigFile(&config.productVariables, absolutePath(config.ProductVariablesFileName))
Colin Cross485e5722015-08-27 13:28:01 -0700378}
379
Jingwen Chenc711fec2020-11-22 23:52:50 -0500380// loadFromConfigFile loads and decodes configuration options from a JSON file
381// in the current working directory.
Cole Faustf8231dd2023-04-21 17:37:11 -0700382func loadFromConfigFile(configurable *ProductVariables, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800383 // Try to open the file
Colin Cross485e5722015-08-27 13:28:01 -0700384 configFileReader, err := os.Open(filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800385 defer configFileReader.Close()
386 if os.IsNotExist(err) {
387 // Need to create a file, so that blueprint & ninja don't get in
388 // a dependency tracking loop.
389 // Make a file-configurable-options with defaults, write it out using
390 // a json writer.
Colin Cross27385972015-09-18 10:57:10 -0700391 configurable.SetDefaultConfig()
392 err = saveToConfigFile(configurable, filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800393 if err != nil {
394 return err
395 }
Colin Cross15cd21a2018-02-27 11:26:02 -0800396 } else if err != nil {
397 return fmt.Errorf("config file: could not open %s: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800398 } else {
399 // Make a decoder for it
400 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700401 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800402 if err != nil {
Colin Cross15cd21a2018-02-27 11:26:02 -0800403 return fmt.Errorf("config file: %s did not parse correctly: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800404 }
405 }
406
Liz Kammer09f947d2021-05-12 14:51:49 -0400407 if Bool(configurable.GcovCoverage) && Bool(configurable.ClangCoverage) {
408 return fmt.Errorf("GcovCoverage and ClangCoverage cannot both be set")
409 }
410
411 configurable.Native_coverage = proptools.BoolPtr(
412 Bool(configurable.GcovCoverage) ||
413 Bool(configurable.ClangCoverage))
414
Yuntao Xu402e9b02021-08-09 15:44:44 -0700415 // when Platform_sdk_final is true (or PLATFORM_VERSION_CODENAME is REL), use Platform_sdk_version;
416 // if false (pre-released version, for example), use Platform_sdk_codename.
417 if Bool(configurable.Platform_sdk_final) {
418 if configurable.Platform_sdk_version != nil {
419 configurable.Platform_sdk_version_or_codename =
420 proptools.StringPtr(strconv.Itoa(*(configurable.Platform_sdk_version)))
421 } else {
422 return fmt.Errorf("Platform_sdk_version cannot be pointed by a NULL pointer")
423 }
424 } else {
425 configurable.Platform_sdk_version_or_codename =
426 proptools.StringPtr(String(configurable.Platform_sdk_codename))
427 }
428
Liz Kammer09f947d2021-05-12 14:51:49 -0400429 return saveToBazelConfigFile(configurable, filepath.Dir(filename))
Colin Cross3f40fa42015-01-30 17:27:36 -0800430}
431
Colin Crossd8f20142016-11-03 09:43:26 -0700432// atomically writes the config file in case two copies of soong_build are running simultaneously
433// (for example, docs generation and ninja manifest generation)
Cole Faustf8231dd2023-04-21 17:37:11 -0700434func saveToConfigFile(config *ProductVariables, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800435 data, err := json.MarshalIndent(&config, "", " ")
436 if err != nil {
437 return fmt.Errorf("cannot marshal config data: %s", err.Error())
438 }
439
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800440 f, err := os.CreateTemp(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800441 if err != nil {
Jingwen Chenc711fec2020-11-22 23:52:50 -0500442 return fmt.Errorf("cannot create empty config file %s: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800443 }
Colin Crossd8f20142016-11-03 09:43:26 -0700444 defer os.Remove(f.Name())
445 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800446
Colin Crossd8f20142016-11-03 09:43:26 -0700447 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800448 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700449 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
450 }
451
Colin Crossd8f20142016-11-03 09:43:26 -0700452 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700453 if err != nil {
454 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800455 }
456
Colin Crossd8f20142016-11-03 09:43:26 -0700457 f.Close()
458 os.Rename(f.Name(), filename)
459
Colin Cross3f40fa42015-01-30 17:27:36 -0800460 return nil
461}
462
Cole Faust87c0c332023-07-31 12:10:12 -0700463type productVariableStarlarkRepresentation struct {
464 soongType string
465 selectable bool
466 archVariant bool
467}
468
Cole Faustf8231dd2023-04-21 17:37:11 -0700469func saveToBazelConfigFile(config *ProductVariables, outDir string) error {
Liz Kammer09f947d2021-05-12 14:51:49 -0400470 dir := filepath.Join(outDir, bazel.SoongInjectionDirName, "product_config")
471 err := createDirIfNonexistent(dir, os.ModePerm)
472 if err != nil {
473 return fmt.Errorf("Could not create dir %s: %s", dir, err)
474 }
475
Cole Faust87c0c332023-07-31 12:10:12 -0700476 allProductVariablesType := reflect.TypeOf((*ProductVariables)(nil)).Elem()
477 productVariablesInfo := make(map[string]productVariableStarlarkRepresentation)
Sam Delmerico5c32bbf2022-01-20 20:15:02 +0000478 p := variableProperties{}
479 t := reflect.TypeOf(p.Product_variables)
480 for i := 0; i < t.NumField(); i++ {
481 f := t.Field(i)
Cole Faust87c0c332023-07-31 12:10:12 -0700482 archVariant := proptools.HasTag(f, "android", "arch_variant")
483 if mainProductVariablesStructField, ok := allProductVariablesType.FieldByName(f.Name); ok {
484 productVariablesInfo[f.Name] = productVariableStarlarkRepresentation{
485 soongType: stringRepresentationOfSimpleType(mainProductVariablesStructField.Type),
486 selectable: true,
487 archVariant: archVariant,
488 }
489 } else {
490 panic("Unknown variable " + f.Name)
Sam Delmerico5c32bbf2022-01-20 20:15:02 +0000491 }
492 }
493
Cole Fausteb644cf2023-04-11 13:48:17 -0700494 err = pathtools.WriteFileIfChanged(filepath.Join(dir, "product_variable_constants.bzl"), []byte(fmt.Sprintf(`
Cole Faust87c0c332023-07-31 12:10:12 -0700495# product_var_constant_info is a map of product variables to information about them. The fields are:
496# - soongType: The type of the product variable as it appears in soong's ProductVariables struct.
497# examples are string, bool, int, *bool, *string, []string, etc. This may be an overly
498# conservative estimation of the type, for example a *bool could oftentimes just be a
499# bool that defaults to false.
500# - selectable: if this product variable can be selected on in Android.bp/build files. This means
501# it's listed in the "variableProperties" soong struct. Currently all variables in
502# this list are selectable because we only need the selectable ones at the moment,
503# but the list may be expanded later.
504# - archVariant: If the variable is tagged as arch variant in the "variableProperties" struct.
505product_var_constant_info = %s
506product_var_constraints = [k for k, v in product_var_constant_info.items() if v.selectable]
507arch_variant_product_var_constraints = [k for k, v in product_var_constant_info.items() if v.selectable and v.archVariant]
508`, starlark_fmt.PrintAny(productVariablesInfo, 0))), 0644)
Cole Fausteb644cf2023-04-11 13:48:17 -0700509 if err != nil {
510 return fmt.Errorf("Could not write .bzl config file %s", err)
511 }
Chris Parsons0008cf82023-02-03 18:45:43 -0500512 err = pathtools.WriteFileIfChanged(filepath.Join(dir, "BUILD"),
513 []byte(bazel.GeneratedBazelFileWarning), 0644)
Liz Kammer09f947d2021-05-12 14:51:49 -0400514 if err != nil {
515 return fmt.Errorf("Could not write BUILD config file %s", err)
516 }
517
518 return nil
519}
520
Cole Faust87c0c332023-07-31 12:10:12 -0700521func stringRepresentationOfSimpleType(ty reflect.Type) string {
522 switch ty.Kind() {
523 case reflect.String:
524 return "string"
525 case reflect.Bool:
526 return "bool"
527 case reflect.Int:
528 return "int"
529 case reflect.Slice:
530 return "[]" + stringRepresentationOfSimpleType(ty.Elem())
531 case reflect.Pointer:
532 return "*" + stringRepresentationOfSimpleType(ty.Elem())
533 default:
534 panic("unimplemented type: " + ty.Kind().String())
535 }
536}
537
Colin Cross988414c2020-01-11 01:11:46 +0000538// NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that
539// use the android package.
Lukacs T. Berkid6cee7e2021-09-01 16:25:51 +0200540func NullConfig(outDir, soongOutDir string) Config {
Colin Cross988414c2020-01-11 01:11:46 +0000541 return Config{
542 config: &config{
Lukacs T. Berkid6cee7e2021-09-01 16:25:51 +0200543 outDir: outDir,
Lukacs T. Berki9f6c24a2021-08-26 15:07:24 +0200544 soongOutDir: soongOutDir,
545 fs: pathtools.OsFs,
Colin Cross988414c2020-01-11 01:11:46 +0000546 },
547 }
548}
549
Jingwen Chenc711fec2020-11-22 23:52:50 -0500550// NewConfig creates a new Config object. The srcDir argument specifies the path
551// to the root source directory. It also loads the config file, if found.
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800552func NewConfig(cmdArgs CmdArgs, availableEnv map[string]string) (Config, error) {
Jingwen Chenc711fec2020-11-22 23:52:50 -0500553 // Make a config with default options.
Colin Cross9272ade2016-08-17 15:24:12 -0700554 config := &config{
Kiyoung Kima37d9ba2023-04-19 13:13:45 +0900555 ProductVariablesFileName: cmdArgs.SoongVariables,
Dan Willemsen87b17d12015-07-14 00:39:06 -0700556
Lukacs T. Berki53b2f362021-04-12 14:04:24 +0200557 env: availableEnv,
Colin Cross6ccbc912017-10-10 23:07:38 -0700558
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800559 outDir: cmdArgs.OutDir,
560 soongOutDir: cmdArgs.SoongOutDir,
561 runGoTests: cmdArgs.RunGoTests,
Lukacs T. Berkie1df43f2021-09-08 15:31:14 +0200562 multilibConflicts: make(map[ArchType]bool),
Colin Cross98be1bb2019-12-13 20:41:13 -0800563
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800564 moduleListFile: cmdArgs.ModuleListFile,
MarkDacekff851b82022-04-21 18:33:17 +0000565 fs: pathtools.NewOsFs(absSrcDir),
566 mixedBuildDisabledModules: make(map[string]struct{}),
567 mixedBuildEnabledModules: make(map[string]struct{}),
MarkDacekd06db5d2022-11-29 00:47:59 +0000568 bazelForceEnabledModules: make(map[string]struct{}),
Chris Parsons9402ca82023-02-23 17:28:06 -0500569
LaMont Jones52a72432023-03-09 18:19:35 +0000570 MultitreeBuild: cmdArgs.MultitreeBuild,
571 UseBazelProxy: cmdArgs.UseBazelProxy,
Jihoon Kang1bff0342023-01-17 20:40:22 +0000572
Jihoon Kang2a929ad2023-06-08 19:02:07 +0000573 buildFromSourceStub: cmdArgs.BuildFromSourceStub,
Colin Cross68f55102015-03-25 14:43:57 -0700574 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800575
Dan Willemsen00269f22017-07-06 16:59:48 -0700576 config.deviceConfig = &deviceConfig{
Colin Cross9272ade2016-08-17 15:24:12 -0700577 config: config,
578 }
579
Liz Kammer7941b302020-07-28 13:27:34 -0700580 // Soundness check of the build and source directories. This won't catch strange
581 // configurations with symlinks, but at least checks the obvious case.
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800582 absBuildDir, err := filepath.Abs(cmdArgs.SoongOutDir)
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700583 if err != nil {
584 return Config{}, err
585 }
586
Lukacs T. Berkif7e36d82021-08-16 17:05:09 +0200587 absSrcDir, err := filepath.Abs(".")
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700588 if err != nil {
589 return Config{}, err
590 }
591
592 if strings.HasPrefix(absSrcDir, absBuildDir) {
593 return Config{}, fmt.Errorf("Build dir must not contain source directory")
594 }
595
Colin Cross3f40fa42015-01-30 17:27:36 -0800596 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700597 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800598 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700599 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800600 }
601
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800602 KatiEnabledMarkerFile := filepath.Join(cmdArgs.SoongOutDir, ".soong.kati_enabled")
Jingwen Chencda22c92020-11-23 00:22:30 -0500603 if _, err := os.Stat(absolutePath(KatiEnabledMarkerFile)); err == nil {
604 config.katiEnabled = true
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800605 }
606
Colin Cross0c66bc62021-07-20 09:47:41 -0700607 determineBuildOS(config)
608
Jingwen Chenc711fec2020-11-22 23:52:50 -0500609 // Sets up the map of target OSes to the finer grained compilation targets
610 // that are configured from the product variables.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700611 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700612 if err != nil {
613 return Config{}, err
614 }
615
Paul Duffin1356d8c2020-02-25 19:26:33 +0000616 // Make the CommonOS OsType available for all products.
617 targets[CommonOS] = []Target{commonTargetMap[CommonOS.Name]}
618
Dan Albert4098deb2016-10-19 14:04:41 -0700619 var archConfig []archConfig
Jingwen Chenc4d91bc2020-11-24 22:59:26 -0500620 if config.NdkAbis() {
Dan Albert4098deb2016-10-19 14:04:41 -0700621 archConfig = getNdkAbisConfig()
Martin Stjernholmc1ecc432019-11-15 15:00:31 +0000622 } else if config.AmlAbis() {
623 archConfig = getAmlAbisConfig()
Dan Albert4098deb2016-10-19 14:04:41 -0700624 }
625
626 if archConfig != nil {
Liz Kammerb7f33662022-02-28 14:16:16 -0500627 androidTargets, err := decodeAndroidArchSettings(archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800628 if err != nil {
629 return Config{}, err
630 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700631 targets[Android] = androidTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800632 }
633
Colin Cross3b19f5d2019-09-17 14:45:31 -0700634 multilib := make(map[string]bool)
635 for _, target := range targets[Android] {
636 if seen := multilib[target.Arch.ArchType.Multilib]; seen {
637 config.multilibConflicts[target.Arch.ArchType] = true
638 }
639 multilib[target.Arch.ArchType.Multilib] = true
640 }
641
Jingwen Chenc711fec2020-11-22 23:52:50 -0500642 // Map of OS to compilation targets.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700643 config.Targets = targets
Jingwen Chenc711fec2020-11-22 23:52:50 -0500644
645 // Compilation targets for host tools.
Colin Cross0c66bc62021-07-20 09:47:41 -0700646 config.BuildOSTarget = config.Targets[config.BuildOS][0]
647 config.BuildOSCommonTarget = getCommonTargets(config.Targets[config.BuildOS])[0]
Jingwen Chenc711fec2020-11-22 23:52:50 -0500648
649 // Compilation targets for Android.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700650 if len(config.Targets[Android]) > 0 {
651 config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
Sam Delmericocc271e22022-06-01 15:45:02 +0000652 config.AndroidFirstDeviceTarget = FirstTarget(config.Targets[Android], "lib64", "lib32")[0]
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700653 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700654
Usta Shresthacae3bfa2022-12-21 11:44:26 -0500655 setBuildMode := func(arg string, mode SoongBuildMode) {
656 if arg != "" {
657 if config.BuildMode != AnalysisNoBazel {
658 fmt.Fprintf(os.Stderr, "buildMode is already set, illegal argument: %s", arg)
659 os.Exit(1)
660 }
661 config.BuildMode = mode
662 }
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800663 }
Usta Shresthacae3bfa2022-12-21 11:44:26 -0500664 setBazelMode := func(arg bool, argName string, mode SoongBuildMode) {
665 if arg {
666 if config.BuildMode != AnalysisNoBazel {
667 fmt.Fprintf(os.Stderr, "buildMode is already set, illegal argument: %s", argName)
668 os.Exit(1)
669 }
670 config.BuildMode = mode
671 }
672 }
673 setBuildMode(cmdArgs.SymlinkForestMarker, SymlinkForest)
674 setBuildMode(cmdArgs.Bp2buildMarker, Bp2build)
675 setBuildMode(cmdArgs.BazelQueryViewDir, GenerateQueryView)
Usta Shresthacae3bfa2022-12-21 11:44:26 -0500676 setBuildMode(cmdArgs.ModuleGraphFile, GenerateModuleGraph)
677 setBuildMode(cmdArgs.DocFile, GenerateDocFile)
Usta Shresthacae3bfa2022-12-21 11:44:26 -0500678 setBazelMode(cmdArgs.BazelMode, "--bazel-mode", BazelProdMode)
679 setBazelMode(cmdArgs.BazelModeStaging, "--bazel-mode-staging", BazelStagingMode)
Sasha Smundakaf5ca922022-12-12 21:23:34 -0800680
MarkDacek1de78f32023-05-02 21:00:48 +0000681 for _, module := range getForceEnabledModulesFromFlag(cmdArgs.BazelForceEnabledModules) {
MarkDacekd06db5d2022-11-29 00:47:59 +0000682 config.bazelForceEnabledModules[module] = struct{}{}
683 }
MarkDacek9c094ca2023-03-16 19:15:19 +0000684 config.BazelContext, err = NewBazelContext(config)
685 config.Bp2buildPackageConfig = GetBp2BuildAllowList()
MarkDacekd06db5d2022-11-29 00:47:59 +0000686
Jihoon Kang1c92c3e2023-03-23 17:44:51 +0000687 // TODO(b/276958307): Replace the hardcoded list to a sdk_library local prop.
688 config.apiLibraries = map[string]struct{}{
689 "android.net.ipsec.ike": {},
690 "art.module.public.api": {},
691 "conscrypt.module.public.api": {},
692 "framework-adservices": {},
693 "framework-appsearch": {},
694 "framework-bluetooth": {},
695 "framework-connectivity": {},
696 "framework-connectivity-t": {},
697 "framework-graphics": {},
Mark White387a6582023-08-06 00:20:47 +0000698 "framework-location": {},
Jihoon Kang1c92c3e2023-03-23 17:44:51 +0000699 "framework-media": {},
700 "framework-mediaprovider": {},
Roshan Pius92307ff2023-11-13 17:16:35 -0800701 "framework-nfc": {},
Jihoon Kang1c92c3e2023-03-23 17:44:51 +0000702 "framework-ondevicepersonalization": {},
Alyssa Ketpreechasawat9f634362023-11-08 16:03:53 +0000703 "framework-pdf": {},
Jihoon Kang1c92c3e2023-03-23 17:44:51 +0000704 "framework-permission": {},
705 "framework-permission-s": {},
706 "framework-scheduling": {},
707 "framework-sdkextensions": {},
708 "framework-statsd": {},
709 "framework-sdksandbox": {},
710 "framework-tethering": {},
711 "framework-uwb": {},
712 "framework-virtualization": {},
713 "framework-wifi": {},
714 "i18n.module.public.api": {},
715 }
716
Jihoon Kangc1b04d62023-11-16 19:07:04 +0000717 config.productVariables.Build_from_text_stub = boolPtr(config.BuildFromTextStub())
718
Jingwen Chenc711fec2020-11-22 23:52:50 -0500719 return Config{config}, err
720}
Colin Cross988414c2020-01-11 01:11:46 +0000721
MarkDacek1de78f32023-05-02 21:00:48 +0000722func getForceEnabledModulesFromFlag(forceEnabledFlag string) []string {
723 if forceEnabledFlag == "" {
724 return []string{}
725 }
726 return strings.Split(forceEnabledFlag, ",")
727}
728
Colin Cross98be1bb2019-12-13 20:41:13 -0800729// mockFileSystem replaces all reads with accesses to the provided map of
730// filenames to contents stored as a byte slice.
731func (c *config) mockFileSystem(bp string, fs map[string][]byte) {
732 mockFS := map[string][]byte{}
733
734 if _, exists := mockFS["Android.bp"]; !exists {
735 mockFS["Android.bp"] = []byte(bp)
736 }
737
738 for k, v := range fs {
739 mockFS[k] = v
740 }
741
742 // no module list file specified; find every file named Blueprints or Android.bp
743 pathsToParse := []string{}
744 for candidate := range mockFS {
745 base := filepath.Base(candidate)
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200746 if base == "Android.bp" {
Colin Cross98be1bb2019-12-13 20:41:13 -0800747 pathsToParse = append(pathsToParse, candidate)
748 }
749 }
750 if len(pathsToParse) < 1 {
751 panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", mockFS))
752 }
753 mockFS[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n"))
754
755 c.fs = pathtools.MockFs(mockFS)
756 c.mockBpList = blueprint.MockModuleListFile
757}
758
Jason Wuff1bb312022-12-21 09:57:26 -0500759// TODO(b/265062549): Add a field to our collected (and uploaded) metrics which
760// describes a reason that we fell back to non-mixed builds.
Chris Parsonsad876012022-08-20 14:48:32 -0400761// Returns true if "Bazel builds" is enabled. In this mode, part of build
762// analysis is handled by Bazel.
763func (c *config) IsMixedBuildsEnabled() bool {
Chris Parsons428c30f2022-11-29 14:14:52 -0500764 globalMixedBuildsSupport := c.Once(OnceKey{"globalMixedBuildsSupport"}, func() interface{} {
765 if c.productVariables.DeviceArch != nil && *c.productVariables.DeviceArch == "riscv64" {
Chris Parsons428c30f2022-11-29 14:14:52 -0500766 return false
767 }
Liz Kammer36ba6b22023-06-29 10:18:39 -0400768 // Disable Bazel when Kythe is running
769 if c.EmitXrefRules() {
770 return false
771 }
Sam Delmerico5150d0d2022-11-15 17:44:44 -0500772 if c.IsEnvTrue("GLOBAL_THINLTO") {
Sam Delmerico5150d0d2022-11-15 17:44:44 -0500773 return false
774 }
Sam Delmerico5150d0d2022-11-15 17:44:44 -0500775 if len(c.productVariables.SanitizeHost) > 0 {
Sam Delmerico5150d0d2022-11-15 17:44:44 -0500776 return false
777 }
778 if len(c.productVariables.SanitizeDevice) > 0 {
Sam Delmerico5150d0d2022-11-15 17:44:44 -0500779 return false
780 }
781 if len(c.productVariables.SanitizeDeviceDiag) > 0 {
Sam Delmerico5150d0d2022-11-15 17:44:44 -0500782 return false
783 }
784 if len(c.productVariables.SanitizeDeviceArch) > 0 {
Sam Delmerico5150d0d2022-11-15 17:44:44 -0500785 return false
786 }
Chris Parsons428c30f2022-11-29 14:14:52 -0500787 return true
788 }).(bool)
789
Chris Parsons21f80272023-06-15 04:02:28 +0000790 bazelModeEnabled := c.BuildMode == BazelProdMode || c.BuildMode == BazelStagingMode
Chris Parsons428c30f2022-11-29 14:14:52 -0500791 return globalMixedBuildsSupport && bazelModeEnabled
Chris Parsonsad876012022-08-20 14:48:32 -0400792}
793
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +0100794func (c *config) SetAllowMissingDependencies() {
795 c.productVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
796}
797
Jingwen Chenc711fec2020-11-22 23:52:50 -0500798// BlueprintToolLocation returns the directory containing build system tools
799// from Blueprint, like soong_zip and merge_zips.
Lukacs T. Berkia806e412021-09-01 08:57:48 +0200800func (c *config) HostToolDir() string {
Colin Crossacfcc1f2021-10-25 15:40:32 -0700801 if c.KatiEnabled() {
802 return filepath.Join(c.outDir, "host", c.PrebuiltOS(), "bin")
803 } else {
804 return filepath.Join(c.soongOutDir, "host", c.PrebuiltOS(), "bin")
805 }
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700806}
807
Dan Willemsen60e62f02018-11-16 21:05:32 -0800808func (c *config) HostToolPath(ctx PathContext, tool string) Path {
Cole Faust3b703f32023-10-16 13:30:51 -0700809 path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "bin", tool)
Colin Cross790ef352021-10-25 19:15:55 -0700810 return path
Dan Willemsen60e62f02018-11-16 21:05:32 -0800811}
812
Colin Cross790ef352021-10-25 19:15:55 -0700813func (c *config) HostJNIToolPath(ctx PathContext, lib string) Path {
Martin Stjernholm7260d062019-12-09 21:47:14 +0000814 ext := ".so"
815 if runtime.GOOS == "darwin" {
816 ext = ".dylib"
817 }
Cole Faust3b703f32023-10-16 13:30:51 -0700818 path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "lib64", lib+ext)
Colin Cross790ef352021-10-25 19:15:55 -0700819 return path
Martin Stjernholm7260d062019-12-09 21:47:14 +0000820}
821
Colin Crossae5330a2021-11-03 13:31:22 -0700822func (c *config) HostJavaToolPath(ctx PathContext, tool string) Path {
Cole Faust3b703f32023-10-16 13:30:51 -0700823 path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "framework", tool)
Colin Cross3e3eda62021-11-04 10:22:51 -0700824 return path
825}
826
Vinh Tran09581952023-05-16 16:03:20 -0400827func (c *config) HostCcSharedLibPath(ctx PathContext, lib string) Path {
828 libDir := "lib"
829 if ctx.Config().BuildArch.Multilib == "lib64" {
830 libDir = "lib64"
831 }
Cole Faust3b703f32023-10-16 13:30:51 -0700832 return pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, libDir, lib+".so")
Vinh Tran09581952023-05-16 16:03:20 -0400833}
834
Jingwen Chenc711fec2020-11-22 23:52:50 -0500835// PrebuiltOS returns the name of the host OS used in prebuilts directories.
Colin Cross1332b002015-04-07 17:11:30 -0700836func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800837 switch runtime.GOOS {
838 case "linux":
839 return "linux-x86"
840 case "darwin":
841 return "darwin-x86"
842 default:
843 panic("Unknown GOOS")
844 }
845}
846
847// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700848func (c *config) GoRoot() string {
Lukacs T. Berkif7e36d82021-08-16 17:05:09 +0200849 return fmt.Sprintf("prebuilts/go/%s", c.PrebuiltOS())
Colin Cross3f40fa42015-01-30 17:27:36 -0800850}
851
Jingwen Chenc711fec2020-11-22 23:52:50 -0500852// PrebuiltBuildTool returns the path to a tool in the prebuilts directory containing
853// checked-in tools, like Kati, Ninja or Toybox, for the current host OS.
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700854func (c *config) PrebuiltBuildTool(ctx PathContext, tool string) Path {
855 return PathForSource(ctx, "prebuilts/build-tools", c.PrebuiltOS(), "bin", tool)
856}
857
Jingwen Chenc711fec2020-11-22 23:52:50 -0500858// CpPreserveSymlinksFlags returns the host-specific flag for the cp(1) command
859// to preserve symlinks.
Colin Cross1332b002015-04-07 17:11:30 -0700860func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700861 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800862 case "darwin":
863 return "-R"
864 case "linux":
865 return "-d"
866 default:
867 return ""
868 }
869}
Colin Cross68f55102015-03-25 14:43:57 -0700870
Colin Cross1332b002015-04-07 17:11:30 -0700871func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700872 var val string
873 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700874 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800875 defer c.envLock.Unlock()
876 if c.envDeps == nil {
877 c.envDeps = make(map[string]string)
878 }
Colin Cross68f55102015-03-25 14:43:57 -0700879 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700880 if c.envFrozen {
881 panic("Cannot access new environment variables after envdeps are frozen")
882 }
Colin Cross6ccbc912017-10-10 23:07:38 -0700883 val, _ = c.env[key]
Colin Cross68f55102015-03-25 14:43:57 -0700884 c.envDeps[key] = val
885 }
886 return val
887}
888
Colin Cross99d7c232016-11-23 16:52:04 -0800889func (c *config) GetenvWithDefault(key string, defaultValue string) string {
890 ret := c.Getenv(key)
891 if ret == "" {
892 return defaultValue
893 }
894 return ret
895}
896
897func (c *config) IsEnvTrue(key string) bool {
898 value := c.Getenv(key)
899 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
900}
901
902func (c *config) IsEnvFalse(key string) bool {
903 value := c.Getenv(key)
904 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
905}
906
Jingwen Chenc711fec2020-11-22 23:52:50 -0500907// EnvDeps returns the environment variables this build depends on. The first
908// call to this function blocks future reads from the environment.
Colin Cross1332b002015-04-07 17:11:30 -0700909func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700910 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800911 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700912 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700913 return c.envDeps
914}
Colin Cross35cec122015-04-02 14:37:16 -0700915
Jingwen Chencda22c92020-11-23 00:22:30 -0500916func (c *config) KatiEnabled() bool {
917 return c.katiEnabled
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800918}
919
Cole Faust11edf552023-10-13 11:32:14 -0700920func (c *config) ProductVariables() ProductVariables {
921 return c.productVariables
922}
923
Nan Zhang581fd212018-01-10 16:06:12 -0800924func (c *config) BuildId() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800925 return String(c.productVariables.BuildId)
Nan Zhang581fd212018-01-10 16:06:12 -0800926}
927
Jingwen Chenc711fec2020-11-22 23:52:50 -0500928// BuildNumberFile returns the path to a text file containing metadata
929// representing the current build's number.
930//
931// Rules that want to reference the build number should read from this file
932// without depending on it. They will run whenever their other dependencies
933// require them to run and get the current build number. This ensures they don't
934// rebuild on every incremental build when the build number changes.
Colin Cross2a2e0db2020-02-21 16:55:46 -0800935func (c *config) BuildNumberFile(ctx PathContext) Path {
936 return PathForOutput(ctx, String(c.productVariables.BuildNumberFile))
Nan Zhang581fd212018-01-10 16:06:12 -0800937}
938
Jingwen Chenc711fec2020-11-22 23:52:50 -0500939// DeviceName returns the name of the current device target.
Colin Cross35cec122015-04-02 14:37:16 -0700940// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700941func (c *config) DeviceName() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800942 return *c.productVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700943}
944
Trevor Radcliffe90727f42022-03-21 19:34:02 +0000945// DeviceProduct returns the current product target. There could be multiple of
946// these per device type.
947//
Chris Parsonsef615e52022-08-18 22:04:11 -0400948// NOTE: Do not base conditional logic on this value. It may break product inheritance.
Trevor Radcliffe90727f42022-03-21 19:34:02 +0000949func (c *config) DeviceProduct() string {
950 return *c.productVariables.DeviceProduct
951}
952
Cole Faustb85d1a12022-11-08 18:14:01 -0800953// HasDeviceProduct returns if the build has a product. A build will not
954// necessarily have a product when --skip-config is passed to soong, like it is
955// in prebuilts/build-tools/build-prebuilts.sh
956func (c *config) HasDeviceProduct() bool {
957 return c.productVariables.DeviceProduct != nil
958}
959
Anton Hansson53c88442019-03-18 15:53:16 +0000960func (c *config) DeviceResourceOverlays() []string {
961 return c.productVariables.DeviceResourceOverlays
962}
963
964func (c *config) ProductResourceOverlays() []string {
965 return c.productVariables.ProductResourceOverlays
Colin Cross30e076a2015-04-13 13:58:27 -0700966}
967
Colin Crossbfd347d2018-05-09 11:11:35 -0700968func (c *config) PlatformVersionName() string {
969 return String(c.productVariables.Platform_version_name)
970}
971
Dan Albert4f378d72020-07-23 17:32:15 -0700972func (c *config) PlatformSdkVersion() ApiLevel {
973 return uncheckedFinalApiLevel(*c.productVariables.Platform_sdk_version)
Colin Cross30e076a2015-04-13 13:58:27 -0700974}
975
Cole Faust37d27c42023-04-12 10:27:45 -0700976func (c *config) RawPlatformSdkVersion() *int {
977 return c.productVariables.Platform_sdk_version
978}
979
Mu-Le Lee5e047532022-07-27 02:32:03 +0000980func (c *config) PlatformSdkFinal() bool {
981 return Bool(c.productVariables.Platform_sdk_final)
982}
983
Colin Crossd09b0b62018-04-18 11:06:47 -0700984func (c *config) PlatformSdkCodename() string {
985 return String(c.productVariables.Platform_sdk_codename)
986}
987
Anton Hansson97d0bae2022-02-16 16:15:10 +0000988func (c *config) PlatformSdkExtensionVersion() int {
989 return *c.productVariables.Platform_sdk_extension_version
990}
991
992func (c *config) PlatformBaseSdkExtensionVersion() int {
993 return *c.productVariables.Platform_base_sdk_extension_version
994}
995
Colin Cross092c9da2019-04-02 22:56:43 -0700996func (c *config) PlatformSecurityPatch() string {
997 return String(c.productVariables.Platform_security_patch)
998}
999
1000func (c *config) PlatformPreviewSdkVersion() string {
1001 return String(c.productVariables.Platform_preview_sdk_version)
1002}
1003
1004func (c *config) PlatformMinSupportedTargetSdkVersion() string {
1005 return String(c.productVariables.Platform_min_supported_target_sdk_version)
1006}
1007
1008func (c *config) PlatformBaseOS() string {
1009 return String(c.productVariables.Platform_base_os)
1010}
1011
Inseob Kim4f1f3d92022-04-25 18:23:58 +09001012func (c *config) PlatformVersionLastStable() string {
1013 return String(c.productVariables.Platform_version_last_stable)
1014}
1015
Jiyong Park37073842022-06-21 10:13:42 +09001016func (c *config) PlatformVersionKnownCodenames() string {
1017 return String(c.productVariables.Platform_version_known_codenames)
1018}
1019
Dan Albert1a246272020-07-06 14:49:35 -07001020func (c *config) MinSupportedSdkVersion() ApiLevel {
Dan Albert6bfb6bb2022-08-17 20:11:57 +00001021 return uncheckedFinalApiLevel(21)
Dan Albert1a246272020-07-06 14:49:35 -07001022}
1023
1024func (c *config) FinalApiLevels() []ApiLevel {
1025 var levels []ApiLevel
Dan Albert4f378d72020-07-23 17:32:15 -07001026 for i := 1; i <= c.PlatformSdkVersion().FinalOrFutureInt(); i++ {
Dan Albert1a246272020-07-06 14:49:35 -07001027 levels = append(levels, uncheckedFinalApiLevel(i))
1028 }
1029 return levels
1030}
1031
1032func (c *config) PreviewApiLevels() []ApiLevel {
1033 var levels []ApiLevel
Dan Albertf93ea132023-10-05 20:40:46 +00001034 i := 0
1035 for _, codename := range c.PlatformVersionActiveCodenames() {
1036 if codename == "REL" {
1037 continue
1038 }
1039
Dan Albert1a246272020-07-06 14:49:35 -07001040 levels = append(levels, ApiLevel{
1041 value: codename,
1042 number: i,
1043 isPreview: true,
1044 })
Dan Albertf93ea132023-10-05 20:40:46 +00001045 i++
Dan Albert1a246272020-07-06 14:49:35 -07001046 }
1047 return levels
1048}
1049
satayevcca4ab72021-11-30 12:33:55 +00001050func (c *config) LatestPreviewApiLevel() ApiLevel {
1051 level := NoneApiLevel
1052 for _, l := range c.PreviewApiLevels() {
1053 if l.GreaterThan(level) {
1054 level = l
1055 }
1056 }
1057 return level
1058}
1059
Dan Albert1a246272020-07-06 14:49:35 -07001060func (c *config) AllSupportedApiLevels() []ApiLevel {
1061 var levels []ApiLevel
1062 levels = append(levels, c.FinalApiLevels()...)
1063 return append(levels, c.PreviewApiLevels()...)
Dan Albertf5415d72017-08-17 16:19:59 -07001064}
1065
Jingwen Chenc711fec2020-11-22 23:52:50 -05001066// DefaultAppTargetSdk returns the API level that platform apps are targeting.
1067// This converts a codename to the exact ApiLevel it represents.
Dan Albert4f378d72020-07-23 17:32:15 -07001068func (c *config) DefaultAppTargetSdk(ctx EarlyModuleContext) ApiLevel {
Alixfb7f7b92023-03-02 19:35:02 +00001069 // This logic is replicated in starlark, if changing logic here update starlark code too
1070 // https://cs.android.com/android/platform/superproject/+/master:build/bazel/rules/common/api.bzl;l=72;drc=231c7e8c8038fd478a79eb68aa5b9f5c64e0e061
Colin Crossd09b0b62018-04-18 11:06:47 -07001071 if Bool(c.productVariables.Platform_sdk_final) {
1072 return c.PlatformSdkVersion()
Colin Crossd09b0b62018-04-18 11:06:47 -07001073 }
Jingwen Chenc711fec2020-11-22 23:52:50 -05001074 codename := c.PlatformSdkCodename()
Jiyong Park3a00e3d2023-03-27 17:39:48 +09001075 hostOnlyBuild := c.productVariables.DeviceArch == nil
Jingwen Chenc711fec2020-11-22 23:52:50 -05001076 if codename == "" {
Jiyong Park3a00e3d2023-03-27 17:39:48 +09001077 // There are some host-only builds (those are invoked by build-prebuilts.sh) which
1078 // don't set platform sdk codename. Platform sdk codename makes sense only when we
1079 // are building the platform. So we don't enforce the below panic for the host-only
1080 // builds.
1081 if hostOnlyBuild {
1082 return NoneApiLevel
1083 }
1084 panic("Platform_sdk_codename must be set")
Jingwen Chenc711fec2020-11-22 23:52:50 -05001085 }
1086 if codename == "REL" {
1087 panic("Platform_sdk_codename should not be REL when Platform_sdk_final is true")
1088 }
1089 return ApiLevelOrPanic(ctx, codename)
Colin Crossd09b0b62018-04-18 11:06:47 -07001090}
1091
Colin Cross3bc7ffa2017-11-22 16:19:37 -08001092func (c *config) AppsDefaultVersionName() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001093 return String(c.productVariables.AppsDefaultVersionName)
Colin Cross3bc7ffa2017-11-22 16:19:37 -08001094}
1095
Dan Albert31384de2017-07-28 12:39:46 -07001096// Codenames that are active in the current lunch target.
1097func (c *config) PlatformVersionActiveCodenames() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001098 return c.productVariables.Platform_version_active_codenames
Dan Albert31384de2017-07-28 12:39:46 -07001099}
1100
Dan Albert8c7a9942023-03-27 20:34:01 +00001101// All unreleased codenames.
1102func (c *config) PlatformVersionAllPreviewCodenames() []string {
1103 return c.productVariables.Platform_version_all_preview_codenames
1104}
1105
Colin Crossface4e42017-10-30 17:32:15 -07001106func (c *config) ProductAAPTConfig() []string {
Colin Crossa74ca042019-01-31 14:31:51 -08001107 return c.productVariables.AAPTConfig
Colin Cross30e076a2015-04-13 13:58:27 -07001108}
1109
Colin Crossface4e42017-10-30 17:32:15 -07001110func (c *config) ProductAAPTPreferredConfig() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001111 return String(c.productVariables.AAPTPreferredConfig)
Colin Cross30e076a2015-04-13 13:58:27 -07001112}
1113
Colin Crossface4e42017-10-30 17:32:15 -07001114func (c *config) ProductAAPTCharacteristics() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001115 return String(c.productVariables.AAPTCharacteristics)
Colin Crossface4e42017-10-30 17:32:15 -07001116}
1117
1118func (c *config) ProductAAPTPrebuiltDPI() []string {
Colin Crossa74ca042019-01-31 14:31:51 -08001119 return c.productVariables.AAPTPrebuiltDPI
Colin Cross30e076a2015-04-13 13:58:27 -07001120}
1121
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001122func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001123 defaultCert := String(c.productVariables.DefaultAppCertificate)
Colin Cross61ae0b72017-12-01 17:16:02 -08001124 if defaultCert != "" {
1125 return PathForSource(ctx, filepath.Dir(defaultCert))
Colin Cross61ae0b72017-12-01 17:16:02 -08001126 }
Jingwen Chenc711fec2020-11-22 23:52:50 -05001127 return PathForSource(ctx, "build/make/target/product/security")
Colin Cross30e076a2015-04-13 13:58:27 -07001128}
1129
Colin Crosse1731a52017-12-14 11:22:55 -08001130func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001131 defaultCert := String(c.productVariables.DefaultAppCertificate)
Colin Cross61ae0b72017-12-01 17:16:02 -08001132 if defaultCert != "" {
Colin Crosse1731a52017-12-14 11:22:55 -08001133 return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -08001134 }
Jingwen Chenc711fec2020-11-22 23:52:50 -05001135 defaultDir := c.DefaultAppCertificateDir(ctx)
1136 return defaultDir.Join(ctx, "testkey.x509.pem"), defaultDir.Join(ctx, "testkey.pk8")
Colin Cross30e076a2015-04-13 13:58:27 -07001137}
Colin Cross6ff51382015-12-17 16:39:19 -08001138
Jiyong Park9335a262018-12-24 11:31:58 +09001139func (c *config) ApexKeyDir(ctx ModuleContext) SourcePath {
1140 // TODO(b/121224311): define another variable such as TARGET_APEX_KEY_OVERRIDE
1141 defaultCert := String(c.productVariables.DefaultAppCertificate)
Dan Willemsen412160e2019-04-09 21:36:26 -07001142 if defaultCert == "" || filepath.Dir(defaultCert) == "build/make/target/product/security" {
Jiyong Park9335a262018-12-24 11:31:58 +09001143 // When defaultCert is unset or is set to the testkeys path, use the APEX keys
1144 // that is under the module dir
Colin Cross07e51612019-03-05 12:46:40 -08001145 return pathForModuleSrc(ctx)
Jiyong Park9335a262018-12-24 11:31:58 +09001146 }
Jingwen Chenc711fec2020-11-22 23:52:50 -05001147 // If not, APEX keys are under the specified directory
1148 return PathForSource(ctx, filepath.Dir(defaultCert))
Jiyong Park9335a262018-12-24 11:31:58 +09001149}
1150
Inseob Kim80fa7982022-08-12 21:36:25 +09001151// Certificate for the NetworkStack sepolicy context
1152func (c *config) MainlineSepolicyDevCertificatesDir(ctx ModuleContext) SourcePath {
1153 cert := String(c.productVariables.MainlineSepolicyDevCertificates)
1154 if cert != "" {
1155 return PathForSource(ctx, cert)
1156 }
1157 return c.DefaultAppCertificateDir(ctx)
1158}
1159
Jingwen Chenc711fec2020-11-22 23:52:50 -05001160// AllowMissingDependencies configures Blueprint/Soong to not fail when modules
1161// are configured to depend on non-existent modules. Note that this does not
1162// affect missing input dependencies at the Ninja level.
Colin Cross6ff51382015-12-17 16:39:19 -08001163func (c *config) AllowMissingDependencies() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001164 return Bool(c.productVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -08001165}
Dan Willemsen322acaf2016-01-12 23:07:05 -08001166
Jeongik Cha816a23a2020-07-08 01:09:23 +09001167// Returns true if a full platform source tree cannot be assumed.
Colin Crossfc3674a2017-09-18 17:41:52 -07001168func (c *config) UnbundledBuild() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001169 return Bool(c.productVariables.Unbundled_build)
Colin Crossfc3674a2017-09-18 17:41:52 -07001170}
1171
Martin Stjernholmfd9eb4b2020-06-17 01:13:15 +01001172// Returns true if building apps that aren't bundled with the platform.
1173// UnbundledBuild() is always true when this is true.
1174func (c *config) UnbundledBuildApps() bool {
Cole Faust701ca252021-11-23 19:02:08 -08001175 return len(c.productVariables.Unbundled_build_apps) > 0
Martin Stjernholmfd9eb4b2020-06-17 01:13:15 +01001176}
1177
Jeongik Cha4b073cd2021-06-08 11:35:00 +09001178// Returns true if building image that aren't bundled with the platform.
1179// UnbundledBuild() is always true when this is true.
1180func (c *config) UnbundledBuildImage() bool {
1181 return Bool(c.productVariables.Unbundled_build_image)
1182}
1183
Jeongik Cha816a23a2020-07-08 01:09:23 +09001184// Returns true if building modules against prebuilt SDKs.
1185func (c *config) AlwaysUsePrebuiltSdks() bool {
1186 return Bool(c.productVariables.Always_use_prebuilt_sdks)
Colin Cross1f367bf2018-12-18 22:46:24 -08001187}
1188
Colin Cross126a25c2017-10-31 13:55:34 -07001189func (c *config) MinimizeJavaDebugInfo() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001190 return Bool(c.productVariables.MinimizeJavaDebugInfo) && !Bool(c.productVariables.Eng)
Colin Cross126a25c2017-10-31 13:55:34 -07001191}
1192
Colin Crossed064c02018-09-05 16:28:13 -07001193func (c *config) Debuggable() bool {
1194 return Bool(c.productVariables.Debuggable)
1195}
1196
Jaewoong Jung1d6eb682018-11-29 15:08:44 -08001197func (c *config) Eng() bool {
1198 return Bool(c.productVariables.Eng)
1199}
1200
Colin Crossc53c37f2021-12-08 15:42:22 -08001201// DevicePrimaryArchType returns the ArchType for the first configured device architecture, or
1202// Common if there are no device architectures.
Jiyong Park8d52f862018-07-07 18:02:07 +09001203func (c *config) DevicePrimaryArchType() ArchType {
Colin Crossc53c37f2021-12-08 15:42:22 -08001204 if androidTargets := c.Targets[Android]; len(androidTargets) > 0 {
1205 return androidTargets[0].Arch.ArchType
1206 }
1207 return Common
Jiyong Park8d52f862018-07-07 18:02:07 +09001208}
1209
Colin Cross16b23492016-01-06 14:41:07 -08001210func (c *config) SanitizeHost() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001211 return append([]string(nil), c.productVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -08001212}
1213
1214func (c *config) SanitizeDevice() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001215 return append([]string(nil), c.productVariables.SanitizeDevice...)
Colin Cross23ae82a2016-11-02 14:34:39 -07001216}
1217
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -07001218func (c *config) SanitizeDeviceDiag() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001219 return append([]string(nil), c.productVariables.SanitizeDeviceDiag...)
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -07001220}
1221
Colin Cross23ae82a2016-11-02 14:34:39 -07001222func (c *config) SanitizeDeviceArch() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001223 return append([]string(nil), c.productVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -08001224}
Colin Crossa1ad8d12016-06-01 17:09:44 -07001225
Vishwath Mohan1b017a72017-01-19 13:54:55 -08001226func (c *config) EnableCFI() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001227 if c.productVariables.EnableCFI == nil {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -08001228 return true
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -08001229 }
Jingwen Chenc711fec2020-11-22 23:52:50 -05001230 return *c.productVariables.EnableCFI
Vishwath Mohan1b017a72017-01-19 13:54:55 -08001231}
1232
Kostya Kortchinskyd5275c82019-02-01 08:42:56 -08001233func (c *config) DisableScudo() bool {
1234 return Bool(c.productVariables.DisableScudo)
1235}
1236
Colin Crossa1ad8d12016-06-01 17:09:44 -07001237func (c *config) Android64() bool {
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001238 for _, t := range c.Targets[Android] {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001239 if t.Arch.ArchType.Multilib == "lib64" {
1240 return true
1241 }
1242 }
1243
1244 return false
1245}
Colin Cross9272ade2016-08-17 15:24:12 -07001246
Colin Cross9d45bb72016-08-29 16:14:13 -07001247func (c *config) UseGoma() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001248 return Bool(c.productVariables.UseGoma)
Colin Cross9d45bb72016-08-29 16:14:13 -07001249}
1250
Ramy Medhatbbf25672019-07-17 12:30:04 +00001251func (c *config) UseRBE() bool {
1252 return Bool(c.productVariables.UseRBE)
1253}
1254
Ramy Medhat8ea054a2020-01-27 14:19:44 -05001255func (c *config) UseRBEJAVAC() bool {
1256 return Bool(c.productVariables.UseRBEJAVAC)
1257}
1258
1259func (c *config) UseRBER8() bool {
1260 return Bool(c.productVariables.UseRBER8)
1261}
1262
1263func (c *config) UseRBED8() bool {
1264 return Bool(c.productVariables.UseRBED8)
1265}
1266
Colin Cross8b8bec32019-11-15 13:18:43 -08001267func (c *config) UseRemoteBuild() bool {
1268 return c.UseGoma() || c.UseRBE()
1269}
1270
Colin Cross66548102018-06-19 22:47:35 -07001271func (c *config) RunErrorProne() bool {
1272 return c.IsEnvTrue("RUN_ERROR_PRONE")
1273}
1274
Jingwen Chenc711fec2020-11-22 23:52:50 -05001275// XrefCorpusName returns the Kythe cross-reference corpus name.
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001276func (c *config) XrefCorpusName() string {
1277 return c.Getenv("XREF_CORPUS")
1278}
1279
Jingwen Chenc711fec2020-11-22 23:52:50 -05001280// XrefCuEncoding returns the compilation unit encoding to use for Kythe code
1281// xrefs. Can be 'json' (default), 'proto' or 'all'.
Sasha Smundak6c2d4f92020-01-09 17:34:23 -08001282func (c *config) XrefCuEncoding() string {
1283 if enc := c.Getenv("KYTHE_KZIP_ENCODING"); enc != "" {
1284 return enc
1285 }
1286 return "json"
1287}
1288
Sasha Smundakb0addaf2021-02-16 10:39:40 -08001289// XrefCuJavaSourceMax returns the maximum number of the Java source files
1290// in a single compilation unit
1291const xrefJavaSourceFileMaxDefault = "1000"
1292
1293func (c Config) XrefCuJavaSourceMax() string {
1294 v := c.Getenv("KYTHE_JAVA_SOURCE_BATCH_SIZE")
1295 if v == "" {
1296 return xrefJavaSourceFileMaxDefault
1297 }
1298 if _, err := strconv.ParseUint(v, 0, 0); err != nil {
1299 fmt.Fprintf(os.Stderr,
1300 "bad KYTHE_JAVA_SOURCE_BATCH_SIZE value: %s, will use %s",
1301 err, xrefJavaSourceFileMaxDefault)
1302 return xrefJavaSourceFileMaxDefault
1303 }
1304 return v
1305
1306}
1307
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001308func (c *config) EmitXrefRules() bool {
1309 return c.XrefCorpusName() != ""
1310}
1311
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001312func (c *config) ClangTidy() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001313 return Bool(c.productVariables.ClangTidy)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001314}
1315
1316func (c *config) TidyChecks() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001317 if c.productVariables.TidyChecks == nil {
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001318 return ""
1319 }
Dan Willemsen45133ac2018-03-09 21:22:06 -08001320 return *c.productVariables.TidyChecks
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001321}
1322
Colin Cross0f4e0d62016-07-27 10:56:55 -07001323func (c *config) LibartImgHostBaseAddress() string {
1324 return "0x60000000"
1325}
1326
1327func (c *config) LibartImgDeviceBaseAddress() string {
Elliott Hughesda3a0712020-03-06 16:55:28 -08001328 return "0x70000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -07001329}
1330
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -08001331func (c *config) ArtUseReadBarrier() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001332 return Bool(c.productVariables.ArtUseReadBarrier)
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -08001333}
1334
Jingwen Chenc711fec2020-11-22 23:52:50 -05001335// Enforce Runtime Resource Overlays for a module. RROs supersede static RROs,
1336// but some modules still depend on it.
1337//
1338// More info: https://source.android.com/devices/architecture/rros
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001339func (c *config) EnforceRROForModule(name string) bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001340 enforceList := c.productVariables.EnforceRROTargets
Jeongik Chacee5ba92021-02-19 12:11:51 +09001341
Roland Levillainf6cc2612020-07-09 16:58:14 +01001342 if len(enforceList) > 0 {
Yo Chiang4ebd06a2019-10-01 13:13:41 +08001343 if InList("*", enforceList) {
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001344 return true
1345 }
Colin Crossa74ca042019-01-31 14:31:51 -08001346 return InList(name, enforceList)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001347 }
1348 return false
1349}
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001350func (c *config) EnforceRROExcludedOverlay(path string) bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001351 excluded := c.productVariables.EnforceRROExcludedOverlays
Roland Levillainf6cc2612020-07-09 16:58:14 +01001352 if len(excluded) > 0 {
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001353 return HasAnyPrefix(path, excluded)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001354 }
1355 return false
1356}
1357
1358func (c *config) ExportedNamespaces() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001359 return append([]string(nil), c.productVariables.NamespacesToExport...)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001360}
1361
Sam Delmerico98a73292023-02-21 11:50:29 -05001362func (c *config) SourceRootDirs() []string {
1363 return c.productVariables.SourceRootDirs
1364}
1365
Spandan Dasc5763832022-11-08 18:42:16 +00001366func (c *config) IncludeTags() []string {
1367 return c.productVariables.IncludeTags
1368}
1369
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001370func (c *config) HostStaticBinaries() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001371 return Bool(c.productVariables.HostStaticBinaries)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001372}
1373
Colin Cross5a0dcd52018-10-05 14:20:06 -07001374func (c *config) UncompressPrivAppDex() bool {
1375 return Bool(c.productVariables.UncompressPrivAppDex)
1376}
1377
1378func (c *config) ModulesLoadedByPrivilegedModules() []string {
1379 return c.productVariables.ModulesLoadedByPrivilegedModules
1380}
1381
Jingwen Chenc711fec2020-11-22 23:52:50 -05001382// DexpreoptGlobalConfigPath returns the path to the dexpreopt.config file in
1383// the output directory, if it was created during the product configuration
1384// phase by Kati.
Jingwen Chenebb0b572020-11-02 00:24:57 -05001385func (c *config) DexpreoptGlobalConfigPath(ctx PathContext) OptionalPath {
Colin Cross988414c2020-01-11 01:11:46 +00001386 if c.productVariables.DexpreoptGlobalConfig == nil {
Jingwen Chenebb0b572020-11-02 00:24:57 -05001387 return OptionalPathForPath(nil)
1388 }
1389 return OptionalPathForPath(
1390 pathForBuildToolDep(ctx, *c.productVariables.DexpreoptGlobalConfig))
1391}
1392
Jingwen Chenc711fec2020-11-22 23:52:50 -05001393// DexpreoptGlobalConfig returns the raw byte contents of the dexpreopt global
1394// configuration. Since the configuration file was created by Kati during
1395// product configuration (externally of soong_build), it's not tracked, so we
1396// also manually add a Ninja file dependency on the configuration file to the
1397// rule that creates the main build.ninja file. This ensures that build.ninja is
1398// regenerated correctly if dexpreopt.config changes.
Jingwen Chenebb0b572020-11-02 00:24:57 -05001399func (c *config) DexpreoptGlobalConfig(ctx PathContext) ([]byte, error) {
1400 path := c.DexpreoptGlobalConfigPath(ctx)
1401 if !path.Valid() {
Colin Cross988414c2020-01-11 01:11:46 +00001402 return nil, nil
1403 }
Jingwen Chenebb0b572020-11-02 00:24:57 -05001404 ctx.AddNinjaFileDeps(path.String())
Sasha Smundakaf5ca922022-12-12 21:23:34 -08001405 return os.ReadFile(absolutePath(path.String()))
Colin Cross43f08db2018-11-12 10:13:39 -08001406}
1407
Inseob Kim7b85eeb2021-03-23 20:52:24 +09001408func (c *deviceConfig) WithDexpreopt() bool {
1409 return c.config.productVariables.WithDexpreopt
1410}
1411
Colin Cross662d6142022-11-03 20:38:01 -07001412func (c *config) FrameworksBaseDirExists(ctx PathGlobContext) bool {
Colin Cross5a756a62021-03-16 16:34:46 -07001413 return ExistentPathForSource(ctx, "frameworks", "base", "Android.bp").Valid()
David Brazdil91b4e3e2019-01-23 21:04:05 +00001414}
1415
Inseob Kimae553032019-05-14 18:52:49 +09001416func (c *config) VndkSnapshotBuildArtifacts() bool {
1417 return Bool(c.productVariables.VndkSnapshotBuildArtifacts)
1418}
1419
Colin Cross3b19f5d2019-09-17 14:45:31 -07001420func (c *config) HasMultilibConflict(arch ArchType) bool {
1421 return c.multilibConflicts[arch]
1422}
1423
Sasha Smundakaf5ca922022-12-12 21:23:34 -08001424func (c *config) PrebuiltHiddenApiDir(_ PathContext) string {
Bill Peckhambae47492021-01-08 09:34:44 -08001425 return String(c.productVariables.PrebuiltHiddenApiDir)
1426}
1427
MarkDacekd06db5d2022-11-29 00:47:59 +00001428func (c *config) BazelModulesForceEnabledByFlag() map[string]struct{} {
1429 return c.bazelForceEnabledModules
1430}
1431
Kiyoung Kime623c582023-07-06 16:43:44 +09001432func (c *config) IsVndkDeprecated() bool {
1433 return !Bool(c.productVariables.KeepVndk)
1434}
1435
Justin Yun41cbb5e2023-11-29 17:58:16 +09001436func (c *config) VendorApiLevel() string {
1437 return String(c.productVariables.VendorApiLevel)
1438}
1439
Colin Cross9272ade2016-08-17 15:24:12 -07001440func (c *deviceConfig) Arches() []Arch {
1441 var arches []Arch
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001442 for _, target := range c.config.Targets[Android] {
Colin Cross9272ade2016-08-17 15:24:12 -07001443 arches = append(arches, target.Arch)
1444 }
1445 return arches
1446}
Dan Willemsend2ede872016-11-18 14:54:24 -08001447
Jayant Chowdhary34ce67d2018-03-08 11:00:50 -08001448func (c *deviceConfig) BinderBitness() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001449 is32BitBinder := c.config.productVariables.Binder32bit
Jayant Chowdhary34ce67d2018-03-08 11:00:50 -08001450 if is32BitBinder != nil && *is32BitBinder {
1451 return "32"
1452 }
1453 return "64"
1454}
1455
Dan Willemsen4353bc42016-12-05 17:16:02 -08001456func (c *deviceConfig) VendorPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001457 if c.config.productVariables.VendorPath != nil {
1458 return *c.config.productVariables.VendorPath
Dan Willemsen4353bc42016-12-05 17:16:02 -08001459 }
1460 return "vendor"
1461}
1462
Justin Yun71549282017-11-17 12:10:28 +09001463func (c *deviceConfig) VndkVersion() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001464 return String(c.config.productVariables.DeviceVndkVersion)
Justin Yun71549282017-11-17 12:10:28 +09001465}
1466
Jose Galmes6f843bc2020-12-11 13:36:29 -08001467func (c *deviceConfig) RecoverySnapshotVersion() string {
1468 return String(c.config.productVariables.RecoverySnapshotVersion)
1469}
1470
Jeongik Cha219141c2020-08-06 23:00:37 +09001471func (c *deviceConfig) CurrentApiLevelForVendorModules() string {
1472 return StringDefault(c.config.productVariables.DeviceCurrentApiLevelForVendorModules, "current")
1473}
1474
Justin Yun8fe12122017-12-07 17:18:15 +09001475func (c *deviceConfig) PlatformVndkVersion() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001476 return String(c.config.productVariables.Platform_vndk_version)
Justin Yun8fe12122017-12-07 17:18:15 +09001477}
1478
Justin Yun71549282017-11-17 12:10:28 +09001479func (c *deviceConfig) ExtraVndkVersions() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001480 return c.config.productVariables.ExtraVndkVersions
Dan Willemsend2ede872016-11-18 14:54:24 -08001481}
Jack He8cc71432016-12-08 15:45:07 -08001482
Vic Yangefd249e2018-11-12 20:19:56 -08001483func (c *deviceConfig) VndkUseCoreVariant() bool {
Kiyoung Kim03b6cba2023-10-06 14:12:43 +09001484 return Bool(c.config.productVariables.VndkUseCoreVariant) && Bool(c.config.productVariables.KeepVndk)
Vic Yangefd249e2018-11-12 20:19:56 -08001485}
1486
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001487func (c *deviceConfig) SystemSdkVersions() []string {
Colin Crossa74ca042019-01-31 14:31:51 -08001488 return c.config.productVariables.DeviceSystemSdkVersions
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001489}
1490
1491func (c *deviceConfig) PlatformSystemSdkVersions() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001492 return c.config.productVariables.Platform_systemsdk_versions
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001493}
1494
Jiyong Park2db76922017-11-08 16:03:48 +09001495func (c *deviceConfig) OdmPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001496 if c.config.productVariables.OdmPath != nil {
1497 return *c.config.productVariables.OdmPath
Jiyong Park2db76922017-11-08 16:03:48 +09001498 }
1499 return "odm"
1500}
1501
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +09001502func (c *deviceConfig) ProductPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001503 if c.config.productVariables.ProductPath != nil {
1504 return *c.config.productVariables.ProductPath
Jiyong Park2db76922017-11-08 16:03:48 +09001505 }
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +09001506 return "product"
Jiyong Park2db76922017-11-08 16:03:48 +09001507}
1508
Justin Yund5f6c822019-06-25 16:47:17 +09001509func (c *deviceConfig) SystemExtPath() string {
1510 if c.config.productVariables.SystemExtPath != nil {
1511 return *c.config.productVariables.SystemExtPath
Dario Frenifd05a742018-05-29 13:28:54 +01001512 }
Justin Yund5f6c822019-06-25 16:47:17 +09001513 return "system_ext"
Dario Frenifd05a742018-05-29 13:28:54 +01001514}
1515
Jack He8cc71432016-12-08 15:45:07 -08001516func (c *deviceConfig) BtConfigIncludeDir() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001517 return String(c.config.productVariables.BtConfigIncludeDir)
Jack He8cc71432016-12-08 15:45:07 -08001518}
Dan Willemsen581341d2017-02-09 16:16:31 -08001519
Jiyong Parkd773eb32017-07-03 13:18:12 +09001520func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001521 return c.config.productVariables.DeviceKernelHeaders
Jiyong Parkd773eb32017-07-03 13:18:12 +09001522}
1523
Roland Levillainada12702020-06-09 13:07:36 +01001524// JavaCoverageEnabledForPath returns whether Java code coverage is enabled for
1525// path. Coverage is enabled by default when the product variable
1526// JavaCoveragePaths is empty. If JavaCoveragePaths is not empty, coverage is
1527// enabled for any path which is part of this variable (and not part of the
1528// JavaCoverageExcludePaths product variable). Value "*" in JavaCoveragePaths
1529// represents any path.
1530func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool {
1531 coverage := false
Chris Gross2f748692020-06-24 20:36:59 +00001532 if len(c.config.productVariables.JavaCoveragePaths) == 0 ||
Roland Levillainada12702020-06-09 13:07:36 +01001533 InList("*", c.config.productVariables.JavaCoveragePaths) ||
1534 HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) {
1535 coverage = true
1536 }
Roland Levillainf6cc2612020-07-09 16:58:14 +01001537 if coverage && len(c.config.productVariables.JavaCoverageExcludePaths) > 0 {
Roland Levillainada12702020-06-09 13:07:36 +01001538 if HasAnyPrefix(path, c.config.productVariables.JavaCoverageExcludePaths) {
1539 coverage = false
1540 }
1541 }
1542 return coverage
1543}
1544
Colin Cross1a6acd42020-06-16 17:51:46 -07001545// Returns true if gcov or clang coverage is enabled.
Dan Willemsen581341d2017-02-09 16:16:31 -08001546func (c *deviceConfig) NativeCoverageEnabled() bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001547 return Bool(c.config.productVariables.GcovCoverage) ||
1548 Bool(c.config.productVariables.ClangCoverage)
Dan Willemsen581341d2017-02-09 16:16:31 -08001549}
1550
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001551func (c *deviceConfig) ClangCoverageEnabled() bool {
1552 return Bool(c.config.productVariables.ClangCoverage)
1553}
1554
Pirama Arumuga Nainarb37ae582022-01-26 22:14:32 -08001555func (c *deviceConfig) ClangCoverageContinuousMode() bool {
1556 return Bool(c.config.productVariables.ClangCoverageContinuousMode)
1557}
1558
Colin Cross1a6acd42020-06-16 17:51:46 -07001559func (c *deviceConfig) GcovCoverageEnabled() bool {
1560 return Bool(c.config.productVariables.GcovCoverage)
1561}
1562
Roland Levillain4f5297b2020-06-09 12:44:06 +01001563// NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native
1564// code coverage is enabled for path. By default, coverage is not enabled for a
1565// given path unless it is part of the NativeCoveragePaths product variable (and
1566// not part of the NativeCoverageExcludePaths product variable). Value "*" in
1567// NativeCoveragePaths represents any path.
1568func (c *deviceConfig) NativeCoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -08001569 coverage := false
Roland Levillainf6cc2612020-07-09 16:58:14 +01001570 if len(c.config.productVariables.NativeCoveragePaths) > 0 {
Roland Levillain4f5297b2020-06-09 12:44:06 +01001571 if InList("*", c.config.productVariables.NativeCoveragePaths) || HasAnyPrefix(path, c.config.productVariables.NativeCoveragePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -07001572 coverage = true
Dan Willemsen581341d2017-02-09 16:16:31 -08001573 }
1574 }
Roland Levillainf6cc2612020-07-09 16:58:14 +01001575 if coverage && len(c.config.productVariables.NativeCoverageExcludePaths) > 0 {
Yi Kongfd07ed22023-02-16 17:42:27 +09001576 // Workaround coverage boot failure.
1577 // http://b/269981180
1578 if strings.HasPrefix(path, "external/protobuf") {
1579 coverage = false
1580 }
Roland Levillain4f5297b2020-06-09 12:44:06 +01001581 if HasAnyPrefix(path, c.config.productVariables.NativeCoverageExcludePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -07001582 coverage = false
Ryan Campbell469a18a2017-02-27 09:01:54 -08001583 }
1584 }
1585 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -08001586}
Ivan Lozano5f595532017-07-13 14:46:05 -07001587
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -08001588func (c *deviceConfig) PgoAdditionalProfileDirs() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001589 return c.config.productVariables.PgoAdditionalProfileDirs
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -08001590}
1591
Vinh Tran44cb78c2023-03-09 22:07:19 -05001592// AfdoProfile returns fully qualified path associated to the given module name
1593func (c *deviceConfig) AfdoProfile(name string) (*string, error) {
1594 for _, afdoProfile := range c.config.productVariables.AfdoProfiles {
1595 split := strings.Split(afdoProfile, ":")
1596 if len(split) != 3 {
1597 return nil, fmt.Errorf("AFDO_PROFILES has invalid value: %s. "+
1598 "The expected format is <module>:<fully-qualified-path-to-fdo_profile>", afdoProfile)
1599 }
1600 if split[0] == name {
1601 return proptools.StringPtr(strings.Join([]string{split[1], split[2]}, ":")), nil
1602 }
1603 }
1604 return nil, nil
1605}
1606
Tri Vo35a51432018-03-25 20:00:00 -07001607func (c *deviceConfig) VendorSepolicyDirs() []string {
1608 return c.config.productVariables.BoardVendorSepolicyDirs
1609}
1610
1611func (c *deviceConfig) OdmSepolicyDirs() []string {
1612 return c.config.productVariables.BoardOdmSepolicyDirs
1613}
1614
Felixa20a8752020-05-17 18:28:35 +02001615func (c *deviceConfig) SystemExtPublicSepolicyDirs() []string {
1616 return c.config.productVariables.SystemExtPublicSepolicyDirs
Tri Vo35a51432018-03-25 20:00:00 -07001617}
1618
Felixa20a8752020-05-17 18:28:35 +02001619func (c *deviceConfig) SystemExtPrivateSepolicyDirs() []string {
1620 return c.config.productVariables.SystemExtPrivateSepolicyDirs
Tri Vo35a51432018-03-25 20:00:00 -07001621}
1622
Inseob Kim0866b002019-04-15 20:21:29 +09001623func (c *deviceConfig) SepolicyM4Defs() []string {
1624 return c.config.productVariables.BoardSepolicyM4Defs
1625}
1626
Jiyong Park7f67f482019-01-05 12:57:48 +09001627func (c *deviceConfig) OverrideManifestPackageNameFor(name string) (manifestName string, overridden bool) {
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001628 return findOverrideValue(c.config.productVariables.ManifestPackageNameOverrides, name,
1629 "invalid override rule %q in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES should be <module_name>:<manifest_name>")
1630}
1631
1632func (c *deviceConfig) OverrideCertificateFor(name string) (certificatePath string, overridden bool) {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001633 return findOverrideValue(c.config.productVariables.CertificateOverrides, name,
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001634 "invalid override rule %q in PRODUCT_CERTIFICATE_OVERRIDES should be <module_name>:<certificate_module_name>")
1635}
1636
Jaewoong Jung9d22a912019-01-23 16:27:47 -08001637func (c *deviceConfig) OverridePackageNameFor(name string) string {
1638 newName, overridden := findOverrideValue(
1639 c.config.productVariables.PackageNameOverrides,
1640 name,
1641 "invalid override rule %q in PRODUCT_PACKAGE_NAME_OVERRIDES should be <module_name>:<package_name>")
1642 if overridden {
1643 return newName
1644 }
1645 return name
1646}
1647
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001648func findOverrideValue(overrides []string, name string, errorMsg string) (newValue string, overridden bool) {
Jiyong Park7f67f482019-01-05 12:57:48 +09001649 if overrides == nil || len(overrides) == 0 {
1650 return "", false
1651 }
1652 for _, o := range overrides {
1653 split := strings.Split(o, ":")
1654 if len(split) != 2 {
1655 // This shouldn't happen as this is first checked in make, but just in case.
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001656 panic(fmt.Errorf(errorMsg, o))
Jiyong Park7f67f482019-01-05 12:57:48 +09001657 }
1658 if matchPattern(split[0], name) {
1659 return substPattern(split[0], split[1], name), true
1660 }
1661 }
1662 return "", false
1663}
1664
Albert Martineefabcf2022-03-21 20:11:16 +00001665func (c *deviceConfig) ApexGlobalMinSdkVersionOverride() string {
1666 return String(c.config.productVariables.ApexGlobalMinSdkVersionOverride)
1667}
1668
Ivan Lozano5f595532017-07-13 14:46:05 -07001669func (c *config) IntegerOverflowDisabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001670 if len(c.productVariables.IntegerOverflowExcludePaths) == 0 {
Ivan Lozano5f595532017-07-13 14:46:05 -07001671 return false
1672 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001673 return HasAnyPrefix(path, c.productVariables.IntegerOverflowExcludePaths)
Ivan Lozano5f595532017-07-13 14:46:05 -07001674}
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001675
1676func (c *config) CFIDisabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001677 if len(c.productVariables.CFIExcludePaths) == 0 {
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001678 return false
1679 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001680 return HasAnyPrefix(path, c.productVariables.CFIExcludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001681}
1682
1683func (c *config) CFIEnabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001684 if len(c.productVariables.CFIIncludePaths) == 0 {
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001685 return false
1686 }
Evgenii Stepanov779b64e2021-04-09 14:33:10 -07001687 return HasAnyPrefix(path, c.productVariables.CFIIncludePaths) && !c.CFIDisabledForPath(path)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001688}
Colin Crosse15ddaf2017-12-04 11:24:31 -08001689
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08001690func (c *config) MemtagHeapDisabledForPath(path string) bool {
1691 if len(c.productVariables.MemtagHeapExcludePaths) == 0 {
1692 return false
1693 }
1694 return HasAnyPrefix(path, c.productVariables.MemtagHeapExcludePaths)
1695}
1696
1697func (c *config) MemtagHeapAsyncEnabledForPath(path string) bool {
1698 if len(c.productVariables.MemtagHeapAsyncIncludePaths) == 0 {
1699 return false
1700 }
Evgenii Stepanov779b64e2021-04-09 14:33:10 -07001701 return HasAnyPrefix(path, c.productVariables.MemtagHeapAsyncIncludePaths) && !c.MemtagHeapDisabledForPath(path)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08001702}
1703
1704func (c *config) MemtagHeapSyncEnabledForPath(path string) bool {
1705 if len(c.productVariables.MemtagHeapSyncIncludePaths) == 0 {
1706 return false
1707 }
Evgenii Stepanov779b64e2021-04-09 14:33:10 -07001708 return HasAnyPrefix(path, c.productVariables.MemtagHeapSyncIncludePaths) && !c.MemtagHeapDisabledForPath(path)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08001709}
1710
Tomislav Novakf734f002023-08-22 10:51:44 -07001711func (c *config) HWASanDisabledForPath(path string) bool {
1712 if len(c.productVariables.HWASanExcludePaths) == 0 {
1713 return false
1714 }
1715 return HasAnyPrefix(path, c.productVariables.HWASanExcludePaths)
1716}
1717
Hang Lua98aab92023-03-17 13:17:22 +08001718func (c *config) HWASanEnabledForPath(path string) bool {
1719 if len(c.productVariables.HWASanIncludePaths) == 0 {
1720 return false
1721 }
Tomislav Novakf734f002023-08-22 10:51:44 -07001722 return HasAnyPrefix(path, c.productVariables.HWASanIncludePaths) && !c.HWASanDisabledForPath(path)
Hang Lua98aab92023-03-17 13:17:22 +08001723}
1724
Dan Willemsen0fe78662018-03-26 12:41:18 -07001725func (c *config) VendorConfig(name string) VendorConfig {
Colin Cross9d34f352019-11-22 16:03:51 -08001726 return soongconfig.Config(c.productVariables.VendorVars[name])
Dan Willemsen0fe78662018-03-26 12:41:18 -07001727}
1728
Colin Cross395f2cf2018-10-24 16:10:32 -07001729func (c *config) NdkAbis() bool {
1730 return Bool(c.productVariables.Ndk_abis)
1731}
1732
Martin Stjernholmc1ecc432019-11-15 15:00:31 +00001733func (c *config) AmlAbis() bool {
1734 return Bool(c.productVariables.Aml_abis)
1735}
1736
Jiyong Park4da07972021-01-05 21:01:11 +09001737func (c *config) ForceApexSymlinkOptimization() bool {
1738 return Bool(c.productVariables.ForceApexSymlinkOptimization)
1739}
1740
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001741func (c *config) ApexCompressionEnabled() bool {
1742 return Bool(c.productVariables.CompressedApex) && !c.UnbundledBuildApps()
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +00001743}
1744
Dennis Shene2ed70c2023-01-11 14:15:43 +00001745func (c *config) ApexTrimEnabled() bool {
1746 return Bool(c.productVariables.TrimmedApex)
1747}
1748
Jeongik Chac9464142019-01-07 12:07:27 +09001749func (c *config) EnforceSystemCertificate() bool {
1750 return Bool(c.productVariables.EnforceSystemCertificate)
1751}
1752
Colin Cross440e0d02020-06-11 11:32:11 -07001753func (c *config) EnforceSystemCertificateAllowList() []string {
1754 return c.productVariables.EnforceSystemCertificateAllowList
Jeongik Chac9464142019-01-07 12:07:27 +09001755}
1756
Jeongik Cha2cc570d2019-10-29 15:44:45 +09001757func (c *config) EnforceProductPartitionInterface() bool {
1758 return Bool(c.productVariables.EnforceProductPartitionInterface)
1759}
1760
JaeMan Parkff715562020-10-19 17:25:58 +09001761func (c *config) EnforceInterPartitionJavaSdkLibrary() bool {
1762 return Bool(c.productVariables.EnforceInterPartitionJavaSdkLibrary)
1763}
1764
1765func (c *config) InterPartitionJavaLibraryAllowList() []string {
1766 return c.productVariables.InterPartitionJavaLibraryAllowList
1767}
1768
Colin Crossf24a22a2019-01-31 14:12:44 -08001769func (c *config) ProductHiddenAPIStubs() []string {
1770 return c.productVariables.ProductHiddenAPIStubs
Colin Cross8faf8fc2019-01-16 15:15:52 -08001771}
1772
Colin Crossf24a22a2019-01-31 14:12:44 -08001773func (c *config) ProductHiddenAPIStubsSystem() []string {
1774 return c.productVariables.ProductHiddenAPIStubsSystem
Colin Cross8faf8fc2019-01-16 15:15:52 -08001775}
1776
Colin Crossf24a22a2019-01-31 14:12:44 -08001777func (c *config) ProductHiddenAPIStubsTest() []string {
1778 return c.productVariables.ProductHiddenAPIStubsTest
Colin Cross8faf8fc2019-01-16 15:15:52 -08001779}
Dan Willemsen71c74602019-04-10 12:27:35 -07001780
Dan Willemsen54879d12019-04-18 10:08:46 -07001781func (c *deviceConfig) TargetFSConfigGen() []string {
Dan Willemsen71c74602019-04-10 12:27:35 -07001782 return c.config.productVariables.TargetFSConfigGen
1783}
Inseob Kim0866b002019-04-15 20:21:29 +09001784
1785func (c *config) ProductPublicSepolicyDirs() []string {
1786 return c.productVariables.ProductPublicSepolicyDirs
1787}
1788
1789func (c *config) ProductPrivateSepolicyDirs() []string {
1790 return c.productVariables.ProductPrivateSepolicyDirs
1791}
1792
Inseob Kim5eb7ee92022-04-27 10:30:34 +09001793func (c *config) TargetMultitreeUpdateMeta() bool {
1794 return c.productVariables.MultitreeUpdateMeta
1795}
1796
Inseob Kim1f086e22019-05-09 13:29:15 +09001797func (c *deviceConfig) DeviceArch() string {
1798 return String(c.config.productVariables.DeviceArch)
1799}
1800
1801func (c *deviceConfig) DeviceArchVariant() string {
1802 return String(c.config.productVariables.DeviceArchVariant)
1803}
1804
1805func (c *deviceConfig) DeviceSecondaryArch() string {
1806 return String(c.config.productVariables.DeviceSecondaryArch)
1807}
1808
1809func (c *deviceConfig) DeviceSecondaryArchVariant() string {
1810 return String(c.config.productVariables.DeviceSecondaryArchVariant)
1811}
Yifan Hong82db7352020-01-21 16:12:26 -08001812
1813func (c *deviceConfig) BoardUsesRecoveryAsBoot() bool {
1814 return Bool(c.config.productVariables.BoardUsesRecoveryAsBoot)
1815}
Yifan Hong97365ee2020-07-29 09:51:57 -07001816
1817func (c *deviceConfig) BoardKernelBinaries() []string {
1818 return c.config.productVariables.BoardKernelBinaries
1819}
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001820
Yifan Hong42bef8d2020-08-05 14:36:09 -07001821func (c *deviceConfig) BoardKernelModuleInterfaceVersions() []string {
1822 return c.config.productVariables.BoardKernelModuleInterfaceVersions
1823}
1824
Yifan Hongdd8dacc2020-10-21 15:40:17 -07001825func (c *deviceConfig) BoardMoveRecoveryResourcesToVendorBoot() bool {
1826 return Bool(c.config.productVariables.BoardMoveRecoveryResourcesToVendorBoot)
1827}
1828
Inseob Kim16ebd5a2020-12-09 23:08:17 +09001829func (c *deviceConfig) PlatformSepolicyVersion() string {
1830 return String(c.config.productVariables.PlatformSepolicyVersion)
1831}
1832
Inseob Kima10ef272021-09-15 03:04:53 +00001833func (c *deviceConfig) TotSepolicyVersion() string {
1834 return String(c.config.productVariables.TotSepolicyVersion)
1835}
1836
Inseob Kim843f6642022-01-07 09:11:23 +09001837func (c *deviceConfig) PlatformSepolicyCompatVersions() []string {
1838 return c.config.productVariables.PlatformSepolicyCompatVersions
1839}
1840
Inseob Kim16ebd5a2020-12-09 23:08:17 +09001841func (c *deviceConfig) BoardSepolicyVers() string {
Inseob Kim0c4eec82021-03-22 22:33:40 +09001842 if ver := String(c.config.productVariables.BoardSepolicyVers); ver != "" {
1843 return ver
1844 }
1845 return c.PlatformSepolicyVersion()
Inseob Kim16ebd5a2020-12-09 23:08:17 +09001846}
1847
Inseob Kim1a0afcc2022-02-14 23:10:51 +09001848func (c *deviceConfig) SystemExtSepolicyPrebuiltApiDir() string {
1849 return String(c.config.productVariables.SystemExtSepolicyPrebuiltApiDir)
1850}
1851
1852func (c *deviceConfig) ProductSepolicyPrebuiltApiDir() string {
1853 return String(c.config.productVariables.ProductSepolicyPrebuiltApiDir)
1854}
1855
1856func (c *deviceConfig) IsPartnerTrebleSepolicyTestEnabled() bool {
1857 return c.SystemExtSepolicyPrebuiltApiDir() != "" || c.ProductSepolicyPrebuiltApiDir() != ""
1858}
1859
Inseob Kim7cf14652021-01-06 23:06:52 +09001860func (c *deviceConfig) DirectedVendorSnapshot() bool {
1861 return c.config.productVariables.DirectedVendorSnapshot
1862}
1863
1864func (c *deviceConfig) VendorSnapshotModules() map[string]bool {
1865 return c.config.productVariables.VendorSnapshotModules
1866}
1867
Jose Galmes4c6895e2021-02-09 07:44:30 -08001868func (c *deviceConfig) DirectedRecoverySnapshot() bool {
1869 return c.config.productVariables.DirectedRecoverySnapshot
1870}
1871
1872func (c *deviceConfig) RecoverySnapshotModules() map[string]bool {
1873 return c.config.productVariables.RecoverySnapshotModules
1874}
1875
Justin DeMartino383bfb32021-02-24 10:49:43 -08001876func createDirsMap(previous map[string]bool, dirs []string) (map[string]bool, error) {
1877 var ret = make(map[string]bool)
1878 for _, dir := range dirs {
1879 clean := filepath.Clean(dir)
1880 if previous[clean] || ret[clean] {
1881 return nil, fmt.Errorf("Duplicate entry %s", dir)
1882 }
1883 ret[clean] = true
1884 }
1885 return ret, nil
1886}
1887
1888func (c *deviceConfig) createDirsMapOnce(onceKey OnceKey, previous map[string]bool, dirs []string) map[string]bool {
1889 dirMap := c.Once(onceKey, func() interface{} {
1890 ret, err := createDirsMap(previous, dirs)
1891 if err != nil {
1892 panic(fmt.Errorf("%s: %w", onceKey.key, err))
1893 }
1894 return ret
1895 })
1896 if dirMap == nil {
1897 return nil
1898 }
1899 return dirMap.(map[string]bool)
1900}
1901
1902var vendorSnapshotDirsExcludedKey = NewOnceKey("VendorSnapshotDirsExcludedMap")
1903
1904func (c *deviceConfig) VendorSnapshotDirsExcludedMap() map[string]bool {
1905 return c.createDirsMapOnce(vendorSnapshotDirsExcludedKey, nil,
1906 c.config.productVariables.VendorSnapshotDirsExcluded)
1907}
1908
1909var vendorSnapshotDirsIncludedKey = NewOnceKey("VendorSnapshotDirsIncludedMap")
1910
1911func (c *deviceConfig) VendorSnapshotDirsIncludedMap() map[string]bool {
1912 excludedMap := c.VendorSnapshotDirsExcludedMap()
1913 return c.createDirsMapOnce(vendorSnapshotDirsIncludedKey, excludedMap,
1914 c.config.productVariables.VendorSnapshotDirsIncluded)
1915}
1916
1917var recoverySnapshotDirsExcludedKey = NewOnceKey("RecoverySnapshotDirsExcludedMap")
1918
1919func (c *deviceConfig) RecoverySnapshotDirsExcludedMap() map[string]bool {
1920 return c.createDirsMapOnce(recoverySnapshotDirsExcludedKey, nil,
1921 c.config.productVariables.RecoverySnapshotDirsExcluded)
1922}
1923
1924var recoverySnapshotDirsIncludedKey = NewOnceKey("RecoverySnapshotDirsIncludedMap")
1925
1926func (c *deviceConfig) RecoverySnapshotDirsIncludedMap() map[string]bool {
1927 excludedMap := c.RecoverySnapshotDirsExcludedMap()
1928 return c.createDirsMapOnce(recoverySnapshotDirsIncludedKey, excludedMap,
1929 c.config.productVariables.RecoverySnapshotDirsIncluded)
1930}
1931
Rob Seymour925aa092021-08-10 20:42:03 +00001932func (c *deviceConfig) HostFakeSnapshotEnabled() bool {
1933 return c.config.productVariables.HostFakeSnapshotEnabled
1934}
1935
Inseob Kim60c32f02020-12-21 22:53:05 +09001936func (c *deviceConfig) ShippingApiLevel() ApiLevel {
1937 if c.config.productVariables.ShippingApiLevel == nil {
1938 return NoneApiLevel
1939 }
1940 apiLevel, _ := strconv.Atoi(*c.config.productVariables.ShippingApiLevel)
1941 return uncheckedFinalApiLevel(apiLevel)
1942}
1943
Liz Kammer33cc80e2023-05-18 18:20:28 +00001944func (c *deviceConfig) BuildBrokenPluginValidation() []string {
1945 return c.config.productVariables.BuildBrokenPluginValidation
1946}
1947
Alix Espinoef47e542022-09-14 19:10:51 +00001948func (c *deviceConfig) BuildBrokenClangAsFlags() bool {
1949 return c.config.productVariables.BuildBrokenClangAsFlags
1950}
1951
1952func (c *deviceConfig) BuildBrokenClangCFlags() bool {
1953 return c.config.productVariables.BuildBrokenClangCFlags
1954}
1955
Alixb5f6d9e2022-04-20 23:00:58 +00001956func (c *deviceConfig) BuildBrokenClangProperty() bool {
1957 return c.config.productVariables.BuildBrokenClangProperty
1958}
1959
Inseob Kim67e5add192021-03-17 18:05:33 +09001960func (c *deviceConfig) BuildBrokenEnforceSyspropOwner() bool {
1961 return c.config.productVariables.BuildBrokenEnforceSyspropOwner
1962}
1963
1964func (c *deviceConfig) BuildBrokenTrebleSyspropNeverallow() bool {
1965 return c.config.productVariables.BuildBrokenTrebleSyspropNeverallow
1966}
1967
Cole Faustedc4c502022-09-09 19:39:25 -07001968func (c *deviceConfig) BuildBrokenUsesSoongPython2Modules() bool {
1969 return c.config.productVariables.BuildBrokenUsesSoongPython2Modules
1970}
1971
Hridya Valsaraju5a5c7d52021-04-02 16:45:24 -07001972func (c *deviceConfig) BuildDebugfsRestrictionsEnabled() bool {
1973 return c.config.productVariables.BuildDebugfsRestrictionsEnabled
1974}
1975
Inseob Kim0cac7b42021-02-03 18:16:46 +09001976func (c *deviceConfig) BuildBrokenVendorPropertyNamespace() bool {
1977 return c.config.productVariables.BuildBrokenVendorPropertyNamespace
1978}
1979
Liz Kammer619be462022-01-28 15:13:39 -05001980func (c *deviceConfig) BuildBrokenInputDir(name string) bool {
1981 return InList(name, c.config.productVariables.BuildBrokenInputDirModules)
1982}
1983
Jiakai Zhang48203e32023-06-02 23:42:21 +01001984func (c *config) BuildWarningBadOptionalUsesLibsAllowlist() []string {
1985 return c.productVariables.BuildWarningBadOptionalUsesLibsAllowlist
1986}
1987
Yu Liu6a7940c2023-05-09 17:12:22 -07001988func (c *deviceConfig) GenruleSandboxing() bool {
1989 return Bool(c.config.productVariables.GenruleSandboxing)
Vinh Tran140d5882022-06-10 14:23:27 -04001990}
1991
Inseob Kim67e5add192021-03-17 18:05:33 +09001992func (c *deviceConfig) RequiresInsecureExecmemForSwiftshader() bool {
1993 return c.config.productVariables.RequiresInsecureExecmemForSwiftshader
1994}
1995
Devin Moorec381e102023-07-06 22:03:58 +00001996func (c *deviceConfig) Release_aidl_use_unfrozen() bool {
1997 return Bool(c.config.productVariables.Release_aidl_use_unfrozen)
1998}
1999
Inseob Kim67e5add192021-03-17 18:05:33 +09002000func (c *config) SelinuxIgnoreNeverallows() bool {
2001 return c.productVariables.SelinuxIgnoreNeverallows
2002}
2003
Inseob Kima10ef272021-09-15 03:04:53 +00002004func (c *deviceConfig) SepolicyFreezeTestExtraDirs() []string {
2005 return c.config.productVariables.SepolicyFreezeTestExtraDirs
2006}
2007
2008func (c *deviceConfig) SepolicyFreezeTestExtraPrebuiltDirs() []string {
2009 return c.config.productVariables.SepolicyFreezeTestExtraPrebuiltDirs
2010}
2011
Jiyong Parkd163d4d2021-10-12 16:47:43 +09002012func (c *deviceConfig) GenerateAidlNdkPlatformBackend() bool {
2013 return c.config.productVariables.GenerateAidlNdkPlatformBackend
2014}
2015
Christopher Ferris98f10222022-07-13 23:16:52 -07002016func (c *config) IgnorePrefer32OnDevice() bool {
2017 return c.productVariables.IgnorePrefer32OnDevice
2018}
2019
Ulya Trafimovich249386a2020-07-01 14:31:13 +01002020func (c *config) BootJars() []string {
2021 return c.Once(earlyBootJarsKey, func() interface{} {
Paul Duffin69d1fb12020-10-23 21:14:20 +01002022 list := c.productVariables.BootJars.CopyOfJars()
satayevd604b212021-07-21 14:23:52 +01002023 return append(list, c.productVariables.ApexBootJars.CopyOfJars()...)
Ulya Trafimovich249386a2020-07-01 14:31:13 +01002024 }).([]string)
2025}
Paul Duffin9a89a2a2020-10-28 19:20:06 +00002026
satayevd604b212021-07-21 14:23:52 +01002027func (c *config) NonApexBootJars() ConfiguredJarList {
Paul Duffin9a89a2a2020-10-28 19:20:06 +00002028 return c.productVariables.BootJars
2029}
2030
satayevd604b212021-07-21 14:23:52 +01002031func (c *config) ApexBootJars() ConfiguredJarList {
2032 return c.productVariables.ApexBootJars
Paul Duffin9a89a2a2020-10-28 19:20:06 +00002033}
Colin Cross77cdcfd2021-03-12 11:28:25 -08002034
2035func (c *config) RBEWrapper() string {
2036 return c.GetenvWithDefault("RBE_WRAPPER", remoteexec.DefaultWrapperPath)
2037}
Colin Cross9b698b62021-12-22 09:55:32 -08002038
2039// UseHostMusl returns true if the host target has been configured to build against musl libc.
2040func (c *config) UseHostMusl() bool {
2041 return Bool(c.productVariables.HostMusl)
2042}
MarkDacekff851b82022-04-21 18:33:17 +00002043
MarkDacekf47e1422023-04-19 16:47:36 +00002044func (c *config) GetMixedBuildsEnabledModules() map[string]struct{} {
2045 return c.mixedBuildEnabledModules
2046}
2047
MarkDacek6f6b9622023-05-02 16:28:55 +00002048func (c *config) GetMixedBuildsDisabledModules() map[string]struct{} {
2049 return c.mixedBuildDisabledModules
2050}
2051
Chris Parsonsf874e462022-05-10 13:50:12 -04002052func (c *config) LogMixedBuild(ctx BaseModuleContext, useBazel bool) {
MarkDacekff851b82022-04-21 18:33:17 +00002053 moduleName := ctx.Module().Name()
2054 c.mixedBuildsLock.Lock()
2055 defer c.mixedBuildsLock.Unlock()
2056 if useBazel {
2057 c.mixedBuildEnabledModules[moduleName] = struct{}{}
2058 } else {
2059 c.mixedBuildDisabledModules[moduleName] = struct{}{}
2060 }
2061}
Spandan Das9e93d3d2023-03-08 05:47:29 +00002062
Chris Parsons0c4de1f2023-09-21 20:36:35 +00002063func (c *config) HasBazelBuildTargetInSource(dir string, target string) bool {
2064 for _, existingTarget := range c.bazelTargetsByDir[dir] {
2065 if target == existingTarget {
Chris Parsons8152a942023-06-06 16:17:50 +00002066 return true
2067 }
2068 }
2069 return false
2070}
2071
2072func (c *config) SetBazelBuildFileTargets(bazelTargetsByDir map[string][]string) {
2073 c.bazelTargetsByDir = bazelTargetsByDir
2074}
2075
Spandan Das9e93d3d2023-03-08 05:47:29 +00002076// ApiSurfaces directory returns the source path inside the api_surfaces repo
2077// (relative to workspace root).
2078func (c *config) ApiSurfacesDir(s ApiSurface, version string) string {
2079 return filepath.Join(
2080 "build",
2081 "bazel",
2082 "api_surfaces",
2083 s.String(),
2084 version)
2085}
Jihoon Kang1bff0342023-01-17 20:40:22 +00002086
Jihoon Kang1975d3e2023-10-16 23:24:11 +00002087func (c *config) JavaCoverageEnabled() bool {
2088 return c.IsEnvTrue("EMMA_INSTRUMENT") || c.IsEnvTrue("EMMA_INSTRUMENT_STATIC") || c.IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK")
2089}
2090
Jihoon Kangc1b04d62023-11-16 19:07:04 +00002091func (c *deviceConfig) BuildFromSourceStub() bool {
2092 return Bool(c.config.productVariables.BuildFromSourceStub)
2093}
2094
Jihoon Kang1bff0342023-01-17 20:40:22 +00002095func (c *config) BuildFromTextStub() bool {
Jihoon Kang1975d3e2023-10-16 23:24:11 +00002096 // TODO: b/302320354 - Remove the coverage build specific logic once the
2097 // robust solution for handling native properties in from-text stub build
2098 // is implemented.
Jihoon Kangc1b04d62023-11-16 19:07:04 +00002099 return !c.buildFromSourceStub &&
2100 !c.JavaCoverageEnabled() &&
2101 !c.deviceConfig.BuildFromSourceStub()
Jihoon Kang1bff0342023-01-17 20:40:22 +00002102}
Spandan Das4deab282023-03-30 17:06:32 +00002103
2104func (c *config) SetBuildFromTextStub(b bool) {
Jihoon Kang2a929ad2023-06-08 19:02:07 +00002105 c.buildFromSourceStub = !b
Jihoon Kangcbcad7c2023-06-01 22:31:52 +00002106 c.productVariables.Build_from_text_stub = boolPtr(b)
Spandan Das4deab282023-03-30 17:06:32 +00002107}
Jihoon Kang1c92c3e2023-03-23 17:44:51 +00002108
MarkDacek9c094ca2023-03-16 19:15:19 +00002109func (c *config) AddForceEnabledModules(forceEnabled []string) {
2110 for _, forceEnabledModule := range forceEnabled {
2111 c.bazelForceEnabledModules[forceEnabledModule] = struct{}{}
2112 }
2113}
Jihoon Kang1c92c3e2023-03-23 17:44:51 +00002114
2115func (c *config) SetApiLibraries(libs []string) {
2116 c.apiLibraries = make(map[string]struct{})
2117 for _, lib := range libs {
2118 c.apiLibraries[lib] = struct{}{}
2119 }
2120}
2121
2122func (c *config) GetApiLibraries() map[string]struct{} {
2123 return c.apiLibraries
2124}
Inseob Kim5bac3b62023-08-25 21:29:46 +09002125
Liz Kammere1b39a52023-09-18 14:32:18 -04002126// Bp2buildMode indicates whether the config is for bp2build mode of Soong
2127func (c *config) Bp2buildMode() bool {
2128 return c.BuildMode == Bp2build
2129}
2130
Inseob Kim5bac3b62023-08-25 21:29:46 +09002131func (c *deviceConfig) CheckVendorSeappViolations() bool {
2132 return Bool(c.config.productVariables.CheckVendorSeappViolations)
2133}
Jihoon Kangcfbc4072023-09-20 01:02:18 +00002134
2135func (c *deviceConfig) NextReleaseHideFlaggedApi() bool {
2136 return Bool(c.config.productVariables.NextReleaseHideFlaggedApi)
2137}
Jihoon Kangf3aa3222023-09-26 22:32:08 +00002138
2139func (c *deviceConfig) ReleaseExposeFlaggedApi() bool {
2140 return Bool(c.config.productVariables.Release_expose_flagged_api)
2141}
Jihoon Kangc8313892023-09-20 00:54:47 +00002142
2143func (c *deviceConfig) HideFlaggedApis() bool {
2144 return c.NextReleaseHideFlaggedApi() && !c.ReleaseExposeFlaggedApi()
2145}
Inseob Kime4e85d52023-10-25 23:53:58 +09002146
2147func (c *config) GetBuildFlag(name string) (string, bool) {
2148 val, ok := c.productVariables.BuildFlags[name]
2149 return val, ok
2150}
Spandan Dase3fcb412023-10-26 20:48:02 +00002151
2152var (
2153 mainlineApexContributionBuildFlags = []string{
2154 "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES",
2155 "RELEASE_APEX_CONTRIBUTIONS_APPSEARCH",
2156 "RELEASE_APEX_CONTRIBUTIONS_ART",
2157 "RELEASE_APEX_CONTRIBUTIONS_BLUETOOTH",
2158 "RELEASE_APEX_CONTRIBUTIONS_CONFIGINFRASTRUCTURE",
2159 "RELEASE_APEX_CONTRIBUTIONS_CONNECTIVITY",
2160 "RELEASE_APEX_CONTRIBUTIONS_CONSCRYPT",
2161 "RELEASE_APEX_CONTRIBUTIONS_CRASHRECOVERY",
2162 "RELEASE_APEX_CONTRIBUTIONS_DEVICELOCK",
2163 "RELEASE_APEX_CONTRIBUTIONS_HEALTHFITNESS",
2164 "RELEASE_APEX_CONTRIBUTIONS_IPSEC",
2165 "RELEASE_APEX_CONTRIBUTIONS_MEDIA",
2166 "RELEASE_APEX_CONTRIBUTIONS_MEDIAPROVIDER",
2167 "RELEASE_APEX_CONTRIBUTIONS_ONDEVICEPERSONALIZATION",
2168 "RELEASE_APEX_CONTRIBUTIONS_PERMISSION",
2169 "RELEASE_APEX_CONTRIBUTIONS_REMOTEKEYPROVISIONING",
2170 "RELEASE_APEX_CONTRIBUTIONS_SCHEDULING",
2171 "RELEASE_APEX_CONTRIBUTIONS_SDKEXTENSIONS",
2172 "RELEASE_APEX_CONTRIBUTIONS_STATSD",
2173 "RELEASE_APEX_CONTRIBUTIONS_UWB",
2174 "RELEASE_APEX_CONTRIBUTIONS_WIFI",
2175 }
2176)
2177
2178// Returns the list of _selected_ apex_contributions
2179// Each mainline module will have one entry in the list
2180func (c *config) AllApexContributions() []string {
2181 ret := []string{}
2182 for _, f := range mainlineApexContributionBuildFlags {
2183 if val, exists := c.GetBuildFlag(f); exists && val != "" {
2184 ret = append(ret, val)
2185 }
2186 }
2187 return ret
2188}