Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git dependencies #344

Merged
merged 15 commits into from
Sep 2, 2016
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
44 changes: 40 additions & 4 deletions src/haxelib/Data.hx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,46 @@ abstract Dependencies(Dynamic<DependencyVersion>) from Dynamic<DependencyVersion
@:to public function toArray():Array<Dependency> {
var fields = Reflect.fields(this);
fields.sort(Reflect.compare);
return [for (f in fields) {
name: f,
version: (Reflect.field(this, f) : DependencyVersion),
}];

var result:Array<Dependency> = new Array<Dependency>();

for (f in fields) {
var value:String = Reflect.field(this, f);

var isGit = value != null && (value + "").startsWith("git:");

if ( !isGit )
{
result.push ({
name: f,
type: (DependencyType.Haxelib : DependencyType),
version: (cast value : DependencyVersion),
url: (null : String),
subDir: (null : String),
branch: (null : String),
});
}
else
{
value = value.substr(4);
var urlParts = value.split("#");
var url = urlParts[0];
var branch = urlParts.length > 1 ? urlParts[1] : null;

result.push ({
name: f,
type: (DependencyType.Git : DependencyType),
version: (DependencyVersion.DEFAULT : DependencyVersion),
url: (url : String),
subDir: (null : String),
branch: (branch : String),
});
}


}

return result;
}
public inline function iterator()
return toArray().iterator();
Expand Down
122 changes: 96 additions & 26 deletions src/haxelib/client/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Main {
var siteUrl : String;
var site : SiteProxy;
var isHaxelibRun : Bool;
var alreadyUpdatedVcsDependencies:Map<String,String> = new Map<String,String>();


function new() {
Expand Down Expand Up @@ -632,6 +633,12 @@ class Main {
doInstallFile(rep, prj, true, true);
return;
}

if ( prj.endsWith("haxelib.json") )
{
installFromHaxelibJson( rep, prj);
return;
}
}

// Name provided that wasn't a local hxml or zip, so try to install it from server
Expand Down Expand Up @@ -663,7 +670,7 @@ class Main {
'-cpp ' => 'hxcpp',
'-cs ' => 'hxcs',
];
var libsToInstall = new Map<String, {name:String,version:String}>();
var libsToInstall = new Map<String, {name:String,version:String,type:String,url:String,branch:String,subDir:String}>();

function processHxml(path) {
var hxml = sys.io.File.getContent(path);
Expand All @@ -674,18 +681,44 @@ class Main {
if (l.startsWith(target)) {
var lib = targets[target];
if (!libsToInstall.exists(lib))
libsToInstall[lib] = { name: lib, version: null }
libsToInstall[lib] = { name: lib, version: null, type:"haxelib", url: null, branch: null, subDir: null }
}

if (l.startsWith("-lib")) {
var key = l.substr(5);
var parts = key.split(":");
var libName = parts[0].trim();
var libVersion = if (parts.length > 1) parts[1].trim() else null;
if (l.startsWith("-lib"))
{
var key = l.substr(5).trim();
var parts = ~/:/.split(key);
var libName = parts[0];
var libVersion:String = null;
var branch:String = null;
var url:String = null;
var subDir:String = null;
var type:String;

if ( parts.length > 1 )
{
if ( parts[1].startsWith("git:") )
{

type = "git";
var urlParts = parts[1].substr(4).split("#");
url = urlParts[0];
branch = urlParts.length > 1 ? urlParts[1] : null;
}
else
{
type = "haxelib";
libVersion = parts[1];
}
}
else
{
type = "haxelib";
}

switch libsToInstall[key] {
case null, { version: null } :
libsToInstall.set(key, { name:libName, version:libVersion } );
libsToInstall.set(key, { name:libName, version:libVersion, type: type, url: url, subDir: subDir, branch: branch } );
default:
}
}
Expand All @@ -702,7 +735,13 @@ class Main {
// Check the version numbers are all good
// TODO: can we collapse this into a single API call? It's getting too slow otherwise.
print("Loading info about the required libraries");
for (l in libsToInstall) {
for (l in libsToInstall)
{
if ( l.type == "git" )
{
// Do not check git repository infos
continue;
}
var inf = site.infos(l.name);
l.version = getVersion(inf, l.version);
}
Expand All @@ -716,10 +755,21 @@ class Main {

// Install if they confirm
if (ask("Continue?")) {
for (l in libsToInstall)
doInstall(rep, l.name, l.version, true);
for (l in libsToInstall) {
if ( l.type == "haxelib" )
doInstall(rep, l.name, l.version, true);
else if ( l.type == "git" )
useVcs(VcsID.Git, function(vcs) doVcsInstall(rep, vcs, l.name, l.url, l.branch, l.subDir, l.version));
else if ( l.type == "hg" )
useVcs(VcsID.Hg, function(vcs) doVcsInstall(rep, vcs, l.name, l.url, l.branch, l.subDir, l.version));
}
}
}

function installFromHaxelibJson( rep:String, path:String )
{
doInstallDependencies(rep, Data.readData(File.getContent(path), false).dependencies);
}

function installFromAllHxml(rep:String) {
var cwd = Sys.getCwd();
Expand Down Expand Up @@ -869,9 +919,9 @@ class Main {
}
}

print("Installing dependency "+d.name+" "+d.version);
if( d.version == "" )
if( d.version == "" && d.type == DependencyType.Haxelib )
d.version = site.getLatestVersion(d.name);
print("Installing dependency "+d.name+" "+d.version);

switch d.type {
case Haxelib:
Expand Down Expand Up @@ -1304,21 +1354,43 @@ class Main {
}

function doVcsInstall(rep:String, vcs:Vcs, libName:String, url:String, branch:String, subDir:String, version:String) {

var proj = rep + Data.safe(libName);

// find & remove all existing repos:
removeExistingDevLib(proj);
// currently we already kill all dev-repos for all supported Vcs.


var libPath = proj + "/" + vcs.directory;

var jsonPath = libPath + "/haxelib.json";

if ( FileSystem.exists(proj + "/" + Data.safe(vcs.directory)) ) {
print("You already have "+libName+" version "+vcs.directory+" installed.");

var wasUpdated = this.alreadyUpdatedVcsDependencies.exists(libName);
var currentBranch = if (wasUpdated) this.alreadyUpdatedVcsDependencies.get(libName) else null;

if (branch != null && (!wasUpdated || (wasUpdated && currentBranch != branch))
&& ask("Overwrite branch: " + (currentBranch == null?"<unspecified>":"\"" + currentBranch + "\"") + " with \"" + branch + "\""))
{
deleteRec(libPath);
this.alreadyUpdatedVcsDependencies.set(libName, branch);
}
else
{
if (!wasUpdated)
{
print("Updating " + libName+" version " + vcs.directory + " ...");
this.alreadyUpdatedVcsDependencies.set(libName, branch);
updateByName(rep, libName);
setCurrent(rep, libName, vcs.directory, true);

if(FileSystem.exists(jsonPath))
doInstallDependencies(rep, Data.readData(File.getContent(jsonPath), false).dependencies);
}
return;
}
}

// prepare for new repo
deleteRec(libPath);


print("Installing " +libName + " from " +url);

print("Installing " +libName + " from " +url + ( branch != null ? " branch: " + branch : "" ));

try {
vcs.clone(libPath, url, branch, version);
} catch(error:VcsError) {
Expand All @@ -1336,7 +1408,6 @@ class Main {
throw message;
}


// finish it!
if (subDir != null) {
libPath += "/" + subDir;
Expand All @@ -1347,7 +1418,6 @@ class Main {
print("Library "+libName+" current version is now "+vcs.directory);
}

var jsonPath = libPath + "/haxelib.json";
if(FileSystem.exists(jsonPath))
doInstallDependencies(rep, Data.readData(File.getContent(jsonPath), false).dependencies);
}
Expand Down
4 changes: 2 additions & 2 deletions src/haxelib/client/Vcs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ class Git extends Vcs {


Sys.setCwd(libPath);

if (version != null) {
if (version != null && version != "") {
var ret = command(executable, ["checkout", "tags/" + version]);
if (ret.code != 0)
throw VcsError.CantCheckoutVersion(this, version, ret.out);
Expand Down
2 changes: 2 additions & 0 deletions test/HaxelibTests.hx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class HaxelibTests {
}
r.add(new TestVcsNotFound());

r.add(new TestInstall());

var success = r.run();
Sys.exit(success ? 0 : 1);
}
Expand Down
9 changes: 9 additions & 0 deletions test/libraries/UseGitDep/foo/Foo.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package foo;

class Foo {

public function new() {
trace("new Foo");
}

}
13 changes: 13 additions & 0 deletions test/libraries/UseGitDep/haxelib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Foo",
"url" : "http://example.org",
"license": "GPL",
"tags": ["foo", "test"],
"description": "This project is an example of an haxelib project",
"version": "0.1.0-alpha.0",
"releasenote": "Initial release, everything is working correctly",
"dependencies": {
"signal": "git:https://github.com/fzzr-/hx.signal.git"
},
"contributors": ["Foo"]
}
7 changes: 7 additions & 0 deletions test/libraries/UseGitDep/haxelib.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<project name="Foo" url="http://example.org" license="GPL">
<user name="Foo"/>
<tag v="foo"/>
<tag v="test"/>
<description>This project is an example of an haxelib project</description>
<version name="1.0.0-alpha.0">Initial release, everything is working correctly</version>
</project>
13 changes: 13 additions & 0 deletions test/libraries/UseGitDep/tag_haxelib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Foo",
"url" : "http://example.org",
"license": "GPL",
"tags": ["foo", "test"],
"description": "This project is an example of an haxelib project",
"version": "0.1.0-alpha.0",
"releasenote": "Initial release, everything is working correctly",
"dependencies": {
"signal": "git:https://github.com/fzzr-/hx.signal.git#0.9.2"
},
"contributors": ["Foo"]
}
Loading