Skip to content

Commit

Permalink
Adding support for initialization files to prolog compilation box.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Krulis committed Mar 24, 2019
1 parent b0cfcde commit dcd281e
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PrologCompilationBox extends CompilationBox
public static $BOX_TYPE = "prolog-compilation";
public static $PROLOG_BINARY = "/usr/bin/swipl";
public static $DEFAULT_NAME = "SWI-Prolog Compilation";
public static $INIT_FILE_PORT_KEY = "init-file";
public static $WRAPPER_FILE_PORT_KEY = "compilation-wrapper";

private static $initialized = false;
Expand All @@ -34,6 +35,7 @@ public static function init() {
if (!self::$initialized) {
self::$initialized = true;
self::$defaultInputPorts = array(
new Port((new PortMeta())->setName(self::$INIT_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port((new PortMeta())->setName(self::$WRAPPER_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port((new PortMeta())->setName(self::$RUNNER_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port((new PortMeta())->setName(self::$ARGS_PORT_KEY)->setType(VariableTypes::$STRING_ARRAY_TYPE)),
Expand Down Expand Up @@ -111,20 +113,22 @@ public function compile(CompilationParams $params): array {
$this->getInputPortValue(self::$ARGS_PORT_KEY)->getValue());
}

$initFile = $this->getInputPortValue(self::$INIT_FILE_PORT_KEY)->getValue();
$sourceFiles = $this->getInputPortValue(self::$SOURCE_FILES_PORT_KEY)->getValue(ConfigParams::$EVAL_DIR);
$extraFiles = $this->getInputPortValue(self::$EXTRA_FILES_PORT_KEY)->getValue(ConfigParams::$EVAL_DIR);
$runnerFile = $this->getInputPortValue(self::$RUNNER_FILE_PORT_KEY)->getValue(ConfigParams::$EVAL_DIR);

array_push($args,
"-o",
$this->getOutputPortValue(self::$BINARY_FILE_PORT_KEY)->getValue(ConfigParams::$EVAL_DIR),
"-c"
"-c",
$initFile,
...$sourceFiles
);
array_push($args, ...$extraFiles);
array_push($args, $runnerFile);

$task->setCommandArguments(
array_merge(
$args,
$this->getInputPortValue(self::$SOURCE_FILES_PORT_KEY)->getValue(ConfigParams::$EVAL_DIR),
$this->getInputPortValue(self::$EXTRA_FILES_PORT_KEY)->getValue(ConfigParams::$EVAL_DIR),
[ $this->getInputPortValue(self::$RUNNER_FILE_PORT_KEY)->getValue(ConfigParams::$EVAL_DIR) ]
)
);
$task->setCommandArguments($args);

// check if file produced by compilation was successfully created
$binary = $this->getOutputPortValue(self::$BINARY_FILE_PORT_KEY)->getDirPrefixedValue(ConfigParams::$SOURCE_DIR);
Expand Down

0 comments on commit dcd281e

Please sign in to comment.