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;
}
Aggregations