Skip to content

Commit

Permalink
Add Windows & Mac Compiler Fields To SBOM (#3608)
Browse files Browse the repository at this point in the history
  • Loading branch information
steelhead31 authored Jan 11, 2024
1 parent 928b569 commit 5bb80cb
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions sbin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ configureReproducibleBuildParameter() {
if [ "${BUILD_CONFIG[RELEASE]}" == "true" ]
then
# Use release date
addConfigureArg "--with-source-date=" "version"
addConfigureArg "--with-source-date=" "version"
else
# Use BUILD_TIMESTAMP date

Expand Down Expand Up @@ -141,7 +141,7 @@ configureReproducibleBuildParameter() {
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
Expand Down Expand Up @@ -343,7 +343,7 @@ configureVersionStringParameter() {
buildTimestamp="${buildTimestamp//Z/}"
else
# Get current ISO-8601 datetime
buildTimestamp=$(date -u +"%Y-%m-%d %H:%M:%S")
buildTimestamp=$(date -u +"%Y-%m-%d %H:%M:%S")
fi
BUILD_CONFIG[BUILD_TIMESTAMP]="${buildTimestamp}"

Expand Down Expand Up @@ -543,7 +543,7 @@ configureFreetypeLocation() {
esac
fi

if [[ -n "$freetypeDir" ]]; then
if [[ -n "$freetypeDir" ]]; then
echo "setting freetype dir to ${freetypeDir}"
addConfigureArg "--with-freetype=" "${freetypeDir}"
fi
Expand Down Expand Up @@ -887,6 +887,16 @@ generateSBoM() {
addGCC
fi

# Add Windows Compiler Version To SBOM
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
addCompilerWindows
fi

# Add Mac Compiler Version To SBOM
if [ "$(uname)" == "Darwin" ]; then
addCompilerMacOS
fi

addBootJDK

# Add ALSA 3rd party
Expand Down Expand Up @@ -1112,6 +1122,32 @@ addGCC() {
addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "GCC" "${gcc_version}"
}

addCompilerWindows() {
local inputConfigFile="${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/configure.txt"

## Extract Windows Compiler Versions
local msvs_version="$(grep -o -P '\* Toolchain:\s+\K[^"]+' "${inputConfigFile}")"
local msvs_c_version="$(grep -o -P '\* C Compiler:\s+\K[^"]+' "${inputConfigFile}" | awk '{print $2}')"
local msvs_cpp_version="$(grep -o -P '\* C\+\+ Compiler:\s+\K[^"]+' "${inputConfigFile}" | awk '{print $2}')"

echo "Adding Windows Compiler versions to SBOM: ${msvs_version}"
addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "MSVS Windows Compiler Version" "${msvs_version}"
echo "Adding Windows C Compiler version to SBOM: ${msvs_c_version}"
addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "MSVS C Compiler Version" "${msvs_c_version}"
echo "Adding Windows C++ Compiler version to SBOM: ${msvs_cpp_version}"
addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "MSVS C++ Compiler Version" "${msvs_cpp_version}"
}

addCompilerMacOS() {
local inputConfigFile="${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/configure.txt"

## local macx_version="$(cat "${inputConfigFile}" | grep "* Toolchain:" | awk -F ':' '{print $2}' | sed -e 's/^[ \t]*//')"
local macx_version="$(grep ".* Toolchain:" "${inputConfigFile}" | awk -F ':' '{print $2}' | sed -e 's/^[ \t]*//')"

echo "Adding MacOS compiler version to SBOM: ${macx_version}"
addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "MacOS Compiler" "${macx_version}"
}

addBootJDK() {
local inputConfigFile="${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/configure.txt"

Expand Down Expand Up @@ -1720,7 +1756,7 @@ getFirstTagFromOpenJDKGitRepo() {
if [ -z "$firstMatchingNameFromRepo" ]; then
echo "WARNING: Failed to identify latest tag in the repository" 1>&2
# If the ADOPT_BRANCH_SAFETY flag is set, we may be building from an alternate
# repository that doesn't have the same tags, so allow defaults. For a better
# repository that doesn't have the same tags, so allow defaults. For a better
# options see https://github.com/adoptium/temurin-build/issues/2671
if [ "${BUILD_CONFIG[DISABLE_ADOPT_BRANCH_SAFETY]}" == "true" ]; then
if [ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" == "8" ]; then
Expand Down

0 comments on commit 5bb80cb

Please sign in to comment.