Skip to content

Commit 86d8c99

Browse files
authored
Merge pull request #4790 from pypa/feature/distutils-ff11eed0c
Sync with distutils
2 parents 53d5ac2 + c384f18 commit 86d8c99

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

Diff for: newsfragments/4790.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Synced with pypa/distutils@ff11eed0c including bugfix for duplicate CFLAGS and adaption to support Python 3.13 is_abs in the C compiler (#4669).

Diff for: setuptools/_distutils/ccompiler.py

+23-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
for the Distutils compiler abstraction model."""
55

66
import os
7+
import pathlib
78
import re
89
import sys
910
import types
@@ -969,27 +970,33 @@ def out_extensions(self):
969970
return dict.fromkeys(self.src_extensions, self.obj_extension)
970971

971972
def _make_out_path(self, output_dir, strip_dir, src_name):
972-
base, ext = os.path.splitext(src_name)
973-
base = self._make_relative(base)
973+
return self._make_out_path_exts(
974+
output_dir, strip_dir, src_name, self.out_extensions
975+
)
976+
977+
@classmethod
978+
def _make_out_path_exts(cls, output_dir, strip_dir, src_name, extensions):
979+
r"""
980+
>>> exts = {'.c': '.o'}
981+
>>> CCompiler._make_out_path_exts('.', False, '/foo/bar.c', exts).replace('\\', '/')
982+
'./foo/bar.o'
983+
>>> CCompiler._make_out_path_exts('.', True, '/foo/bar.c', exts).replace('\\', '/')
984+
'./bar.o'
985+
"""
986+
src = pathlib.PurePath(src_name)
987+
# Ensure base is relative to honor output_dir (python/cpython#37775).
988+
base = cls._make_relative(src)
974989
try:
975-
new_ext = self.out_extensions[ext]
990+
new_ext = extensions[src.suffix]
976991
except LookupError:
977-
raise UnknownFileError(f"unknown file type '{ext}' (from '{src_name}')")
992+
raise UnknownFileError(f"unknown file type '{src.suffix}' (from '{src}')")
978993
if strip_dir:
979-
base = os.path.basename(base)
980-
return os.path.join(output_dir, base + new_ext)
994+
base = pathlib.PurePath(base.name)
995+
return os.path.join(output_dir, base.with_suffix(new_ext))
981996

982997
@staticmethod
983-
def _make_relative(base):
984-
"""
985-
In order to ensure that a filename always honors the
986-
indicated output_dir, make sure it's relative.
987-
Ref python/cpython#37775.
988-
"""
989-
# Chop off the drive
990-
no_drive = os.path.splitdrive(base)[1]
991-
# If abs, chop off leading /
992-
return no_drive[os.path.isabs(no_drive) :]
998+
def _make_relative(base: pathlib.Path):
999+
return base.relative_to(base.anchor)
9931000

9941001
def shared_object_filename(self, basename, strip_dir=False, output_dir=''):
9951002
assert output_dir is not None

Diff for: setuptools/_distutils/sysconfig.py

-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ def customize_compiler(compiler):
341341
ldshared = _add_flags(ldshared, 'LD')
342342
ldcxxshared = _add_flags(ldcxxshared, 'LD')
343343
cflags = os.environ.get('CFLAGS', cflags)
344-
cflags = _add_flags(cflags, 'C')
345344
ldshared = _add_flags(ldshared, 'C')
346345
cxxflags = os.environ.get('CXXFLAGS', cxxflags)
347346
ldcxxshared = _add_flags(ldcxxshared, 'CXX')

Diff for: setuptools/_distutils/tests/test_ccompiler.py

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import pytest
99

10+
pytestmark = pytest.mark.usefixtures('suppress_path_mangle')
11+
1012

1113
def _make_strs(paths):
1214
"""

Diff for: setuptools/_distutils/tests/test_sysconfig.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,9 @@ def test_customize_compiler(self):
130130
comp = self.customize_compiler()
131131
assert comp.exes['archiver'] == 'env_ar --env-arflags'
132132
assert comp.exes['preprocessor'] == 'env_cpp --env-cppflags'
133-
assert (
134-
comp.exes['compiler'] == 'env_cc --env-cflags --env-cflags --env-cppflags'
135-
)
133+
assert comp.exes['compiler'] == 'env_cc --env-cflags --env-cppflags'
136134
assert comp.exes['compiler_so'] == (
137-
'env_cc --env-cflags --env-cflags --env-cppflags --sc-ccshared'
135+
'env_cc --env-cflags --env-cppflags --sc-ccshared'
138136
)
139137
assert (
140138
comp.exes['compiler_cxx']

0 commit comments

Comments
 (0)