OLD | NEW |
1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """ | 5 """ |
6 TestGyp.py: a testing framework for GYP integration tests. | 6 TestGyp.py: a testing framework for GYP integration tests. |
7 """ | 7 """ |
8 | 8 |
9 import collections | 9 import collections |
10 from contextlib import contextmanager | 10 from contextlib import contextmanager |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 # TODO: --depth=. works around Chromium-specific tree climbing. | 282 # TODO: --depth=. works around Chromium-specific tree climbing. |
283 depth = kw.pop('depth', '.') | 283 depth = kw.pop('depth', '.') |
284 run_args = ['--depth='+depth] | 284 run_args = ['--depth='+depth] |
285 run_args.extend(['--format='+f for f in self.formats]); | 285 run_args.extend(['--format='+f for f in self.formats]); |
286 run_args.append(gyp_file) | 286 run_args.append(gyp_file) |
287 if self.no_parallel: | 287 if self.no_parallel: |
288 run_args += ['--no-parallel'] | 288 run_args += ['--no-parallel'] |
289 # TODO: if extra_args contains a '--build' flag | 289 # TODO: if extra_args contains a '--build' flag |
290 # we really want that to only apply to the last format (self.format). | 290 # we really want that to only apply to the last format (self.format). |
291 run_args.extend(self.extra_args) | 291 run_args.extend(self.extra_args) |
| 292 # Default xcode_ninja_target_pattern to ^.*$ to fix xcode-ninja tests |
| 293 xcode_ninja_target_pattern = kw.pop('xcode_ninja_target_pattern', '.*') |
| 294 run_args.extend( |
| 295 ['-G', 'xcode_ninja_target_pattern=%s' % xcode_ninja_target_pattern]) |
292 run_args.extend(args) | 296 run_args.extend(args) |
293 return self.run(program=self.gyp, arguments=run_args, **kw) | 297 return self.run(program=self.gyp, arguments=run_args, **kw) |
294 | 298 |
295 def run(self, *args, **kw): | 299 def run(self, *args, **kw): |
296 """ | 300 """ |
297 Executes a program by calling the superclass .run() method. | 301 Executes a program by calling the superclass .run() method. |
298 | 302 |
299 This exists to provide a common place to filter out keyword | 303 This exists to provide a common place to filter out keyword |
300 arguments implemented in this layer, without having to update | 304 arguments implemented in this layer, without having to update |
301 the tool-specific subclasses or clutter the tests themselves | 305 the tool-specific subclasses or clutter the tests themselves |
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 result = [] | 1322 result = [] |
1319 chdir = kw.get('chdir') | 1323 chdir = kw.get('chdir') |
1320 if chdir: | 1324 if chdir: |
1321 result.append(chdir) | 1325 result.append(chdir) |
1322 configuration = self.configuration_dirname() | 1326 configuration = self.configuration_dirname() |
1323 result.extend(['build', configuration]) | 1327 result.extend(['build', configuration]) |
1324 result.append(self.built_file_basename(name, type, **kw)) | 1328 result.append(self.built_file_basename(name, type, **kw)) |
1325 return self.workpath(*result) | 1329 return self.workpath(*result) |
1326 | 1330 |
1327 | 1331 |
| 1332 class TestGypXcodeNinja(TestGypXcode): |
| 1333 """ |
| 1334 Subclass for testing the GYP Xcode Ninja generator. |
| 1335 """ |
| 1336 format = 'xcode-ninja' |
| 1337 |
| 1338 def initialize_build_tool(self): |
| 1339 super(TestGypXcodeNinja, self).initialize_build_tool() |
| 1340 # When using '--build', make sure ninja is first in the format list. |
| 1341 self.formats.insert(0, 'ninja') |
| 1342 |
| 1343 def build(self, gyp_file, target=None, **kw): |
| 1344 """ |
| 1345 Runs an xcodebuild using the .xcodeproj generated from the specified |
| 1346 gyp_file. |
| 1347 """ |
| 1348 build_config = self.configuration |
| 1349 if build_config and build_config.endswith(('-iphoneos', |
| 1350 '-iphonesimulator')): |
| 1351 build_config, sdk = self.configuration.split('-') |
| 1352 kw['arguments'] = kw.get('arguments', []) + ['-sdk', sdk] |
| 1353 |
| 1354 with self._build_configuration(build_config): |
| 1355 return super(TestGypXcodeNinja, self).build( |
| 1356 gyp_file.replace('.gyp', '.ninja.gyp'), target, **kw) |
| 1357 |
| 1358 @contextmanager |
| 1359 def _build_configuration(self, build_config): |
| 1360 config = self.configuration |
| 1361 self.configuration = build_config |
| 1362 try: |
| 1363 yield |
| 1364 finally: |
| 1365 self.configuration = config |
| 1366 |
| 1367 def built_file_path(self, name, type=None, **kw): |
| 1368 result = [] |
| 1369 chdir = kw.get('chdir') |
| 1370 if chdir: |
| 1371 result.append(chdir) |
| 1372 result.append('out') |
| 1373 result.append(self.configuration_dirname()) |
| 1374 subdir = kw.get('subdir') |
| 1375 if subdir and type != self.SHARED_LIB: |
| 1376 result.append(subdir) |
| 1377 result.append(self.built_file_basename(name, type, **kw)) |
| 1378 return self.workpath(*result) |
| 1379 |
| 1380 def up_to_date(self, gyp_file, target=None, **kw): |
| 1381 result = self.build(gyp_file, target, **kw) |
| 1382 if not result: |
| 1383 stdout = self.stdout() |
| 1384 if 'ninja: no work to do' not in stdout: |
| 1385 self.report_not_up_to_date() |
| 1386 self.fail_test() |
| 1387 return result |
| 1388 |
| 1389 def run_built_executable(self, name, *args, **kw): |
| 1390 """ |
| 1391 Runs an executable built by xcodebuild + ninja. |
| 1392 """ |
| 1393 configuration = self.configuration_dirname() |
| 1394 os.environ['DYLD_LIBRARY_PATH'] = os.path.join('out', configuration) |
| 1395 # Enclosing the name in a list avoids prepending the original dir. |
| 1396 program = [self.built_file_path(name, type=self.EXECUTABLE, **kw)] |
| 1397 return self.run(program=program, *args, **kw) |
| 1398 |
| 1399 |
1328 format_class_list = [ | 1400 format_class_list = [ |
1329 TestGypGypd, | 1401 TestGypGypd, |
1330 TestGypAndroid, | 1402 TestGypAndroid, |
1331 TestGypCMake, | 1403 TestGypCMake, |
1332 TestGypMake, | 1404 TestGypMake, |
1333 TestGypMSVS, | 1405 TestGypMSVS, |
1334 TestGypMSVSNinja, | 1406 TestGypMSVSNinja, |
1335 TestGypNinja, | 1407 TestGypNinja, |
1336 TestGypXcode, | 1408 TestGypXcode, |
| 1409 TestGypXcodeNinja, |
1337 ] | 1410 ] |
1338 | 1411 |
1339 def TestGyp(*args, **kw): | 1412 def TestGyp(*args, **kw): |
1340 """ | 1413 """ |
1341 Returns an appropriate TestGyp* instance for a specified GYP format. | 1414 Returns an appropriate TestGyp* instance for a specified GYP format. |
1342 """ | 1415 """ |
1343 format = kw.pop('format', os.environ.get('TESTGYP_FORMAT')) | 1416 format = kw.pop('format', os.environ.get('TESTGYP_FORMAT')) |
1344 for format_class in format_class_list: | 1417 for format_class in format_class_list: |
1345 if format == format_class.format: | 1418 if format == format_class.format: |
1346 return format_class(*args, **kw) | 1419 return format_class(*args, **kw) |
1347 raise Exception, "unknown format %r" % format | 1420 raise Exception, "unknown format %r" % format |
OLD | NEW |