Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User can now specify regexes used to find binaries #833

Merged
merged 11 commits into from
Mar 6, 2024
61 changes: 18 additions & 43 deletions wix/Build.OpenJDK_generic.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,55 +36,28 @@ IF NOT DEFINED PRODUCT_HELP_LINK SET PRODUCT_HELP_LINK=https://github.com/adopti
IF NOT DEFINED PRODUCT_SUPPORT_LINK SET PRODUCT_SUPPORT_LINK=https://adoptium.net/support
IF NOT DEFINED PRODUCT_UPDATE_INFO_LINK SET PRODUCT_UPDATE_INFO_LINK=https://adoptium.net/temurin/releases

REM This needs tidying up, it's got out of control now
IF NOT "%ARCH%" == "x64" (
IF NOT "%ARCH%" == "x86-32" (
IF NOT "%ARCH%" == "arm64" (
IF NOT "%ARCH%" == "x86-32 x64" (
IF NOT "%ARCH%" == "x86-32 arm64" (
IF NOT "%ARCH%" == "arm64 x86-32" (
IF NOT "%ARCH%" == "x64 x86-32" (
IF NOT "%ARCH%" == "x64 arm64" (
IF NOT "%ARCH%" == "arm64 x64" (
IF NOT "%ARCH%" == "x86-32 x64 arm64" (
IF NOT "%ARCH%" == "x86-32 arm64 x64" (
IF NOT "%ARCH%" == "arm64 x86-32 x64" (
IF NOT "%ARCH%" == "arm64 x64 x86-32" (
IF NOT "%ARCH%" == "x86-32 x64 arm64" (
IF NOT "%ARCH%" == "x64 x86-32 arm64" (
ECHO ARCH %ARCH% not supported : valid values : x64, x86-32, arm64, x86-32 x64, x64 x86-32, x86-32 x64 arm64, x86-32 arm64 x64, arm64 x86-32 x64, arm64 x64 x86-32, x86-32 x64 arm64, x64 x86-32 arm64
GOTO FAILED
)
)
)
)
)
)
)
)
)
)
)
)
)
)
powershell -ExecutionPolicy Bypass -File "%~dp0\helpers\Validate-Input.ps1" ^
-toValidate '%ARCH%' ^
-validInputs "x64 x86-32 arm64" ^
-delimiter " "

IF %ERRORLEVEL% == 1 (
ECHO ARCH %ARCH% not supported : valid values are any combination of : x64, x86-32, arm64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"x86" is missing here.

(I don't know how x86 is different from x86-32 and why it as been added)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x86 is the same as x86-32. Some vendors (like Microsoft) use x86 instead of x86-32 so this change helps vendors use this code without local modification

Copy link
Contributor Author

@jmjaffe37 jmjaffe37 Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, I updated this for you in my latest PR: #851

GOTO FAILED
)

REM Update to handle the change of build variant until implications
REM of setting this to Temurin can be evaluated
IF "%JVM%" == "temurin" SET JVM=hotspot

IF NOT "%JVM%" == "hotspot" (
IF NOT "%JVM%" == "openj9" (
IF NOT "%JVM%" == "dragonwell" (
IF NOT "%JVM%" == "openj9 hotspot" (
IF NOT "%JVM%" == "hotspot openj9" (
ECHO JVM "%JVM%" not supported : valid values : hotspot, openj9, dragonwell, hotspot openj9, openj9 hotspot
GOTO FAILED
)
)
)
)
powershell -ExecutionPolicy Bypass -File "%~dp0\helpers\Validate-Input.ps1" ^
-toValidate '%JVM%' ^
-validInputs "hotspot,openj9,dragonwell,openj9 hotspot,hotspot openj9" ^
-delimiter ","

IF %ERRORLEVEL% == 1 (
ECHO JVM "%JVM%" not supported : valid values : hotspot, openj9, dragonwell, hotspot openj9, openj9 hotspot
GOTO FAILED
)

IF NOT "%PRODUCT_CATEGORY%" == "jre" (
Expand Down Expand Up @@ -147,6 +120,8 @@ FOR %%A IN (%ARCH%) DO (
IF !PLATFORM! == x86-32 (
SET PLATFORM=x86
)
@REM Microsoft uses "x86" instead of "x86-32" for the platform folder
IF !VENDOR! == Microsoft SET FOLDER_PLATFORM=!PLATFORM!
jmjaffe37 marked this conversation as resolved.
Show resolved Hide resolved

SET SETUP_RESOURCES_DIR=.\Resources

Expand Down
61 changes: 52 additions & 9 deletions wix/SourceDir/CreateSourceFolder.AdoptOpenJDK.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
<#
.SYNOPSIS
This script extracts the contents of a zip file to a directory structure that is expected by the Wix toolset.

.DESCRIPTION
The script takes a zip file and extracts its contents to a directory structure that is expected by the Wix toolset.
The script also performs some cleanup on the extracted files.

.PARAMETER openjdk_filename_regex
A regular expression that matches the OpenJDK filename. Default is ^OpenJDK(?<major>\d*).

.PARAMETER jvm_regex
A regular expression that matches the JVM. Default is (?<jvm>hotspot|openj9|dragonwell).

.PARAMETER jvm
The JVM to be used. If not provided, the script will attempt to extract the JVM from the filename.

.PARAMETER platform_regex
A regular expression that matches the platform. Default is (?<platform>x86-32|x64|aarch64).

.NOTES
File Name: CreateSourceFolder.AdoptOpenJDK.ps1
karianna marked this conversation as resolved.
Show resolved Hide resolved
Author : AdoptOpenJDK
Version : 1.0
Date : March. 01, 2024

.EXAMPLE
PS> .\CreateSourceFolder.AdoptOpenJDK.ps1 -openjdk_filename_regex "^OpenJDK(?<major>\d*)" -platform_regex "(?<platform>x86-32|x64|aarch64)" -jvm_regex "(?<jvm>hotspot|openj9|dragonwell)" -jvm "hotspot"

#>

param (
[Parameter(Mandatory = $false)]
[string]$openjdk_filename_regex = "^OpenJDK(?<major>\d*)",
[Parameter(Mandatory = $false)]
[string]$platform_regex = "(?<platform>x86-32|x64|aarch64)",
[Parameter(Mandatory = $false)]
[string]$jvm_regex = "(?<jvm>hotspot|openj9|dragonwell)",
[Parameter(Mandatory = $false)]
[string]$jvm = ""
)

Get-ChildItem -Path .\ -Filter *.zip -File -Name| ForEach-Object {

$filename = [System.IO.Path]::GetFileName($_)
Write-Output "Processing filename : $filename"

# validate that the zip file is OpenJDK with an optional major version number
$openjdk_filename_regex = "^OpenJDK(?<major>\d*)"
$openjdk_found = $filename -match $openjdk_filename_regex
if (!$openjdk_found) {
Write-Output "filename : $filename doesn't match regex $openjdk_filename_regex"
Expand All @@ -20,16 +61,18 @@ Get-ChildItem -Path .\ -Filter *.zip -File -Name| ForEach-Object {
$major=$openjdk_basedir + $Matches.major
}

$jvm_regex = "(?<jvm>hotspot|openj9|dragonwell)"
$jvm_found = $filename -match $jvm_regex
if (!$jvm_found) {
Write-Output "filename : $filename doesn't match regex $jvm_regex"
exit 2
if ([string]::IsNullOrEmpty($jvm)) {

$jvm_found = $filename -match $jvm_regex
if (!$jvm_found) {
Write-Output "filename : $filename doesn't match regex $jvm_regex"
exit 2
}
$jvm = $Matches.jvm

}
$jvm = $Matches.jvm

# Windows Architecture supported
$platform_regex = "(?<platform>x86-32|x64|aarch64)"
$platform_found = $filename -match $platform_regex
if (!$platform_found) {
Write-Output "filename : $filename doesn't match regex $platform_regex"
Expand All @@ -56,7 +99,7 @@ Get-ChildItem -Path .\ -Filter *.zip -File -Name| ForEach-Object {
} elseif ( $_.Name -Match "(.*)_(.*)$" ) {
$NewName = $_.Name -replace "(.*)_(.*)$",'$1'
}

$Destination = Join-Path -Path $SourcePath -ChildPath $NewName

if (Test-Path $Destination) { Remove-Item $Destination -Recurse; }
Expand Down
53 changes: 53 additions & 0 deletions wix/helpers/Validate-Input.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<#
.SYNOPSIS
This script verifies the validity an input, given a list of possible inputs.

.DESCRIPTION
The script takes a string as input and checks if it is valid against a list of valid inputs.
If the input is valid, the script returns 0. If the input is invalid, the script returns 1.

.PARAMETER validInputs
A comma seperated list of valid inputs.

.PARAMETER toValidate
The input to be verified.

.PARAMETER delimiter
The delimiter used to split the input string. Default is a space.

.NOTES
File Name: Validate-Input.ps1
Author : Joshua Martin-Jaffe
Version : 1.0
Date : Feb. 29, 2024

.EXAMPLE
PS> .\Validate-Input.ps1 -validInputs 'x86-32 x64' -toValidate 'x86-32 x64' -delimiter ' '

True

#>

param (
[Parameter(Mandatory = $true)]
[string]$validInputs,
[Parameter(Mandatory = $true)]
[string]$toValidate,
[Parameter(Mandatory = $true)]
[string]$delimiter
)

$validInputs = $validInputs.Trim("'")
$validInputArray = $validInputs -split "$delimiter"

$toValidate = $toValidate.Trim("'")
$inputArray = $toValidate -split "$delimiter"


for ($i = 0; $i -lt $inputArray.Length; $i++) {
if ($validInputArray -notcontains $inputArray[$i]) {
echo $inputArray[$i] ' is an invalid input'
exit 1 # Invalid input
}
}
exit 0 # Valid input
Loading