summaryrefslogtreecommitdiff
path: root/tradefed/autogen.go
diff options
context:
space:
mode:
Diffstat (limited to 'tradefed/autogen.go')
-rw-r--r--tradefed/autogen.go249
1 files changed, 136 insertions, 113 deletions
diff --git a/tradefed/autogen.go b/tradefed/autogen.go
index 236e559b5..c2429ab7a 100644
--- a/tradefed/autogen.go
+++ b/tradefed/autogen.go
@@ -107,153 +107,176 @@ func (ob Object) Config() string {
}
-// MaybeAutoGenTestConfigBuilder provides a Build() method that will either
-// generate a AndroidTest.xml file, or use an existing user-supplied one.
-// It used to be a bunch of separate functions for each language, but was
-// converted to this builder pattern to have one function that accepts many
-// optional arguments.
-type MaybeAutoGenTestConfigBuilder struct {
- ctx android.ModuleContext
- name string
- outputFileName string
- testConfigProp *string
- testConfigTemplateProp *string
- testSuites []string
- config []Config
- configsForAutogenerated []Config
- autoGenConfig *bool
- unitTest *bool
- testInstallBase string
- deviceTemplate string
- hostTemplate string
- hostUnitTestTemplate string
+func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string, configs []Config, testInstallBase string) {
+ autogenTemplateWithNameAndOutputFile(ctx, ctx.ModuleName(), output, template, configs, "", testInstallBase)
}
-func NewMaybeAutoGenTestConfigBuilder(ctx android.ModuleContext) *MaybeAutoGenTestConfigBuilder {
- return &MaybeAutoGenTestConfigBuilder{
- ctx: ctx,
- name: ctx.ModuleName(),
- }
-}
-
-func (b *MaybeAutoGenTestConfigBuilder) SetName(name string) *MaybeAutoGenTestConfigBuilder {
- b.name = name
- return b
-}
-
-func (b *MaybeAutoGenTestConfigBuilder) SetOutputFileName(outputFileName string) *MaybeAutoGenTestConfigBuilder {
- b.outputFileName = outputFileName
- return b
-}
-
-func (b *MaybeAutoGenTestConfigBuilder) SetTestConfigProp(testConfigProp *string) *MaybeAutoGenTestConfigBuilder {
- b.testConfigProp = testConfigProp
- return b
+func autogenTemplateWithName(ctx android.ModuleContext, name string, output android.WritablePath, template string, configs []Config, testInstallBase string) {
+ autogenTemplateWithNameAndOutputFile(ctx, name, output, template, configs, "", testInstallBase)
}
-func (b *MaybeAutoGenTestConfigBuilder) SetTestTemplateConfigProp(testConfigTemplateProp *string) *MaybeAutoGenTestConfigBuilder {
- b.testConfigTemplateProp = testConfigTemplateProp
- return b
-}
+func autogenTemplateWithNameAndOutputFile(ctx android.ModuleContext, name string, output android.WritablePath, template string, configs []Config, outputFileName string, testInstallBase string) {
+ var configStrings []string
+ for _, config := range configs {
+ configStrings = append(configStrings, config.Config())
+ }
+ extraConfigs := strings.Join(configStrings, fmt.Sprintf("\\n%s", test_xml_indent))
+ extraConfigs = proptools.NinjaAndShellEscape(extraConfigs)
-func (b *MaybeAutoGenTestConfigBuilder) SetTestSuites(testSuites []string) *MaybeAutoGenTestConfigBuilder {
- b.testSuites = testSuites
- return b
+ ctx.Build(pctx, android.BuildParams{
+ Rule: autogenTestConfig,
+ Description: "test config",
+ Output: output,
+ Args: map[string]string{
+ "name": name,
+ "template": template,
+ "extraConfigs": extraConfigs,
+ "outputFileName": outputFileName,
+ "testInstallBase": testInstallBase,
+ },
+ })
}
-func (b *MaybeAutoGenTestConfigBuilder) SetConfig(config []Config) *MaybeAutoGenTestConfigBuilder {
- b.config = config
- return b
-}
+func AutoGenNativeTestConfig(ctx android.ModuleContext, testConfigProp *string,
+ testConfigTemplateProp *string, testSuites []string, config []Config, autoGenConfig *bool, testInstallBase string) android.Path {
-func (b *MaybeAutoGenTestConfigBuilder) SetOptionsForAutogenerated(configsForAutogenerated []Option) *MaybeAutoGenTestConfigBuilder {
- configs := make([]Config, 0, len(configsForAutogenerated))
- for _, c := range configsForAutogenerated {
- configs = append(configs, c)
+ path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
+ if autogenPath != nil {
+ templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
+ if templatePath.Valid() {
+ autogenTemplate(ctx, autogenPath, templatePath.String(), config, testInstallBase)
+ } else {
+ if ctx.Device() {
+ autogenTemplate(ctx, autogenPath, "${NativeTestConfigTemplate}", config, testInstallBase)
+ } else {
+ autogenTemplate(ctx, autogenPath, "${NativeHostTestConfigTemplate}", config, testInstallBase)
+ }
+ }
+ return autogenPath
}
- b.configsForAutogenerated = configs
- return b
+ return path
}
-func (b *MaybeAutoGenTestConfigBuilder) SetUnitTest(unitTest *bool) *MaybeAutoGenTestConfigBuilder {
- b.unitTest = unitTest
- return b
+func AutoGenShellTestConfig(ctx android.ModuleContext, testConfigProp *string,
+ testConfigTemplateProp *string, testSuites []string, config []Config, autoGenConfig *bool, outputFileName string) android.Path {
+ path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
+ if autogenPath != nil {
+ templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
+ if templatePath.Valid() {
+ autogenTemplateWithNameAndOutputFile(ctx, ctx.ModuleName(), autogenPath, templatePath.String(), config, outputFileName, "")
+ } else {
+ autogenTemplateWithNameAndOutputFile(ctx, ctx.ModuleName(), autogenPath, "${ShellTestConfigTemplate}", config, outputFileName, "")
+ }
+ return autogenPath
+ }
+ return path
}
-func (b *MaybeAutoGenTestConfigBuilder) SetAutoGenConfig(autoGenConfig *bool) *MaybeAutoGenTestConfigBuilder {
- b.autoGenConfig = autoGenConfig
- return b
+func AutoGenNativeBenchmarkTestConfig(ctx android.ModuleContext, testConfigProp *string,
+ testConfigTemplateProp *string, testSuites []string, configs []Config, autoGenConfig *bool) android.Path {
+ path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
+ if autogenPath != nil {
+ templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
+ if templatePath.Valid() {
+ autogenTemplate(ctx, autogenPath, templatePath.String(), configs, "")
+ } else {
+ autogenTemplate(ctx, autogenPath, "${NativeBenchmarkTestConfigTemplate}", configs, "")
+ }
+ return autogenPath
+ }
+ return path
}
-func (b *MaybeAutoGenTestConfigBuilder) SetTestInstallBase(testInstallBase string) *MaybeAutoGenTestConfigBuilder {
- b.testInstallBase = testInstallBase
- return b
+func AutoGenJavaTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string,
+ testSuites []string, config []Config, autoGenConfig *bool, unitTest *bool) android.Path {
+ path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
+ if autogenPath != nil {
+ templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
+ if templatePath.Valid() {
+ autogenTemplate(ctx, autogenPath, templatePath.String(), config, "")
+ } else {
+ if ctx.Device() {
+ autogenTemplate(ctx, autogenPath, "${JavaTestConfigTemplate}", config, "")
+ } else {
+ if Bool(unitTest) {
+ autogenTemplate(ctx, autogenPath, "${JavaHostUnitTestConfigTemplate}", config, "")
+ } else {
+ autogenTemplate(ctx, autogenPath, "${JavaHostTestConfigTemplate}", config, "")
+ }
+ }
+ }
+ return autogenPath
+ }
+ return path
}
-func (b *MaybeAutoGenTestConfigBuilder) SetDeviceTemplate(deviceTemplate string) *MaybeAutoGenTestConfigBuilder {
- b.deviceTemplate = deviceTemplate
- return b
-}
+func AutoGenPythonBinaryHostTestConfig(ctx android.ModuleContext, testConfigProp *string,
+ testConfigTemplateProp *string, testSuites []string, autoGenConfig *bool) android.Path {
-func (b *MaybeAutoGenTestConfigBuilder) SetHostTemplate(hostTemplate string) *MaybeAutoGenTestConfigBuilder {
- b.hostTemplate = hostTemplate
- return b
+ path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
+ if autogenPath != nil {
+ templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
+ if templatePath.Valid() {
+ autogenTemplate(ctx, autogenPath, templatePath.String(), nil, "")
+ } else {
+ autogenTemplate(ctx, autogenPath, "${PythonBinaryHostTestConfigTemplate}", nil, "")
+ }
+ return autogenPath
+ }
+ return path
}
-func (b *MaybeAutoGenTestConfigBuilder) SetHostUnitTestTemplate(hostUnitTestTemplate string) *MaybeAutoGenTestConfigBuilder {
- b.hostUnitTestTemplate = hostUnitTestTemplate
- return b
+func AutoGenRustTestConfig(ctx android.ModuleContext, testConfigProp *string,
+ testConfigTemplateProp *string, testSuites []string, config []Config, autoGenConfig *bool, testInstallBase string) android.Path {
+ path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
+ if autogenPath != nil {
+ templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
+ if templatePath.Valid() {
+ autogenTemplate(ctx, autogenPath, templatePath.String(), config, testInstallBase)
+ } else {
+ if ctx.Device() {
+ autogenTemplate(ctx, autogenPath, "${RustDeviceTestConfigTemplate}", config, testInstallBase)
+ } else {
+ autogenTemplate(ctx, autogenPath, "${RustHostTestConfigTemplate}", config, testInstallBase)
+ }
+ }
+ return autogenPath
+ }
+ return path
}
-func (b *MaybeAutoGenTestConfigBuilder) Build() android.Path {
- config := append(b.config, b.configsForAutogenerated...)
- path, autogenPath := testConfigPath(b.ctx, b.testConfigProp, b.testSuites, b.autoGenConfig, b.testConfigTemplateProp)
+func AutoGenRustBenchmarkConfig(ctx android.ModuleContext, testConfigProp *string,
+ testConfigTemplateProp *string, testSuites []string, config []Config, autoGenConfig *bool) android.Path {
+ path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
if autogenPath != nil {
- templatePath := getTestConfigTemplate(b.ctx, b.testConfigTemplateProp)
+ templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
if templatePath.Valid() {
- autogenTemplate(b.ctx, b.name, autogenPath, templatePath.String(), config, b.outputFileName, b.testInstallBase)
+ autogenTemplate(ctx, autogenPath, templatePath.String(), config, "")
} else {
- if b.ctx.Device() {
- autogenTemplate(b.ctx, b.name, autogenPath, b.deviceTemplate, config, b.outputFileName, b.testInstallBase)
+ if ctx.Device() {
+ autogenTemplate(ctx, autogenPath, "${RustDeviceBenchmarkConfigTemplate}", config, "")
} else {
- if Bool(b.unitTest) {
- autogenTemplate(b.ctx, b.name, autogenPath, b.hostUnitTestTemplate, config, b.outputFileName, b.testInstallBase)
- } else {
- autogenTemplate(b.ctx, b.name, autogenPath, b.hostTemplate, config, b.outputFileName, b.testInstallBase)
- }
+ autogenTemplate(ctx, autogenPath, "${RustHostBenchmarkConfigTemplate}", config, "")
}
}
return autogenPath
}
- if len(b.configsForAutogenerated) > 0 {
- b.ctx.ModuleErrorf("Extra tradefed configurations were provided for an autogenerated xml file, but the autogenerated xml file was not used.")
- }
return path
}
-func autogenTemplate(ctx android.ModuleContext, name string, output android.WritablePath, template string, configs []Config, outputFileName string, testInstallBase string) {
- if template == "" {
- ctx.ModuleErrorf("Empty template")
- }
- var configStrings []string
- for _, config := range configs {
- configStrings = append(configStrings, config.Config())
+func AutoGenRobolectricTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string,
+ testSuites []string, autoGenConfig *bool) android.Path {
+ path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
+ if autogenPath != nil {
+ templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
+ if templatePath.Valid() {
+ autogenTemplate(ctx, autogenPath, templatePath.String(), nil, "")
+ } else {
+ autogenTemplate(ctx, autogenPath, "${RobolectricTestConfigTemplate}", nil, "")
+ }
+ return autogenPath
}
- extraConfigs := strings.Join(configStrings, fmt.Sprintf("\\n%s", test_xml_indent))
- extraConfigs = proptools.NinjaAndShellEscape(extraConfigs)
-
- ctx.Build(pctx, android.BuildParams{
- Rule: autogenTestConfig,
- Description: "test config",
- Output: output,
- Args: map[string]string{
- "name": name,
- "template": template,
- "extraConfigs": extraConfigs,
- "outputFileName": outputFileName,
- "testInstallBase": testInstallBase,
- },
- })
+ return path
}
var autogenInstrumentationTest = pctx.StaticRule("autogenInstrumentationTest", blueprint.RuleParams{