env.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2015 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/shared"
  17. )
  18. // This file supports dependencies on environment variables. During build manifest generation,
  19. // any dependency on an environment variable is added to a list. During the singleton phase
  20. // a JSON file is written containing the current value of all used environment variables.
  21. // The next time the top-level build script is run, it uses the soong_env executable to
  22. // compare the contents of the environment variables, rewriting the file if necessary to cause
  23. // a manifest regeneration.
  24. var originalEnv map[string]string
  25. func InitEnvironment(envFile string) {
  26. var err error
  27. originalEnv, err = shared.EnvFromFile(envFile)
  28. if err != nil {
  29. panic(err)
  30. }
  31. }
  32. func EnvSingleton() Singleton {
  33. return &envSingleton{}
  34. }
  35. type envSingleton struct{}
  36. func (c *envSingleton) GenerateBuildActions(ctx SingletonContext) {
  37. envDeps := ctx.Config().EnvDeps()
  38. envFile := PathForOutput(ctx, "soong.environment.used")
  39. if ctx.Failed() {
  40. return
  41. }
  42. data, err := shared.EnvFileContents(envDeps)
  43. if err != nil {
  44. ctx.Errorf(err.Error())
  45. }
  46. err = WriteFileToOutputDir(envFile, data, 0666)
  47. if err != nil {
  48. ctx.Errorf(err.Error())
  49. }
  50. ctx.AddNinjaFileDeps(envFile.String())
  51. }