Skip to content

Commit eb64e2b

Browse files
committed
Add hx install
1 parent a494d0b commit eb64e2b

File tree

6 files changed

+47
-10
lines changed

6 files changed

+47
-10
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ Usage: hx download <VERSION> [AS_NAME]
3434
Note: short hash VERSION is also supported for development nightlies (e.g. dd5e467)
3535
```
3636

37+
### Installing archive
38+
39+
If you already have an archive available (a nightly from a branch other than
40+
`development`, for example), you can install it with:
41+
42+
`hx install my_haxe_release.tar.gz [AS_NAME]`
43+
3744
## List available versions
3845

3946
Use `hx list` to get a list of all haxe versions available throught your (local)

extra/hx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/bin/bash
22

33
ROOT=$(dirname $(readlink -f $0))/..
4+
CALL_SITE=$(realpath $(pwd))
5+
46
BUILD_OS="linux64"
57
if [[ "$OSTYPE" == "darwin"* ]]; then
68
BUILD_OS="mac"
79
fi
810

911
VERSION="${BUILD_OS}_569e52e"
1012

11-
HAXE_STD_PATH=$ROOT/build/$VERSION/std $ROOT/build/$VERSION/haxe --cwd $ROOT run-hx.hxml $@
13+
CALL_SITE=$CALL_SITE HAXE_STD_PATH=$ROOT/build/$VERSION/std $ROOT/build/$VERSION/haxe --cwd $ROOT run-hx.hxml $@

extra/hx.bat

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ SET ROOT=%~dp0
44
SET ROOT=%ROOT%..
55
SET VERSION=windows64_569e52e
66
SET HAXE_STD_PATH=%ROOT%\build\%VERSION%\std
7+
SET CALL_SITE=%CD%
78

89
CALL %ROOT%\build\%VERSION%\haxe.exe --cwd %ROOT% run-hx.hxml %*

src/HaxeDownload.hx

+26-9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ class HaxeDownload {
3737
}
3838
}
3939

40+
public static function installLocal(file:String, ?alias:String):Void {
41+
file = Path.isAbsolute(file) ? file : Path.join([Utils.getCallSite(), file]);
42+
if (!FileSystem.exists(file)) throw 'Cannot find release file $file';
43+
44+
// Copy archive to releases/
45+
final filename = Path.withoutDirectory(file);
46+
final dest = Path.join([Utils.releasesDir, filename]);
47+
FileSync.copyFile(file, dest);
48+
49+
// Install release
50+
installFile(dest, filename, alias);
51+
}
52+
4053
static function downloadLatest(?alias:String = "dev"):Void {
4154
final url = Utils.getBuildUrl("latest");
4255
install(url[0], url[1], alias);
@@ -58,17 +71,21 @@ class HaxeDownload {
5871

5972
DownloadHelper.download(url + filename, path, () -> {
6073
Sys.println('Downloaded $filename');
61-
final out = DownloadHelper.extract(path);
62-
FileSystem.deleteFile(path);
74+
installFile(path, filename, alias);
75+
});
76+
}
6377

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

67-
final versionPath = Path.join([Utils.versionsDir, alias]);
68-
try FileSystem.deleteFile(versionPath) catch(_) {}
69-
FileSync.symlink(releasePath, versionPath);
70-
Sys.println('Installed $filename as $alias');
71-
});
82+
final releasePath = Path.join([FileSystem.absolutePath(Utils.releasesDir), out]);
83+
if (alias == null) alias = Utils.getVersionString(releasePath);
84+
85+
final versionPath = Path.join([Utils.versionsDir, alias]);
86+
try FileSystem.deleteFile(versionPath) catch(_) {}
87+
FileSync.symlink(releasePath, versionPath);
88+
Sys.println('Installed $filename as $alias');
7289
}
7390

7491
public static function displayUsage() {

src/HaxeManager.hx

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class HaxeManager {
1515
case ["download", args]: HaxeDownload.run(args);
1616
case ["select", args]: HaxeSelect.run(args);
1717

18+
case ["install", [file]]: HaxeDownload.installLocal(file);
19+
case ["install", [file, alias]]: HaxeDownload.installLocal(file, alias);
20+
1821
case ["current", []]: Sys.println(Utils.getCurrent().or(""));
1922
case ["current", ["--name"]]:
2023
if (Sys.systemName() == "Windows")
@@ -59,6 +62,9 @@ class HaxeManager {
5962
' or: ${ORANGE}hx download latest ${UNDERLINE}[AS_NAME]${RESET}',
6063
' Install Haxe releases or nightlies',
6164
'',
65+
' or: ${ORANGE}hx install ${UNDERLINE}<FILE>${UNDERLINE_OFF} ${UNDERLINE}[AS_NAME]${RESET}',
66+
' Install Haxe release archive',
67+
'',
6268
' or: ${ORANGE}hx ${UNDERLINE}<VERSION>${RESET}',
6369
' or: ${ORANGE}hx select ${UNDERLINE}<VERSION>${RESET}',
6470
' Switch to installed Haxe version ${BOLD}VERSION${BOLD_OFF}',

src/tools/Utils.hx

+4
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class Utils {
135135
link(dir);
136136
}
137137

138+
public static function getCallSite():String {
139+
return Sys.getEnv("CALL_SITE");
140+
}
141+
138142
static function unlinkCurrent():Void {
139143
if (FileSystem.exists(currentDir)) FileSync.unlink(currentDir);
140144
}

0 commit comments

Comments
 (0)