-
-
Notifications
You must be signed in to change notification settings - Fork 256
/
Copy pathbuild.sh
executable file
·2519 lines (2160 loc) · 105 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
# ********************************************************************************
# Copyright (c) 2017, 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
# ********************************************************************************
################################################################################
#
# 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 DevKit if required
configureDevKitConfigureParameter() {
if [[ -n "${BUILD_CONFIG[USE_ADOPTIUM_DEVKIT]}" ]]; then
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
# Windows DevKit, currently only Redist DLLs
# Default to build architecture unless target ARCHITECTURE variable is set
local target_arch="${BUILD_CONFIG[OS_ARCHITECTURE]}"
if [ ${ARCHITECTURE+x} ] && [ -n "${ARCHITECTURE}" ]; then
target_arch="${ARCHITECTURE}"
fi
echo "Target architecture for Windows devkit: ${target_arch}"
# This is TARGET Architecture for the Redist DLLs to use
local dll_arch
if [[ "${target_arch}" == "x86-32" ]]; then
dll_arch="x86"
elif [[ "${target_arch}" == "aarch64" ]]; then
dll_arch="arm64"
else
dll_arch="x64"
fi
# Add Windows Redist DLL paths
addConfigureArg "--with-ucrt-dll-dir=" "${BUILD_CONFIG[ADOPTIUM_DEVKIT_LOCATION]}/ucrt/DLLs/${dll_arch}"
addConfigureArg "--with-msvcr-dll=" "${BUILD_CONFIG[ADOPTIUM_DEVKIT_LOCATION]}/${dll_arch}/vcruntime140.dll"
addConfigureArg "--with-vcruntime-1-dll=" "${BUILD_CONFIG[ADOPTIUM_DEVKIT_LOCATION]}/${dll_arch}/vcruntime140_1.dll"
addConfigureArg "--with-msvcp-dll=" "${BUILD_CONFIG[ADOPTIUM_DEVKIT_LOCATION]}/${dll_arch}/msvcp140.dll"
else
addConfigureArg "--with-devkit=" "${BUILD_CONFIG[ADOPTIUM_DEVKIT_LOCATION]}"
fi
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" ] && [ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" -lt 22 ]; then
addConfigureArg "--with-extra-cflags=" "-qnotimestamps"
addConfigureArg "--with-extra-cxxflags=" "-qnotimestamps"
fi
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
}
# JDK 24+ includes JEP 493 which allows for the JDK to enable
# linking from the run-time image (instead of only from JMODs). Enable
# this option. This has the effect, that no 'jmods' directory will be
# produced in the resulting build. Thus, the tarball and, especially the
# extracted tarball will be smaller in terms of disk space size.
configureLinkableRuntimeParameter() {
if [[ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" -ge 24 ]]; then
addConfigureArg "--enable-linkable-runtime" ""
fi
}
# Get the OpenJDK update version and build version
getOpenJDKUpdateAndBuildVersion() {
cd "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}"
if [ "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE]}" == "true" ]; then
echo "Version: local dir; OPENJDK_BUILD_NUMBER set as ${BUILD_CONFIG[OPENJDK_BUILD_NUMBER]}"
elif [ -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}" ] && [ "${BUILD_CONFIG[BUILD_VARIANT]}" != "${BUILD_VARIANT_OPENJ9}" ]; then
echo "Checking cloned freetype source version for version 2.8.1, that needs updated builds/windows/vc2010/freetype.vcxproj ..."
# Determine cloned freetype version
local freetype_version=""
# Obtain FreeType version from freetype.h
local freetypeInclude="${BUILD_CONFIG[WORKSPACE_DIR]}/libs/freetype/include/freetype/freetype.h"
if [[ -f "${freetypeInclude}" ]]; then
local ver_major="$(grep "FREETYPE_MAJOR" "${freetypeInclude}" | grep "#define" | tr -s " " | cut -d" " -f3)"
local ver_minor="$(grep "FREETYPE_MINOR" "${freetypeInclude}" | grep "#define" | tr -s " " | cut -d" " -f3)"
local ver_patch="$(grep "FREETYPE_PATCH" "${freetypeInclude}" | grep "#define" | tr -s " " | cut -d" " -f3)"
local freetype_version="${ver_major}.${ver_minor}.${ver_patch}"
if [[ "${freetype_version}" == "2.8.1" ]]; then
echo "Freetype 2.8.1 found, updating builds/windows/vc2010/freetype.vcxproj ..."
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"
else
echo "Freetype source is version ${freetype_version}, no updated required."
fi
else
echo "No include/freetype/freetype.h found, Freetype source not version 2.8.1, no updated required."
fi
fi
}
getOpenJdkVersion() {
local version
if [ "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE]}" == "true" ]; then
version=${BUILD_CONFIG[TAG]:-$(createDefaultTag)}
elif [ "${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() {
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:[email protected]"
BUILD_CONFIG[VENDOR_VM_BUG_URL]="mailto:[email protected]"
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"
fi
# For jdk-17+ aarch64 linux, we need to add --enable-compatible-cds-alignment, until upstream
# fix for https://bugs.openjdk.org/browse/JDK-8331942 is merged into all jdk-17+ versions
# (but not for OpenJ9 where it's not supported)
if [ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" -ge 17 ] && [ "${BUILD_CONFIG[OS_KERNEL_NAME]}" == "linux" ] && [ "${BUILD_CONFIG[OS_ARCHITECTURE]}" == "aarch64" ] && [ "${BUILD_CONFIG[BUILD_VARIANT]}" != "${BUILD_VARIANT_OPENJ9}" ]; then
addConfigureArg "--enable-compatible-cds-alignment" ""
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
}
configureAlsaLocation() {
if [[ ! "${CONFIGURE_ARGS}" =~ "--with-alsa" ]]; then
if [[ "${BUILD_CONFIG[ALSA]}" == "true" ]]; then
# Only use the Adoptium downloaded ALSA if not using a DevKit, which already has a sysroot ALSA
if [[ ${BUILD_CONFIG[USER_SUPPLIED_CONFIGURE_ARGS]} != *"--with-devkit="* ]] && [[ ${CONFIGURE_ARGS} != *"--with-devkit="* ]]; then
addConfigureArg "--with-alsa=" "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/installedalsa"
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
configureDevKitConfigureParameter
configureLinkableRuntimeParameter
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
configureAlsaLocation
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/\"}"
setDevKitEnvironment
configureFreetypeLocation
configureZlibLocation
echo "Completed configuring the version string parameter, config args are now: ${CONFIGURE_ARGS}"
}
# Get the DevKit path from the --with-devkit configure arg
getConfigureArgPath() {
local arg_path=""
local arg_regex="${1}=([^ ]+)"
if [[ "${CONFIGURE_ARGS}" =~ $arg_regex ]]; then
arg_path=${BASH_REMATCH[1]};
fi
echo "${arg_path}"
}
# Ensure environment set correctly for devkit
setDevKitEnvironment() {
if [[ "${BUILD_CONFIG[OS_KERNEL_NAME]}" == "linux" ]]; then
# If DevKit is used ensure LD_LIBRARY_PATH for linux is using the DevKit sysroot
local devkit_path=$(getConfigureArgPath "--with-devkit")
if [[ -n "${devkit_path}" ]]; then
if [[ -d "${devkit_path}" ]]; then
echo "Using gcc from DevKit toolchain specified in configure args location: --with-devkit=${devkit_path}"
if [[ -z ${LD_LIBRARY_PATH+x} ]]; then
export LD_LIBRARY_PATH=${devkit_path}/lib64:${devkit_path}/lib
else
export LD_LIBRARY_PATH=${devkit_path}/lib64:${devkit_path}/lib:${LD_LIBRARY_PATH}
fi
else
echo "--with-devkit location '${devkit_path}' not found"
exit 1
fi
fi
fi
}
# Make sure we're in the build root directory for OpenJDK now
# This maybe the OpenJDK source directory, or a user supplied build directory
stepIntoTheOpenJDKBuildRootDirectory() {
if [ -z "${BUILD_CONFIG[USER_OPENJDK_BUILD_ROOT_DIRECTORY]}" ] ; then
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
else
if [ ! -d "${BUILD_CONFIG[USER_OPENJDK_BUILD_ROOT_DIRECTORY]}" ] ; then
echo "ERROR: User supplied openjdk build root directory does not exist: ${BUILD_CONFIG[USER_OPENJDK_BUILD_ROOT_DIRECTORY]}"
exit 2
else
echo "Using user supplied openjdk build root directory: ${BUILD_CONFIG[USER_OPENJDK_BUILD_ROOT_DIRECTORY]}"
cd "${BUILD_CONFIG[USER_OPENJDK_BUILD_ROOT_DIRECTORY]}" || exit
fi
fi
echo "Should be in the openjdk build root directory, I'm at $PWD"
}
buildTemplatedFile() {
echo "Configuring command and using the pre-built config params..."
stepIntoTheOpenJDKBuildRootDirectory
echo "Currently at '${PWD}'"
if [[ "${BUILD_CONFIG[ASSEMBLE_EXPLODED_IMAGE]}" != "true" ]]; then
FULL_CONFIGURE="bash ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/configure --verbose ${CONFIGURE_ARGS}"
echo "Running ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/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
if [[ "${BUILD_CONFIG[ENABLE_SBOM_STRACE]}" == "true" ]]; then
# Check if strace is available
if which strace >/dev/null 2>&1; then
echo "Strace is available on system"
strace_calls="open,openat,execve"
# trace syscalls
FULL_MAKE_COMMAND="mkdir ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/straceOutput \&\& strace -o ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/straceOutput/outputFile -ff -e trace=${strace_calls} ${FULL_MAKE_COMMAND}"
else
echo "Strace is not available on system"
exit 2
fi
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]}"
if [ -e "${sourceDir}/.git" ] ; then
echo "Temporarily moving VCS source dir to ${tmpSourceVCS}"
mv "${sourceDir}/.git" "${tmpSourceVCS}"
else
echo "No VCS source dir found in ${sourceDir}"
fi
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}"
if [ -e "${tmpSourceVCS}" ] ; then
echo "Restoring VCS source dir from ${tmpSourceVCS} to ${sourceDir}/.git"
mv "${tmpSourceVCS}" "${sourceDir}/.git"
fi
cd "${oldPwd}"
}
executeTemplatedFile() {
if [ "${BUILD_CONFIG[CREATE_SOURCE_ARCHIVE]}" == "true" ]; then
createSourceArchive
fi
stepIntoTheOpenJDKBuildRootDirectory
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
# Always get the "actual" buildTimestamp used in making openjdk
local specFile="./spec.gmk"
if [ -z "${BUILD_CONFIG[USER_OPENJDK_BUILD_ROOT_DIRECTORY]}" ] ; then
specFile="build/*/spec.gmk"
fi
# For reproducible builds get openjdk timestamp used in the spec.gmk file
local buildTimestamp=$(grep SOURCE_DATE_ISO_8601 ${specFile} | 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
# Restore exit behavior
set -eu
}
createOpenJDKFailureLogsArchive() {
echo "OpenJDK make failed, archiving make failed logs"
if [ -z "${BUILD_CONFIG[USER_OPENJDK_BUILD_ROOT_DIRECTORY]}" ] ; then
cd build/*
fi
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 TemurinGenSbom.java
setupJavaEnv() {
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
# Has the user specified their own local cache for the dependency jars?
local localJarCacheOption=""
if [[ -n "${BUILD_CONFIG[LOCAL_DEPENDENCY_CACHE_DIR]}" ]]; then
localJarCacheOption="-Dlocal.deps.cache.dir=${BUILD_CONFIG[LOCAL_DEPENDENCY_CACHE_DIR]}"
else
# Select a suitable default location that users may use
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
# Windows
localJarCacheOption="-Dlocal.deps.cache.dir=c:/dependency_cache"
elif [[ "${BUILD_CONFIG[OS_KERNEL_NAME]}" == "darwin" ]]; then
# MacOS
localJarCacheOption="-Dlocal.deps.cache.dir=${HOME}/dependency_cache"
else
# Assume unix based path
localJarCacheOption="-Dlocal.deps.cache.dir=/usr/local/dependency_cache"
fi
fi
echo "Using CycloneDX local jar cache build option: ${localJarCacheOption}"
JAVA_HOME=${javaHome} ant -f "${ANTBUILDFILE}" clean
JAVA_HOME=${javaHome} ant -f "${ANTBUILDFILE}" build "${localJarCacheOption}"
}
# 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-validator.jar:${CYCLONEDB_JAR_DIR}/commons-codec.jar:${CYCLONEDB_JAR_DIR}/commons-io.jar:${CYCLONEDB_JAR_DIR}/github-package-url.jar:${CYCLONEDB_JAR_DIR}/commons-collections4.jar:${CYCLONEDB_JAR_DIR}/stax2-api.jar:${CYCLONEDB_JAR_DIR}/woodstox-core.jar:${CYCLONEDB_JAR_DIR}/commons-lang3.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-validator.jar" "${CYCLONEDB_JAR_DIR}/commons-codec.jar" "${CYCLONEDB_JAR_DIR}/commons-io.jar" \
"${CYCLONEDB_JAR_DIR}/github-package-url.jar" "${CYCLONEDB_JAR_DIR}/commons-collections4.jar" \
"${CYCLONEDB_JAR_DIR}/stax2-api.jar" "${CYCLONEDB_JAR_DIR}/woodstox-core.jar" "${CYCLONEDB_JAR_DIR}/commons-lang3.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
# exit from local var=$(setupJavaEnv) is not propagated. We have to ensure that the exit propagates, and is fatal for the script
# So the declaration is split. In that case the bug does not occur and thus the `exit 2` from setupJavaEnv is correctly propagated
local javaHome
javaHome="$(setupJavaEnv)"
echo "build.sh : $(date +%T) : Generating SBoM ..."
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]^}"
# TODO: Replace this "if" with its predecessor (commented out below) once
# OS_ARCHITECTURE has been replaced by the new target architecture variable.