Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions src/haxelib/VersionData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ package haxelib;
else
throw 'Invalid VscID $s';
}

public function getName() {
return switch cast(this, VcsID) {
case Git: "Git";
case Hg: "Mercurial";
};
}
}

/** Class containing repoducible git or hg library data. **/
Expand All @@ -28,7 +35,7 @@ class VcsData {
var url:String;
/** Commit hash **/
@:optional
var ref:Null<String>;
var commit:Null<String>;
/** The git tag or mercurial revision **/
@:optional
var tag:Null<String>;
Expand All @@ -45,7 +52,7 @@ class VcsData {

public function toString(): String {
var qualifier =
if (ref != null) ref
if (commit != null) commit
else if (tag != null) tag
else if (branch != null) branch
else null;
Expand All @@ -54,6 +61,39 @@ class VcsData {
else
url;
}

/**
Returns whether this vcs data will always reproduce an identical installation
(i.e. the commit id is locked down)
**/
public function isReproducible() {
return commit != null;
}

/**
Returns an anonymous object containing only the non-null, non-empty VcsData fields,
excluding the null/empty ones.
**/
public function getCleaned() {
var data:{
url:String,
?commit:String,
?tag:String,
?branch:String,
?subDir:String
} = { url : url };

if (commit != null)
data.commit = commit;
if (tag != null)
data.tag = tag;
if (!(branch == null || branch == ""))
data.branch = branch;
if (!(subDir == null || haxe.io.Path.normalize(subDir) == ""))
data.subDir = subDir;

return data;
}
}

/** Data required to reproduce a library version **/
Expand Down Expand Up @@ -89,7 +129,7 @@ class VersionDataHelper {
type: type,
data: {
url: vcsRegex.matched(2),
ref: vcsRegex.matched(3),
commit: vcsRegex.matched(3),
branch: vcsRegex.matched(4),
subDir: null,
tag: null
Expand Down
17 changes: 17 additions & 0 deletions src/haxelib/api/FsUtils.hx
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,21 @@ class FsUtils {
seek(root);
return ret;
}

/**
Switches to directory found at `path`, executes `f()` in this directory,
before switching back to the previous directory.
**/
public static function runInDirectory<T>(path:String, f:() -> T):T {
final oldCwd = Sys.getCwd();
try {
Sys.setCwd(path);
final value = f();
Sys.setCwd(oldCwd);
return value;
} catch (e) {
Sys.setCwd(oldCwd);
throw e;
}
}
}
17 changes: 15 additions & 2 deletions src/haxelib/api/GlobalScope.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ class GlobalScope extends Scope {
}

public function setVcsVersion(library:ProjectName, vcsVersion:VcsID, ?data:VcsData):Void {
if (data == null) data = {url: "unknown"};
if (data != null) {
repository.setVcsData(library, vcsVersion, data);
}

if (data.subDir != null) {
if (data != null && data.subDir != "" && data.subDir != null) {
final devDir = repository.getValidVersionPath(library, vcsVersion) + data.subDir;
repository.setDevPath(library, devDir);
} else {
Expand Down Expand Up @@ -273,4 +275,15 @@ class GlobalScope extends Scope {
return {path: path, version: current};
}

public function resolve(library:ProjectName):VersionData {
final version = repository.getCurrentVersion(library);

return switch version {
case vcs if (VcsID.isValid(vcs)):
final vcsId = VcsID.ofString(vcs);
VcsInstall(vcsId, repository.getVcsData(library, vcsId));
case semVer:
Haxelib(SemVer.ofString(semVer));
};
}
}
Loading
Loading