From 95234bb9002dfb259d37125ae5382a404d0f5ab1 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Moreno Date: Mon, 14 Nov 2022 12:56:32 +0100 Subject: [PATCH 1/2] Make clib build reproducible by sorting sources Fix https://github.com/pypa/setuptools/issues/3678 --- changelog.d/3678.change.rst | 1 + setuptools/command/build_clib.py | 2 +- setuptools/tests/test_build_clib.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 changelog.d/3678.change.rst diff --git a/changelog.d/3678.change.rst b/changelog.d/3678.change.rst new file mode 100644 index 0000000000..9893f99fc8 --- /dev/null +++ b/changelog.d/3678.change.rst @@ -0,0 +1 @@ +Make clib builds reproducible by sorting sources -- by :user:`danigm` diff --git a/setuptools/command/build_clib.py b/setuptools/command/build_clib.py index 67ce2444ea..09483e69e5 100644 --- a/setuptools/command/build_clib.py +++ b/setuptools/command/build_clib.py @@ -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) diff --git a/setuptools/tests/test_build_clib.py b/setuptools/tests/test_build_clib.py index af9e7c6dc3..2d9273cdca 100644 --- a/setuptools/tests/test_build_clib.py +++ b/setuptools/tests/test_build_clib.py @@ -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 @@ -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] From 3ec0769aac15f588159eb88433c1d942c0bf34d7 Mon Sep 17 00:00:00 2001 From: danigm Date: Tue, 15 Nov 2022 17:17:11 +0100 Subject: [PATCH 2/2] Better changelog message in changelog.d/3678.change.rst Co-authored-by: Anderson Bravalheri --- changelog.d/3678.change.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/3678.change.rst b/changelog.d/3678.change.rst index 9893f99fc8..89d796d777 100644 --- a/changelog.d/3678.change.rst +++ b/changelog.d/3678.change.rst @@ -1 +1 @@ -Make clib builds reproducible by sorting sources -- by :user:`danigm` +Improve clib builds reproducibility by sorting sources -- by :user:`danigm`