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// bpglob 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// github.com/google/blueprint/bootstrap/glob.go for a longer description. 19package main 20 21import ( 22 "flag" 23 "fmt" 24 "os" 25 26 "github.com/google/blueprint/pathtools" 27) 28 29var ( 30 out = flag.String("o", "", "file to write list of files that match glob") 31 32 excludes multiArg 33) 34 35func 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 54func usage() { 55 fmt.Fprintln(os.Stderr, "usage: bpglob -o out glob") 56 flag.PrintDefaults() 57 os.Exit(2) 58} 59 60func main() { 61 flag.Parse() 62 63 if *out == "" { 64 fmt.Fprintln(os.Stderr, "error: -o is required") 65 usage() 66 } 67 68 if flag.NArg() != 1 { 69 usage() 70 } 71 72 _, err := pathtools.GlobWithDepFile(flag.Arg(0), *out, *out+".d", excludes) 73 if err != nil { 74 fmt.Fprintf(os.Stderr, "error: %s\n", err.Error()) 75 os.Exit(1) 76 } 77} 78