blob: 3b523a2f45b49b4cb092b7cd7e807c28532313c5 [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 Cross463a90e2015-06-17 14:20:06 -070030func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070031 RegisterSingletonType("env", EnvSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -070032}
33
Colin Cross68f55102015-03-25 14:43:57 -070034func EnvSingleton() blueprint.Singleton {
35 return &envSingleton{}
36}
37
38type envSingleton struct{}
39
40func (c *envSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
41 envDeps := ctx.Config().(Config).EnvDeps()
42
Dan Willemsen34cc69e2015-09-23 15:26:20 -070043 envFile := PathForOutput(ctx, ".soong.environment")
44 if ctx.Failed() {
45 return
46 }
Colin Cross68f55102015-03-25 14:43:57 -070047
Dan Willemsen34cc69e2015-09-23 15:26:20 -070048 err := env.WriteEnvFile(envFile.String(), envDeps)
Colin Cross68f55102015-03-25 14:43:57 -070049 if err != nil {
50 ctx.Errorf(err.Error())
51 }
52
Dan Willemsen34cc69e2015-09-23 15:26:20 -070053 ctx.AddNinjaFileDeps(envFile.String())
Colin Cross68f55102015-03-25 14:43:57 -070054}