Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 1 | // 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 | |
Jaewoong Jung | f2200ad | 2020-11-16 16:01:27 -0800 | [diff] [blame] | 15 | // soong_env determines if the given soong environment file (usually ".soong.environment") is stale |
| 16 | // by comparing its contents to the current corresponding environment variable values. |
| 17 | // It fails if the file cannot be opened or corrupted, or its contents differ from the current |
| 18 | // values. |
| 19 | |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 20 | package main |
| 21 | |
| 22 | import ( |
| 23 | "flag" |
| 24 | "fmt" |
| 25 | "os" |
| 26 | |
| 27 | "android/soong/env" |
| 28 | ) |
| 29 | |
| 30 | func usage() { |
| 31 | fmt.Fprintf(os.Stderr, "usage: soong_env env_file\n") |
| 32 | fmt.Fprintf(os.Stderr, "exits with success if the environment varibles in env_file match\n") |
| 33 | fmt.Fprintf(os.Stderr, "the current environment\n") |
| 34 | flag.PrintDefaults() |
| 35 | os.Exit(2) |
| 36 | } |
| 37 | |
Jaewoong Jung | f2200ad | 2020-11-16 16:01:27 -0800 | [diff] [blame] | 38 | // This is a simple executable packaging, and the real work happens in env.StaleEnvFile. |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 39 | func main() { |
| 40 | flag.Parse() |
| 41 | |
| 42 | if flag.NArg() != 1 { |
| 43 | usage() |
| 44 | } |
| 45 | |
| 46 | stale, err := env.StaleEnvFile(flag.Arg(0)) |
| 47 | if err != nil { |
| 48 | fmt.Fprintf(os.Stderr, "error: %s\n", err.Error()) |
| 49 | os.Exit(1) |
| 50 | } |
| 51 | |
| 52 | if stale { |
| 53 | os.Exit(1) |
| 54 | } |
| 55 | |
| 56 | os.Exit(0) |
| 57 | } |