blob: 4a94c0bcb8487b0356ee480e1e729326b0b6bfdb [file] [log] [blame]
Colin Crossce75d2c2016-10-06 16:12:58 -07001// Copyright 2016 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
15package android
16
Colin Cross74d73e22017-08-02 11:05:49 -070017import (
18 "fmt"
Jaewoong Jung3e18b192019-06-11 12:25:34 -070019 "reflect"
Paul Duffind23c7262020-12-11 18:13:08 +000020 "strings"
Colin Cross74d73e22017-08-02 11:05:49 -070021
22 "github.com/google/blueprint"
Jaewoong Jung939ebd52019-03-26 15:07:36 -070023 "github.com/google/blueprint/proptools"
Colin Cross74d73e22017-08-02 11:05:49 -070024)
Colin Crossce75d2c2016-10-06 16:12:58 -070025
26// This file implements common functionality for handling modules that may exist as prebuilts,
27// source, or both.
28
Paul Duffin0c4979b2019-12-19 15:11:53 +000029func RegisterPrebuiltMutators(ctx RegistrationContext) {
30 ctx.PreArchMutators(RegisterPrebuiltsPreArchMutators)
Colin Crossd8d8b852024-12-20 16:32:37 -080031 ctx.PreDepsMutators(RegisterPrebuiltsPreDepsMutators)
Paul Duffin0c4979b2019-12-19 15:11:53 +000032 ctx.PostDepsMutators(RegisterPrebuiltsPostDepsMutators)
33}
34
Paul Duffin80342d72020-06-26 22:08:43 +010035// Marks a dependency tag as possibly preventing a reference to a source from being
36// replaced with the prebuilt.
37type ReplaceSourceWithPrebuilt interface {
38 blueprint.DependencyTag
39
40 // Return true if the dependency defined by this tag should be replaced with the
41 // prebuilt.
42 ReplaceSourceWithPrebuilt() bool
43}
44
Nan Zhang2502e122017-03-09 18:43:01 -080045type prebuiltDependencyTag struct {
46 blueprint.BaseDependencyTag
47}
48
Jiyong Park03b68dd2019-07-26 23:20:40 +090049var PrebuiltDepTag prebuiltDependencyTag
Colin Crossce75d2c2016-10-06 16:12:58 -070050
Paul Duffin78ac5b92020-01-14 12:42:08 +000051// Mark this tag so dependencies that use it are excluded from visibility enforcement.
52func (t prebuiltDependencyTag) ExcludeFromVisibilityEnforcement() {}
53
Paul Duffindddd5462020-04-07 15:25:44 +010054// Mark this tag so dependencies that use it are excluded from APEX contents.
55func (t prebuiltDependencyTag) ExcludeFromApexContents() {}
56
57var _ ExcludeFromVisibilityEnforcementTag = PrebuiltDepTag
58var _ ExcludeFromApexContentsTag = PrebuiltDepTag
59
Paul Duffinbf4de042022-09-27 12:41:52 +010060// UserSuppliedPrebuiltProperties contains the prebuilt properties that can be specified in an
61// Android.bp file.
62type UserSuppliedPrebuiltProperties struct {
Colin Cross74d73e22017-08-02 11:05:49 -070063 // When prefer is set to true the prebuilt will be used instead of any source module with
64 // a matching name.
Cole Faust12ff57d2024-07-30 13:17:28 -070065 Prefer proptools.Configurable[bool] `android:"arch_variant,replace_instead_of_append"`
Colin Crossce75d2c2016-10-06 16:12:58 -070066
Paul Duffin0c52c7b2021-07-06 17:15:25 +010067 // When specified this names a Soong config variable that controls the prefer property.
68 //
69 // If the value of the named Soong config variable is true then prefer is set to false and vice
70 // versa. If the Soong config variable is not set then it defaults to false, so prefer defaults
71 // to true.
72 //
73 // If specified then the prefer property is ignored in favor of the value of the Soong config
74 // variable.
Spandan Dasa9cf0c82024-04-01 22:28:59 +000075 //
76 // DEPRECATED: This property is being deprecated b/308188211.
77 // Use RELEASE_APEX_CONTRIBUTIONS build flags to select prebuilts of mainline modules.
Paul Duffin0c52c7b2021-07-06 17:15:25 +010078 Use_source_config_var *ConfigVarProperties
Paul Duffinbf4de042022-09-27 12:41:52 +010079}
80
81// CopyUserSuppliedPropertiesFromPrebuilt copies the user supplied prebuilt properties from the
82// prebuilt properties.
83func (u *UserSuppliedPrebuiltProperties) CopyUserSuppliedPropertiesFromPrebuilt(p *Prebuilt) {
84 *u = p.properties.UserSuppliedPrebuiltProperties
85}
86
87type PrebuiltProperties struct {
88 UserSuppliedPrebuiltProperties
Paul Duffin0c52c7b2021-07-06 17:15:25 +010089
Colin Cross74d73e22017-08-02 11:05:49 -070090 SourceExists bool `blueprint:"mutated"`
91 UsePrebuilt bool `blueprint:"mutated"`
Martin Stjernholm009a9dc2020-03-05 17:34:13 +000092
93 // Set if the module has been renamed to remove the "prebuilt_" prefix.
94 PrebuiltRenamedToSource bool `blueprint:"mutated"`
Colin Cross74d73e22017-08-02 11:05:49 -070095}
96
Paul Duffin0c52c7b2021-07-06 17:15:25 +010097// Properties that can be used to select a Soong config variable.
98type ConfigVarProperties struct {
99 // Allow instances of this struct to be used as a property value in a BpPropertySet.
100 BpPrintableBase
101
102 // The name of the configuration namespace.
103 //
104 // As passed to add_soong_config_namespace in Make.
105 Config_namespace *string
106
107 // The name of the configuration variable.
108 //
109 // As passed to add_soong_config_var_value in Make.
110 Var_name *string
111}
112
Colin Cross74d73e22017-08-02 11:05:49 -0700113type Prebuilt struct {
114 properties PrebuiltProperties
Jaewoong Jung3e18b192019-06-11 12:25:34 -0700115
Martin Stjernholme65c3ae2021-11-23 01:24:06 +0000116 // nil if the prebuilt has no srcs property at all. See InitPrebuiltModuleWithoutSrcs.
117 srcsSupplier PrebuiltSrcsSupplier
118
119 // "-" if the prebuilt has no srcs property at all. See InitPrebuiltModuleWithoutSrcs.
Paul Duffindcb4bd62020-03-12 23:43:52 +0000120 srcsPropertyName string
Colin Crossce75d2c2016-10-06 16:12:58 -0700121}
122
Paul Duffind23c7262020-12-11 18:13:08 +0000123// RemoveOptionalPrebuiltPrefix returns the result of removing the "prebuilt_" prefix from the
124// supplied name if it has one, or returns the name unmodified if it does not.
125func RemoveOptionalPrebuiltPrefix(name string) string {
126 return strings.TrimPrefix(name, "prebuilt_")
127}
128
Trevor Radcliffe5d6fa4d2022-05-17 21:59:36 +0000129// RemoveOptionalPrebuiltPrefixFromBazelLabel removes the "prebuilt_" prefix from the *target name* of a Bazel label.
130// This differs from RemoveOptionalPrebuiltPrefix in that it does not remove it from the start of the string, but
131// instead removes it from the target name itself.
132func RemoveOptionalPrebuiltPrefixFromBazelLabel(label string) string {
133 splitLabel := strings.Split(label, ":")
134 bazelModuleNameNoPrebuilt := RemoveOptionalPrebuiltPrefix(splitLabel[1])
135 return strings.Join([]string{
136 splitLabel[0],
137 bazelModuleNameNoPrebuilt,
138 }, ":")
139}
140
Colin Crossce75d2c2016-10-06 16:12:58 -0700141func (p *Prebuilt) Name(name string) string {
Paul Duffin864116c2021-04-02 10:24:13 +0100142 return PrebuiltNameFromSource(name)
143}
144
145// PrebuiltNameFromSource returns the result of prepending the "prebuilt_" prefix to the supplied
146// name.
147func PrebuiltNameFromSource(name string) string {
Colin Crossce75d2c2016-10-06 16:12:58 -0700148 return "prebuilt_" + name
149}
150
Paul Duffin50061512020-01-21 16:31:05 +0000151func (p *Prebuilt) ForcePrefer() {
Cole Faust12ff57d2024-07-30 13:17:28 -0700152 p.properties.Prefer = NewSimpleConfigurable(true)
Paul Duffin38b57852020-05-13 16:08:09 +0100153}
154
Paul Duffin56dc66e2021-03-01 13:18:44 +0000155// SingleSourcePathFromSupplier invokes the supplied supplier for the current module in the
156// supplied context to retrieve a list of file paths, ensures that the returned list of file paths
157// contains a single value and then assumes that is a module relative file path and converts it to
158// a Path accordingly.
159//
160// Any issues, such as nil supplier or not exactly one file path will be reported as errors on the
161// supplied context and this will return nil.
162func SingleSourcePathFromSupplier(ctx ModuleContext, srcsSupplier PrebuiltSrcsSupplier, srcsPropertyName string) Path {
163 if srcsSupplier != nil {
164 srcs := srcsSupplier(ctx, ctx.Module())
Paul Duffindcb4bd62020-03-12 23:43:52 +0000165
166 if len(srcs) == 0 {
Paul Duffin56dc66e2021-03-01 13:18:44 +0000167 ctx.PropertyErrorf(srcsPropertyName, "missing prebuilt source file")
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700168 return nil
169 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700170
Paul Duffindcb4bd62020-03-12 23:43:52 +0000171 if len(srcs) > 1 {
Paul Duffin56dc66e2021-03-01 13:18:44 +0000172 ctx.PropertyErrorf(srcsPropertyName, "multiple prebuilt source files")
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700173 return nil
174 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700175
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700176 // Return the singleton source after expanding any filegroup in the
177 // sources.
Paul Duffindcb4bd62020-03-12 23:43:52 +0000178 src := srcs[0]
Jaewoong Jung3e18b192019-06-11 12:25:34 -0700179 return PathForModuleSrc(ctx, src)
Paul Duffindcb4bd62020-03-12 23:43:52 +0000180 } else {
181 ctx.ModuleErrorf("prebuilt source was not set")
182 return nil
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700183 }
Colin Cross74d73e22017-08-02 11:05:49 -0700184}
185
Paul Duffin56dc66e2021-03-01 13:18:44 +0000186// The below source-related functions and the srcs, src fields are based on an assumption that
187// prebuilt modules have a static source property at the moment. Currently there is only one
188// exception, android_app_import, which chooses a source file depending on the product's DPI
189// preference configs. We'll want to add native support for dynamic source cases if we end up having
190// more modules like this.
191func (p *Prebuilt) SingleSourcePath(ctx ModuleContext) Path {
192 return SingleSourcePathFromSupplier(ctx, p.srcsSupplier, p.srcsPropertyName)
193}
194
Jiyong Park4d277042019-04-23 18:00:10 +0900195func (p *Prebuilt) UsePrebuilt() bool {
196 return p.properties.UsePrebuilt
197}
198
Colin Crossd8d8b852024-12-20 16:32:37 -0800199func (p *Prebuilt) SetUsePrebuilt(use bool) {
200 p.properties.UsePrebuilt = use
201}
202
Paul Duffindcb4bd62020-03-12 23:43:52 +0000203// Called to provide the srcs value for the prebuilt module.
204//
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000205// This can be called with a context for any module not just the prebuilt one itself. It can also be
206// called concurrently.
207//
Paul Duffindcb4bd62020-03-12 23:43:52 +0000208// Return the src value or nil if it is not available.
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000209type PrebuiltSrcsSupplier func(ctx BaseModuleContext, prebuilt Module) []string
Paul Duffindcb4bd62020-03-12 23:43:52 +0000210
Martin Stjernholme65c3ae2021-11-23 01:24:06 +0000211func initPrebuiltModuleCommon(module PrebuiltInterface) *Prebuilt {
212 p := module.Prebuilt()
213 module.AddProperties(&p.properties)
Martin Stjernholme65c3ae2021-11-23 01:24:06 +0000214 return p
215}
216
217// Initialize the module as a prebuilt module that has no dedicated property that lists its
218// sources. SingleSourcePathFromSupplier should not be called for this module.
219//
220// This is the case e.g. for header modules, which provides the headers in source form
221// regardless whether they are prebuilt or not.
222func InitPrebuiltModuleWithoutSrcs(module PrebuiltInterface) {
223 p := initPrebuiltModuleCommon(module)
224 p.srcsPropertyName = "-"
225}
226
Paul Duffindcb4bd62020-03-12 23:43:52 +0000227// Initialize the module as a prebuilt module that uses the provided supplier to access the
228// prebuilt sources of the module.
229//
230// The supplier will be called multiple times and must return the same values each time it
231// is called. If it returns an empty array (or nil) then the prebuilt module will not be used
232// as a replacement for a source module with the same name even if prefer = true.
233//
234// If the Prebuilt.SingleSourcePath() is called on the module then this must return an array
235// containing exactly one source file.
236//
237// The provided property name is used to provide helpful error messages in the event that
238// a problem arises, e.g. calling SingleSourcePath() when more than one source is provided.
239func InitPrebuiltModuleWithSrcSupplier(module PrebuiltInterface, srcsSupplier PrebuiltSrcsSupplier, srcsPropertyName string) {
Paul Duffindcb4bd62020-03-12 23:43:52 +0000240 if srcsSupplier == nil {
241 panic(fmt.Errorf("srcsSupplier must not be nil"))
242 }
243 if srcsPropertyName == "" {
244 panic(fmt.Errorf("srcsPropertyName must not be empty"))
245 }
246
Martin Stjernholme65c3ae2021-11-23 01:24:06 +0000247 p := initPrebuiltModuleCommon(module)
Paul Duffindcb4bd62020-03-12 23:43:52 +0000248 p.srcsSupplier = srcsSupplier
249 p.srcsPropertyName = srcsPropertyName
250}
251
Cole Faust96a692b2024-08-08 14:47:51 -0700252// InitPrebuiltModule is the same as InitPrebuiltModuleWithSrcSupplier, but uses the
253// provided list of strings property as the source provider.
Paul Duffindcb4bd62020-03-12 23:43:52 +0000254func InitPrebuiltModule(module PrebuiltInterface, srcs *[]string) {
255 if srcs == nil {
256 panic(fmt.Errorf("srcs must not be nil"))
257 }
258
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000259 srcsSupplier := func(ctx BaseModuleContext, _ Module) []string {
Paul Duffindcb4bd62020-03-12 23:43:52 +0000260 return *srcs
261 }
262
263 InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "srcs")
Colin Crossce75d2c2016-10-06 16:12:58 -0700264}
265
Cole Faust96a692b2024-08-08 14:47:51 -0700266// InitConfigurablePrebuiltModule is the same as InitPrebuiltModule, but uses a
267// Configurable list of strings property instead of a regular list of strings.
268func InitConfigurablePrebuiltModule(module PrebuiltInterface, srcs *proptools.Configurable[[]string]) {
269 if srcs == nil {
270 panic(fmt.Errorf("srcs must not be nil"))
271 }
272
273 srcsSupplier := func(ctx BaseModuleContext, _ Module) []string {
274 return srcs.GetOrDefault(ctx, nil)
275 }
276
277 InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "srcs")
278}
279
Cole Faustc71b1752024-10-14 12:14:54 -0700280// InitConfigurablePrebuiltModuleString is the same as InitPrebuiltModule, but uses a
281// Configurable string property instead of a regular list of strings. It only produces a single
282// source file.
283func InitConfigurablePrebuiltModuleString(module PrebuiltInterface, srcs *proptools.Configurable[string], propertyName string) {
284 if srcs == nil {
285 panic(fmt.Errorf("%s must not be nil", propertyName))
286 }
287
288 srcsSupplier := func(ctx BaseModuleContext, _ Module) []string {
289 src := srcs.GetOrDefault(ctx, "")
290 if src == "" {
291 return nil
292 }
293 return []string{src}
294 }
295
296 InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, propertyName)
297}
298
Jaewoong Jung3e18b192019-06-11 12:25:34 -0700299func InitSingleSourcePrebuiltModule(module PrebuiltInterface, srcProps interface{}, srcField string) {
Paul Duffindcb4bd62020-03-12 23:43:52 +0000300 srcPropsValue := reflect.ValueOf(srcProps).Elem()
301 srcStructField, _ := srcPropsValue.Type().FieldByName(srcField)
302 if !srcPropsValue.IsValid() || srcStructField.Name == "" {
303 panic(fmt.Errorf("invalid single source prebuilt %+v", module))
304 }
305
306 if srcPropsValue.Kind() != reflect.Struct && srcPropsValue.Kind() != reflect.Interface {
307 panic(fmt.Errorf("invalid single source prebuilt %+v", srcProps))
308 }
309
310 srcFieldIndex := srcStructField.Index
311 srcPropertyName := proptools.PropertyNameForField(srcField)
312
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000313 srcsSupplier := func(ctx BaseModuleContext, _ Module) []string {
Cole Fausta963b942024-04-11 17:43:00 -0700314 if !module.Enabled(ctx) {
Jaewoong Jung84f1b802020-12-04 11:51:29 -0800315 return nil
316 }
Paul Duffindcb4bd62020-03-12 23:43:52 +0000317 value := srcPropsValue.FieldByIndex(srcFieldIndex)
318 if value.Kind() == reflect.Ptr {
Cole Faust97494b12024-01-12 14:02:47 -0800319 if value.IsNil() {
320 return nil
321 }
Paul Duffindcb4bd62020-03-12 23:43:52 +0000322 value = value.Elem()
323 }
324 if value.Kind() != reflect.String {
Martin Stjernholm25a69de2021-09-09 02:48:30 +0100325 panic(fmt.Errorf("prebuilt src field %q in %T in module %s should be a string or a pointer to one but was %v", srcField, srcProps, module, value))
Paul Duffindcb4bd62020-03-12 23:43:52 +0000326 }
327 src := value.String()
328 if src == "" {
329 return nil
330 }
331 return []string{src}
332 }
333
334 InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, srcPropertyName)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700335}
336
Colin Crossce75d2c2016-10-06 16:12:58 -0700337type PrebuiltInterface interface {
338 Module
339 Prebuilt() *Prebuilt
Colin Crossce75d2c2016-10-06 16:12:58 -0700340}
341
Paul Duffine1d38372021-04-02 10:35:24 +0100342// IsModulePreferred returns true if the given module is preferred.
343//
344// A source module is preferred if there is no corresponding prebuilt module or the prebuilt module
345// does not have "prefer: true".
346//
347// A prebuilt module is preferred if there is no corresponding source module or the prebuilt module
348// has "prefer: true".
349func IsModulePreferred(module Module) bool {
350 if module.IsReplacedByPrebuilt() {
351 // A source module that has been replaced by a prebuilt counterpart.
352 return false
353 }
Paul Duffinf7c99f52021-04-28 10:41:21 +0100354 if p := GetEmbeddedPrebuilt(module); p != nil {
355 return p.UsePrebuilt()
Paul Duffine1d38372021-04-02 10:35:24 +0100356 }
357 return true
358}
359
Yu Liu367827f2025-02-15 00:18:33 +0000360func IsModulePreferredProxy(ctx OtherModuleProviderContext, module ModuleProxy) bool {
361 if OtherModuleProviderOrDefault(ctx, module, CommonModuleInfoKey).ReplacedByPrebuilt {
362 // A source module that has been replaced by a prebuilt counterpart.
363 return false
364 }
365 if p, ok := OtherModuleProvider(ctx, module, PrebuiltModuleInfoProvider); ok {
366 return p.UsePrebuilt
367 }
368 return true
369}
370
Paul Duffinf7c99f52021-04-28 10:41:21 +0100371// IsModulePrebuilt returns true if the module implements PrebuiltInterface and
372// has been initialized as a prebuilt and so returns a non-nil value from the
373// PrebuiltInterface.Prebuilt() method.
374func IsModulePrebuilt(module Module) bool {
375 return GetEmbeddedPrebuilt(module) != nil
376}
377
378// GetEmbeddedPrebuilt returns a pointer to the embedded Prebuilt structure or
379// nil if the module does not implement PrebuiltInterface or has not been
380// initialized as a prebuilt module.
381func GetEmbeddedPrebuilt(module Module) *Prebuilt {
382 if p, ok := module.(PrebuiltInterface); ok {
383 return p.Prebuilt()
384 }
385
386 return nil
387}
388
Martin Stjernholmdbd814d2022-01-12 23:18:30 +0000389// PrebuiltGetPreferred returns the module that is preferred for the given
390// module. That is either the module itself or the prebuilt counterpart that has
391// taken its place. The given module must be a direct dependency of the current
392// context module, and it must be the source module if both source and prebuilt
393// exist.
394//
395// This function is for use on dependencies after PrebuiltPostDepsMutator has
396// run - any dependency that is registered before that will already reference
Colin Cross1e954b62024-09-13 13:50:00 -0700397// the right module. This function is only safe to call after all TransitionMutators
398// have run, e.g. in GenerateAndroidBuildActions.
Martin Stjernholmdbd814d2022-01-12 23:18:30 +0000399func PrebuiltGetPreferred(ctx BaseModuleContext, module Module) Module {
Yu Liub5275322024-11-13 18:40:43 +0000400 if !OtherModuleProviderOrDefault(ctx, module, CommonModuleInfoKey).ReplacedByPrebuilt {
Martin Stjernholmdbd814d2022-01-12 23:18:30 +0000401 return module
402 }
Yu Liu8a8d5b42025-01-07 00:48:08 +0000403 if _, ok := OtherModuleProvider(ctx, module, PrebuiltModuleInfoProvider); ok {
Martin Stjernholmdbd814d2022-01-12 23:18:30 +0000404 // If we're given a prebuilt then assume there's no source module around.
405 return module
406 }
407
408 sourceModDepFound := false
409 var prebuiltMod Module
410
Yu Liud2a95952024-10-10 00:15:26 +0000411 ctx.WalkDepsProxy(func(child, parent ModuleProxy) bool {
Martin Stjernholmdbd814d2022-01-12 23:18:30 +0000412 if prebuiltMod != nil {
413 return false
414 }
Yu Liue472c1d2025-02-26 20:13:04 +0000415 if EqualModules(parent, ctx.Module()) {
Martin Stjernholmdbd814d2022-01-12 23:18:30 +0000416 // First level: Only recurse if the module is found as a direct dependency.
417 sourceModDepFound = child == module
418 return sourceModDepFound
419 }
420 // Second level: Follow PrebuiltDepTag to the prebuilt.
421 if t := ctx.OtherModuleDependencyTag(child); t == PrebuiltDepTag {
422 prebuiltMod = child
423 }
424 return false
425 })
426
427 if prebuiltMod == nil {
428 if !sourceModDepFound {
429 panic(fmt.Errorf("Failed to find source module as a direct dependency: %s", module))
430 } else {
431 panic(fmt.Errorf("Failed to find prebuilt for source module: %s", module))
432 }
433 }
434 return prebuiltMod
435}
436
Colin Cross5ea9bcc2017-07-27 15:41:32 -0700437func RegisterPrebuiltsPreArchMutators(ctx RegisterMutatorsContext) {
Colin Cross8a962802024-10-09 15:29:27 -0700438 ctx.BottomUp("prebuilt_rename", PrebuiltRenameMutator).UsesRename()
Colin Crosscec81712017-07-13 14:43:27 -0700439}
440
Colin Crossd8d8b852024-12-20 16:32:37 -0800441func RegisterPrebuiltsPreDepsMutators(ctx RegisterMutatorsContext) {
Colin Cross8a962802024-10-09 15:29:27 -0700442 ctx.BottomUp("prebuilt_source", PrebuiltSourceDepsMutator).UsesReverseDependencies()
443 ctx.BottomUp("prebuilt_select", PrebuiltSelectModuleMutator)
Colin Crossd8d8b852024-12-20 16:32:37 -0800444}
445
446func RegisterPrebuiltsPostDepsMutators(ctx RegisterMutatorsContext) {
Colin Cross8a962802024-10-09 15:29:27 -0700447 ctx.BottomUp("prebuilt_postdeps", PrebuiltPostDepsMutator).UsesReplaceDependencies()
Colin Crosscec81712017-07-13 14:43:27 -0700448}
449
Spandan Das3576e762024-01-03 18:57:03 +0000450// Returns the name of the source module corresponding to a prebuilt module
451// For source modules, it returns its own name
452type baseModuleName interface {
453 BaseModuleName() string
454}
455
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000456// PrebuiltRenameMutator ensures that there always is a module with an
457// undecorated name.
458func PrebuiltRenameMutator(ctx BottomUpMutatorContext) {
Paul Duffinf7c99f52021-04-28 10:41:21 +0100459 m := ctx.Module()
460 if p := GetEmbeddedPrebuilt(m); p != nil {
Spandan Das3576e762024-01-03 18:57:03 +0000461 bmn, _ := m.(baseModuleName)
462 name := bmn.BaseModuleName()
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000463 if !ctx.OtherModuleExists(name) {
464 ctx.Rename(name)
Paul Duffinf7c99f52021-04-28 10:41:21 +0100465 p.properties.PrebuiltRenamedToSource = true
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000466 }
467 }
468}
469
470// PrebuiltSourceDepsMutator adds dependencies to the prebuilt module from the
471// corresponding source module, if one exists for the same variant.
Spandan Das1c4d94d2023-10-26 22:38:34 +0000472// Add a dependency from the prebuilt to `all_apex_contributions`
473// The metadata will be used for source vs prebuilts selection
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000474func PrebuiltSourceDepsMutator(ctx BottomUpMutatorContext) {
Paul Duffinf7c99f52021-04-28 10:41:21 +0100475 m := ctx.Module()
Spandan Das85bd4622024-08-01 00:51:20 +0000476 if p := GetEmbeddedPrebuilt(m); p != nil {
Spandan Das1c4d94d2023-10-26 22:38:34 +0000477 // Add a dependency from the prebuilt to the `all_apex_contributions`
478 // metadata module
479 // TODO: When all branches contain this singleton module, make this strict
480 // TODO: Add this dependency only for mainline prebuilts and not every prebuilt module
481 if ctx.OtherModuleExists("all_apex_contributions") {
Jihoon Kanga3a05462024-04-05 00:36:44 +0000482 ctx.AddDependency(m, AcDepTag, "all_apex_contributions")
Spandan Das1c4d94d2023-10-26 22:38:34 +0000483 }
Spandan Das85bd4622024-08-01 00:51:20 +0000484 if m.Enabled(ctx) && !p.properties.PrebuiltRenamedToSource {
485 // If this module is a prebuilt, is enabled and has not been renamed to source then add a
486 // dependency onto the source if it is present.
487 bmn, _ := m.(baseModuleName)
488 name := bmn.BaseModuleName()
489 if ctx.OtherModuleReverseDependencyVariantExists(name) {
Colin Crossd8d8b852024-12-20 16:32:37 -0800490 ctx.AddReverseVariationDependency(nil, PrebuiltDepTag, name)
Spandan Das85bd4622024-08-01 00:51:20 +0000491 p.properties.SourceExists = true
492 }
493 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700494 }
495}
496
Jooyung Hanebaa5732023-05-02 11:43:14 +0900497// checkInvariantsForSourceAndPrebuilt checks if invariants are kept when replacing
498// source with prebuilt. Note that the current module for the context is the source module.
499func checkInvariantsForSourceAndPrebuilt(ctx BaseModuleContext, s, p Module) {
500 if _, ok := s.(OverrideModule); ok {
501 // skip the check when the source module is `override_X` because it's only a placeholder
502 // for the actual source module. The check will be invoked for the actual module.
503 return
504 }
505 if sourcePartition, prebuiltPartition := s.PartitionTag(ctx.DeviceConfig()), p.PartitionTag(ctx.DeviceConfig()); sourcePartition != prebuiltPartition {
506 ctx.OtherModuleErrorf(p, "partition is different: %s(%s) != %s(%s)",
507 sourcePartition, ctx.ModuleName(), prebuiltPartition, ctx.OtherModuleName(p))
508 }
509}
510
Colin Crossc3e7fa62017-03-17 13:14:32 -0700511// PrebuiltSelectModuleMutator marks prebuilts that are used, either overriding source modules or
512// because the source module doesn't exist. It also disables installing overridden source modules.
Spandan Dase3fcb412023-10-26 20:48:02 +0000513//
514// If the visited module is the metadata module `all_apex_contributions`, it sets a
515// provider containing metadata about whether source or prebuilt of mainline modules should be used.
516// This logic was added here to prevent the overhead of creating a new mutator.
Spandan Das1c4d94d2023-10-26 22:38:34 +0000517func PrebuiltSelectModuleMutator(ctx BottomUpMutatorContext) {
Paul Duffinf7c99f52021-04-28 10:41:21 +0100518 m := ctx.Module()
519 if p := GetEmbeddedPrebuilt(m); p != nil {
Martin Stjernholme65c3ae2021-11-23 01:24:06 +0000520 if p.srcsSupplier == nil && p.srcsPropertyName == "" {
Colin Cross74d73e22017-08-02 11:05:49 -0700521 panic(fmt.Errorf("prebuilt module did not have InitPrebuiltModule called on it"))
522 }
523 if !p.properties.SourceExists {
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000524 p.properties.UsePrebuilt = p.usePrebuilt(ctx, nil, m)
Colin Crossc3e7fa62017-03-17 13:14:32 -0700525 }
Spandan Das1c4d94d2023-10-26 22:38:34 +0000526 // Propagate the provider received from `all_apex_contributions`
527 // to the source module
Jihoon Kanga3a05462024-04-05 00:36:44 +0000528 ctx.VisitDirectDepsWithTag(AcDepTag, func(am Module) {
Colin Cross313aa542023-12-13 13:47:44 -0800529 psi, _ := OtherModuleProvider(ctx, am, PrebuiltSelectionInfoProvider)
530 SetProvider(ctx, PrebuiltSelectionInfoProvider, psi)
Spandan Das1c4d94d2023-10-26 22:38:34 +0000531 })
532
Colin Crossc3e7fa62017-03-17 13:14:32 -0700533 } else if s, ok := ctx.Module().(Module); ok {
Spandan Das3576e762024-01-03 18:57:03 +0000534 // Use `all_apex_contributions` for source vs prebuilt selection.
535 psi := PrebuiltSelectionInfoMap{}
536 ctx.VisitDirectDepsWithTag(PrebuiltDepTag, func(am Module) {
537 // The value of psi gets overwritten with the provider from the last visited prebuilt.
538 // But all prebuilts have the same value of the provider, so this should be idempontent.
539 psi, _ = OtherModuleProvider(ctx, am, PrebuiltSelectionInfoProvider)
540 })
Paul Duffinf7c99f52021-04-28 10:41:21 +0100541 ctx.VisitDirectDepsWithTag(PrebuiltDepTag, func(prebuiltModule Module) {
542 p := GetEmbeddedPrebuilt(prebuiltModule)
543 if p.usePrebuilt(ctx, s, prebuiltModule) {
Jooyung Hanebaa5732023-05-02 11:43:14 +0900544 checkInvariantsForSourceAndPrebuilt(ctx, s, prebuiltModule)
545
Colin Crossee6143c2017-12-30 17:54:27 -0800546 p.properties.UsePrebuilt = true
Liz Kammer5ca3a622020-08-05 15:40:41 -0700547 s.ReplacedByPrebuilt()
Colin Crossa2f296f2016-11-29 15:16:18 -0800548 }
549 })
Spandan Das3576e762024-01-03 18:57:03 +0000550
551 // If any module in this mainline module family has been flagged using apex_contributions, disable every other module in that family
552 // Add source
553 allModules := []Module{s}
554 // Add each prebuilt
555 ctx.VisitDirectDepsWithTag(PrebuiltDepTag, func(prebuiltModule Module) {
556 allModules = append(allModules, prebuiltModule)
557 })
558 hideUnflaggedModules(ctx, psi, allModules)
559
Colin Crossa2f296f2016-11-29 15:16:18 -0800560 }
Spandan Das3576e762024-01-03 18:57:03 +0000561
Spandan Dase3fcb412023-10-26 20:48:02 +0000562 // If this is `all_apex_contributions`, set a provider containing
563 // metadata about source vs prebuilts selection
564 if am, ok := m.(*allApexContributions); ok {
565 am.SetPrebuiltSelectionInfoProvider(ctx)
566 }
Colin Crossa2f296f2016-11-29 15:16:18 -0800567}
568
Spandan Das3576e762024-01-03 18:57:03 +0000569// If any module in this mainline module family has been flagged using apex_contributions, disable every other module in that family
570func hideUnflaggedModules(ctx BottomUpMutatorContext, psi PrebuiltSelectionInfoMap, allModulesInFamily []Module) {
571 var selectedModuleInFamily Module
572 // query all_apex_contributions to see if any module in this family has been selected
573 for _, moduleInFamily := range allModulesInFamily {
574 // validate that are no duplicates
Spandan Das23956d12024-01-19 00:22:22 +0000575 if isSelected(psi, moduleInFamily) {
Spandan Das3576e762024-01-03 18:57:03 +0000576 if selectedModuleInFamily == nil {
577 // Store this so we can validate that there are no duplicates
578 selectedModuleInFamily = moduleInFamily
579 } else {
580 // There are duplicate modules from the same mainline module family
581 ctx.ModuleErrorf("Found duplicate variations of the same module in apex_contributions: %s and %s. Please remove one of these.\n", selectedModuleInFamily.Name(), moduleInFamily.Name())
582 }
583 }
584 }
585
586 // If a module has been selected, hide all other modules
587 if selectedModuleInFamily != nil {
588 for _, moduleInFamily := range allModulesInFamily {
589 if moduleInFamily.Name() != selectedModuleInFamily.Name() {
590 moduleInFamily.HideFromMake()
Spandan Das034af2c2024-10-30 21:45:09 +0000591 moduleInFamily.SkipInstall()
Spandan Dasf2c10572024-02-27 04:49:52 +0000592 // If this is a prebuilt module, unset properties.UsePrebuilt
593 // properties.UsePrebuilt might evaluate to true via soong config var fallback mechanism
594 // Set it to false explicitly so that the following mutator does not replace rdeps to this unselected prebuilt
595 if p := GetEmbeddedPrebuilt(moduleInFamily); p != nil {
596 p.properties.UsePrebuilt = false
597 }
598 }
599 }
600 }
601 // Do a validation pass to make sure that multiple prebuilts of a specific module are not selected.
602 // This might happen if the prebuilts share the same soong config var namespace.
603 // This should be an error, unless one of the prebuilts has been explicitly declared in apex_contributions
604 var selectedPrebuilt Module
605 for _, moduleInFamily := range allModulesInFamily {
606 // Skip if this module is in a different namespace
607 if !moduleInFamily.ExportedToMake() {
608 continue
609 }
610 // Skip for the top-level java_sdk_library_(_import). This has some special cases that need to be addressed first.
611 // This does not run into non-determinism because PrebuiltPostDepsMutator also has the special case
612 if sdkLibrary, ok := moduleInFamily.(interface{ SdkLibraryName() *string }); ok && sdkLibrary.SdkLibraryName() != nil {
613 continue
614 }
615 if p := GetEmbeddedPrebuilt(moduleInFamily); p != nil && p.properties.UsePrebuilt {
616 if selectedPrebuilt == nil {
617 selectedPrebuilt = moduleInFamily
618 } else {
619 ctx.ModuleErrorf("Multiple prebuilt modules %v and %v have been marked as preferred for this source module. "+
620 "Please add the appropriate prebuilt module to apex_contributions for this release config.", selectedPrebuilt.Name(), moduleInFamily.Name())
Spandan Das3576e762024-01-03 18:57:03 +0000621 }
622 }
623 }
624}
625
Colin Crossd6495802025-01-14 15:50:48 -0800626func IsDontReplaceSourceWithPrebuiltTag(tag blueprint.DependencyTag) bool {
627 if t, ok := tag.(ReplaceSourceWithPrebuilt); ok {
628 return !t.ReplaceSourceWithPrebuilt()
629 }
630 return false
631}
632
Jaewoong Jung6158dfe2021-03-23 14:08:29 -0700633// PrebuiltPostDepsMutator replaces dependencies on the source module with dependencies on the
634// prebuilt when both modules exist and the prebuilt should be used. When the prebuilt should not
635// be used, disable installing it.
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700636func PrebuiltPostDepsMutator(ctx BottomUpMutatorContext) {
Paul Duffinf7c99f52021-04-28 10:41:21 +0100637 m := ctx.Module()
638 if p := GetEmbeddedPrebuilt(m); p != nil {
Spandan Das3576e762024-01-03 18:57:03 +0000639 bmn, _ := m.(baseModuleName)
640 name := bmn.BaseModuleName()
Spandan Das81d95c52024-02-01 23:41:11 +0000641 psi := PrebuiltSelectionInfoMap{}
Jihoon Kanga3a05462024-04-05 00:36:44 +0000642 ctx.VisitDirectDepsWithTag(AcDepTag, func(am Module) {
Spandan Das81d95c52024-02-01 23:41:11 +0000643 psi, _ = OtherModuleProvider(ctx, am, PrebuiltSelectionInfoProvider)
644 })
645
Colin Cross74d73e22017-08-02 11:05:49 -0700646 if p.properties.UsePrebuilt {
647 if p.properties.SourceExists {
Paul Duffin80342d72020-06-26 22:08:43 +0100648 ctx.ReplaceDependenciesIf(name, func(from blueprint.Module, tag blueprint.DependencyTag, to blueprint.Module) bool {
Spandan Das81d95c52024-02-01 23:41:11 +0000649 if sdkLibrary, ok := m.(interface{ SdkLibraryName() *string }); ok && sdkLibrary.SdkLibraryName() != nil {
650 // Do not replace deps to the top-level prebuilt java_sdk_library hook.
651 // This hook has been special-cased in #isSelected to be _always_ active, even in next builds
652 // for dexpreopt and hiddenapi processing.
653 // If we do not special-case this here, rdeps referring to a java_sdk_library in next builds via libs
654 // will get prebuilt stubs
655 // TODO (b/308187268): Remove this after the apexes have been added to apex_contributions
Spandan Dasf2c10572024-02-27 04:49:52 +0000656 if psi.IsSelected(name) {
Spandan Das81d95c52024-02-01 23:41:11 +0000657 return false
658 }
659 }
660
Paul Duffin80342d72020-06-26 22:08:43 +0100661 if t, ok := tag.(ReplaceSourceWithPrebuilt); ok {
662 return t.ReplaceSourceWithPrebuilt()
663 }
Paul Duffin80342d72020-06-26 22:08:43 +0100664 return true
665 })
Colin Cross0f3c72f2016-11-23 15:44:07 -0800666 }
667 } else {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800668 m.HideFromMake()
Spandan Das034af2c2024-10-30 21:45:09 +0000669 m.SkipInstall()
Colin Crossce75d2c2016-10-06 16:12:58 -0700670 }
671 }
672}
673
Spandan Dasfc12d2f2023-10-27 20:06:32 +0000674// A wrapper around PrebuiltSelectionInfoMap.IsSelected with special handling for java_sdk_library
675// java_sdk_library is a macro that creates
676// 1. top-level impl library
677// 2. stub libraries (suffixed with .stubs...)
678//
679// java_sdk_library_import is a macro that creates
680// 1. top-level "impl" library
681// 2. stub libraries (suffixed with .stubs...)
682//
683// the impl of java_sdk_library_import is a "hook" for hiddenapi and dexpreopt processing. It does not have an impl jar, but acts as a shim
684// to provide the jar deapxed from the prebuilt apex
685//
686// isSelected uses `all_apex_contributions` to supersede source vs prebuilts selection of the stub libraries. It does not supersede the
687// selection of the top-level "impl" library so that this hook can work
688//
689// TODO (b/308174306) - Fix this when we need to support multiple prebuilts in main
690func isSelected(psi PrebuiltSelectionInfoMap, m Module) bool {
691 if sdkLibrary, ok := m.(interface{ SdkLibraryName() *string }); ok && sdkLibrary.SdkLibraryName() != nil {
692 sln := proptools.String(sdkLibrary.SdkLibraryName())
Spandan Das23956d12024-01-19 00:22:22 +0000693
Spandan Dasfc12d2f2023-10-27 20:06:32 +0000694 // This is the top-level library
695 // Do not supersede the existing prebuilts vs source selection mechanisms
Spandan Das81d95c52024-02-01 23:41:11 +0000696 // TODO (b/308187268): Remove this after the apexes have been added to apex_contributions
Spandan Das23956d12024-01-19 00:22:22 +0000697 if bmn, ok := m.(baseModuleName); ok && sln == bmn.BaseModuleName() {
Spandan Dasfc12d2f2023-10-27 20:06:32 +0000698 return false
699 }
700
701 // Stub library created by java_sdk_library_import
Spandan Das23956d12024-01-19 00:22:22 +0000702 // java_sdk_library creates several child modules (java_import + prebuilt_stubs_sources) dynamically.
703 // This code block ensures that these child modules are selected if the top-level java_sdk_library_import is listed
704 // in the selected apex_contributions.
705 if javaImport, ok := m.(createdByJavaSdkLibraryName); ok && javaImport.CreatedByJavaSdkLibraryName() != nil {
706 return psi.IsSelected(PrebuiltNameFromSource(proptools.String(javaImport.CreatedByJavaSdkLibraryName())))
Spandan Dasfc12d2f2023-10-27 20:06:32 +0000707 }
708
709 // Stub library created by java_sdk_library
Spandan Das3576e762024-01-03 18:57:03 +0000710 return psi.IsSelected(sln)
Spandan Dasfc12d2f2023-10-27 20:06:32 +0000711 }
Spandan Das3576e762024-01-03 18:57:03 +0000712 return psi.IsSelected(m.Name())
Spandan Dasfc12d2f2023-10-27 20:06:32 +0000713}
714
Spandan Das23956d12024-01-19 00:22:22 +0000715// implemented by child modules of java_sdk_library_import
716type createdByJavaSdkLibraryName interface {
717 CreatedByJavaSdkLibraryName() *string
718}
719
Spandan Das972917d2024-02-27 09:31:51 +0000720// Returns true if the prebuilt variant is disabled
721// e.g. for a cc_prebuilt_library_shared, this will return
722// - true for the static variant of the module
723// - false for the shared variant of the module
724//
725// Even though this is a cc_prebuilt_library_shared, we create both the variants today
726// https://source.corp.google.com/h/googleplex-android/platform/build/soong/+/e08e32b45a18a77bc3c3e751f730539b1b374f1b:cc/library.go;l=2113-2116;drc=2c4a9779cd1921d0397a12b3d3521f4c9b30d747;bpv=1;bpt=0
Colin Crossb2388e32024-10-07 15:05:23 -0700727func (p *Prebuilt) variantIsDisabled(ctx BaseModuleContext, prebuilt Module) bool {
Spandan Das972917d2024-02-27 09:31:51 +0000728 return p.srcsSupplier != nil && len(p.srcsSupplier(ctx, prebuilt)) == 0
729}
730
Spandan Das85bd4622024-08-01 00:51:20 +0000731type apexVariationName interface {
732 ApexVariationName() string
733}
734
Colin Crossa2f296f2016-11-29 15:16:18 -0800735// usePrebuilt returns true if a prebuilt should be used instead of the source module. The prebuilt
736// will be used if it is marked "prefer" or if the source module is disabled.
Colin Crossb2388e32024-10-07 15:05:23 -0700737func (p *Prebuilt) usePrebuilt(ctx BaseModuleContext, source Module, prebuilt Module) bool {
Spandan Das85bd4622024-08-01 00:51:20 +0000738 isMainlinePrebuilt := func(prebuilt Module) bool {
739 apex, ok := prebuilt.(apexVariationName)
740 if !ok {
741 return false
742 }
743 // Prebuilts of aosp apexes in prebuilts/runtime
744 // Used in minimal art branches
745 if prebuilt.base().BaseModuleName() == apex.ApexVariationName() {
746 return false
747 }
748 return InList(apex.ApexVariationName(), ctx.Config().AllMainlineApexNames())
749 }
750
Spandan Das1c4d94d2023-10-26 22:38:34 +0000751 // Use `all_apex_contributions` for source vs prebuilt selection.
752 psi := PrebuiltSelectionInfoMap{}
Spandan Das85bd4622024-08-01 00:51:20 +0000753 var psiDepTag blueprint.DependencyTag
754 if p := GetEmbeddedPrebuilt(ctx.Module()); p != nil {
755 // This is a prebuilt module, visit all_apex_contributions to get the info
756 psiDepTag = AcDepTag
757 } else {
758 // This is a source module, visit any of its prebuilts to get the info
759 psiDepTag = PrebuiltDepTag
760 }
761 ctx.VisitDirectDepsWithTag(psiDepTag, func(am Module) {
Colin Cross313aa542023-12-13 13:47:44 -0800762 psi, _ = OtherModuleProvider(ctx, am, PrebuiltSelectionInfoProvider)
Spandan Das1c4d94d2023-10-26 22:38:34 +0000763 })
Spandan Dasfc12d2f2023-10-27 20:06:32 +0000764
Spandan Das1c4d94d2023-10-26 22:38:34 +0000765 // If the source module is explicitly listed in the metadata module, use that
Spandan Dasfc12d2f2023-10-27 20:06:32 +0000766 if source != nil && isSelected(psi, source) {
Spandan Das1c4d94d2023-10-26 22:38:34 +0000767 return false
768 }
769 // If the prebuilt module is explicitly listed in the metadata module, use that
Spandan Das972917d2024-02-27 09:31:51 +0000770 if isSelected(psi, prebuilt) && !p.variantIsDisabled(ctx, prebuilt) {
Spandan Das1c4d94d2023-10-26 22:38:34 +0000771 return true
772 }
Spandan Dasfc12d2f2023-10-27 20:06:32 +0000773
Spandan Das85bd4622024-08-01 00:51:20 +0000774 // If this is a mainline prebuilt, but has not been flagged, hide it.
775 if isMainlinePrebuilt(prebuilt) {
776 return false
777 }
778
Spandan Das1c4d94d2023-10-26 22:38:34 +0000779 // If the baseModuleName could not be found in the metadata module,
780 // fall back to the existing source vs prebuilt selection.
781 // TODO: Drop the fallback mechanisms
782
Spandan Das972917d2024-02-27 09:31:51 +0000783 if p.variantIsDisabled(ctx, prebuilt) {
Colin Crossb63d7b32023-12-07 16:54:51 -0800784 return false
785 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700786
Colin Crossb63d7b32023-12-07 16:54:51 -0800787 // Skip prebuilt modules under unexported namespaces so that we won't
788 // end up shadowing non-prebuilt module when prebuilt module under same
789 // name happens to have a `Prefer` property set to true.
790 if ctx.Config().KatiEnabled() && !prebuilt.ExportedToMake() {
791 return false
LuK1337fb545bf2021-01-10 17:47:46 +0100792 }
793
Paul Duffin0c52c7b2021-07-06 17:15:25 +0100794 // If source is not available or is disabled then always use the prebuilt.
Cole Fausta963b942024-04-11 17:43:00 -0700795 if source == nil || !source.Enabled(ctx) {
Colin Crossb63d7b32023-12-07 16:54:51 -0800796 return true
Colin Crossa2f296f2016-11-29 15:16:18 -0800797 }
798
Paul Duffin0c52c7b2021-07-06 17:15:25 +0100799 // TODO: use p.Properties.Name and ctx.ModuleDir to override preference
Cole Faust12ff57d2024-07-30 13:17:28 -0700800 return p.properties.Prefer.GetOrDefault(ctx, false)
Colin Crossce75d2c2016-10-06 16:12:58 -0700801}
Jiyong Park0a573d72019-07-07 12:39:16 +0900802
803func (p *Prebuilt) SourceExists() bool {
804 return p.properties.SourceExists
805}