phony.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. package android
  15. import (
  16. "sync"
  17. "github.com/google/blueprint"
  18. )
  19. var phonyMapOnceKey = NewOnceKey("phony")
  20. type phonyMap map[string]Paths
  21. var phonyMapLock sync.Mutex
  22. func getPhonyMap(config Config) phonyMap {
  23. return config.Once(phonyMapOnceKey, func() interface{} {
  24. return make(phonyMap)
  25. }).(phonyMap)
  26. }
  27. func addPhony(config Config, name string, deps ...Path) {
  28. phonyMap := getPhonyMap(config)
  29. phonyMapLock.Lock()
  30. defer phonyMapLock.Unlock()
  31. phonyMap[name] = append(phonyMap[name], deps...)
  32. }
  33. type phonySingleton struct {
  34. phonyMap phonyMap
  35. phonyList []string
  36. }
  37. var _ SingletonMakeVarsProvider = (*phonySingleton)(nil)
  38. func (p *phonySingleton) GenerateBuildActions(ctx SingletonContext) {
  39. p.phonyMap = getPhonyMap(ctx.Config())
  40. p.phonyList = SortedKeys(p.phonyMap)
  41. for _, phony := range p.phonyList {
  42. p.phonyMap[phony] = SortedUniquePaths(p.phonyMap[phony])
  43. }
  44. if !ctx.Config().KatiEnabled() {
  45. for _, phony := range p.phonyList {
  46. ctx.Build(pctx, BuildParams{
  47. Rule: blueprint.Phony,
  48. Outputs: []WritablePath{PathForPhony(ctx, phony)},
  49. Implicits: p.phonyMap[phony],
  50. })
  51. }
  52. }
  53. }
  54. func (p phonySingleton) MakeVars(ctx MakeVarsContext) {
  55. for _, phony := range p.phonyList {
  56. ctx.Phony(phony, p.phonyMap[phony]...)
  57. }
  58. }
  59. func phonySingletonFactory() Singleton {
  60. return &phonySingleton{}
  61. }