Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [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 | |
| 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. |
| 19 | package main |
| 20 | |
| 21 | import ( |
| 22 | "flag" |
| 23 | "fmt" |
| 24 | "os" |
| 25 | |
| 26 | "android/soong/glob" |
| 27 | ) |
| 28 | |
| 29 | var ( |
| 30 | out = flag.String("o", "", "file to write list of files that match glob") |
Colin Cross | 3e8ec07 | 2015-03-31 16:40:23 -0700 | [diff] [blame] | 31 | |
| 32 | excludes multiArg |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 33 | ) |
| 34 | |
Colin Cross | 3e8ec07 | 2015-03-31 16:40:23 -0700 | [diff] [blame] | 35 | func init() { |
| 36 | flag.Var(&excludes, "e", "pattern to exclude from results") |
| 37 | } |
| 38 | |
| 39 | type multiArg []string |
| 40 | |
| 41 | func (m *multiArg) String() string { |
| 42 | return `""` |
| 43 | } |
| 44 | |
| 45 | func (m *multiArg) Set(s string) error { |
| 46 | *m = append(*m, s) |
| 47 | return nil |
| 48 | } |
| 49 | |
| 50 | func (m *multiArg) Get() interface{} { |
| 51 | return m |
| 52 | } |
| 53 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 54 | func usage() { |
| 55 | fmt.Fprintf(os.Stderr, "usage: soong_glob -o out glob\n") |
| 56 | flag.PrintDefaults() |
| 57 | os.Exit(2) |
| 58 | } |
| 59 | |
| 60 | func main() { |
| 61 | flag.Parse() |
| 62 | |
| 63 | if *out == "" { |
Colin Cross | 079602c | 2016-05-27 12:45:11 -0700 | [diff] [blame] | 64 | fmt.Fprintf(os.Stderr, "error: -o is required\n") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 65 | usage() |
| 66 | } |
| 67 | |
| 68 | if flag.NArg() != 1 { |
| 69 | usage() |
| 70 | } |
| 71 | |
Colin Cross | 3e8ec07 | 2015-03-31 16:40:23 -0700 | [diff] [blame] | 72 | _, err := glob.GlobWithDepFile(flag.Arg(0), *out, *out+".d", excludes) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 73 | if err != nil { |
| 74 | fmt.Fprintf(os.Stderr, "error: %s\n", err.Error()) |
| 75 | os.Exit(1) |
| 76 | } |
| 77 | } |