Skip to content

Commit

Permalink
Rework scripts for downloading dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lymia committed Dec 19, 2023
1 parent 1c7a041 commit 9f11fc9
Show file tree
Hide file tree
Showing 14 changed files with 507 additions and 85 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ libraryDependencies += "org.tukaani" % "xz" % "1.9
ThisBuild / assemblyMergeStrategy := {
case x if x.startsWith("moe/lymia") => MergeStrategy.first
case x if x.endsWith("module-info.class") => MergeStrategy.discard
case x if x.startsWith("com/intellij") => MergeStrategy.first // for debug builds
case x =>
val oldStrategy = (ThisBuild / assemblyMergeStrategy).value
oldStrategy(x)
}

// Build native binaries
nativeImageInstalled := true
nativeImageGraalHome := (target.value / f"graalvm-${PlatformType.currentPlatform.name}").toPath
nativeImageGraalHome := (target.value / "deps" / f"graalvm-${PlatformType.currentPlatform.name}").toPath

nativeImageOptions += "--no-fallback"
nativeImageOptions += "-Djava.awt.headless=false"
Expand Down
12 changes: 2 additions & 10 deletions scripts/ci/build-installer_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
# THE SOFTWARE.
#

. scripts/ci/install-graalvm.sh

LINUXDEPLOY_DL="https://github.com/linuxdeploy/linuxdeploy/releases/download/1-alpha-20231026-1/linuxdeploy-x86_64.AppImage"
. scripts/ci/install-deps.sh

echo "Extracting native tarballs..."
rm -rfv target/native-bin || exit 1
Expand All @@ -46,12 +44,6 @@ ASSEMBLY_JAR="$(sbt "print assembly" --error || exit 1)"
echo "ASSEMBLY_JAR=$ASSEMBLY_JAR"
cp "$(echo "$ASSEMBLY_JAR" | head -n 1 | tr -d '\n')" target/"$ASSEMBLY_NAME" || exit 1

echo "Downloading tools..."
if [ ! -f target/linuxdeploy ]; then
wget -O target/linuxdeploy "$LINUXDEPLOY_DL" || exit 1
chmod +x target/linuxdeploy || exit 1
fi

echo "Cleaning up after previous scripts..."
rm -rfv target/native-image target/dist-build || exit 1
mkdir -p target/native-image target/dist-build || exit 1
Expand Down Expand Up @@ -80,6 +72,6 @@ cd ../../../.. || exit 1
# Build AppImage
echo "Building AppImage..."
cd target/dist-build/linux || exit 1
LDAI_COMP=xz ../../linuxdeploy --appdir AppDir/ --output appimage || exit 1
LDAI_COMP=xz ../../deps/linuxdeploy --appdir AppDir/ --output appimage || exit 1
cd ../../.. || exit 1
cp -v target/dist-build/linux/MPPatch_Installer-x86_64.AppImage target/"$APPIMAGE_NAME" || exit 1
37 changes: 25 additions & 12 deletions scripts/ci/build-installer_win32.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
$ErrorActionPreference = "Stop"
#
# Copyright (c) 2015-2023 Lymia Kanokawa <lymia@lymia.moe>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

$URL_RCEDIT = "https://github.com/electron/rcedit/releases/download/v2.0.0/rcedit-x64.exe"
$ErrorActionPreference = "Stop"

# Install graalvm
scripts/ci/install-graalvm.ps1
scripts/ci/install-deps.ps1

# Extract native tarballs
echo "Extracting native tarballs..."
Expand All @@ -15,13 +35,6 @@ cd target/native-bin
tar -xv -f ../../target/mppatch_ci_natives-linux.tar.gz
cd ../..

# Download rcedit if it isn't already downloaded
if (-Not(Test-Path "target/rcedit.exe" -PathType Leaf)) {
echo "Downloading 'rcedit.exe'..."
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri "$URL_RCEDIT" -OutFile "target/rcedit.exe"
}

# Find the current version
$VERSION = "$( sbt "print version" --error )".Trim()
$VERSION = $VERSION.Split(" ")[0].Trim() # fix a weird Github Actions difference
Expand All @@ -38,7 +51,7 @@ if (Test-Path target/native-image) {
rm -Recurse -Force -Verbose target/native-image
}
sbt nativeImage
target/rcedit.exe "target/native-image/mppatch-installer.exe" `
target/deps/rcedit.exe "target/native-image/mppatch-installer.exe" `
--set-version-string "FileDescription" "MPPatch Installer - Native Image Installer" `
--set-file-version "$FILE_VERSION" `
--set-version-string "ProductName" "MPPatch" `
Expand Down Expand Up @@ -78,7 +91,7 @@ echo "Writing NSIS split resources..."
[System.IO.File]::WriteAllBytes("target/mppatch-installer-data.dat", @($bytes[$nsisLocation..($bytes.Count - 1)]))

echo "Building final installer..."
target/rcedit.exe "target/mppatch-installer-stub.exe" `
target/deps/rcedit.exe "target/mppatch-installer-stub.exe" `
--set-version-string "FileDescription" "MPPatch Installer" `
--set-file-version "$FILE_VERSION" `
--set-version-string "ProductName" "MPPatch" `
Expand Down
65 changes: 65 additions & 0 deletions scripts/ci/install-deps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#
# Copyright (c) 2015-2023 Lymia Kanokawa <lymia@lymia.moe>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

$ErrorActionPreference = "Stop"

$GRAALVM_WIN32_URL = "https://download.bell-sw.com/vm/23.1.1/bellsoft-liberica-vm-openjdk21.0.1+12-23.1.1+1-windows-amd64.zip"
$GRAALVM_WIN32_DIR = "bellsoft-liberica-vm-openjdk21-23.1.1"
$GRAALVM_WIN32_SHA = "edf9abd89a5da392488517e5135e1ac158f37e44c6c677cd7c784937b515dbdb"

$RCEDIT_URL = "https://github.com/electron/rcedit/releases/download/v2.0.0/rcedit-x64.exe"
$RCEDIT_SHA = "3e7801db1a5edbec91b49a24a094aad776cb4515488ea5a4ca2289c400eade2a"

function Download-Dependency {
param (
[string]$Name,
[string]$Uri,
[string]$Sha256
)

if (-Not(Test-Path "target/deps/dl/$Name" -PathType Container)) {
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri "$Uri" -OutFile "target/deps/dl/$Name"
$FileSha256=$(Get-FileHash "target/deps/dl/$Name" -Algorithm SHA256).Hash
echo "${Name}: expected - $Sha256, found - $FileSha256"
if ($Sha256 -ne $FileSha256) {
Remove-Item "target/deps/dl/$Name"
throw "${Name}: sha256 mismatch"
}
}
}

New-Item "target/deps/dl" -ItemType Directory -ea 0 -Verbose

# Install GraalVM for Windows
if (-Not(Test-Path "target/deps/graalvm-win32" -PathType Container)) {
echo "Downloading GraalVM for Windows..."
Download-Dependency -Name "graalvm-win32.zip" -Uri "$GRAALVM_WIN32_URL" -Sha256 "$GRAALVM_WIN32_SHA"
Expand-Archive -Path "target/deps/dl/graalvm-win32.zip" -DestinationPath "target/deps/graalvm-win32"
}

# Install rcedit
if (-Not (Test-Path "target/deps/rcedit.exe" -PathType Container)) {
echo "Downloading rcedit..."
Download-Dependency -Name "rcedit.exe" -Uri "$RCEDIT_URL" -Sha256 "$RCEDIT_SHA"
Copy-Item "target/deps/dl/rcedit.exe" "target/deps/rcedit.exe"
}
62 changes: 62 additions & 0 deletions scripts/ci/install-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

#
# Copyright (c) 2015-2023 Lymia Kanokawa <lymia@lymia.moe>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

GRAALVM_LINUX_URL="https://download.bell-sw.com/vm/23.1.1/bellsoft-liberica-vm-openjdk21.0.1+12-23.1.1+1-linux-amd64.tar.gz"
GRAALVM_LINUX_DIR="bellsoft-liberica-vm-openjdk21-23.1.1"
GRAALVM_LINUX_SHA="8b3549e3a53cd4bb5e27bf1fa373cf9573874218c55b70681799a68004d088fa"

LINUXDEPLOY_URL="https://github.com/linuxdeploy/linuxdeploy/releases/download/1-alpha-20231026-1/linuxdeploy-x86_64.AppImage"
LINUXDEPLOY_SHA="c242e21f573532c03adc2c356b70055ee0de2ae66e235d086b714e69d2cae529"

mkdir -pv target/deps target/deps/dl || exit 1

download_file() {
if [ ! -f "target/deps/dl/$1" ]; then
wget "$2" -O "target/deps/dl/$1" || exit 1
CUR_SHA256="$(sha256sum "target/deps/dl/$1" | cut -d' ' -f 1 | tr -d '\n')"
if [ "$CUR_SHA256" != "$3" ]; then
rm -v "target/deps/dl/$1" || exit 1
echo "$1: sha256 mismatch"
exit 1
fi
fi
}

# GraalVM for Linux
if [ ! -d target/deps/graalvm-linux ]; then
echo "Downloading GraalVM for Linux..."
download_file "graalvm-linux.tar.gz" "$GRAALVM_LINUX_URL" "$GRAALVM_LINUX_SHA" || exit 1
cd target/deps || exit 1
tar -xv -f dl/graalvm-linux.tar.gz || exit 1
mv -v "$GRAALVM_LINUX_DIR" graalvm-linux || exit 1
cd ../.. || exit 1
fi

# linuxdeploy
if [ ! -f target/deps/linuxdeploy ]; then
echo "Downloading linuxdeploy..."
download_file "linuxdeploy" "$LINUXDEPLOY_URL" "$LINUXDEPLOY_SHA" || exit 1
cp -v target/deps/dl/linuxdeploy target/deps/ || exit 1
chmod -v +x target/deps/linuxdeploy || exit 1
fi
14 changes: 0 additions & 14 deletions scripts/ci/install-graalvm.ps1

This file was deleted.

35 changes: 0 additions & 35 deletions scripts/ci/install-graalvm.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@
}]},
"bundles":[{
"name":"com.formdev.flatlaf.resources.Bundle",
"locales":[""]
"locales":["", "und"]
}, {
"name":"com.sun.org.apache.xml.internal.serializer.XMLEntities",
"locales":[""]
"locales":["", "und"]
}, {
"name":"com.sun.swing.internal.plaf.basic.resources.basic",
"classNames":["com.sun.swing.internal.plaf.basic.resources.basic"]
Expand Down
Loading

0 comments on commit 9f11fc9

Please sign in to comment.