summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryukawa@chromium.org <yukawa@chromium.org@78cadc50-ecff-11dd-a971-7dbc132099af>2014-06-09 17:11:16 +0000
committeryukawa@chromium.org <yukawa@chromium.org@78cadc50-ecff-11dd-a971-7dbc132099af>2014-06-09 17:11:16 +0000
commit018065bdc1a6da9356c0e4556631346fb83527b0 (patch)
tree25737939a27a66182f2a22ad240043cf78bf7501
parent3917682a16d5c19ff3576a8be0ffdb3a332954b1 (diff)
downloadgyp-018065bdc1a6da9356c0e4556631346fb83527b0.tar.gz
Add unittest for 'AR' in 'make_global_settings'
Currently sharing the code among host/NaCl/NDK/Emscripten on top of Ninja+gyp isn't so easy as it should be because not all items in 'make_global_settings' are recognized by Ninja generator (gyp:434). On the other hand, the current test coverage of 'make_global_settings' isn't so good. Thus this CL describes the current behavior with some unittests before making Ninja generator aware of 'AR' in 'make_global_settings' like Make generator. BUG=gyp:434 TEST=unittest R=scottmg@chromium.org Review URL: https://codereview.chromium.org/320743002 git-svn-id: http://gyp.googlecode.com/svn/trunk@1931 78cadc50-ecff-11dd-a971-7dbc132099af
-rw-r--r--test/make_global_settings/ar/gyptest-make_global_settings_ar.py134
-rw-r--r--test/make_global_settings/ar/make_global_settings_ar.gyp29
2 files changed, 163 insertions, 0 deletions
diff --git a/test/make_global_settings/ar/gyptest-make_global_settings_ar.py b/test/make_global_settings/ar/gyptest-make_global_settings_ar.py
new file mode 100644
index 00000000..7b3da341
--- /dev/null
+++ b/test/make_global_settings/ar/gyptest-make_global_settings_ar.py
@@ -0,0 +1,134 @@
+#!/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 'AR' 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_ar_target(test, ar=None, rel_path=False):
+ if rel_path:
+ ar_expected = resolve_path(test, ar)
+ else:
+ ar_expected = ar
+ # Resolve default values
+ if ar_expected is None:
+ if test.format == 'make':
+ # Make generator hasn't set the default value for AR.
+ # You can remove the following assertion as long as it doesn't
+ # break existing projects.
+ test.must_not_contain('Makefile', 'AR ?= ')
+ return
+ elif test.format == 'ninja':
+ if sys.platform == 'win32':
+ ar_expected = 'lib.exe'
+ else:
+ ar_expected = 'ar'
+ if test.format == 'make':
+ test.must_contain('Makefile', 'AR ?= %s' % ar_expected)
+ elif test.format == 'ninja':
+ test.must_contain('out/Default/build.ninja', 'ar = %s' % ar_expected)
+ else:
+ test.fail_test()
+
+
+def verify_ar_host(test, ar=None, rel_path=False):
+ if rel_path:
+ ar_expected = resolve_path(test, ar)
+ else:
+ ar_expected = ar
+ # Resolve default values
+ if ar_expected is None:
+ if test.format == 'make':
+ ar_expected = '$(AR)'
+ elif test.format == 'ninja':
+ if sys.platform == 'win32':
+ # TODO(yukawa): Make sure if this is an expected result or not.
+ ar_expected = 'ar'
+ else:
+ ar_expected = '$ar'
+ if test.format == 'make':
+ test.must_contain('Makefile', 'AR.host ?= %s' % ar_expected)
+ elif test.format == 'ninja':
+ test.must_contain('out/Default/build.ninja', 'ar_host = %s' % ar_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_ar.gyp')
+verify_ar_target(test)
+
+
+# Test 'AR' in 'make_global_settings'.
+test.run_gyp('make_global_settings_ar.gyp', '-Dcustom_ar_target=my_ar')
+# TODO(yukawa): Support 'AR' in Ninja generator
+if test.format == 'make':
+ verify_ar_target(test, ar='my_ar', rel_path=True)
+
+
+# Test 'AR'/'AR.host' in 'make_global_settings'.
+test.run_gyp('make_global_settings_ar.gyp',
+ '-Dcustom_ar_target=my_ar_target1',
+ '-Dcustom_ar_host=my_ar_host1')
+# TODO(yukawa): Support 'AR'/'AR.host' in Ninja generator
+if test.format == 'make':
+ verify_ar_target(test, ar='my_ar_target1', rel_path=True)
+ verify_ar_host(test, ar='my_ar_host1', rel_path=True)
+
+
+# Test $AR and $AR_host environment variables.
+try:
+ os.environ['AR'] = 'my_ar_target2'
+ os.environ['AR_host'] = 'my_ar_host2'
+ test.run_gyp('make_global_settings_ar.gyp')
+finally:
+ del os.environ['AR']
+ del os.environ['AR_host']
+# Ninja generator resolves $AR in gyp phase. Make generator doesn't.
+if test.format == 'ninja':
+ if sys.platform == 'win32':
+ # TODO(yukawa): Make sure if this is an expected result or not.
+ verify_ar_target(test, ar='lib.exe', rel_path=False)
+ else:
+ verify_ar_target(test, ar='my_ar_target2', rel_path=False)
+verify_ar_host(test, ar='my_ar_host2', rel_path=False)
+
+
+# Test 'AR' in 'make_global_settings' with $AR_host environment variable.
+try:
+ os.environ['AR_host'] = 'my_ar_host3'
+ test.run_gyp('make_global_settings_ar.gyp',
+ '-Dcustom_ar_target=my_ar_target3')
+finally:
+ del os.environ['AR_host']
+# TODO(yukawa): Support 'AR' in Ninja generator
+if test.format == 'make':
+ verify_ar_target(test, ar='my_ar_target3', rel_path=True)
+verify_ar_host(test, ar='my_ar_host3', rel_path=False)
+
+
+test.pass_test()
diff --git a/test/make_global_settings/ar/make_global_settings_ar.gyp b/test/make_global_settings/ar/make_global_settings_ar.gyp
new file mode 100644
index 00000000..3430d82a
--- /dev/null
+++ b/test/make_global_settings/ar/make_global_settings_ar.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_ar_target%': '',
+ 'custom_ar_host%': '',
+ },
+ 'conditions': [
+ ['"<(custom_ar_target)"!=""', {
+ 'make_global_settings': [
+ ['AR', '<(custom_ar_target)'],
+ ],
+ }],
+ ['"<(custom_ar_host)"!=""', {
+ 'make_global_settings': [
+ ['AR.host', '<(custom_ar_host)'],
+ ],
+ }],
+ ],
+ 'targets': [
+ {
+ 'target_name': 'make_global_settings_ar_test',
+ 'type': 'static_library',
+ 'sources': [ 'foo.c' ],
+ },
+ ],
+}