Skip to content

Commit 4e58da0

Browse files
committed
Replace hxfzf extra with hx list-modules
1 parent c6d97c1 commit 4e58da0

8 files changed

+130
-97
lines changed

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ On Unix, you can also run:
5555
- `hx current --name` to get the name under which that version is installed
5656
- `hx current --full` to get both name and version string (`[NAME] ([VERSION])`)
5757

58+
## List all Haxe modules for current hxml
59+
60+
Prints a list of all `.hx` files in all your classpath, to be passed to `fzf`
61+
or other tools.
62+
63+
Usage: `hx list-modules [compile.hxml]` (will default to `build.hxml`)
64+
65+
5866
## Included tools
5967

6068
`extra/` folder contains optional tools you can install individually with their
@@ -63,13 +71,6 @@ On Unix, you can also run:
6371
Note that those have been written when Haxe Manager was unix only and probably
6472
can't work at all on Windows.
6573

66-
### `hxfzf`
67-
68-
Prints a list of all `.hx` files in all your classpath, to be passed to `fzf`
69-
or other tools.
70-
71-
Usage: `hxfzf [compile.hxml]` (will default to `build.hxml`)
72-
7374
### `++haxe`
7475

7576
Note if you're using Haxe >= 4.3.0: this is not useful anymore, since

extra/fzf/classpath.hxml

-3
This file was deleted.

extra/fzf/hxfzf.sh

-44
This file was deleted.

extra/fzf/install.sh

-13
This file was deleted.

extra/fzf/src/ClassPathMacro.hx

-27
This file was deleted.

extra/install-all.sh

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
ROOT=$(dirname $(readlink -f $0))
44

55
sh "$ROOT/++haxe/install.sh"
6-
sh "$ROOT/fzf/install.sh"
76
sh "$ROOT/local/install.sh"
87
sh "$ROOT/make-haxe/install.sh"
98
sh "$ROOT/rofi/install.sh"

src/HaxeManager.hx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import tools.Utils;
2-
31
import ansi.ANSI;
2+
import tools.Utils;
43

54
using tools.NullTools;
65

@@ -32,6 +31,8 @@ class HaxeManager {
3231
Sys.println(Utils.getCurrentFull().or(""));
3332

3433
case ["list", []]: for (v in Utils.getVersions()) Sys.println(v);
34+
case ["list-modules", []]: HaxeModules.listModules();
35+
case ["list-modules", [hxml]]: HaxeModules.listModules(hxml);
3536

3637
case ["--help", []]: displayUsage();
3738
case ["--help", ["download"]]: HaxeDownload.displayUsage();

src/HaxeModules.hx

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import haxe.io.Path;
2+
import sys.FileSystem;
3+
import sys.io.Process;
4+
5+
import tools.Utils;
6+
7+
using StringTools;
8+
9+
class HaxeModules {
10+
static var targets = [
11+
"js",
12+
"hl",
13+
"cpp",
14+
"cppia",
15+
"cs",
16+
"java",
17+
"jvm",
18+
"lua",
19+
"swf",
20+
"neko",
21+
"php",
22+
"python",
23+
"interp"
24+
];
25+
26+
public static function listModules(?hxml:String = "build.hxml"):Void {
27+
final cwd = Utils.getCallSite();
28+
hxml = Path.isAbsolute(hxml) ? hxml : Path.join([cwd, hxml]);
29+
if (!FileSystem.exists(hxml)) throw 'Cannot find hxml file $hxml';
30+
31+
final stdRoot = FileSystem.fullPath(Path.join([Sys.getCwd(), "current", "std"]));
32+
Sys.putEnv("HAXE_STD_PATH", stdRoot);
33+
final proc = new Process("haxe", [
34+
"--cwd", cwd,
35+
hxml,
36+
FileSystem.absolutePath("extra/fzf/classpath.hxml")
37+
]);
38+
39+
try {
40+
final code = proc.exitCode();
41+
final out = proc.stdout.readAll().toString();
42+
proc.close();
43+
44+
var target:Null<String> = null;
45+
var classpath:Array<String> = [];
46+
final targetPrefix = "[TARGET]: ";
47+
final cpPrefix = "[CLASSPATH]: ";
48+
49+
for (l in out.split("\n")) {
50+
if (l.startsWith(targetPrefix)) {
51+
target = l.substr(targetPrefix.length);
52+
} else if (l.startsWith(cpPrefix)) {
53+
var cp = l.substr(cpPrefix.length);
54+
classpath.push(cp);
55+
}
56+
}
57+
58+
final old = Sys.getCwd();
59+
Sys.setCwd(cwd);
60+
61+
function findModules(path:String) {
62+
if (Path.extension(path) == "hx") return Sys.println(path);
63+
if (!FileSystem.isDirectory(path)) return;
64+
65+
path = Path.addTrailingSlash(path);
66+
for (f in FileSystem.readDirectory(path)) findModules(path + f);
67+
}
68+
69+
function extractTargetStd(cp:String):Array<String> {
70+
var path = FileSystem.fullPath(Path.isAbsolute(cp) ? cp : Path.join([cwd, cp]));
71+
if (!path.startsWith(stdRoot)) return [cp, null];
72+
73+
cp = path; // Use resolved path for std
74+
var path = cp.substr(stdRoot.length);
75+
path = StringTools.replace(path, '\\', '/');
76+
while (path.charCodeAt(0) == '/'.code) path = path.substr(1);
77+
return [cp, path.split('/').shift()];
78+
}
79+
80+
var ignoredTargets = [];
81+
if (target != null) {
82+
if (target != "java" && target != "jvm") ignoredTargets = ignoredTargets.concat(["java", "jvm"]);
83+
if (target != "cpp" && target != "cppia") ignoredTargets.push("cpp");
84+
if (target != "js") ignoredTargets.push("js");
85+
if (target != "hl") ignoredTargets.push("hl");
86+
if (target != "cs") ignoredTargets.push("cs");
87+
if (target != "lua") ignoredTargets.push("lua");
88+
if (target != "neko") ignoredTargets.push("neko");
89+
if (target != "php") ignoredTargets.push("php");
90+
if (target != "python") ignoredTargets.push("python");
91+
if (target != "swf") ignoredTargets.push("flash");
92+
}
93+
94+
for (cp in classpath) {
95+
switch extractTargetStd(cp) {
96+
// Non-std
97+
case [cp, null]: findModules(cp);
98+
99+
// Top level std
100+
case [cp, ""]:
101+
cp = Path.addTrailingSlash(cp);
102+
var sub = FileSystem.readDirectory(cp);
103+
for (f in sub) {
104+
if (ignoredTargets.contains(f)) continue;
105+
findModules(cp + f);
106+
}
107+
108+
case [_, t] if (ignoredTargets.contains(t)):
109+
case [cp, _]: findModules(cp);
110+
};
111+
}
112+
113+
Sys.setCwd(old);
114+
} catch (e) {
115+
Utils.displayError(Std.string(e));
116+
proc.close();
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)