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 'LD' 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_ld_target(test, ld=None, rel_path=False): 27 if rel_path: 28 ld_expected = resolve_path(test, ld) 29 else: 30 ld_expected = ld 31 # Resolve default values 32 if ld_expected is None: 33 if test.format == 'make': 34 # Make generator hasn't set the default value for LD. 35 # You can remove the following assertion as long as it doesn't 36 # break existing projects. 37 test.must_not_contain('Makefile', 'LD ?= ') 38 return 39 elif test.format == 'ninja': 40 if sys.platform == 'win32': 41 ld_expected = 'link.exe' 42 else: 43 ld_expected = '$cc' 44 if test.format == 'make': 45 test.must_contain('Makefile', 'LD ?= %s' % ld_expected) 46 elif test.format == 'ninja': 47 test.must_contain('out/Default/build.ninja', 'ld = %s' % ld_expected) 48 else: 49 test.fail_test() 50 51 52 def verify_ld_host(test, ld=None, rel_path=False): 53 if rel_path: 54 ld_expected = resolve_path(test, ld) 55 else: 56 ld_expected = ld 57 # Resolve default values 58 if ld_expected is None: 59 if test.format == 'make': 60 # Make generator hasn't set the default value for LD.host. 61 # You can remove the following assertion as long as it doesn't 62 # break existing projects. 63 test.must_not_contain('Makefile', 'LD.host ?= ') 64 return 65 elif test.format == 'ninja': 66 if sys.platform == 'win32': 67 ld_expected = '$ld' 68 else: 69 ld_expected = '$cc_host' 70 if test.format == 'make': 71 test.must_contain('Makefile', 'LD.host ?= %s' % ld_expected) 72 elif test.format == 'ninja': 73 test.must_contain('out/Default/build.ninja', 'ld_host = %s' % ld_expected) 74 else: 75 test.fail_test() 76 77 78 test_format = ['ninja'] 79 if sys.platform in ('linux2', 'darwin'): 80 test_format += ['make'] 81 82 test = TestGyp.TestGyp(formats=test_format) 83 84 # Check default values 85 test.run_gyp('make_global_settings_ld.gyp') 86 verify_ld_target(test) 87 88 89 # Check default values with GYP_CROSSCOMPILE enabled. 90 with TestGyp.LocalEnv({'GYP_CROSSCOMPILE': '1'}): 91 test.run_gyp('make_global_settings_ld.gyp') 92 verify_ld_target(test) 93 verify_ld_host(test) 94 95 96 # Test 'LD' in 'make_global_settings'. 97 with TestGyp.LocalEnv({'GYP_CROSSCOMPILE': '1'}): 98 test.run_gyp('make_global_settings_ld.gyp', '-Dcustom_ld_target=my_ld') 99 verify_ld_target(test, ld='my_ld', rel_path=True) 100 101 102 # Test 'LD'/'LD.host' in 'make_global_settings'. 103 with TestGyp.LocalEnv({'GYP_CROSSCOMPILE': '1'}): 104 test.run_gyp('make_global_settings_ld.gyp', 105 '-Dcustom_ld_target=my_ld_target1', 106 '-Dcustom_ld_host=my_ld_host1') 107 verify_ld_target(test, ld='my_ld_target1', rel_path=True) 108 verify_ld_host(test, ld='my_ld_host1', rel_path=True) 109 110 111 # Unlike other environment variables such as $AR/$AR_host, $CC/$CC_host, 112 # and $CXX/$CXX_host, neither Make generator nor Ninja generator recognizes 113 # $LD/$LD_host environment variables as of r1935. This may or may not be 114 # intentional, but here we leave a test case to verify this behavior just for 115 # the record. 116 # If you want to support $LD/$LD_host, please revise the following test case as 117 # well as the generator. 118 with TestGyp.LocalEnv({'GYP_CROSSCOMPILE': '1', 119 'LD': 'my_ld_target2', 120 'LD_host': 'my_ld_host2'}): 121 test.run_gyp('make_global_settings_ld.gyp') 122 if test.format == 'make': 123 test.must_not_contain('Makefile', 'my_ld_target2') 124 test.must_not_contain('Makefile', 'my_ld_host2') 125 elif test.format == 'ninja': 126 test.must_not_contain('out/Default/build.ninja', 'my_ld_target2') 127 test.must_not_contain('out/Default/build.ninja', 'my_ld_host2') 128 129 130 test.pass_test() 131