OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 |
| 3 # Copyright (c) 2014 Google Inc. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """ |
| 8 Verifies 'AR' in make_global_settings. |
| 9 """ |
| 10 |
| 11 import os |
| 12 import sys |
| 13 import TestGyp |
| 14 |
| 15 def resolve_path(test, path): |
| 16 if path is None: |
| 17 return None |
| 18 elif test.format == 'make': |
| 19 return '$(abspath %s)' % path |
| 20 elif test.format == 'ninja': |
| 21 return os.path.join('..', '..', path) |
| 22 else: |
| 23 test.fail_test() |
| 24 |
| 25 |
| 26 def verify_ar_target(test, ar=None, rel_path=False): |
| 27 if rel_path: |
| 28 ar_expected = resolve_path(test, ar) |
| 29 else: |
| 30 ar_expected = ar |
| 31 # Resolve default values |
| 32 if ar_expected is None: |
| 33 if test.format == 'make': |
| 34 # Make generator hasn't set the default value for AR. |
| 35 # You can remove the following assertion as long as it doesn't |
| 36 # break existing projects. |
| 37 test.must_not_contain('Makefile', 'AR ?= ') |
| 38 return |
| 39 elif test.format == 'ninja': |
| 40 if sys.platform == 'win32': |
| 41 ar_expected = 'lib.exe' |
| 42 else: |
| 43 ar_expected = 'ar' |
| 44 if test.format == 'make': |
| 45 test.must_contain('Makefile', 'AR ?= %s' % ar_expected) |
| 46 elif test.format == 'ninja': |
| 47 test.must_contain('out/Default/build.ninja', 'ar = %s' % ar_expected) |
| 48 else: |
| 49 test.fail_test() |
| 50 |
| 51 |
| 52 def verify_ar_host(test, ar=None, rel_path=False): |
| 53 if rel_path: |
| 54 ar_expected = resolve_path(test, ar) |
| 55 else: |
| 56 ar_expected = ar |
| 57 # Resolve default values |
| 58 if ar_expected is None: |
| 59 if test.format == 'make': |
| 60 ar_expected = '$(AR)' |
| 61 elif test.format == 'ninja': |
| 62 if sys.platform == 'win32': |
| 63 # TODO(yukawa): Make sure if this is an expected result or not. |
| 64 ar_expected = 'ar' |
| 65 else: |
| 66 ar_expected = '$ar' |
| 67 if test.format == 'make': |
| 68 test.must_contain('Makefile', 'AR.host ?= %s' % ar_expected) |
| 69 elif test.format == 'ninja': |
| 70 test.must_contain('out/Default/build.ninja', 'ar_host = %s' % ar_expected) |
| 71 else: |
| 72 test.fail_test() |
| 73 |
| 74 |
| 75 test_format = ['ninja'] |
| 76 if sys.platform in ('linux2', 'darwin'): |
| 77 test_format += ['make'] |
| 78 |
| 79 test = TestGyp.TestGyp(formats=test_format) |
| 80 |
| 81 # Check default values |
| 82 test.run_gyp('make_global_settings_ar.gyp') |
| 83 verify_ar_target(test) |
| 84 |
| 85 |
| 86 # Test 'AR' in 'make_global_settings'. |
| 87 test.run_gyp('make_global_settings_ar.gyp', '-Dcustom_ar_target=my_ar') |
| 88 # TODO(yukawa): Support 'AR' in Ninja generator |
| 89 if test.format == 'make': |
| 90 verify_ar_target(test, ar='my_ar', rel_path=True) |
| 91 |
| 92 |
| 93 # Test 'AR'/'AR.host' in 'make_global_settings'. |
| 94 test.run_gyp('make_global_settings_ar.gyp', |
| 95 '-Dcustom_ar_target=my_ar_target1', |
| 96 '-Dcustom_ar_host=my_ar_host1') |
| 97 # TODO(yukawa): Support 'AR'/'AR.host' in Ninja generator |
| 98 if test.format == 'make': |
| 99 verify_ar_target(test, ar='my_ar_target1', rel_path=True) |
| 100 verify_ar_host(test, ar='my_ar_host1', rel_path=True) |
| 101 |
| 102 |
| 103 # Test $AR and $AR_host environment variables. |
| 104 try: |
| 105 os.environ['AR'] = 'my_ar_target2' |
| 106 os.environ['AR_host'] = 'my_ar_host2' |
| 107 test.run_gyp('make_global_settings_ar.gyp') |
| 108 finally: |
| 109 del os.environ['AR'] |
| 110 del os.environ['AR_host'] |
| 111 # Ninja generator resolves $AR in gyp phase. Make generator doesn't. |
| 112 if test.format == 'ninja': |
| 113 if sys.platform == 'win32': |
| 114 # TODO(yukawa): Make sure if this is an expected result or not. |
| 115 verify_ar_target(test, ar='lib.exe', rel_path=False) |
| 116 else: |
| 117 verify_ar_target(test, ar='my_ar_target2', rel_path=False) |
| 118 verify_ar_host(test, ar='my_ar_host2', rel_path=False) |
| 119 |
| 120 |
| 121 # Test 'AR' in 'make_global_settings' with $AR_host environment variable. |
| 122 try: |
| 123 os.environ['AR_host'] = 'my_ar_host3' |
| 124 test.run_gyp('make_global_settings_ar.gyp', |
| 125 '-Dcustom_ar_target=my_ar_target3') |
| 126 finally: |
| 127 del os.environ['AR_host'] |
| 128 # TODO(yukawa): Support 'AR' in Ninja generator |
| 129 if test.format == 'make': |
| 130 verify_ar_target(test, ar='my_ar_target3', rel_path=True) |
| 131 verify_ar_host(test, ar='my_ar_host3', rel_path=False) |
| 132 |
| 133 |
| 134 test.pass_test() |
OLD | NEW |