blob: 478fffce270839da1b6d870d52a807e5aa75b869 [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 (
Colin Cross463a90e2015-06-17 14:20:06 -070018 "android/soong"
Colin Cross68f55102015-03-25 14:43:57 -070019 "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
Colin Cross463a90e2015-06-17 14:20:06 -070031func init() {
32 soong.RegisterSingletonType("env", EnvSingleton)
33}
34
Colin Cross68f55102015-03-25 14:43:57 -070035func 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
Dan Willemsen34cc69e2015-09-23 15:26:20 -070044 envFile := PathForOutput(ctx, ".soong.environment")
45 if ctx.Failed() {
46 return
47 }
Colin Cross68f55102015-03-25 14:43:57 -070048
Dan Willemsen34cc69e2015-09-23 15:26:20 -070049 err := env.WriteEnvFile(envFile.String(), envDeps)
Colin Cross68f55102015-03-25 14:43:57 -070050 if err != nil {
51 ctx.Errorf(err.Error())
52 }
53
Dan Willemsen34cc69e2015-09-23 15:26:20 -070054 ctx.AddNinjaFileDeps(envFile.String())
Colin Cross68f55102015-03-25 14:43:57 -070055}