Search in sources :

Example 1 with BuiltinLibraryIdentifier

use of mb.stratego.build.strincr.BuiltinLibraryIdentifier in project spoofax by metaborg.

the class GenerateSourcesBuilder method splitOffLinkedLibrariesIncludeDirs.

/**
 * Copy oldArgs to newArgs, except for built-in libraries, which are split off and their names returned.
 * @return
 */
public static Arguments splitOffLinkedLibrariesIncludeDirs(Arguments oldArgs, Collection<IModuleImportService.ModuleIdentifier> builtinLibs, Collection<ResourcePath> includeDirs, String projectPath) {
    final Arguments newArgs = new Arguments();
    for (Iterator<Object> iterator = oldArgs.iterator(); iterator.hasNext(); ) {
        Object oldArg = iterator.next();
        if (oldArg.equals("-I")) {
            final Object nextOldArg = iterator.next();
            final Path nextOldArgPath;
            if (nextOldArg instanceof File) {
                nextOldArgPath = ((File) nextOldArg).toPath();
            } else if (nextOldArg instanceof String) {
                final String nextOldArgString = (String) nextOldArg;
                final Path path = Paths.get(nextOldArgString);
                if (path.isAbsolute()) {
                    nextOldArgPath = path;
                } else {
                    nextOldArgPath = Paths.get(projectPath, nextOldArgString);
                }
            } else {
                logger.error("-I argument is not a string or file? Ignoring this for import resolution: " + nextOldArg);
                newArgs.add(oldArg, nextOldArg);
                continue;
            }
            if (Files.exists(nextOldArgPath)) {
                includeDirs.add(new FSPath(nextOldArgPath));
            } else {
                logger.warn("-I argument '" + nextOldArgPath + "' does not exist, ignoring.");
            }
        } else if (oldArg.equals("-la")) {
            final Object nextOldArg = iterator.next();
            final String nextOldArgString = nextOldArg instanceof String ? (String) nextOldArg : nextOldArg.toString();
            @Nullable final BuiltinLibraryIdentifier libraryIdentifier = BuiltinLibraryIdentifier.fromString(nextOldArgString);
            if (libraryIdentifier == null) {
                // throw new MetaborgRuntimeException("Incremental compiler internal bug: missing support for custom pre-compiled libraries such as: " + nextOldArgString);
                newArgs.add(oldArg, nextOldArg);
                continue;
            }
            builtinLibs.add(libraryIdentifier);
        } else {
            newArgs.add(oldArg);
        }
    }
    return newArgs;
}
Also used : Path(java.nio.file.Path) ResourcePath(mb.resource.hierarchical.ResourcePath) FSPath(mb.resource.fs.FSPath) BuiltinLibraryIdentifier(mb.stratego.build.strincr.BuiltinLibraryIdentifier) Arguments(org.metaborg.util.cmd.Arguments) FSPath(mb.resource.fs.FSPath) File(java.io.File)

Aggregations

File (java.io.File)1 Path (java.nio.file.Path)1 FSPath (mb.resource.fs.FSPath)1 ResourcePath (mb.resource.hierarchical.ResourcePath)1 BuiltinLibraryIdentifier (mb.stratego.build.strincr.BuiltinLibraryIdentifier)1 Arguments (org.metaborg.util.cmd.Arguments)1