Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac38d7e5 authored by Justin DeMartino's avatar Justin DeMartino
Browse files

Add support to extend commands bpfix and androidmk

Allows our partners to maintain partner-specific fixes in their repos. Converts most of androidmk into a library similar to bpfix. Makes some methods and types public for use by extended versions.

Bug:140727544
Test: Ran unit test cases &&
  ran test conversions with sample
Change-Id: I7e1fbf3a6a7a8bd47334f43fe3eb68cbbd3426c1
parent 7289ddbe
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -19,12 +19,23 @@
blueprint_go_binary {
    name: "androidmk",
    srcs: [
        "cmd/androidmk/android.go",
        "cmd/androidmk/androidmk.go",
        "cmd/androidmk/values.go",
        "cmd/androidmk.go",
    ],
    deps: [
        "androidmk-lib",
    ],
}

bootstrap_go_package {
    name: "androidmk-lib",
    pkgPath: "android/soong/androidmk/androidmk",
    srcs: [
        "androidmk/android.go",
        "androidmk/androidmk.go",
        "androidmk/values.go",
    ],
    testSrcs: [
        "cmd/androidmk/androidmk_test.go",
        "androidmk/androidmk_test.go",
    ],
    deps: [
        "androidmk-parser",
+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package androidmk

import (
	"android/soong/android"
+2 −36
Original line number Diff line number Diff line
@@ -12,14 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package androidmk

import (
	"bytes"
	"flag"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
	"text/scanner"

@@ -30,13 +27,6 @@ import (
	bpparser "github.com/google/blueprint/parser"
)

var usage = func() {
	fmt.Fprintf(os.Stderr, "usage: androidmk [flags] <inputFile>\n"+
		"\nandroidmk parses <inputFile> as an Android.mk file and attempts to output an analogous Android.bp file (to standard out)\n")
	flag.PrintDefaults()
	os.Exit(1)
}

// TODO: non-expanded variables with expressions

type bpFile struct {
@@ -118,31 +108,7 @@ type conditional struct {
	eq   bool
}

func main() {
	flag.Usage = usage
	flag.Parse()
	if len(flag.Args()) != 1 {
		usage()
	}
	filePathToRead := flag.Arg(0)
	b, err := ioutil.ReadFile(filePathToRead)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	output, errs := convertFile(os.Args[1], bytes.NewBuffer(b))
	if len(errs) > 0 {
		for _, err := range errs {
			fmt.Fprintln(os.Stderr, "ERROR: ", err)
		}
		os.Exit(1)
	}

	fmt.Print(output)
}

func convertFile(filename string, buffer *bytes.Buffer) (string, []error) {
func ConvertFile(filename string, buffer *bytes.Buffer) (string, []error) {
	p := mkparser.NewParser(filename, buffer)

	nodes, errs := p.Parse()
+2 −2
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package androidmk

import (
	"bytes"
@@ -1350,7 +1350,7 @@ func TestEndToEnd(t *testing.T) {
			t.Error(err)
		}

		got, errs := convertFile(fmt.Sprintf("<testcase %d>", i), bytes.NewBufferString(test.in))
		got, errs := ConvertFile(fmt.Sprintf("<testcase %d>", i), bytes.NewBufferString(test.in))
		if len(errs) > 0 {
			t.Errorf("Unexpected errors: %q", errs)
			continue
+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package androidmk

import (
	"fmt"
Loading