File reproducible.patch of Package blender
commit 2115054bb8a41bb7ddffce32e396d9ffced300b1
Author: Bernhard M. Wiedemann <bwiedemann@suse.de>
Date: Sat Sep 7 06:19:50 2019 +0200
Sort list of .dat files
Sort list of .dat files
in .png generation to make builds reproducible.
See https://reproducible-builds.org/ for why this matters.
Note: scandir is only available on POSIX-compliant platforms (Linux,
BSD, MacOSX, cygwin) - so others would need some compat layer.
Reviewers: mont29
Differential Revision: https://developer.blender.org/D5858
Index: b/source/blender/datatoc/datatoc_icon.c
===================================================================
--- a/source/blender/datatoc/datatoc_icon.cc
+++ b/source/blender/datatoc/datatoc_icon.cc
@@ -416,9 +416,10 @@ static bool icon_merge(struct IconMergeC
static bool icondir_to_png(const char *path_src, const char *file_dst)
{
/* Takes a path full of 'dat' files and writes out */
- DIR *dir;
- const dirent *fname;
+ struct dirent **namelist;
+ int dirn;
+ dirent *fname;
char filepath[1024];
int found = 0, fail = 0;
IconMergeContext context;
@@ -429,8 +430,8 @@ static bool icondir_to_png(const char *p
icon_merge_context_init(&context);
errno = 0;
- dir = opendir(path_src);
- if (dir == nullptr) {
+ dirn = scandir(path_src, &namelist, nullptr, alphasort);
+ if (dirn == -1) {
printf(
"%s: failed to dir '%s', (%s)\n", __func__, path_src, errno ? strerror(errno) : "unknown");
return false;
@@ -436,7 +437,8 @@ static bool icondir_to_png(const char *p
return false;
}
- while ((fname = readdir(dir)) != nullptr) {
+ while (dirn--) {
+ fname = namelist[dirn];
if (path_test_extension(fname->d_name, ".dat")) {
if (!path_join(filepath, sizeof(filepath), path_src, fname->d_name)) {
printf("%s: path is too long (%s, %s)\n", __func__, path_src, fname->d_name);
@@ -449,11 +451,12 @@ static bool icondir_to_png(const char *p
fail++;
}
}
+ free(fname);
}
icon_merge_context_free(&context);
- closedir(dir);
+ free(namelist);
if (found == 0) {
printf("%s: dir '%s' has no icons\n", __func__, path_src);
Index: b/source/blender/datatoc/datatoc_icon.py
===================================================================
--- a/source/blender/datatoc/datatoc_icon.py
+++ b/source/blender/datatoc/datatoc_icon.py
@@ -98,7 +98,7 @@ def icondir_to_png(path_src, file_dst):
import os
import array
- files = [os.path.join(path_src, f) for f in os.listdir(path_src) if f.endswith(".dat")]
+ files = [os.path.join(path_src, f) for f in sorted(os.listdir(path_src)) if f.endswith(".dat")]
# First check if we need to bother.
if os.path.exists(file_dst):