|
@@ -107,176 +107,153 @@ func (ob Object) Config() string {
|
|
|
|
|
|
}
|
|
|
|
|
|
-func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string, configs []Config, testInstallBase string) {
|
|
|
- autogenTemplateWithNameAndOutputFile(ctx, ctx.ModuleName(), output, template, configs, "", testInstallBase)
|
|
|
+// 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 autogenTemplateWithName(ctx android.ModuleContext, name string, output android.WritablePath, template string, configs []Config, testInstallBase string) {
|
|
|
- autogenTemplateWithNameAndOutputFile(ctx, name, output, template, configs, "", testInstallBase)
|
|
|
+func NewMaybeAutoGenTestConfigBuilder(ctx android.ModuleContext) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ return &MaybeAutoGenTestConfigBuilder{
|
|
|
+ ctx: ctx,
|
|
|
+ name: ctx.ModuleName(),
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-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) SetName(name string) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ b.name = name
|
|
|
+ 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) SetOutputFileName(outputFileName string) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ b.outputFileName = outputFileName
|
|
|
+ return b
|
|
|
}
|
|
|
|
|
|
-func AutoGenNativeTestConfig(ctx android.ModuleContext, testConfigProp *string,
|
|
|
- testConfigTemplateProp *string, testSuites []string, config []Config, autoGenConfig *bool, testInstallBase string) android.Path {
|
|
|
+func (b *MaybeAutoGenTestConfigBuilder) SetTestConfigProp(testConfigProp *string) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ b.testConfigProp = testConfigProp
|
|
|
+ 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(), config, testInstallBase)
|
|
|
- } else {
|
|
|
- if ctx.Device() {
|
|
|
- autogenTemplate(ctx, autogenPath, "${NativeTestConfigTemplate}", config, testInstallBase)
|
|
|
- } else {
|
|
|
- autogenTemplate(ctx, autogenPath, "${NativeHostTestConfigTemplate}", config, testInstallBase)
|
|
|
- }
|
|
|
- }
|
|
|
- return autogenPath
|
|
|
- }
|
|
|
- return path
|
|
|
+func (b *MaybeAutoGenTestConfigBuilder) SetTestTemplateConfigProp(testConfigTemplateProp *string) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ b.testConfigTemplateProp = testConfigTemplateProp
|
|
|
+ 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) SetTestSuites(testSuites []string) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ b.testSuites = testSuites
|
|
|
+ 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) SetConfig(config []Config) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ b.config = config
|
|
|
+ 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
|
|
|
+func (b *MaybeAutoGenTestConfigBuilder) SetOptionsForAutogenerated(configsForAutogenerated []Option) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ configs := make([]Config, 0, len(configsForAutogenerated))
|
|
|
+ for _, c := range configsForAutogenerated {
|
|
|
+ configs = append(configs, c)
|
|
|
}
|
|
|
- return path
|
|
|
+ b.configsForAutogenerated = configs
|
|
|
+ return b
|
|
|
}
|
|
|
|
|
|
-func AutoGenPythonBinaryHostTestConfig(ctx android.ModuleContext, testConfigProp *string,
|
|
|
- testConfigTemplateProp *string, testSuites []string, autoGenConfig *bool) android.Path {
|
|
|
+func (b *MaybeAutoGenTestConfigBuilder) SetUnitTest(unitTest *bool) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ b.unitTest = unitTest
|
|
|
+ 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) SetAutoGenConfig(autoGenConfig *bool) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ b.autoGenConfig = autoGenConfig
|
|
|
+ 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) SetTestInstallBase(testInstallBase string) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ b.testInstallBase = testInstallBase
|
|
|
+ return b
|
|
|
}
|
|
|
|
|
|
-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)
|
|
|
+func (b *MaybeAutoGenTestConfigBuilder) SetDeviceTemplate(deviceTemplate string) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ b.deviceTemplate = deviceTemplate
|
|
|
+ return b
|
|
|
+}
|
|
|
+
|
|
|
+func (b *MaybeAutoGenTestConfigBuilder) SetHostTemplate(hostTemplate string) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ b.hostTemplate = hostTemplate
|
|
|
+ return b
|
|
|
+}
|
|
|
+
|
|
|
+func (b *MaybeAutoGenTestConfigBuilder) SetHostUnitTestTemplate(hostUnitTestTemplate string) *MaybeAutoGenTestConfigBuilder {
|
|
|
+ b.hostUnitTestTemplate = hostUnitTestTemplate
|
|
|
+ return b
|
|
|
+}
|
|
|
+
|
|
|
+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)
|
|
|
if autogenPath != nil {
|
|
|
- templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
|
|
+ templatePath := getTestConfigTemplate(b.ctx, b.testConfigTemplateProp)
|
|
|
if templatePath.Valid() {
|
|
|
- autogenTemplate(ctx, autogenPath, templatePath.String(), config, "")
|
|
|
+ autogenTemplate(b.ctx, b.name, autogenPath, templatePath.String(), config, b.outputFileName, b.testInstallBase)
|
|
|
} else {
|
|
|
- if ctx.Device() {
|
|
|
- autogenTemplate(ctx, autogenPath, "${RustDeviceBenchmarkConfigTemplate}", config, "")
|
|
|
+ if b.ctx.Device() {
|
|
|
+ autogenTemplate(b.ctx, b.name, autogenPath, b.deviceTemplate, config, b.outputFileName, b.testInstallBase)
|
|
|
} else {
|
|
|
- autogenTemplate(ctx, autogenPath, "${RustHostBenchmarkConfigTemplate}", config, "")
|
|
|
+ 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)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
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 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
|
|
|
+func autogenTemplate(ctx android.ModuleContext, name string, output android.WritablePath, template string, configs []Config, outputFileName string, testInstallBase string) {
|
|
|
+ if template == "" {
|
|
|
+ ctx.ModuleErrorf("Empty template")
|
|
|
}
|
|
|
- return path
|
|
|
+ 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)
|
|
|
+
|
|
|
+ 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,
|
|
|
+ },
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
var autogenInstrumentationTest = pctx.StaticRule("autogenInstrumentationTest", blueprint.RuleParams{
|