Skip to content

Commit

Permalink
gh-38931: OS X: do not use -ld_classic
Browse files Browse the repository at this point in the history
    
Recent versions of Xcode have deprecated `-ld_classic`, so (a) we stop
using it, (b) we filter warnings about it when doctesting, and (c) we
filter some other warnings related to ld in Xcode.

Without these changes, when building with the latest Xcode, I get many
doctest failures because of the new warning
```
ld: warning: -ld_classic is deprecated and will be removed in a future
release
```

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [X] The title is concise and informative.
- [X] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - #12345: short description why this is a dependency -->
<!-- - #34567: ... -->
    
URL: #38931
Reported by: John H. Palmieri
Reviewer(s): Marc Culler
  • Loading branch information
Release Manager committed Nov 14, 2024
2 parents 7254cca + e79ccb9 commit 0df1f22
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/bin/sage-env
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,15 @@ if [ -n "$SAGE_LOCAL" ]; then
# "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.
# 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"
# Add -ld_classic only if -ld_classic is not deprecated.
if [ -z "$(ld -ld_classic 2>&1 | grep 'ld_classic is deprecated')" ]; then
LDFLAGS="$LDFLAGS -Wl,-ld_classic"
fi
fi
else
# On a macOS system with no toolchain we don't want this script
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 0df1f22

Please sign in to comment.