Justin DeMartino | ac38d7e | 2019-10-15 17:45:05 -0700 | [diff] [blame] | 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 | |
| 15 | package main |
| 16 | |
| 17 | import ( |
| 18 | "bytes" |
| 19 | "flag" |
| 20 | "fmt" |
| 21 | "io/ioutil" |
| 22 | "os" |
| 23 | |
| 24 | "android/soong/androidmk/androidmk" |
| 25 | |
Colin Cross | ce23942 | 2019-11-08 14:17:49 -0800 | [diff] [blame] | 26 | _ "android/soong/partner/bpfix/extensions" |
Justin DeMartino | ac38d7e | 2019-10-15 17:45:05 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | var 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 | |
| 36 | func 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 | } |