summaryrefslogtreecommitdiff
path: root/testing/all_test_specs.go
blob: 9d4645b3729f3d685c16ef8f1041a15b76d88351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package testing

import (
	"android/soong/android"
)

const ownershipDirectory = "ownership"
const fileContainingFilePaths = "all_test_spec_paths.rsp"
const allTestSpecsFile = "all_test_specs.pb"

func AllTestSpecsFactory() android.Singleton {
	return &allTestSpecsSingleton{}
}

type allTestSpecsSingleton struct {
	// Path where the collected metadata is stored after successful validation.
	outputPath android.OutputPath
}

func (this *allTestSpecsSingleton) GenerateBuildActions(ctx android.SingletonContext) {
	var intermediateMetadataPaths android.Paths

	ctx.VisitAllModules(func(module android.Module) {
		if !ctx.ModuleHasProvider(module, TestSpecProviderKey) {
			return
		}
		intermediateMetadataPaths = append(intermediateMetadataPaths, ctx.ModuleProvider(module, TestSpecProviderKey).(TestSpecProviderData).IntermediatePath)
	})

	rspFile := android.PathForOutput(ctx, fileContainingFilePaths)
	this.outputPath = android.PathForOutput(ctx, ownershipDirectory, allTestSpecsFile)

	rule := android.NewRuleBuilder(pctx, ctx)
	cmd := rule.Command().
		BuiltTool("metadata").
		FlagWithArg("-rule ", "test_spec").
		FlagWithRspFileInputList("-inputFile ", rspFile, intermediateMetadataPaths)
	cmd.FlagWithOutput("-outputFile ", this.outputPath)
	rule.Build("all_test_specs_rule", "Generate all test specifications")
	ctx.Phony("all_test_specs", this.outputPath)
}

func (this *allTestSpecsSingleton) MakeVars(ctx android.MakeVarsContext) {
	ctx.DistForGoal("test_specs", this.outputPath)
}