| Aditya Choudhary | 2368e9e | 2023-11-09 20:07:52 +0000 | [diff] [blame] | 1 | package testing | 
|  | 2 |  | 
|  | 3 | import ( | 
|  | 4 | "android/soong/android" | 
|  | 5 | ) | 
|  | 6 |  | 
|  | 7 | const ownershipDirectory = "ownership" | 
|  | 8 | const fileContainingFilePaths = "all_test_spec_paths.rsp" | 
|  | 9 | const allTestSpecsFile = "all_test_specs.pb" | 
|  | 10 |  | 
|  | 11 | func AllTestSpecsFactory() android.Singleton { | 
|  | 12 | return &allTestSpecsSingleton{} | 
|  | 13 | } | 
|  | 14 |  | 
|  | 15 | type allTestSpecsSingleton struct { | 
|  | 16 | // Path where the collected metadata is stored after successful validation. | 
|  | 17 | outputPath android.OutputPath | 
|  | 18 | } | 
|  | 19 |  | 
|  | 20 | func (this *allTestSpecsSingleton) GenerateBuildActions(ctx android.SingletonContext) { | 
|  | 21 | var intermediateMetadataPaths android.Paths | 
|  | 22 |  | 
|  | 23 | ctx.VisitAllModules(func(module android.Module) { | 
| Aditya Choudhary | b7b3de8 | 2023-11-17 12:37:41 +0000 | [diff] [blame] | 24 | if !ctx.ModuleHasProvider(module, TestSpecProviderKey) { | 
| Aditya Choudhary | 2368e9e | 2023-11-09 20:07:52 +0000 | [diff] [blame] | 25 | return | 
|  | 26 | } | 
| Aditya Choudhary | b7b3de8 | 2023-11-17 12:37:41 +0000 | [diff] [blame] | 27 | intermediateMetadataPaths = append(intermediateMetadataPaths, ctx.ModuleProvider(module, TestSpecProviderKey).(TestSpecProviderData).IntermediatePath) | 
| Aditya Choudhary | 2368e9e | 2023-11-09 20:07:52 +0000 | [diff] [blame] | 28 | }) | 
|  | 29 |  | 
|  | 30 | rspFile := android.PathForOutput(ctx, fileContainingFilePaths) | 
|  | 31 | this.outputPath = android.PathForOutput(ctx, ownershipDirectory, allTestSpecsFile) | 
|  | 32 |  | 
|  | 33 | rule := android.NewRuleBuilder(pctx, ctx) | 
|  | 34 | cmd := rule.Command(). | 
|  | 35 | BuiltTool("metadata"). | 
|  | 36 | FlagWithArg("-rule ", "test_spec"). | 
|  | 37 | FlagWithRspFileInputList("-inputFile ", rspFile, intermediateMetadataPaths) | 
|  | 38 | cmd.FlagWithOutput("-outputFile ", this.outputPath) | 
|  | 39 | rule.Build("all_test_specs_rule", "Generate all test specifications") | 
|  | 40 | ctx.Phony("all_test_specs", this.outputPath) | 
|  | 41 | } | 
|  | 42 |  | 
|  | 43 | func (this *allTestSpecsSingleton) MakeVars(ctx android.MakeVarsContext) { | 
|  | 44 | ctx.DistForGoal("test_specs", this.outputPath) | 
|  | 45 | } |