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 // make-c is simple program to measure time to parse Makefiles in android. 16 package main 17 18 import ( 19 "bufio" 20 "bytes" 21 "fmt" 22 "os/exec" 23 "time" 24 ) 25 26 func main() { 27 parseDone := make(chan bool) 28 cmd := exec.Command("make", "-n") 29 r, err := cmd.StdoutPipe() 30 if err != nil { 31 panic(err) 32 } 33 t := time.Now() 34 go func() { 35 s := bufio.NewScanner(r) 36 for s.Scan() { 37 if bytes.HasPrefix(s.Bytes(), []byte("echo ")) { 38 parseDone <- true 39 return 40 } 41 fmt.Println(s.Text()) 42 } 43 if err := s.Err(); err != nil { 44 panic(err) 45 } 46 panic("unexpected end of make?") 47 }() 48 err = cmd.Start() 49 if err != nil { 50 panic(err) 51 } 52 select { 53 case <-parseDone: 54 fmt.Printf("make -c: %v\n", time.Since(t)) 55 } 56 cmd.Process.Kill() 57 cmd.Wait() 58 } 59