From 48e4c750cdea1a2bceb29ca2b9178617e8690af6 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sun, 26 Jun 2016 20:46:00 -0700 Subject: [PATCH] Still doesn't deploy, fixed grunt up to it --- lib/tessel/commands.js | 4 +- lib/tessel/deployment/rust.js | 90 ++++++++++++++++++----------------- test/unit/deploy.js | 6 ++- 3 files changed, 53 insertions(+), 47 deletions(-) diff --git a/lib/tessel/commands.js b/lib/tessel/commands.js index 59fd4b27..32d1ccc7 100644 --- a/lib/tessel/commands.js +++ b/lib/tessel/commands.js @@ -4,7 +4,7 @@ * Language: * * */ -var rust = require('./deployment/rust') +var rust = require('./deployment/rust'); module.exports.app = { // Note: These should be converted to method shorthand @@ -24,7 +24,7 @@ module.exports.js = { }; module.exports.rs = { - execute: () => [rust.BINARY_NAME], + execute: () => [rust.exports.meta.binary], }; module.exports.py = { diff --git a/lib/tessel/deployment/rust.js b/lib/tessel/deployment/rust.js index 949a25e1..c530ba20 100644 --- a/lib/tessel/deployment/rust.js +++ b/lib/tessel/deployment/rust.js @@ -19,13 +19,11 @@ var lists = require('./lists/rust'); var Tessel = require('../tessel'); var log = require('../../log'); -var BINARY_NAME = 'rust_executable' - var exportables = { meta: { name: 'rust', extname: 'rs', - binary: BINARY_NAME, + binary: 'rust_executable', entry: 'src/main.rs', configuration: 'Cargo.toml', checkConfiguration: (pushdir, basename, program) => { @@ -44,7 +42,7 @@ var exportables = { shell: () => { return tags.stripIndent ` #!/bin/sh - exec /app/remote-script/${BINARY_NAME} + exec /app/remote-script/${exportables.meta.binary} `; }, }, @@ -67,7 +65,7 @@ exportables.tarBundle = function(opts) { // include the parameter in the list. exportables.preRun = function(tessel, options) { // jshint ignore:line return new Promise((resolve) => { - return tessel.connection.exec(commands.chmod('+x', `${Tessel.REMOTE_RUN_PATH}${BINARY_NAME}`), {}, () => resolve()); + return tessel.connection.exec(commands.chmod('+x', `${Tessel.REMOTE_RUN_PATH}${exportables.meta.binary}`), {}, () => resolve()); }); }; @@ -78,8 +76,7 @@ exportables.postRun = function(tessel, options) { */ exportables.remoteRustCompilation = function(opts) { - log.info("Compiling Rust code..."); - log.info(opts) + log.info('Compiling Rust code...'); return new Promise(function(resolve, reject) { // Save our incoming compiled buffer to this array @@ -102,61 +99,68 @@ exportables.remoteRustCompilation = function(opts) { path: '/rust-compile', method: 'POST', headers: { - 'Content-Type': 'application/octet-stream', - // TODO: How is this safely resolvable? - // Perhaps parsing opts.resolvedEntryPoint? - 'X-BINARY-NAME': 'hello', - 'X-PROJECT-FOLDER': path.basename(opts.target), + 'Content-Type': 'application/octet-stream', + // TODO: How is this safely resolvable? + // Perhaps parsing opts.resolvedEntryPoint? + 'X-BINARY-NAME': 'hello', + 'X-PROJECT-FOLDER': path.basename(opts.target), } }; // Create a new tar pack for incoming executable data var pack = tarStream.pack(); // Create the entry file name - var entry = pack.entry( { name : BINARY_NAME }); + var entry = pack.entry({ + name: exportables.meta.binary + }); // Set up the request var post_req = http.request(post_options, function(res) { // When we get incoming binary data, save to our buffers res.on('data', function(chunk) { - // Write this incoming data to our tar packer - entry.write(chunk); - }) - // Reject on failure - .on('error', function(e) { - return reject(e); - }) - // When the post completes, resolve with the executable - .on('end', function() { - // Indicate that all data has been received - pack.finalize(); - - // Turn the stream into an array of buffers - return streamToArray(pack) - .then((arr) => { - // For each buffer in the array - for (var i = 0, l = arr.length; i < l ; ++i) { - // Grab the part - var part = parts[i] - // Push it into our buffer array - buffers.push((part instanceof Buffer) ? part : new Buffer(part)) - } - // Resolve with concatenated buffers - return resolve(Buffer.concat(buffers)); + // Write this incoming data to our tar packer + entry.write(chunk); }) - }) + // Reject on failure + .on('error', function(e) { + return reject(e); + }) + // When the post completes, resolve with the executable + .on('end', function() { + // Indicate that all data has been received + pack.finalize(); + + // Turn the stream into an array of buffers + return streamToArray(pack) + .then((arr) => { + // For each buffer in the array + for (var i = 0, l = arr.length; i < l; ++i) { + // Grab the part + var part = parts[i]; + // Push it into our buffer array + buffers.push((part instanceof Buffer) ? part : new Buffer(part)); + } + // Resolve with concatenated buffers + return resolve(Buffer.concat(buffers)); + }); + }); }); // Create an outgoing tar packer for our project - var outgoingPacker = tar.Pack({ noProprietary: true }) - .on('error', reject) + var outgoingPacker = tar.Pack({ + noProprietary: true + }) + .on('error', reject); // Send the project directory through the tar packer and into the post request - Reader({ path: opts.target, type: "Directory" }) + Reader({ + path: opts.target, + type: 'Directory' + }) .on('error', reject) .pipe(outgoingPacker) - .pipe(post_req) + .pipe(post_req); }); -} +}; module.exports = exportables; diff --git a/test/unit/deploy.js b/test/unit/deploy.js index 1e605037..ba25df51 100644 --- a/test/unit/deploy.js +++ b/test/unit/deploy.js @@ -1,3 +1,5 @@ +var rust = require('../../lib/tessel/deployment/rust'); + process.on('uncaughtException', function(err) { console.error(err.stack); }); @@ -547,7 +549,7 @@ exports['deploy.run'] = { callback(null, this.tessel._rps); if (this.exec.callCount === 1) { - test.deepEqual(command, ['chmod', '+x', '/tmp/remote-script/rust_executable']); + test.deepEqual(command, ['chmod', '+x', '/tmp/remote-script/' + rust.exports.meta.binary]); } if (this.exec.callCount === 2) { this.tessel._rps.emit('close'); @@ -558,7 +560,7 @@ exports['deploy.run'] = { entryPoint: 'foo', lang: deployment.rs, }).then(() => { - test.deepEqual(this.exec.lastCall.args[0], ['rust_executable']); + test.deepEqual(this.exec.lastCall.args[0], [rust.exports.meta.binary]); test.done(); }); },