Add tests for androidmk am: 6c2ac0673d
am: 54a7e882c8
* commit '54a7e882c891d884b8f71416a4c6bbb63ac19a81':
Add tests for androidmk
Change-Id: Icc1d86b84359a64d00a713d5c781de9d3ba86dd0
This commit is contained in:
@@ -206,6 +206,9 @@ blueprint_go_binary {
|
|||||||
"androidmk/cmd/androidmk/androidmk.go",
|
"androidmk/cmd/androidmk/androidmk.go",
|
||||||
"androidmk/cmd/androidmk/values.go",
|
"androidmk/cmd/androidmk/values.go",
|
||||||
],
|
],
|
||||||
|
testSrcs: [
|
||||||
|
"androidmk/cmd/androidmk/test.go",
|
||||||
|
],
|
||||||
deps: [
|
deps: [
|
||||||
"androidmk-parser",
|
"androidmk-parser",
|
||||||
"blueprint-parser",
|
"blueprint-parser",
|
||||||
|
@@ -71,14 +71,23 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p := mkparser.NewParser(os.Args[1], bytes.NewBuffer(b))
|
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) {
|
||||||
|
p := mkparser.NewParser(filename, buffer)
|
||||||
|
|
||||||
nodes, errs := p.Parse()
|
nodes, errs := p.Parse()
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
for _, err := range errs {
|
return "", errs
|
||||||
fmt.Println("ERROR: ", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file := &bpFile{
|
file := &bpFile{
|
||||||
@@ -169,11 +178,10 @@ func main() {
|
|||||||
Comments: file.comments,
|
Comments: file.comments,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return "", []error{err}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print(string(out))
|
return string(out), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleAssignment(file *bpFile, assignment *mkparser.Assignment, c *conditional) {
|
func handleAssignment(file *bpFile, assignment *mkparser.Assignment, c *conditional) {
|
||||||
|
252
androidmk/cmd/androidmk/test.go
Normal file
252
androidmk/cmd/androidmk/test.go
Normal file
@@ -0,0 +1,252 @@
|
|||||||
|
// Copyright 2016 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
bpparser "github.com/google/blueprint/parser"
|
||||||
|
)
|
||||||
|
|
||||||
|
var testCases = []struct {
|
||||||
|
desc string
|
||||||
|
in string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "basic cc_library_shared with comments",
|
||||||
|
in: `
|
||||||
|
#
|
||||||
|
# Copyright
|
||||||
|
#
|
||||||
|
|
||||||
|
# Module Comment
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
# Name Comment
|
||||||
|
LOCAL_MODULE := test
|
||||||
|
# Source comment
|
||||||
|
LOCAL_SRC_FILES := a.c
|
||||||
|
# Second source comment
|
||||||
|
LOCAL_SRC_FILES += b.c
|
||||||
|
include $(BUILD_SHARED_LIBRARY)`,
|
||||||
|
expected: `
|
||||||
|
//
|
||||||
|
// Copyright
|
||||||
|
//
|
||||||
|
|
||||||
|
// Module Comment
|
||||||
|
cc_library_shared {
|
||||||
|
// Name Comment
|
||||||
|
name: "test",
|
||||||
|
// Source comment
|
||||||
|
srcs: ["a.c"] + ["b.c"], // Second source comment
|
||||||
|
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "split local/global include_dirs (1)",
|
||||||
|
in: `
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_C_INCLUDES := $(LOCAL_PATH)
|
||||||
|
include $(BUILD_SHARED_LIBRARY)`,
|
||||||
|
expected: `
|
||||||
|
cc_library_shared {
|
||||||
|
local_include_dirs: ["."],
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "split local/global include_dirs (2)",
|
||||||
|
in: `
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
||||||
|
include $(BUILD_SHARED_LIBRARY)`,
|
||||||
|
expected: `
|
||||||
|
cc_library_shared {
|
||||||
|
local_include_dirs: ["include"],
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "split local/global include_dirs (3)",
|
||||||
|
in: `
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_C_INCLUDES := system/core/include
|
||||||
|
include $(BUILD_SHARED_LIBRARY)`,
|
||||||
|
expected: `
|
||||||
|
cc_library_shared {
|
||||||
|
include_dirs: ["system/core/include"],
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "split local/global include_dirs (4)",
|
||||||
|
in: `
|
||||||
|
input := testing/include
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
# Comment 1
|
||||||
|
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/include system/core/include $(input)
|
||||||
|
# Comment 2
|
||||||
|
LOCAL_C_INCLUDES += $(TOP)/system/core/include $(LOCAL_PATH)/test/include
|
||||||
|
# Comment 3
|
||||||
|
include $(BUILD_SHARED_LIBRARY)`,
|
||||||
|
expected: `
|
||||||
|
input = ["testing/include"]
|
||||||
|
cc_library_shared {
|
||||||
|
// Comment 1
|
||||||
|
include_dirs: ["system/core/include"] + // Comment 2
|
||||||
|
input + [TOP + "/system/core/include"],
|
||||||
|
local_include_dirs: ["."] + ["include"] + ["test/include"],
|
||||||
|
// Comment 3
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "LOCAL_MODULE_STEM",
|
||||||
|
in: `
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE := libtest
|
||||||
|
LOCAL_MODULE_STEM := $(LOCAL_MODULE).so
|
||||||
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE := libtest2
|
||||||
|
LOCAL_MODULE_STEM := testing.so
|
||||||
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libtest",
|
||||||
|
suffix: ".so",
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libtest2",
|
||||||
|
stem: "testing.so",
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "LOCAL_MODULE_HOST_OS",
|
||||||
|
in: `
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE := libtest
|
||||||
|
LOCAL_MODULE_HOST_OS := linux darwin windows
|
||||||
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE := libtest2
|
||||||
|
LOCAL_MODULE_HOST_OS := linux
|
||||||
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libtest",
|
||||||
|
target: {
|
||||||
|
windows: {
|
||||||
|
enabled: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libtest2",
|
||||||
|
target: {
|
||||||
|
darwin: {
|
||||||
|
enabled: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "LOCAL_RTTI_VALUE",
|
||||||
|
in: `
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE := libtest
|
||||||
|
LOCAL_RTTI_FLAG := # Empty flag
|
||||||
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE := libtest2
|
||||||
|
LOCAL_RTTI_FLAG := -frtti
|
||||||
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libtest",
|
||||||
|
rtti: false, // Empty flag
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libtest2",
|
||||||
|
rtti: true,
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "LOCAL_ARM_MODE",
|
||||||
|
in: `
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_ARM_MODE := arm
|
||||||
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
cc_library_shared {
|
||||||
|
arch: {
|
||||||
|
arm: {
|
||||||
|
instruction_set: "arm",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func reformatBlueprint(input string) string {
|
||||||
|
file, errs := bpparser.Parse("<testcase>", bytes.NewBufferString(input), bpparser.NewScope(nil))
|
||||||
|
if len(errs) > 0 {
|
||||||
|
for _, err := range errs {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
}
|
||||||
|
panic(fmt.Sprintf("%d parsing errors in testcase:\n%s", len(errs), input))
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := bpparser.Print(file)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Error printing testcase: %q", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEndToEnd(t *testing.T) {
|
||||||
|
for i, test := range testCases {
|
||||||
|
expected := reformatBlueprint(test.expected)
|
||||||
|
|
||||||
|
got, errs := convertFile(fmt.Sprintf("<testcase %d>", i), bytes.NewBufferString(test.in))
|
||||||
|
if len(errs) > 0 {
|
||||||
|
t.Errorf("Unexpected errors: %q", errs)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(dwillemsen): remove once bpfmt and androidmk agree
|
||||||
|
got = reformatBlueprint(got)
|
||||||
|
|
||||||
|
if got != expected {
|
||||||
|
t.Errorf("failed testcase '%s'\ninput:\n%s\n\nexpected:\n%s\ngot:\n%s\n", test.desc, strings.TrimSpace(test.in), expected, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user