Skip to content

Commit

Permalink
Fix building reproducible (#1540)
Browse files Browse the repository at this point in the history
* Sort regarding to file names if count value is the same

Should fix reproducibility which currently may vary in between builds in
the order the files are discovered in the file system.

* Use SOURCE_DATE_EPOCH for Last Updated message on web pages
  • Loading branch information
gusnan authored Mar 6, 2024
1 parent db023cf commit d56a2c5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
33 changes: 32 additions & 1 deletion docs/scripts/insert_timestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include "dawk.h"

int main(int argc, char **argv)
Expand All @@ -15,7 +18,35 @@ int main(int argc, char **argv)
char buf[64];
char const *version = "unknown";

time(&now);
char *source_date_epoch;
unsigned long long epoch;
char *endptr;

source_date_epoch = getenv("SOURCE_DATE_EPOCH");
if (source_date_epoch) {
errno = 0;
epoch = strtoull(source_date_epoch, &endptr, 10);
if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
|| (errno != 0 && epoch == 0)) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
if (endptr == source_date_epoch) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n", endptr);
exit(EXIT_FAILURE);
}
if (*endptr != '\0') {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n", endptr);
exit(EXIT_FAILURE);
}
if (epoch > ULONG_MAX) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to %lu but was found to be: %llu \n", ULONG_MAX, epoch);
exit(EXIT_FAILURE);
}
now = epoch;
} else {
now = time(NULL);
}
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S UTC", gmtime(&now));

if (argc > 1) {
Expand Down
12 changes: 10 additions & 2 deletions docs/scripts/scan_examples.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ typedef struct {
int index;
/* How many APIs are used in each example */
int count;
/* Store a pointer to the file string for comparison purposes */
char *filename;
} lookup_t;
static lookup_t *lookup;
static int compare(const void *pa, const void *pb) {
return ((const lookup_t *) pa)->count - ((const lookup_t *) pb)->count;
int val = ((const lookup_t *) pa)->count - ((const lookup_t *) pb)->count;

// if different count values, sort according to this.
if (val != 0) return val;

// But if the count value is the same, sort according to filename
return strcmp( (char*)((const lookup_t *) pa)->filename, (char*)((const lookup_t *) pb)->filename);
}

int main(int argc, char* argv[])
Expand All @@ -81,9 +89,9 @@ int main(int argc, char* argv[])
lookup = calloc(argc, sizeof(lookup_t));
for (j = 0; j < argc; ++j) {
lookup[j].index = j;
lookup[j].filename = argv[j];
}


for (j = 1; j < argc; ++j) {
d_open_input(argv[j]);
while (d_getline(line)) {
Expand Down

0 comments on commit d56a2c5

Please sign in to comment.