Skip to content

Commit d805c53

Browse files
committed
Improve clib builds reproducibility (#3679)
2 parents 8c58148 + 3ec0769 commit d805c53

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

changelog.d/3678.change.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve clib builds reproducibility by sorting sources -- by :user:`danigm`

setuptools/command/build_clib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def build_libraries(self, libraries):
2828
"in 'libraries' option (library '%s'), "
2929
"'sources' must be present and must be "
3030
"a list of source filenames" % lib_name)
31-
sources = list(sources)
31+
sources = sorted(list(sources))
3232

3333
log.info("building '%s' library", lib_name)
3434

setuptools/tests/test_build_clib.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
import random
56
from distutils.errors import DistutilsSetupError
67
from setuptools.command.build_clib import build_clib
78
from setuptools.dist import Distribution
@@ -56,3 +57,30 @@ def test_build_libraries(self, mock_newer):
5657
cmd.build_libraries(libs)
5758
assert cmd.compiler.compile.call_count == 1
5859
assert cmd.compiler.create_static_lib.call_count == 1
60+
61+
@mock.patch(
62+
'setuptools.command.build_clib.newer_pairwise_group')
63+
def test_build_libraries_reproducible(self, mock_newer):
64+
dist = Distribution()
65+
cmd = build_clib(dist)
66+
67+
# with that out of the way, let's see if the crude dependency
68+
# system works
69+
cmd.compiler = mock.MagicMock(spec=cmd.compiler)
70+
mock_newer.return_value = ([], [])
71+
72+
original_sources = ['a-example.c', 'example.c']
73+
sources = original_sources
74+
75+
obj_deps = {'': ('global.h',), 'example.c': ('example.h',)}
76+
libs = [('example', {'sources': sources, 'obj_deps': obj_deps})]
77+
78+
cmd.build_libraries(libs)
79+
computed_call_args = mock_newer.call_args[0]
80+
81+
while sources == original_sources:
82+
sources = random.sample(original_sources, len(original_sources))
83+
libs = [('example', {'sources': sources, 'obj_deps': obj_deps})]
84+
85+
cmd.build_libraries(libs)
86+
assert computed_call_args == mock_newer.call_args[0]

0 commit comments

Comments
 (0)