|
6 | 6 | import sys
|
7 | 7 | import os
|
8 | 8 | import re
|
9 |
| -import warnings |
10 | 9 |
|
11 | 10 | from distutils.errors import (
|
12 | 11 | CompileError,
|
@@ -924,37 +923,39 @@ def find_library_file(self, dirs, lib, debug=0):
|
924 | 923 | def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
|
925 | 924 | if output_dir is None:
|
926 | 925 | output_dir = ''
|
927 |
| - obj_names = [] |
928 |
| - for src_name in source_filenames: |
929 |
| - base, ext = os.path.splitext(src_name) |
930 |
| - base = self._mangle_base(base) |
931 |
| - if ext not in self.src_extensions: |
932 |
| - raise UnknownFileError( |
933 |
| - "unknown file type '{}' (from '{}')".format(ext, src_name) |
934 |
| - ) |
935 |
| - if strip_dir: |
936 |
| - base = os.path.basename(base) |
937 |
| - obj_names.append(os.path.join(output_dir, base + self.obj_extension)) |
938 |
| - return obj_names |
| 926 | + return list( |
| 927 | + self._make_out_path(output_dir, strip_dir, src_name) |
| 928 | + for src_name in source_filenames |
| 929 | + ) |
| 930 | + |
| 931 | + @property |
| 932 | + def out_extensions(self): |
| 933 | + return dict.fromkeys(self.src_extensions, self.obj_extension) |
| 934 | + |
| 935 | + def _make_out_path(self, output_dir, strip_dir, src_name): |
| 936 | + base, ext = os.path.splitext(src_name) |
| 937 | + base = self._make_relative(base) |
| 938 | + try: |
| 939 | + new_ext = self.out_extensions[ext] |
| 940 | + except LookupError: |
| 941 | + raise UnknownFileError( |
| 942 | + "unknown file type '{}' (from '{}')".format(ext, src_name) |
| 943 | + ) |
| 944 | + if strip_dir: |
| 945 | + base = os.path.basename(base) |
| 946 | + return os.path.join(output_dir, base + new_ext) |
939 | 947 |
|
940 | 948 | @staticmethod
|
941 |
| - def _mangle_base(base): |
| 949 | + def _make_relative(base): |
942 | 950 | """
|
943 |
| - For unknown reasons, absolute paths are mangled. |
| 951 | + In order to ensure that a filename always honors the |
| 952 | + indicated output_dir, make sure it's relative. |
| 953 | + Ref python/cpython#37775. |
944 | 954 | """
|
945 | 955 | # Chop off the drive
|
946 | 956 | no_drive = os.path.splitdrive(base)[1]
|
947 | 957 | # If abs, chop off leading /
|
948 |
| - rel = no_drive[os.path.isabs(no_drive) :] |
949 |
| - if rel != base: |
950 |
| - msg = ( |
951 |
| - f"Absolute path {base!r} is being replaced with a " |
952 |
| - f"relative path {rel!r} for outputs. This behavior is " |
953 |
| - "deprecated. If this behavior is desired, please " |
954 |
| - "comment in pypa/distutils#169." |
955 |
| - ) |
956 |
| - warnings.warn(msg, DeprecationWarning) |
957 |
| - return rel |
| 958 | + return no_drive[os.path.isabs(no_drive) :] |
958 | 959 |
|
959 | 960 | def shared_object_filename(self, basename, strip_dir=0, output_dir=''):
|
960 | 961 | assert output_dir is not None
|
|
0 commit comments