Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make clib build reproducible by sorting sources #3679

Merged
merged 2 commits into from Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3678.change.rst
@@ -0,0 +1 @@
Make clib builds reproducible by sorting sources -- by :user:`danigm`
danigm marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion setuptools/command/build_clib.py
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
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]