diff --git a/README.md b/README.md index 815fc64..eade296 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,13 @@ Usage: hx download [AS_NAME] Note: short hash VERSION is also supported for development nightlies (e.g. dd5e467) ``` +### Installing archive + +If you already have an archive available (a nightly from a branch other than +`development`, for example), you can install it with: + +`hx install my_haxe_release.tar.gz [AS_NAME]` + ## List available versions Use `hx list` to get a list of all haxe versions available throught your (local) diff --git a/extra/hx b/extra/hx index b71bb30..34e6dc5 100755 --- a/extra/hx +++ b/extra/hx @@ -1,6 +1,8 @@ #!/bin/bash ROOT=$(dirname $(readlink -f $0))/.. +CALL_SITE=$(realpath $(pwd)) + BUILD_OS="linux64" if [[ "$OSTYPE" == "darwin"* ]]; then BUILD_OS="mac" @@ -8,4 +10,4 @@ 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 $@ diff --git a/extra/hx.bat b/extra/hx.bat index 3d618c1..11993d9 100644 --- a/extra/hx.bat +++ b/extra/hx.bat @@ -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 %* diff --git a/src/HaxeDownload.hx b/src/HaxeDownload.hx index 69f84fe..39ee49d 100644 --- a/src/HaxeDownload.hx +++ b/src/HaxeDownload.hx @@ -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); @@ -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() { diff --git a/src/HaxeManager.hx b/src/HaxeManager.hx index 9efad0a..3601183 100644 --- a/src/HaxeManager.hx +++ b/src/HaxeManager.hx @@ -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") @@ -59,6 +62,9 @@ class HaxeManager { ' or: ${ORANGE}hx download latest ${UNDERLINE}[AS_NAME]${RESET}', ' Install Haxe releases or nightlies', '', + ' or: ${ORANGE}hx install ${UNDERLINE}${UNDERLINE_OFF} ${UNDERLINE}[AS_NAME]${RESET}', + ' Install Haxe release archive', + '', ' or: ${ORANGE}hx ${UNDERLINE}${RESET}', ' or: ${ORANGE}hx select ${UNDERLINE}${RESET}', ' Switch to installed Haxe version ${BOLD}VERSION${BOLD_OFF}', diff --git a/src/tools/Utils.hx b/src/tools/Utils.hx index 7931842..ef1b42f 100644 --- a/src/tools/Utils.hx +++ b/src/tools/Utils.hx @@ -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); }