Skip to content

Commit

Permalink
Still doesn't deploy, fixed grunt up to it
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Lewis authored and johnnyman727 committed Jul 13, 2016
1 parent 13a34f2 commit 48e4c75
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 47 deletions.
4 changes: 2 additions & 2 deletions lib/tessel/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,7 +24,7 @@ module.exports.js = {
};

module.exports.rs = {
execute: () => [rust.BINARY_NAME],
execute: () => [rust.exports.meta.binary],
};

module.exports.py = {
Expand Down
90 changes: 47 additions & 43 deletions lib/tessel/deployment/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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}
`;
},
},
Expand All @@ -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());
});
};

Expand All @@ -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
Expand All @@ -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;
6 changes: 4 additions & 2 deletions test/unit/deploy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var rust = require('../../lib/tessel/deployment/rust');

process.on('uncaughtException', function(err) {
console.error(err.stack);
});
Expand Down Expand Up @@ -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');
Expand All @@ -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();
});
},
Expand Down

0 comments on commit 48e4c75

Please sign in to comment.