Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 1 | // Copyright 2020 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 | |
| 17 | import ( |
| 18 | "sync" |
| 19 | |
| 20 | "github.com/google/blueprint" |
| 21 | ) |
| 22 | |
| 23 | var phonyMapOnceKey = NewOnceKey("phony") |
| 24 | |
| 25 | type phonyMap map[string]Paths |
| 26 | |
| 27 | var phonyMapLock sync.Mutex |
| 28 | |
| 29 | func getPhonyMap(config Config) phonyMap { |
| 30 | return config.Once(phonyMapOnceKey, func() interface{} { |
| 31 | return make(phonyMap) |
| 32 | }).(phonyMap) |
| 33 | } |
| 34 | |
| 35 | func addPhony(config Config, name string, deps ...Path) { |
| 36 | phonyMap := getPhonyMap(config) |
| 37 | phonyMapLock.Lock() |
| 38 | defer phonyMapLock.Unlock() |
| 39 | phonyMap[name] = append(phonyMap[name], deps...) |
| 40 | } |
| 41 | |
| 42 | type phonySingleton struct { |
| 43 | phonyMap phonyMap |
| 44 | phonyList []string |
| 45 | } |
| 46 | |
| 47 | var _ SingletonMakeVarsProvider = (*phonySingleton)(nil) |
| 48 | |
| 49 | func (p *phonySingleton) GenerateBuildActions(ctx SingletonContext) { |
| 50 | p.phonyMap = getPhonyMap(ctx.Config()) |
| 51 | p.phonyList = SortedStringKeys(p.phonyMap) |
| 52 | for _, phony := range p.phonyList { |
| 53 | p.phonyMap[phony] = SortedUniquePaths(p.phonyMap[phony]) |
| 54 | } |
| 55 | |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 56 | if !ctx.Config().KatiEnabled() { |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 57 | for _, phony := range p.phonyList { |
| 58 | ctx.Build(pctx, BuildParams{ |
| 59 | Rule: blueprint.Phony, |
| 60 | Outputs: []WritablePath{PathForPhony(ctx, phony)}, |
| 61 | Implicits: p.phonyMap[phony], |
| 62 | }) |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | func (p phonySingleton) MakeVars(ctx MakeVarsContext) { |
| 68 | for _, phony := range p.phonyList { |
| 69 | ctx.Phony(phony, p.phonyMap[phony]...) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | func phonySingletonFactory() Singleton { |
| 74 | return &phonySingleton{} |
| 75 | } |