Skip to content

Commit

Permalink
WIP #600 Added arch code gen
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed Aug 9, 2016
1 parent ad1dc9c commit a1d47e6
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions src/plugins/ExportProject/ExportProject.js
Expand Up @@ -2,9 +2,11 @@
/*jshint node:true, browser:true*/

define([
'q',
'text!./metadata.json',
'plugin/ExecuteJob/ExecuteJob/ExecuteJob'
], function (
Q,
pluginMetadata,
PluginBase
) {
Expand Down Expand Up @@ -48,10 +50,15 @@ define([
ExportProject.prototype.main = function (callback) {
// Export the deepforge project as a torch project
var files = {},
artifact;
artifactName = `TestProject`, // FIXME: Change to project name
artifact = this.blobClient.createArtifact(artifactName);

this.createClasses(files); // Create the classes
this.createCustomLayers(files);
this.createArchitectures(artifact)
.then(() => {
return artifact.addFiles(files)
})
// operations
// TODO
// artifacts -> may need a bash script to download the data...
Expand All @@ -60,10 +67,7 @@ define([
// TODO
// README
// TODO
var artifactName = `TestProject`; // FIXME: Change to project name
artifact = this.blobClient.createArtifact(artifactName);

artifact.addFiles(files)
.then(() => artifact.save())
.then(hash => {
this.result.addArtifact(hash);
Expand All @@ -73,5 +77,38 @@ define([
});
};

ExportProject.prototype.isArchDir = function (node) {
return this.core.getAttribute(node, 'name') === 'MyArchitectures';
};

ExportProject.prototype.createArchitectures = function (artifact) {
var archIds,
hashes,
files = {};

// Get all architecture ids
return this.core.loadChildren(this.rootNode)
.then(children => {
var archDir = children.find(node => this.isArchDir(node));
archIds = this.core.getChildrenPaths(archDir);

return Q.all(archIds.map(id => this.getPtrCodeHash(id)));
})
// Add the hashes by name
.then(_hashes => {
hashes = _hashes;
return Q.all(archIds.map(id => this.core.loadByPath(this.rootNode, id)));
})
.then(arches => {
var name;
// TODO: Detect duplicate names
for (var i = arches.length; i--;) {
name = this.core.getAttribute(arches[i], 'name');
files[`architectures/${name}.lua`] = hashes[i];
}
return artifact.addObjectHashes(files);
});
};

return ExportProject;
});

0 comments on commit a1d47e6

Please sign in to comment.