blob: e33a0258b59c48a761196e273d9c8cdea4d4e461 [file] [log] [blame]
Colin Cross68f55102015-03-25 14:43:57 -07001// 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/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
30func EnvSingleton() blueprint.Singleton {
31 return &envSingleton{}
32}
33
34type envSingleton struct{}
35
36func (c *envSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
37 envDeps := ctx.Config().(Config).EnvDeps()
38
39 envFile := ".soong.environment"
40
41 err := env.WriteEnvFile(envFile, envDeps)
42 if err != nil {
43 ctx.Errorf(err.Error())
44 }
45
46 ctx.AddNinjaFileDeps(envFile)
47}