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