1// Copyright 2017 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 15package main 16 17import ( 18 "bytes" 19 "flag" 20 "fmt" 21 "io/ioutil" 22 "os" 23 24 "android/soong/androidmk/androidmk" 25 26 _ "android/soong/partner/bpfix/extensions" 27) 28 29var usage = func() { 30 fmt.Fprintf(os.Stderr, "usage: %s [flags] <inputFile>\n"+ 31 "\n%s parses <inputFile> as an Android.mk file and attempts to output an analogous Android.bp file (to standard out)\n", os.Args[0], os.Args[0]) 32 flag.PrintDefaults() 33 os.Exit(1) 34} 35 36func main() { 37 flag.Usage = usage 38 flag.Parse() 39 if len(flag.Args()) != 1 { 40 usage() 41 } 42 filePathToRead := flag.Arg(0) 43 b, err := ioutil.ReadFile(filePathToRead) 44 if err != nil { 45 fmt.Println(err.Error()) 46 return 47 } 48 49 output, errs := androidmk.ConvertFile(os.Args[1], bytes.NewBuffer(b)) 50 if len(errs) > 0 { 51 for _, err := range errs { 52 fmt.Fprintln(os.Stderr, "ERROR: ", err) 53 } 54 os.Exit(1) 55 } 56 57 fmt.Print(output) 58} 59