Skip to content

Commit

Permalink
Deploy: fix for windows deployment, re: binary module resolution and …
Browse files Browse the repository at this point in the history
…injection

commit 4e040a4
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Thu Apr 14 17:55:47 2016 -0400

    Restore all other test files

    Signed-off-by: Rick Waldron <waldron.rick@gmail.com>

commit 4502608
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Thu Apr 14 17:53:55 2016 -0400

    Normalize buildPath

    Signed-off-by: Rick Waldron <waldron.rick@gmail.com>

commit 250cf13
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Thu Apr 14 17:38:22 2016 -0400

    Is "exists" even called?

    Signed-off-by: Rick Waldron <waldron.rick@gmail.com>

commit 01fd049
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Thu Apr 14 17:33:06 2016 -0400

    Improve build path matching

    Signed-off-by: Rick Waldron <waldron.rick@gmail.com>

commit fa82779
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Thu Apr 14 16:45:30 2016 -0400

    Log the modulePath

    Signed-off-by: Rick Waldron <waldron.rick@gmail.com>

commit 8f75b4e
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Thu Apr 14 16:40:35 2016 -0400

    Gracefully handle null return from python script to read binding.gyp

    Signed-off-by: Rick Waldron <waldron.rick@gmail.com>

commit 2beac30
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Thu Apr 14 16:35:39 2016 -0400

    Fix missing path.normalize

    Signed-off-by: Rick Waldron <waldron.rick@gmail.com>

commit b838a9f
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Thu Apr 14 16:25:56 2016 -0400

    Eliminate regexp that won't match on windows

    Signed-off-by: Rick Waldron <waldron.rick@gmail.com>

commit 0333a1f
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Thu Apr 14 15:49:32 2016 -0400

    First, limit testing to test/unit/deploy.js

    Signed-off-by: Rick Waldron <waldron.rick@gmail.com>

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Apr 14, 2016
1 parent d13de24 commit 8f42d5e
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 10 deletions.
12 changes: 10 additions & 2 deletions lib/tessel/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,16 @@ function logMissingBinaryModuleWarning(name) {
logs.warn(warning.trim());
}

var isWindows = /^win/.test(process.platform);

actions.resolveBinaryModules = function(opts) {
var cwd = process.cwd();
var target = opts.target || cwd;
var relative = path.relative(cwd, target);
var globRoot = relative || target;
var buildexp = /(?:build\/(Debug|Release|bindings)\/)/;
var buildexp = isWindows ?
/(?:build\\(Debug|Release|bindings)\\)/ :
/(?:build\/(Debug|Release|bindings)\/)/;

binaryModulesUsed.clear();

Expand All @@ -457,7 +461,7 @@ actions.resolveBinaryModules = function(opts) {
var modulePath = bindings.getRoot(globPath);
var packageJson = require(path.join(globRoot, modulePath, 'package.json'));
var binName = path.basename(globPath);
var buildPath = globPath.replace(path.join(modulePath), '').replace(binName, '');
var buildPath = path.normalize(globPath.replace(path.join(modulePath), '').replace(binName, ''));
var buildType = (function() {
var matches = buildPath.match(buildexp);
if (matches && matches.length) {
Expand Down Expand Up @@ -658,6 +662,10 @@ actions.resolveBinaryModules.readGypFileSync = function(gypfile) {
var result = cp.spawnSync(python, ['-c', program]);
var output = result.output;

if (output == null) {
return '';
}

return output.reduce((accum, buffer) => {
if (buffer) {
accum += decoder.write(buffer);
Expand Down
80 changes: 72 additions & 8 deletions test/unit/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ exports['deploy.tarBundle'] = {
}).then(() => {

test.equal(this.readdirSync.callCount, 1);
test.equal(this.readdirSync.lastCall.args[0], target);
test.equal(this.readdirSync.lastCall.args[0], path.normalize(target));

test.equal(this.logsWarn.callCount, 1);
test.equal(this.logsWarn.firstCall.args[0], 'Some assets in this project were not deployed (see: t2 run --help)');
Expand Down Expand Up @@ -1658,7 +1658,7 @@ exports['deploy.tarBundle'] = {
slim: true,
}).then(() => {
test.equal(this.readdirSync.callCount, 1);
test.equal(this.readdirSync.lastCall.args[0], target);
test.equal(this.readdirSync.lastCall.args[0], path.normalize(target));
test.equal(this.logsWarn.callCount, 0);

// Ultimately, all assets were accounted for, even though
Expand Down Expand Up @@ -2007,9 +2007,25 @@ exports['deploy.resolveBinaryModules'] = {
});

this.getRoot = sandbox.stub(bindings, 'getRoot', (file) => {
var pattern = /(?:node_modules)\/(\w.+)\/(?:build|binding\.)/;
var results = pattern.exec(file);
return path.normalize('node_modules/' + results[1] + '/');
var pathPart = '';

if (file.includes('debug')) {
pathPart = 'debug';
}

if (file.includes('linked')) {
pathPart = 'linked';
}

if (file.includes('missing')) {
pathPart = 'missing';
}

if (file.includes('release')) {
pathPart = 'release';
}

return path.normalize(`node_modules/${pathPart}/`);
});

done();
Expand Down Expand Up @@ -2093,6 +2109,38 @@ exports['deploy.resolveBinaryModules'] = {
});
},

spawnPythonScriptReturnsNull: function(test) {
test.expect(1);

this.readGypFileSync.restore();
this.readGypFileSync = sandbox.spy(deploy.resolveBinaryModules, 'readGypFileSync');

this.globSync.restore();
this.globSync = sandbox.stub(deploy.glob, 'sync', () => {
return [
path.normalize('node_modules/release/build/Release/release.node'),
path.normalize('node_modules/release/binding.gyp'),
path.normalize('node_modules/missing/binding.gyp'),
];
});

this.exists = sandbox.stub(fs, 'existsSync', () => true);
this.spawnSync = sandbox.stub(cp, 'spawnSync', () => {
return {
output: null
};
});

deploy.resolveBinaryModules({
target: this.target
}).then(() => {
test.equal(this.readGypFileSync.lastCall.returnValue, '');
test.done();
}).catch(error => {
test.ok(false, error.toString());
test.done();
});
},
spawnPythonScript: function(test) {
test.expect(7);

Expand Down Expand Up @@ -2315,9 +2363,25 @@ exports['deploy.injectBinaryModules'] = {
});

this.getRoot = sandbox.stub(bindings, 'getRoot', (file) => {
var pattern = /(?:node_modules)\/(\w.+)\/(?:build|binding\.)/;
var results = pattern.exec(file);
return path.normalize('node_modules/' + results[1] + '/');
var pathPart = '';

if (file.includes('debug')) {
pathPart = 'debug';
}

if (file.includes('linked')) {
pathPart = 'linked';
}

if (file.includes('missing')) {
pathPart = 'missing';
}

if (file.includes('release')) {
pathPart = 'release';
}

return path.normalize(`node_modules/${pathPart}/`);
});

this.globRoot = path.join(__dirname, '/../../test/unit/fixtures/project-binary-modules/');
Expand Down

0 comments on commit 8f42d5e

Please sign in to comment.