From 09e62f73075c842d50cb814a02a5860bc18ee5c0 Mon Sep 17 00:00:00 2001 From: Adam Farley Date: Fri, 26 Jan 2024 12:27:46 +0000 Subject: [PATCH 01/12] Temporarily patch architecture confusion when cross-compiling on mac Currently, when we build an x64 mac build on an arm64 machine, we put arm64 all over the place by mistake. This change is to partially compensate for that mistake until such time as we can impliment a comprehensive seperation of build architecture and target architecture in our build scripts. Signed-off-by: Adam Farley --- sbin/build.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/sbin/build.sh b/sbin/build.sh index 37387edeb..8dab15cca 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -875,7 +875,16 @@ generateSBoM() { # 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]^}" + # TODO: Replace this "if" with its predecessor (commented out below) once + # OS_ARCHITECTURE has been replaced by the new target architecture variable. + # This is because OS_ARCHITECTURE is currently the build arch, not the target arch, + # and that confuses things when cross-compiling an x64 mac build on arm mac. + # addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" + if [ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_mac_.* ]; then + addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "x86_64" + else + addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" + endif # Set default SBOM formulation addSBOMFormulation "${javaHome}" "${classpath}" "${sbomJson}" "CycloneDX" @@ -1361,8 +1370,17 @@ cleanAndMoveArchiveFiles() { staticLibsDir="lib/static/windows-${osArch}" ;; darwin) - # on MacOSX the layout is: Contents/Home/lib/static/darwin-amd64/ - staticLibsDir="Contents/Home/lib/static/darwin-${osArch}" + # On MacOSX the layout is: Contents/Home/lib/static/darwin-[target architecture]/ + # TODO: Replace this "if" with its predecessor (commented out below) once + # OS_ARCHITECTURE has been replaced by the new target architecture variable. + # This is because OS_ARCHITECTURE is currently the build arch, not the target arch, + # and that confuses things when cross-compiling an x64 mac build on arm mac. + # staticLibsDir="Contents/Home/lib/static/darwin-${osArch}" + if [ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_mac_.* ]; then + staticLibsDir="Contents/Home/lib/static/darwin-amd64" + else + staticLibsDir="Contents/Home/lib/static/darwin-${osArch}" + fi ;; linux) # on Linux the layout is: lib/static/linux-amd64/glibc From 2cc403cfff4f631137bf216dac2c7f06df2d9c1c Mon Sep 17 00:00:00 2001 From: Adam Farley Date: Fri, 26 Jan 2024 12:47:38 +0000 Subject: [PATCH 02/12] Tidying the fix for simplicity Signed-off-by: Adam Farley --- sbin/build.sh | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/sbin/build.sh b/sbin/build.sh index 8dab15cca..4a550ef0e 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -880,7 +880,7 @@ generateSBoM() { # This is because OS_ARCHITECTURE is currently the build arch, not the target arch, # and that confuses things when cross-compiling an x64 mac build on arm mac. # addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" - if [ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_mac_.* ]; then + if [ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]; then addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "x86_64" else addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" @@ -1360,7 +1360,12 @@ cleanAndMoveArchiveFiles() { # Windows: lib/static/windows-amd64/ # osArch="${BUILD_CONFIG[OS_ARCHITECTURE]}" - if [ "${BUILD_CONFIG[OS_ARCHITECTURE]}" = "x86_64" ]; then + # TODO: Replace this "if" condition with its predecessor (commented out below) once + # OS_ARCHITECTURE has been replaced by the new target architecture variable. + # This is because OS_ARCHITECTURE is currently the build arch, not the target arch, + # and that confuses things when cross-compiling an x64 mac build on arm mac. + # if [ "${BUILD_CONFIG[OS_ARCHITECTURE]}" = "x86_64" ]; then + if [ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]; then osArch="amd64" fi pushd ${staticLibsImagePath} @@ -1371,16 +1376,7 @@ cleanAndMoveArchiveFiles() { ;; darwin) # On MacOSX the layout is: Contents/Home/lib/static/darwin-[target architecture]/ - # TODO: Replace this "if" with its predecessor (commented out below) once - # OS_ARCHITECTURE has been replaced by the new target architecture variable. - # This is because OS_ARCHITECTURE is currently the build arch, not the target arch, - # and that confuses things when cross-compiling an x64 mac build on arm mac. - # staticLibsDir="Contents/Home/lib/static/darwin-${osArch}" - if [ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_mac_.* ]; then - staticLibsDir="Contents/Home/lib/static/darwin-amd64" - else - staticLibsDir="Contents/Home/lib/static/darwin-${osArch}" - fi + staticLibsDir="Contents/Home/lib/static/darwin-${osArch}" ;; linux) # on Linux the layout is: lib/static/linux-amd64/glibc From fc2e29f1bb5e6134b81fe518a74666a96edc69b4 Mon Sep 17 00:00:00 2001 From: Adam Farley Date: Fri, 26 Jan 2024 12:51:08 +0000 Subject: [PATCH 03/12] Fixing typo in if statement Signed-off-by: Adam Farley --- sbin/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbin/build.sh b/sbin/build.sh index 4a550ef0e..a35361dde 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -884,7 +884,7 @@ generateSBoM() { addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "x86_64" else addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" - endif + fi # Set default SBOM formulation addSBOMFormulation "${javaHome}" "${classpath}" "${sbomJson}" "CycloneDX" From fcac5dcdb990b36429c50f2fa775ff2741bb5c13 Mon Sep 17 00:00:00 2001 From: Adam Farley Date: Fri, 26 Jan 2024 13:17:06 +0000 Subject: [PATCH 04/12] Tidying IFs and fixing the arch capitalization Signed-off-by: Adam Farley --- sbin/build.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sbin/build.sh b/sbin/build.sh index a35361dde..4fac8eeab 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -881,7 +881,7 @@ generateSBoM() { # and that confuses things when cross-compiling an x64 mac build on arm mac. # addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" if [ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]; then - addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "x86_64" + addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "X86_64" else addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" fi @@ -1360,14 +1360,19 @@ cleanAndMoveArchiveFiles() { # Windows: lib/static/windows-amd64/ # osArch="${BUILD_CONFIG[OS_ARCHITECTURE]}" - # TODO: Replace this "if" condition with its predecessor (commented out below) once - # OS_ARCHITECTURE has been replaced by the new target architecture variable. + if [ "${BUILD_CONFIG[OS_ARCHITECTURE]}" = "x86_64" ]; then + osArch="amd64" + fi + + # TODO: Remove the "if" below once OS_ARCHITECTURE has been replaced. # This is because OS_ARCHITECTURE is currently the build arch, not the target arch, # and that confuses things when cross-compiling an x64 mac build on arm mac. - # if [ "${BUILD_CONFIG[OS_ARCHITECTURE]}" = "x86_64" ]; then - if [ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]; then - osArch="amd64" + if [ "${BUILD_CONFIG[OS_ARCHITECTURE]}" = "arm64" ]; then + if [ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]; then + osArch="amd64" + fi fi + pushd ${staticLibsImagePath} case "${BUILD_CONFIG[OS_KERNEL_NAME]}" in *cygwin*) From 81975da2b7d40baec43921839e06c7f76b42d0e1 Mon Sep 17 00:00:00 2001 From: Adam Farley Date: Fri, 26 Jan 2024 13:34:38 +0000 Subject: [PATCH 05/12] Adding square brackets to permit regex Signed-off-by: Adam Farley --- sbin/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sbin/build.sh b/sbin/build.sh index 4fac8eeab..938963cc3 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -880,7 +880,7 @@ generateSBoM() { # This is because OS_ARCHITECTURE is currently the build arch, not the target arch, # and that confuses things when cross-compiling an x64 mac build on arm mac. # addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" - if [ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]; then + if [[ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]]; then addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "X86_64" else addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" @@ -1368,7 +1368,7 @@ cleanAndMoveArchiveFiles() { # This is because OS_ARCHITECTURE is currently the build arch, not the target arch, # and that confuses things when cross-compiling an x64 mac build on arm mac. if [ "${BUILD_CONFIG[OS_ARCHITECTURE]}" = "arm64" ]; then - if [ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]; then + if [[ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]]; then osArch="amd64" fi fi From aa8d14e0a814d81af72ccff8a9618d00cd8c45c9 Mon Sep 17 00:00:00 2001 From: Adam Farley Date: Fri, 26 Jan 2024 14:25:44 +0000 Subject: [PATCH 06/12] Debug messages Signed-off-by: Adam Farley --- sbin/build.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sbin/build.sh b/sbin/build.sh index 938963cc3..c2abceb11 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -880,9 +880,12 @@ generateSBoM() { # This is because OS_ARCHITECTURE is currently the build arch, not the target arch, # and that confuses things when cross-compiling an x64 mac build on arm mac. # addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" + echo "DEBUG 1" if [[ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]]; then + echo "DEBUG 2" addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "X86_64" else + echo "DEBUG 3" addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" fi From 9e550e7719cae95f52f87a45e4f126a4c794b094 Mon Sep 17 00:00:00 2001 From: Adam Farley Date: Fri, 26 Jan 2024 15:30:22 +0000 Subject: [PATCH 07/12] Adding another debug comment Signed-off-by: Adam Farley --- sbin/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/sbin/build.sh b/sbin/build.sh index c2abceb11..01b1cb256 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -31,6 +31,7 @@ set -eu SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +echo "DEBUG: Running Adam's build script copy." # shellcheck source=sbin/prepareWorkspace.sh source "$SCRIPT_DIR/prepareWorkspace.sh" From 211c633617f5cc053bae9db5c404317a7099803b Mon Sep 17 00:00:00 2001 From: Adam Farley Date: Fri, 26 Jan 2024 16:48:39 +0000 Subject: [PATCH 08/12] Changing to lowercase to match previous behaviour Signed-off-by: Adam Farley --- sbin/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbin/build.sh b/sbin/build.sh index 01b1cb256..114f936c3 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -884,7 +884,7 @@ generateSBoM() { echo "DEBUG 1" if [[ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]]; then echo "DEBUG 2" - addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "X86_64" + addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "x86_64" else echo "DEBUG 3" addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" From 33586d282282029b2829ce5a6e05dc49120338e2 Mon Sep 17 00:00:00 2001 From: Stewart X Addison <6487691+sxa@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:22:44 +0000 Subject: [PATCH 09/12] Remove debug statement --- sbin/build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/sbin/build.sh b/sbin/build.sh index 114f936c3..6721ce3d1 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -31,7 +31,6 @@ set -eu SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -echo "DEBUG: Running Adam's build script copy." # shellcheck source=sbin/prepareWorkspace.sh source "$SCRIPT_DIR/prepareWorkspace.sh" From e3afec71979129ad3c74c5ff841d8f4f958db2a7 Mon Sep 17 00:00:00 2001 From: Stewart X Addison <6487691+sxa@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:22:54 +0000 Subject: [PATCH 10/12] Remove debug statement --- sbin/build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/sbin/build.sh b/sbin/build.sh index 6721ce3d1..45df49ee7 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -882,7 +882,6 @@ generateSBoM() { # addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" echo "DEBUG 1" if [[ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]]; then - echo "DEBUG 2" addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "x86_64" else echo "DEBUG 3" From f6f4d3ee295e6701f382783f39d23a496c10770d Mon Sep 17 00:00:00 2001 From: Stewart X Addison <6487691+sxa@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:23:05 +0000 Subject: [PATCH 11/12] Remove debug statement --- sbin/build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/sbin/build.sh b/sbin/build.sh index 45df49ee7..ec00d9833 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -884,7 +884,6 @@ generateSBoM() { if [[ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]]; then addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "x86_64" else - echo "DEBUG 3" addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" fi From 14a209f3634673d4fbda37ad15bc3186170857f1 Mon Sep 17 00:00:00 2001 From: Stewart X Addison <6487691+sxa@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:31:30 +0000 Subject: [PATCH 12/12] Remove debug statement --- sbin/build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/sbin/build.sh b/sbin/build.sh index ec00d9833..467514b3c 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -880,7 +880,6 @@ generateSBoM() { # This is because OS_ARCHITECTURE is currently the build arch, not the target arch, # and that confuses things when cross-compiling an x64 mac build on arm mac. # addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" - echo "DEBUG 1" if [[ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]]; then addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "x86_64" else