-
-
Notifications
You must be signed in to change notification settings - Fork 249
/
build.sh
executable file
·2170 lines (1852 loc) · 88.5 KB
/
build.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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# shellcheck disable=SC2155,SC2153,SC2038,SC1091,SC2116,SC2086
################################################################################
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
################################################################################
#
# Build OpenJDK - can be called directly but is typically called by
# docker-build.sh or native-build.sh.
#
# See bottom of the script for the call order and each function for further
# details.
#
# Calls 'configure' then 'make' in order to build OpenJDK
#
################################################################################
set -eu
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=sbin/prepareWorkspace.sh
source "$SCRIPT_DIR/prepareWorkspace.sh"
# shellcheck source=sbin/common/config_init.sh
source "$SCRIPT_DIR/common/config_init.sh"
# shellcheck source=sbin/common/constants.sh
source "$SCRIPT_DIR/common/constants.sh"
# shellcheck source=sbin/common/common.sh
source "$SCRIPT_DIR/common/common.sh"
source "$SCRIPT_DIR/common/sbom.sh"
export LIB_DIR=$(crossPlatformRealPath "${SCRIPT_DIR}/../pipelines/")
export CYCLONEDB_DIR="${SCRIPT_DIR}/../cyclonedx-lib"
export jreTargetPath
export CONFIGURE_ARGS=""
export ADDITIONAL_MAKE_TARGETS=""
export GIT_CLONE_ARGUMENTS=()
# Parse the CL arguments, defers to the shared function in common-functions.sh
function parseArguments() {
parseConfigurationArguments "$@"
}
# Add an argument to the configure call
addConfigureArg() {
# Only add an arg if it is not overridden by a user-specified arg.
if [[ ${BUILD_CONFIG[USER_SUPPLIED_CONFIGURE_ARGS]} != *"$1"* ]]; then
CONFIGURE_ARGS="${CONFIGURE_ARGS} ${1}${2}"
fi
}
# Add an argument to the configure call (if it's not empty)
addConfigureArgIfValueIsNotEmpty() {
# Only try to add an arg if the second argument is not empty.
if [ -n "$2" ]; then
addConfigureArg "$1" "$2"
fi
}
# Configure the boot JDK
configureBootJDKConfigureParameter() {
addConfigureArgIfValueIsNotEmpty "--with-boot-jdk=" "${BUILD_CONFIG[JDK_BOOT_DIR]}"
}
# Shenandaoh was backported to Java 11 as of 11.0.9 but requires this build
# parameter to ensure its inclusion. For Java 12+ this is automatically set
configureShenandoahBuildParameter() {
if [ "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" == "${JDK11_CORE_VERSION}" ]; then
if [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_TEMURIN}" ] || [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_CORRETTO}" ]; then
addConfigureArg "--with-jvm-features=" "shenandoahgc"
fi
fi
}
# Configure reproducible build
# jdk-17 and jdk-19+ support reproducible builds
configureReproducibleBuildParameter() {
if [[ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" -ge 19 || "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" -eq 17 ]]
then
# Enable reproducible builds implicitly with --with-source-date
if [ "${BUILD_CONFIG[RELEASE]}" == "true" ]
then
# Use release date
addConfigureArg "--with-source-date=" "version"
else
# Use BUILD_TIMESTAMP date
# Convert BUILD_TIMESTAMP to seconds since Epoch
local buildTimestampSeconds
if isGnuCompatDate; then
buildTimestampSeconds=$(date --utc --date="${BUILD_CONFIG[BUILD_TIMESTAMP]}" +"%s")
else
buildTimestampSeconds=$(date -u -j -f "%Y-%m-%d %H:%M:%S" "${BUILD_CONFIG[BUILD_TIMESTAMP]}" +"%s")
fi
addConfigureArg "--with-source-date=" "${buildTimestampSeconds}"
# Specify --with-hotspot-build-time to ensure dual pass builds like MacOS use same time
# Use supplied date
addConfigureArg "--with-hotspot-build-time=" "'${BUILD_CONFIG[BUILD_TIMESTAMP]}'"
fi
# TZ issue: https://github.com/adoptium/temurin-build/issues/3075
export TZ=UTC
# disable CCache (remove --enable-ccache if exist)
addConfigureArg "--disable-ccache" ""
CONFIGURE_ARGS="${CONFIGURE_ARGS//--enable-ccache/}"
# Ensure reproducible and comparable binary with a unique build user identifier
addConfigureArg "--with-build-user=" "admin"
if [ "${BUILD_CONFIG[OS_KERNEL_NAME]}" == "aix" ]; then
addConfigureArg "--with-extra-cflags=" "-qnotimestamps"
addConfigureArg "--with-extra-cxxflags=" "-qnotimestamps"
fi
configureReproducibleBuildDebugMapping
fi
}
# For reproducible builds we need to add debug mappings for the system header paths,
# so that debug symbol files (and thus libraries) are deterministic
configureReproducibleBuildDebugMapping() {
# For Linux add -fdebug-prefix-map'ings for root and gcc include paths,
# pointing to a common set of folders so that the debug binaries are deterministic:
#
# root include : /usr/include
# gcc include : /usr/local/gcc_include
# g++ include : /usr/local/gxx_include
#
if [ "${BUILD_CONFIG[OS_KERNEL_NAME]}" == "linux" ]; then
# Add debug prefix map for root /usr/include, allowing for a SYSROOT
sysroot="$(echo "${BUILD_CONFIG[USER_SUPPLIED_CONFIGURE_ARGS]}" | sed -nE 's/.*\-\-with\-sysroot=([^[:space:]]+).*/\1/p')"
if [ "x$sysroot" != "x" ]; then
root_include=${sysroot%/}"/usr/include"
gcc_sysroot="--sysroot=${sysroot%/}"
else
root_include="/usr/include"
gcc_sysroot=""
fi
echo "Adding -fdebug-prefix-map for root include: ${root_include}=/usr/include"
fdebug_flags="-fdebug-prefix-map=${root_include}/=/usr/include/"
# Add debug prefix map for gcc include, allowing for SYSROOT
if [ -n "${CC-}" ]; then
gcc_include="$(dirname "$(echo "#include <stddef.h>" | $CC $gcc_sysroot -v -E - 2>&1 | grep stddef | tail -1 | tr -s " " | cut -d'"' -f2)")"
elif [ "$(which gcc)" != "" ]; then
gcc_include="$(dirname "$(echo "#include <stddef.h>" | gcc $gcc_sysroot -v -E - 2>&1 | grep stddef | tail -1 | tr -s " " | cut -d'"' -f2)")"
else
# Can't find gcc..
gcc_include=""
fi
if [ "x$gcc_include" != "x" ]; then
echo "Adding -fdebug-prefix-map for gcc include: ${gcc_include}=/usr/local/gcc_include"
fdebug_flags+=" -fdebug-prefix-map=${gcc_include}/=/usr/local/gcc_include/"
fi
# Add debug prefix map for g++ include, allowing for SYSROOT
if [ -n "${CXX-}" ]; then
gxx_include="$(dirname "$(echo "#include <cstddef>" | $CXX $gcc_sysroot -v -E -x c++ - 2>&1 | grep cstddef | tail -1 | tr -s " " | cut -d'"' -f2)")"
elif [ "$(which g++)" != "" ]; then
gxx_include="$(dirname "$(echo "#include <cstddef>" | g++ $gcc_sysroot -v -E -x c++ - 2>&1 | grep cstddef | tail -1 | tr -s " " | cut -d'"' -f2)")"
else
# Can't find g++..
gxx_include=""
fi
if [ "x$gxx_include" != "x" ]; then
echo "Adding -fdebug-prefix-map for g++ include: ${gxx_include}=/usr/local/gxx_include"
fdebug_flags+=" -fdebug-prefix-map=${gxx_include}/=/usr/local/gxx_include/"
fi
addConfigureArg "--with-extra-cflags=" "'${fdebug_flags}'"
addConfigureArg "--with-extra-cxxflags=" "'${fdebug_flags}'"
fi
}
# Configure for MacOS Codesign
configureMacOSCodesignParameter() {
if [ -n "${BUILD_CONFIG[MACOSX_CODESIGN_IDENTITY]}" ]; then
# This command needs to escape the double quotes because they are needed to preserve the spaces in the codesign cert name
addConfigureArg "--with-macosx-codesign-identity=" "\"${BUILD_CONFIG[MACOSX_CODESIGN_IDENTITY]}\""
fi
}
# Get the OpenJDK update version and build version
getOpenJDKUpdateAndBuildVersion() {
cd "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}"
if [ -d "${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/.git" ]; then
# It does exist and it's a repo other than the Temurin one
cd "${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" || return
if [ -f ".git/shallow.lock" ]; then
echo "Detected lock file, assuming this is an error, removing"
rm ".git/shallow.lock"
fi
# shellcheck disable=SC2154
echo "Pulling latest tags and getting the latest update version using git fetch -q --tags ${BUILD_CONFIG[SHALLOW_CLONE_OPTION]}"
# shellcheck disable=SC2154
echo "NOTE: This can take quite some time! Please be patient"
# shellcheck disable=SC2086
git fetch -q --tags ${BUILD_CONFIG[SHALLOW_CLONE_OPTION]}
local openJdkVersion=$(getOpenJdkVersion)
if [[ "${openJdkVersion}" == "" ]]; then
# shellcheck disable=SC2154
echo "Unable to detect git tag, exiting..."
exit 1
else
echo "OpenJDK repo tag is $openJdkVersion"
fi
local openjdk_update_version
openjdk_update_version=$(echo "${openJdkVersion}" | cut -d'u' -f 2 | cut -d'-' -f 1)
# TODO don't modify config in build script
echo "Version: ${openjdk_update_version} ${BUILD_CONFIG[OPENJDK_BUILD_NUMBER]}"
fi
cd "${BUILD_CONFIG[WORKSPACE_DIR]}"
}
patchFreetypeWindows() {
# Allow freetype 2.8.1 to be built for JDK8u with Visual Studio 2017 (see https://github.com/openjdk/jdk8u-dev/pull/3#issuecomment-1087677766).
# Don't apply the patch for OpenJ9 (OpenJ9 doesn't need the patch and, technically, it should only be applied for version 2.8.1).
if [ "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" = "${JDK8_CORE_VERSION}" ] && [ "${ARCHITECTURE}" = "x64" ] && [ "${BUILD_CONFIG[BUILD_VARIANT]}" != "${BUILD_VARIANT_OPENJ9}" ]; then
rm "${BUILD_CONFIG[WORKSPACE_DIR]}/libs/freetype/builds/windows/vc2010/freetype.vcxproj"
# Copy the replacement freetype.vcxproj file from the .github directory
cp "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/.github/workflows/freetype.vcxproj" "${BUILD_CONFIG[WORKSPACE_DIR]}/libs/freetype/builds/windows/vc2010/freetype.vcxproj"
fi
}
getOpenJdkVersion() {
local version
if [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_CORRETTO}" ]; then
local corrVerFile=${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/version.txt
local corrVersion="$(cut -d'.' -f 1 <"${corrVerFile}")"
if [ "${corrVersion}" == "8" ]; then
local updateNum="$(cut -d'.' -f 2 <"${corrVerFile}")"
local buildNum="$(cut -d'.' -f 3 <"${corrVerFile}")"
local fixNum="$(cut -d'.' -f 4 <"${corrVerFile}")"
version="jdk8u${updateNum}-b${buildNum}.${fixNum}"
else
local minorNum="$(cut -d'.' -f 2 <"${corrVerFile}")"
local updateNum="$(cut -d'.' -f 3 <"${corrVerFile}")"
local buildNum="$(cut -d'.' -f 4 <"${corrVerFile}")"
local fixNum="$(cut -d'.' -f 5 <"${corrVerFile}")"
version="jdk-${corrVersion}.${minorNum}.${updateNum}+${buildNum}.${fixNum}"
fi
elif [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_DRAGONWELL}" ]; then
local dragonwellVerFile=${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/version.txt
if [ -r "${dragonwellVerFile}" ]; then
if [ "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" == "${JDK8_CORE_VERSION}" ]; then
local updateNum="$(cut -d'.' -f 2 <"${dragonwellVerFile}")"
local buildNum="$(cut -d'.' -f 6 <"${dragonwellVerFile}")"
version="jdk8u${updateNum}-b${buildNum}"
else
local minorNum="$(cut -d'.' -f 2 <"${dragonwellVerFile}")"
local updateNum="$(cut -d'.' -f 3 <"${dragonwellVerFile}")"
# special handling for dragonwell version
local buildNum="$(cut -d'.' -f 5 <"${dragonwellVerFile}" | cut -d'-' -f 1)"
version="jdk-11.${minorNum}.${updateNum}+${buildNum}"
fi
else
version=${BUILD_CONFIG[TAG]:-$(getFirstTagFromOpenJDKGitRepo)}
version=$(echo "$version" | cut -d'_' -f 2)
fi
elif [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_BISHENG}" ]; then
local bishengVerFile=${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/version.txt
if [ -r "${bishengVerFile}" ]; then
if [ "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" == "${JDK8_CORE_VERSION}" ]; then
local updateNum="$(cut -d'.' -f 2 <"${bishengVerFile}")"
local buildNum="$(cut -d'.' -f 5 <"${bishengVerFile}")"
version="jdk8u${updateNum}-b${buildNum}"
else
local minorNum="$(cut -d'.' -f 2 <"${bishengVerFile}")"
local updateNum="$(cut -d'.' -f 3 <"${bishengVerFile}")"
local buildNum="$(cut -d'.' -f 5 <"${bishengVerFile}")"
version="jdk-11.${minorNum}.${updateNum}+${buildNum}"
fi
else
version=${BUILD_CONFIG[TAG]:-$(getFirstTagFromOpenJDKGitRepo)}
version=$(echo "$version" | cut -d'-' -f 2 | cut -d'_' -f 1)
fi
else
version=${BUILD_CONFIG[TAG]:-$(getFirstTagFromOpenJDKGitRepo)}
# TODO remove pending #1016
version=${version%_adopt}
version=${version#aarch64-shenandoah-}
fi
echo "${version}"
}
# Ensure that we produce builds with versions strings something like:
#
# openjdk 11.0.12 2021-07-20
# OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
# OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)
configureVersionStringParameter() {
stepIntoTheWorkingDirectory
local openJdkVersion=$(getOpenJdkVersion)
echo "OpenJDK repo tag is ${openJdkVersion}"
# --with-milestone=fcs deprecated at jdk12+ and not used for jdk11- (we use --without-version-pre/opt)
if [ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" == 8 ] && [ "${BUILD_CONFIG[RELEASE]}" == "true" ]; then
addConfigureArg "--with-milestone=" "fcs"
elif [ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" == 8 ] && [ "${BUILD_CONFIG[RELEASE]}" != "true" ]; then
addConfigureArg "--with-milestone=" "beta"
fi
# Determine build date timestamp to use
local buildTimestamp
if [[ -n "${BUILD_CONFIG[BUILD_REPRODUCIBLE_DATE]}" ]]; then
# Use input reproducible build date supplied in ISO8601 format UTC time
buildTimestamp="${BUILD_CONFIG[BUILD_REPRODUCIBLE_DATE]}"
# BusyBox doesn't use T Z iso8601 format
buildTimestamp="${buildTimestamp//T/ }"
buildTimestamp="${buildTimestamp//Z/}"
else
# Get current ISO-8601 datetime
buildTimestamp=$(date -u +"%Y-%m-%d %H:%M:%S")
fi
BUILD_CONFIG[BUILD_TIMESTAMP]="${buildTimestamp}"
# Convert ISO-8601 buildTimestamp string to dateSuffix format: %Y%m%d%H%M
# "%Y-%m-%d %H:%M:%S" to "%Y%m%d%H%M"
local dateSuffix=$(echo "${buildTimestamp}" | cut -d":" -f1-2 | tr -d ": -")
# Configures "vendor" jdk properties.
# Temurin default values are set after this code block
# TODO 1. We should probably look at having these values passed through a config
# file as opposed to hardcoding in shell
# TODO 2. This highlights us conflating variant with vendor. e.g. OpenJ9 is really
# a technical variant with Eclipse as the vendor
if [[ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_TEMURIN}" ]]; then
BUILD_CONFIG[VENDOR]="Eclipse Adoptium"
BUILD_CONFIG[VENDOR_URL]="https://adoptium.net/"
BUILD_CONFIG[VENDOR_BUG_URL]="https://github.com/adoptium/adoptium-support/issues"
BUILD_CONFIG[VENDOR_VM_BUG_URL]="https://github.com/adoptium/adoptium-support/issues"
elif [[ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_DRAGONWELL}" ]]; then
BUILD_CONFIG[VENDOR]="Alibaba"
BUILD_CONFIG[VENDOR_VERSION]="\"(Alibaba Dragonwell)\""
BUILD_CONFIG[VENDOR_URL]="http://www.alibabagroup.com"
BUILD_CONFIG[VENDOR_BUG_URL]="mailto:dragonwell_use@googlegroups.com"
BUILD_CONFIG[VENDOR_VM_BUG_URL]="mailto:dragonwell_use@googlegroups.com"
elif [[ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_FAST_STARTUP}" ]]; then
BUILD_CONFIG[VENDOR]="Adoptium"
BUILD_CONFIG[VENDOR_VERSION]="Fast-Startup"
BUILD_CONFIG[VENDOR_BUG_URL]="https://github.com/adoptium/jdk11u-fast-startup-incubator/issues"
BUILD_CONFIG[VENDOR_VM_BUG_URL]="https://github.com/adoptium/jdk11u-fast-startup-incubator/issues"
elif [[ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_OPENJ9}" ]]; then
BUILD_CONFIG[VENDOR_VM_BUG_URL]="https://github.com/eclipse-openj9/openj9/issues"
elif [[ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_BISHENG}" ]]; then
BUILD_CONFIG[VENDOR]="Huawei"
BUILD_CONFIG[VENDOR_VERSION]="Bisheng"
BUILD_CONFIG[VENDOR_BUG_URL]="https://gitee.com/openeuler/bishengjdk-${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}/issues"
BUILD_CONFIG[VENDOR_VM_BUG_URL]="https://gitee.com/openeuler/bishengjdk-${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}/issues"
fi
if [ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" != 8 ]; then
addConfigureArg "--with-vendor-name=" "\"${BUILD_CONFIG[VENDOR]}\""
fi
# This looks silly, but in the case where someone is building a plain hotspot
# This makes it a bit easier to find the code that sets it to override
# Replace file:///dev/null with a URL similar to the vendor ones in the section above
addConfigureArg "--with-vendor-url=" "${BUILD_CONFIG[VENDOR_URL]:-"file:///dev/null"}"
addConfigureArg "--with-vendor-bug-url=" "${BUILD_CONFIG[VENDOR_BUG_URL]:-"file:///dev/null"}"
addConfigureArg "--with-vendor-vm-bug-url=" "${BUILD_CONFIG[VENDOR_VM_BUG_URL]:-"file:///dev/null"}"
local buildNumber
if [ "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" == "${JDK8_CORE_VERSION}" ]; then
if [ "${BUILD_CONFIG[RELEASE]}" == "false" ]; then
addConfigureArg "--with-user-release-suffix=" "${dateSuffix}"
fi
if [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_TEMURIN}" ]; then
# NOTE: There maybe a behavioural difference with this config depending on the jdk8u source branch you're working with.
addConfigureArg "--with-company-name=" "\"Temurin\""
# No JFR support in AIX or zero builds (s390 or armv7l)
if [ "${BUILD_CONFIG[OS_ARCHITECTURE]}" != "s390x" ] && [ "${BUILD_CONFIG[OS_KERNEL_NAME]}" != "aix" ] && [ "${BUILD_CONFIG[OS_ARCHITECTURE]}" != "armv7l" ]; then
addConfigureArg "--enable-jfr" ""
fi
fi
# Set the update version (e.g. 131), this gets passed in from the calling script
local updateNumber=${BUILD_CONFIG[OPENJDK_UPDATE_VERSION]}
if [ -z "${updateNumber}" ]; then
updateNumber=$(echo "${openJdkVersion}" | cut -f1 -d"-" | cut -f2 -d"u")
fi
addConfigureArgIfValueIsNotEmpty "--with-update-version=" "${updateNumber}"
# Set the build number (e.g. b04), this gets passed in from the calling script
buildNumber=${BUILD_CONFIG[OPENJDK_BUILD_NUMBER]}
if [ -z "${buildNumber}" ]; then
buildNumber=$(echo "${openJdkVersion}" | cut -f2 -d"-")
fi
if [ "${buildNumber}" ] && [ "${buildNumber}" != "ga" ]; then
addConfigureArgIfValueIsNotEmpty "--with-build-number=" "${buildNumber}"
fi
elif [ "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" == "${JDK9_CORE_VERSION}" ]; then
buildNumber=${BUILD_CONFIG[OPENJDK_BUILD_NUMBER]}
if [ -z "${buildNumber}" ]; then
buildNumber=$(echo "${openJdkVersion}" | cut -f2 -d"+")
fi
if [ "${BUILD_CONFIG[RELEASE]}" == "false" ]; then
addConfigureArg "--with-version-opt=" "${dateSuffix}"
addConfigureArg "--with-version-pre=" "beta"
else
addConfigureArg "--without-version-opt" ""
addConfigureArg "--without-version-pre" ""
fi
addConfigureArgIfValueIsNotEmpty "--with-version-build=" "${buildNumber}"
else
# > JDK 9
# Set the build number (e.g. b04), this gets passed in from the calling script
buildNumber=${BUILD_CONFIG[OPENJDK_BUILD_NUMBER]}
if [ -z "${buildNumber}" ]; then
# Get build number (eg.10) from tag of potential format "jdk-11.0.4+10_adopt"
buildNumber=$(echo "${openJdkVersion}" | cut -d_ -f1 | cut -f2 -d"+")
fi
if [ "${BUILD_CONFIG[RELEASE]}" == "false" ]; then
addConfigureArg "--with-version-opt=" "${dateSuffix}"
addConfigureArg "--with-version-pre=" "beta"
else
# "LTS" builds from jdk-21 will use "LTS" version opt
if isFromJdk21LTS; then
addConfigureArg "--with-version-opt=" "LTS"
else
addConfigureArg "--without-version-opt" ""
fi
addConfigureArg "--without-version-pre" ""
fi
addConfigureArgIfValueIsNotEmpty "--with-version-build=" "${buildNumber}"
fi
if [ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" -gt 8 ]; then
# Derive Adoptium metadata "version" string to use as vendor.version string
# Take openJdkVersion, remove jdk- prefix and build suffix, replace with specified buildNumber
# eg.:
# openJdkVersion = jdk-11.0.7+<build>
# vendor.version = Adoptium-11.0.7+<buildNumber>
#
# Remove "jdk-" prefix from openJdkVersion tag
local derivedOpenJdkMetadataVersion=${openJdkVersion#"jdk-"}
# Remove "+<build>" suffix
derivedOpenJdkMetadataVersion=$(echo "${derivedOpenJdkMetadataVersion}" | cut -f1 -d"+")
# Add "+<buildNumber>" being used
derivedOpenJdkMetadataVersion="${derivedOpenJdkMetadataVersion}+${buildNumber}"
if [ "${BUILD_CONFIG[RELEASE]}" == "false" ]; then
# Not a release build so add date suffix
derivedOpenJdkMetadataVersion="${derivedOpenJdkMetadataVersion}-${dateSuffix}"
fi
if [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_TEMURIN}" ]; then
addConfigureArg "--with-vendor-version-string=" "${BUILD_CONFIG[VENDOR_VERSION]:-"Temurin"}-${derivedOpenJdkMetadataVersion}"
fi
fi
echo "Completed configuring the version string parameter, config args are now: ${CONFIGURE_ARGS}"
}
# Construct all of the 'configure' parameters
buildingTheRestOfTheConfigParameters() {
if [ -n "$(which ccache)" ]; then
addConfigureArg "--enable-ccache" ""
fi
if [ "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" == "${JDK8_CORE_VERSION}" ]; then
addConfigureArg "--with-x=" "/usr/include/X11"
addConfigureArg "--with-alsa=" "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/installedalsa"
fi
}
configureDebugParameters() {
# We don't want any extra debug symbols - ensure it's set to release;
# other options include fastdebug and slowdebug.
addConfigureArg "--with-debug-level=" "release"
# If debug symbols package is requested, generate them separately
if [ ${BUILD_CONFIG[CREATE_DEBUG_IMAGE]} == true ]; then
addConfigureArg "--with-native-debug-symbols=" "external"
else
if [ "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" == "${JDK8_CORE_VERSION}" ]; then
addConfigureArg "--disable-zip-debug-info" ""
if [[ "${BUILD_CONFIG[BUILD_VARIANT]}" != "${BUILD_VARIANT_OPENJ9}" ]]; then
addConfigureArg "--disable-debug-symbols" ""
fi
else
if [[ "${BUILD_CONFIG[BUILD_VARIANT]}" != "${BUILD_VARIANT_OPENJ9}" ]]; then
addConfigureArg "--with-native-debug-symbols=" "none"
fi
fi
fi
}
configureFreetypeLocation() {
if [[ ! "${CONFIGURE_ARGS}" =~ "--with-freetype" ]]; then
if [[ "${BUILD_CONFIG[FREETYPE]}" == "true" ]]; then
local freetypeDir="${BUILD_CONFIG[FREETYPE_DIRECTORY]}"
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
case "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" in
jdk8* | jdk9* | jdk10*) addConfigureArg "--with-freetype-src=" "${BUILD_CONFIG[WORKSPACE_DIR]}/libs/freetype" ;;
*) freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:-bundled} ;;
esac
else
case "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" in
jdk8* | jdk9* | jdk10*) freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:-"${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/installedfreetype"} ;;
*) freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:-bundled} ;;
esac
fi
if [[ -n "$freetypeDir" ]]; then
echo "setting freetype dir to ${freetypeDir}"
addConfigureArg "--with-freetype=" "${freetypeDir}"
fi
fi
fi
}
configureZlibLocation() {
if [[ "${BUILD_CONFIG[BUILD_VARIANT]}" != "${BUILD_VARIANT_OPENJ9}" ]]; then
if [[ ! "${CONFIGURE_ARGS}" =~ "--with-zlib" ]]; then
addConfigureArg "--with-zlib=" "bundled"
fi
fi
}
# Configure the command parameters
configureCommandParameters() {
configureVersionStringParameter
configureBootJDKConfigureParameter
configureShenandoahBuildParameter
configureMacOSCodesignParameter
configureDebugParameters
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
echo "Windows or Windows-like environment detected, skipping configuring environment for custom Boot JDK and other 'configure' settings."
else
echo "Building up the configure command..."
buildingTheRestOfTheConfigParameters
fi
echo "Adjust configure for reproducible build"
configureReproducibleBuildParameter
echo "Configuring jvm variants if provided"
addConfigureArgIfValueIsNotEmpty "--with-jvm-variants=" "${BUILD_CONFIG[JVM_VARIANT]}"
if [ "${BUILD_CONFIG[CUSTOM_CACERTS]}" = "true" ] ; then
if [[ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" -ge "17" ]]; then
echo "Configure custom cacerts src security/certs"
addConfigureArgIfValueIsNotEmpty "--with-cacerts-src=" "$SCRIPT_DIR/../security/certs"
else
echo "Configure custom cacerts file security/cacerts"
addConfigureArgIfValueIsNotEmpty "--with-cacerts-file=" "$SCRIPT_DIR/../security/cacerts"
fi
fi
# Finally, we add any configure arguments the user has specified on the command line.
# This is done last, to ensure the user can override any args they need to.
# The substitution allows the user to pass in speech marks without having to guess
# at the number of escapes needed to ensure that they persist up to this point.
CONFIGURE_ARGS="${CONFIGURE_ARGS} ${BUILD_CONFIG[USER_SUPPLIED_CONFIGURE_ARGS]//temporary_speech_mark_placeholder/\"}"
configureFreetypeLocation
configureZlibLocation
echo "Completed configuring the version string parameter, config args are now: ${CONFIGURE_ARGS}"
}
# Make sure we're in the source directory for OpenJDK now
stepIntoTheWorkingDirectory() {
cd "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" || exit
# corretto/corretto-8 (jdk-8 only) nest their source under /src in their dir
if [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_CORRETTO}" ] && [ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" == "8" ]; then
cd "src"
fi
echo "Should have the source, I'm at $PWD"
}
buildTemplatedFile() {
echo "Configuring command and using the pre-built config params..."
stepIntoTheWorkingDirectory
echo "Currently at '${PWD}'"
if [[ "${BUILD_CONFIG[ASSEMBLE_EXPLODED_IMAGE]}" != "true" ]]; then
FULL_CONFIGURE="bash ./configure --verbose ${CONFIGURE_ARGS}"
echo "Running ./configure with arguments '${FULL_CONFIGURE}'"
else
FULL_CONFIGURE="echo \"Skipping configure because we're assembling an exploded image\""
echo "Skipping configure because we're assembling an exploded image"
fi
# If it's Java 9+ then we also make test-image to build the native test libraries,
# For openj9 add debug-image. For JDK 22+ static-libs-image target name changed to
# static-libs-graal-image. See JDK-8307858.
JDK_VERSION_NUMBER="${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}"
if [[ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_OPENJ9}" ]]; then
ADDITIONAL_MAKE_TARGETS=" test-image debug-image"
elif [ "$JDK_VERSION_NUMBER" -gt 8 ] && [ "$JDK_VERSION_NUMBER" -lt 22 ]; then
ADDITIONAL_MAKE_TARGETS=" test-image static-libs-image"
elif [ "$JDK_VERSION_NUMBER" -ge 22 ] || [ "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" == "${JDKHEAD_VERSION}" ]; then
ADDITIONAL_MAKE_TARGETS=" test-image static-libs-graal-image"
fi
if [[ "${BUILD_CONFIG[MAKE_EXPLODED]}" == "true" ]]; then
# In order to make an exploded image we cannot have any additional targets
ADDITIONAL_MAKE_TARGETS=""
fi
FULL_MAKE_COMMAND="${BUILD_CONFIG[MAKE_COMMAND_NAME]} ${BUILD_CONFIG[MAKE_ARGS_FOR_ANY_PLATFORM]} ${BUILD_CONFIG[USER_SUPPLIED_MAKE_ARGS]} ${ADDITIONAL_MAKE_TARGETS}"
if [[ "${BUILD_CONFIG[ASSEMBLE_EXPLODED_IMAGE]}" == "true" ]]; then
# This is required so that make will only touch the jmods and not re-compile them after signing
FULL_MAKE_COMMAND="make -t \&\& ${FULL_MAKE_COMMAND}"
fi
# shellcheck disable=SC2002
cat "$SCRIPT_DIR/build.template" |
sed -e "s|{configureArg}|${FULL_CONFIGURE}|" \
-e "s|{makeCommandArg}|${FULL_MAKE_COMMAND}|" >"${BUILD_CONFIG[WORKSPACE_DIR]}/config/configure-and-build.sh"
}
createSourceArchive() {
local sourceDir="${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}"
local sourceArchiveTargetPath="$(getSourceArchivePath)"
local tmpSourceVCS="${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/tmp-openjdk-git"
local srcArchiveName
if echo ${BUILD_CONFIG[TARGET_FILE_NAME]} | grep -q x64_linux_hotspot -; then
# Transform 'OpenJDK11U-jdk_aarch64_linux_hotspot_11.0.12_7.tar.gz' to 'OpenJDK11U-sources_11.0.12_7.tar.gz'
# shellcheck disable=SC2001
srcArchiveName="$(echo "${BUILD_CONFIG[TARGET_FILE_NAME]}" | sed 's/_x64_linux_hotspot_/-sources_/g')"
else
srcArchiveName=$(getTargetFileNameForComponent "sources")
fi
local oldPwd="${PWD}"
echo "Source archive name is going to be: ${srcArchiveName}"
if ! echo "${srcArchiveName}" | grep -q '-sources' -; then
echo "Error: Unexpected source archive name! Expected '-sources' in name."
echo " Source archive name was: ${srcArchiveName}"
exit 1
fi
cd "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}"
echo "Temporarily moving VCS source dir to ${tmpSourceVCS}"
mv "${sourceDir}/.git" "${tmpSourceVCS}"
echo "Temporarily moving source dir to ${sourceArchiveTargetPath}"
mv "${sourceDir}" "${sourceArchiveTargetPath}"
echo "OpenJDK source archive path will be ${sourceArchiveTargetPath}."
createArchive "${sourceArchiveTargetPath}" "${srcArchiveName}"
echo "Restoring source dir from ${sourceArchiveTargetPath} to ${sourceDir}"
mv "${sourceArchiveTargetPath}" "${sourceDir}"
echo "Restoring VCS source dir from ${tmpSourceVCS} to ${sourceDir}/.git"
mv "${tmpSourceVCS}" "${sourceDir}/.git"
cd "${oldPwd}"
}
executeTemplatedFile() {
if [ "${BUILD_CONFIG[CREATE_SOURCE_ARCHIVE]}" == "true" ]; then
createSourceArchive
fi
stepIntoTheWorkingDirectory
echo "Currently at '${PWD}'"
# We need the exitcode from the configure-and-build.sh script
set +eu
# Execute the build passing the workspace dir and target dir as params for configure.txt
bash "${BUILD_CONFIG[WORKSPACE_DIR]}/config/configure-and-build.sh" ${BUILD_CONFIG[WORKSPACE_DIR]} ${BUILD_CONFIG[TARGET_DIR]}
exitCode=$?
if [ "${exitCode}" -eq 3 ]; then
createOpenJDKFailureLogsArchive
echo "Failed to make the JDK, exiting"
exit 1
elif [ "${exitCode}" -eq 2 ]; then
echo "Failed to configure the JDK, exiting"
echo "Did you set the JDK boot directory correctly? Override by exporting JDK_BOOT_DIR"
echo "For example, on RHEL you would do export JDK_BOOT_DIR=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.131-2.6.9.0.el7_3.x86_64"
echo "Current JDK_BOOT_DIR value: ${BUILD_CONFIG[JDK_BOOT_DIR]}"
exit 2
fi
if [[ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" -ge 19 || "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" -eq 17 ]]; then
if [ "${BUILD_CONFIG[RELEASE]}" == "true" ]; then
# For "release" reproducible builds get openjdk timestamp used
local buildTimestamp=$(grep SOURCE_DATE_ISO_8601 build/*/spec.gmk | tr -s ' ' | cut -d' ' -f4)
# BusyBox doesn't use T Z iso8601 format
buildTimestamp="${buildTimestamp//T/ }"
buildTimestamp="${buildTimestamp//Z/}"
BUILD_CONFIG[BUILD_TIMESTAMP]="${buildTimestamp}"
fi
fi
# Restore exit behavior
set -eu
}
createOpenJDKFailureLogsArchive() {
echo "OpenJDK make failed, archiving make failed logs"
cd build/*
local adoptLogArchiveDir="TemurinLogsArchive"
# Create new folder for failure logs
rm -rf ${adoptLogArchiveDir}
mkdir ${adoptLogArchiveDir}
# Copy build and failure logs
if [[ -f "build.log" ]]; then
echo "Copying build.log to ${adoptLogArchiveDir}"
cp build.log ${adoptLogArchiveDir}
fi
if [[ -d "make-support/failure-logs" ]]; then
echo "Copying make-support/failure-logs to ${adoptLogArchiveDir}"
mkdir -p "${adoptLogArchiveDir}/make-support"
cp -r "make-support/failure-logs" "${adoptLogArchiveDir}/make-support"
fi
# Find any cores, dumps, ..
find . -name 'core.*' -o -name 'core.*.dmp' -o -name 'javacore.*.txt' -o -name 'Snap.*.trc' -o -name 'jitdump.*.dmp' | sed 's#^./##' | while read -r dump ; do
filedir=$(dirname "${dump}")
echo "Copying ${dump} to ${adoptLogArchiveDir}/${filedir}"
mkdir -p "${adoptLogArchiveDir}/${filedir}"
cp "${dump}" "${adoptLogArchiveDir}/${filedir}"
done
# Archive logs
local makeFailureLogsName=$(echo "${BUILD_CONFIG[TARGET_FILE_NAME]//-jdk/-makefailurelogs}")
createArchive "${adoptLogArchiveDir}" "${makeFailureLogsName}"
}
# Setup JAVA env to run "ant task"
setupAntEnv() {
local javaHome=""
if [ ${JAVA_HOME+x} ] && [ -d "${JAVA_HOME}" ]; then
javaHome=${JAVA_HOME}
elif [ ${JDK17_BOOT_DIR+x} ] && [ -d "${JDK17_BOOT_DIR}" ]; then
javaHome=${JDK17_BOOT_DIR}
elif [ ${JDK8_BOOT_DIR+x} ] && [ -d "${JDK8_BOOT_DIR}" ]; then
javaHome=${JDK8_BOOT_DIR}
elif [ ${JDK11_BOOT_DIR+x} ] && [ -d "${JDK11_BOOT_DIR}" ]; then
javaHome=${JDK11_BOOT_DIR}
elif [ ${BUILD_CONFIG[JDK_BOOT_DIR]+x} ] && [ -d "${BUILD_CONFIG[JDK_BOOT_DIR]}" ]; then
# fall back to use JDK_BOOT_DIR which is set in make-adopt-build-farm.sh
javaHome="${BUILD_CONFIG[JDK_BOOT_DIR]}"
else
echo "Unable to find a suitable JAVA_HOME to build the cyclonedx-lib"
exit 2
fi
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
javaHome=$(cygpath -w "${javaHome}")
fi
echo "${javaHome}"
}
# Build the CycloneDX Java library and app used for SBoM generation
buildCyclonedxLib() {
local javaHome="${1}"
# Make Ant aware of cygwin path
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
ANTBUILDFILE=$(cygpath -m "${CYCLONEDB_DIR}/build.xml")
else
ANTBUILDFILE="${CYCLONEDB_DIR}/build.xml"
fi
JAVA_HOME=${javaHome} ant -f "${ANTBUILDFILE}" clean
JAVA_HOME=${javaHome} ant -f "${ANTBUILDFILE}" build
}
# get the classpath to run the CycloneDX java app TemurinGenSBOM
getCyclonedxClasspath() {
local CYCLONEDB_JAR_DIR="${CYCLONEDB_DIR}/build/jar"
local classpath="${CYCLONEDB_JAR_DIR}/temurin-gen-sbom.jar:${CYCLONEDB_JAR_DIR}/cyclonedx-core-java.jar:${CYCLONEDB_JAR_DIR}/jackson-core.jar:${CYCLONEDB_JAR_DIR}/jackson-dataformat-xml.jar:${CYCLONEDB_JAR_DIR}/jackson-databind.jar:${CYCLONEDB_JAR_DIR}/jackson-annotations.jar:${CYCLONEDB_JAR_DIR}/json-schema.jar:${CYCLONEDB_JAR_DIR}/commons-codec.jar:${CYCLONEDB_JAR_DIR}/commons-io.jar:${CYCLONEDB_JAR_DIR}/github-package-url.jar"
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
classpath=""
for jarfile in "${CYCLONEDB_JAR_DIR}/temurin-gen-sbom.jar" "${CYCLONEDB_JAR_DIR}/cyclonedx-core-java.jar" \
"${CYCLONEDB_JAR_DIR}/jackson-core.jar" "${CYCLONEDB_JAR_DIR}/jackson-dataformat-xml.jar" \
"${CYCLONEDB_JAR_DIR}/jackson-databind.jar" "${CYCLONEDB_JAR_DIR}/jackson-annotations.jar" \
"${CYCLONEDB_JAR_DIR}/json-schema.jar" "${CYCLONEDB_JAR_DIR}/commons-codec.jar" "${CYCLONEDB_JAR_DIR}/commons-io.jar" \
"${CYCLONEDB_JAR_DIR}/github-package-url.jar" ;
do
classpath+=$(cygpath -w "${jarfile}")";"
done
fi
echo "${classpath}"
}
# Generate the SBoM
generateSBoM() {
if [[ "${BUILD_CONFIG[CREATE_SBOM]}" == "false" ]] || [[ ! -d "${CYCLONEDB_DIR}" ]]; then
echo "Skip generating SBOM"
return
fi
local javaHome="$(setupAntEnv)"
buildCyclonedxLib "${javaHome}"
# classpath to run java app TemurinGenSBOM
local classpath="$(getCyclonedxClasspath)"
local sbomTargetName=$(getTargetFileNameForComponent "sbom")
# Remove the tarball / zip extension from the name to be used for the SBOM
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
sbomTargetName=$(echo "${sbomTargetName}.json" | sed "s/\.zip//")
else
sbomTargetName=$(echo "${sbomTargetName}.json" | sed "s/\.tar\.gz//")
fi
local sbomJson="$(joinPathOS ${BUILD_CONFIG[WORKSPACE_DIR]} ${BUILD_CONFIG[TARGET_DIR]} ${sbomTargetName})"
echo "OpenJDK SBOM will be ${sbomJson}."
# Clean any old json
rm -f "${sbomJson}"
local fullVer=$(cat "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/productVersion.txt")
local fullVerOutput=$(cat "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/productVersionOutput.txt")
# Create initial SBOM json
createSBOMFile "${javaHome}" "${classpath}" "${sbomJson}"
# Set default SBOM metadata
addSBOMMetadata "${javaHome}" "${classpath}" "${sbomJson}"
# Create component to metadata in SBOM
addSBOMMetadataComponent "${javaHome}" "${classpath}" "${sbomJson}" "Eclipse Temurin" "framework" "${fullVer}" "Eclipse Temurin components"
# Below add property to metadata
# Add OS full version (Kernel is covered in the first field)
addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS version" "${BUILD_CONFIG[OS_FULL_VERSION]^}"
addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}"
# Set default SBOM formulation
addSBOMFormulation "${javaHome}" "${classpath}" "${sbomJson}" "CycloneDX"
addSBOMFormulationComp "${javaHome}" "${classpath}" "${sbomJson}" "CycloneDX" "CycloneDX jar SHAs"
# Below add build tools into metadata tools
if [ "${BUILD_CONFIG[OS_KERNEL_NAME]}" == "linux" ]; then
addGLIBCforLinux
addGCC
fi
addBootJDK
# Add ALSA 3rd party
addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "ALSA" "$(cat ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/dependency_version_alsa.txt)"
# Add FreeType 3rd party
addFreeTypeVersionInfo
# Add FreeMarker 3rd party (openj9)
local freemarker_version="$(joinPathOS ${BUILD_CONFIG[WORKSPACE_DIR]} ${BUILD_CONFIG[TARGET_DIR]} 'metadata/dependency_version_freemarker.txt')"
if [ -f "${freemarker_version}" ]; then
addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "FreeMarker" "$(cat ${freemarker_version})"
fi
# Add CycloneDX versions
addCycloneDXVersions
# Add Build Docker image SHA1
local buildimagesha=$(cat ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/docker.txt)
# ${BUILD_CONFIG[USE_DOCKER]^} always set to false cannot rely on it.
if [ -n "${buildimagesha}" ] && [ "${buildimagesha}" != "N.A" ]; then
addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "Use Docker for build" "true"
addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "Docker image SHA1" "${buildimagesha}"
else
addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "Use Docker for build" "false"
fi
checkingToolSummary
# add individual components that have been generated in this build
local components=("JDK" "JRE" "SOURCES" "STATIC-LIBS" "DEBUGIMAGE" "TESTIMAGE")
for component in "${components[@]}"
do
local componentLowerCase=$(echo "${component}" | tr '[:upper:]' '[:lower:]')
local componentName="${component} Component"
# shellcheck disable=SC2001
local archiveName=$(getTargetFileNameForComponent "${componentLowerCase}")
local archiveFile="$(joinPath ${BUILD_CONFIG[WORKSPACE_DIR]} ${BUILD_CONFIG[TARGET_DIR]} ${archiveName})"
# special handling for static-libs, determine the glibc type that is used.
if [ "${component}" == "STATIC-LIBS" ]; then
local staticLibsVariants=("" "-glibc" "-musl")
for staticLibsVariant in "${staticLibsVariants[@]}"
do
# shellcheck disable=SC2001
archiveName=$(getTargetFileNameForComponent "static-libs${staticLibsVariant}")
archiveFile="$(joinPath ${BUILD_CONFIG[WORKSPACE_DIR]} ${BUILD_CONFIG[TARGET_DIR]} ${archiveName})"
if [ -f "${archiveFile}" ]; then
break
fi
done
fi
if [ ! -f "${archiveFile}" ]; then
continue
fi
local sha=$(sha256File "${archiveFile}")
# Create JDK Component
addSBOMComponent "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "${fullVer}" "${BUILD_CONFIG[BUILD_VARIANT]^} ${component} Component"
# Add SHA256 hash for the component
addSBOMComponentHash "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "${sha}"
# Below add different properties to JDK component
# Add target archive name as JDK Component Property
addSBOMComponentProperty "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "Filename" "${archiveName}"
# Add variant as JDK Component Property
addSBOMComponentProperty "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "JDK Variant" "${BUILD_CONFIG[BUILD_VARIANT]^}"
# Add scmRef as JDK Component Property
addSBOMComponentPropertyFromFile "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "SCM Ref" "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/scmref.txt"
# Add OpenJDK source ref commit as JDK Component Property
addSBOMComponentPropertyFromFile "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "OpenJDK Source Commit" "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/openjdkSource.txt"
# Add buildRef as JDK Component Property
addSBOMComponentPropertyFromFile "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "Temurin Build Ref" "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/buildSource.txt"
# Add jenkins job ID as JDK Component Property
addSBOMComponentProperty "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "Builder Job Reference" "${BUILD_URL:-N.A}"
# Add jenkins builder (agent/machine name) as JDK Component Property
addSBOMComponentProperty "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "Builder Name" "${NODE_NAME:-N.A}"
# Add build timestamp
addSBOMComponentProperty "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "Build Timestamp" "${BUILD_CONFIG[BUILD_TIMESTAMP]}"
# Add Tool Summary section from configure.txt
addSBOMComponentPropertyFromFile "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "Build Tools Summary" "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/dependency_tool_sum.txt"
# Add builtConfig JDK Component Property, load as Json string
built_config=$(createConfigToJsonString)
addSBOMComponentProperty "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "Build Config" "${built_config}"
# Add full_version_output JDK Component Property
addSBOMComponentProperty "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "full_version_output" "${fullVerOutput}"
# Add makejdk_any_platform_args JDK Component Property
addSBOMComponentPropertyFromFile "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "makejdk_any_platform_args" "${BUILD_CONFIG[WORKSPACE_DIR]}/config/makejdk-any-platform.args"
# Add make_command_args JDK Component Property
addSBOMComponentPropertyFromFile "${javaHome}" "${classpath}" "${sbomJson}" "${componentName}" "make_command_args" "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/makeCommandArg.txt"
done
# Print SBOM location
echo "CycloneDX SBOM has been created in ${sbomJson}"
}
# Generate build tools info into dependency file
checkingToolSummary() {
echo "Checking and getting Tool Summary info:"
inputConfigFile="${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/configure.txt"
outputConfigFile="${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/dependency_tool_sum.txt"
sed -n '/^Tools summary:$/,$p' "${inputConfigFile}" > "${outputConfigFile}"
}
# Determine FreeType version being used in the build from either the system or bundled freetype.h definition
addFreeTypeVersionInfo() {
# Default to "system"
local FREETYPE_TO_USE="system"