| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1 | // 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 |  | 
|  | 15 | package android | 
|  | 16 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 17 | import ( | 
|  | 18 | "fmt" | 
| Jaewoong Jung | 3e18b19 | 2019-06-11 12:25:34 -0700 | [diff] [blame] | 19 | "reflect" | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 20 |  | 
|  | 21 | "github.com/google/blueprint" | 
| Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 23 | ) | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 24 |  | 
|  | 25 | // This file implements common functionality for handling modules that may exist as prebuilts, | 
|  | 26 | // source, or both. | 
|  | 27 |  | 
| Paul Duffin | 0c4979b | 2019-12-19 15:11:53 +0000 | [diff] [blame] | 28 | func RegisterPrebuiltMutators(ctx RegistrationContext) { | 
|  | 29 | ctx.PreArchMutators(RegisterPrebuiltsPreArchMutators) | 
|  | 30 | ctx.PostDepsMutators(RegisterPrebuiltsPostDepsMutators) | 
|  | 31 | } | 
|  | 32 |  | 
| Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 33 | // Marks a dependency tag as possibly preventing a reference to a source from being | 
|  | 34 | // replaced with the prebuilt. | 
|  | 35 | type ReplaceSourceWithPrebuilt interface { | 
|  | 36 | blueprint.DependencyTag | 
|  | 37 |  | 
|  | 38 | // Return true if the dependency defined by this tag should be replaced with the | 
|  | 39 | // prebuilt. | 
|  | 40 | ReplaceSourceWithPrebuilt() bool | 
|  | 41 | } | 
|  | 42 |  | 
| Nan Zhang | 2502e12 | 2017-03-09 18:43:01 -0800 | [diff] [blame] | 43 | type prebuiltDependencyTag struct { | 
|  | 44 | blueprint.BaseDependencyTag | 
|  | 45 | } | 
|  | 46 |  | 
| Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 47 | var PrebuiltDepTag prebuiltDependencyTag | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 48 |  | 
| Paul Duffin | 78ac5b9 | 2020-01-14 12:42:08 +0000 | [diff] [blame] | 49 | // Mark this tag so dependencies that use it are excluded from visibility enforcement. | 
|  | 50 | func (t prebuiltDependencyTag) ExcludeFromVisibilityEnforcement() {} | 
|  | 51 |  | 
| Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 52 | // Mark this tag so dependencies that use it are excluded from APEX contents. | 
|  | 53 | func (t prebuiltDependencyTag) ExcludeFromApexContents() {} | 
|  | 54 |  | 
|  | 55 | var _ ExcludeFromVisibilityEnforcementTag = PrebuiltDepTag | 
|  | 56 | var _ ExcludeFromApexContentsTag = PrebuiltDepTag | 
|  | 57 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 58 | type PrebuiltProperties struct { | 
|  | 59 | // When prefer is set to true the prebuilt will be used instead of any source module with | 
|  | 60 | // a matching name. | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 61 | Prefer *bool `android:"arch_variant"` | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 62 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 63 | SourceExists bool `blueprint:"mutated"` | 
|  | 64 | UsePrebuilt  bool `blueprint:"mutated"` | 
| Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 65 |  | 
|  | 66 | // Set if the module has been renamed to remove the "prebuilt_" prefix. | 
|  | 67 | PrebuiltRenamedToSource bool `blueprint:"mutated"` | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 68 | } | 
|  | 69 |  | 
|  | 70 | type Prebuilt struct { | 
|  | 71 | properties PrebuiltProperties | 
| Jaewoong Jung | 3e18b19 | 2019-06-11 12:25:34 -0700 | [diff] [blame] | 72 |  | 
| Paul Duffin | dcb4bd6 | 2020-03-12 23:43:52 +0000 | [diff] [blame] | 73 | srcsSupplier     PrebuiltSrcsSupplier | 
|  | 74 | srcsPropertyName string | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 75 | } | 
|  | 76 |  | 
|  | 77 | func (p *Prebuilt) Name(name string) string { | 
|  | 78 | return "prebuilt_" + name | 
|  | 79 | } | 
|  | 80 |  | 
| Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 81 | func (p *Prebuilt) ForcePrefer() { | 
|  | 82 | p.properties.Prefer = proptools.BoolPtr(true) | 
|  | 83 | } | 
|  | 84 |  | 
| Paul Duffin | 38b5785 | 2020-05-13 16:08:09 +0100 | [diff] [blame] | 85 | func (p *Prebuilt) Prefer() bool { | 
|  | 86 | return proptools.Bool(p.properties.Prefer) | 
|  | 87 | } | 
|  | 88 |  | 
| Jaewoong Jung | a5e5abc | 2019-04-26 14:31:50 -0700 | [diff] [blame] | 89 | // The below source-related functions and the srcs, src fields are based on an assumption that | 
|  | 90 | // prebuilt modules have a static source property at the moment. Currently there is only one | 
|  | 91 | // exception, android_app_import, which chooses a source file depending on the product's DPI | 
|  | 92 | // preference configs. We'll want to add native support for dynamic source cases if we end up having | 
|  | 93 | // more modules like this. | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 94 | func (p *Prebuilt) SingleSourcePath(ctx ModuleContext) Path { | 
| Paul Duffin | dcb4bd6 | 2020-03-12 23:43:52 +0000 | [diff] [blame] | 95 | if p.srcsSupplier != nil { | 
|  | 96 | srcs := p.srcsSupplier() | 
|  | 97 |  | 
|  | 98 | if len(srcs) == 0 { | 
|  | 99 | ctx.PropertyErrorf(p.srcsPropertyName, "missing prebuilt source file") | 
| Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 100 | return nil | 
|  | 101 | } | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 102 |  | 
| Paul Duffin | dcb4bd6 | 2020-03-12 23:43:52 +0000 | [diff] [blame] | 103 | if len(srcs) > 1 { | 
|  | 104 | ctx.PropertyErrorf(p.srcsPropertyName, "multiple prebuilt source files") | 
| Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 105 | return nil | 
|  | 106 | } | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 107 |  | 
| Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 108 | // Return the singleton source after expanding any filegroup in the | 
|  | 109 | // sources. | 
| Paul Duffin | dcb4bd6 | 2020-03-12 23:43:52 +0000 | [diff] [blame] | 110 | src := srcs[0] | 
| Jaewoong Jung | 3e18b19 | 2019-06-11 12:25:34 -0700 | [diff] [blame] | 111 | return PathForModuleSrc(ctx, src) | 
| Paul Duffin | dcb4bd6 | 2020-03-12 23:43:52 +0000 | [diff] [blame] | 112 | } else { | 
|  | 113 | ctx.ModuleErrorf("prebuilt source was not set") | 
|  | 114 | return nil | 
| Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 115 | } | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 116 | } | 
|  | 117 |  | 
| Jiyong Park | 4d27704 | 2019-04-23 18:00:10 +0900 | [diff] [blame] | 118 | func (p *Prebuilt) UsePrebuilt() bool { | 
|  | 119 | return p.properties.UsePrebuilt | 
|  | 120 | } | 
|  | 121 |  | 
| Paul Duffin | dcb4bd6 | 2020-03-12 23:43:52 +0000 | [diff] [blame] | 122 | // Called to provide the srcs value for the prebuilt module. | 
|  | 123 | // | 
|  | 124 | // Return the src value or nil if it is not available. | 
|  | 125 | type PrebuiltSrcsSupplier func() []string | 
|  | 126 |  | 
|  | 127 | // Initialize the module as a prebuilt module that uses the provided supplier to access the | 
|  | 128 | // prebuilt sources of the module. | 
|  | 129 | // | 
|  | 130 | // The supplier will be called multiple times and must return the same values each time it | 
|  | 131 | // is called. If it returns an empty array (or nil) then the prebuilt module will not be used | 
|  | 132 | // as a replacement for a source module with the same name even if prefer = true. | 
|  | 133 | // | 
|  | 134 | // If the Prebuilt.SingleSourcePath() is called on the module then this must return an array | 
|  | 135 | // containing exactly one source file. | 
|  | 136 | // | 
|  | 137 | // The provided property name is used to provide helpful error messages in the event that | 
|  | 138 | // a problem arises, e.g. calling SingleSourcePath() when more than one source is provided. | 
|  | 139 | func InitPrebuiltModuleWithSrcSupplier(module PrebuiltInterface, srcsSupplier PrebuiltSrcsSupplier, srcsPropertyName string) { | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 140 | p := module.Prebuilt() | 
|  | 141 | module.AddProperties(&p.properties) | 
| Paul Duffin | dcb4bd6 | 2020-03-12 23:43:52 +0000 | [diff] [blame] | 142 |  | 
|  | 143 | if srcsSupplier == nil { | 
|  | 144 | panic(fmt.Errorf("srcsSupplier must not be nil")) | 
|  | 145 | } | 
|  | 146 | if srcsPropertyName == "" { | 
|  | 147 | panic(fmt.Errorf("srcsPropertyName must not be empty")) | 
|  | 148 | } | 
|  | 149 |  | 
|  | 150 | p.srcsSupplier = srcsSupplier | 
|  | 151 | p.srcsPropertyName = srcsPropertyName | 
|  | 152 | } | 
|  | 153 |  | 
|  | 154 | func InitPrebuiltModule(module PrebuiltInterface, srcs *[]string) { | 
|  | 155 | if srcs == nil { | 
|  | 156 | panic(fmt.Errorf("srcs must not be nil")) | 
|  | 157 | } | 
|  | 158 |  | 
|  | 159 | srcsSupplier := func() []string { | 
|  | 160 | return *srcs | 
|  | 161 | } | 
|  | 162 |  | 
|  | 163 | InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "srcs") | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 164 | } | 
|  | 165 |  | 
| Jaewoong Jung | 3e18b19 | 2019-06-11 12:25:34 -0700 | [diff] [blame] | 166 | func InitSingleSourcePrebuiltModule(module PrebuiltInterface, srcProps interface{}, srcField string) { | 
| Paul Duffin | dcb4bd6 | 2020-03-12 23:43:52 +0000 | [diff] [blame] | 167 | srcPropsValue := reflect.ValueOf(srcProps).Elem() | 
|  | 168 | srcStructField, _ := srcPropsValue.Type().FieldByName(srcField) | 
|  | 169 | if !srcPropsValue.IsValid() || srcStructField.Name == "" { | 
|  | 170 | panic(fmt.Errorf("invalid single source prebuilt %+v", module)) | 
|  | 171 | } | 
|  | 172 |  | 
|  | 173 | if srcPropsValue.Kind() != reflect.Struct && srcPropsValue.Kind() != reflect.Interface { | 
|  | 174 | panic(fmt.Errorf("invalid single source prebuilt %+v", srcProps)) | 
|  | 175 | } | 
|  | 176 |  | 
|  | 177 | srcFieldIndex := srcStructField.Index | 
|  | 178 | srcPropertyName := proptools.PropertyNameForField(srcField) | 
|  | 179 |  | 
|  | 180 | srcsSupplier := func() []string { | 
|  | 181 | value := srcPropsValue.FieldByIndex(srcFieldIndex) | 
|  | 182 | if value.Kind() == reflect.Ptr { | 
|  | 183 | value = value.Elem() | 
|  | 184 | } | 
|  | 185 | if value.Kind() != reflect.String { | 
|  | 186 | panic(fmt.Errorf("prebuilt src field %q should be a string or a pointer to one but was %d %q", srcPropertyName, value.Kind(), value)) | 
|  | 187 | } | 
|  | 188 | src := value.String() | 
|  | 189 | if src == "" { | 
|  | 190 | return nil | 
|  | 191 | } | 
|  | 192 | return []string{src} | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, srcPropertyName) | 
| Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 196 | } | 
|  | 197 |  | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 198 | type PrebuiltInterface interface { | 
|  | 199 | Module | 
|  | 200 | Prebuilt() *Prebuilt | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 201 | } | 
|  | 202 |  | 
| Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 203 | func RegisterPrebuiltsPreArchMutators(ctx RegisterMutatorsContext) { | 
| Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 204 | ctx.BottomUp("prebuilt_rename", PrebuiltRenameMutator).Parallel() | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 205 | } | 
|  | 206 |  | 
| Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 207 | func RegisterPrebuiltsPostDepsMutators(ctx RegisterMutatorsContext) { | 
| Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 208 | ctx.BottomUp("prebuilt_source", PrebuiltSourceDepsMutator).Parallel() | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 209 | ctx.TopDown("prebuilt_select", PrebuiltSelectModuleMutator).Parallel() | 
| Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 210 | ctx.BottomUp("prebuilt_postdeps", PrebuiltPostDepsMutator).Parallel() | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 211 | } | 
|  | 212 |  | 
| Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 213 | // PrebuiltRenameMutator ensures that there always is a module with an | 
|  | 214 | // undecorated name. | 
|  | 215 | func PrebuiltRenameMutator(ctx BottomUpMutatorContext) { | 
|  | 216 | if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil { | 
|  | 217 | name := m.base().BaseModuleName() | 
|  | 218 | if !ctx.OtherModuleExists(name) { | 
|  | 219 | ctx.Rename(name) | 
|  | 220 | m.Prebuilt().properties.PrebuiltRenamedToSource = true | 
|  | 221 | } | 
|  | 222 | } | 
|  | 223 | } | 
|  | 224 |  | 
|  | 225 | // PrebuiltSourceDepsMutator adds dependencies to the prebuilt module from the | 
|  | 226 | // corresponding source module, if one exists for the same variant. | 
|  | 227 | func PrebuiltSourceDepsMutator(ctx BottomUpMutatorContext) { | 
| Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 228 | if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Enabled() && m.Prebuilt() != nil { | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 229 | p := m.Prebuilt() | 
| Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 230 | if !p.properties.PrebuiltRenamedToSource { | 
|  | 231 | name := m.base().BaseModuleName() | 
|  | 232 | if ctx.OtherModuleReverseDependencyVariantExists(name) { | 
|  | 233 | ctx.AddReverseDependency(ctx.Module(), PrebuiltDepTag, name) | 
|  | 234 | p.properties.SourceExists = true | 
|  | 235 | } | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 236 | } | 
|  | 237 | } | 
|  | 238 | } | 
|  | 239 |  | 
| Colin Cross | c3e7fa6 | 2017-03-17 13:14:32 -0700 | [diff] [blame] | 240 | // PrebuiltSelectModuleMutator marks prebuilts that are used, either overriding source modules or | 
|  | 241 | // because the source module doesn't exist.  It also disables installing overridden source modules. | 
| Colin Cross | a2f296f | 2016-11-29 15:16:18 -0800 | [diff] [blame] | 242 | func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) { | 
| Colin Cross | c3e7fa6 | 2017-03-17 13:14:32 -0700 | [diff] [blame] | 243 | if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil { | 
|  | 244 | p := m.Prebuilt() | 
| Paul Duffin | dcb4bd6 | 2020-03-12 23:43:52 +0000 | [diff] [blame] | 245 | if p.srcsSupplier == nil { | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 246 | panic(fmt.Errorf("prebuilt module did not have InitPrebuiltModule called on it")) | 
|  | 247 | } | 
|  | 248 | if !p.properties.SourceExists { | 
|  | 249 | p.properties.UsePrebuilt = p.usePrebuilt(ctx, nil) | 
| Colin Cross | c3e7fa6 | 2017-03-17 13:14:32 -0700 | [diff] [blame] | 250 | } | 
|  | 251 | } else if s, ok := ctx.Module().(Module); ok { | 
| Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 252 | ctx.VisitDirectDepsWithTag(PrebuiltDepTag, func(m Module) { | 
| Colin Cross | ee6143c | 2017-12-30 17:54:27 -0800 | [diff] [blame] | 253 | p := m.(PrebuiltInterface).Prebuilt() | 
|  | 254 | if p.usePrebuilt(ctx, s) { | 
|  | 255 | p.properties.UsePrebuilt = true | 
|  | 256 | s.SkipInstall() | 
| Colin Cross | a2f296f | 2016-11-29 15:16:18 -0800 | [diff] [blame] | 257 | } | 
|  | 258 | }) | 
|  | 259 | } | 
|  | 260 | } | 
|  | 261 |  | 
| Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 262 | // PrebuiltPostDepsMutator does two operations.  It replace dependencies on the | 
|  | 263 | // source module with dependencies on the prebuilt when both modules exist and | 
|  | 264 | // the prebuilt should be used.  When the prebuilt should not be used, disable | 
|  | 265 | // installing it.  Secondly, it also adds a sourcegroup to any filegroups found | 
|  | 266 | // in the prebuilt's 'Srcs' property. | 
|  | 267 | func PrebuiltPostDepsMutator(ctx BottomUpMutatorContext) { | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 268 | if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil { | 
|  | 269 | p := m.Prebuilt() | 
|  | 270 | name := m.base().BaseModuleName() | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 271 | if p.properties.UsePrebuilt { | 
|  | 272 | if p.properties.SourceExists { | 
| Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 273 | ctx.ReplaceDependenciesIf(name, func(from blueprint.Module, tag blueprint.DependencyTag, to blueprint.Module) bool { | 
|  | 274 | if t, ok := tag.(ReplaceSourceWithPrebuilt); ok { | 
|  | 275 | return t.ReplaceSourceWithPrebuilt() | 
|  | 276 | } | 
|  | 277 |  | 
|  | 278 | return true | 
|  | 279 | }) | 
| Colin Cross | 0f3c72f | 2016-11-23 15:44:07 -0800 | [diff] [blame] | 280 | } | 
|  | 281 | } else { | 
|  | 282 | m.SkipInstall() | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 283 | } | 
|  | 284 | } | 
|  | 285 | } | 
|  | 286 |  | 
| Colin Cross | a2f296f | 2016-11-29 15:16:18 -0800 | [diff] [blame] | 287 | // usePrebuilt returns true if a prebuilt should be used instead of the source module.  The prebuilt | 
|  | 288 | // will be used if it is marked "prefer" or if the source module is disabled. | 
|  | 289 | func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module) bool { | 
| Paul Duffin | dcb4bd6 | 2020-03-12 23:43:52 +0000 | [diff] [blame] | 290 | if p.srcsSupplier != nil && len(p.srcsSupplier()) == 0 { | 
| Colin Cross | a2f296f | 2016-11-29 15:16:18 -0800 | [diff] [blame] | 291 | return false | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 292 | } | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 293 |  | 
| Colin Cross | a2f296f | 2016-11-29 15:16:18 -0800 | [diff] [blame] | 294 | // TODO: use p.Properties.Name and ctx.ModuleDir to override preference | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 295 | if Bool(p.properties.Prefer) { | 
| Colin Cross | a2f296f | 2016-11-29 15:16:18 -0800 | [diff] [blame] | 296 | return true | 
|  | 297 | } | 
|  | 298 |  | 
| Colin Cross | c3e7fa6 | 2017-03-17 13:14:32 -0700 | [diff] [blame] | 299 | return source == nil || !source.Enabled() | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 300 | } | 
| Jiyong Park | 0a573d7 | 2019-07-07 12:39:16 +0900 | [diff] [blame] | 301 |  | 
|  | 302 | func (p *Prebuilt) SourceExists() bool { | 
|  | 303 | return p.properties.SourceExists | 
|  | 304 | } |