| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1 | // Copyright 2017 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 python | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "errors" | 
|  | 19 | "fmt" | 
|  | 20 | "io/ioutil" | 
|  | 21 | "os" | 
|  | 22 | "path/filepath" | 
|  | 23 | "reflect" | 
|  | 24 | "sort" | 
|  | 25 | "strings" | 
|  | 26 | "testing" | 
|  | 27 |  | 
|  | 28 | "android/soong/android" | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 29 | ) | 
|  | 30 |  | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 31 | type pyModule struct { | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 32 | name          string | 
|  | 33 | actualVersion string | 
|  | 34 | pyRunfiles    []string | 
|  | 35 | srcsZip       string | 
|  | 36 | depsSrcsZips  []string | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 37 | } | 
|  | 38 |  | 
|  | 39 | var ( | 
|  | 40 | buildNamePrefix          = "soong_python_test" | 
|  | 41 | moduleVariantErrTemplate = "%s: module %q variant %q: " | 
|  | 42 | pkgPathErrTemplate       = moduleVariantErrTemplate + | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 43 | "pkg_path: %q must be a relative path contained in par file." | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 44 | badIdentifierErrTemplate = moduleVariantErrTemplate + | 
|  | 45 | "srcs: the path %q contains invalid token %q." | 
|  | 46 | dupRunfileErrTemplate = moduleVariantErrTemplate + | 
|  | 47 | "found two files to be placed at the same runfiles location %q." + | 
|  | 48 | " First file: in module %s at path %q." + | 
|  | 49 | " Second file: in module %s at path %q." | 
|  | 50 | noSrcFileErr      = moduleVariantErrTemplate + "doesn't have any source files!" | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 51 | badSrcFileExtErr  = moduleVariantErrTemplate + "srcs: found non (.py|.proto) file: %q!" | 
|  | 52 | badDataFileExtErr = moduleVariantErrTemplate + "data: found (.py|.proto) file: %q!" | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 53 | bpFile            = "Blueprints" | 
|  | 54 |  | 
|  | 55 | data = []struct { | 
|  | 56 | desc      string | 
|  | 57 | mockFiles map[string][]byte | 
|  | 58 |  | 
|  | 59 | errors           []string | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 60 | expectedBinaries []pyModule | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 61 | }{ | 
|  | 62 | { | 
|  | 63 | desc: "module without any src files", | 
|  | 64 | mockFiles: map[string][]byte{ | 
|  | 65 | bpFile: []byte(`subdirs = ["dir"]`), | 
|  | 66 | filepath.Join("dir", bpFile): []byte( | 
|  | 67 | `python_library_host { | 
|  | 68 | name: "lib1", | 
|  | 69 | }`, | 
|  | 70 | ), | 
|  | 71 | }, | 
|  | 72 | errors: []string{ | 
|  | 73 | fmt.Sprintf(noSrcFileErr, | 
|  | 74 | "dir/Blueprints:1:1", "lib1", "PY3"), | 
|  | 75 | }, | 
|  | 76 | }, | 
|  | 77 | { | 
|  | 78 | desc: "module with bad src file ext", | 
|  | 79 | mockFiles: map[string][]byte{ | 
|  | 80 | bpFile: []byte(`subdirs = ["dir"]`), | 
|  | 81 | filepath.Join("dir", bpFile): []byte( | 
|  | 82 | `python_library_host { | 
|  | 83 | name: "lib1", | 
|  | 84 | srcs: [ | 
|  | 85 | "file1.exe", | 
|  | 86 | ], | 
|  | 87 | }`, | 
|  | 88 | ), | 
|  | 89 | "dir/file1.exe": nil, | 
|  | 90 | }, | 
|  | 91 | errors: []string{ | 
|  | 92 | fmt.Sprintf(badSrcFileExtErr, | 
|  | 93 | "dir/Blueprints:3:11", "lib1", "PY3", "dir/file1.exe"), | 
|  | 94 | }, | 
|  | 95 | }, | 
|  | 96 | { | 
|  | 97 | desc: "module with bad data file ext", | 
|  | 98 | mockFiles: map[string][]byte{ | 
|  | 99 | bpFile: []byte(`subdirs = ["dir"]`), | 
|  | 100 | filepath.Join("dir", bpFile): []byte( | 
|  | 101 | `python_library_host { | 
|  | 102 | name: "lib1", | 
|  | 103 | srcs: [ | 
|  | 104 | "file1.py", | 
|  | 105 | ], | 
|  | 106 | data: [ | 
|  | 107 | "file2.py", | 
|  | 108 | ], | 
|  | 109 | }`, | 
|  | 110 | ), | 
|  | 111 | "dir/file1.py": nil, | 
|  | 112 | "dir/file2.py": nil, | 
|  | 113 | }, | 
|  | 114 | errors: []string{ | 
|  | 115 | fmt.Sprintf(badDataFileExtErr, | 
|  | 116 | "dir/Blueprints:6:11", "lib1", "PY3", "dir/file2.py"), | 
|  | 117 | }, | 
|  | 118 | }, | 
|  | 119 | { | 
|  | 120 | desc: "module with bad pkg_path format", | 
|  | 121 | mockFiles: map[string][]byte{ | 
|  | 122 | bpFile: []byte(`subdirs = ["dir"]`), | 
|  | 123 | filepath.Join("dir", bpFile): []byte( | 
|  | 124 | `python_library_host { | 
|  | 125 | name: "lib1", | 
|  | 126 | pkg_path: "a/c/../../", | 
|  | 127 | srcs: [ | 
|  | 128 | "file1.py", | 
|  | 129 | ], | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | python_library_host { | 
|  | 133 | name: "lib2", | 
|  | 134 | pkg_path: "a/c/../../../", | 
|  | 135 | srcs: [ | 
|  | 136 | "file1.py", | 
|  | 137 | ], | 
|  | 138 | } | 
|  | 139 |  | 
|  | 140 | python_library_host { | 
|  | 141 | name: "lib3", | 
|  | 142 | pkg_path: "/a/c/../../", | 
|  | 143 | srcs: [ | 
|  | 144 | "file1.py", | 
|  | 145 | ], | 
|  | 146 | }`, | 
|  | 147 | ), | 
|  | 148 | "dir/file1.py": nil, | 
|  | 149 | }, | 
|  | 150 | errors: []string{ | 
|  | 151 | fmt.Sprintf(pkgPathErrTemplate, | 
|  | 152 | "dir/Blueprints:11:15", "lib2", "PY3", "a/c/../../../"), | 
|  | 153 | fmt.Sprintf(pkgPathErrTemplate, | 
|  | 154 | "dir/Blueprints:19:15", "lib3", "PY3", "/a/c/../../"), | 
|  | 155 | }, | 
|  | 156 | }, | 
|  | 157 | { | 
|  | 158 | desc: "module with bad runfile src path format", | 
|  | 159 | mockFiles: map[string][]byte{ | 
|  | 160 | bpFile: []byte(`subdirs = ["dir"]`), | 
|  | 161 | filepath.Join("dir", bpFile): []byte( | 
|  | 162 | `python_library_host { | 
|  | 163 | name: "lib1", | 
|  | 164 | pkg_path: "a/b/c/", | 
|  | 165 | srcs: [ | 
|  | 166 | ".file1.py", | 
|  | 167 | "123/file1.py", | 
|  | 168 | "-e/f/file1.py", | 
|  | 169 | ], | 
|  | 170 | }`, | 
|  | 171 | ), | 
|  | 172 | "dir/.file1.py":     nil, | 
|  | 173 | "dir/123/file1.py":  nil, | 
|  | 174 | "dir/-e/f/file1.py": nil, | 
|  | 175 | }, | 
|  | 176 | errors: []string{ | 
|  | 177 | fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11", | 
|  | 178 | "lib1", "PY3", "runfiles/a/b/c/-e/f/file1.py", "-e"), | 
|  | 179 | fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11", | 
|  | 180 | "lib1", "PY3", "runfiles/a/b/c/.file1.py", ".file1"), | 
|  | 181 | fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11", | 
|  | 182 | "lib1", "PY3", "runfiles/a/b/c/123/file1.py", "123"), | 
|  | 183 | }, | 
|  | 184 | }, | 
|  | 185 | { | 
|  | 186 | desc: "module with duplicate runfile path", | 
|  | 187 | mockFiles: map[string][]byte{ | 
|  | 188 | bpFile: []byte(`subdirs = ["dir"]`), | 
|  | 189 | filepath.Join("dir", bpFile): []byte( | 
|  | 190 | `python_library_host { | 
|  | 191 | name: "lib1", | 
|  | 192 | pkg_path: "a/b/", | 
|  | 193 | srcs: [ | 
|  | 194 | "c/file1.py", | 
|  | 195 | ], | 
|  | 196 | } | 
|  | 197 |  | 
|  | 198 | python_library_host { | 
|  | 199 | name: "lib2", | 
|  | 200 | pkg_path: "a/b/c/", | 
|  | 201 | srcs: [ | 
|  | 202 | "file1.py", | 
|  | 203 | ], | 
|  | 204 | libs: [ | 
|  | 205 | "lib1", | 
|  | 206 | ], | 
|  | 207 | } | 
|  | 208 | `, | 
|  | 209 | ), | 
|  | 210 | "dir/c/file1.py": nil, | 
|  | 211 | "dir/file1.py":   nil, | 
|  | 212 | }, | 
|  | 213 | errors: []string{ | 
|  | 214 | fmt.Sprintf(dupRunfileErrTemplate, "dir/Blueprints:9:6", | 
|  | 215 | "lib2", "PY3", "runfiles/a/b/c/file1.py", "lib2", "dir/file1.py", | 
|  | 216 | "lib1", "dir/c/file1.py"), | 
|  | 217 | }, | 
|  | 218 | }, | 
|  | 219 | { | 
|  | 220 | desc: "module for testing dependencies", | 
|  | 221 | mockFiles: map[string][]byte{ | 
|  | 222 | bpFile: []byte(`subdirs = ["dir"]`), | 
|  | 223 | filepath.Join("dir", bpFile): []byte( | 
| Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 224 | `python_defaults { | 
|  | 225 | name: "default_lib", | 
|  | 226 | srcs: [ | 
|  | 227 | "default.py", | 
|  | 228 | ], | 
|  | 229 | version: { | 
|  | 230 | py2: { | 
|  | 231 | enabled: true, | 
|  | 232 | srcs: [ | 
|  | 233 | "default_py2.py", | 
|  | 234 | ], | 
|  | 235 | }, | 
|  | 236 | py3: { | 
|  | 237 | enabled: false, | 
|  | 238 | srcs: [ | 
|  | 239 | "default_py3.py", | 
|  | 240 | ], | 
|  | 241 | }, | 
|  | 242 | }, | 
|  | 243 | } | 
|  | 244 |  | 
|  | 245 | python_library_host { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 246 | name: "lib5", | 
|  | 247 | pkg_path: "a/b/", | 
|  | 248 | srcs: [ | 
|  | 249 | "file1.py", | 
|  | 250 | ], | 
|  | 251 | version: { | 
|  | 252 | py2: { | 
|  | 253 | enabled: true, | 
|  | 254 | }, | 
|  | 255 | py3: { | 
|  | 256 | enabled: true, | 
|  | 257 | }, | 
|  | 258 | }, | 
|  | 259 | } | 
|  | 260 |  | 
|  | 261 | python_library_host { | 
|  | 262 | name: "lib6", | 
|  | 263 | pkg_path: "c/d/", | 
|  | 264 | srcs: [ | 
|  | 265 | "file2.py", | 
|  | 266 | ], | 
|  | 267 | libs: [ | 
|  | 268 | "lib5", | 
|  | 269 | ], | 
|  | 270 | } | 
|  | 271 |  | 
|  | 272 | python_binary_host { | 
|  | 273 | name: "bin", | 
| Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 274 | defaults: ["default_lib"], | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 275 | pkg_path: "e/", | 
|  | 276 | srcs: [ | 
|  | 277 | "bin.py", | 
|  | 278 | ], | 
|  | 279 | libs: [ | 
|  | 280 | "lib5", | 
|  | 281 | ], | 
|  | 282 | version: { | 
|  | 283 | py3: { | 
|  | 284 | enabled: true, | 
|  | 285 | srcs: [ | 
|  | 286 | "file4.py", | 
|  | 287 | ], | 
|  | 288 | libs: [ | 
|  | 289 | "lib6", | 
|  | 290 | ], | 
|  | 291 | }, | 
|  | 292 | }, | 
|  | 293 | }`, | 
|  | 294 | ), | 
| Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 295 | filepath.Join("dir", "default.py"):     nil, | 
|  | 296 | filepath.Join("dir", "default_py2.py"): nil, | 
|  | 297 | filepath.Join("dir", "default_py3.py"): nil, | 
|  | 298 | filepath.Join("dir", "file1.py"):       nil, | 
|  | 299 | filepath.Join("dir", "file2.py"):       nil, | 
|  | 300 | filepath.Join("dir", "bin.py"):         nil, | 
|  | 301 | filepath.Join("dir", "file4.py"):       nil, | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 302 | stubTemplateHost: []byte(`PYTHON_BINARY = '%interpreter%' | 
|  | 303 | MAIN_FILE = '%main%'`), | 
|  | 304 | }, | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 305 | expectedBinaries: []pyModule{ | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 306 | { | 
|  | 307 | name:          "bin", | 
|  | 308 | actualVersion: "PY3", | 
|  | 309 | pyRunfiles: []string{ | 
| Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 310 | "runfiles/e/default.py", | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 311 | "runfiles/e/bin.py", | 
| Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 312 | "runfiles/e/default_py3.py", | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 313 | "runfiles/e/file4.py", | 
|  | 314 | }, | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 315 | srcsZip: "@prefix@/.intermediates/dir/bin/PY3/bin.py.srcszip", | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 316 | depsSrcsZips: []string{ | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 317 | "@prefix@/.intermediates/dir/lib5/PY3/lib5.py.srcszip", | 
|  | 318 | "@prefix@/.intermediates/dir/lib6/PY3/lib6.py.srcszip", | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 319 | }, | 
|  | 320 | }, | 
|  | 321 | }, | 
|  | 322 | }, | 
|  | 323 | } | 
|  | 324 | ) | 
|  | 325 |  | 
|  | 326 | func TestPythonModule(t *testing.T) { | 
|  | 327 | config, buildDir := setupBuildEnv(t) | 
| Nan Zhang | aac67d3 | 2017-06-12 10:49:42 -0700 | [diff] [blame] | 328 | defer tearDownBuildEnv(buildDir) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 329 | for _, d := range data { | 
|  | 330 | t.Run(d.desc, func(t *testing.T) { | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 331 | ctx := android.NewTestContext() | 
|  | 332 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { | 
|  | 333 | ctx.BottomUp("version_split", versionSplitMutator()).Parallel() | 
|  | 334 | }) | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 335 | ctx.RegisterModuleType("python_library_host", | 
|  | 336 | android.ModuleFactoryAdaptor(PythonLibraryHostFactory)) | 
|  | 337 | ctx.RegisterModuleType("python_binary_host", | 
|  | 338 | android.ModuleFactoryAdaptor(PythonBinaryHostFactory)) | 
| Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 339 | ctx.RegisterModuleType("python_defaults", | 
|  | 340 | android.ModuleFactoryAdaptor(defaultsFactory)) | 
|  | 341 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 342 | ctx.Register() | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 343 | ctx.MockFileSystem(d.mockFiles) | 
|  | 344 | _, testErrs := ctx.ParseBlueprintsFiles(bpFile) | 
| Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 345 | android.FailIfErrored(t, testErrs) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 346 | _, actErrs := ctx.PrepareBuildActions(config) | 
|  | 347 | if len(actErrs) > 0 { | 
|  | 348 | testErrs = append(testErrs, expectErrors(t, actErrs, d.errors)...) | 
|  | 349 | } else { | 
|  | 350 | for _, e := range d.expectedBinaries { | 
|  | 351 | testErrs = append(testErrs, | 
|  | 352 | expectModule(t, ctx, buildDir, e.name, | 
|  | 353 | e.actualVersion, | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 354 | e.srcsZip, | 
|  | 355 | e.pyRunfiles, | 
|  | 356 | e.depsSrcsZips)...) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 357 | } | 
|  | 358 | } | 
| Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 359 | android.FailIfErrored(t, testErrs) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 360 | }) | 
|  | 361 | } | 
|  | 362 | } | 
|  | 363 |  | 
|  | 364 | func expectErrors(t *testing.T, actErrs []error, expErrs []string) (testErrs []error) { | 
|  | 365 | actErrStrs := []string{} | 
|  | 366 | for _, v := range actErrs { | 
|  | 367 | actErrStrs = append(actErrStrs, v.Error()) | 
|  | 368 | } | 
|  | 369 | sort.Strings(actErrStrs) | 
|  | 370 | if len(actErrStrs) != len(expErrs) { | 
|  | 371 | t.Errorf("got (%d) errors, expected (%d) errors!", len(actErrStrs), len(expErrs)) | 
|  | 372 | for _, v := range actErrStrs { | 
|  | 373 | testErrs = append(testErrs, errors.New(v)) | 
|  | 374 | } | 
|  | 375 | } else { | 
|  | 376 | sort.Strings(expErrs) | 
|  | 377 | for i, v := range actErrStrs { | 
|  | 378 | if v != expErrs[i] { | 
|  | 379 | testErrs = append(testErrs, errors.New(v)) | 
|  | 380 | } | 
|  | 381 | } | 
|  | 382 | } | 
|  | 383 |  | 
|  | 384 | return | 
|  | 385 | } | 
|  | 386 |  | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 387 | func expectModule(t *testing.T, ctx *android.TestContext, buildDir, name, variant, expectedSrcsZip string, | 
|  | 388 | expectedPyRunfiles, expectedDepsSrcsZips []string) (testErrs []error) { | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 389 | module := ctx.ModuleForTests(name, variant) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 390 |  | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 391 | base, baseOk := module.Module().(*Module) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 392 | if !baseOk { | 
|  | 393 | t.Fatalf("%s is not Python module!", name) | 
|  | 394 | } | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 395 |  | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 396 | actualPyRunfiles := []string{} | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 397 | for _, path := range base.srcsPathMappings { | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 398 | actualPyRunfiles = append(actualPyRunfiles, path.dest) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 399 | } | 
|  | 400 |  | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 401 | if !reflect.DeepEqual(actualPyRunfiles, expectedPyRunfiles) { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 402 | testErrs = append(testErrs, errors.New(fmt.Sprintf( | 
|  | 403 | `binary "%s" variant "%s" has unexpected pyRunfiles: %q!`, | 
|  | 404 | base.Name(), | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 405 | base.properties.Actual_version, | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 406 | actualPyRunfiles))) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 407 | } | 
|  | 408 |  | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 409 | if base.srcsZip.String() != strings.Replace(expectedSrcsZip, "@prefix@", buildDir, 1) { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 410 | testErrs = append(testErrs, errors.New(fmt.Sprintf( | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 411 | `binary "%s" variant "%s" has unexpected srcsZip: %q!`, | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 412 | base.Name(), | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 413 | base.properties.Actual_version, | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 414 | base.srcsZip))) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 415 | } | 
|  | 416 |  | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 417 | for i, _ := range expectedDepsSrcsZips { | 
|  | 418 | expectedDepsSrcsZips[i] = strings.Replace(expectedDepsSrcsZips[i], "@prefix@", buildDir, 1) | 
|  | 419 | } | 
|  | 420 | if !reflect.DeepEqual(base.depsSrcsZips.Strings(), expectedDepsSrcsZips) { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 421 | testErrs = append(testErrs, errors.New(fmt.Sprintf( | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 422 | `binary "%s" variant "%s" has unexpected depsSrcsZips: %q!`, | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 423 | base.Name(), | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 424 | base.properties.Actual_version, | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 425 | base.depsSrcsZips))) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 426 | } | 
|  | 427 |  | 
|  | 428 | return | 
|  | 429 | } | 
|  | 430 |  | 
|  | 431 | func setupBuildEnv(t *testing.T) (config android.Config, buildDir string) { | 
|  | 432 | buildDir, err := ioutil.TempDir("", buildNamePrefix) | 
|  | 433 | if err != nil { | 
|  | 434 | t.Fatal(err) | 
|  | 435 | } | 
|  | 436 |  | 
| Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 437 | config = android.TestConfig(buildDir, nil) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 438 |  | 
|  | 439 | return | 
|  | 440 | } | 
|  | 441 |  | 
| Nan Zhang | aac67d3 | 2017-06-12 10:49:42 -0700 | [diff] [blame] | 442 | func tearDownBuildEnv(buildDir string) { | 
|  | 443 | os.RemoveAll(buildDir) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 444 | } |