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