Make Test_per_src a property on all binaries

Change-Id: I36b84807cac3d8fd7ef50c8ffb8e2a85ddc10509
This commit is contained in:
Colin Cross 2015-09-16 16:00:08 -07:00
parent 47cf66b8d1
commit 6002e056fd

View file

@ -1328,6 +1328,10 @@ type CCBinaryProperties struct {
// if set, add an extra objcopy --prefix-symbols= step // if set, add an extra objcopy --prefix-symbols= step
Prefix_symbols string Prefix_symbols string
// Create a separate binary for each source file. Useful when there is
// global state that can not be torn down and reset between each test suite.
Test_per_src bool
} }
type CCBinary struct { type CCBinary struct {
@ -1489,16 +1493,39 @@ func (c *CCBinary) HostToolPath() string {
return "" return ""
} }
type CCTestProperties struct { func (c *CCBinary) testPerSrc() bool {
// Create a separate test for each source file. Useful when there is return c.BinaryProperties.Test_per_src
// global state that can not be torn down and reset between each test suite. }
Test_per_src bool
func (c *CCBinary) binary() *CCBinary {
return c
}
type testPerSrc interface {
binary() *CCBinary
testPerSrc() bool
}
var _ testPerSrc = (*CCBinary)(nil)
func TestPerSrcMutator(mctx blueprint.EarlyMutatorContext) {
if test, ok := mctx.Module().(testPerSrc); ok {
if test.testPerSrc() {
testNames := make([]string, len(test.binary().Properties.Srcs))
for i, src := range test.binary().Properties.Srcs {
testNames[i] = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src))
}
tests := mctx.CreateLocalVariations(testNames...)
for i, src := range test.binary().Properties.Srcs {
tests[i].(testPerSrc).binary().Properties.Srcs = []string{src}
tests[i].(testPerSrc).binary().BinaryProperties.Stem = mctx.ModuleName() + "_" + testNames[i]
}
}
}
} }
type CCTest struct { type CCTest struct {
CCBinary CCBinary
TestProperties CCTestProperties
} }
func (c *CCTest) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags { func (c *CCTest) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
@ -1531,19 +1558,9 @@ func (c *CCTest) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
} }
} }
func (c *CCTest) testPerSrc() bool {
return c.TestProperties.Test_per_src
}
func (c *CCTest) test() *CCTest {
return c
}
func NewCCTest(test *CCTest, module CCModuleType, func NewCCTest(test *CCTest, module CCModuleType,
hod common.HostOrDeviceSupported, props ...interface{}) (blueprint.Module, []interface{}) { hod common.HostOrDeviceSupported, props ...interface{}) (blueprint.Module, []interface{}) {
props = append(props, &test.TestProperties)
return NewCCBinary(&test.CCBinary, module, hod, props...) return NewCCBinary(&test.CCBinary, module, hod, props...)
} }
@ -1553,29 +1570,6 @@ func CCTestFactory() (blueprint.Module, []interface{}) {
return NewCCTest(module, module, common.HostAndDeviceSupported) return NewCCTest(module, module, common.HostAndDeviceSupported)
} }
type testPerSrc interface {
test() *CCTest
testPerSrc() bool
}
var _ testPerSrc = (*CCTest)(nil)
func TestPerSrcMutator(mctx blueprint.EarlyMutatorContext) {
if test, ok := mctx.Module().(testPerSrc); ok {
if test.testPerSrc() {
testNames := make([]string, len(test.test().Properties.Srcs))
for i, src := range test.test().Properties.Srcs {
testNames[i] = strings.TrimSuffix(src, filepath.Ext(src))
}
tests := mctx.CreateLocalVariations(testNames...)
for i, src := range test.test().Properties.Srcs {
tests[i].(testPerSrc).test().Properties.Srcs = []string{src}
tests[i].(testPerSrc).test().BinaryProperties.Stem = testNames[i]
}
}
}
}
type CCBenchmark struct { type CCBenchmark struct {
CCBinary CCBinary
} }
@ -1666,8 +1660,7 @@ func CCBinaryHostFactory() (blueprint.Module, []interface{}) {
func CCTestHostFactory() (blueprint.Module, []interface{}) { func CCTestHostFactory() (blueprint.Module, []interface{}) {
module := &CCTest{} module := &CCTest{}
return NewCCBinary(&module.CCBinary, module, common.HostSupported, return NewCCBinary(&module.CCBinary, module, common.HostSupported)
&module.TestProperties)
} }
// //