-
-
Notifications
You must be signed in to change notification settings - Fork 249
/
repro_common.sh
executable file
·499 lines (445 loc) · 20.1 KB
/
repro_common.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
#!/bin/bash
# shellcheck disable=SC2086
# ********************************************************************************
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made
# available under the terms of the Apache Software License 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: Apache-2.0
# ********************************************************************************
TEMURIN_TOOLS_BINREPL="temurin.tools.BinRepl"
# Expand JDK jmods & zips to process binaries within
function expandJDK() {
local JDK_DIR="$1"
local OS="$2"
local JDK_ROOT="$1"
local JDK_BIN_DIR="${JDK_ROOT}_CP/bin"
if [[ "$OS" =~ Darwin* ]]; then
JDK_ROOT=$(realpath ${JDK_DIR}/../../)
JDK_BIN_DIR="${JDK_ROOT}_CP/Contents/Home/bin"
fi
mkdir "${JDK_ROOT}_CP"
cp -R ${JDK_ROOT}/* ${JDK_ROOT}_CP
echo "Expanding the 'modules' Image to compare extracted files"
modulesFile="${JDK_DIR}/lib/modules"
mkdir "${JDK_DIR}/lib/modules_extracted"
extractedDir="${JDK_DIR}/lib/modules_extracted"
if [[ "$OS" =~ CYGWIN* ]]; then
modulesFile=$(cygpath -w $modulesFile)
extractedDir=$(cygpath -w $extractedDir)
fi
"${JDK_BIN_DIR}/jimage" extract --dir "${extractedDir}" "${modulesFile}"
rm "${JDK_DIR}/lib/modules"
echo "Expanding the 'src.zip' to normalize file permissions"
unzip "${JDK_DIR}/lib/src.zip" -d "${JDK_DIR}/lib/src_zip_expanded" 1> /dev/null
rm "${JDK_DIR}/lib/src.zip"
echo "Expanding jmods to process binaries within"
FILES=$(find "${JDK_DIR}" -type f -path '*.jmod')
for f in $FILES
do
base=$(basename "$f")
dir=$(dirname "$f")
expand_dir="${dir}/expanded_${base}"
mkdir -p "${expand_dir}"
if [[ "$OS" =~ CYGWIN* ]]; then
f=$(cygpath -w $f)
expand_dir=$(cygpath -w $expand_dir)
fi
"${JDK_BIN_DIR}/jmod" extract --dir "${expand_dir}" "$f"
rm "$f"
done
echo "Expanding the 'jrt-fs.jar' to remove signatures from within.."
mkdir "${JDK_DIR}/lib/jrt-fs-expanded"
unzip -d "${JDK_DIR}/lib/jrt-fs-expanded" "${JDK_DIR}/lib/jrt-fs.jar" 1> /dev/null
rm "${JDK_DIR}/lib/jrt-fs.jar"
mkdir -p "${JDK_DIR}/jmods/expanded_java.base.jmod/lib/jrt-fs-expanded"
unzip -d "${JDK_DIR}/jmods/expanded_java.base.jmod/lib/jrt-fs-expanded" "${JDK_DIR}/jmods/expanded_java.base.jmod/lib/jrt-fs.jar" 1> /dev/null
rm "${JDK_DIR}/jmods/expanded_java.base.jmod/lib/jrt-fs.jar"
echo "Expanding 'ct.sym' to workaround zip timestamp differences (https://bugs.openjdk.org/browse/JDK-8327466)"
mkdir "${JDK_DIR}/lib/ct-sym-expanded"
unzip -d "${JDK_DIR}/lib/ct-sym-expanded" "${JDK_DIR}/lib/ct.sym" 1> /dev/null
rm "${JDK_DIR}/lib/ct.sym"
mkdir -p "${JDK_DIR}/jmods/expanded_jdk.compiler.jmod/lib/ct-sym-expanded"
unzip -d "${JDK_DIR}/jmods/expanded_jdk.compiler.jmod/lib/ct-sym-expanded" "${JDK_DIR}/jmods/expanded_jdk.compiler.jmod/lib/ct.sym" 1> /dev/null
rm "${JDK_DIR}/jmods/expanded_jdk.compiler.jmod/lib/ct.sym"
rm -rf "${JDK_ROOT}_CP"
}
# Process SystemModules classes to remove ModuleHashes$Builder differences due to Signatures
# 1. javap
# 2. search for line: // Method jdk/internal/module/ModuleHashes$Builder.hashForModule:(Ljava/lang/String;[B)Ljdk/internal/module/ModuleHashes$Builder;
# 3. followed 3 lines later by: // String <module>
# 4. then remove all lines until next: invokevirtual
# 5. remove Last modified, Classfile and SHA-256 checksum javap artefact statements
function removeSystemModulesHashBuilderParams() {
# Key strings
moduleHashesFunction="// Method jdk/internal/module/ModuleHashes\$Builder.hashForModule:(Ljava/lang/String;[B)Ljdk/internal/module/ModuleHashes\$Builder;"
moduleString="// String "
virtualFunction="invokevirtual"
systemModules="SystemModules\$0.class SystemModules\$all.class SystemModules\$default.class"
for systemModule in $systemModules
do
FILES=$(find "${JDK_DIR}" -type f -name "$systemModule")
for f in $FILES
do
if [[ "$OS" =~ CYGWIN* ]]; then
ff=$(cygpath -w $f)
else
ff=$f
fi
javap -v -sysinfo -l -p -c -s -constants "$ff" > "$f.javap.tmp"
rm "$f"
# Remove "instruction number:" prefix, so we can just match code
if [[ $(uname) =~ Darwin* ]]; then
sed -i "" -E 's/^[[:space:]]+[0-9]+:(.*)/\1/' "$f.javap.tmp"
else
sed -i -E 's/^[[:space:]]+[0-9]+:(.*)/\1/' "$f.javap.tmp"
fi
cc=99
found=false
while IFS= read -r line
do
cc=$((cc+1))
# Detect hashForModule function
if [[ "$line" =~ .*"$moduleHashesFunction".* ]]; then
cc=0
fi
# 3rd instruction line is the Module string to confirm entry
if [[ "$cc" -eq 3 ]] && [[ "$line" =~ .*"$moduleString"[a-z\.]+.* ]]; then
found=true
module=$(echo "$line" | tr -s ' ' | tr -d '\r' | cut -d' ' -f6)
export module
fi
# hasForModule function section finishes upon finding invokevirtual
if [[ "$found" = true ]] && [[ "$line" =~ .*"$virtualFunction".* ]]; then
found=false
fi
if [[ "$found" = false ]]; then
echo "$line" >> "$f.javap.tmp2"
fi
done < "$f.javap.tmp"
rm "$f.javap.tmp"
grep -v "Last modified\|Classfile\|SHA-256 checksum" "$f.javap.tmp2" > "$f.javap"
rm "$f.javap.tmp2"
done
done
echo "Successfully removed all SystemModules jdk.jpackage hash differences from ${JDK_DIR}"
}
# Required for Vendor "Comparable Builds"
#
# Remove the Windows EXE/DLL timestamps and internal VS CRC and debug repro hex values
# The Windows PE format contains various values determined from the binary content
# which will vary due to the different Vendor branding
# timestamp - Used to be an actual timestamp but MSFT changed this to a checksum determined from binary content
# checksum - A checksum value of the binary
# reprohex - A hex UUID to identify the binary version, again generated from binary content
function removeWindowsNonComparableData() {
echo "Removing EXE/DLL timestamps, CRC and debug repro hex from ${JDK_DIR}"
# We need to do this for all executables if patching VS_VERSION_INFO
if [[ "$PATCH_VS_VERSION_INFO" = true ]]; then
FILES=$(find "${JDK_DIR}" -type f -path '*.exe' && find "${JDK_DIR}" -type f -path '*.dll')
else
FILES=$(find "${JDK_DIR}" -type f -name 'jvm.dll')
fi
for ff in $FILES
do
f=$(cygpath -w $ff)
echo "Removing EXE/DLL non-comparable timestamp, CRC, debug repro hex from $f"
# Determine non-comparable data using dumpbin
dmpfile="$ff.dumpbin.tmp"
rm -f "$dmpfile"
if ! dumpbin "$f" /HEADERS > "$dmpfile"; then
echo " FAILED == > dumpbin \"$f\" /ALL > $dmpfile"
exit 1
fi
# Determine non-comparable stamps and hex codes from dumpbin output
timestamp=$(grep "time date stamp" "$dmpfile" | head -1 | tr -s ' ' | cut -d' ' -f2)
checksum=$(grep "checksum" "$dmpfile" | head -1 | tr -s ' ' | cut -d' ' -f2)
reprohex=$(grep "${timestamp} repro" "$dmpfile" | head -1 | tr -s ' ' | cut -d' ' -f7-38 | tr ' ' ':' | tr -d '\r')
reprohexhalf=$(grep "${timestamp} repro" "$dmpfile" | head -1 | tr -s ' ' | cut -d' ' -f7-22 | tr ' ' ':' | tr -d '\r')
rm -f "$dmpfile"
# Neutralize reprohex string
if [ -n "$reprohex" ]; then
if ! java "$TEMURIN_TOOLS_BINREPL" --inFile "$f" --outFile "$f" --hex "${reprohex}-AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA"; then
echo " FAILED ==> java $TEMURIN_TOOLS_BINREPL --inFile \"$f\" --outFile \"$f\" --hex \"${reprohex}-AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA\""
exit 1
fi
fi
# Neutralize timestamp hex string
hexstr="00000000"
timestamphex=${hexstr:0:-${#timestamp}}$timestamp
timestamphexLE="${timestamphex:6:2}:${timestamphex:4:2}:${timestamphex:2:2}:${timestamphex:0:2}"
if ! java "$TEMURIN_TOOLS_BINREPL" --inFile "$f" --outFile "$f" --hex "${timestamphexLE}-AA:AA:AA:AA"; then
echo " FAILED ==> java $TEMURIN_TOOLS_BINREPL --inFile \"$f\" --outFile \"$f\" --hex \"${timestamphexLE}-AA:AA:AA:AA\""
exit 1
fi
if [ -n "$reprohexhalf" ]; then
if ! java "$TEMURIN_TOOLS_BINREPL" --inFile "$f" --outFile "$f" --hex "${reprohexhalf}-AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA"; then
echo " FAILED ==> java $TEMURIN_TOOLS_BINREPL --inFile \"$f\" --outFile \"$f\" --hex \"${reprohexhalf}-AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA\""
exit 1
fi
fi
# Neutralize checksum string
# Prefix checksum to 8 digits
hexstr="00000000"
checksumhex=${hexstr:0:-${#checksum}}$checksum
checksumhexLE="${checksumhex:6:2}:${checksumhex:4:2}:${checksumhex:2:2}:${checksumhex:0:2}"
if ! java "$TEMURIN_TOOLS_BINREPL" --inFile "$f" --outFile "$f" --hex "${checksumhexLE}-AA:AA:AA:AA" --firstOnly --32bitBoundaryOnly; then
echo " FAILED ==> java $TEMURIN_TOOLS_BINREPL --inFile \"$f\" --outFile \"$f\" --hex \"${checksumhexLE}-AA:AA:AA:AA\" --firstOnly --32bitBoundaryOnly"
exit 1
fi
done
echo "Successfully removed all EXE/DLL timestamps, CRC and debug repro hex from ${JDK_DIR}"
}
# Required for Vendor "Comparable Builds"
#
# Remove the MACOS dylib non-comparable data
# MacOS Mach-O format stores a uuid value that consists of a "hash" of the code and
# the some length part of the user's build folder.
# See https://github.com/adoptium/temurin-build/issues/2899#issuecomment-1153757419
function removeMacOSNonComparableData() {
echo "Removing MacOS dylib non-comparable UUID from ${JDK_DIR}"
FILES=$(find "${MAC_JDK_ROOT}" \( -type f -and -path '*.dylib' -or -path '*/bin/*' -or -path '*/lib/jspawnhelper' -not -path '*/modules_extracted/*' -or -path '*/jpackageapplauncher*' \))
for f in $FILES
do
uuid=$(otool -l "$f" | grep "uuid" | tr -s " " | tr -d "-" | cut -d" " -f3)
if [ -z "$uuid" ]; then
echo " FAILED ==> otool -l \"$f\" | grep \"uuid\" | tr -s \" \" | tr -d \"-\" | cut -d\" \" -f3"
exit 1
else
# Format uuid for BINREPL
uuidhex="${uuid:0:2}:${uuid:2:2}:${uuid:4:2}:${uuid:6:2}:${uuid:8:2}:${uuid:10:2}:${uuid:12:2}:${uuid:14:2}:${uuid:16:2}:${uuid:18:2}:${uuid:20:2}:${uuid:22:2}:${uuid:24:2}:${uuid:26:2}:${uuid:28:2}:${uuid:30:2}"
if ! java "$TEMURIN_TOOLS_BINREPL" --inFile "$f" --outFile "$f" --hex "${uuidhex}-AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA" --firstOnly; then
echo " FAILED ==> java \"$TEMURIN_TOOLS_BINREPL\" --inFile \"$f\" --outFile \"$f\" --hex \"${uuidhex}-AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA\" --firstOnly"
exit 1
fi
fi
done
echo "Successfully removed all MacOS dylib non-comparable UUID from ${JDK_DIR}"
}
# Normalize the following ModuleAttributes that can be ordered differently
# depending on how the vendor has signed and re-packed the JMODs
# - ModuleResolution:
# - ModuleTarget:
# java.base also requires the dependent module "hash:" values to be excluded
# as they differ due to the Signatures
function processModuleInfo() {
if [[ "$OS" =~ CYGWIN* ]] || [[ "$OS" =~ Darwin* ]]; then
echo "Normalizing ModuleAttributes order in module-info.class, converting to javap"
moduleAttr="ModuleResolution ModuleTarget"
FILES=$(find "${JDK_DIR}" -type f -name "module-info.class")
for f in $FILES
do
if [[ "$OS" =~ CYGWIN* ]]; then
ff=$(cygpath -w $f)
else
ff=$f
fi
javap -v -sysinfo -l -p -c -s -constants "$ff" > "$f.javap.tmp"
rm "$f"
cc=99
foundAttr=false
attrName=""
# Clear any attr tmp files
for attr in $moduleAttr
do
rm -f "$f.javap.$attr"
done
while IFS= read -r line
do
cc=$((cc+1))
# Module attr have only 1 line definition
if [[ "$foundAttr" = true ]] && [[ "$cc" -gt 1 ]]; then
foundAttr=false
attrName=""
fi
# If not processing an attr then check for attr
if [[ "$foundAttr" = false ]]; then
for attr in $moduleAttr
do
if [[ "$line" =~ .*"$attr:".* ]]; then
cc=0
foundAttr=true
attrName="$attr"
fi
done
fi
# Echo attr to attr tmp file, otherwise to tmp2
if [[ "$foundAttr" = true ]]; then
echo "$line" >> "$f.javap.$attrName"
else
echo "$line" >> "$f.javap.tmp2"
fi
done < "$f.javap.tmp"
rm "$f.javap.tmp"
# Remove javap Classfile and timestamp and SHA-256 hash
if [[ "$f" =~ .*"java.base".* ]]; then
grep -v "Last modified\|Classfile\|SHA-256 checksum\|hash:" "$f.javap.tmp2" > "$f.javap"
else
grep -v "Last modified\|Classfile\|SHA-256 checksum" "$f.javap.tmp2" > "$f.javap"
fi
rm "$f.javap.tmp2"
# Append any ModuleAttr tmp files
for attr in $moduleAttr
do
if [[ -f "$f.javap.$attr" ]]; then
cat "$f.javap.$attr" >> "$f.javap"
fi
rm -f "$f.javap.$attr"
done
done
fi
}
# Remove windowns generate classes jdk/bin/server/classes.jsa & jdk/bin/server/classes_nocoops.jsa
function removeGeneratedClasses() {
local JDK_DIR="$1"
local OS="$2"
if [[ "$OS" =~ CYGWIN* ]] || [[ "$OS" =~ Darwin* ]]; then
rm -rf "$JDK_DIR/bin/server/classes.jsa"
rm -rf "$JDK_DIR/bin/server/classes_nocoops.jsa"
fi
}
# Remove all Signatures
function removeSignatures() {
local JDK_DIR="$1"
local OS="$2"
if [[ "$OS" =~ CYGWIN* ]]; then
# signtool should be on PATH
signToolPath="signtool"
echo "Removing all Signatures from ${JDK_DIR}"
FILES=$(find "${JDK_DIR}" -type f -name '*.exe' -o -name '*.dll')
for f in $FILES
do
f=$(cygpath -w $f)
rc=0
"$signToolPath" remove /s "$f" 1> /dev/null 2>&1 || rc=$?
# if [ $rc -ne 0 ]; then
# echo "Removing signature from $f failed"
# fi
done
elif [[ "$OS" =~ Darwin* ]]; then
MAC_JDK_ROOT="${JDK_DIR}/../.."
echo "Removing all Signatures from ${MAC_JDK_ROOT}"
if [ ! -d "${MAC_JDK_ROOT}/Contents" ]; then
echo "Error: ${MAC_JDK_ROOT} does not contain the MacOS JDK Contents directory"
exit 1
fi
# Remove any extended app attr
xattr -cr "${MAC_JDK_ROOT}"
FILES=$(find "${MAC_JDK_ROOT}" \( -type f -and -path '*.dylib' -or -path '*/bin/*' -or -path '*/lib/jspawnhelper' -not -path '*/modules_extracted/*' -or -path '*/jpackageapplauncher*' \))
for f in $FILES
do
echo "Removing signature from $f"
codesign --remove-signature "$f" 1> /dev/null
done
fi
}
# Sign with temporary Signature, which when removed results in determinisitic binary length
function tempSign() {
local JDK_DIR="$1"
local OS="$2"
if [[ "$OS" =~ CYGWIN* ]]; then
# signtool should be on PATH
signToolPath="signtool"
echo "Adding temp Signatures for ${JDK_DIR}"
selfCert="test"
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout $selfCert.key -out $selfCert.crt -subj "/CN=example.com" -addext "subjectAltName=DNS:example.com,DNS:*.example.com,IP:10.0.0.1"
openssl pkcs12 -export -passout pass:test -out $selfCert.pfx -inkey $selfCert.key -in $selfCert.crt
FILES=$(find "${JDK_DIR}" -type f -name '*.exe' -o -name '*.dll')
for f in $FILES
do
rc=0
f=$(cygpath -w $f)
"$signToolPath" sign /f $selfCert.pfx /p test /fd SHA256 $f 1> /dev/null || rc=$?
if [ $rc -ne 0 ]; then
echo "Adding Temp Signature for $f failed"
fi
done
elif [[ "$OS" =~ Darwin* ]]; then
MAC_JDK_ROOT="${JDK_DIR}/../../Contents"
echo "Adding temp Signatures for ${MAC_JDK_ROOT}"
FILES=$(find "${MAC_JDK_ROOT}" \( -type f -and -path '*.dylib' -or -path '*/bin/*' -or -path '*/lib/jspawnhelper' -not -path '*/modules_extracted/*' -or -path '*/jpackageapplauncher*' \))
for f in $FILES
do
echo "Signing $f with ad-hoc signing"
# Sign both with same local Certificate, this adjusts __LINKEDIT vmsize identically
codesign -s "-" "$f"
done
fi
}
# If performing a reproducible compare to a non temurin build-scripts built JDK
# then remove certain Temurin build-script added metadata or different files
function cleanTemurinFiles() {
local DIR="$1"
echo "Cleaning Temurin build-scripts specific files and metadata from ${DIR}"
echo "Removing Temurin NOTICE file from $DIR"
rm "${DIR}"/NOTICE
if [[ $(uname) =~ Darwin* ]]; then
echo "Removing Temurin specific lines from release file in $DIR"
sed -i "" '/^BUILD_SOURCE=.*$/d' "${DIR}/release"
sed -i "" '/^BUILD_SOURCE_REPO=.*$/d' "${DIR}/release"
sed -i "" '/^SOURCE_REPO=.*$/d' "${DIR}/release"
sed -i "" '/^FULL_VERSION=.*$/d' "${DIR}/release"
sed -i "" '/^SEMANTIC_VERSION=.*$/d' "${DIR}/release"
sed -i "" '/^BUILD_INFO=.*$/d' "${DIR}/release"
sed -i "" '/^JVM_VARIANT=.*$/d' "${DIR}/release"
sed -i "" '/^JVM_VERSION=.*$/d' "${DIR}/release"
sed -i "" '/^IMAGE_TYPE=.*$/d' "${DIR}/release"
echo "Removing SOURCE= from ${DIR}/release file, as Temurin builds from Adoptium mirror repo _adopt tag"
sed -i "" '/^SOURCE=.*$/d' "${DIR}/release"
else
echo "Removing Temurin specific lines from release file in $DIR"
sed -i '/^BUILD_SOURCE=.*$/d' "${DIR}/release"
sed -i '/^BUILD_SOURCE_REPO=.*$/d' "${DIR}/release"
sed -i '/^SOURCE_REPO=.*$/d' "${DIR}/release"
sed -i '/^FULL_VERSION=.*$/d' "${DIR}/release"
sed -i '/^SEMANTIC_VERSION=.*$/d' "${DIR}/release"
sed -i '/^BUILD_INFO=.*$/d' "${DIR}/release"
sed -i '/^JVM_VARIANT=.*$/d' "${DIR}/release"
sed -i '/^JVM_VERSION=.*$/d' "${DIR}/release"
sed -i '/^IMAGE_TYPE=.*$/d' "${DIR}/release"
echo "Removing SOURCE= from ${DIR}/release file, as Temurin builds from Adoptium mirror repo _adopt tag"
sed -i '/^SOURCE=.*$/d' "${DIR}/release"
fi
echo "Removing cacerts file, as Temurin builds with different Mozilla cacerts"
find "${DIR}" -type f -name "cacerts" -delete
echo "Removing any JDK image files not shipped by Temurin(*.pdb, *.pdb, demo) in $DIR"
find "${DIR}" -type f -name "*.pdb" -delete
find "${DIR}" -type f -name "*.map" -delete
rm -rf "${DIR}/demo"
}
# Temurin release file metadata BUILD_INFO/SOURCE can/will be different
function cleanTemurinBuildInfo() {
local DIR="$1"
echo "Cleaning any Temurin build-scripts release file BUILD_INFO from ${DIR}"
if [[ $(uname) =~ Darwin* ]]; then
sed -i "" '/^BUILD_SOURCE=.*$/d' "${DIR}/release"
sed -i "" '/^BUILD_SOURCE_REPO=.*$/d' "${DIR}/release"
sed -i "" '/^BUILD_INFO=.*$/d' "${DIR}/release"
else
sed -i '/^BUILD_SOURCE=.*$/d' "${DIR}/release"
sed -i '/^BUILD_SOURCE_REPO=.*$/d' "${DIR}/release"
sed -i '/^BUILD_INFO=.*$/d' "${DIR}/release"
fi
}
# Patch the Vendor strings from the BootJDK in jrt-fs/jar MANIFEST
function patchManifests() {
local JDK_DIR="$1"
if [[ $(uname) =~ Darwin* ]]; then
echo "Removing jrt-fs.jar MANIFEST.MF BootJDK vendor string lines"
sed -i "" '/^Implementation-Vendor:.*$/d' "${JDK_DIR}/lib/jrt-fs-expanded/META-INF/MANIFEST.MF"
sed -i "" '/^Created-By:.*$/d' "${JDK_DIR}/lib/jrt-fs-expanded/META-INF/MANIFEST.MF"
sed -i "" '/^Implementation-Vendor:.*$/d' "${JDK_DIR}/jmods/expanded_java.base.jmod/lib/jrt-fs-expanded/META-INF/MANIFEST.MF"
sed -i "" '/^Created-By:.*$/d' "${JDK_DIR}/jmods/expanded_java.base.jmod/lib/jrt-fs-expanded/META-INF/MANIFEST.MF"
else
echo "Removing jrt-fs.jar MANIFEST.MF BootJDK vendor string lines"
sed -i '/^Implementation-Vendor:.*$/d' "${JDK_DIR}/lib/jrt-fs-expanded/META-INF/MANIFEST.MF"
sed -i '/^Created-By:.*$/d' "${JDK_DIR}/lib/jrt-fs-expanded/META-INF/MANIFEST.MF"
sed -i '/^Implementation-Vendor:.*$/d' "${JDK_DIR}/jmods/expanded_java.base.jmod/lib/jrt-fs-expanded/META-INF/MANIFEST.MF"
sed -i '/^Created-By:.*$/d' "${JDK_DIR}/jmods/expanded_java.base.jmod/lib/jrt-fs-expanded/META-INF/MANIFEST.MF"
fi
}