Skip to content

Integrate boilerplate logic into the build.java script itself #75

@Karm

Description

@Karm

During the Windows CI automation it turned out some (for me) serious batch-fu was needed. It might have been easier if written in PowerShell entirely, but it would have been definitely easier if those preparation tasks were actually carried out by the build.java script itself. The goal of this issue is to translate these steps to Java and integrate nicely into build.java.

Current Windows build code:

@echo off
set PYTHONHTTPSVERIFY=0
set "JAVA_HOME=C:\Program Files\AdoptOpenJDK\%OPENJDK%"
set "PATH=%JAVA_HOME%\bin;%PATH%"
set MAVEN_REPO=C:\tmp\.m2\repository
set "MANDREL_REPO=%WORKSPACE%\mandrel"
set "MX_HOME=%WORKSPACE%\mx"

pushd mandrel
for /F "tokens=*" %%i in ('"git log --pretty=format:%%h -n1"') do set VER=%%i
set "MANDREL_VERSION=%MANDREL_VERSION_SUBSTRING% %VER%"
for /f "tokens=1 delims= " %%a IN ("%MANDREL_VERSION%") do set MANDREL_VERSION_UNTIL_SPACE=%%a
for /f "tokens=6" %%g in ('java --version 2^>^&1 ^| findstr /R "Runtime.*build "') do set JAVA_VERSION=%%g
set JAVA_VERSION=%JAVA_VERSION:~0,-1%
set MANDREL_HOME=%WORKSPACE%\mandrel-java11-%MANDREL_VERSION_UNTIL_SPACE%
popd

call vcvars64
IF NOT %ERRORLEVEL% == 0 ( exit 1 )

"%JAVA_HOME%\bin\java" -ea build.java --maven-local-repository "%MAVEN_REPO%" --mandrel-repo "%MANDREL_REPO%" --mx-home "%MX_HOME%" --mandrel-version "%MANDREL_VERSION%" --mandrel-home "%MANDREL_HOME%" --archive-suffix zip
IF NOT %ERRORLEVEL% == 0 ( exit 1 )

for /f "tokens=5" %%g in ('dir mandrel-*.zip ^| findstr /R mandrel-.*.zip') do set ZIP_NAME=%%g
powershell -c "$hash=(Get-FileHash %ZIP_NAME% -Algorithm SHA1).Hash;echo \"$hash %ZIP_NAME%\"">%ZIP_NAME%.sha1
IF NOT %ERRORLEVEL% == 0 ( exit 1 )

(
echo This is a dev build of Mandrel from https://github.com/graalvm/mandrel.
echo Mandrel %MANDREL_VERSION%
echo OpenJDK used: %JAVA_VERSION%
) >MANDREL.md

if not exist "%MANDREL_HOME%\bin\native-image.cmd" (
  echo "Cannot find native-image tool. Quitting..."
  exit 1
) else (
  echo "native-image.cmd is present, good."
)

(
echo|set /p=" public class Hello {"
echo|set /p=" public static void main(String[] args) {"
echo|set /p="     System.out.println("Hello.");"
echo|set /p=" }"
echo|set /p=" }"
) >Hello.java

set "JAVA_HOME=%MANDREL_HOME%"
set "PATH=%JAVA_HOME%\bin;%PATH%"
javac Hello.java
native-image Hello

for /F "tokens=*" %%i in ('hello.exe') do set HELLO_OUT=%%i
if "%HELLO_OUT%" == "Hello." (
  echo Done
) else (
  echo Native image fail
  exit 1
)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions