port libPath and convertToHScript for lix
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
-lib tink_json
|
||||
-lib tink_syntaxhub
|
||||
-lib haxe-strings
|
||||
-cp kiss/src
|
||||
-cp cloner/src
|
||||
-cp src
|
||||
-D analyzer-optimize
|
||||
--macro kiss.KissFrontend.use()
|
@@ -2,5 +2,6 @@
|
||||
-lib hscript
|
||||
-lib uuid
|
||||
-lib tink_macro
|
||||
--main kiss.Main
|
||||
--interp
|
||||
-lib tink_syntaxhub
|
||||
-lib haxe-strings
|
||||
--run kiss.Main
|
@@ -6,6 +6,7 @@ import haxe.macro.Context;
|
||||
import haxe.macro.PositionTools;
|
||||
import sys.io.File;
|
||||
import haxe.io.Path;
|
||||
import kiss.Helpers;
|
||||
using kiss.Helpers;
|
||||
#end
|
||||
|
||||
@@ -166,7 +167,7 @@ class AsyncEmbeddedScript {
|
||||
}
|
||||
|
||||
if (dslHaxelib.length > 0) {
|
||||
dslFile = Path.join([Prelude.libPath(dslHaxelib), dslFile]);
|
||||
dslFile = Path.join([Helpers.libPath(dslHaxelib), dslFile]);
|
||||
}
|
||||
|
||||
// This brings in the DSL's functions and global variables.
|
||||
|
@@ -82,7 +82,7 @@ class CompilerTools {
|
||||
var classPathFolders = classPath.split("/");
|
||||
while (classPathFolders.length > 0) {
|
||||
try {
|
||||
Prelude.libPath(classPathFolders[classPathFolders.length - 1]);
|
||||
Helpers.libPath(classPathFolders[classPathFolders.length - 1]);
|
||||
break;
|
||||
} catch (e) {
|
||||
classPathFolders.pop();
|
||||
@@ -116,7 +116,7 @@ class CompilerTools {
|
||||
var haxelibRepositoryPath = haxelibSetupOutput.substr(haxelibSetupOutput.indexOf(messageBeforePath)).replace(messageBeforePath, "");
|
||||
|
||||
var mainHxFile = "ExternMain.hx";
|
||||
copyToFolder(mainHxFile, Path.join([Prelude.libPath("kiss"), "src", "kiss"]));
|
||||
copyToFolder(mainHxFile, Path.join([Helpers.libPath("kiss"), "src", "kiss"]));
|
||||
|
||||
var mainClassName = mainHxFile.withoutDirectory().withoutExtension();
|
||||
|
||||
|
@@ -14,6 +14,8 @@ import kiss.Prelude;
|
||||
import kiss.cloner.Cloner;
|
||||
import uuid.Uuid;
|
||||
import sys.io.Process;
|
||||
import sys.FileSystem;
|
||||
import haxe.io.Path;
|
||||
|
||||
using uuid.Uuid;
|
||||
using tink.MacroApi;
|
||||
@@ -843,4 +845,42 @@ class Helpers {
|
||||
throw KissError.fromExp(exp, '${description} should resolve at compile-time to a string literal of ${description2}');
|
||||
}
|
||||
}
|
||||
|
||||
// Get the path to a haxelib the program depends on
|
||||
public static function libPath(haxelibName:String) {
|
||||
var classPaths = Context.getClassPath();
|
||||
|
||||
for (dir in classPaths) {
|
||||
var parts = Path.normalize(dir).split("/");
|
||||
var matchingPartIndex = parts.indexOf(haxelibName);
|
||||
|
||||
|
||||
if (matchingPartIndex != -1) {
|
||||
var path = parts.slice(0, matchingPartIndex + 1).join("/");
|
||||
|
||||
// TODO support all possible classPath formats:
|
||||
|
||||
// <libname>/<classPath...>
|
||||
if (FileSystem.exists(Path.join([path, "haxelib.json"]))) return path;
|
||||
|
||||
// <libname>/<version>/haxelib/<classPath...>
|
||||
if (parts[matchingPartIndex + 2] == "haxelib") {
|
||||
var haxelibPath = parts.slice(0, matchingPartIndex + 3).join("/");
|
||||
if (FileSystem.exists(Path.join([haxelibPath, "haxelib.json"]))) return haxelibPath;
|
||||
}
|
||||
|
||||
// <libname>/<version>/github/<commit>/<classPath...>
|
||||
if (parts[matchingPartIndex + 2] == "github") {
|
||||
var githubPath = parts.slice(0, matchingPartIndex + 4).join("/");
|
||||
if (FileSystem.exists(Path.join([githubPath, "haxelib.json"]))) return githubPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Special case fallback: kiss when its classpath is "src"
|
||||
if (haxelibName == "kiss") return Path.directory(Sys.getEnv("KISS_BUILD_HXML"));
|
||||
|
||||
throw 'Could not find haxelib $haxelibName in class paths';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -75,6 +75,8 @@ typedef KissState = {
|
||||
class Kiss {
|
||||
#if macro
|
||||
public static function defaultKissState(?context:FrontendContext):KissState {
|
||||
Sys.putEnv("KISS_BUILD_HXML", Prelude.joinPath(Helpers.libPath("kiss"), "build.hxml"));
|
||||
|
||||
var className = "";
|
||||
var pack = [];
|
||||
if (context == null) {
|
||||
@@ -124,7 +126,6 @@ class Kiss {
|
||||
"enumerate" => Symbol("Prelude.enumerate"),
|
||||
"assertProcess" => Symbol("Prelude.assertProcess"),
|
||||
"tryProcess" => Symbol("Prelude.tryProcess"),
|
||||
"libPath" => Symbol("Prelude.libPath"),
|
||||
"userHome" => Symbol("Prelude.userHome"),
|
||||
"random" => Symbol("Std.random"),
|
||||
"walkDirectory" => Symbol("Prelude.walkDirectory"),
|
||||
|
@@ -6,6 +6,7 @@ import kiss.Reader;
|
||||
import kiss.ReaderExp;
|
||||
import kiss.Kiss;
|
||||
import kiss.KissError;
|
||||
import kiss.Helpers;
|
||||
import kiss.CompilerTools;
|
||||
import uuid.Uuid;
|
||||
import hscript.Parser;
|
||||
@@ -44,10 +45,16 @@ class Macros {
|
||||
Kiss.load(compileTimeResolveToString("The only argument to (load...)", "a .kiss file path", args[0], k), k, null, false, wholeExp);
|
||||
};
|
||||
|
||||
k.doc("libPath", 1, 1, '(libPath <dependency>)');
|
||||
macros["libPath"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
|
||||
var b = wholeExp.expBuilder();
|
||||
return b.str(Helpers.libPath(compileTimeResolveToString("The only argument to (libPath...)", "a haxelib dependency name", args[0], k)));
|
||||
};
|
||||
|
||||
k.doc("loadFrom", 2, 2, '(loadFrom "<haxelib name>" "<file.kiss>")');
|
||||
macros["loadFrom"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
|
||||
var libName = compileTimeResolveToString("The first argument to (loadFrom...)", "a haxe library's name", args[0], k);
|
||||
var libPath = Prelude.libPath(libName);
|
||||
var libPath = Helpers.libPath(libName);
|
||||
var otherKissFile = compileTimeResolveToString("The second argument to (loadFrom...)", "a .kiss file path", args[1], k);
|
||||
Kiss.load(otherKissFile, k, libPath, false, wholeExp);
|
||||
};
|
||||
|
@@ -586,12 +586,14 @@ class Prelude {
|
||||
* So don't use raw string literals in Kiss you want parsed and evaluated at runtime.
|
||||
*/
|
||||
public static function convertToHScript(kissStr:String):String {
|
||||
var buildHxml = Sys.getEnv("KISS_BUILD_HXML");
|
||||
var cwd = Path.directory(buildHxml);
|
||||
#if macro
|
||||
return Kiss.measure("Prelude.convertToHScript", () -> {
|
||||
#end
|
||||
#if (!macro && hxnodejs)
|
||||
var hscript = try {
|
||||
assertProcess("haxelib", ["run", "kiss", "convert", "--all", "--hscript"], kissStr.split('\n'));
|
||||
assertProcess("haxe", [buildHxml, "convert", "--all", "--hscript"], kissStr.split('\n'), true, cwd);
|
||||
} catch (e) {
|
||||
throw 'failed to convert ${kissStr} to hscript:\n$e';
|
||||
}
|
||||
@@ -601,7 +603,7 @@ class Prelude {
|
||||
return hscript.trim();
|
||||
#elseif (!macro && python)
|
||||
var hscript = try {
|
||||
assertProcess("haxelib", ["run", "kiss", "convert", "--hscript"], [kissStr.replace('\n', ' ')], false);
|
||||
assertProcess("haxe", [buildHxml, "convert", "--hscript"], [kissStr.replace('\n', ' ')], false, cwd);
|
||||
} catch (e) {
|
||||
throw 'failed to convert ${kissStr} to hscript:\n$e';
|
||||
}
|
||||
@@ -610,8 +612,11 @@ class Prelude {
|
||||
}
|
||||
return hscript.trim();
|
||||
#elseif sys
|
||||
var oldCwd = Sys.getCwd();
|
||||
Sys.setCwd(cwd);
|
||||
|
||||
if (kissProcess == null)
|
||||
kissProcess = new Process("haxelib", ["run", "kiss", "convert", "--hscript"]);
|
||||
kissProcess = new Process("haxe", [buildHxml, "convert", "--hscript"]);
|
||||
|
||||
kissProcess.stdin.writeString('${kissStr.replace("\n", " ")}\n');
|
||||
|
||||
@@ -620,9 +625,11 @@ class Prelude {
|
||||
if (output.startsWith(">>> ")) {
|
||||
output = output.substr(4);
|
||||
}
|
||||
Sys.setCwd(oldCwd);
|
||||
return output;
|
||||
} catch (e) {
|
||||
var error = kissProcess.stderr.readAll().toString();
|
||||
Sys.setCwd(oldCwd);
|
||||
throw 'failed to convert ${kissStr} to hscript: ${error}';
|
||||
}
|
||||
#else
|
||||
@@ -786,11 +793,6 @@ class Prelude {
|
||||
#end
|
||||
}
|
||||
|
||||
// Get the path to a haxelib the user has installed
|
||||
public static function libPath(haxelibName:String) {
|
||||
return assertProcess("haxelib", ["libpath", haxelibName]).trim();
|
||||
}
|
||||
|
||||
#if target.threaded
|
||||
static var shellCountMutex = new Mutex();
|
||||
#end
|
||||
|
Reference in New Issue
Block a user