Skip to content

Commit e87a64d

Browse files
marko-bekhtasebersole
authored andcommitted
HHH-18488 Configure archive tasks to produce reproducible archives
1 parent 43745c9 commit e87a64d

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ plugins {
3838

3939
apply from: file( 'gradle/module.gradle' )
4040

41-
4241
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4342
// Release Task
4443

ci/compare-build-results.sh

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
3+
# This is a simple script to check if builds are reproducible. The steps are:
4+
# 1. Build ORM with `./gradlew --no-daemon clean publishToMavenLocal --no-build-cache -Dmaven.repo.local=some-path/out/build1`
5+
# 2. Build ORM with `./gradlew --no-daemon clean publishToMavenLocal --no-build-cache -Dmaven.repo.local=some-path/out/build2` second time pointing to a different local maven repository to publish
6+
# 3. Compare the build results with sh ./ci/compare-build-results.sh some-path/out/build1 some-path/out/build2
7+
# 4. The generated .buildcompare file will also contain the diffscope commands to see/compare the problematic build artifacts
8+
9+
outputDir1=$1
10+
outputDir2=$2
11+
outputDir1=${outputDir1%/}
12+
outputDir2=${outputDir2%/}
13+
14+
ok=()
15+
okFiles=()
16+
ko=()
17+
koFiles=()
18+
19+
for f in `find ${outputDir1} -type f | grep -v "javadoc.jar$" | grep -v "maven-metadata-local.xml$" | sort`
20+
do
21+
flocal=${f#$outputDir1}
22+
# echo "comparing ${flocal}"
23+
sha1=`shasum -a 512 $f | cut -f 1 -d ' '`
24+
sha2=`shasum -a 512 $outputDir2$flocal | cut -f 1 -d ' '`
25+
# echo "$sha1"
26+
# echo "$sha2"
27+
if [ "$sha1" = "$sha2" ]; then
28+
ok+=($flocal)
29+
okFiles+=(${flocal##*/})
30+
else
31+
ko+=($flocal)
32+
koFiles+=(${flocal##*/})
33+
fi
34+
done
35+
36+
# generate .buildcompare
37+
buildcompare=".buildcompare"
38+
echo "ok=${#ok[@]}" >> ${buildcompare}
39+
echo "ko=${#ko[@]}" >> ${buildcompare}
40+
echo "okFiles=\"${okFiles[@]}\"" >> ${buildcompare}
41+
echo "koFiles=\"${koFiles[@]}\"" >> ${buildcompare}
42+
echo "" >> ${buildcompare}
43+
echo "# see what caused the mismatch in the checksum by executing the following diffscope commands" >> ${buildcompare}
44+
for f in ${ko[@]}
45+
do
46+
echo "# diffoscope $outputDir1$f $outputDir2$f" >> ${buildcompare}
47+
done
48+
49+
if [ ${#ko[@]} -eq 0 ]; then
50+
exit 0
51+
else
52+
exit 1
53+
fi

gradle/java-module.gradle

+9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ if ( !project.description ) {
5757
project.description = "The Hibernate ORM $project.name module"
5858
}
5959

60+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61+
// Reproducible Builds
62+
63+
// https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives
64+
// Configure archive tasks to produce reproducible archives:
65+
tasks.withType(AbstractArchiveTask).configureEach {
66+
preserveFileTimestamps = false
67+
reproducibleFileOrder = true
68+
}
6069

6170
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6271
// Configurations and Dependencies

tooling/hibernate-gradle-plugin/hibernate-gradle-plugin.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ gradlePlugin {
5757
}
5858
}
5959

60+
tasks.withType(AbstractArchiveTask).configureEach {
61+
preserveFileTimestamps = false
62+
reproducibleFileOrder = true
63+
}
6064

6165
test {
6266
useJUnitPlatform()
@@ -153,4 +157,4 @@ gradle.taskGraph.whenReady { tg ->
153157
}
154158
}
155159
}
156-
}
160+
}

0 commit comments

Comments
 (0)