OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2014 Google Inc. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """ | 7 """ |
8 Verifies 'AR' in make_global_settings. | 8 Verifies 'LD' in make_global_settings. |
9 """ | 9 """ |
10 | 10 |
11 import os | 11 import os |
12 import sys | 12 import sys |
13 import TestGyp | 13 import TestGyp |
14 | 14 |
15 def resolve_path(test, path): | 15 def resolve_path(test, path): |
16 if path is None: | 16 if path is None: |
17 return None | 17 return None |
18 elif test.format == 'make': | 18 elif test.format == 'make': |
19 return '$(abspath %s)' % path | 19 return '$(abspath %s)' % path |
20 elif test.format == 'ninja': | 20 elif test.format == 'ninja': |
21 return os.path.join('..', '..', path) | 21 return os.path.join('..', '..', path) |
22 else: | 22 else: |
23 test.fail_test() | 23 test.fail_test() |
24 | 24 |
25 | 25 |
26 def verify_ar_target(test, ar=None, rel_path=False): | 26 def verify_ld_target(test, ld=None, rel_path=False): |
27 if rel_path: | 27 if rel_path: |
28 ar_expected = resolve_path(test, ar) | 28 ld_expected = resolve_path(test, ld) |
29 else: | 29 else: |
30 ar_expected = ar | 30 ld_expected = ld |
31 # Resolve default values | 31 # Resolve default values |
32 if ar_expected is None: | 32 if ld_expected is None: |
33 if test.format == 'make': | 33 if test.format == 'make': |
34 # Make generator hasn't set the default value for AR. | 34 # Make generator hasn't set the default value for LD. |
35 # You can remove the following assertion as long as it doesn't | 35 # You can remove the following assertion as long as it doesn't |
36 # break existing projects. | 36 # break existing projects. |
37 test.must_not_contain('Makefile', 'AR ?= ') | 37 test.must_not_contain('Makefile', 'LD ?= ') |
38 return | 38 return |
39 elif test.format == 'ninja': | 39 elif test.format == 'ninja': |
40 if sys.platform == 'win32': | 40 if sys.platform == 'win32': |
41 ar_expected = 'lib.exe' | 41 ld_expected = 'link.exe' |
42 else: | 42 else: |
43 ar_expected = 'ar' | 43 ld_expected = '$cc' |
44 if test.format == 'make': | 44 if test.format == 'make': |
45 test.must_contain('Makefile', 'AR ?= %s' % ar_expected) | 45 test.must_contain('Makefile', 'LD ?= %s' % ld_expected) |
46 elif test.format == 'ninja': | 46 elif test.format == 'ninja': |
47 test.must_contain('out/Default/build.ninja', 'ar = %s' % ar_expected) | 47 test.must_contain('out/Default/build.ninja', 'ld = %s' % ld_expected) |
48 else: | 48 else: |
49 test.fail_test() | 49 test.fail_test() |
50 | 50 |
51 | 51 |
52 def verify_ar_host(test, ar=None, rel_path=False): | 52 def verify_ld_host(test, ld=None, rel_path=False): |
53 if rel_path: | 53 if rel_path: |
54 ar_expected = resolve_path(test, ar) | 54 ld_expected = resolve_path(test, ld) |
55 else: | 55 else: |
56 ar_expected = ar | 56 ld_expected = ld |
57 # Resolve default values | 57 # Resolve default values |
58 if ar_expected is None: | 58 if ld_expected is None: |
59 if test.format == 'make': | 59 if test.format == 'make': |
60 ar_expected = '$(AR)' | 60 ld_expected = '$(LD)' |
61 elif test.format == 'ninja': | 61 elif test.format == 'ninja': |
62 if sys.platform == 'win32': | 62 if sys.platform == 'win32': |
63 # TODO(yukawa): Make sure if this is an expected result or not. | 63 # TODO(yukawa): Make sure if this is an expected result or not. |
64 ar_expected = 'ar' | 64 ld_expected = 'ld' |
65 else: | 65 else: |
66 ar_expected = '$ar' | 66 ld_expected = '$ld' |
67 if test.format == 'make': | 67 if test.format == 'make': |
68 test.must_contain('Makefile', 'AR.host ?= %s' % ar_expected) | 68 test.must_contain('Makefile', 'LD.host ?= %s' % ld_expected) |
69 elif test.format == 'ninja': | 69 elif test.format == 'ninja': |
70 test.must_contain('out/Default/build.ninja', 'ar_host = %s' % ar_expected) | 70 test.must_contain('out/Default/build.ninja', 'ld_host = %s' % ld_expected) |
71 else: | 71 else: |
72 test.fail_test() | 72 test.fail_test() |
73 | 73 |
74 | 74 |
75 test_format = ['ninja'] | 75 test_format = ['ninja'] |
76 if sys.platform in ('linux2', 'darwin'): | 76 if sys.platform in ('linux2', 'darwin'): |
77 test_format += ['make'] | 77 test_format += ['make'] |
78 | 78 |
79 test = TestGyp.TestGyp(formats=test_format) | 79 test = TestGyp.TestGyp(formats=test_format) |
80 | 80 |
81 # Check default values | 81 # Check default values |
82 test.run_gyp('make_global_settings_ar.gyp') | 82 test.run_gyp('make_global_settings_ld.gyp') |
83 verify_ar_target(test) | 83 verify_ld_target(test) |
84 | 84 |
85 | 85 |
86 # Test 'AR' in 'make_global_settings'. | 86 # Test 'LD' in 'make_global_settings'. |
87 test.run_gyp('make_global_settings_ar.gyp', '-Dcustom_ar_target=my_ar') | 87 test.run_gyp('make_global_settings_ld.gyp', '-Dcustom_ld_target=my_ld') |
88 verify_ar_target(test, ar='my_ar', rel_path=True) | 88 # TODO(yukawa): Support 'LD' in Ninja generator |
| 89 if test.format == 'make': |
| 90 verify_ld_target(test, ld='my_ld', rel_path=True) |
89 | 91 |
90 | 92 |
91 # Test 'AR'/'AR.host' in 'make_global_settings'. | 93 # Test 'LD'/'LD.host' in 'make_global_settings'. |
92 test.run_gyp('make_global_settings_ar.gyp', | 94 test.run_gyp('make_global_settings_ld.gyp', |
93 '-Dcustom_ar_target=my_ar_target1', | 95 '-Dcustom_ld_target=my_ld_target1', |
94 '-Dcustom_ar_host=my_ar_host1') | 96 '-Dcustom_ld_host=my_ld_host1') |
95 verify_ar_target(test, ar='my_ar_target1', rel_path=True) | 97 # TODO(yukawa): Support 'LD'/'LD.host' in Ninja generator |
96 # TODO(yukawa): Support 'AR.host' in Ninja generator | |
97 if test.format == 'make': | 98 if test.format == 'make': |
98 verify_ar_host(test, ar='my_ar_host1', rel_path=True) | 99 verify_ld_target(test, ld='my_ld_target1', rel_path=True) |
| 100 verify_ld_host(test, ld='my_ld_host1', rel_path=True) |
99 | 101 |
100 | 102 |
101 # Test $AR and $AR_host environment variables. | 103 # Unlike other environment variables such as $AR/$AR_host, $CC/$CC_host, |
102 with TestGyp.LocalEnv({'AR': 'my_ar_target2', | 104 # and $CXX/$CXX_host, neither Make generator nor Ninja generator recognizes |
103 'AR_host': 'my_ar_host2'}): | 105 # $LD/$LD_host environment variables as of r1935. This may or may not be |
104 test.run_gyp('make_global_settings_ar.gyp') | 106 # intentional, but here we leave a test case to verify this behavior just for |
105 # Ninja generator resolves $AR in gyp phase. Make generator doesn't. | 107 # the record. |
106 if test.format == 'ninja': | 108 # If you want to support $LD/$LD_host, please revise the following test case as |
107 if sys.platform == 'win32': | 109 # well as the generator. |
108 # TODO(yukawa): Make sure if this is an expected result or not. | 110 with TestGyp.LocalEnv({'LD': 'my_ld_target2', |
109 verify_ar_target(test, ar='lib.exe', rel_path=False) | 111 'LD_host': 'my_ld_host2'}): |
110 else: | 112 test.run_gyp('make_global_settings_ld.gyp') |
111 verify_ar_target(test, ar='my_ar_target2', rel_path=False) | 113 if test.format == 'make': |
112 verify_ar_host(test, ar='my_ar_host2', rel_path=False) | 114 test.must_not_contain('Makefile', 'my_ld_target2') |
113 | 115 test.must_not_contain('Makefile', 'my_ld_host2') |
114 | 116 elif test.format == 'ninja': |
115 # Test 'AR' in 'make_global_settings' with $AR_host environment variable. | 117 test.must_not_contain('out/Default/build.ninja', 'my_ld_target2') |
116 with TestGyp.LocalEnv({'AR_host': 'my_ar_host3'}): | 118 test.must_not_contain('out/Default/build.ninja', 'my_ld_host2') |
117 test.run_gyp('make_global_settings_ar.gyp', | |
118 '-Dcustom_ar_target=my_ar_target3') | |
119 verify_ar_target(test, ar='my_ar_target3', rel_path=True) | |
120 verify_ar_host(test, ar='my_ar_host3', rel_path=False) | |
121 | 119 |
122 | 120 |
123 test.pass_test() | 121 test.pass_test() |
OLD | NEW |