Search in sources :

Example 46 with MetaborgException

use of org.metaborg.core.MetaborgException in project spoofax by metaborg.

the class LanguageSpecBuilder method clean.

public void clean(LanguageSpecBuildInput input) throws MetaborgException {
    final FileObject location = input.languageSpec().location();
    logger.debug("Cleaning {}", location);
    final SpoofaxCommonPaths paths = new SpoofaxLangSpecCommonPaths(location);
    cleanAndLog(paths.srcGenDir());
    cleanAndLog(paths.targetDir());
    try {
        final String path = path(input);
        plutoClean(path);
    } catch (IOException e) {
        throw new MetaborgException("Cleaning Pluto file attributes failed", e);
    }
    for (IBuildStep buildStep : buildSteps) {
        buildStep.execute(LanguageSpecBuildPhase.clean, input);
    }
}
Also used : MetaborgException(org.metaborg.core.MetaborgException) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) SpoofaxCommonPaths(org.metaborg.spoofax.core.build.SpoofaxCommonPaths)

Example 47 with MetaborgException

use of org.metaborg.core.MetaborgException in project spoofax by metaborg.

the class LanguageSpecBuilder method archive.

public FileObject archive(LanguageSpecBuildInput input) throws MetaborgException {
    logger.debug("Archiving language implementation for {}", input.languageSpec().location());
    initPluto();
    final File archiveFile;
    try {
        final Origin generateSourcesOrigin = GenerateSourcesBuilder.origin(generateSourcesBuilderInput(input));
        final Origin packageOrigin = PackageBuilder.origin(packageBuilderInput(input, generateSourcesOrigin));
        final Origin origin = Origin.Builder().add(generateSourcesOrigin).add(packageOrigin).get();
        final String path = path(input);
        archiveFile = plutoBuild(ArchiveBuilder.request(archiveBuilderInput(input, origin)), path).val();
    } catch (RequiredBuilderFailed e) {
        if (e.getMessage().contains("no rebuild of failing builder")) {
            throw new MetaborgException(failingRebuildMessage);
        }
        throw new MetaborgException();
    } catch (RuntimeException e) {
        throw e;
    } catch (Throwable e) {
        throw new MetaborgException(e);
    }
    for (IBuildStep buildStep : buildSteps) {
        buildStep.execute(LanguageSpecBuildPhase.pkg, input);
    }
    return resourceService.resolve(archiveFile);
}
Also used : Origin(build.pluto.dependency.Origin) MetaborgException(org.metaborg.core.MetaborgException) RequiredBuilderFailed(build.pluto.builder.RequiredBuilderFailed) File(java.io.File)

Example 48 with MetaborgException

use of org.metaborg.core.MetaborgException in project spoofax by metaborg.

the class LanguageSpecBuilder method compile.

public void compile(LanguageSpecBuildInput input) throws MetaborgException {
    logger.debug("Running pre-Java build for {}", input.languageSpec().location());
    initPluto();
    try {
        final String path = path(input);
        plutoBuild(GenerateSourcesBuilder.request(generateSourcesBuilderInput(input)), path);
    } catch (RequiredBuilderFailed e) {
        if (e.getMessage().contains("no rebuild of failing builder")) {
            throw new MetaborgException(failingRebuildMessage, e);
        } else {
            throw new MetaborgException();
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Throwable e) {
        throw new MetaborgException(e);
    }
    final SpoofaxCommonPaths paths = new SpoofaxLangSpecCommonPaths(input.languageSpec().location());
    // HACK: compile the main ESV file to make sure that packed.esv file is always available.
    final Iterable<FileObject> esvRoots = languagePathService.sourcePaths(input.project(), SpoofaxConstants.LANG_ESV_NAME);
    final FileObject mainEsvFile = paths.findEsvMainFile(esvRoots);
    try {
        if (mainEsvFile != null && mainEsvFile.exists()) {
            logger.info("Compiling Main ESV file {}", mainEsvFile);
            // @formatter:off
            final BuildInput buildInput = new BuildInputBuilder(input.languageSpec()).addSource(mainEsvFile).addTransformGoal(new CompileGoal()).withMessagePrinter(new StreamMessagePrinter(sourceTextService, false, true, logger)).build(dependencyService, languagePathService);
            // @formatter:on
            final ISpoofaxBuildOutput result = runner.build(buildInput, null, null).schedule().block().result();
            if (!result.success()) {
                throw new MetaborgException("Compiling Main ESV file failed");
            }
        }
    } catch (FileSystemException e) {
        final String message = logger.format("Could not compile ESV file {}", mainEsvFile);
        throw new MetaborgException(message, e);
    } catch (InterruptedException e) {
    // Ignore
    }
    // HACK: compile the main DS file if available, after generating sources (because ds can depend on Stratego
    // strategies), to generate an interpreter.
    final Iterable<FileObject> dsRoots = languagePathService.sourcePaths(input.project(), SpoofaxConstants.LANG_DYNSEM_NAME);
    final FileObject mainDsFile = paths.findDsMainFile(dsRoots, input.languageSpec().config().strategoName());
    try {
        if (mainDsFile != null && mainDsFile.exists()) {
            if (languageIdentifierService.identify(mainDsFile, input.project()) == null) {
                logger.error("Could not identify DynSem main file {}, please add DynSem as a compile dependency", mainDsFile);
            }
            logger.info("Compiling main DynSem file {}", mainDsFile);
            // @formatter:off
            final BuildInput buildInput = new BuildInputBuilder(input.languageSpec()).addSource(mainDsFile).addTransformGoal(new EndNamedGoal("Generate interpreter")).withMessagePrinter(new StreamMessagePrinter(sourceTextService, false, true, logger)).build(dependencyService, languagePathService);
            // @formatter:on
            final ISpoofaxBuildOutput result = runner.build(buildInput, null, null).schedule().block().result();
            if (!result.success()) {
                logger.error("Compiling main DynSem file {} failed", mainDsFile);
            }
        }
    } catch (FileSystemException e) {
        final String message = logger.format("Could not compile DynSem file {}", mainDsFile);
        throw new MetaborgException(message, e);
    } catch (InterruptedException e) {
    // Ignore
    }
    for (IBuildStep buildStep : buildSteps) {
        buildStep.execute(LanguageSpecBuildPhase.compile, input);
    }
}
Also used : StreamMessagePrinter(org.metaborg.core.messages.StreamMessagePrinter) CompileGoal(org.metaborg.core.action.CompileGoal) ISpoofaxBuildOutput(org.metaborg.spoofax.core.build.ISpoofaxBuildOutput) MetaborgException(org.metaborg.core.MetaborgException) BuildInputBuilder(org.metaborg.core.build.BuildInputBuilder) FileSystemException(org.apache.commons.vfs2.FileSystemException) BuildInput(org.metaborg.core.build.BuildInput) EndNamedGoal(org.metaborg.core.action.EndNamedGoal) RequiredBuilderFailed(build.pluto.builder.RequiredBuilderFailed) FileObject(org.apache.commons.vfs2.FileObject) SpoofaxCommonPaths(org.metaborg.spoofax.core.build.SpoofaxCommonPaths)

Example 49 with MetaborgException

use of org.metaborg.core.MetaborgException 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");
    }
}
Also used : ResourceAgentTracker(org.metaborg.spoofax.meta.core.pluto.util.ResourceAgentTracker) MetaborgException(org.metaborg.core.MetaborgException) ExecutionResult(org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor.ExecutionResult) StrategoExecutor(org.metaborg.spoofax.meta.core.pluto.util.StrategoExecutor)

Aggregations

MetaborgException (org.metaborg.core.MetaborgException)49 FileObject (org.apache.commons.vfs2.FileObject)25 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)19 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)17 HybridInterpreter (org.strategoxt.HybridInterpreter)14 IProject (org.metaborg.core.project.IProject)12 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)11 IOException (java.io.IOException)9 IContext (org.metaborg.core.context.IContext)9 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)9 Nullable (javax.annotation.Nullable)8 AnalysisException (org.metaborg.core.analysis.AnalysisException)8 FileSystemException (org.apache.commons.vfs2.FileSystemException)7 MetaborgRuntimeException (org.metaborg.core.MetaborgRuntimeException)7 ISpoofaxAnalyzeResults (org.metaborg.spoofax.core.analysis.ISpoofaxAnalyzeResults)6 SpoofaxAnalyzeResults (org.metaborg.spoofax.core.analysis.SpoofaxAnalyzeResults)6 IStrategoAppl (org.spoofax.interpreter.terms.IStrategoAppl)6 ILanguage (org.metaborg.core.language.ILanguage)5 ISourceRegion (org.metaborg.core.source.ISourceRegion)5 ISpoofaxParseUnit (org.metaborg.spoofax.core.unit.ISpoofaxParseUnit)5