Skip to content

Commit 09952aa

Browse files
committed
📦 Normalize tmp dir path in built artifacts
This patch makes sure that the random temporary directory path does not end up in the built C-extensions. The effect is that downstreams will get reproducible build results.
1 parent 6cbe369 commit 09952aa

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

‎packaging/pep517_backend/_backend.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def _exclude_dir_path(
261261

262262

263263
@contextmanager
264-
def _in_temporary_directory(src_dir: Path) -> _c.Iterator[None]:
264+
def _in_temporary_directory(src_dir: Path) -> _c.Iterator[Path]:
265265
with TemporaryDirectory(prefix='.tmp-yarl-pep517-') as tmp_dir:
266266
tmp_dir_path = Path(tmp_dir)
267267
root_tmp_dir_path = tmp_dir_path.parent
@@ -276,7 +276,7 @@ def _in_temporary_directory(src_dir: Path) -> _c.Iterator[None]:
276276
symlinks=True,
277277
)
278278
os.chdir(tmp_src_dir)
279-
yield
279+
yield tmp_src_dir
280280

281281

282282
@contextmanager
@@ -356,12 +356,13 @@ def maybe_prebuild_c_extensions(
356356
stacklevel=999,
357357
)
358358

359+
original_src_dir = Path.cwd().resolve()
359360
build_dir_ctx = (
360361
nullcontext()
361362
if build_inplace
362-
else _in_temporary_directory(src_dir=Path.cwd().resolve())
363+
else _in_temporary_directory(src_dir=original_src_dir)
363364
)
364-
with build_dir_ctx:
365+
with build_dir_ctx as tmp_build_dir:
365366
config = _get_local_cython_config()
366367

367368
cythonize_args = _make_cythonize_cli_args_from_config(
@@ -371,6 +372,8 @@ def maybe_prebuild_c_extensions(
371372
with _patched_cython_env(
372373
config['env'],
373374
cython_line_tracing_requested=cython_line_tracing_requested,
375+
original_source_directory=original_src_dir,
376+
temporary_build_directory=tmp_build_dir,
374377
):
375378
_cythonize_cli_cmd(cythonize_args) # type: ignore[no-untyped-call]
376379
with patched_distutils_cmd_install():

‎packaging/pep517_backend/_cython_configuration.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ def patched_env(
184184
env: dict[str, str],
185185
*,
186186
cython_line_tracing_requested: bool,
187+
original_source_directory: Path | None = None,
188+
temporary_build_directory: Path | None = None,
187189
) -> _c.Iterator[None]:
188190
"""Temporary set given env vars.
189191
@@ -224,6 +226,16 @@ def patched_env(
224226
'-DNDEBUG', # disable assertions
225227
)
226228
),
229+
*(
230+
# In-tree mode:
231+
()
232+
if temporary_build_directory is None
233+
# Temporary build directory mode:
234+
else (
235+
'-ffile-prefix-map='
236+
f'{temporary_build_directory!s}={original_source_directory!s}',
237+
)
238+
),
227239
# Finally, append the user-set env var, ensuring its top priority:
228240
orig_env.get('CFLAGS', ''),
229241
# Last thing, strip spaces caused by empty leading/trailing flags:

0 commit comments

Comments
 (0)