blob: 227d7b0180845c38287af916d798bdf927717f00 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// 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
15// soong_glob is the command line tool that checks if the list of files matching a glob has
16// changed, and only updates the output file list if it has changed. It is used to optimize
17// out build.ninja regenerations when non-matching files are added. See
18// android/soong/common/glob.go for a longer description.
19package main
20
21import (
22 "flag"
23 "fmt"
24 "os"
25
26 "android/soong/glob"
27)
28
29var (
30 out = flag.String("o", "", "file to write list of files that match glob")
31)
32
33func usage() {
34 fmt.Fprintf(os.Stderr, "usage: soong_glob -o out glob\n")
35 flag.PrintDefaults()
36 os.Exit(2)
37}
38
39func main() {
40 flag.Parse()
41
42 if *out == "" {
43 fmt.Fprintln(os.Stderr, "error: -o is required\n")
44 usage()
45 }
46
47 if flag.NArg() != 1 {
48 usage()
49 }
50
51 _, err := glob.GlobWithDepFile(flag.Arg(0), *out, *out+".d")
52 if err != nil {
53 fmt.Fprintf(os.Stderr, "error: %s\n", err.Error())
54 os.Exit(1)
55 }
56}