use of org.metaborg.util.cmd.Arguments in project spoofax by metaborg.
the class Strj method build.
@Override
public None build(Input input) throws IOException {
requireBuild(input.origin);
require(input.inputFile);
final File rtree = FileCommands.replaceExtension(input.outputPath, "rtree");
final File strdep = FileCommands.addExtension(input.outputPath, "dep");
// @formatter:off
final Arguments arguments = new Arguments().addFile("-i", input.inputFile).addFile("-o", input.outputPath).addLine(input.packageName != null ? "-p " + input.packageName : "").add(input.library ? "--library" : "").add(input.clean ? "--clean" : "");
for (File dir : input.includeDirs) {
if (dir != null) {
arguments.addFile("-I", dir);
}
}
for (File file : input.includeFiles) {
if (file != null) {
arguments.addFile("-i", file);
}
}
for (String lib : input.includeLibs) {
if (lib != null && !lib.isEmpty()) {
arguments.add("-la", lib);
}
}
if (input.cacheDir != null) {
arguments.addFile("--cache-dir", input.cacheDir);
}
arguments.addAll(input.extraArgs);
// Delete rtree file to prevent it influencing the build.
rtree.delete();
// @formatter:off
final ResourceAgentTracker tracker = newResourceTracker(Pattern.quote("[ strj | info ]") + ".*", Pattern.quote("[ strj | error ] Compilation failed") + ".*", Pattern.quote("[ strj | warning ] Nullary constructor") + ".*", Pattern.quote("[ strj | warning ] No Stratego files found in directory") + ".*", Pattern.quote("[ strj | warning ] Found more than one matching subdirectory found for") + ".*", Pattern.quote(" [\"") + ".*" + Pattern.quote("\"]"));
final ExecutionResult result = new StrategoExecutor().withStrjContext().withStrategy(org.strategoxt.strj.main_0_0.instance).withTracker(tracker).withName("strj").executeCLI(arguments);
// @formatter:on
// Delete rtree file again to prevent it influencing subsequent builds.
rtree.delete();
if (input.depPath.isDirectory()) {
for (Path sourceFile : FileCommands.listFilesRecursive(input.depPath.toPath())) {
provide(sourceFile.toFile());
}
} else {
provide(input.depPath);
}
provide(strdep);
if (result.success) {
if (FileCommands.exists(strdep)) {
registerUsedPaths(strdep);
}
} else {
// If Stratego compilation fails, the resulting .dep file is incomplete, so require all Stratego files.
for (File sourceFile : FileUtils.listFiles(context.baseDir, new String[] { "str" }, true)) {
require(sourceFile);
}
}
setState(State.finished(result.success));
return None.val;
}
use of org.metaborg.util.cmd.Arguments in project spoofax by metaborg.
the class MakePermissive method build.
@Override
public OutputPersisted<File> build(Input input) throws IOException {
requireBuild(input.origin);
require(input.inputFile);
// @formatter:off
final Arguments arguments = new Arguments().addFile("-i", input.inputFile).addFile("-o", input.outputFile).addLine("--optimize on").addLine("--semantic-completions off").addLine("--syntactic-completions off");
final ExecutionResult result = new StrategoExecutor().withPermissiveGrammarsContext().withStrategy(make_permissive.getMainStrategy()).withTracker(newResourceTracker(Pattern.quote("[ make-permissive | info ]") + ".*")).withName("make-permissive").executeCLI(arguments);
// @formatter:on
provide(input.outputFile);
setState(State.finished(result.success));
return OutputPersisted.of(input.outputFile);
}
use of org.metaborg.util.cmd.Arguments in project spoofax by metaborg.
the class Rtg2Sig method build.
@Override
public OutputPersisted<File> build(Input input) throws IOException {
requireBuild(input.origin);
require(input.inputFile);
// @formatter:off
final Arguments arguments = new Arguments().addFile("-i", input.inputFile).add("--module", input.module).addFile("-o", input.outputFile);
final ExecutionResult result = new StrategoExecutor().withToolsContext().withStrategy(main_rtg2sig_0_0.instance).withTracker(newResourceTracker()).withName("rtg2sig").executeCLI(arguments);
// @formatter:on
provide(input.outputFile);
setState(State.finished(result.success));
return OutputPersisted.of(input.outputFile);
}
use of org.metaborg.util.cmd.Arguments in project spoofax by metaborg.
the class Sdf2ParenthesizeLegacy method build.
@Override
public None build(Input input) throws IOException {
requireBuild(input.origin);
if (SpoofaxContext.BETTER_STAMPERS) {
require(input.inputFile, new Sdf2ParenthesizeStamper(input.context));
} else {
require(input.inputFile);
}
// @formatter:off
final Arguments arguments = new Arguments().addFile("-i", input.inputFile).add("-m", input.inputModule).add("--lang", input.inputModule).add("--omod", input.outputModule).addFile("-o", input.outputFile).add("--main-strategy", "io-" + input.inputModule + "-parenthesize").add("--rule-prefix", input.inputModule).add("--sig-module", "signatures/-");
final ExecutionResult result = new StrategoExecutor().withToolsContext().withStrategy(main_sdf2parenthesize_0_0.instance).withTracker(newResourceTracker(Pattern.quote("[ sdf2parenthesize | info ]") + ".*", Pattern.quote("Invoking native tool") + ".*")).withName("sdf2parenthesize").executeCLI(arguments);
if (!result.success) {
FileCommands.writeToFile(input.outputFile, "module " + input.inputModule + "\nrules\n\n parenthesize-" + input.inputModule + " = id");
}
// @formatter:on
provide(input.outputFile);
return None.val;
}
use of org.metaborg.util.cmd.Arguments in project spoofax by metaborg.
the class SpoofaxLanguageSpecConfig method sdfArgs.
public Arguments sdfArgs() {
final List<String> values = config.getList(String.class, PROP_SDF_ARGS);
final Arguments arguments = new Arguments();
if (values != null) {
for (String value : values) {
arguments.add(value);
}
}
return arguments;
}
Aggregations