diff options
author | yukawa@chromium.org <yukawa@chromium.org@78cadc50-ecff-11dd-a971-7dbc132099af> | 2014-06-13 01:10:39 +0000 |
---|---|---|
committer | yukawa@chromium.org <yukawa@chromium.org@78cadc50-ecff-11dd-a971-7dbc132099af> | 2014-06-13 01:10:39 +0000 |
commit | 133926d7f47ef5d89309b6122984406bef33c0bd (patch) | |
tree | 1af091cb8cf26c8fd5dfa527af39dd760d17ad8b | |
parent | 5a0658e560c0503e2385ad339e06b6fae3031c15 (diff) | |
download | gyp-133926d7f47ef5d89309b6122984406bef33c0bd.tar.gz |
Add unittest for 'LD' in 'make_global_settings'
This CL describes the current behavior with some unittests, before making Ninja generator aware of 'LD' in 'make_global_settings'. See gyp r1931 for the background.
BUG=gyp:434
TEST=unittest
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/322973006
git-svn-id: http://gyp.googlecode.com/svn/trunk@1937 78cadc50-ecff-11dd-a971-7dbc132099af
-rw-r--r-- | test/make_global_settings/ld/gyptest-make_global_settings_ld.py | 121 | ||||
-rw-r--r-- | test/make_global_settings/ld/make_global_settings_ld.gyp | 29 |
2 files changed, 150 insertions, 0 deletions
diff --git a/test/make_global_settings/ld/gyptest-make_global_settings_ld.py b/test/make_global_settings/ld/gyptest-make_global_settings_ld.py new file mode 100644 index 00000000..4ce38fbb --- /dev/null +++ b/test/make_global_settings/ld/gyptest-make_global_settings_ld.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python + +# Copyright (c) 2014 Google Inc. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +Verifies 'LD' in make_global_settings. +""" + +import os +import sys +import TestGyp + +def resolve_path(test, path): + if path is None: + return None + elif test.format == 'make': + return '$(abspath %s)' % path + elif test.format == 'ninja': + return os.path.join('..', '..', path) + else: + test.fail_test() + + +def verify_ld_target(test, ld=None, rel_path=False): + if rel_path: + ld_expected = resolve_path(test, ld) + else: + ld_expected = ld + # Resolve default values + if ld_expected is None: + if test.format == 'make': + # Make generator hasn't set the default value for LD. + # You can remove the following assertion as long as it doesn't + # break existing projects. + test.must_not_contain('Makefile', 'LD ?= ') + return + elif test.format == 'ninja': + if sys.platform == 'win32': + ld_expected = 'link.exe' + else: + ld_expected = '$cc' + if test.format == 'make': + test.must_contain('Makefile', 'LD ?= %s' % ld_expected) + elif test.format == 'ninja': + test.must_contain('out/Default/build.ninja', 'ld = %s' % ld_expected) + else: + test.fail_test() + + +def verify_ld_host(test, ld=None, rel_path=False): + if rel_path: + ld_expected = resolve_path(test, ld) + else: + ld_expected = ld + # Resolve default values + if ld_expected is None: + if test.format == 'make': + ld_expected = '$(LD)' + elif test.format == 'ninja': + if sys.platform == 'win32': + # TODO(yukawa): Make sure if this is an expected result or not. + ld_expected = 'ld' + else: + ld_expected = '$ld' + if test.format == 'make': + test.must_contain('Makefile', 'LD.host ?= %s' % ld_expected) + elif test.format == 'ninja': + test.must_contain('out/Default/build.ninja', 'ld_host = %s' % ld_expected) + else: + test.fail_test() + + +test_format = ['ninja'] +if sys.platform in ('linux2', 'darwin'): + test_format += ['make'] + +test = TestGyp.TestGyp(formats=test_format) + +# Check default values +test.run_gyp('make_global_settings_ld.gyp') +verify_ld_target(test) + + +# Test 'LD' in 'make_global_settings'. +test.run_gyp('make_global_settings_ld.gyp', '-Dcustom_ld_target=my_ld') +# TODO(yukawa): Support 'LD' in Ninja generator +if test.format == 'make': + verify_ld_target(test, ld='my_ld', rel_path=True) + + +# Test 'LD'/'LD.host' in 'make_global_settings'. +test.run_gyp('make_global_settings_ld.gyp', + '-Dcustom_ld_target=my_ld_target1', + '-Dcustom_ld_host=my_ld_host1') +# TODO(yukawa): Support 'LD'/'LD.host' in Ninja generator +if test.format == 'make': + verify_ld_target(test, ld='my_ld_target1', rel_path=True) + verify_ld_host(test, ld='my_ld_host1', rel_path=True) + + +# Unlike other environment variables such as $AR/$AR_host, $CC/$CC_host, +# and $CXX/$CXX_host, neither Make generator nor Ninja generator recognizes +# $LD/$LD_host environment variables as of r1935. This may or may not be +# intentional, but here we leave a test case to verify this behavior just for +# the record. +# If you want to support $LD/$LD_host, please revise the following test case as +# well as the generator. +with TestGyp.LocalEnv({'LD': 'my_ld_target2', + 'LD_host': 'my_ld_host2'}): + test.run_gyp('make_global_settings_ld.gyp') +if test.format == 'make': + test.must_not_contain('Makefile', 'my_ld_target2') + test.must_not_contain('Makefile', 'my_ld_host2') +elif test.format == 'ninja': + test.must_not_contain('out/Default/build.ninja', 'my_ld_target2') + test.must_not_contain('out/Default/build.ninja', 'my_ld_host2') + + +test.pass_test() diff --git a/test/make_global_settings/ld/make_global_settings_ld.gyp b/test/make_global_settings/ld/make_global_settings_ld.gyp new file mode 100644 index 00000000..6837c773 --- /dev/null +++ b/test/make_global_settings/ld/make_global_settings_ld.gyp @@ -0,0 +1,29 @@ +# Copyright (c) 2014 Google Inc. All rights reserved. +# Use of this source code is governed by a BSD-style licence that can be +# found in the LICENSE file. + +{ + 'variables': { + 'custom_ld_target%': '', + 'custom_ld_host%': '', + }, + 'conditions': [ + ['"<(custom_ld_target)"!=""', { + 'make_global_settings': [ + ['LD', '<(custom_ld_target)'], + ], + }], + ['"<(custom_ld_host)"!=""', { + 'make_global_settings': [ + ['LD.host', '<(custom_ld_host)'], + ], + }], + ], + 'targets': [ + { + 'target_name': 'make_global_settings_ld_test', + 'type': 'static_library', + 'sources': [ 'foo.c' ], + }, + ], +} |