diff options
author | 2023-11-09 20:07:52 +0000 | |
---|---|---|
committer | 2023-11-21 14:06:57 +0000 | |
commit | 2368e9ea9e621862eec4d5b4a37afa5698c8143f (patch) | |
tree | 3495fc9edcd2c2062742e9f495be772c891b3999 | |
parent | b91108c9c07c45ff708030114372db6d217b4e2d (diff) |
Add Singleton class to collect and validate test spec metadata.
Bug: 296873595
Test: Manual testing (Will add unit test case in the next change.)
Change-Id: Ic4177c5f76602088d52a31ca8d9fbaa703855837
-rw-r--r-- | testing/Android.bp | 1 | ||||
-rw-r--r-- | testing/all_test_specs.go | 45 | ||||
-rw-r--r-- | testing/init.go | 6 |
3 files changed, 52 insertions, 0 deletions
diff --git a/testing/Android.bp b/testing/Android.bp index 26a7d9316..85e6a8ba8 100644 --- a/testing/Android.bp +++ b/testing/Android.bp @@ -12,6 +12,7 @@ bootstrap_go_package { ], srcs: [ + "all_test_specs.go", "test_spec.go", "init.go", ], diff --git a/testing/all_test_specs.go b/testing/all_test_specs.go new file mode 100644 index 000000000..2ecf15fa6 --- /dev/null +++ b/testing/all_test_specs.go @@ -0,0 +1,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) +} diff --git a/testing/init.go b/testing/init.go index 8820a6063..206b4306f 100644 --- a/testing/init.go +++ b/testing/init.go @@ -18,10 +18,16 @@ import ( "android/soong/android" ) +var ( + pctx = android.NewPackageContext("android/soong/testing") +) + func init() { RegisterBuildComponents(android.InitRegistrationContext) + pctx.HostBinToolVariable("metadata", "metadata") } func RegisterBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("test_spec", TestSpecFactory) + ctx.RegisterParallelSingletonType("all_test_specs", AllTestSpecsFactory) } |