use of org.metaborg.spoofax.meta.core.pluto.util.ResourceAgentTracker 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.spoofax.meta.core.pluto.util.ResourceAgentTracker in project spoofax by metaborg.
the class SpoofaxContext method newResourceTracker.
public ResourceAgentTracker newResourceTracker(String... excludePatterns) {
final ResourceAgentTracker tracker = new ResourceAgentTracker(resourceService, base, excludePatterns);
final ResourceAgent agent = tracker.agent();
agent.setAbsoluteWorkingDir(base);
agent.setAbsoluteDefinitionDir(base);
return tracker;
}
use of org.metaborg.spoofax.meta.core.pluto.util.ResourceAgentTracker in project spoofax by metaborg.
the class StrategoBuildStep method execute.
@Override
protected void execute(StrategoBuildStepConfig config, LanguageSpecBuildPhase phase, LanguageSpecBuildInput input) throws MetaborgException {
// @formatter:off
final StrategoExecutor executor = new StrategoExecutor().withToolsContext().withTracker(new ResourceAgentTracker(resourceService, input.languageSpec().location())).withStrategyName(config.strategy).withName(config.strategy);
// @formatter:on
final ExecutionResult result = executor.executeCLI(config.arguments());
if (!result.success) {
throw new MetaborgException("Stratego execution of " + config.strategy + " failed");
}
}
Aggregations