Merge remote-tracking branch 'aosp/upstream' into inclusive am: c69182870e
am: ec4ae78c09
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1380886 Change-Id: I5f711b44855aa14fb6f2b3f60818b8b5124bbef1
This commit is contained in:
commit
4914fd7bc8
5 changed files with 102 additions and 22 deletions
|
@ -1,6 +1,7 @@
|
||||||
package bpdoc
|
package bpdoc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -44,3 +45,37 @@ func TestNestedPropertyStructs(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAllPackages(t *testing.T) {
|
||||||
|
packages, err := AllPackages(pkgFiles, moduleTypeNameFactories, moduleTypeNamePropertyStructs)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expected nil error for AllPackages(%v, %v, %v), got %s", pkgFiles, moduleTypeNameFactories, moduleTypeNamePropertyStructs, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if numPackages := len(packages); numPackages != 1 {
|
||||||
|
t.Errorf("Expected %d package, got %d packages %v instead", len(pkgFiles), numPackages, packages)
|
||||||
|
}
|
||||||
|
|
||||||
|
pkg := packages[0]
|
||||||
|
|
||||||
|
for _, m := range pkg.ModuleTypes {
|
||||||
|
for _, p := range m.PropertyStructs {
|
||||||
|
for _, err := range noMutatedProperties(p.Properties) {
|
||||||
|
t.Errorf("%s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func noMutatedProperties(properties []Property) []error {
|
||||||
|
errs := []error{}
|
||||||
|
for _, p := range properties {
|
||||||
|
if hasTag(p.Tag, "blueprint", "mutated") {
|
||||||
|
err := fmt.Errorf("Property %s has `blueprint:\"mutated\" tag but should have been excluded.", p)
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
errs = append(errs, noMutatedProperties(p.Properties)...)
|
||||||
|
}
|
||||||
|
return errs
|
||||||
|
}
|
||||||
|
|
|
@ -251,6 +251,7 @@ func filterPropsByTag(props *[]Property, key, value string, exclude bool) {
|
||||||
filtered := (*props)[:0]
|
filtered := (*props)[:0]
|
||||||
for _, x := range *props {
|
for _, x := range *props {
|
||||||
if hasTag(x.Tag, key, value) == !exclude {
|
if hasTag(x.Tag, key, value) == !exclude {
|
||||||
|
filterPropsByTag(&x.Properties, key, value, exclude)
|
||||||
filtered = append(filtered, x)
|
filtered = append(filtered, x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,8 @@ func TestExcludeByTag(t *testing.T) {
|
||||||
|
|
||||||
ps.ExcludeByTag("tag1", "a")
|
ps.ExcludeByTag("tag1", "a")
|
||||||
|
|
||||||
expected := []string{"c"}
|
expected := []string{"c", "d", "g"}
|
||||||
actual := []string{}
|
actual := actualProperties(t, ps.Properties)
|
||||||
for _, p := range ps.Properties {
|
|
||||||
actual = append(actual, p.Name)
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(expected, actual) {
|
if !reflect.DeepEqual(expected, actual) {
|
||||||
t.Errorf("unexpected ExcludeByTag result, expected: %q, actual: %q", expected, actual)
|
t.Errorf("unexpected ExcludeByTag result, expected: %q, actual: %q", expected, actual)
|
||||||
}
|
}
|
||||||
|
@ -47,12 +44,20 @@ func TestIncludeByTag(t *testing.T) {
|
||||||
|
|
||||||
ps.IncludeByTag("tag1", "c")
|
ps.IncludeByTag("tag1", "c")
|
||||||
|
|
||||||
expected := []string{"b", "c"}
|
expected := []string{"b", "c", "d", "f", "g"}
|
||||||
actual := []string{}
|
actual := actualProperties(t, ps.Properties)
|
||||||
for _, p := range ps.Properties {
|
|
||||||
actual = append(actual, p.Name)
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(expected, actual) {
|
if !reflect.DeepEqual(expected, actual) {
|
||||||
t.Errorf("unexpected IncludeByTag result, expected: %q, actual: %q", expected, actual)
|
t.Errorf("unexpected IncludeByTag result, expected: %q, actual: %q", expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func actualProperties(t *testing.T, props []Property) []string {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
actual := []string{}
|
||||||
|
for _, p := range props {
|
||||||
|
actual = append(actual, p.Name)
|
||||||
|
actual = append(actual, actualProperties(t, p.Properties)...)
|
||||||
|
}
|
||||||
|
return actual
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
package bpdoc
|
package bpdoc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"html/template"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -23,11 +24,29 @@ import (
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type factoryFn func() (blueprint.Module, []interface{})
|
||||||
|
|
||||||
// foo docs.
|
// foo docs.
|
||||||
func fooFactory() (blueprint.Module, []interface{}) {
|
func fooFactory() (blueprint.Module, []interface{}) {
|
||||||
return nil, []interface{}{&props{}}
|
return nil, []interface{}{&props{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bar docs.
|
||||||
|
func barFactory() (blueprint.Module, []interface{}) {
|
||||||
|
return nil, []interface{}{&complexProps{}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// for bpdoc_test.go
|
||||||
|
type complexProps struct {
|
||||||
|
A string
|
||||||
|
B_mutated string `blueprint:"mutated"`
|
||||||
|
|
||||||
|
Nested struct {
|
||||||
|
C string
|
||||||
|
D_mutated string `blueprint:"mutated"`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// props docs.
|
// props docs.
|
||||||
type props struct {
|
type props struct {
|
||||||
// A docs.
|
// A docs.
|
||||||
|
@ -39,10 +58,18 @@ type tagTestProps struct {
|
||||||
A string `tag1:"a,b" tag2:"c"`
|
A string `tag1:"a,b" tag2:"c"`
|
||||||
B string `tag1:"a,c"`
|
B string `tag1:"a,c"`
|
||||||
C string `tag1:"b,c"`
|
C string `tag1:"b,c"`
|
||||||
|
|
||||||
|
D struct {
|
||||||
|
E string `tag1:"a,b" tag2:"c"`
|
||||||
|
F string `tag1:"a,c"`
|
||||||
|
G string `tag1:"b,c"`
|
||||||
|
} `tag1:"b,c"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var pkgPath string
|
var pkgPath string
|
||||||
var pkgFiles map[string][]string
|
var pkgFiles map[string][]string
|
||||||
|
var moduleTypeNameFactories map[string]reflect.Value
|
||||||
|
var moduleTypeNamePropertyStructs map[string][]interface{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pc, filename, _, _ := runtime.Caller(0)
|
pc, filename, _, _ := runtime.Caller(0)
|
||||||
|
@ -57,16 +84,28 @@ func init() {
|
||||||
pkgFiles = map[string][]string{
|
pkgFiles = map[string][]string{
|
||||||
pkgPath: {filename},
|
pkgPath: {filename},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
factories := map[string]factoryFn{"foo": fooFactory, "bar": barFactory}
|
||||||
|
|
||||||
|
moduleTypeNameFactories = make(map[string]reflect.Value, len(factories))
|
||||||
|
moduleTypeNamePropertyStructs = make(map[string][]interface{}, len(factories))
|
||||||
|
for name, factory := range factories {
|
||||||
|
moduleTypeNameFactories[name] = reflect.ValueOf(factory)
|
||||||
|
_, structs := factory()
|
||||||
|
moduleTypeNamePropertyStructs[name] = structs
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestModuleTypeDocs(t *testing.T) {
|
func TestModuleTypeDocs(t *testing.T) {
|
||||||
r := NewReader(pkgFiles)
|
r := NewReader(pkgFiles)
|
||||||
mt, err := r.ModuleType("foo_module", reflect.ValueOf(fooFactory))
|
for m := range moduleTypeNameFactories {
|
||||||
|
mt, err := r.ModuleType(m+"_module", moduleTypeNameFactories[m])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if mt.Text != "foo docs.\n\n" {
|
expectedText := template.HTML(m + " docs.\n\n")
|
||||||
|
if mt.Text != expectedText {
|
||||||
t.Errorf("unexpected docs %q", mt.Text)
|
t.Errorf("unexpected docs %q", mt.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +113,7 @@ func TestModuleTypeDocs(t *testing.T) {
|
||||||
t.Errorf("expected pkgpath %q, got %q", pkgPath, mt.PkgPath)
|
t.Errorf("expected pkgpath %q, got %q", pkgPath, mt.PkgPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPropertyStruct(t *testing.T) {
|
func TestPropertyStruct(t *testing.T) {
|
||||||
r := NewReader(pkgFiles)
|
r := NewReader(pkgFiles)
|
||||||
|
|
|
@ -1172,9 +1172,8 @@ func runAndRemoveLoadHooks(ctx *Context, config interface{}, module *moduleInfo,
|
||||||
|
|
||||||
// Check the syntax of a generated blueprint file.
|
// Check the syntax of a generated blueprint file.
|
||||||
//
|
//
|
||||||
// This is intended to perform a quick sanity check for generated blueprint
|
// This is intended to perform a quick syntactic check for generated blueprint
|
||||||
// code to ensure that it is syntactically correct, where syntactically correct
|
// code, where syntactically correct means:
|
||||||
// means:
|
|
||||||
// * No variable definitions.
|
// * No variable definitions.
|
||||||
// * Valid module types.
|
// * Valid module types.
|
||||||
// * Valid property names.
|
// * Valid property names.
|
||||||
|
|
Loading…
Reference in a new issue