androidmk.go 1.4 KB

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