summaryrefslogtreecommitdiffstats
path: root/third_party/python/gyp/test/no-cpp
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/no-cpp
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/no-cpp')
-rw-r--r--third_party/python/gyp/test/no-cpp/gyptest-no-cpp.py53
-rw-r--r--third_party/python/gyp/test/no-cpp/src/call-f-main.c2
-rw-r--r--third_party/python/gyp/test/no-cpp/src/empty-main.c1
-rw-r--r--third_party/python/gyp/test/no-cpp/src/f.cc3
-rw-r--r--third_party/python/gyp/test/no-cpp/src/test.gyp25
5 files changed, 84 insertions, 0 deletions
diff --git a/third_party/python/gyp/test/no-cpp/gyptest-no-cpp.py b/third_party/python/gyp/test/no-cpp/gyptest-no-cpp.py
new file mode 100644
index 0000000000..a5d64512af
--- /dev/null
+++ b/third_party/python/gyp/test/no-cpp/gyptest-no-cpp.py
@@ -0,0 +1,53 @@
+#!/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.
+
+"""
+Checks that C-only targets aren't linked against libstdc++.
+"""
+
+import TestGyp
+
+import re
+import subprocess
+import sys
+
+# set |match| to ignore build stderr output.
+test = TestGyp.TestGyp(match = lambda a, b: True)
+if (sys.platform != 'win32' and
+ not (sys.platform == 'darwin' and test.format == 'make')):
+ # TODO: Does a test like this make sense with Windows?
+
+ CHDIR = 'src'
+ test.run_gyp('test.gyp', chdir=CHDIR)
+ test.build('test.gyp', 'no_cpp', chdir=CHDIR)
+
+ def LinksLibStdCpp(path):
+ path = test.built_file_path(path, chdir=CHDIR)
+ if sys.platform == 'darwin':
+ proc = subprocess.Popen(['otool', '-L', path], stdout=subprocess.PIPE)
+ else:
+ proc = subprocess.Popen(['ldd', path], stdout=subprocess.PIPE)
+ output = proc.communicate()[0].decode('utf-8')
+ assert not proc.returncode
+ return 'libstdc++' in output or 'libc++' in output
+
+ if LinksLibStdCpp('no_cpp'):
+ test.fail_test()
+
+ # Make, ninja, and CMake pick the compiler driver based on transitive
+ # checks. Xcode doesn't.
+ build_error_code = {
+ 'xcode': 65, # EX_DATAERR, see `man sysexits`
+ 'make': 0,
+ 'ninja': 0,
+ 'cmake': 0,
+ 'xcode-ninja': 0,
+ }[test.format]
+
+ test.build('test.gyp', 'no_cpp_dep_on_cc_lib', chdir=CHDIR,
+ status=build_error_code)
+
+ test.pass_test()
diff --git a/third_party/python/gyp/test/no-cpp/src/call-f-main.c b/third_party/python/gyp/test/no-cpp/src/call-f-main.c
new file mode 100644
index 0000000000..8b95c5910e
--- /dev/null
+++ b/third_party/python/gyp/test/no-cpp/src/call-f-main.c
@@ -0,0 +1,2 @@
+void* f();
+int main() { f(); }
diff --git a/third_party/python/gyp/test/no-cpp/src/empty-main.c b/third_party/python/gyp/test/no-cpp/src/empty-main.c
new file mode 100644
index 0000000000..237c8ce181
--- /dev/null
+++ b/third_party/python/gyp/test/no-cpp/src/empty-main.c
@@ -0,0 +1 @@
+int main() {}
diff --git a/third_party/python/gyp/test/no-cpp/src/f.cc b/third_party/python/gyp/test/no-cpp/src/f.cc
new file mode 100644
index 0000000000..02f50f21a0
--- /dev/null
+++ b/third_party/python/gyp/test/no-cpp/src/f.cc
@@ -0,0 +1,3 @@
+extern "C" { void* f(); }
+
+void* f() { return new int; }
diff --git a/third_party/python/gyp/test/no-cpp/src/test.gyp b/third_party/python/gyp/test/no-cpp/src/test.gyp
new file mode 100644
index 0000000000..417015ec80
--- /dev/null
+++ b/third_party/python/gyp/test/no-cpp/src/test.gyp
@@ -0,0 +1,25 @@
+# Copyright (c) 2013 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': 'no_cpp',
+ 'type': 'executable',
+ 'sources': [ 'empty-main.c' ],
+ },
+ # A static_library with a cpp file and a linkable with only .c files
+ # depending on it causes a linker error:
+ {
+ 'target_name': 'cpp_lib',
+ 'type': 'static_library',
+ 'sources': [ 'f.cc' ],
+ },
+ {
+ 'target_name': 'no_cpp_dep_on_cc_lib',
+ 'type': 'executable',
+ 'dependencies': [ 'cpp_lib' ],
+ 'sources': [ 'call-f-main.c' ],
+ },
+ ],
+}