config.go 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841
  1. // Copyright 2015 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package android
  15. // This is the primary location to write and read all configuration values and
  16. // product variables necessary for soong_build's operation.
  17. import (
  18. "bytes"
  19. "encoding/json"
  20. "fmt"
  21. "os"
  22. "path/filepath"
  23. "reflect"
  24. "runtime"
  25. "strconv"
  26. "strings"
  27. "sync"
  28. "github.com/google/blueprint"
  29. "github.com/google/blueprint/bootstrap"
  30. "github.com/google/blueprint/pathtools"
  31. "github.com/google/blueprint/proptools"
  32. "android/soong/android/soongconfig"
  33. "android/soong/bazel"
  34. "android/soong/remoteexec"
  35. "android/soong/starlark_fmt"
  36. )
  37. // Bool re-exports proptools.Bool for the android package.
  38. var Bool = proptools.Bool
  39. // String re-exports proptools.String for the android package.
  40. var String = proptools.String
  41. // StringDefault re-exports proptools.StringDefault for the android package.
  42. var StringDefault = proptools.StringDefault
  43. // FutureApiLevelInt is a placeholder constant for unreleased API levels.
  44. const FutureApiLevelInt = 10000
  45. // FutureApiLevel represents unreleased API levels.
  46. var FutureApiLevel = ApiLevel{
  47. value: "current",
  48. number: FutureApiLevelInt,
  49. isPreview: true,
  50. }
  51. // The product variables file name, containing product config from Kati.
  52. const productVariablesFileName = "soong.variables"
  53. // A Config object represents the entire build configuration for Android.
  54. type Config struct {
  55. *config
  56. }
  57. type SoongBuildMode int
  58. type CmdArgs struct {
  59. bootstrap.Args
  60. RunGoTests bool
  61. OutDir string
  62. SoongOutDir string
  63. SymlinkForestMarker string
  64. Bp2buildMarker string
  65. BazelQueryViewDir string
  66. BazelApiBp2buildDir string
  67. ModuleGraphFile string
  68. ModuleActionsFile string
  69. DocFile string
  70. BazelMode bool
  71. BazelModeDev bool
  72. BazelModeStaging bool
  73. BazelForceEnabledModules string
  74. UseBazelProxy bool
  75. }
  76. // Build modes that soong_build can run as.
  77. const (
  78. // Don't use bazel at all during module analysis.
  79. AnalysisNoBazel SoongBuildMode = iota
  80. // Symlink fores mode: merge two directory trees into a symlink forest
  81. SymlinkForest
  82. // Bp2build mode: Generate BUILD files from blueprint files and exit.
  83. Bp2build
  84. // Generate BUILD files which faithfully represent the dependency graph of
  85. // blueprint modules. Individual BUILD targets will not, however, faitfhully
  86. // express build semantics.
  87. GenerateQueryView
  88. // Generate BUILD files for API contributions to API surfaces
  89. ApiBp2build
  90. // Create a JSON representation of the module graph and exit.
  91. GenerateModuleGraph
  92. // Generate a documentation file for module type definitions and exit.
  93. GenerateDocFile
  94. // Use bazel during analysis of many allowlisted build modules. The allowlist
  95. // is considered a "developer mode" allowlist, as some modules may be
  96. // allowlisted on an experimental basis.
  97. BazelDevMode
  98. // Use bazel during analysis of a few allowlisted build modules. The allowlist
  99. // is considered "staging, as these are modules being prepared to be released
  100. // into prod mode shortly after.
  101. BazelStagingMode
  102. // Use bazel during analysis of build modules from an allowlist carefully
  103. // curated by the build team to be proven stable.
  104. BazelProdMode
  105. )
  106. // SoongOutDir returns the build output directory for the configuration.
  107. func (c Config) SoongOutDir() string {
  108. return c.soongOutDir
  109. }
  110. func (c Config) OutDir() string {
  111. return c.outDir
  112. }
  113. func (c Config) RunGoTests() bool {
  114. return c.runGoTests
  115. }
  116. func (c Config) DebugCompilation() bool {
  117. return false // Never compile Go code in the main build for debugging
  118. }
  119. func (c Config) Subninjas() []string {
  120. return []string{}
  121. }
  122. func (c Config) PrimaryBuilderInvocations() []bootstrap.PrimaryBuilderInvocation {
  123. return []bootstrap.PrimaryBuilderInvocation{}
  124. }
  125. // RunningInsideUnitTest returns true if this code is being run as part of a Soong unit test.
  126. func (c Config) RunningInsideUnitTest() bool {
  127. return c.config.TestProductVariables != nil
  128. }
  129. // A DeviceConfig object represents the configuration for a particular device
  130. // being built. For now there will only be one of these, but in the future there
  131. // may be multiple devices being built.
  132. type DeviceConfig struct {
  133. *deviceConfig
  134. }
  135. // VendorConfig represents the configuration for vendor-specific behavior.
  136. type VendorConfig soongconfig.SoongConfig
  137. // Definition of general build configuration for soong_build. Some of these
  138. // product configuration values are read from Kati-generated soong.variables.
  139. type config struct {
  140. // Options configurable with soong.variables
  141. productVariables productVariables
  142. // Only available on configs created by TestConfig
  143. TestProductVariables *productVariables
  144. // A specialized context object for Bazel/Soong mixed builds and migration
  145. // purposes.
  146. BazelContext BazelContext
  147. ProductVariablesFileName string
  148. // BuildOS stores the OsType for the OS that the build is running on.
  149. BuildOS OsType
  150. // BuildArch stores the ArchType for the CPU that the build is running on.
  151. BuildArch ArchType
  152. Targets map[OsType][]Target
  153. BuildOSTarget Target // the Target for tools run on the build machine
  154. BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine
  155. AndroidCommonTarget Target // the Target for common modules for the Android device
  156. AndroidFirstDeviceTarget Target // the first Target for modules for the Android device
  157. // multilibConflicts for an ArchType is true if there is earlier configured
  158. // device architecture with the same multilib value.
  159. multilibConflicts map[ArchType]bool
  160. deviceConfig *deviceConfig
  161. outDir string // The output directory (usually out/)
  162. soongOutDir string
  163. moduleListFile string // the path to the file which lists blueprint files to parse.
  164. runGoTests bool
  165. env map[string]string
  166. envLock sync.Mutex
  167. envDeps map[string]string
  168. envFrozen bool
  169. // Changes behavior based on whether Kati runs after soong_build, or if soong_build
  170. // runs standalone.
  171. katiEnabled bool
  172. captureBuild bool // true for tests, saves build parameters for each module
  173. ignoreEnvironment bool // true for tests, returns empty from all Getenv calls
  174. fs pathtools.FileSystem
  175. mockBpList string
  176. BuildMode SoongBuildMode
  177. Bp2buildPackageConfig Bp2BuildConversionAllowlist
  178. Bp2buildSoongConfigDefinitions soongconfig.Bp2BuildSoongConfigDefinitions
  179. // If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error
  180. // in tests when a path doesn't exist.
  181. TestAllowNonExistentPaths bool
  182. // The list of files that when changed, must invalidate soong_build to
  183. // regenerate build.ninja.
  184. ninjaFileDepsSet sync.Map
  185. OncePer
  186. // These fields are only used for metrics collection. A module should be added
  187. // to these maps only if its implementation supports Bazel handling in mixed
  188. // builds. A module being in the "enabled" list indicates that there is a
  189. // variant of that module for which bazel-handling actually took place.
  190. // A module being in the "disabled" list indicates that there is a variant of
  191. // that module for which bazel-handling was denied.
  192. mixedBuildsLock sync.Mutex
  193. mixedBuildEnabledModules map[string]struct{}
  194. mixedBuildDisabledModules map[string]struct{}
  195. // These are modules to be built with Bazel beyond the allowlisted/build-mode
  196. // specified modules. They are passed via the command-line flag
  197. // "--bazel-force-enabled-modules"
  198. bazelForceEnabledModules map[string]struct{}
  199. // If true, for any requests to Bazel, communicate with a Bazel proxy using
  200. // unix sockets, instead of spawning Bazel as a subprocess.
  201. UseBazelProxy bool
  202. }
  203. type deviceConfig struct {
  204. config *config
  205. OncePer
  206. }
  207. type jsonConfigurable interface {
  208. SetDefaultConfig()
  209. }
  210. func loadConfig(config *config) error {
  211. return loadFromConfigFile(&config.productVariables, absolutePath(config.ProductVariablesFileName))
  212. }
  213. // loadFromConfigFile loads and decodes configuration options from a JSON file
  214. // in the current working directory.
  215. func loadFromConfigFile(configurable *productVariables, filename string) error {
  216. // Try to open the file
  217. configFileReader, err := os.Open(filename)
  218. defer configFileReader.Close()
  219. if os.IsNotExist(err) {
  220. // Need to create a file, so that blueprint & ninja don't get in
  221. // a dependency tracking loop.
  222. // Make a file-configurable-options with defaults, write it out using
  223. // a json writer.
  224. configurable.SetDefaultConfig()
  225. err = saveToConfigFile(configurable, filename)
  226. if err != nil {
  227. return err
  228. }
  229. } else if err != nil {
  230. return fmt.Errorf("config file: could not open %s: %s", filename, err.Error())
  231. } else {
  232. // Make a decoder for it
  233. jsonDecoder := json.NewDecoder(configFileReader)
  234. err = jsonDecoder.Decode(configurable)
  235. if err != nil {
  236. return fmt.Errorf("config file: %s did not parse correctly: %s", filename, err.Error())
  237. }
  238. }
  239. if Bool(configurable.GcovCoverage) && Bool(configurable.ClangCoverage) {
  240. return fmt.Errorf("GcovCoverage and ClangCoverage cannot both be set")
  241. }
  242. configurable.Native_coverage = proptools.BoolPtr(
  243. Bool(configurable.GcovCoverage) ||
  244. Bool(configurable.ClangCoverage))
  245. // when Platform_sdk_final is true (or PLATFORM_VERSION_CODENAME is REL), use Platform_sdk_version;
  246. // if false (pre-released version, for example), use Platform_sdk_codename.
  247. if Bool(configurable.Platform_sdk_final) {
  248. if configurable.Platform_sdk_version != nil {
  249. configurable.Platform_sdk_version_or_codename =
  250. proptools.StringPtr(strconv.Itoa(*(configurable.Platform_sdk_version)))
  251. } else {
  252. return fmt.Errorf("Platform_sdk_version cannot be pointed by a NULL pointer")
  253. }
  254. } else {
  255. configurable.Platform_sdk_version_or_codename =
  256. proptools.StringPtr(String(configurable.Platform_sdk_codename))
  257. }
  258. return saveToBazelConfigFile(configurable, filepath.Dir(filename))
  259. }
  260. // atomically writes the config file in case two copies of soong_build are running simultaneously
  261. // (for example, docs generation and ninja manifest generation)
  262. func saveToConfigFile(config *productVariables, filename string) error {
  263. data, err := json.MarshalIndent(&config, "", " ")
  264. if err != nil {
  265. return fmt.Errorf("cannot marshal config data: %s", err.Error())
  266. }
  267. f, err := os.CreateTemp(filepath.Dir(filename), "config")
  268. if err != nil {
  269. return fmt.Errorf("cannot create empty config file %s: %s", filename, err.Error())
  270. }
  271. defer os.Remove(f.Name())
  272. defer f.Close()
  273. _, err = f.Write(data)
  274. if err != nil {
  275. return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
  276. }
  277. _, err = f.WriteString("\n")
  278. if err != nil {
  279. return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
  280. }
  281. f.Close()
  282. os.Rename(f.Name(), filename)
  283. return nil
  284. }
  285. func saveToBazelConfigFile(config *productVariables, outDir string) error {
  286. dir := filepath.Join(outDir, bazel.SoongInjectionDirName, "product_config")
  287. err := createDirIfNonexistent(dir, os.ModePerm)
  288. if err != nil {
  289. return fmt.Errorf("Could not create dir %s: %s", dir, err)
  290. }
  291. nonArchVariantProductVariables := []string{}
  292. archVariantProductVariables := []string{}
  293. p := variableProperties{}
  294. t := reflect.TypeOf(p.Product_variables)
  295. for i := 0; i < t.NumField(); i++ {
  296. f := t.Field(i)
  297. nonArchVariantProductVariables = append(nonArchVariantProductVariables, strings.ToLower(f.Name))
  298. if proptools.HasTag(f, "android", "arch_variant") {
  299. archVariantProductVariables = append(archVariantProductVariables, strings.ToLower(f.Name))
  300. }
  301. }
  302. nonArchVariantProductVariablesJson := starlark_fmt.PrintStringList(nonArchVariantProductVariables, 0)
  303. if err != nil {
  304. return fmt.Errorf("cannot marshal product variable data: %s", err.Error())
  305. }
  306. archVariantProductVariablesJson := starlark_fmt.PrintStringList(archVariantProductVariables, 0)
  307. if err != nil {
  308. return fmt.Errorf("cannot marshal arch variant product variable data: %s", err.Error())
  309. }
  310. configJson, err := json.MarshalIndent(&config, "", " ")
  311. if err != nil {
  312. return fmt.Errorf("cannot marshal config data: %s", err.Error())
  313. }
  314. // The backslashes need to be escaped because this text is going to be put
  315. // inside a Starlark string literal.
  316. configJson = bytes.ReplaceAll(configJson, []byte("\\"), []byte("\\\\"))
  317. bzl := []string{
  318. bazel.GeneratedBazelFileWarning,
  319. fmt.Sprintf(`_product_vars = json.decode("""%s""")`, configJson),
  320. fmt.Sprintf(`_product_var_constraints = %s`, nonArchVariantProductVariablesJson),
  321. fmt.Sprintf(`_arch_variant_product_var_constraints = %s`, archVariantProductVariablesJson),
  322. "\n", `
  323. product_vars = _product_vars
  324. product_var_constraints = _product_var_constraints
  325. arch_variant_product_var_constraints = _arch_variant_product_var_constraints
  326. `,
  327. }
  328. err = pathtools.WriteFileIfChanged(filepath.Join(dir, "product_variables.bzl"),
  329. []byte(strings.Join(bzl, "\n")), 0644)
  330. if err != nil {
  331. return fmt.Errorf("Could not write .bzl config file %s", err)
  332. }
  333. err = pathtools.WriteFileIfChanged(filepath.Join(dir, "BUILD"),
  334. []byte(bazel.GeneratedBazelFileWarning), 0644)
  335. if err != nil {
  336. return fmt.Errorf("Could not write BUILD config file %s", err)
  337. }
  338. return nil
  339. }
  340. // NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that
  341. // use the android package.
  342. func NullConfig(outDir, soongOutDir string) Config {
  343. return Config{
  344. config: &config{
  345. outDir: outDir,
  346. soongOutDir: soongOutDir,
  347. fs: pathtools.OsFs,
  348. },
  349. }
  350. }
  351. // NewConfig creates a new Config object. The srcDir argument specifies the path
  352. // to the root source directory. It also loads the config file, if found.
  353. func NewConfig(cmdArgs CmdArgs, availableEnv map[string]string) (Config, error) {
  354. // Make a config with default options.
  355. config := &config{
  356. ProductVariablesFileName: filepath.Join(cmdArgs.SoongOutDir, productVariablesFileName),
  357. env: availableEnv,
  358. outDir: cmdArgs.OutDir,
  359. soongOutDir: cmdArgs.SoongOutDir,
  360. runGoTests: cmdArgs.RunGoTests,
  361. multilibConflicts: make(map[ArchType]bool),
  362. moduleListFile: cmdArgs.ModuleListFile,
  363. fs: pathtools.NewOsFs(absSrcDir),
  364. mixedBuildDisabledModules: make(map[string]struct{}),
  365. mixedBuildEnabledModules: make(map[string]struct{}),
  366. bazelForceEnabledModules: make(map[string]struct{}),
  367. UseBazelProxy: cmdArgs.UseBazelProxy,
  368. }
  369. config.deviceConfig = &deviceConfig{
  370. config: config,
  371. }
  372. // Soundness check of the build and source directories. This won't catch strange
  373. // configurations with symlinks, but at least checks the obvious case.
  374. absBuildDir, err := filepath.Abs(cmdArgs.SoongOutDir)
  375. if err != nil {
  376. return Config{}, err
  377. }
  378. absSrcDir, err := filepath.Abs(".")
  379. if err != nil {
  380. return Config{}, err
  381. }
  382. if strings.HasPrefix(absSrcDir, absBuildDir) {
  383. return Config{}, fmt.Errorf("Build dir must not contain source directory")
  384. }
  385. // Load any configurable options from the configuration file
  386. err = loadConfig(config)
  387. if err != nil {
  388. return Config{}, err
  389. }
  390. KatiEnabledMarkerFile := filepath.Join(cmdArgs.SoongOutDir, ".soong.kati_enabled")
  391. if _, err := os.Stat(absolutePath(KatiEnabledMarkerFile)); err == nil {
  392. config.katiEnabled = true
  393. }
  394. determineBuildOS(config)
  395. // Sets up the map of target OSes to the finer grained compilation targets
  396. // that are configured from the product variables.
  397. targets, err := decodeTargetProductVariables(config)
  398. if err != nil {
  399. return Config{}, err
  400. }
  401. // Make the CommonOS OsType available for all products.
  402. targets[CommonOS] = []Target{commonTargetMap[CommonOS.Name]}
  403. var archConfig []archConfig
  404. if config.NdkAbis() {
  405. archConfig = getNdkAbisConfig()
  406. } else if config.AmlAbis() {
  407. archConfig = getAmlAbisConfig()
  408. }
  409. if archConfig != nil {
  410. androidTargets, err := decodeAndroidArchSettings(archConfig)
  411. if err != nil {
  412. return Config{}, err
  413. }
  414. targets[Android] = androidTargets
  415. }
  416. multilib := make(map[string]bool)
  417. for _, target := range targets[Android] {
  418. if seen := multilib[target.Arch.ArchType.Multilib]; seen {
  419. config.multilibConflicts[target.Arch.ArchType] = true
  420. }
  421. multilib[target.Arch.ArchType.Multilib] = true
  422. }
  423. // Map of OS to compilation targets.
  424. config.Targets = targets
  425. // Compilation targets for host tools.
  426. config.BuildOSTarget = config.Targets[config.BuildOS][0]
  427. config.BuildOSCommonTarget = getCommonTargets(config.Targets[config.BuildOS])[0]
  428. // Compilation targets for Android.
  429. if len(config.Targets[Android]) > 0 {
  430. config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
  431. config.AndroidFirstDeviceTarget = FirstTarget(config.Targets[Android], "lib64", "lib32")[0]
  432. }
  433. setBuildMode := func(arg string, mode SoongBuildMode) {
  434. if arg != "" {
  435. if config.BuildMode != AnalysisNoBazel {
  436. fmt.Fprintf(os.Stderr, "buildMode is already set, illegal argument: %s", arg)
  437. os.Exit(1)
  438. }
  439. config.BuildMode = mode
  440. }
  441. }
  442. setBazelMode := func(arg bool, argName string, mode SoongBuildMode) {
  443. if arg {
  444. if config.BuildMode != AnalysisNoBazel {
  445. fmt.Fprintf(os.Stderr, "buildMode is already set, illegal argument: %s", argName)
  446. os.Exit(1)
  447. }
  448. config.BuildMode = mode
  449. }
  450. }
  451. setBuildMode(cmdArgs.SymlinkForestMarker, SymlinkForest)
  452. setBuildMode(cmdArgs.Bp2buildMarker, Bp2build)
  453. setBuildMode(cmdArgs.BazelQueryViewDir, GenerateQueryView)
  454. setBuildMode(cmdArgs.BazelApiBp2buildDir, ApiBp2build)
  455. setBuildMode(cmdArgs.ModuleGraphFile, GenerateModuleGraph)
  456. setBuildMode(cmdArgs.DocFile, GenerateDocFile)
  457. setBazelMode(cmdArgs.BazelModeDev, "--bazel-mode-dev", BazelDevMode)
  458. setBazelMode(cmdArgs.BazelMode, "--bazel-mode", BazelProdMode)
  459. setBazelMode(cmdArgs.BazelModeStaging, "--bazel-mode-staging", BazelStagingMode)
  460. config.BazelContext, err = NewBazelContext(config)
  461. config.Bp2buildPackageConfig = GetBp2BuildAllowList()
  462. for _, module := range strings.Split(cmdArgs.BazelForceEnabledModules, ",") {
  463. config.bazelForceEnabledModules[module] = struct{}{}
  464. }
  465. return Config{config}, err
  466. }
  467. // mockFileSystem replaces all reads with accesses to the provided map of
  468. // filenames to contents stored as a byte slice.
  469. func (c *config) mockFileSystem(bp string, fs map[string][]byte) {
  470. mockFS := map[string][]byte{}
  471. if _, exists := mockFS["Android.bp"]; !exists {
  472. mockFS["Android.bp"] = []byte(bp)
  473. }
  474. for k, v := range fs {
  475. mockFS[k] = v
  476. }
  477. // no module list file specified; find every file named Blueprints or Android.bp
  478. pathsToParse := []string{}
  479. for candidate := range mockFS {
  480. base := filepath.Base(candidate)
  481. if base == "Android.bp" {
  482. pathsToParse = append(pathsToParse, candidate)
  483. }
  484. }
  485. if len(pathsToParse) < 1 {
  486. panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", mockFS))
  487. }
  488. mockFS[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n"))
  489. c.fs = pathtools.MockFs(mockFS)
  490. c.mockBpList = blueprint.MockModuleListFile
  491. }
  492. // TODO(b/265062549): Add a field to our collected (and uploaded) metrics which
  493. // describes a reason that we fell back to non-mixed builds.
  494. // Returns true if "Bazel builds" is enabled. In this mode, part of build
  495. // analysis is handled by Bazel.
  496. func (c *config) IsMixedBuildsEnabled() bool {
  497. globalMixedBuildsSupport := c.Once(OnceKey{"globalMixedBuildsSupport"}, func() interface{} {
  498. if c.productVariables.DeviceArch != nil && *c.productVariables.DeviceArch == "riscv64" {
  499. return false
  500. }
  501. if c.IsEnvTrue("GLOBAL_THINLTO") {
  502. return false
  503. }
  504. if len(c.productVariables.SanitizeHost) > 0 {
  505. return false
  506. }
  507. if len(c.productVariables.SanitizeDevice) > 0 {
  508. return false
  509. }
  510. if len(c.productVariables.SanitizeDeviceDiag) > 0 {
  511. return false
  512. }
  513. if len(c.productVariables.SanitizeDeviceArch) > 0 {
  514. return false
  515. }
  516. return true
  517. }).(bool)
  518. bazelModeEnabled := c.BuildMode == BazelProdMode || c.BuildMode == BazelDevMode || c.BuildMode == BazelStagingMode
  519. return globalMixedBuildsSupport && bazelModeEnabled
  520. }
  521. func (c *config) SetAllowMissingDependencies() {
  522. c.productVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
  523. }
  524. // BlueprintToolLocation returns the directory containing build system tools
  525. // from Blueprint, like soong_zip and merge_zips.
  526. func (c *config) HostToolDir() string {
  527. if c.KatiEnabled() {
  528. return filepath.Join(c.outDir, "host", c.PrebuiltOS(), "bin")
  529. } else {
  530. return filepath.Join(c.soongOutDir, "host", c.PrebuiltOS(), "bin")
  531. }
  532. }
  533. func (c *config) HostToolPath(ctx PathContext, tool string) Path {
  534. path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "bin", false, tool)
  535. return path
  536. }
  537. func (c *config) HostJNIToolPath(ctx PathContext, lib string) Path {
  538. ext := ".so"
  539. if runtime.GOOS == "darwin" {
  540. ext = ".dylib"
  541. }
  542. path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "lib64", false, lib+ext)
  543. return path
  544. }
  545. func (c *config) HostJavaToolPath(ctx PathContext, tool string) Path {
  546. path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "framework", false, tool)
  547. return path
  548. }
  549. // PrebuiltOS returns the name of the host OS used in prebuilts directories.
  550. func (c *config) PrebuiltOS() string {
  551. switch runtime.GOOS {
  552. case "linux":
  553. return "linux-x86"
  554. case "darwin":
  555. return "darwin-x86"
  556. default:
  557. panic("Unknown GOOS")
  558. }
  559. }
  560. // GoRoot returns the path to the root directory of the Go toolchain.
  561. func (c *config) GoRoot() string {
  562. return fmt.Sprintf("prebuilts/go/%s", c.PrebuiltOS())
  563. }
  564. // PrebuiltBuildTool returns the path to a tool in the prebuilts directory containing
  565. // checked-in tools, like Kati, Ninja or Toybox, for the current host OS.
  566. func (c *config) PrebuiltBuildTool(ctx PathContext, tool string) Path {
  567. return PathForSource(ctx, "prebuilts/build-tools", c.PrebuiltOS(), "bin", tool)
  568. }
  569. // CpPreserveSymlinksFlags returns the host-specific flag for the cp(1) command
  570. // to preserve symlinks.
  571. func (c *config) CpPreserveSymlinksFlags() string {
  572. switch runtime.GOOS {
  573. case "darwin":
  574. return "-R"
  575. case "linux":
  576. return "-d"
  577. default:
  578. return ""
  579. }
  580. }
  581. func (c *config) Getenv(key string) string {
  582. var val string
  583. var exists bool
  584. c.envLock.Lock()
  585. defer c.envLock.Unlock()
  586. if c.envDeps == nil {
  587. c.envDeps = make(map[string]string)
  588. }
  589. if val, exists = c.envDeps[key]; !exists {
  590. if c.envFrozen {
  591. panic("Cannot access new environment variables after envdeps are frozen")
  592. }
  593. val, _ = c.env[key]
  594. c.envDeps[key] = val
  595. }
  596. return val
  597. }
  598. func (c *config) GetenvWithDefault(key string, defaultValue string) string {
  599. ret := c.Getenv(key)
  600. if ret == "" {
  601. return defaultValue
  602. }
  603. return ret
  604. }
  605. func (c *config) IsEnvTrue(key string) bool {
  606. value := c.Getenv(key)
  607. return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
  608. }
  609. func (c *config) IsEnvFalse(key string) bool {
  610. value := c.Getenv(key)
  611. return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
  612. }
  613. func (c *config) TargetsJava17() bool {
  614. return c.IsEnvTrue("EXPERIMENTAL_TARGET_JAVA_VERSION_17")
  615. }
  616. // EnvDeps returns the environment variables this build depends on. The first
  617. // call to this function blocks future reads from the environment.
  618. func (c *config) EnvDeps() map[string]string {
  619. c.envLock.Lock()
  620. defer c.envLock.Unlock()
  621. c.envFrozen = true
  622. return c.envDeps
  623. }
  624. func (c *config) KatiEnabled() bool {
  625. return c.katiEnabled
  626. }
  627. func (c *config) BuildId() string {
  628. return String(c.productVariables.BuildId)
  629. }
  630. // BuildNumberFile returns the path to a text file containing metadata
  631. // representing the current build's number.
  632. //
  633. // Rules that want to reference the build number should read from this file
  634. // without depending on it. They will run whenever their other dependencies
  635. // require them to run and get the current build number. This ensures they don't
  636. // rebuild on every incremental build when the build number changes.
  637. func (c *config) BuildNumberFile(ctx PathContext) Path {
  638. return PathForOutput(ctx, String(c.productVariables.BuildNumberFile))
  639. }
  640. // DeviceName returns the name of the current device target.
  641. // TODO: take an AndroidModuleContext to select the device name for multi-device builds
  642. func (c *config) DeviceName() string {
  643. return *c.productVariables.DeviceName
  644. }
  645. // DeviceProduct returns the current product target. There could be multiple of
  646. // these per device type.
  647. //
  648. // NOTE: Do not base conditional logic on this value. It may break product inheritance.
  649. func (c *config) DeviceProduct() string {
  650. return *c.productVariables.DeviceProduct
  651. }
  652. // HasDeviceProduct returns if the build has a product. A build will not
  653. // necessarily have a product when --skip-config is passed to soong, like it is
  654. // in prebuilts/build-tools/build-prebuilts.sh
  655. func (c *config) HasDeviceProduct() bool {
  656. return c.productVariables.DeviceProduct != nil
  657. }
  658. func (c *config) DeviceResourceOverlays() []string {
  659. return c.productVariables.DeviceResourceOverlays
  660. }
  661. func (c *config) ProductResourceOverlays() []string {
  662. return c.productVariables.ProductResourceOverlays
  663. }
  664. func (c *config) PlatformVersionName() string {
  665. return String(c.productVariables.Platform_version_name)
  666. }
  667. func (c *config) PlatformSdkVersion() ApiLevel {
  668. return uncheckedFinalApiLevel(*c.productVariables.Platform_sdk_version)
  669. }
  670. func (c *config) PlatformSdkFinal() bool {
  671. return Bool(c.productVariables.Platform_sdk_final)
  672. }
  673. func (c *config) PlatformSdkCodename() string {
  674. return String(c.productVariables.Platform_sdk_codename)
  675. }
  676. func (c *config) PlatformSdkExtensionVersion() int {
  677. return *c.productVariables.Platform_sdk_extension_version
  678. }
  679. func (c *config) PlatformBaseSdkExtensionVersion() int {
  680. return *c.productVariables.Platform_base_sdk_extension_version
  681. }
  682. func (c *config) PlatformSecurityPatch() string {
  683. return String(c.productVariables.Platform_security_patch)
  684. }
  685. func (c *config) PlatformPreviewSdkVersion() string {
  686. return String(c.productVariables.Platform_preview_sdk_version)
  687. }
  688. func (c *config) PlatformMinSupportedTargetSdkVersion() string {
  689. return String(c.productVariables.Platform_min_supported_target_sdk_version)
  690. }
  691. func (c *config) PlatformBaseOS() string {
  692. return String(c.productVariables.Platform_base_os)
  693. }
  694. func (c *config) PlatformVersionLastStable() string {
  695. return String(c.productVariables.Platform_version_last_stable)
  696. }
  697. func (c *config) PlatformVersionKnownCodenames() string {
  698. return String(c.productVariables.Platform_version_known_codenames)
  699. }
  700. func (c *config) MinSupportedSdkVersion() ApiLevel {
  701. return uncheckedFinalApiLevel(21)
  702. }
  703. func (c *config) FinalApiLevels() []ApiLevel {
  704. var levels []ApiLevel
  705. for i := 1; i <= c.PlatformSdkVersion().FinalOrFutureInt(); i++ {
  706. levels = append(levels, uncheckedFinalApiLevel(i))
  707. }
  708. return levels
  709. }
  710. func (c *config) PreviewApiLevels() []ApiLevel {
  711. var levels []ApiLevel
  712. for i, codename := range c.PlatformVersionActiveCodenames() {
  713. levels = append(levels, ApiLevel{
  714. value: codename,
  715. number: i,
  716. isPreview: true,
  717. })
  718. }
  719. return levels
  720. }
  721. func (c *config) LatestPreviewApiLevel() ApiLevel {
  722. level := NoneApiLevel
  723. for _, l := range c.PreviewApiLevels() {
  724. if l.GreaterThan(level) {
  725. level = l
  726. }
  727. }
  728. return level
  729. }
  730. func (c *config) AllSupportedApiLevels() []ApiLevel {
  731. var levels []ApiLevel
  732. levels = append(levels, c.FinalApiLevels()...)
  733. return append(levels, c.PreviewApiLevels()...)
  734. }
  735. // DefaultAppTargetSdk returns the API level that platform apps are targeting.
  736. // This converts a codename to the exact ApiLevel it represents.
  737. func (c *config) DefaultAppTargetSdk(ctx EarlyModuleContext) ApiLevel {
  738. if Bool(c.productVariables.Platform_sdk_final) {
  739. return c.PlatformSdkVersion()
  740. }
  741. codename := c.PlatformSdkCodename()
  742. if codename == "" {
  743. return NoneApiLevel
  744. }
  745. if codename == "REL" {
  746. panic("Platform_sdk_codename should not be REL when Platform_sdk_final is true")
  747. }
  748. return ApiLevelOrPanic(ctx, codename)
  749. }
  750. func (c *config) AppsDefaultVersionName() string {
  751. return String(c.productVariables.AppsDefaultVersionName)
  752. }
  753. // Codenames that are active in the current lunch target.
  754. func (c *config) PlatformVersionActiveCodenames() []string {
  755. return c.productVariables.Platform_version_active_codenames
  756. }
  757. func (c *config) ProductAAPTConfig() []string {
  758. return c.productVariables.AAPTConfig
  759. }
  760. func (c *config) ProductAAPTPreferredConfig() string {
  761. return String(c.productVariables.AAPTPreferredConfig)
  762. }
  763. func (c *config) ProductAAPTCharacteristics() string {
  764. return String(c.productVariables.AAPTCharacteristics)
  765. }
  766. func (c *config) ProductAAPTPrebuiltDPI() []string {
  767. return c.productVariables.AAPTPrebuiltDPI
  768. }
  769. func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
  770. defaultCert := String(c.productVariables.DefaultAppCertificate)
  771. if defaultCert != "" {
  772. return PathForSource(ctx, filepath.Dir(defaultCert))
  773. }
  774. return PathForSource(ctx, "build/make/target/product/security")
  775. }
  776. func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
  777. defaultCert := String(c.productVariables.DefaultAppCertificate)
  778. if defaultCert != "" {
  779. return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8")
  780. }
  781. defaultDir := c.DefaultAppCertificateDir(ctx)
  782. return defaultDir.Join(ctx, "testkey.x509.pem"), defaultDir.Join(ctx, "testkey.pk8")
  783. }
  784. func (c *config) ApexKeyDir(ctx ModuleContext) SourcePath {
  785. // TODO(b/121224311): define another variable such as TARGET_APEX_KEY_OVERRIDE
  786. defaultCert := String(c.productVariables.DefaultAppCertificate)
  787. if defaultCert == "" || filepath.Dir(defaultCert) == "build/make/target/product/security" {
  788. // When defaultCert is unset or is set to the testkeys path, use the APEX keys
  789. // that is under the module dir
  790. return pathForModuleSrc(ctx)
  791. }
  792. // If not, APEX keys are under the specified directory
  793. return PathForSource(ctx, filepath.Dir(defaultCert))
  794. }
  795. // Certificate for the NetworkStack sepolicy context
  796. func (c *config) MainlineSepolicyDevCertificatesDir(ctx ModuleContext) SourcePath {
  797. cert := String(c.productVariables.MainlineSepolicyDevCertificates)
  798. if cert != "" {
  799. return PathForSource(ctx, cert)
  800. }
  801. return c.DefaultAppCertificateDir(ctx)
  802. }
  803. // AllowMissingDependencies configures Blueprint/Soong to not fail when modules
  804. // are configured to depend on non-existent modules. Note that this does not
  805. // affect missing input dependencies at the Ninja level.
  806. func (c *config) AllowMissingDependencies() bool {
  807. return Bool(c.productVariables.Allow_missing_dependencies)
  808. }
  809. // Returns true if a full platform source tree cannot be assumed.
  810. func (c *config) UnbundledBuild() bool {
  811. return Bool(c.productVariables.Unbundled_build)
  812. }
  813. // Returns true if building apps that aren't bundled with the platform.
  814. // UnbundledBuild() is always true when this is true.
  815. func (c *config) UnbundledBuildApps() bool {
  816. return len(c.productVariables.Unbundled_build_apps) > 0
  817. }
  818. // Returns true if building image that aren't bundled with the platform.
  819. // UnbundledBuild() is always true when this is true.
  820. func (c *config) UnbundledBuildImage() bool {
  821. return Bool(c.productVariables.Unbundled_build_image)
  822. }
  823. // Returns true if building modules against prebuilt SDKs.
  824. func (c *config) AlwaysUsePrebuiltSdks() bool {
  825. return Bool(c.productVariables.Always_use_prebuilt_sdks)
  826. }
  827. func (c *config) MinimizeJavaDebugInfo() bool {
  828. return Bool(c.productVariables.MinimizeJavaDebugInfo) && !Bool(c.productVariables.Eng)
  829. }
  830. func (c *config) Debuggable() bool {
  831. return Bool(c.productVariables.Debuggable)
  832. }
  833. func (c *config) Eng() bool {
  834. return Bool(c.productVariables.Eng)
  835. }
  836. // DevicePrimaryArchType returns the ArchType for the first configured device architecture, or
  837. // Common if there are no device architectures.
  838. func (c *config) DevicePrimaryArchType() ArchType {
  839. if androidTargets := c.Targets[Android]; len(androidTargets) > 0 {
  840. return androidTargets[0].Arch.ArchType
  841. }
  842. return Common
  843. }
  844. func (c *config) SanitizeHost() []string {
  845. return append([]string(nil), c.productVariables.SanitizeHost...)
  846. }
  847. func (c *config) SanitizeDevice() []string {
  848. return append([]string(nil), c.productVariables.SanitizeDevice...)
  849. }
  850. func (c *config) SanitizeDeviceDiag() []string {
  851. return append([]string(nil), c.productVariables.SanitizeDeviceDiag...)
  852. }
  853. func (c *config) SanitizeDeviceArch() []string {
  854. return append([]string(nil), c.productVariables.SanitizeDeviceArch...)
  855. }
  856. func (c *config) EnableCFI() bool {
  857. if c.productVariables.EnableCFI == nil {
  858. return true
  859. }
  860. return *c.productVariables.EnableCFI
  861. }
  862. func (c *config) DisableScudo() bool {
  863. return Bool(c.productVariables.DisableScudo)
  864. }
  865. func (c *config) Android64() bool {
  866. for _, t := range c.Targets[Android] {
  867. if t.Arch.ArchType.Multilib == "lib64" {
  868. return true
  869. }
  870. }
  871. return false
  872. }
  873. func (c *config) UseGoma() bool {
  874. return Bool(c.productVariables.UseGoma)
  875. }
  876. func (c *config) UseRBE() bool {
  877. return Bool(c.productVariables.UseRBE)
  878. }
  879. func (c *config) UseRBEJAVAC() bool {
  880. return Bool(c.productVariables.UseRBEJAVAC)
  881. }
  882. func (c *config) UseRBER8() bool {
  883. return Bool(c.productVariables.UseRBER8)
  884. }
  885. func (c *config) UseRBED8() bool {
  886. return Bool(c.productVariables.UseRBED8)
  887. }
  888. func (c *config) UseRemoteBuild() bool {
  889. return c.UseGoma() || c.UseRBE()
  890. }
  891. func (c *config) RunErrorProne() bool {
  892. return c.IsEnvTrue("RUN_ERROR_PRONE")
  893. }
  894. // XrefCorpusName returns the Kythe cross-reference corpus name.
  895. func (c *config) XrefCorpusName() string {
  896. return c.Getenv("XREF_CORPUS")
  897. }
  898. // XrefCuEncoding returns the compilation unit encoding to use for Kythe code
  899. // xrefs. Can be 'json' (default), 'proto' or 'all'.
  900. func (c *config) XrefCuEncoding() string {
  901. if enc := c.Getenv("KYTHE_KZIP_ENCODING"); enc != "" {
  902. return enc
  903. }
  904. return "json"
  905. }
  906. // XrefCuJavaSourceMax returns the maximum number of the Java source files
  907. // in a single compilation unit
  908. const xrefJavaSourceFileMaxDefault = "1000"
  909. func (c Config) XrefCuJavaSourceMax() string {
  910. v := c.Getenv("KYTHE_JAVA_SOURCE_BATCH_SIZE")
  911. if v == "" {
  912. return xrefJavaSourceFileMaxDefault
  913. }
  914. if _, err := strconv.ParseUint(v, 0, 0); err != nil {
  915. fmt.Fprintf(os.Stderr,
  916. "bad KYTHE_JAVA_SOURCE_BATCH_SIZE value: %s, will use %s",
  917. err, xrefJavaSourceFileMaxDefault)
  918. return xrefJavaSourceFileMaxDefault
  919. }
  920. return v
  921. }
  922. func (c *config) EmitXrefRules() bool {
  923. return c.XrefCorpusName() != ""
  924. }
  925. func (c *config) ClangTidy() bool {
  926. return Bool(c.productVariables.ClangTidy)
  927. }
  928. func (c *config) TidyChecks() string {
  929. if c.productVariables.TidyChecks == nil {
  930. return ""
  931. }
  932. return *c.productVariables.TidyChecks
  933. }
  934. func (c *config) LibartImgHostBaseAddress() string {
  935. return "0x60000000"
  936. }
  937. func (c *config) LibartImgDeviceBaseAddress() string {
  938. return "0x70000000"
  939. }
  940. func (c *config) ArtUseReadBarrier() bool {
  941. return Bool(c.productVariables.ArtUseReadBarrier)
  942. }
  943. // Enforce Runtime Resource Overlays for a module. RROs supersede static RROs,
  944. // but some modules still depend on it.
  945. //
  946. // More info: https://source.android.com/devices/architecture/rros
  947. func (c *config) EnforceRROForModule(name string) bool {
  948. enforceList := c.productVariables.EnforceRROTargets
  949. if len(enforceList) > 0 {
  950. if InList("*", enforceList) {
  951. return true
  952. }
  953. return InList(name, enforceList)
  954. }
  955. return false
  956. }
  957. func (c *config) EnforceRROExcludedOverlay(path string) bool {
  958. excluded := c.productVariables.EnforceRROExcludedOverlays
  959. if len(excluded) > 0 {
  960. return HasAnyPrefix(path, excluded)
  961. }
  962. return false
  963. }
  964. func (c *config) ExportedNamespaces() []string {
  965. return append([]string(nil), c.productVariables.NamespacesToExport...)
  966. }
  967. func (c *config) IncludeTags() []string {
  968. return c.productVariables.IncludeTags
  969. }
  970. func (c *config) HostStaticBinaries() bool {
  971. return Bool(c.productVariables.HostStaticBinaries)
  972. }
  973. func (c *config) UncompressPrivAppDex() bool {
  974. return Bool(c.productVariables.UncompressPrivAppDex)
  975. }
  976. func (c *config) ModulesLoadedByPrivilegedModules() []string {
  977. return c.productVariables.ModulesLoadedByPrivilegedModules
  978. }
  979. // DexpreoptGlobalConfigPath returns the path to the dexpreopt.config file in
  980. // the output directory, if it was created during the product configuration
  981. // phase by Kati.
  982. func (c *config) DexpreoptGlobalConfigPath(ctx PathContext) OptionalPath {
  983. if c.productVariables.DexpreoptGlobalConfig == nil {
  984. return OptionalPathForPath(nil)
  985. }
  986. return OptionalPathForPath(
  987. pathForBuildToolDep(ctx, *c.productVariables.DexpreoptGlobalConfig))
  988. }
  989. // DexpreoptGlobalConfig returns the raw byte contents of the dexpreopt global
  990. // configuration. Since the configuration file was created by Kati during
  991. // product configuration (externally of soong_build), it's not tracked, so we
  992. // also manually add a Ninja file dependency on the configuration file to the
  993. // rule that creates the main build.ninja file. This ensures that build.ninja is
  994. // regenerated correctly if dexpreopt.config changes.
  995. func (c *config) DexpreoptGlobalConfig(ctx PathContext) ([]byte, error) {
  996. path := c.DexpreoptGlobalConfigPath(ctx)
  997. if !path.Valid() {
  998. return nil, nil
  999. }
  1000. ctx.AddNinjaFileDeps(path.String())
  1001. return os.ReadFile(absolutePath(path.String()))
  1002. }
  1003. func (c *deviceConfig) WithDexpreopt() bool {
  1004. return c.config.productVariables.WithDexpreopt
  1005. }
  1006. func (c *config) FrameworksBaseDirExists(ctx PathGlobContext) bool {
  1007. return ExistentPathForSource(ctx, "frameworks", "base", "Android.bp").Valid()
  1008. }
  1009. func (c *config) VndkSnapshotBuildArtifacts() bool {
  1010. return Bool(c.productVariables.VndkSnapshotBuildArtifacts)
  1011. }
  1012. func (c *config) HasMultilibConflict(arch ArchType) bool {
  1013. return c.multilibConflicts[arch]
  1014. }
  1015. func (c *config) PrebuiltHiddenApiDir(_ PathContext) string {
  1016. return String(c.productVariables.PrebuiltHiddenApiDir)
  1017. }
  1018. func (c *config) BazelModulesForceEnabledByFlag() map[string]struct{} {
  1019. return c.bazelForceEnabledModules
  1020. }
  1021. func (c *deviceConfig) Arches() []Arch {
  1022. var arches []Arch
  1023. for _, target := range c.config.Targets[Android] {
  1024. arches = append(arches, target.Arch)
  1025. }
  1026. return arches
  1027. }
  1028. func (c *deviceConfig) BinderBitness() string {
  1029. is32BitBinder := c.config.productVariables.Binder32bit
  1030. if is32BitBinder != nil && *is32BitBinder {
  1031. return "32"
  1032. }
  1033. return "64"
  1034. }
  1035. func (c *deviceConfig) VendorPath() string {
  1036. if c.config.productVariables.VendorPath != nil {
  1037. return *c.config.productVariables.VendorPath
  1038. }
  1039. return "vendor"
  1040. }
  1041. func (c *deviceConfig) VndkVersion() string {
  1042. return String(c.config.productVariables.DeviceVndkVersion)
  1043. }
  1044. func (c *deviceConfig) RecoverySnapshotVersion() string {
  1045. return String(c.config.productVariables.RecoverySnapshotVersion)
  1046. }
  1047. func (c *deviceConfig) CurrentApiLevelForVendorModules() string {
  1048. return StringDefault(c.config.productVariables.DeviceCurrentApiLevelForVendorModules, "current")
  1049. }
  1050. func (c *deviceConfig) PlatformVndkVersion() string {
  1051. return String(c.config.productVariables.Platform_vndk_version)
  1052. }
  1053. func (c *deviceConfig) ProductVndkVersion() string {
  1054. return String(c.config.productVariables.ProductVndkVersion)
  1055. }
  1056. func (c *deviceConfig) ExtraVndkVersions() []string {
  1057. return c.config.productVariables.ExtraVndkVersions
  1058. }
  1059. func (c *deviceConfig) VndkUseCoreVariant() bool {
  1060. return Bool(c.config.productVariables.VndkUseCoreVariant)
  1061. }
  1062. func (c *deviceConfig) SystemSdkVersions() []string {
  1063. return c.config.productVariables.DeviceSystemSdkVersions
  1064. }
  1065. func (c *deviceConfig) PlatformSystemSdkVersions() []string {
  1066. return c.config.productVariables.Platform_systemsdk_versions
  1067. }
  1068. func (c *deviceConfig) OdmPath() string {
  1069. if c.config.productVariables.OdmPath != nil {
  1070. return *c.config.productVariables.OdmPath
  1071. }
  1072. return "odm"
  1073. }
  1074. func (c *deviceConfig) ProductPath() string {
  1075. if c.config.productVariables.ProductPath != nil {
  1076. return *c.config.productVariables.ProductPath
  1077. }
  1078. return "product"
  1079. }
  1080. func (c *deviceConfig) SystemExtPath() string {
  1081. if c.config.productVariables.SystemExtPath != nil {
  1082. return *c.config.productVariables.SystemExtPath
  1083. }
  1084. return "system_ext"
  1085. }
  1086. func (c *deviceConfig) BtConfigIncludeDir() string {
  1087. return String(c.config.productVariables.BtConfigIncludeDir)
  1088. }
  1089. func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
  1090. return c.config.productVariables.DeviceKernelHeaders
  1091. }
  1092. // JavaCoverageEnabledForPath returns whether Java code coverage is enabled for
  1093. // path. Coverage is enabled by default when the product variable
  1094. // JavaCoveragePaths is empty. If JavaCoveragePaths is not empty, coverage is
  1095. // enabled for any path which is part of this variable (and not part of the
  1096. // JavaCoverageExcludePaths product variable). Value "*" in JavaCoveragePaths
  1097. // represents any path.
  1098. func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool {
  1099. coverage := false
  1100. if len(c.config.productVariables.JavaCoveragePaths) == 0 ||
  1101. InList("*", c.config.productVariables.JavaCoveragePaths) ||
  1102. HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) {
  1103. coverage = true
  1104. }
  1105. if coverage && len(c.config.productVariables.JavaCoverageExcludePaths) > 0 {
  1106. if HasAnyPrefix(path, c.config.productVariables.JavaCoverageExcludePaths) {
  1107. coverage = false
  1108. }
  1109. }
  1110. return coverage
  1111. }
  1112. // Returns true if gcov or clang coverage is enabled.
  1113. func (c *deviceConfig) NativeCoverageEnabled() bool {
  1114. return Bool(c.config.productVariables.GcovCoverage) ||
  1115. Bool(c.config.productVariables.ClangCoverage)
  1116. }
  1117. func (c *deviceConfig) ClangCoverageEnabled() bool {
  1118. return Bool(c.config.productVariables.ClangCoverage)
  1119. }
  1120. func (c *deviceConfig) ClangCoverageContinuousMode() bool {
  1121. return Bool(c.config.productVariables.ClangCoverageContinuousMode)
  1122. }
  1123. func (c *deviceConfig) GcovCoverageEnabled() bool {
  1124. return Bool(c.config.productVariables.GcovCoverage)
  1125. }
  1126. // NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native
  1127. // code coverage is enabled for path. By default, coverage is not enabled for a
  1128. // given path unless it is part of the NativeCoveragePaths product variable (and
  1129. // not part of the NativeCoverageExcludePaths product variable). Value "*" in
  1130. // NativeCoveragePaths represents any path.
  1131. func (c *deviceConfig) NativeCoverageEnabledForPath(path string) bool {
  1132. coverage := false
  1133. if len(c.config.productVariables.NativeCoveragePaths) > 0 {
  1134. if InList("*", c.config.productVariables.NativeCoveragePaths) || HasAnyPrefix(path, c.config.productVariables.NativeCoveragePaths) {
  1135. coverage = true
  1136. }
  1137. }
  1138. if coverage && len(c.config.productVariables.NativeCoverageExcludePaths) > 0 {
  1139. if HasAnyPrefix(path, c.config.productVariables.NativeCoverageExcludePaths) {
  1140. coverage = false
  1141. }
  1142. }
  1143. return coverage
  1144. }
  1145. func (c *deviceConfig) PgoAdditionalProfileDirs() []string {
  1146. return c.config.productVariables.PgoAdditionalProfileDirs
  1147. }
  1148. func (c *deviceConfig) VendorSepolicyDirs() []string {
  1149. return c.config.productVariables.BoardVendorSepolicyDirs
  1150. }
  1151. func (c *deviceConfig) OdmSepolicyDirs() []string {
  1152. return c.config.productVariables.BoardOdmSepolicyDirs
  1153. }
  1154. func (c *deviceConfig) SystemExtPublicSepolicyDirs() []string {
  1155. return c.config.productVariables.SystemExtPublicSepolicyDirs
  1156. }
  1157. func (c *deviceConfig) SystemExtPrivateSepolicyDirs() []string {
  1158. return c.config.productVariables.SystemExtPrivateSepolicyDirs
  1159. }
  1160. func (c *deviceConfig) SepolicyM4Defs() []string {
  1161. return c.config.productVariables.BoardSepolicyM4Defs
  1162. }
  1163. func (c *deviceConfig) OverrideManifestPackageNameFor(name string) (manifestName string, overridden bool) {
  1164. return findOverrideValue(c.config.productVariables.ManifestPackageNameOverrides, name,
  1165. "invalid override rule %q in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES should be <module_name>:<manifest_name>")
  1166. }
  1167. func (c *deviceConfig) OverrideCertificateFor(name string) (certificatePath string, overridden bool) {
  1168. return findOverrideValue(c.config.productVariables.CertificateOverrides, name,
  1169. "invalid override rule %q in PRODUCT_CERTIFICATE_OVERRIDES should be <module_name>:<certificate_module_name>")
  1170. }
  1171. func (c *deviceConfig) OverridePackageNameFor(name string) string {
  1172. newName, overridden := findOverrideValue(
  1173. c.config.productVariables.PackageNameOverrides,
  1174. name,
  1175. "invalid override rule %q in PRODUCT_PACKAGE_NAME_OVERRIDES should be <module_name>:<package_name>")
  1176. if overridden {
  1177. return newName
  1178. }
  1179. return name
  1180. }
  1181. func findOverrideValue(overrides []string, name string, errorMsg string) (newValue string, overridden bool) {
  1182. if overrides == nil || len(overrides) == 0 {
  1183. return "", false
  1184. }
  1185. for _, o := range overrides {
  1186. split := strings.Split(o, ":")
  1187. if len(split) != 2 {
  1188. // This shouldn't happen as this is first checked in make, but just in case.
  1189. panic(fmt.Errorf(errorMsg, o))
  1190. }
  1191. if matchPattern(split[0], name) {
  1192. return substPattern(split[0], split[1], name), true
  1193. }
  1194. }
  1195. return "", false
  1196. }
  1197. func (c *deviceConfig) ApexGlobalMinSdkVersionOverride() string {
  1198. return String(c.config.productVariables.ApexGlobalMinSdkVersionOverride)
  1199. }
  1200. func (c *config) IntegerOverflowDisabledForPath(path string) bool {
  1201. if len(c.productVariables.IntegerOverflowExcludePaths) == 0 {
  1202. return false
  1203. }
  1204. return HasAnyPrefix(path, c.productVariables.IntegerOverflowExcludePaths)
  1205. }
  1206. func (c *config) CFIDisabledForPath(path string) bool {
  1207. if len(c.productVariables.CFIExcludePaths) == 0 {
  1208. return false
  1209. }
  1210. return HasAnyPrefix(path, c.productVariables.CFIExcludePaths)
  1211. }
  1212. func (c *config) CFIEnabledForPath(path string) bool {
  1213. if len(c.productVariables.CFIIncludePaths) == 0 {
  1214. return false
  1215. }
  1216. return HasAnyPrefix(path, c.productVariables.CFIIncludePaths) && !c.CFIDisabledForPath(path)
  1217. }
  1218. func (c *config) MemtagHeapDisabledForPath(path string) bool {
  1219. if len(c.productVariables.MemtagHeapExcludePaths) == 0 {
  1220. return false
  1221. }
  1222. return HasAnyPrefix(path, c.productVariables.MemtagHeapExcludePaths)
  1223. }
  1224. func (c *config) MemtagHeapAsyncEnabledForPath(path string) bool {
  1225. if len(c.productVariables.MemtagHeapAsyncIncludePaths) == 0 {
  1226. return false
  1227. }
  1228. return HasAnyPrefix(path, c.productVariables.MemtagHeapAsyncIncludePaths) && !c.MemtagHeapDisabledForPath(path)
  1229. }
  1230. func (c *config) MemtagHeapSyncEnabledForPath(path string) bool {
  1231. if len(c.productVariables.MemtagHeapSyncIncludePaths) == 0 {
  1232. return false
  1233. }
  1234. return HasAnyPrefix(path, c.productVariables.MemtagHeapSyncIncludePaths) && !c.MemtagHeapDisabledForPath(path)
  1235. }
  1236. func (c *config) VendorConfig(name string) VendorConfig {
  1237. return soongconfig.Config(c.productVariables.VendorVars[name])
  1238. }
  1239. func (c *config) NdkAbis() bool {
  1240. return Bool(c.productVariables.Ndk_abis)
  1241. }
  1242. func (c *config) AmlAbis() bool {
  1243. return Bool(c.productVariables.Aml_abis)
  1244. }
  1245. func (c *config) FlattenApex() bool {
  1246. return Bool(c.productVariables.Flatten_apex)
  1247. }
  1248. func (c *config) ForceApexSymlinkOptimization() bool {
  1249. return Bool(c.productVariables.ForceApexSymlinkOptimization)
  1250. }
  1251. func (c *config) ApexCompressionEnabled() bool {
  1252. return Bool(c.productVariables.CompressedApex) && !c.UnbundledBuildApps()
  1253. }
  1254. func (c *config) ApexTrimEnabled() bool {
  1255. return Bool(c.productVariables.TrimmedApex)
  1256. }
  1257. func (c *config) EnforceSystemCertificate() bool {
  1258. return Bool(c.productVariables.EnforceSystemCertificate)
  1259. }
  1260. func (c *config) EnforceSystemCertificateAllowList() []string {
  1261. return c.productVariables.EnforceSystemCertificateAllowList
  1262. }
  1263. func (c *config) EnforceProductPartitionInterface() bool {
  1264. return Bool(c.productVariables.EnforceProductPartitionInterface)
  1265. }
  1266. func (c *config) EnforceInterPartitionJavaSdkLibrary() bool {
  1267. return Bool(c.productVariables.EnforceInterPartitionJavaSdkLibrary)
  1268. }
  1269. func (c *config) InterPartitionJavaLibraryAllowList() []string {
  1270. return c.productVariables.InterPartitionJavaLibraryAllowList
  1271. }
  1272. func (c *config) InstallExtraFlattenedApexes() bool {
  1273. return Bool(c.productVariables.InstallExtraFlattenedApexes)
  1274. }
  1275. func (c *config) ProductHiddenAPIStubs() []string {
  1276. return c.productVariables.ProductHiddenAPIStubs
  1277. }
  1278. func (c *config) ProductHiddenAPIStubsSystem() []string {
  1279. return c.productVariables.ProductHiddenAPIStubsSystem
  1280. }
  1281. func (c *config) ProductHiddenAPIStubsTest() []string {
  1282. return c.productVariables.ProductHiddenAPIStubsTest
  1283. }
  1284. func (c *deviceConfig) TargetFSConfigGen() []string {
  1285. return c.config.productVariables.TargetFSConfigGen
  1286. }
  1287. func (c *config) ProductPublicSepolicyDirs() []string {
  1288. return c.productVariables.ProductPublicSepolicyDirs
  1289. }
  1290. func (c *config) ProductPrivateSepolicyDirs() []string {
  1291. return c.productVariables.ProductPrivateSepolicyDirs
  1292. }
  1293. func (c *config) MissingUsesLibraries() []string {
  1294. return c.productVariables.MissingUsesLibraries
  1295. }
  1296. func (c *config) TargetMultitreeUpdateMeta() bool {
  1297. return c.productVariables.MultitreeUpdateMeta
  1298. }
  1299. func (c *deviceConfig) DeviceArch() string {
  1300. return String(c.config.productVariables.DeviceArch)
  1301. }
  1302. func (c *deviceConfig) DeviceArchVariant() string {
  1303. return String(c.config.productVariables.DeviceArchVariant)
  1304. }
  1305. func (c *deviceConfig) DeviceSecondaryArch() string {
  1306. return String(c.config.productVariables.DeviceSecondaryArch)
  1307. }
  1308. func (c *deviceConfig) DeviceSecondaryArchVariant() string {
  1309. return String(c.config.productVariables.DeviceSecondaryArchVariant)
  1310. }
  1311. func (c *deviceConfig) BoardUsesRecoveryAsBoot() bool {
  1312. return Bool(c.config.productVariables.BoardUsesRecoveryAsBoot)
  1313. }
  1314. func (c *deviceConfig) BoardKernelBinaries() []string {
  1315. return c.config.productVariables.BoardKernelBinaries
  1316. }
  1317. func (c *deviceConfig) BoardKernelModuleInterfaceVersions() []string {
  1318. return c.config.productVariables.BoardKernelModuleInterfaceVersions
  1319. }
  1320. func (c *deviceConfig) BoardMoveRecoveryResourcesToVendorBoot() bool {
  1321. return Bool(c.config.productVariables.BoardMoveRecoveryResourcesToVendorBoot)
  1322. }
  1323. func (c *deviceConfig) PlatformSepolicyVersion() string {
  1324. return String(c.config.productVariables.PlatformSepolicyVersion)
  1325. }
  1326. func (c *deviceConfig) TotSepolicyVersion() string {
  1327. return String(c.config.productVariables.TotSepolicyVersion)
  1328. }
  1329. func (c *deviceConfig) PlatformSepolicyCompatVersions() []string {
  1330. return c.config.productVariables.PlatformSepolicyCompatVersions
  1331. }
  1332. func (c *deviceConfig) BoardSepolicyVers() string {
  1333. if ver := String(c.config.productVariables.BoardSepolicyVers); ver != "" {
  1334. return ver
  1335. }
  1336. return c.PlatformSepolicyVersion()
  1337. }
  1338. func (c *deviceConfig) BoardPlatVendorPolicy() []string {
  1339. return c.config.productVariables.BoardPlatVendorPolicy
  1340. }
  1341. func (c *deviceConfig) BoardReqdMaskPolicy() []string {
  1342. return c.config.productVariables.BoardReqdMaskPolicy
  1343. }
  1344. func (c *deviceConfig) BoardSystemExtPublicPrebuiltDirs() []string {
  1345. return c.config.productVariables.BoardSystemExtPublicPrebuiltDirs
  1346. }
  1347. func (c *deviceConfig) BoardSystemExtPrivatePrebuiltDirs() []string {
  1348. return c.config.productVariables.BoardSystemExtPrivatePrebuiltDirs
  1349. }
  1350. func (c *deviceConfig) BoardProductPublicPrebuiltDirs() []string {
  1351. return c.config.productVariables.BoardProductPublicPrebuiltDirs
  1352. }
  1353. func (c *deviceConfig) BoardProductPrivatePrebuiltDirs() []string {
  1354. return c.config.productVariables.BoardProductPrivatePrebuiltDirs
  1355. }
  1356. func (c *deviceConfig) SystemExtSepolicyPrebuiltApiDir() string {
  1357. return String(c.config.productVariables.SystemExtSepolicyPrebuiltApiDir)
  1358. }
  1359. func (c *deviceConfig) ProductSepolicyPrebuiltApiDir() string {
  1360. return String(c.config.productVariables.ProductSepolicyPrebuiltApiDir)
  1361. }
  1362. func (c *deviceConfig) IsPartnerTrebleSepolicyTestEnabled() bool {
  1363. return c.SystemExtSepolicyPrebuiltApiDir() != "" || c.ProductSepolicyPrebuiltApiDir() != ""
  1364. }
  1365. func (c *deviceConfig) DirectedVendorSnapshot() bool {
  1366. return c.config.productVariables.DirectedVendorSnapshot
  1367. }
  1368. func (c *deviceConfig) VendorSnapshotModules() map[string]bool {
  1369. return c.config.productVariables.VendorSnapshotModules
  1370. }
  1371. func (c *deviceConfig) DirectedRecoverySnapshot() bool {
  1372. return c.config.productVariables.DirectedRecoverySnapshot
  1373. }
  1374. func (c *deviceConfig) RecoverySnapshotModules() map[string]bool {
  1375. return c.config.productVariables.RecoverySnapshotModules
  1376. }
  1377. func createDirsMap(previous map[string]bool, dirs []string) (map[string]bool, error) {
  1378. var ret = make(map[string]bool)
  1379. for _, dir := range dirs {
  1380. clean := filepath.Clean(dir)
  1381. if previous[clean] || ret[clean] {
  1382. return nil, fmt.Errorf("Duplicate entry %s", dir)
  1383. }
  1384. ret[clean] = true
  1385. }
  1386. return ret, nil
  1387. }
  1388. func (c *deviceConfig) createDirsMapOnce(onceKey OnceKey, previous map[string]bool, dirs []string) map[string]bool {
  1389. dirMap := c.Once(onceKey, func() interface{} {
  1390. ret, err := createDirsMap(previous, dirs)
  1391. if err != nil {
  1392. panic(fmt.Errorf("%s: %w", onceKey.key, err))
  1393. }
  1394. return ret
  1395. })
  1396. if dirMap == nil {
  1397. return nil
  1398. }
  1399. return dirMap.(map[string]bool)
  1400. }
  1401. var vendorSnapshotDirsExcludedKey = NewOnceKey("VendorSnapshotDirsExcludedMap")
  1402. func (c *deviceConfig) VendorSnapshotDirsExcludedMap() map[string]bool {
  1403. return c.createDirsMapOnce(vendorSnapshotDirsExcludedKey, nil,
  1404. c.config.productVariables.VendorSnapshotDirsExcluded)
  1405. }
  1406. var vendorSnapshotDirsIncludedKey = NewOnceKey("VendorSnapshotDirsIncludedMap")
  1407. func (c *deviceConfig) VendorSnapshotDirsIncludedMap() map[string]bool {
  1408. excludedMap := c.VendorSnapshotDirsExcludedMap()
  1409. return c.createDirsMapOnce(vendorSnapshotDirsIncludedKey, excludedMap,
  1410. c.config.productVariables.VendorSnapshotDirsIncluded)
  1411. }
  1412. var recoverySnapshotDirsExcludedKey = NewOnceKey("RecoverySnapshotDirsExcludedMap")
  1413. func (c *deviceConfig) RecoverySnapshotDirsExcludedMap() map[string]bool {
  1414. return c.createDirsMapOnce(recoverySnapshotDirsExcludedKey, nil,
  1415. c.config.productVariables.RecoverySnapshotDirsExcluded)
  1416. }
  1417. var recoverySnapshotDirsIncludedKey = NewOnceKey("RecoverySnapshotDirsIncludedMap")
  1418. func (c *deviceConfig) RecoverySnapshotDirsIncludedMap() map[string]bool {
  1419. excludedMap := c.RecoverySnapshotDirsExcludedMap()
  1420. return c.createDirsMapOnce(recoverySnapshotDirsIncludedKey, excludedMap,
  1421. c.config.productVariables.RecoverySnapshotDirsIncluded)
  1422. }
  1423. func (c *deviceConfig) HostFakeSnapshotEnabled() bool {
  1424. return c.config.productVariables.HostFakeSnapshotEnabled
  1425. }
  1426. func (c *deviceConfig) ShippingApiLevel() ApiLevel {
  1427. if c.config.productVariables.ShippingApiLevel == nil {
  1428. return NoneApiLevel
  1429. }
  1430. apiLevel, _ := strconv.Atoi(*c.config.productVariables.ShippingApiLevel)
  1431. return uncheckedFinalApiLevel(apiLevel)
  1432. }
  1433. func (c *deviceConfig) BuildBrokenClangAsFlags() bool {
  1434. return c.config.productVariables.BuildBrokenClangAsFlags
  1435. }
  1436. func (c *deviceConfig) BuildBrokenClangCFlags() bool {
  1437. return c.config.productVariables.BuildBrokenClangCFlags
  1438. }
  1439. func (c *deviceConfig) BuildBrokenClangProperty() bool {
  1440. return c.config.productVariables.BuildBrokenClangProperty
  1441. }
  1442. func (c *deviceConfig) BuildBrokenEnforceSyspropOwner() bool {
  1443. return c.config.productVariables.BuildBrokenEnforceSyspropOwner
  1444. }
  1445. func (c *deviceConfig) BuildBrokenTrebleSyspropNeverallow() bool {
  1446. return c.config.productVariables.BuildBrokenTrebleSyspropNeverallow
  1447. }
  1448. func (c *deviceConfig) BuildDebugfsRestrictionsEnabled() bool {
  1449. return c.config.productVariables.BuildDebugfsRestrictionsEnabled
  1450. }
  1451. func (c *deviceConfig) BuildBrokenVendorPropertyNamespace() bool {
  1452. return c.config.productVariables.BuildBrokenVendorPropertyNamespace
  1453. }
  1454. func (c *deviceConfig) BuildBrokenInputDir(name string) bool {
  1455. return InList(name, c.config.productVariables.BuildBrokenInputDirModules)
  1456. }
  1457. func (c *deviceConfig) BuildBrokenDepfile() bool {
  1458. return Bool(c.config.productVariables.BuildBrokenDepfile)
  1459. }
  1460. func (c *deviceConfig) RequiresInsecureExecmemForSwiftshader() bool {
  1461. return c.config.productVariables.RequiresInsecureExecmemForSwiftshader
  1462. }
  1463. func (c *config) SelinuxIgnoreNeverallows() bool {
  1464. return c.productVariables.SelinuxIgnoreNeverallows
  1465. }
  1466. func (c *deviceConfig) SepolicySplit() bool {
  1467. return c.config.productVariables.SepolicySplit
  1468. }
  1469. func (c *deviceConfig) SepolicyFreezeTestExtraDirs() []string {
  1470. return c.config.productVariables.SepolicyFreezeTestExtraDirs
  1471. }
  1472. func (c *deviceConfig) SepolicyFreezeTestExtraPrebuiltDirs() []string {
  1473. return c.config.productVariables.SepolicyFreezeTestExtraPrebuiltDirs
  1474. }
  1475. func (c *deviceConfig) GenerateAidlNdkPlatformBackend() bool {
  1476. return c.config.productVariables.GenerateAidlNdkPlatformBackend
  1477. }
  1478. func (c *config) IgnorePrefer32OnDevice() bool {
  1479. return c.productVariables.IgnorePrefer32OnDevice
  1480. }
  1481. func (c *config) BootJars() []string {
  1482. return c.Once(earlyBootJarsKey, func() interface{} {
  1483. list := c.productVariables.BootJars.CopyOfJars()
  1484. return append(list, c.productVariables.ApexBootJars.CopyOfJars()...)
  1485. }).([]string)
  1486. }
  1487. func (c *config) NonApexBootJars() ConfiguredJarList {
  1488. return c.productVariables.BootJars
  1489. }
  1490. func (c *config) ApexBootJars() ConfiguredJarList {
  1491. return c.productVariables.ApexBootJars
  1492. }
  1493. func (c *config) RBEWrapper() string {
  1494. return c.GetenvWithDefault("RBE_WRAPPER", remoteexec.DefaultWrapperPath)
  1495. }
  1496. // UseHostMusl returns true if the host target has been configured to build against musl libc.
  1497. func (c *config) UseHostMusl() bool {
  1498. return Bool(c.productVariables.HostMusl)
  1499. }
  1500. func (c *config) LogMixedBuild(ctx BaseModuleContext, useBazel bool) {
  1501. moduleName := ctx.Module().Name()
  1502. c.mixedBuildsLock.Lock()
  1503. defer c.mixedBuildsLock.Unlock()
  1504. if useBazel {
  1505. c.mixedBuildEnabledModules[moduleName] = struct{}{}
  1506. } else {
  1507. c.mixedBuildDisabledModules[moduleName] = struct{}{}
  1508. }
  1509. }