Skip to content

Commit

Permalink
Get compiler version for run scripts lazily (HaxeFoundation#646)
Browse files Browse the repository at this point in the history
It only has to be checked when running interp scripts, so we can avoid
checking it in other cases.
  • Loading branch information
tobil4sk authored Aug 30, 2024
1 parent 8d07d4a commit 3a6aebf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/haxelib/api/GlobalScope.hx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GlobalScope extends Scope {
main: info.main
};

ScriptRunner.run(libraryRunData, resolveCompiler(), callData);
ScriptRunner.run(libraryRunData, callData, () -> haxeVersion);
}

public function getVersion(library:ProjectName):Version {
Expand Down
10 changes: 5 additions & 5 deletions src/haxelib/api/ScriptRunner.hx
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ class ScriptRunner {
/**
Run `library`, with `callData`.
`compilerData` is used if it is an interpreted script.
`getCompilerVersion` is used if it is an interpreted script.
**/
public static function run(library:LibraryRunData, compilerData:LibraryData, callData:CallData):Void {
public static function run(library:LibraryRunData, callData:CallData, getCompilerVersion:()->SemVer):Void {
final type = getType(library);

final cmd = getCmd(type);
final args = generateArgs(type, callData, SemVer.ofString(compilerData.version));
final args = generateArgs(type, callData, getCompilerVersion);

final oldState = getState();

Expand Down Expand Up @@ -122,15 +122,15 @@ class ScriptRunner {
}
}

static function generateArgs(runType:RunType, callData:CallData, compilerVersion:SemVer):Array<String> {
static function generateArgs(runType:RunType, callData:CallData, getCompilerVersion:() -> SemVer):Array<String> {
switch runType {
case Neko(path):
final callArgs = callData.args.copy();
callArgs.unshift(path);
callArgs.push(callData.dir);
return callArgs;
case Script(main, name, version, dependencies):
final isHaxe4 = SemVer.compare(compilerVersion, SemVer.ofString('4.0.0')) >= 0;
final isHaxe4 = SemVer.compare(getCompilerVersion(), SemVer.ofString('4.0.0')) >= 0;
final useGlobalRepo = isHaxe4 && callData.useGlobalRepo;

final callArgs = generateScriptArgs(main, name, version, dependencies, useGlobalRepo);
Expand Down

0 comments on commit 3a6aebf

Please sign in to comment.