Search in sources :

Example 1 with StrategoExecutor

use of org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor in project spoofax by metaborg.

the class PackSdf method build.

@Override
public OutputPersisted<File> build(Input input) throws IOException {
    require(input.inputFile);
    if (input.origin != null) {
        requireBuild(input.origin);
    }
    final Arguments args = new Arguments();
    args.addAll(input.extraArgs);
    for (File path : input.includePaths) {
        require(path, FileExistsStamper.instance);
        if (!path.exists()) {
            continue;
        }
        if (FilenameUtils.isExtension(path.getName(), "def")) {
            args.addFile("-Idef", path);
        } else {
            /*
                 * HACK: for full incremental soundness, a require on the directory is needed here, since new files can
                 * be added to the path, which influence pack-sdf. However, since the Spoofax build generates new files
                 * into some of these directories, that would cause the requirement to always be inconsistent, always
                 * triggering a rebuild. This is why we omit the requirement.
                 * 
                 * seba: This could be solved using a customary stamper that only tracks files matching some naming
                 * convention.
                 */
            args.addFile("-I", path);
        }
    }
    // @formatter:off
    final Arguments arguments = new Arguments().addFile("-i", input.inputFile).addFile("-o", input.outputFile).addAll(args);
    final ExecutionResult result = new StrategoExecutor().withToolsContext().withStrategy(main_pack_sdf_0_0.instance).withTracker(newResourceTracker(Pattern.quote("  including ") + ".*")).withName("pack-sdf").executeCLI(arguments);
    // @formatter:on
    provide(input.outputFile);
    for (File required : extractRequiredPaths(result.errLog)) {
        require(required);
    }
    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) File(java.io.File) StrategoExecutor(org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor)

Example 2 with StrategoExecutor

use of org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor in project spoofax by metaborg.

the class Sdf2Rtg method build.

@Override
public OutputPersisted<File> build(Input input) throws IOException {
    requireBuild(input.origin);
    if (SpoofaxContext.BETTER_STAMPERS) {
        require(input.inputFile, new Sdf2RtgStamper(input.context));
    } else {
        require(input.inputFile);
    }
    // @formatter:off
    final Arguments arguments = new Arguments().addFile("-i", input.inputFile).add("-m", input.module).addFile("-o", input.outputFile).add("--ignore-missing-cons");
    final ExecutionResult result = new StrategoExecutor().withToolsContext().withStrategy(main_sdf2rtg_0_0.instance).withTracker(newResourceTracker(Pattern.quote("Invoking native tool") + ".*")).withName("sdf2rtg").executeCLI(arguments);
    // @formatter:on
    provide(input.outputFile);
    setState(State.finished(result.success));
    return OutputPersisted.of(input.outputFile);
}
Also used : Sdf2RtgStamper(org.metaborg.spoofax.meta.core.pluto.stamp.Sdf2RtgStamper) 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 3 with StrategoExecutor

use of org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor 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 4 with StrategoExecutor

use of org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor 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 5 with StrategoExecutor

use of org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor 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)

Aggregations

StrategoExecutor (org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor)7 ExecutionResult (org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor.ExecutionResult)7 Arguments (org.metaborg.util.cmd.Arguments)6 File (java.io.File)2 ResourceAgentTracker (org.metaborg.spoofax.meta.core.pluto.util.ResourceAgentTracker)2 Path (java.nio.file.Path)1 MetaborgException (org.metaborg.core.MetaborgException)1 Sdf2ParenthesizeStamper (org.metaborg.spoofax.meta.core.pluto.stamp.Sdf2ParenthesizeStamper)1 Sdf2RtgStamper (org.metaborg.spoofax.meta.core.pluto.stamp.Sdf2RtgStamper)1