Skip to content

Commit

Permalink
Simplify the parsing logic of makejdk_any_platform_args (#3957)
Browse files Browse the repository at this point in the history
* Simplify parsing logic

Signed-off-by: Sophia Guo <sophia.gwf@gmail.com>

* Simplify build args parsing

* unset SPEC temporarily for test

* remove unused code

* linter issue

* linter issue

* add param

---------

Signed-off-by: Sophia Guo <sophia.gwf@gmail.com>
  • Loading branch information
sophia-guo authored Oct 4, 2024
1 parent 73622de commit 47929da
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 117 deletions.
3 changes: 2 additions & 1 deletion test/system/reproducibleCompare/playlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
</test>
<test>
<testCaseName>Rebuild_Same_JDK_Reproducibility_Test_win</testCaseName>
<command>$(TEST_ROOT)$(D)system$(D)reproducibleCompare$(D)windows_repro_build_compare.sh $(SBOM_FILE) $(JDK_FILE) $(REPORTDIR); \
<command>unset SPEC;\
$(TEST_ROOT)$(D)system$(D)reproducibleCompare$(D)windows_repro_build_compare.sh $(SBOM_FILE) $(JDK_FILE) $(REPORTDIR); \
$(TEST_STATUS)
</command>
<levels>
Expand Down
2 changes: 1 addition & 1 deletion tooling/reproducible/repro_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function removeSystemModulesHashBuilderParams() {
moduleHashesFunction="// Method jdk/internal/module/ModuleHashes\$Builder.hashForModule:(Ljava/lang/String;[B)Ljdk/internal/module/ModuleHashes\$Builder;"
moduleString="// String "
virtualFunction="invokevirtual"

local JDK_DIR="$1"
systemModules="SystemModules\$0.class SystemModules\$all.class SystemModules\$default.class"
for systemModule in $systemModules
do
Expand Down
2 changes: 1 addition & 1 deletion tooling/reproducible/repro_compare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ do
cleanTemurinBuildInfo "${JDK_DIR}"

if [[ "$OS" =~ CYGWIN* ]] || [[ "$OS" =~ Darwin* ]]; then
removeSystemModulesHashBuilderParams
removeSystemModulesHashBuilderParams "${JDK_DIR}"
fi
processModuleInfo
done
Expand Down
134 changes: 20 additions & 114 deletions tooling/reproducible/windows_repro_build_compare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ CPP_COMPILER_EXE="cl.exe"
WIN_URCT_BASE="C:/Program Files (x86)/Windows Kits/10/Redist"
SIGNTOOL_BASE="C:/Program Files (x86)/Windows Kits/10"

# Define What Are Configure Args & Redundant Args
# This MAY Need Updating If Additional Configure Args Are Passed
CONFIG_ARGS=("--disable-warnings-as-errors" "--disable-ccache" "--with-toolchain-version" "--with-ucrt-dll-dir" "--with-version-opt")
NOTUSE_ARGS=("--assemble-exploded-image" "--configure-args")

# Addiitonal Working Variables Defined For Use By This Script
SBOMLocalPath="$WORK_DIR/src_sbom.json"
DISTLocalPath="$WORK_DIR/src_jdk_dist.zip"
Expand All @@ -74,17 +69,6 @@ is_url() {
fi
}

# Function to check if a value is in the array
containsElement () {
local e
for e in "${@:2}"; do
if [ "$e" == "$1" ]; then
return 0 # Match found
fi
done
return 1 # No match found
}

Create_WorkDir() {
# Check if the folder exists & remove if it does
echo "Checking If Working Directory: $WORK_DIR Exists"
Expand Down Expand Up @@ -554,105 +538,27 @@ Clone_Build_Repo() {
Prepare_Env_For_Build() {
echo "Setting Variables"
export BOOTJDK_HOME=$WORK_DIR/jdk-${bootJDK}
echo "Parsing Make JDK Any Platform ARGS For Build"
# Split the string into an array of words
IFS=' ' read -ra words <<< "$buildArgs"

# Add The Build Time Stamp In Case It Wasnt In The SBOM ARGS
words+=("--build-reproducible-date")
words+=("\"$buildStamp\"")

# Initialize variables
param=""
value=""
params=()

# Loop through the words
for word in "${words[@]}"; do
# Check if the word starts with '--'
if [[ $word == --* ]] || [[ $word == -b* ]]; then
# If a parameter already exists, store it in the params array
if [[ -n $param ]]; then
params+=("$param=$value")
fi
# Reset variables for the new parameter
param="$word"
value=""
else
value+="$word "
fi
done

# Add the last parameter to the array
params+=("$param=$value")

# Read the separated parameters and values into a new array
export fixed_param=""
export fixed_value=""
export fixed_params=()
export new_params=""
CONFIG_ARRAY=()
BUILD_ARRAY=()
IGNORED_ARRAY=()

for p in "${params[@]}"; do
IFS='=' read -ra parts <<< "$p"
prefixed_param=${parts[0]}
fixed_param="${prefixed_param%%[[:space:]]}"
prepped_value=${parts[1]}
fixed_value=$(echo "$prepped_value" | awk '{$1=$1};1')
# Handle Special parameters
if [ "$fixed_param" == "--jdk-boot-dir" ]; then fixed_value="$BOOTJDK_HOME" ; fi
if [ "$fixed_param" == "--with-toolchain-version" ]; then fixed_value="$visualStudioVersion" ; fi
if [ "$fixed_param" == "--with-ucrt-dll-dir" ]; then fixed_value="temporary_speech_mark_placeholder${UCRT_PARAM_PATH}temporary_speech_mark_placeholder " ; fi
if [ "$fixed_param" == "--target-file-name" ]; then target_file="$fixed_value" ; fi
if [ "$fixed_param" == "--user-openjdk-build-root-directory" ]; then fixed_value="$WORK_DIR/temurin-build/workspace/build/openjdkbuild" ; fi

# Fix Build Variant Parameter To Strip JDK Version

if [ "$fixed_param" == "--build-variant" ] ; then
# Remove Leading White Space
trimmed_value=$(echo "$prepped_value" | awk '{$1=$1};1')
IFS=' ' read -r variant jdk <<< "$trimmed_value"
if [[ $jdk == jdk* ]]; then
variant="$variant "
else
temp="$variant "
variant="$jdk"
jdk="$temp"
fi
fixed_value=$variant
fi

# Check if fixed_param is in CONFIG_ARGS
if containsElement "$fixed_param" "${CONFIG_ARGS[@]}"; then
# Add Config Arg To New Array

# Handle Windows Param Names In Config Args (Replace Space with =)
if [ "$fixed_param" == "--with-toolchain-version" ] || [ "$fixed_param" == "--with-ucrt-dll-dir" ] || [ "$fixed_param" == "--with-version-opt" ] ; then
STRINGTOADD="$fixed_param=$fixed_value"
CONFIG_ARRAY+=("$STRINGTOADD")
else
STRINGTOADD="$fixed_param $fixed_value"
CONFIG_ARRAY+=("$STRINGTOADD")
fi
elif containsElement "$fixed_param" "${NOTUSE_ARGS[@]}"; then
# Strip Parameters To Be Ignored
STRINGTOADD="$fixed_param $fixed_value"
IGNORED_ARRAY+=("$STRINGTOADD")
else
# Not A Config Param Nor Should Be Ignored, So Add To Build Array
STRINGTOADD="$fixed_param $fixed_value"
BUILD_ARRAY+=("$STRINGTOADD")
fi
done

IFS=' ' build_string="${BUILD_ARRAY[*]}"
IFS=' ' config_string=$"${CONFIG_ARRAY[*]}"
final_params="$build_string --configure-args \"$config_string\" $jdk"
# set --build-reproducible-date if not yet
if [[ "${buildArgs}" != *"--build-reproducible-date"* ]]; then
buildArgs="--build-reproducible-date \"${buildStamp}\" ${buildArgs}"
fi
# reset --jdk-boot-dir
# shellcheck disable=SC2001
buildArgs="$(echo "$buildArgs" | sed -e "s|--jdk-boot-dir [^ ]*|--jdk-boot-dir ${BOOTJDK_HOME}|")"
# shellcheck disable=SC2001
buildArgs="$(echo "$buildArgs" | sed -e "s|--with-toolchain-version [^ ]*|with-toolchain-version ${visualStudioVersion}|")"
# shellcheck disable=SC2001
buildArgs="$(echo "$buildArgs" | sed -e "s|--with-ucrt-dll-dir=[^ ]*|--with-ucrt-dll-dir=temporary_speech_mark_placeholder${UCRT_PARAM_PATH}temporary_speech_mark_placeholder|")"
# shellcheck disable=SC2001
buildArgs="$(echo "$buildArgs" | sed -e "s|--user-openjdk-build-root-directory [^ ]*|--user-openjdk-build-root-directory ${WORK_DIR}/temurin-build/workspace/build/openjdkbuild/|")"
# remove ingored options
buildArgs=${buildArgs/--assemble-exploded-image /}
buildArgs=${buildArgs/--enable-sbom-strace /}

echo ""
echo "Make JDK Any Platform Argument List = "
echo "$final_params"
echo "$buildArgs"
echo ""
echo "Parameters Parsed Successfully"
}
Expand All @@ -662,9 +568,9 @@ Build_JDK() {

# Trigger Build
cd "$WORK_DIR"
echo "cd temurin-build && ./makejdk-any-platform.sh $final_params 2>&1 | tee build.$$.log" | sh
echo "cd temurin-build && ./makejdk-any-platform.sh $buildArgs 2>&1 | tee build.$$.log" | sh
# Copy The Built JDK To The Working Directory
cp "$WORK_DIR/temurin-build/workspace/target/$target_file" "$WORK_DIR/reproJDK.zip"
cp "${WORK_DIR}"/temurin-build/workspace/target/OpenJDK*-jdk_*.zip "$WORK_DIR/reproJDK.zip"
}

Compare_JDK() {
Expand Down

0 comments on commit 47929da

Please sign in to comment.