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