blob: c7409e872e2ead5829fda7d9528db0c4c0ba2ac2 [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
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross68f55102015-03-25 14:43:57 -070016
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
Colin Cross68f55102015-03-25 14:43:57 -070030func 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
Dan Willemsen34cc69e2015-09-23 15:26:20 -070039 envFile := PathForOutput(ctx, ".soong.environment")
40 if ctx.Failed() {
41 return
42 }
Colin Cross68f55102015-03-25 14:43:57 -070043
Dan Willemsen34cc69e2015-09-23 15:26:20 -070044 err := env.WriteEnvFile(envFile.String(), envDeps)
Colin Cross68f55102015-03-25 14:43:57 -070045 if err != nil {
46 ctx.Errorf(err.Error())
47 }
48
Dan Willemsen34cc69e2015-09-23 15:26:20 -070049 ctx.AddNinjaFileDeps(envFile.String())
Colin Cross68f55102015-03-25 14:43:57 -070050}