From 6002e056fd009ab2b74145f086c7e3474c7e5322 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 16 Sep 2015 16:00:08 -0700 Subject: [PATCH] Make Test_per_src a property on all binaries Change-Id: I36b84807cac3d8fd7ef50c8ffb8e2a85ddc10509 --- cc/cc.go | 75 +++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 41 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index 857235fe1..398a06563 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1328,6 +1328,10 @@ type CCBinaryProperties struct { // if set, add an extra objcopy --prefix-symbols= step 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 { @@ -1489,16 +1493,39 @@ func (c *CCBinary) HostToolPath() string { return "" } -type CCTestProperties struct { - // Create a separate test 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 +func (c *CCBinary) testPerSrc() bool { + return c.BinaryProperties.Test_per_src +} + +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 { CCBinary - - TestProperties CCTestProperties } 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, hod common.HostOrDeviceSupported, props ...interface{}) (blueprint.Module, []interface{}) { - props = append(props, &test.TestProperties) - return NewCCBinary(&test.CCBinary, module, hod, props...) } @@ -1553,29 +1570,6 @@ func CCTestFactory() (blueprint.Module, []interface{}) { 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 { CCBinary } @@ -1666,8 +1660,7 @@ func CCBinaryHostFactory() (blueprint.Module, []interface{}) { func CCTestHostFactory() (blueprint.Module, []interface{}) { module := &CCTest{} - return NewCCBinary(&module.CCBinary, module, common.HostSupported, - &module.TestProperties) + return NewCCBinary(&module.CCBinary, module, common.HostSupported) } //