Skip to content

Commit

Permalink
OS X: do not use -ld_classic. Filter out some ld warnings when doctes…
Browse files Browse the repository at this point in the history
…ting.
  • Loading branch information
jhpalmieri committed Nov 5, 2024
1 parent 209ae4c commit 2a45742
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
26 changes: 0 additions & 26 deletions src/bin/sage-env
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions src/sage/doctest/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 10 additions & 1 deletion src/sage/tests/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 2a45742

Please sign in to comment.