Skip to content

Commit

Permalink
Change the order of haxelib git submodule installation (HaxeFoundat…
Browse files Browse the repository at this point in the history
…ion#638)

* submodule stuff in progress

* perhaps a submodule fix?

* revert the dipshit logging

* update run.n

* we dont need to spit out every log, but we should use the threads?

* comment out the unneeded git fetch

* small reorder / remove redundant `git submodule init`

* uncomment the lib deletion, since we've ran into issues related

* fix for stderr/stdout related hangs on non-windows when installing git submodules

* remove git progress code

* run.n

* remove whitespace

* proper non-cli coupled logging

* remove unneeded logging/git --quiet flag code for the time being

* run.n

* remove unneeded FsUtils.deleteRec()

* run.n

* remove testing print

* run.n

* removed unused import and throw an exception on submodule error

* add message for SubmoduleError
  • Loading branch information
ninjamuffin99 committed Sep 18, 2024
1 parent 846dcf8 commit 4820514
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
Binary file modified run.n
Binary file not shown.
4 changes: 3 additions & 1 deletion src/haxelib/api/Installer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ class Installer {
userInterface.log('Installing $library from $url' + (branch != null ? " branch: " + branch : ""));
final tag = vcsData.tag;
try {
vcs.clone(libPath, url, branch, tag, userInterface.log.bind(_, Debug));
vcs.clone(libPath, url, branch, tag, userInterface.log.bind(_, Debug), userInterface.log.bind(_, Optional));
} catch (error:VcsError) {
FsUtils.deleteRec(libPath);
switch (error) {
Expand All @@ -779,6 +779,8 @@ class Installer {
throw 'Could not checkout branch, tag or path "$branch": ' + stderr;
case CantCheckoutVersion(_, version, stderr):
throw 'Could not checkout tag "$version": ' + stderr;
case SubmoduleError(_, repo, stderr):
throw 'Could not clone submodule(s) from $repo: ' + stderr;
case CommandFailed(_, code, stdout, stderr):
throw new VcsCommandFailed(id, code, stdout, stderr);
};
Expand Down
38 changes: 31 additions & 7 deletions src/haxelib/api/Vcs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface IVcs {
`debugLog` will be used to log executable output.
**/
function clone(libPath:String, vcsPath:String, ?branch:String, ?version:String, ?debugLog:(msg:String)->Void):Void;
function clone(libPath:String, vcsPath:String, ?branch:String, ?version:String, ?debugLog:(msg:String)->Void, ?optionalLog:(msg:String)->Void):Void;

/**
Updates repository in CWD or CWD/`Vcs.directory` to HEAD.
Expand All @@ -74,6 +74,7 @@ enum VcsError {
CantCheckoutBranch(vcs:Vcs, branch:String, stderr:String);
CantCheckoutVersion(vcs:Vcs, version:String, stderr:String);
CommandFailed(vcs:Vcs, code:Int, stdout:String, stderr:String);
SubmoduleError(vcs:Vcs, repo:String, stderr:String);
}

/** Exception thrown when a vcs update is cancelled. **/
Expand Down Expand Up @@ -230,7 +231,7 @@ abstract class Vcs implements IVcs {
return ret;
}

public abstract function clone(libPath:String, vcsPath:String, ?branch:String, ?version:String, ?debugLog:(msg:String)->Void):Void;
public abstract function clone(libPath:String, vcsPath:String, ?branch:String, ?version:String, ?debugLog:(msg:String)->Void, ?optionalLog:(msg:String)->Void):Void;

public abstract function update(?confirm:() -> Bool, ?debugLog:(msg:String) -> Void, ?summaryLog:(msg:String) -> Void):Bool;

Expand Down Expand Up @@ -320,33 +321,56 @@ class Git extends Vcs {
return true;
}

public function clone(libPath:String, url:String, ?branch:String, ?version:String, ?debugLog:(msg:String)->Void):Void {
public function clone(libPath:String, url:String, ?branch:String, ?version:String, ?debugLog:(msg:String)->Void, ?optionalLog:(msg:String)->Void):Void {
final oldCwd = Sys.getCwd();

final vcsArgs = ["clone", url, libPath];
var vcsArgs = ["clone", url, libPath];

if (!Vcs.flat)
vcsArgs.push('--recursive');
inline function printOptional(msg)
if (optionalLog != null && msg != "")
optionalLog(msg);

printOptional('Cloning ${name} from ${url}');

if (run(vcsArgs, debugLog).code != 0)
throw VcsError.CantCloneRepo(this, url/*, ret.out*/);

Sys.setCwd(libPath);

if (version != null && version != "") {
printOptional('Checking out tag/version ${version} of ${name}');

final ret = run(["checkout", "tags/" + version], debugLog);
if (ret.code != 0) {
Sys.setCwd(oldCwd);
throw VcsError.CantCheckoutVersion(this, version, ret.out);
}
} else if (branch != null) {
printOptional('Checking out branch/commit ${branch} of ${libPath}');

final ret = run(["checkout", branch], debugLog);
if (ret.code != 0){
Sys.setCwd(oldCwd);
throw VcsError.CantCheckoutBranch(this, branch, ret.out);
}
}

if (!Vcs.flat)
{
printOptional('Syncing submodules for ${name}');
run(["submodule", "sync", "--recursive"], debugLog);

var submoduleArgs = ["submodule", "update", "--init", "--recursive"];

printOptional('Downloading/updating submodules for ${name}');
final ret = run(submoduleArgs, debugLog);
if (ret.code != 0)
{
Sys.setCwd(oldCwd);
throw VcsError.SubmoduleError(this, url, ret.out);
}
}

// return prev. cwd:
Sys.setCwd(oldCwd);
}
Expand Down Expand Up @@ -425,7 +449,7 @@ class Mercurial extends Vcs {
return changed;
}

public function clone(libPath:String, url:String, ?branch:String, ?version:String, ?debugLog:(msg:String)->Void):Void {
public function clone(libPath:String, url:String, ?branch:String, ?version:String, ?debugLog:(msg:String)->Void, ?optionalLog:(msg:String)->Void):Void {
final vcsArgs = ["clone", url, libPath];

if (branch != null && version != null) {
Expand Down

0 comments on commit 4820514

Please sign in to comment.