blob: 8020b17a0403a557b2a38cb75938c552f232e752 [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
Jaewoong Jungf2200ad2020-11-16 16:01:27 -080015// 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 Cross68f55102015-03-25 14:43:57 -070020package main
21
22import (
23 "flag"
24 "fmt"
25 "os"
26
27 "android/soong/env"
28)
29
30func 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 Jungf2200ad2020-11-16 16:01:27 -080038// This is a simple executable packaging, and the real work happens in env.StaleEnvFile.
Colin Cross68f55102015-03-25 14:43:57 -070039func 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}