Skip to content

Commit

Permalink
Add hx install
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Apr 23, 2024
1 parent a494d0b commit 8a545cf
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ jobs:
hx current
hx current --name
hx current --full
cd ..
hx install foo.tar.gz
- name: Install extra tools
run: |
Expand Down Expand Up @@ -139,4 +141,6 @@ jobs:
haxe --version
echo "Check hx current"
hx current
cd ..
hx install foo.zip
4 changes: 3 additions & 1 deletion extra/hx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/bash

ROOT=$(dirname $(readlink -f $0))/..
CALL_SITE=$(realpath $(pwd))

BUILD_OS="linux64"
if [[ "$OSTYPE" == "darwin"* ]]; then
BUILD_OS="mac"
fi

VERSION="${BUILD_OS}_569e52e"

HAXE_STD_PATH=$ROOT/build/$VERSION/std $ROOT/build/$VERSION/haxe --cwd $ROOT run-hx.hxml $@
CALL_SITE=$CALL_SITE HAXE_STD_PATH=$ROOT/build/$VERSION/std $ROOT/build/$VERSION/haxe --cwd $ROOT run-hx.hxml $@
1 change: 1 addition & 0 deletions extra/hx.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ SET ROOT=%~dp0
SET ROOT=%ROOT%..
SET VERSION=windows64_569e52e
SET HAXE_STD_PATH=%ROOT%\build\%VERSION%\std
SET CALL_SITE=%CD%

CALL %ROOT%\build\%VERSION%\haxe.exe --cwd %ROOT% run-hx.hxml %*
35 changes: 26 additions & 9 deletions src/HaxeDownload.hx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ class HaxeDownload {
}
}

public static function installLocal(file:String, ?alias:String):Void {
file = Path.isAbsolute(file) ? file : Path.join([Utils.getCallSite(), file]);
if (!FileSystem.exists(file)) throw 'Cannot find release file $file';

// Copy archive to releases/
final filename = Path.withoutDirectory(file);
final dest = Path.join([Utils.releasesDir, filename]);
FileSync.copyFile(file, dest);

// Install release
installFile(dest, filename, alias);
}

static function downloadLatest(?alias:String = "dev"):Void {
final url = Utils.getBuildUrl("latest");
install(url[0], url[1], alias);
Expand All @@ -58,17 +71,21 @@ class HaxeDownload {

DownloadHelper.download(url + filename, path, () -> {
Sys.println('Downloaded $filename');
final out = DownloadHelper.extract(path);
FileSystem.deleteFile(path);
installFile(path, filename, alias);
});
}

final releasePath = Path.join([FileSystem.absolutePath(Utils.releasesDir), out]);
if (alias == null) alias = Utils.getVersionString(releasePath);
static function installFile(path:String, filename:String, ?alias:String):Void {
final out = DownloadHelper.extract(path);
FileSystem.deleteFile(path);

final versionPath = Path.join([Utils.versionsDir, alias]);
try FileSystem.deleteFile(versionPath) catch(_) {}
FileSync.symlink(releasePath, versionPath);
Sys.println('Installed $filename as $alias');
});
final releasePath = Path.join([FileSystem.absolutePath(Utils.releasesDir), out]);
if (alias == null) alias = Utils.getVersionString(releasePath);

final versionPath = Path.join([Utils.versionsDir, alias]);
try FileSystem.deleteFile(versionPath) catch(_) {}
FileSync.symlink(releasePath, versionPath);
Sys.println('Installed $filename as $alias');
}

public static function displayUsage() {
Expand Down
3 changes: 3 additions & 0 deletions src/HaxeManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class HaxeManager {
case ["download", args]: HaxeDownload.run(args);
case ["select", args]: HaxeSelect.run(args);

case ["install", [file]]: HaxeDownload.installLocal(file);
case ["install", [file, alias]]: HaxeDownload.installLocal(file, alias);

case ["current", []]: Sys.println(Utils.getCurrent().or(""));
case ["current", ["--name"]]:
if (Sys.systemName() == "Windows")
Expand Down
4 changes: 4 additions & 0 deletions src/tools/Utils.hx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class Utils {
link(dir);
}

public static function getCallSite():String {
return Sys.getEnv("CALL_SITE");
}

static function unlinkCurrent():Void {
if (FileSystem.exists(currentDir)) FileSync.unlink(currentDir);
}
Expand Down

0 comments on commit 8a545cf

Please sign in to comment.