Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declaration generation #52

Merged
merged 2 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/generator/WDL/entities/TaskGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export default class TaskGenerator {

this.taskBlockString += buildDeclarations(this.declarations, this.settings);
this.taskBlockString += this.buildCommand(this.command, this.commandStyle);
this.taskBlockString += this.buildSegment(constants.OUTPUT, this.outputMappings);
this.taskBlockString += this.buildSegment(constants.META, this.meta);
this.taskBlockString += this.buildSegment(constants.PARAMETER_META, this.parameterMeta);
this.taskBlockString += this.buildSegment(constants.RUNTIME, this.runtime);
this.taskBlockString += this.buildSegment(constants.OUTPUT, this.outputMappings);

this.taskBlockString += `${constants.SCOPE_CLOSE}${EOL}${EOL}`;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ export default class TaskGenerator {

_.forEach(data, (val, key) => {
res += `${DOUBLE_SCOPE_INDENT}${segmentName === constants.OUTPUT ? val.type : ''} `;
res += `${key} ${segmentName === constants.OUTPUT ? constants.EQ : constants.COLON} ${buildValue(val)}${EOL}`;
res += `${key}${segmentName === constants.OUTPUT ? ` ${constants.EQ}` : constants.COLON} ${buildValue(val)}${EOL}`;
});

res += `${SCOPE_INDENT}${constants.SCOPE_CLOSE}${EOL}`;
Expand Down
57 changes: 25 additions & 32 deletions src/generator/WDL/entities/WorkflowGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class WorkflowGenerator {
this.wfStep = wfStep;

const action = wfStep.action;
this.declarations = action.i;
this.declarations = this.getDeclarations(wfStep);
this.outputMappings = wfStep.o;

this.children = wfStep.children;
Expand All @@ -32,6 +32,21 @@ export default class WorkflowGenerator {
this.settings = new Settings(settings);
}

// eslint-disable-next-line class-methods-use-this
getDeclarations(step) {
const declarations = {};
_.forEach(step.action.i || {}, (input, name) => {
declarations[name] = input;
});
_.forEach(step.ownDeclarations || {}, (declaration, name) => {
declarations[name] = {
default: declaration.expression.string,
type: declaration.desc.type,
};
});
return declarations;
}

renderWorkflow() {
const EOL = this.settings.getValue('style.eol');

Expand All @@ -50,7 +65,7 @@ export default class WorkflowGenerator {
}

renderStepMainBody(step, prosessed) {
const declarations = step.action.i;
const declarations = this.getDeclarations(step);
const children = step.children;

let res = '';
Expand All @@ -68,18 +83,14 @@ export default class WorkflowGenerator {
return res;
}

// eslint-disable-next-line class-methods-use-this
getNextOrderedChild(children, processed) {
let res = '';
const isSubset = (source, target) => !_.difference(_.flatten(source), _.flatten(target)).length;

_.forEach(children, (child) => {
if (_.indexOf(processed, child.name) < 0) {
const refs = this.findCallReferences(child);

if (refs.length === 0 || isSubset(refs, processed)) {
res = child.name;
return false;
}
res = child.name;
return false;
}

return true;
Expand All @@ -91,32 +102,14 @@ export default class WorkflowGenerator {
return res;
}

findCallReferences(child) {
const res = [];

_.forEach(child.i, (value) => {
if (value.inputs && _.size(value.inputs) > 0) {
if (_.size(value.inputs) > 1) {
throw new Error('Multiple links into one input are prohibited');
}

const connection = value.inputs[0];
if (connection.from instanceof Port && connection.from.step.name !== this.wfStep.name) {
res.push(connection.from.step.name);
}
}
});

_.forEach(child.children, (item) => {
res.concat(this.findCallReferences(item));
});

return res;
}

buildPortValue(value) {
if (value.desc && value.desc.default && !_.isUndefined(value.desc.default)) {
return `${value.desc.default}`;
} else if (value.desc && value.desc.expression && !_.isUndefined(value.desc.expression)) {
return `${value.desc.expression}`;
} else if (value.expression && value.expression.type.toLowerCase() !== 'identifier'
&& value.expression.type.toLowerCase() !== 'memberaccess' && !_.isUndefined(value.expression.string)) {
return `${value.expression.string}`;
} else if (value.inputs && _.size(value.inputs) > 0) {
if (_.size(value.inputs) > 1) {
throw new Error('Multiple links into one input are prohibited');
Expand Down
8 changes: 1 addition & 7 deletions src/generator/WDL/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export default function generate(objectModel) {
if (!val.type) {
const action = val.action;
actionsToBeRendered[action.name] = action;
} else if (val.type.toLowerCase() === 'workflow') {
actionsToBeRendered[val.action.name] = val;
} else {
actionSelector(val.children);
}
Expand All @@ -27,11 +25,7 @@ export default function generate(objectModel) {
actionSelector(objectModel.children);

_.forEach(actionsToBeRendered, (action) => {
if (!!action.type && action.type.toLowerCase() === 'workflow') {
tasks += new WorkflowGenerator(action, {}).renderWorkflow();
} else {
tasks += new TaskGenerator(action).renderTask();
}
tasks += new TaskGenerator(action).renderTask();
});

return wf + tasks;
Expand Down
16 changes: 10 additions & 6 deletions src/model/Declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@ export default class Declaration extends Port {
if (!declaration.expression || !declaration.type) {
throw new Error('Declaration could be created only using declaration object');
}
super(name, step, {});

delete this.desc;
const expression = extractExpression(declaration.expression);
const type = extractType(declaration.type);
const desc = {
default: expression.string || undefined,
type,
};
super(name, step, desc);

/**
* Declaration expression extracted object.
* @type {string}
* @type {Object}
*/
this.expression = extractExpression(declaration.expression);
this.expression = expression;
/**
* Declaration type.
* @type {string}
*/
this.type = extractType(declaration.type);
this.type = type;
}

}
17 changes: 16 additions & 1 deletion src/parser/WDL/entities/WDLWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export default class WDLWorkflow {

const scatter = WDLWorkflow.findStepInStructureRecursively(parent, item.scatterName);
scatter.i[itemName].bind(port);
if (collection.type.toLowerCase() !== 'memberaccess' && collection.type.toLowerCase() !== 'identifier'
&& !_.isUndefined(collection.string)) {
scatter.i[itemName].desc.expression = collection.string;
}

this.parseBodyBindings(item.attributes.body.list, 'scatter', scatter, ['workflowoutputs', 'meta', 'parametermeta']);
}
Expand Down Expand Up @@ -270,14 +274,25 @@ export default class WDLWorkflow {
if (!step.i[declaration] && step instanceof Workflow && step.ownDeclarations[declaration]) {
// remove declaration and add it as an input
const declarationObj = step.removeDeclaration(declaration);
const port = new Port(declaration, step, { type: declarationObj.type });
const desc = {
type: declarationObj.type,
};
if (expression.string
&& expression.type.toLowerCase() !== 'memberaccess' && expression.type.toLowerCase() !== 'identifier') {
desc.expression = expression.string;
}
const port = new Port(declaration, step, desc);
_.forEach(declarationObj.outputs, conn => conn.to.bind(port));
step.i[declaration] = port;
}

if (step.i[declaration]) {
const bindings = WDLWorkflow.getPortsForBinding(this.workflowStep, parentStep, expression);
_.forEach(bindings, binding => step.i[declaration].bind(binding));
if (expression.string
&& expression.type.toLowerCase() !== 'memberaccess' && expression.type.toLowerCase() !== 'identifier') {
step.i[declaration].expression = expression;
}
} else {
throw new WDLParserError(`Undeclared variable trying to be assigned: call '${step.name}' --> '${declaration}'`);
}
Expand Down