blob: 8694c28aa39ace0cbe81351c5ea7325845531023 [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 (
Dan Willemsen87b17d12015-07-14 00:39:06 -070018 "path/filepath"
19
Colin Cross463a90e2015-06-17 14:20:06 -070020 "android/soong"
Colin Cross68f55102015-03-25 14:43:57 -070021 "android/soong/env"
22
23 "github.com/google/blueprint"
24)
25
26// This file supports dependencies on environment variables. During build manifest generation,
27// any dependency on an environment variable is added to a list. During the singleton phase
28// a JSON file is written containing the current value of all used environment variables.
29// The next time the top-level build script is run, it uses the soong_env executable to
30// compare the contents of the environment variables, rewriting the file if necessary to cause
31// a manifest regeneration.
32
Colin Cross463a90e2015-06-17 14:20:06 -070033func init() {
34 soong.RegisterSingletonType("env", EnvSingleton)
35}
36
Colin Cross68f55102015-03-25 14:43:57 -070037func EnvSingleton() blueprint.Singleton {
38 return &envSingleton{}
39}
40
41type envSingleton struct{}
42
43func (c *envSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
44 envDeps := ctx.Config().(Config).EnvDeps()
45
Dan Willemsen87b17d12015-07-14 00:39:06 -070046 envFile := filepath.Join(ctx.Config().(Config).BuildDir(), ".soong.environment")
Colin Cross68f55102015-03-25 14:43:57 -070047
48 err := env.WriteEnvFile(envFile, envDeps)
49 if err != nil {
50 ctx.Errorf(err.Error())
51 }
52
53 ctx.AddNinjaFileDeps(envFile)
54}