Fix arch specific properties for java modules

Arch specific properties were not being applied to modules
with OS set to Common.

Test: java_test.go
Change-Id: I8f1b49ca51b0cf96f78006dfcd121672e581d9c5
This commit is contained in:
Colin Cross
2017-10-02 13:55:26 -07:00
parent a60ead85fc
commit d5934c8bb7
2 changed files with 88 additions and 62 deletions

View File

@@ -597,10 +597,6 @@ func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
arch := a.Arch() arch := a.Arch()
os := a.Os() os := a.Os()
if arch.ArchType == Common {
return
}
for i := range a.generalProperties { for i := range a.generalProperties {
genProps := a.generalProperties[i] genProps := a.generalProperties[i]
if a.archProperties[i] == nil { if a.archProperties[i] == nil {
@@ -612,6 +608,9 @@ func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
multilibProp := archProps.FieldByName("Multilib") multilibProp := archProps.FieldByName("Multilib")
targetProp := archProps.FieldByName("Target") targetProp := archProps.FieldByName("Target")
var field string
var prefix string
// Handle arch-specific properties in the form: // Handle arch-specific properties in the form:
// arch: { // arch: {
// arm64: { // arm64: {
@@ -620,59 +619,61 @@ func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
// }, // },
t := arch.ArchType t := arch.ArchType
field := proptools.FieldNameForProperty(t.Name) if arch.ArchType != Common {
prefix := "arch." + t.Name field := proptools.FieldNameForProperty(t.Name)
archStruct := a.appendProperties(ctx, genProps, archProp, field, prefix) prefix := "arch." + t.Name
archStruct := a.appendProperties(ctx, genProps, archProp, field, prefix)
// Handle arch-variant-specific properties in the form: // Handle arch-variant-specific properties in the form:
// arch: { // arch: {
// variant: { // variant: {
// key: value, // key: value,
// }, // },
// }, // },
v := variantReplacer.Replace(arch.ArchVariant) v := variantReplacer.Replace(arch.ArchVariant)
if v != "" { if v != "" {
field := proptools.FieldNameForProperty(v) field := proptools.FieldNameForProperty(v)
prefix := "arch." + t.Name + "." + v prefix := "arch." + t.Name + "." + v
a.appendProperties(ctx, genProps, archStruct, field, prefix)
}
// Handle cpu-variant-specific properties in the form:
// arch: {
// variant: {
// key: value,
// },
// },
if arch.CpuVariant != arch.ArchVariant {
c := variantReplacer.Replace(arch.CpuVariant)
if c != "" {
field := proptools.FieldNameForProperty(c)
prefix := "arch." + t.Name + "." + c
a.appendProperties(ctx, genProps, archStruct, field, prefix) a.appendProperties(ctx, genProps, archStruct, field, prefix)
} }
}
// Handle arch-feature-specific properties in the form: // Handle cpu-variant-specific properties in the form:
// arch: { // arch: {
// feature: { // variant: {
// key: value, // key: value,
// }, // },
// }, // },
for _, feature := range arch.ArchFeatures { if arch.CpuVariant != arch.ArchVariant {
field := proptools.FieldNameForProperty(feature) c := variantReplacer.Replace(arch.CpuVariant)
prefix := "arch." + t.Name + "." + feature if c != "" {
a.appendProperties(ctx, genProps, archStruct, field, prefix) field := proptools.FieldNameForProperty(c)
} prefix := "arch." + t.Name + "." + c
a.appendProperties(ctx, genProps, archStruct, field, prefix)
}
}
// Handle multilib-specific properties in the form: // Handle arch-feature-specific properties in the form:
// multilib: { // arch: {
// lib32: { // feature: {
// key: value, // key: value,
// }, // },
// }, // },
field = proptools.FieldNameForProperty(t.Multilib) for _, feature := range arch.ArchFeatures {
prefix = "multilib." + t.Multilib field := proptools.FieldNameForProperty(feature)
a.appendProperties(ctx, genProps, multilibProp, field, prefix) prefix := "arch." + t.Name + "." + feature
a.appendProperties(ctx, genProps, archStruct, field, prefix)
}
// Handle multilib-specific properties in the form:
// multilib: {
// lib32: {
// key: value,
// },
// },
field = proptools.FieldNameForProperty(t.Multilib)
prefix = "multilib." + t.Multilib
a.appendProperties(ctx, genProps, multilibProp, field, prefix)
}
// Handle host-specific properties in the form: // Handle host-specific properties in the form:
// target: { // target: {
@@ -700,9 +701,11 @@ func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
prefix = "target.linux" prefix = "target.linux"
a.appendProperties(ctx, genProps, targetProp, field, prefix) a.appendProperties(ctx, genProps, targetProp, field, prefix)
field = "Linux_" + t.Name if arch.ArchType != Common {
prefix = "target.linux_" + t.Name field = "Linux_" + arch.ArchType.Name
a.appendProperties(ctx, genProps, targetProp, field, prefix) prefix = "target.linux_" + arch.ArchType.Name
a.appendProperties(ctx, genProps, targetProp, field, prefix)
}
} }
if os.Bionic() { if os.Bionic() {
@@ -710,9 +713,11 @@ func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
prefix = "target.bionic" prefix = "target.bionic"
a.appendProperties(ctx, genProps, targetProp, field, prefix) a.appendProperties(ctx, genProps, targetProp, field, prefix)
field = "Bionic_" + t.Name if arch.ArchType != Common {
prefix = "target.bionic_" + t.Name field = "Bionic_" + t.Name
a.appendProperties(ctx, genProps, targetProp, field, prefix) prefix = "target.bionic_" + t.Name
a.appendProperties(ctx, genProps, targetProp, field, prefix)
}
} }
// Handle target OS properties in the form: // Handle target OS properties in the form:
@@ -743,9 +748,11 @@ func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
prefix = "target." + os.Name prefix = "target." + os.Name
a.appendProperties(ctx, genProps, targetProp, field, prefix) a.appendProperties(ctx, genProps, targetProp, field, prefix)
field = os.Field + "_" + t.Name if arch.ArchType != Common {
prefix = "target." + os.Name + "_" + t.Name field = os.Field + "_" + t.Name
a.appendProperties(ctx, genProps, targetProp, field, prefix) prefix = "target." + os.Name + "_" + t.Name
a.appendProperties(ctx, genProps, targetProp, field, prefix)
}
if (os.Class == Host || os.Class == HostCross) && os != Windows { if (os.Class == Host || os.Class == HostCross) && os != Windows {
field := "Not_windows" field := "Not_windows"

View File

@@ -139,7 +139,7 @@ func TestSimple(t *testing.T) {
name: "baz", name: "baz",
srcs: ["c.java"], srcs: ["c.java"],
} }
`) `)
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
combineJar := ctx.ModuleForTests("foo", "android_common").Rule("combineJar") combineJar := ctx.ModuleForTests("foo", "android_common").Rule("combineJar")
@@ -164,6 +164,25 @@ func TestSimple(t *testing.T) {
} }
} }
func TestArchSpecific(t *testing.T) {
ctx := testJava(t, `
java_library {
name: "foo",
srcs: ["a.java"],
target: {
android: {
srcs: ["b.java"],
},
},
}
`)
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
if len(javac.Inputs) != 2 || javac.Inputs[0].String() != "a.java" || javac.Inputs[1].String() != "b.java" {
t.Errorf(`foo inputs %v != ["a.java", "b.java"]`, javac.Inputs)
}
}
var classpathTestcases = []struct { var classpathTestcases = []struct {
name string name string
host android.OsClass host android.OsClass