blob: 83b8154cc85cff483022c6a49330ff51317bfdff [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")
Colin Cross3e8ec072015-03-31 16:40:23 -070031
32 excludes multiArg
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross3e8ec072015-03-31 16:40:23 -070035func init() {
36 flag.Var(&excludes, "e", "pattern to exclude from results")
37}
38
39type multiArg []string
40
41func (m *multiArg) String() string {
42 return `""`
43}
44
45func (m *multiArg) Set(s string) error {
46 *m = append(*m, s)
47 return nil
48}
49
50func (m *multiArg) Get() interface{} {
51 return m
52}
53
Colin Cross3f40fa42015-01-30 17:27:36 -080054func usage() {
55 fmt.Fprintf(os.Stderr, "usage: soong_glob -o out glob\n")
56 flag.PrintDefaults()
57 os.Exit(2)
58}
59
60func main() {
61 flag.Parse()
62
63 if *out == "" {
Colin Cross079602c2016-05-27 12:45:11 -070064 fmt.Fprintf(os.Stderr, "error: -o is required\n")
Colin Cross3f40fa42015-01-30 17:27:36 -080065 usage()
66 }
67
68 if flag.NArg() != 1 {
69 usage()
70 }
71
Colin Cross3e8ec072015-03-31 16:40:23 -070072 _, err := glob.GlobWithDepFile(flag.Arg(0), *out, *out+".d", excludes)
Colin Cross3f40fa42015-01-30 17:27:36 -080073 if err != nil {
74 fmt.Fprintf(os.Stderr, "error: %s\n", err.Error())
75 os.Exit(1)
76 }
77}