From ec4bb7356289221182e9c6f40a5a3c29fc50cb78 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Mon, 5 May 2014 21:53:24 -0400 Subject: [PATCH 1/3] Better installation flow for developing. - Detects if libgit2 is already fetched instead of constantly fetching. - Provides more meta information about libgit2 inside package.json. --- install.js | 14 +++++++------- package.json | 7 +++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/install.js b/install.js index 4818e8242..861c04a07 100644 --- a/install.js +++ b/install.js @@ -10,7 +10,6 @@ var Q = require('q'); var request = require('request'); var tar = require('tar'); var which = require('which'); -var rimraf = require('rimraf'); // This will take in an object and find any matching keys in the environment // to use as overrides. @@ -80,19 +79,20 @@ var dependencies = Q.allSettled([ }); }) -// Successfully found all dependencies. First step is to clean the vendor +// Successfully found all dependencies. First step is to detect the vendor // directory. .then(function() { - console.info('[nodegit] Removing vendor/libgit2.'); + console.info('[nodegit] Detecting vendor/libgit2.'); - return Q.ninvoke(rimraf, null, paths.libgit2); + return Q.ninvoke(fs, 'stat', paths.libgit2); }) -// Now fetch the libgit2 source from GitHub. -.then(function() { +// If the directory already exists, no need to refetch. +.fail(function() { + // Otherwise fetch the libgit2 source from GitHub. console.info('[nodegit] Fetching vendor/libgit2.'); - var url = 'https://github.com/libgit2/libgit2/tarball/' + pkg.libgit2; + var url = 'https://github.com/libgit2/libgit2/tarball/' + pkg.libgit2.sha; var extract = tar.Extract({ path: paths.libgit2, diff --git a/package.json b/package.json index 3853877f5..ff23ea548 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,10 @@ "name": "nodegit", "description": "Node.js libgit2 asynchronous native bindings", "version": "0.1.4", - "libgit2": "a50086d174658914d4d6462afbc83b02825b1f5b", + "libgit2": { + "sha": "a50086d174658914d4d6462afbc83b02825b1f5b", + "libgit2": "a50086d174658914d4d6462afbc83b02825b1f5b" + }, "homepage": "https://github.com/tbranyen/nodegit", "keywords": [ "libgit2", @@ -63,4 +66,4 @@ "codegen": "node build/codegen/generate.js", "publish": "node-pre-gyp package && node-pre-gyp publish" } -} \ No newline at end of file +} From fb583ecfef852c72b98f8ab759f90aeba145bb7f Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Fri, 20 Jun 2014 14:36:53 -0400 Subject: [PATCH 2/3] Removed all references to cmake. --- install.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/install.js b/install.js index 861c04a07..5613d71d2 100644 --- a/install.js +++ b/install.js @@ -39,7 +39,7 @@ function systemPath(parts) { } // Will be used near the end to configure `node-gyp`. -var python, cmake; +var python; // Common reusable paths that can be overwritten by environment variables. var paths = envOverride({ @@ -57,10 +57,7 @@ var dependencies = Q.allSettled([ // This will prioritize `python2` over `python`, because we always want to // work with Python 2.* if it's available. Q.nfcall(which, 'python2'), - Q.nfcall(which, 'python'), - - // Check for any version of CMake. - Q.nfcall(which, 'cmake'), + Q.nfcall(which, 'python') ]) // Determine if all the dependency requirements are met. @@ -69,7 +66,6 @@ var dependencies = Q.allSettled([ // Assign to reusable variables. python = results[0].value || results[1].value; - cmake = results[2].value; // Now lets check the Python version to ensure it's < 3. return Q.nfcall(exec, python + ' --version').then(function(version) { From 87338c0afbb9c3516c2895502751f3863ecd569e Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Fri, 20 Jun 2014 15:21:36 -0400 Subject: [PATCH 3/3] Ensure that libgit2 is removed if outdated. --- install.js | 18 +++++++++++++----- package.json | 3 +-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/install.js b/install.js index 5613d71d2..24dad171f 100644 --- a/install.js +++ b/install.js @@ -1,15 +1,13 @@ -// Core Node.js modules. var os = require('os'); var fs = require('fs'); var path = require('path'); var zlib = require('zlib'); var exec = require('child_process').exec; - -// Third-party modules. var Q = require('q'); var request = require('request'); var tar = require('tar'); var which = require('which'); +var rimraf = require('rimraf'); // This will take in an object and find any matching keys in the environment // to use as overrides. @@ -80,7 +78,14 @@ var dependencies = Q.allSettled([ .then(function() { console.info('[nodegit] Detecting vendor/libgit2.'); - return Q.ninvoke(fs, 'stat', paths.libgit2); + return Q.ninvoke(fs, 'stat', paths.libgit2).then(function() { + return Q.ninvoke(fs, 'stat', paths.libgit2 + pkg.libgit2.sha); + }).fail(function() { + console.info('[nodegit] Removing outdated vendor/libgit2.'); + + // This directory is outdated, remove. + throw Q.ninvoke(rimraf, null, paths.libgit2); + }); }) // If the directory already exists, no need to refetch. @@ -98,7 +103,10 @@ var dependencies = Q.allSettled([ // First extract from Zlib and then extract from Tar. var expand = request.get(url).pipe(zlib.createUnzip()).pipe(extract); - return Q.ninvoke(expand, 'on', 'end'); + return Q.ninvoke(expand, 'on', 'end').then(function() { + // Write out a sha file for testing in the future. + return Q.ninvoke(fs, 'writeFile', paths.libgit2 + pkg.libgit2.sha, ''); + }); }) // Configure the native module using node-gyp. diff --git a/package.json b/package.json index ff23ea548..feede962c 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,7 @@ "description": "Node.js libgit2 asynchronous native bindings", "version": "0.1.4", "libgit2": { - "sha": "a50086d174658914d4d6462afbc83b02825b1f5b", - "libgit2": "a50086d174658914d4d6462afbc83b02825b1f5b" + "sha": "a50086d174658914d4d6462afbc83b02825b1f5b" }, "homepage": "https://github.com/tbranyen/nodegit", "keywords": [