androidmk.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. )
  23. var usage = func() {
  24. fmt.Fprintf(os.Stderr, "usage: androidmk [flags] <inputFile>\n"+
  25. "\nandroidmk parses <inputFile> as an Android.mk file and attempts to output an analogous Android.bp file (to standard out)\n")
  26. flag.PrintDefaults()
  27. os.Exit(1)
  28. }
  29. func main() {
  30. flag.Usage = usage
  31. flag.Parse()
  32. if len(flag.Args()) != 1 {
  33. usage()
  34. }
  35. filePathToRead := flag.Arg(0)
  36. b, err := ioutil.ReadFile(filePathToRead)
  37. if err != nil {
  38. fmt.Println(err.Error())
  39. return
  40. }
  41. output, errs := androidmk.ConvertFile(os.Args[1], bytes.NewBuffer(b))
  42. if len(output) > 0 {
  43. fmt.Print(output)
  44. }
  45. if len(errs) > 0 {
  46. for _, err := range errs {
  47. fmt.Fprintln(os.Stderr, "ERROR: ", err)
  48. }
  49. os.Exit(1)
  50. }
  51. }