Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3678.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve clib builds reproducibility by sorting sources -- by :user:`danigm`
2 changes: 1 addition & 1 deletion setuptools/command/build_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def build_libraries(self, libraries):
"in 'libraries' option (library '%s'), "
"'sources' must be present and must be "
"a list of source filenames" % lib_name)
sources = list(sources)
sources = sorted(list(sources))

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

Expand Down
28 changes: 28 additions & 0 deletions setuptools/tests/test_build_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

import random
from distutils.errors import DistutilsSetupError
from setuptools.command.build_clib import build_clib
from setuptools.dist import Distribution
Expand Down Expand Up @@ -56,3 +57,30 @@ def test_build_libraries(self, mock_newer):
cmd.build_libraries(libs)
assert cmd.compiler.compile.call_count == 1
assert cmd.compiler.create_static_lib.call_count == 1

@mock.patch(
'setuptools.command.build_clib.newer_pairwise_group')
def test_build_libraries_reproducible(self, mock_newer):
dist = Distribution()
cmd = build_clib(dist)

# with that out of the way, let's see if the crude dependency
# system works
cmd.compiler = mock.MagicMock(spec=cmd.compiler)
mock_newer.return_value = ([], [])

original_sources = ['a-example.c', 'example.c']
sources = original_sources

obj_deps = {'': ('global.h',), 'example.c': ('example.h',)}
libs = [('example', {'sources': sources, 'obj_deps': obj_deps})]

cmd.build_libraries(libs)
computed_call_args = mock_newer.call_args[0]

while sources == original_sources:
sources = random.sample(original_sources, len(original_sources))
libs = [('example', {'sources': sources, 'obj_deps': obj_deps})]

cmd.build_libraries(libs)
assert computed_call_args == mock_newer.call_args[0]