Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package tradefed |
| 16 | |
| 17 | import ( |
Julien Desprez | eb7398e | 2019-02-28 08:45:28 -0800 | [diff] [blame] | 18 | "fmt" |
Julien Desprez | eb7398e | 2019-02-28 08:45:28 -0800 | [diff] [blame] | 19 | "strings" |
| 20 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 21 | "github.com/google/blueprint" |
Julien Desprez | eb7398e | 2019-02-28 08:45:28 -0800 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 23 | |
| 24 | "android/soong/android" |
| 25 | ) |
| 26 | |
Dan Shi | 20ccd21 | 2019-08-27 10:37:24 -0700 | [diff] [blame] | 27 | const test_xml_indent = " " |
| 28 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 29 | func getTestConfigTemplate(ctx android.ModuleContext, prop *string) android.OptionalPath { |
| 30 | return ctx.ExpandOptionalSource(prop, "test_config_template") |
| 31 | } |
| 32 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 33 | func getTestConfig(ctx android.ModuleContext, prop *string) android.Path { |
| 34 | if p := ctx.ExpandOptionalSource(prop, "test_config"); p.Valid() { |
| 35 | return p.Path() |
| 36 | } else if p := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "AndroidTest.xml"); p.Valid() { |
| 37 | return p.Path() |
| 38 | } |
| 39 | return nil |
| 40 | } |
| 41 | |
| 42 | var autogenTestConfig = pctx.StaticRule("autogenTestConfig", blueprint.RuleParams{ |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 43 | Command: "sed 's&{MODULE}&${name}&g;s&{EXTRA_CONFIGS}&'${extraConfigs}'&g;s&{OUTPUT_FILENAME}&'${outputFileName}'&g;s&{TEST_INSTALL_BASE}&'${testInstallBase}'&g' $template > $out", |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 44 | CommandDeps: []string{"$template"}, |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 45 | }, "name", "template", "extraConfigs", "outputFileName", "testInstallBase") |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 46 | |
Lorenzo Colitti | e29c21e | 2020-02-14 18:27:56 +0900 | [diff] [blame] | 47 | func testConfigPath(ctx android.ModuleContext, prop *string, testSuites []string, autoGenConfig *bool, testConfigTemplateProp *string) (path android.Path, autogenPath android.WritablePath) { |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 48 | p := getTestConfig(ctx, prop) |
| 49 | if !Bool(autoGenConfig) && p != nil { |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 50 | return p, nil |
Lorenzo Colitti | e29c21e | 2020-02-14 18:27:56 +0900 | [diff] [blame] | 51 | } else if BoolDefault(autoGenConfig, true) && (!android.InList("cts", testSuites) || testConfigTemplateProp != nil) { |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 52 | outputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".config") |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 53 | return nil, outputFile |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 54 | } else { |
| 55 | // CTS modules can be used for test data, so test config files must be |
Lorenzo Colitti | e29c21e | 2020-02-14 18:27:56 +0900 | [diff] [blame] | 56 | // explicitly created using AndroidTest.xml or test_config_template. |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 57 | return nil, nil |
| 58 | } |
| 59 | } |
| 60 | |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 61 | type Config interface { |
| 62 | Config() string |
| 63 | } |
| 64 | |
| 65 | type Option struct { |
| 66 | Name string |
easoncylee | 1e3fdcd | 2020-04-30 10:08:33 +0800 | [diff] [blame] | 67 | Key string |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 68 | Value string |
| 69 | } |
| 70 | |
| 71 | var _ Config = Option{} |
| 72 | |
| 73 | func (o Option) Config() string { |
easoncylee | 1e3fdcd | 2020-04-30 10:08:33 +0800 | [diff] [blame] | 74 | if o.Key != "" { |
| 75 | return fmt.Sprintf(`<option name="%s" key="%s" value="%s" />`, o.Name, o.Key, o.Value) |
| 76 | } |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 77 | return fmt.Sprintf(`<option name="%s" value="%s" />`, o.Name, o.Value) |
| 78 | } |
| 79 | |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 80 | // It can be a template of object or target_preparer. |
| 81 | type Object struct { |
| 82 | // Set it as a target_preparer if object type == "target_preparer". |
| 83 | Type string |
Dan Shi | 20ccd21 | 2019-08-27 10:37:24 -0700 | [diff] [blame] | 84 | Class string |
| 85 | Options []Option |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 86 | } |
| 87 | |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 88 | var _ Config = Object{} |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 89 | |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 90 | func (ob Object) Config() string { |
Dan Shi | 20ccd21 | 2019-08-27 10:37:24 -0700 | [diff] [blame] | 91 | var optionStrings []string |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 92 | for _, option := range ob.Options { |
Dan Shi | 20ccd21 | 2019-08-27 10:37:24 -0700 | [diff] [blame] | 93 | optionStrings = append(optionStrings, option.Config()) |
| 94 | } |
| 95 | var options string |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 96 | if len(ob.Options) == 0 { |
Dan Shi | 20ccd21 | 2019-08-27 10:37:24 -0700 | [diff] [blame] | 97 | options = "" |
| 98 | } else { |
| 99 | optionDelimiter := fmt.Sprintf("\\n%s%s", test_xml_indent, test_xml_indent) |
| 100 | options = optionDelimiter + strings.Join(optionStrings, optionDelimiter) |
| 101 | } |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 102 | if ob.Type == "target_preparer" { |
| 103 | return fmt.Sprintf(`<target_preparer class="%s">%s\n%s</target_preparer>`, ob.Class, options, test_xml_indent) |
| 104 | } else { |
| 105 | return fmt.Sprintf(`<object type="%s" class="%s">%s\n%s</object>`, ob.Type, ob.Class, options, test_xml_indent) |
| 106 | } |
| 107 | |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 108 | } |
| 109 | |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 110 | func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string, configs []Config, testInstallBase string) { |
| 111 | autogenTemplateWithNameAndOutputFile(ctx, ctx.ModuleName(), output, template, configs, "", testInstallBase) |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 112 | } |
| 113 | |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 114 | func autogenTemplateWithName(ctx android.ModuleContext, name string, output android.WritablePath, template string, configs []Config, testInstallBase string) { |
| 115 | autogenTemplateWithNameAndOutputFile(ctx, name, output, template, configs, "", testInstallBase) |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 116 | } |
| 117 | |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 118 | func autogenTemplateWithNameAndOutputFile(ctx android.ModuleContext, name string, output android.WritablePath, template string, configs []Config, outputFileName string, testInstallBase string) { |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 119 | var configStrings []string |
| 120 | for _, config := range configs { |
| 121 | configStrings = append(configStrings, config.Config()) |
Julien Desprez | eb7398e | 2019-02-28 08:45:28 -0800 | [diff] [blame] | 122 | } |
Dan Shi | 20ccd21 | 2019-08-27 10:37:24 -0700 | [diff] [blame] | 123 | extraConfigs := strings.Join(configStrings, fmt.Sprintf("\\n%s", test_xml_indent)) |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 124 | extraConfigs = proptools.NinjaAndShellEscape(extraConfigs) |
Julien Desprez | eb7398e | 2019-02-28 08:45:28 -0800 | [diff] [blame] | 125 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 126 | ctx.Build(pctx, android.BuildParams{ |
| 127 | Rule: autogenTestConfig, |
| 128 | Description: "test config", |
| 129 | Output: output, |
| 130 | Args: map[string]string{ |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 131 | "name": name, |
| 132 | "template": template, |
| 133 | "extraConfigs": extraConfigs, |
| 134 | "outputFileName": outputFileName, |
| 135 | "testInstallBase": testInstallBase, |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 136 | }, |
| 137 | }) |
| 138 | } |
| 139 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 140 | func AutoGenNativeTestConfig(ctx android.ModuleContext, testConfigProp *string, |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 141 | testConfigTemplateProp *string, testSuites []string, config []Config, autoGenConfig *bool, testInstallBase string) android.Path { |
| 142 | |
Lorenzo Colitti | e29c21e | 2020-02-14 18:27:56 +0900 | [diff] [blame] | 143 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 144 | if autogenPath != nil { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 145 | templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 146 | if templatePath.Valid() { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 147 | autogenTemplate(ctx, autogenPath, templatePath.String(), config, testInstallBase) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 148 | } else { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 149 | if ctx.Device() { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 150 | autogenTemplate(ctx, autogenPath, "${NativeTestConfigTemplate}", config, testInstallBase) |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 151 | } else { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 152 | autogenTemplate(ctx, autogenPath, "${NativeHostTestConfigTemplate}", config, testInstallBase) |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 153 | } |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 154 | } |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 155 | return autogenPath |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 156 | } |
| 157 | return path |
| 158 | } |
| 159 | |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 160 | func AutoGenShellTestConfig(ctx android.ModuleContext, testConfigProp *string, |
| 161 | testConfigTemplateProp *string, testSuites []string, config []Config, autoGenConfig *bool, outputFileName string) android.Path { |
| 162 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp) |
| 163 | if autogenPath != nil { |
| 164 | templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 165 | if templatePath.Valid() { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 166 | autogenTemplateWithNameAndOutputFile(ctx, ctx.ModuleName(), autogenPath, templatePath.String(), config, outputFileName, "") |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 167 | } else { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 168 | autogenTemplateWithNameAndOutputFile(ctx, ctx.ModuleName(), autogenPath, "${ShellTestConfigTemplate}", config, outputFileName, "") |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 169 | } |
| 170 | return autogenPath |
| 171 | } |
| 172 | return path |
| 173 | } |
| 174 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 175 | func AutoGenNativeBenchmarkTestConfig(ctx android.ModuleContext, testConfigProp *string, |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 176 | testConfigTemplateProp *string, testSuites []string, configs []Config, autoGenConfig *bool) android.Path { |
Lorenzo Colitti | e29c21e | 2020-02-14 18:27:56 +0900 | [diff] [blame] | 177 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 178 | if autogenPath != nil { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 179 | templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 180 | if templatePath.Valid() { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 181 | autogenTemplate(ctx, autogenPath, templatePath.String(), configs, "") |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 182 | } else { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 183 | autogenTemplate(ctx, autogenPath, "${NativeBenchmarkTestConfigTemplate}", configs, "") |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 184 | } |
| 185 | return autogenPath |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 186 | } |
| 187 | return path |
| 188 | } |
| 189 | |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 190 | func AutoGenJavaTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string, |
Julien Desprez | 70898c4 | 2020-11-19 09:43:45 -0800 | [diff] [blame] | 191 | testSuites []string, autoGenConfig *bool, unitTest *bool) android.Path { |
Lorenzo Colitti | e29c21e | 2020-02-14 18:27:56 +0900 | [diff] [blame] | 192 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 193 | if autogenPath != nil { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 194 | templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 195 | if templatePath.Valid() { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 196 | autogenTemplate(ctx, autogenPath, templatePath.String(), nil, "") |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 197 | } else { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 198 | if ctx.Device() { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 199 | autogenTemplate(ctx, autogenPath, "${JavaTestConfigTemplate}", nil, "") |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 200 | } else { |
Julien Desprez | 70898c4 | 2020-11-19 09:43:45 -0800 | [diff] [blame] | 201 | if Bool(unitTest) { |
| 202 | autogenTemplate(ctx, autogenPath, "${JavaHostUnitTestConfigTemplate}", nil, "") |
| 203 | } else { |
| 204 | autogenTemplate(ctx, autogenPath, "${JavaHostTestConfigTemplate}", nil, "") |
| 205 | } |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 206 | } |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 207 | } |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 208 | return autogenPath |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 209 | } |
| 210 | return path |
| 211 | } |
| 212 | |
yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 213 | func AutoGenPythonBinaryHostTestConfig(ctx android.ModuleContext, testConfigProp *string, |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 214 | testConfigTemplateProp *string, testSuites []string, autoGenConfig *bool) android.Path { |
yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 215 | |
Lorenzo Colitti | e29c21e | 2020-02-14 18:27:56 +0900 | [diff] [blame] | 216 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp) |
yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 217 | if autogenPath != nil { |
| 218 | templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 219 | if templatePath.Valid() { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 220 | autogenTemplate(ctx, autogenPath, templatePath.String(), nil, "") |
yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 221 | } else { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 222 | autogenTemplate(ctx, autogenPath, "${PythonBinaryHostTestConfigTemplate}", nil, "") |
yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 223 | } |
| 224 | return autogenPath |
| 225 | } |
| 226 | return path |
| 227 | } |
| 228 | |
Ivan Lozano | fc80fe7 | 2020-06-11 13:25:36 -0400 | [diff] [blame] | 229 | func AutoGenRustTestConfig(ctx android.ModuleContext, testConfigProp *string, |
| 230 | testConfigTemplateProp *string, testSuites []string, config []Config, autoGenConfig *bool) android.Path { |
Lorenzo Colitti | e29c21e | 2020-02-14 18:27:56 +0900 | [diff] [blame] | 231 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp) |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 232 | if autogenPath != nil { |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 233 | templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 234 | if templatePath.Valid() { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 235 | autogenTemplate(ctx, autogenPath, templatePath.String(), config, "") |
Ivan Lozano | fc80fe7 | 2020-06-11 13:25:36 -0400 | [diff] [blame] | 236 | } else { |
| 237 | if ctx.Device() { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 238 | autogenTemplate(ctx, autogenPath, "${RustDeviceTestConfigTemplate}", config, "") |
Ivan Lozano | fc80fe7 | 2020-06-11 13:25:36 -0400 | [diff] [blame] | 239 | } else { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 240 | autogenTemplate(ctx, autogenPath, "${RustHostTestConfigTemplate}", config, "") |
Ivan Lozano | fc80fe7 | 2020-06-11 13:25:36 -0400 | [diff] [blame] | 241 | } |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 242 | } |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 243 | return autogenPath |
| 244 | } |
| 245 | return path |
| 246 | } |
| 247 | |
Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 248 | func AutoGenRobolectricTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string, |
| 249 | testSuites []string, autoGenConfig *bool) android.Path { |
| 250 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp) |
| 251 | if autogenPath != nil { |
| 252 | templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 253 | if templatePath.Valid() { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 254 | autogenTemplate(ctx, autogenPath, templatePath.String(), nil, "") |
Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 255 | } else { |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 256 | autogenTemplate(ctx, autogenPath, "${RobolectricTestConfigTemplate}", nil, "") |
Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 257 | } |
| 258 | return autogenPath |
| 259 | } |
| 260 | return path |
| 261 | } |
| 262 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 263 | var autogenInstrumentationTest = pctx.StaticRule("autogenInstrumentationTest", blueprint.RuleParams{ |
easoncylee | 5bcff5d | 2020-04-30 14:57:06 +0800 | [diff] [blame] | 264 | Command: "${AutoGenTestConfigScript} $out $in ${EmptyTestConfig} $template ${extraConfigs}", |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 265 | CommandDeps: []string{ |
| 266 | "${AutoGenTestConfigScript}", |
| 267 | "${EmptyTestConfig}", |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 268 | "$template", |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 269 | }, |
easoncylee | 5bcff5d | 2020-04-30 14:57:06 +0800 | [diff] [blame] | 270 | }, "name", "template", "extraConfigs") |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 271 | |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 272 | func AutoGenInstrumentationTestConfig(ctx android.ModuleContext, testConfigProp *string, |
easoncylee | 5bcff5d | 2020-04-30 14:57:06 +0800 | [diff] [blame] | 273 | testConfigTemplateProp *string, manifest android.Path, testSuites []string, autoGenConfig *bool, configs []Config) android.Path { |
Lorenzo Colitti | e29c21e | 2020-02-14 18:27:56 +0900 | [diff] [blame] | 274 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp) |
easoncylee | 5bcff5d | 2020-04-30 14:57:06 +0800 | [diff] [blame] | 275 | var configStrings []string |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 276 | if autogenPath != nil { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 277 | template := "${InstrumentationTestConfigTemplate}" |
| 278 | moduleTemplate := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 279 | if moduleTemplate.Valid() { |
| 280 | template = moduleTemplate.String() |
| 281 | } |
easoncylee | 5bcff5d | 2020-04-30 14:57:06 +0800 | [diff] [blame] | 282 | for _, config := range configs { |
| 283 | configStrings = append(configStrings, config.Config()) |
| 284 | } |
| 285 | extraConfigs := strings.Join(configStrings, fmt.Sprintf("\\n%s", test_xml_indent)) |
| 286 | extraConfigs = fmt.Sprintf("--extra-configs '%s'", extraConfigs) |
| 287 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 288 | ctx.Build(pctx, android.BuildParams{ |
| 289 | Rule: autogenInstrumentationTest, |
| 290 | Description: "test config", |
| 291 | Input: manifest, |
| 292 | Output: autogenPath, |
| 293 | Args: map[string]string{ |
easoncylee | 5bcff5d | 2020-04-30 14:57:06 +0800 | [diff] [blame] | 294 | "name": ctx.ModuleName(), |
| 295 | "template": template, |
| 296 | "extraConfigs": extraConfigs, |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 297 | }, |
| 298 | }) |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 299 | return autogenPath |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 300 | } |
| 301 | return path |
| 302 | } |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 303 | |
| 304 | var Bool = proptools.Bool |
| 305 | var BoolDefault = proptools.BoolDefault |