Support dependencies on environment variables

Ninja can't depend on environment variables, so modifying build
behavior based on environment variables requires coordinating
between the soong script that invokes ninja and the soong_build
manifest generator.

Allow any module to call Config.Getenv to get the contents of an
environment variable while registering a dependency on it.
After all modules have been processed write out the state of
all used environment variables to a JSON file called
.soong.environment.  During the next build the soong script
will use the soong_env tool to compare the contents of
.soong.environment to the current environment, and force a
build manifest regeneration by deleting the .soong.environment
file if any variables have changed.

Change-Id: Id0d81933a857bc2fc1cd7a393a3c6cec73dc4824
diff --git a/config/config.go b/config/config.go
index 6cdc211..6cb61e4 100644
--- a/config/config.go
+++ b/config/config.go
@@ -41,7 +41,8 @@
 type Config struct {
 	FileConfigurableOptions
 
-	srcDir string // the path of the root source directory
+	srcDir  string // the path of the root source directory
+	envDeps map[string]string
 }
 
 // loads configuration options from a JSON file in the cwd.
@@ -103,7 +104,10 @@
 // the root source directory. It also loads the config file, if found.
 func New(srcDir string) (*Config, error) {
 	// Make a config with default options
-	config := &Config{srcDir: srcDir}
+	config := &Config{
+		srcDir:  srcDir,
+		envDeps: make(map[string]string),
+	}
 
 	// Load any configurable options from the configuration file
 	err := loadFromConfigFile(config)
@@ -150,3 +154,17 @@
 		return ""
 	}
 }
+
+func (c *Config) Getenv(key string) string {
+	var val string
+	var exists bool
+	if val, exists = c.envDeps[key]; !exists {
+		val = os.Getenv(key)
+		c.envDeps[key] = val
+	}
+	return val
+}
+
+func (c *Config) EnvDeps() map[string]string {
+	return c.envDeps
+}