ninja_deps.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. "android/soong/starlark_import"
  17. "sort"
  18. )
  19. func (c *config) addNinjaFileDeps(deps ...string) {
  20. for _, dep := range deps {
  21. c.ninjaFileDepsSet.Store(dep, true)
  22. }
  23. }
  24. func (c *config) ninjaFileDeps() []string {
  25. var deps []string
  26. c.ninjaFileDepsSet.Range(func(key, value interface{}) bool {
  27. deps = append(deps, key.(string))
  28. return true
  29. })
  30. sort.Strings(deps)
  31. return deps
  32. }
  33. func ninjaDepsSingletonFactory() Singleton {
  34. return &ninjaDepsSingleton{}
  35. }
  36. type ninjaDepsSingleton struct{}
  37. func (ninjaDepsSingleton) GenerateBuildActions(ctx SingletonContext) {
  38. ctx.AddNinjaFileDeps(ctx.Config().ninjaFileDeps()...)
  39. deps, err := starlark_import.GetNinjaDeps()
  40. if err != nil {
  41. ctx.Errorf("Error running starlark code: %s", err)
  42. } else {
  43. ctx.AddNinjaFileDeps(deps...)
  44. }
  45. }