summaryrefslogtreecommitdiffstats
path: root/third_party/python/gyp/test/compiler-override
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/python/gyp/test/compiler-override
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/python/gyp/test/compiler-override')
-rw-r--r--third_party/python/gyp/test/compiler-override/compiler-exe.gyp16
-rw-r--r--third_party/python/gyp/test/compiler-override/compiler-global-settings.gyp.in34
-rw-r--r--third_party/python/gyp/test/compiler-override/compiler-host.gyp17
-rw-r--r--third_party/python/gyp/test/compiler-override/compiler-shared-lib.gyp16
-rw-r--r--third_party/python/gyp/test/compiler-override/cxxtest.cc7
-rw-r--r--third_party/python/gyp/test/compiler-override/gyptest-compiler-env-toolchain.py78
-rwxr-xr-xthird_party/python/gyp/test/compiler-override/gyptest-compiler-env.py110
-rwxr-xr-xthird_party/python/gyp/test/compiler-override/gyptest-compiler-global-settings.py82
-rwxr-xr-xthird_party/python/gyp/test/compiler-override/my_cc.py7
-rwxr-xr-xthird_party/python/gyp/test/compiler-override/my_cxx.py7
-rwxr-xr-xthird_party/python/gyp/test/compiler-override/my_ld.py7
-rwxr-xr-xthird_party/python/gyp/test/compiler-override/my_nm.py9
-rwxr-xr-xthird_party/python/gyp/test/compiler-override/my_readelf.py9
-rw-r--r--third_party/python/gyp/test/compiler-override/test.c7
14 files changed, 406 insertions, 0 deletions
diff --git a/third_party/python/gyp/test/compiler-override/compiler-exe.gyp b/third_party/python/gyp/test/compiler-override/compiler-exe.gyp
new file mode 100644
index 0000000000..c2f3002f20
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/compiler-exe.gyp
@@ -0,0 +1,16 @@
+# Copyright (c) 2012 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.
+
+{
+ 'targets': [
+ {
+ 'target_name': 'hello',
+ 'type': 'executable',
+ 'sources': [
+ 'test.c',
+ 'cxxtest.cc',
+ ],
+ },
+ ],
+}
diff --git a/third_party/python/gyp/test/compiler-override/compiler-global-settings.gyp.in b/third_party/python/gyp/test/compiler-override/compiler-global-settings.gyp.in
new file mode 100644
index 0000000000..ca13a53e8d
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/compiler-global-settings.gyp.in
@@ -0,0 +1,34 @@
+# Copyright (c) 2012 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.
+
+{
+ # PYTHON and PWD are replaced by the test code before this
+ # gyp file runs
+ 'make_global_settings': [
+ ['CC', r'$PYTHON $PWD/my_cc.py FOO'],
+ ['CXX', r'$PYTHON $PWD/my_cxx.py FOO'],
+ ['CC.host', r'$PYTHON $PWD/my_cc.py BAR'],
+ ['CXX.host', r'$PYTHON $PWD/my_cxx.py BAR'],
+
+ ['LD', r'$PYTHON $PWD/my_ld.py FOO_LINK'],
+ ['LD.host', r'$PYTHON $PWD/my_ld.py BAR_LINK'],
+ ['LINK', r'$PYTHON $PWD/my_ld.py FOO_LINK'],
+ ['LINK.host', r'$PYTHON $PWD/my_ld.py BAR_LINK'],
+ ],
+
+ # The above global settings should mean that
+ # that these targets are built using the fake
+ # toolchain above.
+ 'targets': [
+ {
+ 'toolset': '$TOOLSET',
+ 'target_name': 'hello',
+ 'type': 'executable',
+ 'sources': [
+ 'test.c',
+ 'cxxtest.cc',
+ ],
+ },
+ ],
+}
diff --git a/third_party/python/gyp/test/compiler-override/compiler-host.gyp b/third_party/python/gyp/test/compiler-override/compiler-host.gyp
new file mode 100644
index 0000000000..ab3d247e0b
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/compiler-host.gyp
@@ -0,0 +1,17 @@
+# Copyright (c) 2012 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.
+
+{
+ 'targets': [
+ {
+ 'toolset': 'host',
+ 'target_name': 'hello',
+ 'type': 'executable',
+ 'sources': [
+ 'test.c',
+ 'cxxtest.cc',
+ ],
+ },
+ ],
+}
diff --git a/third_party/python/gyp/test/compiler-override/compiler-shared-lib.gyp b/third_party/python/gyp/test/compiler-override/compiler-shared-lib.gyp
new file mode 100644
index 0000000000..d3e4316135
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/compiler-shared-lib.gyp
@@ -0,0 +1,16 @@
+# Copyright (c) 2012 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.
+
+{
+ 'targets': [
+ {
+ 'target_name': 'hello-lib',
+ 'type': 'shared_library',
+ 'sources': [
+ 'test.c',
+ 'cxxtest.cc',
+ ],
+ },
+ ],
+}
diff --git a/third_party/python/gyp/test/compiler-override/cxxtest.cc b/third_party/python/gyp/test/compiler-override/cxxtest.cc
new file mode 100644
index 0000000000..517a353619
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/cxxtest.cc
@@ -0,0 +1,7 @@
+// Copyright (c) 2012 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.
+
+// Deliberate C syntax error as this file should never be passed to
+// the actual compiler
+#error Should not be passed to a real compiler
diff --git a/third_party/python/gyp/test/compiler-override/gyptest-compiler-env-toolchain.py b/third_party/python/gyp/test/compiler-override/gyptest-compiler-env-toolchain.py
new file mode 100644
index 0000000000..2361d0c7c2
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/gyptest-compiler-env-toolchain.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 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 that the user can override the compiler and linker using
+CC/CXX/NM/READELF environment variables.
+"""
+
+import TestGyp
+import os
+import copy
+import sys
+
+here = os.path.dirname(os.path.abspath(__file__))
+
+if sys.platform == 'win32':
+ # cross compiling not supported by ninja on windows
+ # and make not supported on windows at all.
+ sys.exit(0)
+
+# Clear any existing compiler related env vars.
+for key in ['CC', 'CXX', 'LINK', 'CC_host', 'CXX_host', 'LINK_host',
+ 'NM_target', 'READELF_target']:
+ if key in os.environ:
+ del os.environ[key]
+
+
+def CheckCompiler(test, gypfile, check_for, run_gyp):
+ if run_gyp:
+ test.run_gyp(gypfile)
+ test.build(gypfile)
+
+ test.must_contain_all_lines(test.stdout(), check_for)
+
+
+test = TestGyp.TestGyp(formats=['ninja'])
+# Must set the test format to something with a flavor (the part after the '-')
+# in order to test the desired behavior. Since we want to run a non-host
+# toolchain, we have to set the flavor to something that the ninja generator
+# doesn't know about, so it doesn't default to the host-specific tools (e.g.,
+# 'otool' on mac to generate the .TOC).
+#
+# Note that we can't just pass format=['ninja-some_toolchain'] to the
+# constructor above, because then this test wouldn't be recognized as a ninja
+# format test.
+test.formats = ['ninja-my_flavor' if f == 'ninja' else f for f in test.formats]
+
+
+def TestTargetOverideSharedLib():
+ # The std output from nm and readelf is redirected to files, so we can't
+ # expect their output to appear. Instead, check for the files they create to
+ # see if they actually ran.
+ expected = ['my_cc.py', 'my_cxx.py', 'FOO']
+
+ # Check that CC, CXX, NM, READELF, set target compiler
+ env = {'CC': 'python %s/my_cc.py FOO' % here,
+ 'CXX': 'python %s/my_cxx.py FOO' % here,
+ 'NM': 'python %s/my_nm.py' % here,
+ 'READELF': 'python %s/my_readelf.py' % here}
+
+ with TestGyp.LocalEnv(env):
+ CheckCompiler(test, 'compiler-shared-lib.gyp', expected, True)
+ test.must_contain(test.built_file_path('RAN_MY_NM'), 'RAN_MY_NM')
+ test.must_contain(test.built_file_path('RAN_MY_READELF'), 'RAN_MY_READELF')
+ test.unlink(test.built_file_path('RAN_MY_NM'))
+ test.unlink(test.built_file_path('RAN_MY_READELF'))
+
+ # Run the same tests once the eviron has been restored. The generated
+ # projects should have embedded all the settings in the project files so the
+ # results should be the same.
+ CheckCompiler(test, 'compiler-shared-lib.gyp', expected, False)
+ test.must_contain(test.built_file_path('RAN_MY_NM'), 'RAN_MY_NM')
+ test.must_contain(test.built_file_path('RAN_MY_READELF'), 'RAN_MY_READELF')
+
+
+TestTargetOverideSharedLib()
+test.pass_test()
diff --git a/third_party/python/gyp/test/compiler-override/gyptest-compiler-env.py b/third_party/python/gyp/test/compiler-override/gyptest-compiler-env.py
new file mode 100755
index 0000000000..bb38b6e55b
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/gyptest-compiler-env.py
@@ -0,0 +1,110 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 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 that the user can override the compiler and linker using CC/CXX/LD
+environment variables.
+"""
+
+import TestGyp
+import os
+import copy
+import sys
+
+here = os.path.dirname(os.path.abspath(__file__))
+
+if sys.platform == 'win32':
+ # cross compiling not supported by ninja on windows
+ # and make not supported on windows at all.
+ sys.exit(0)
+
+# Clear any existing compiler related env vars.
+for key in ['CC', 'CXX', 'LINK', 'CC_host', 'CXX_host', 'LINK_host']:
+ if key in os.environ:
+ del os.environ[key]
+
+
+def CheckCompiler(test, gypfile, check_for, run_gyp):
+ if run_gyp:
+ test.run_gyp(gypfile)
+ test.build(gypfile)
+
+ test.must_contain_all_lines(test.stdout(), check_for)
+
+
+test = TestGyp.TestGyp(formats=['ninja', 'make'])
+
+def TestTargetOveride():
+ expected = ['my_cc.py', 'my_cxx.py', 'FOO' ]
+
+ # ninja just uses $CC / $CXX as linker.
+ if test.format not in ['ninja', 'xcode-ninja']:
+ expected.append('FOO_LINK')
+
+ # Check that CC, CXX and LD set target compiler
+ oldenv = os.environ.copy()
+ try:
+ os.environ['CC'] = 'python %s/my_cc.py FOO' % here
+ os.environ['CXX'] = 'python %s/my_cxx.py FOO' % here
+ os.environ['LINK'] = 'python %s/my_ld.py FOO_LINK' % here
+
+ CheckCompiler(test, 'compiler-exe.gyp', expected, True)
+ finally:
+ os.environ.clear()
+ os.environ.update(oldenv)
+
+ # Run the same tests once the eviron has been restored. The
+ # generated should have embedded all the settings in the
+ # project files so the results should be the same.
+ CheckCompiler(test, 'compiler-exe.gyp', expected, False)
+
+
+def TestTargetOverideCompilerOnly():
+ # Same test again but with that CC, CXX and not LD
+ oldenv = os.environ.copy()
+ try:
+ os.environ['CC'] = 'python %s/my_cc.py FOO' % here
+ os.environ['CXX'] = 'python %s/my_cxx.py FOO' % here
+
+ CheckCompiler(test, 'compiler-exe.gyp',
+ ['my_cc.py', 'my_cxx.py', 'FOO'],
+ True)
+ finally:
+ os.environ.clear()
+ os.environ.update(oldenv)
+
+ # Run the same tests once the eviron has been restored. The
+ # generated should have embedded all the settings in the
+ # project files so the results should be the same.
+ CheckCompiler(test, 'compiler-exe.gyp',
+ ['my_cc.py', 'my_cxx.py', 'FOO'],
+ False)
+
+
+def TestHostOveride():
+ expected = ['my_cc.py', 'my_cxx.py', 'HOST' ]
+ if test.format != 'ninja': # ninja just uses $CC / $CXX as linker.
+ expected.append('HOST_LINK')
+
+ # Check that CC_host sets host compilee
+ oldenv = os.environ.copy()
+ try:
+ os.environ['CC_host'] = 'python %s/my_cc.py HOST' % here
+ os.environ['CXX_host'] = 'python %s/my_cxx.py HOST' % here
+ os.environ['LINK_host'] = 'python %s/my_ld.py HOST_LINK' % here
+ CheckCompiler(test, 'compiler-host.gyp', expected, True)
+ finally:
+ os.environ.clear()
+ os.environ.update(oldenv)
+
+ # Run the same tests once the eviron has been restored. The
+ # generated should have embedded all the settings in the
+ # project files so the results should be the same.
+ CheckCompiler(test, 'compiler-host.gyp', expected, False)
+
+
+TestTargetOveride()
+TestTargetOverideCompilerOnly()
+
+test.pass_test()
diff --git a/third_party/python/gyp/test/compiler-override/gyptest-compiler-global-settings.py b/third_party/python/gyp/test/compiler-override/gyptest-compiler-global-settings.py
new file mode 100755
index 0000000000..9f062a4fef
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/gyptest-compiler-global-settings.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 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 that make_global_settings can be used to override the
+compiler settings.
+"""
+from __future__ import print_function
+
+import TestGyp
+import os
+import copy
+import sys
+from string import Template
+
+
+if sys.platform == 'win32':
+ # cross compiling not support by ninja on windows
+ # and make not supported on windows at all.
+ sys.exit(0)
+
+print("This test is currently disabled: https://crbug.com/483696.")
+sys.exit(0)
+
+test = TestGyp.TestGyp(formats=['ninja', 'make'])
+
+gypfile = 'compiler-global-settings.gyp'
+
+replacements = { 'PYTHON': '/usr/bin/python', 'PWD': os.getcwd()}
+
+# Process the .in gyp file to produce the final gyp file
+# since we need to include absolute paths in the make_global_settings
+# section.
+replacements['TOOLSET'] = 'target'
+s = Template(open(gypfile + '.in').read())
+output = open(gypfile, 'w')
+output.write(s.substitute(replacements))
+output.close()
+
+old_env = dict(os.environ)
+os.environ['GYP_CROSSCOMPILE'] = '1'
+test.run_gyp(gypfile)
+os.environ.clear()
+os.environ.update(old_env)
+
+test.build(gypfile)
+test.must_contain_all_lines(test.stdout(), ['my_cc.py', 'my_cxx.py', 'FOO'])
+
+# The xcode generator chokes on the 'host' toolset. Skip the rest of
+# this test (cf. https://code.google.com/p/gyp/issues/detail?id=454).
+if test.format == 'xcode-ninja':
+ test.pass_test()
+
+# Same again but with the host toolset.
+replacements['TOOLSET'] = 'host'
+s = Template(open(gypfile + '.in').read())
+output = open(gypfile, 'w')
+output.write(s.substitute(replacements))
+output.close()
+
+old_env = dict(os.environ)
+os.environ['GYP_CROSSCOMPILE'] = '1'
+test.run_gyp(gypfile)
+os.environ.clear()
+os.environ.update(old_env)
+
+test.build(gypfile)
+test.must_contain_all_lines(test.stdout(), ['my_cc.py', 'my_cxx.py', 'BAR'])
+
+# Check that CC_host overrides make_global_settings
+old_env = dict(os.environ)
+os.environ['CC_host'] = '%s %s/my_cc.py SECRET' % (replacements['PYTHON'],
+ replacements['PWD'])
+test.run_gyp(gypfile)
+os.environ.clear()
+os.environ.update(old_env)
+
+test.build(gypfile)
+test.must_contain_all_lines(test.stdout(), ['SECRET', 'my_cxx.py', 'BAR'])
+
+test.pass_test()
diff --git a/third_party/python/gyp/test/compiler-override/my_cc.py b/third_party/python/gyp/test/compiler-override/my_cc.py
new file mode 100755
index 0000000000..09e1d3c58d
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/my_cc.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 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.
+from __future__ import print_function
+import sys
+print(sys.argv)
diff --git a/third_party/python/gyp/test/compiler-override/my_cxx.py b/third_party/python/gyp/test/compiler-override/my_cxx.py
new file mode 100755
index 0000000000..09e1d3c58d
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/my_cxx.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 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.
+from __future__ import print_function
+import sys
+print(sys.argv)
diff --git a/third_party/python/gyp/test/compiler-override/my_ld.py b/third_party/python/gyp/test/compiler-override/my_ld.py
new file mode 100755
index 0000000000..09e1d3c58d
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/my_ld.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 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.
+from __future__ import print_function
+import sys
+print(sys.argv)
diff --git a/third_party/python/gyp/test/compiler-override/my_nm.py b/third_party/python/gyp/test/compiler-override/my_nm.py
new file mode 100755
index 0000000000..2c4e678110
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/my_nm.py
@@ -0,0 +1,9 @@
+#!/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.
+from __future__ import print_function
+import sys
+print(sys.argv)
+with open('RAN_MY_NM', 'w') as f:
+ f.write('RAN_MY_NM')
diff --git a/third_party/python/gyp/test/compiler-override/my_readelf.py b/third_party/python/gyp/test/compiler-override/my_readelf.py
new file mode 100755
index 0000000000..626665435e
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/my_readelf.py
@@ -0,0 +1,9 @@
+#!/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.
+from __future__ import print_function
+import sys
+print(sys.argv)
+with open('RAN_MY_READELF', 'w') as f:
+ f.write('RAN_MY_READELF')
diff --git a/third_party/python/gyp/test/compiler-override/test.c b/third_party/python/gyp/test/compiler-override/test.c
new file mode 100644
index 0000000000..517a353619
--- /dev/null
+++ b/third_party/python/gyp/test/compiler-override/test.c
@@ -0,0 +1,7 @@
+// Copyright (c) 2012 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.
+
+// Deliberate C syntax error as this file should never be passed to
+// the actual compiler
+#error Should not be passed to a real compiler