Search in sources :

Example 6 with Arguments

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;
}
Also used : Path(java.nio.file.Path) ResourceAgentTracker(org.metaborg.spoofax.meta.core.pluto.util.ResourceAgentTracker) Arguments(org.metaborg.util.cmd.Arguments) ExecutionResult(org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor.ExecutionResult) File(java.io.File) StrategoExecutor(org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor)

Example 7 with Arguments

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);
}
Also used : Arguments(org.metaborg.util.cmd.Arguments) ExecutionResult(org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor.ExecutionResult) StrategoExecutor(org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor)

Example 8 with Arguments

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);
}
Also used : Arguments(org.metaborg.util.cmd.Arguments) ExecutionResult(org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor.ExecutionResult) StrategoExecutor(org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor)

Example 9 with Arguments

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;
}
Also used : Sdf2ParenthesizeStamper(org.metaborg.spoofax.meta.core.pluto.stamp.Sdf2ParenthesizeStamper) Arguments(org.metaborg.util.cmd.Arguments) ExecutionResult(org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor.ExecutionResult) StrategoExecutor(org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor)

Example 10 with Arguments

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;
}
Also used : Arguments(org.metaborg.util.cmd.Arguments)

Aggregations

Arguments (org.metaborg.util.cmd.Arguments)10 StrategoExecutor (org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor)6 ExecutionResult (org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor.ExecutionResult)6 File (java.io.File)4 Nullable (javax.annotation.Nullable)3 Origin (build.pluto.dependency.Origin)1 OutputTransient (build.pluto.output.OutputTransient)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 AllFileSelector (org.apache.commons.vfs2.AllFileSelector)1 FileObject (org.apache.commons.vfs2.FileObject)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 MetaborgException (org.metaborg.core.MetaborgException)1 BuildInput (org.metaborg.core.build.BuildInput)1 IExportConfig (org.metaborg.core.config.IExportConfig)1 IExportVisitor (org.metaborg.core.config.IExportVisitor)1 ILanguageComponentConfig (org.metaborg.core.config.ILanguageComponentConfig)1 LangDirExport (org.metaborg.core.config.LangDirExport)1 LangFileExport (org.metaborg.core.config.LangFileExport)1 ResourceExport (org.metaborg.core.config.ResourceExport)1