From 2a457420c41bd9a745b9a42665266b0b2b07b7d6 Mon Sep 17 00:00:00 2001 From: "John H. Palmieri" Date: Tue, 5 Nov 2024 13:14:11 -0800 Subject: [PATCH] OS X: do not use -ld_classic. Filter out some ld warnings when doctesting. --- src/bin/sage-env | 26 -------------------------- src/sage/doctest/parsing.py | 15 +++++++++++++++ src/sage/tests/cmdline.py | 11 ++++++++++- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/bin/sage-env b/src/bin/sage-env index b9221fe3567..942adc0445a 100644 --- a/src/bin/sage-env +++ b/src/bin/sage-env @@ -373,32 +373,6 @@ if [ -n "$SAGE_LOCAL" ]; then # Construct and export LDFLAGS if [ "$UNAME" = "Darwin" ]; then LDFLAGS="-L$SAGE_LOCAL/lib $LDFLAGS" - # On OS X, use the old linker if it is available. - # if "ld-classic" is present in the selected XCode - # toolchain, add "-Wl,-ld_classic" to LDFLAGS (see #36599) unless - # LD is already set, as it will be with conda on macOS. When the - # selected toolchain is in the Xcode app the output of "xcode-select -p" - # is "/Applications/Xcode.app/Contents/Developer", but "ld-classic" is - # not in the subdirectory "usr/bin/" but rather in the subdirectory - # "Toolchains/XcodeDefault.xctoolchain/usr/bin/". (See #37237.) - if [ -z "$LD" ]; then - # Running xcode-select on a system with no toolchain writes an - # error message to stderr, so redirect stderr to /dev/null. - XCODE_PATH=$(/usr/bin/xcode-select -p 2> /dev/null) - if [ -n $XCODE_PATH ]; then - if [ -x "$XCODE_PATH/usr/bin/ld-classic" -o \ - -x "$XCODE_PATH/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld-classic" ]; then - LDFLAGS="$LDFLAGS -Wl,-ld_classic" - fi - else - # On a macOS system with no toolchain we don't want this script - # to call gcc because that will also print an error message to - # stderr. We can avoid this by setting AS and LD to their - # default values. - AS=as - LD=ld - fi - fi fi if [ "$UNAME" = "Linux" ]; then LDFLAGS="-L$SAGE_LOCAL/lib -Wl,-rpath,$SAGE_LOCAL/lib $LDFLAGS" diff --git a/src/sage/doctest/parsing.py b/src/sage/doctest/parsing.py index 0bc4965cd09..20f6eb6ce69 100644 --- a/src/sage/doctest/parsing.py +++ b/src/sage/doctest/parsing.py @@ -1516,6 +1516,21 @@ def do_fixup(self, want, got): pythran_numpy_warning_regex = re.compile(r'WARNING: Overriding pythran description with argspec information for: numpy\.random\.[a-z_]+') got = pythran_numpy_warning_regex.sub('', got) did_fixup = True + + if "ld_classic is deprecated" in got: + # New warnings as of Oct '24, Xcode 16. + ld_warn_regex = re.compile("ld: warning: -ld_classic is deprecated and will be removed in a future release") + got = ld_warn_regex.sub('', got) + did_fixup = True + + if "duplicate libraries" in got: + # New warnings as of Sept '23, OS X 13.6, new command-line + # tools. In particular, these seem to come from ld in + # Xcode 15. + dup_lib_regex = re.compile("ld: warning: ignoring duplicate libraries: .*") + got = dup_lib_regex.sub('', got) + did_fixup = True + return did_fixup, want, got def output_difference(self, example, got, optionflags): diff --git a/src/sage/tests/cmdline.py b/src/sage/tests/cmdline.py index 406bf1befab..27c614d290f 100644 --- a/src/sage/tests/cmdline.py +++ b/src/sage/tests/cmdline.py @@ -776,4 +776,13 @@ def test_executable(args, input='', timeout=100.0, pydebug_ignore_warnings=False p.stderr.close() err.append(s) - return (''.join(out), ''.join(err), p.wait()) + # In case out or err contains a quoted string, force the use of + # double quotes so that the output is enclosed in single + # quotes. This avoids some doctest failures with some versions of + # OS X and Xcode. + out = ''.join(out) + out = out.replace("'", '"') + err = ''.join(err) + err = err.replace("'", '"') + + return (out, err, p.wait())