Skip to content

Commit

Permalink
comparable_patch.sh updates for Windows (#3561)
Browse files Browse the repository at this point in the history
* Update comparable_patch for Windows

Signed-off-by: U-andrew-repro-te\adoptium <anleonar@redhat.com>

* Add Windows comparable patch fixes

Signed-off-by: U-andrew-repro-te\adoptium <anleonar@redhat.com>

* Add Windows comparable patch fixes

Signed-off-by: U-andrew-repro-te\adoptium <anleonar@redhat.com>

* Update comparable_patch for Windows

Signed-off-by: U-andrew-repro-te\adoptium <anleonar@redhat.com>

* Update comparable_patch for Windows

Signed-off-by: U-andrew-repro-te\adoptium <anleonar@redhat.com>

---------

Signed-off-by: U-andrew-repro-te\adoptium <anleonar@redhat.com>
  • Loading branch information
andrew-m-leonard authored Dec 6, 2023
1 parent 5c41fcb commit e6bd6a1
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 29 deletions.
21 changes: 11 additions & 10 deletions tooling/ReproducibleBuilds.MD → tooling/ReproducibleBuilds.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,29 @@ The patching process involves:

#### Tooling setup:

1. The comparable patch tools, tooling/src/c/WindowsUpdateVsVersionInfo.c and src/java/temurin/tools/BinRepl.java need compiling
before the comparable_patch.sh can be run
1. The comparable patch tools, (Windows only) [tooling/src/c/WindowsUpdateVsVersionInfo.c](https://github.com/adoptium/temurin-build/blob/master/tooling/src/c/WindowsUpdateVsVersionInfo.c) and
[src/java/temurin/tools/BinRepl.java](https://github.com/adoptium/temurin-build/blob/master/tooling/src/java/temurin/tools/BinRepl.java) need compiling
before the comparable_patch.sh can be run.

2. Compile tooling/src/c/WindowsUpdateVsVersionInfo.c :
2. Compile [tooling/src/c/WindowsUpdateVsVersionInfo.c](https://github.com/adoptium/temurin-build/blob/master/tooling/src/c/WindowsUpdateVsVersionInfo.c) (Windows only):

- Ensure VS2022 SDK is installed and on PATH
- Compile:
- cd tooling/src/c
- cl WindowsUpdateVsVersionInfo.c version.lib

3. Compile src/java/temurin/tools/BinRepl.java :
3. Compile [src/java/temurin/tools/BinRepl.java](https://github.com/adoptium/temurin-build/blob/master/tooling/src/java/temurin/tools/BinRepl.java) :

- Ensure suitable JDK on PATH
- cd tooling/src/java
- javac temurin/tools/BinRepl.java

4. Setting environment within a CYGWIN shell :
4. Setting environment within a shell :

- [Windows only] For WindowsUpdateVsVersionInfo.exe : export PATH=<temurin-build>/tooling/src/c:$PATH
- [Windows only] For dumpbin.exe MSVC tool : export PATH=/cygdrive/c/progra\~1/micros\~2/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64:$PATH
- For BinRepl : export CLASSPATH=<temurin-build>/tooling/src/java:$CLASSPATH
- For WindowsUpdateVsVersionInfo.exe : export PATH=<temurin-build>/tooling/src/c:$PATH
- For dumpbin.exe MSVC tool : export PATH=/cygdrive/c/progra\~1/micros\~2/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64:$PATH
- For running BinRepl java : export PATH=<jdk>/bin:$PATH
- A JDK for running BinRepl java : export PATH=<jdk>/bin:$PATH

#### Running comparable_patch.sh:

Expand All @@ -84,7 +85,7 @@ before the comparable_patch.sh can be run
2. Run comparable_patch.sh

```bash
bash comparable_patch.sh <jdk_home_dir> <version_str> <vendor_name> <vendor_url> <vendor_bug_url> <vendor_vm_bug_url>
bash comparable_patch.sh --jdk-dir "<jdk_home_dir>" --version-string "<version_str>" --vendor-name "<vendor_name>" --vendor_url "<vendor_url>" --vendor-bug-url "<vendor_bug_url>" --vendor-vm-bug-url "<vendor_vm_bug_url>" [--patch-vs-version-info]
```

The Vendor strings and urls can be found by running your jdk's "java -XshowSettings":
Expand All @@ -102,7 +103,7 @@ java -XshowSettings:
eg.

```bash
bash comparable_patch.sh jdk1/jdk-21.0.1+12 "Temurin-21.0.1+12" "Eclipse Adoptium" "https://adoptium.net/" "https://github.com/adoptium/adoptium-support/issues" "https://github.com/adoptium/adoptium-support/issues"
bash ./comparable_patch.sh --jdk-dir "jdk1/jdk-21.0.1+12" --version-string "Temurin-21.0.1+12" --vendor-name "Eclipse Adoptium" --vendor_url "https://adoptium.net/" --vendor-bug-url "https://github.com/adoptium/adoptium-support/issues" --vendor-vm-bug-url "https://github.com/adoptium/adoptium-support/issues"
```

3. Unzip the other Vendor JDK to compare with, say into "jdk2", and run a similar comparable_patch.sh
Expand Down
99 changes: 80 additions & 19 deletions tooling/comparable_patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,60 @@ set -eu

TEMURIN_TOOLS_BINREPL="temurin.tools.BinRepl"

if [ "$#" -ne 6 ]; then
echo "Syntax: comparable_patch.sh <jdk_home_dir> <version_str> <vendor_name> <vendor_url> <vendor_bug_url> <vendor_vm_bug_url>"
JDK_DIR=""
VERSION_REPL=""
VENDOR_NAME=""
VENDOR_URL=""
VENDOR_BUG_URL=""
VENDOR_VM_BUG_URL=""
PATCH_VS_VERSION_INFO=false

# Parse arguments
while [[ $# -gt 0 ]] && [[ ."$1" = .-* ]] ; do
opt="$1";
shift;

case "$opt" in
"--jdk-dir" )
JDK_DIR="$1"; shift;;

"--version-string" )
VERSION_REPL="$1"; shift;;

"--vendor-name" )
VENDOR_NAME="$1"; shift;;

"--vendor_url" )
VENDOR_URL="$1"; shift;;

"--vendor-bug-url" )
VENDOR_BUG_URL="$1"; shift;;

"--vendor-vm-bug-url" )
VENDOR_VM_BUG_URL="$1"; shift;;

"--patch-vs-version-info" )
PATCH_VS_VERSION_INFO=true;;

*) echo >&2 "Invalid option: ${opt}"
echo 'Syntax: comparable_patch.sh --jdk-dir "<jdk_home_dir>" --version-string "<version_str>" --vendor-name "<vendor_name>" --vendor_url "<vendor_url>" --vendor-bug-url "<vendor_bug_url>" --vendor-vm-bug-url "<vendor_vm_bug_url>" [--patch-vs-version-info]'; exit 1;;
esac
done

if [ -z "$JDK_DIR" ] || [ -z "$VERSION_REPL" ] || [ -z "$VENDOR_NAME" ] || [ -z "$VENDOR_URL" ] || [ -z "$VENDOR_BUG_URL" ] || [ -z "$VENDOR_VM_BUG_URL" ]; then
echo "Error: Missing argument"
echo 'Syntax: comparable_patch.sh --jdk-dir "<jdk_home_dir>" --version-string "<version_str>" --vendor-name "<vendor_name>" --vendor_url "<vendor_url>" --vendor-bug-url "<vendor_bug_url>" --vendor-vm-bug-url "<vendor_vm_bug_url>" [--patch-vs-version-info]'
exit 1
fi

JDK_DIR="$1"
VERSION_REPL="$2"
VENDOR_NAME="$3"
VENDOR_URL="$4"
VENDOR_BUG_URL="$5"
VENDOR_VM_BUG_URL="$6"
echo "Patching:"
echo " JDK_DIR=$JDK_DIR"
echo " VERSION_REPL=$VERSION_REPL"
echo " VENDOR_NAME=$VENDOR_NAME"
echo " VENDOR_URL=$VENDOR_URL"
echo " VENDOR_BUG_URL=$VENDOR_BUG_URL"
echo " VENDOR_VM_BUG_URL=$VENDOR_VM_BUG_URL"
echo " PATCH_VS_VERSION_INFO=$PATCH_VS_VERSION_INFO"

# Remove excluded files known to differ
# NOTICE - Vendor specfic notice text file
Expand Down Expand Up @@ -206,7 +249,13 @@ function removeSystemModulesHashBuilderParams() {
# reprohex - A hex UUID to identify the binary version, again generated from binary content
function removeWindowsNonComparableData() {
echo "Removing EXE/DLL timestamps, CRC and debug repro hex from ${JDK_DIR}"
FILES=$(find "${JDK_DIR}" -type f -path '*.exe' && find "${JDK_DIR}" -type f -path '*.dll')

# We need to do this for all executables if patching VS_VERSION_INFO
if [[ "$PATCH_VS_VERSION_INFO" = true ]]; then
FILES=$(find "${JDK_DIR}" -type f -path '*.exe' && find "${JDK_DIR}" -type f -path '*.dll')
else
FILES=$(find "${JDK_DIR}" -type f -name 'jvm.dll')
fi
for f in $FILES
do
echo "Removing EXE/DLL non-comparable timestamp, CRC, debug repro hex from $f"
Expand Down Expand Up @@ -311,15 +360,23 @@ function neutraliseVsVersionInfo() {
echo "Successfully updated all EXE/DLL VS_VERSION_INFO in ${JDK_DIR}"
}

# Remove Vendor name from all binaries
# Remove Vendor name from executables
# If patching VS_VERSION_INFO, then all executables need patching,
# otherwise just jvm library that contains the Vendor string differences.
function removeVendorName() {
echo "Removing Vendor name: $VENDOR_NAME from binaries from ${JDK_DIR}"
echo "Removing Vendor name: $VENDOR_NAME from executables from ${JDK_DIR}"

if [[ "$OS" =~ CYGWIN* ]]; then
FILES=$(find "${JDK_DIR}" -type f -path '*.exe' && find "${JDK_DIR}" -type f -path '*.dll')
# We need to do this for all executables if patching VS_VERSION_INFO
if [[ "$PATCH_VS_VERSION_INFO" = true ]]; then
FILES=$(find "${JDK_DIR}" -type f -path '*.exe' && find "${JDK_DIR}" -type f -path '*.dll')
else
FILES=$(find "${JDK_DIR}" -type f -name 'jvm.dll')
fi
elif [[ "$OS" =~ Darwin* ]]; then
FILES=$(find "${JDK_DIR}" -type f -path '*.dylib')
FILES=$(find "${JDK_DIR}" -type f -name 'libjvm.dylib')
else
FILES=$(find "${JDK_DIR}" -type f -path '*.so')
FILES=$(find "${JDK_DIR}" -type f -name 'libjvm.so')
fi
for f in $FILES
do
Expand All @@ -336,7 +393,7 @@ function removeVendorName() {
sed -i "" "s=${VENDOR_NAME}=AAAAAA=g" "${plist}"
fi

echo "Successfully removed all Vendor name: $VENDOR_NAME from binaries from ${JDK_DIR}"
echo "Successfully removed all Vendor name: $VENDOR_NAME from executables from ${JDK_DIR}"
}

# Neutralise VersionProps.class/.java vendor strings
Expand Down Expand Up @@ -467,16 +524,20 @@ echo "Successfully removed all Signatures from ${JDK_DIR}"

removeExcludedFiles

# Needed due to vendor variation in jmod re-packing after signing, putting attributes in different order
processModuleInfo

removeSystemModulesHashBuilderParams

if [[ "$OS" =~ CYGWIN* ]]; then
# Patch Windows VS_VERSION_INFO[COMPANY_NAME]
if [[ "$OS" =~ CYGWIN* ]] && [[ "$PATCH_VS_VERSION_INFO" = true ]]; then
# Neutralise COMPANY_NAME
neutraliseVsVersionInfo

# SystemModules$*.class's differ due to hash differences from COMPANY_NAME
removeSystemModulesHashBuilderParams
fi

if [[ "$OS" =~ CYGWIN* ]]; then
removeWindowsNonComparableData
removeWindowsNonComparableData
fi

if [[ "$OS" =~ Darwin* ]]; then
Expand Down

0 comments on commit e6bd6a1

Please sign in to comment.