diff options
-rw-r--r-- | cc/cc.go | 24 | ||||
-rw-r--r-- | cmd/soong_build/main.go | 1 |
2 files changed, 24 insertions, 1 deletions
@@ -1192,6 +1192,12 @@ func (c *ccBinary) installModule(ctx common.AndroidModuleContext, flags ccFlags) type ccTest struct { ccBinary + + testProperties struct { + // test_per_src: 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 + } } var ( @@ -1234,7 +1240,23 @@ func (c *ccTest) installModule(ctx common.AndroidModuleContext, flags ccFlags) { func NewCCTest() (blueprint.Module, []interface{}) { module := &ccTest{} return newCCDynamic(&module.ccDynamic, module, common.HostAndDeviceSupported, - common.MultilibFirst, &module.binaryProperties) + common.MultilibFirst, &module.binaryProperties, &module.testProperties) +} + +func TestPerSrcMutator(mctx blueprint.EarlyMutatorContext) { + if test, ok := mctx.Module().(*ccTest); ok { + if test.testProperties.Test_per_src { + testNames := make([]string, len(test.properties.Srcs)) + for i, src := range test.properties.Srcs { + testNames[i] = strings.TrimSuffix(src, filepath.Ext(src)) + } + tests := mctx.CreateLocalVariations(testNames...) + for i, src := range test.properties.Srcs { + tests[i].(*ccTest).properties.Srcs = []string{src} + tests[i].(*ccTest).binaryProperties.Stem = testNames[i] + } + } + } } // diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index 8e2887c6..e8e33c6c 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -56,6 +56,7 @@ func main() { // Mutators ctx.RegisterEarlyMutator("arch", common.ArchMutator) ctx.RegisterEarlyMutator("link", cc.LinkageMutator) + ctx.RegisterEarlyMutator("test_per_src", cc.TestPerSrcMutator) // Singletons ctx.RegisterSingletonType("checkbuild", common.CheckbuildSingleton) |