@Override public IExtendedScannerInfo getDefaultScannerInfo( IBuildConfiguration buildConfig, IExtendedScannerInfo baseScannerInfo, ILanguage language, URI buildDirectoryURI) { try { String[] commands = getCompileCommands(language); if (commands == null || commands.length == 0) { // no default commands return null; } Path buildDirectory = Paths.get(buildDirectoryURI); // Pick the first one Path command = Paths.get(commands[0]); List<String> commandLine = new ArrayList<>(); if (command.isAbsolute()) { commandLine.add(command.toString()); } else { commandLine.add(getCommandPath(command).toString()); } if (baseScannerInfo != null && baseScannerInfo.getIncludePaths() != null) { for (String includePath : baseScannerInfo.getIncludePaths()) { commandLine.add("-I" + includePath); // $NON-NLS-1$ } } addDiscoveryOptions(commandLine); // output to stdout commandLine.add("-o"); // $NON-NLS-1$ commandLine.add("-"); // $NON-NLS-1$ // Source is an empty tmp file String extension; if (GPPLanguage.ID.equals(language.getId())) { extension = ".cpp"; } else if (GCCLanguage.ID.equals(language.getId())) { extension = ".c"; } else { // In theory we shouldn't get here return null; } Path tmpFile = Files.createTempFile(buildDirectory, ".sc", extension); // $NON-NLS-1$ commandLine.add(tmpFile.toString()); return getScannerInfo(buildConfig, commandLine, buildDirectory, tmpFile); } catch (IOException e) { Activator.log(e); return null; } }
@Override public IExtendedScannerInfo getScannerInfo( IBuildConfiguration buildConfig, List<String> commandStrings, IExtendedScannerInfo baseScannerInfo, IResource resource, URI buildDirectoryURI) { try { Path buildDirectory = Paths.get(buildDirectoryURI); Path command = Paths.get(commandStrings.get(0)); List<String> commandLine = new ArrayList<>(); if (command.isAbsolute()) { commandLine.add(command.toString()); } else { commandLine.add(getCommandPath(command).toString()); } if (baseScannerInfo != null && baseScannerInfo.getIncludePaths() != null) { for (String includePath : baseScannerInfo.getIncludePaths()) { commandLine.add("-I" + includePath); // $NON-NLS-1$ } } addDiscoveryOptions(commandLine); commandLine.addAll(commandStrings.subList(1, commandStrings.size())); // Change output to stdout boolean haveOut = false; for (int i = 0; i < commandLine.size() - 1; ++i) { if (commandLine.get(i).equals("-o")) { // $NON-NLS-1$ commandLine.set(i + 1, "-"); // $NON-NLS-1$ haveOut = true; break; } } if (!haveOut) { commandLine.add("-o"); // $NON-NLS-1$ commandLine.add("-"); // $NON-NLS-1$ } // Change source file to a tmp file (needs to be empty) Path tmpFile = null; for (int i = 1; i < commandLine.size(); ++i) { if (!commandLine.get(i).startsWith("-")) { // $NON-NLS-1$ // TODO optimize by dealing with multi arg options like -o Path filePath = buildDirectory.resolve(commandLine.get(i)); IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(filePath.toUri()); if (files.length > 0) { // replace it with a temp file Path parentPath = filePath.getParent(); String extension = files[0].getFileExtension(); if (extension == null) { // Not sure if this is a reasonable choice when // there's // no extension extension = ".cpp"; // $NON-NLS-1$ } else { extension = '.' + extension; } tmpFile = Files.createTempFile(parentPath, ".sc", extension); // $NON-NLS-1$ commandLine.set(i, tmpFile.toString()); } } } if (tmpFile == null) { // Have to assume there wasn't a source file. Add one in the // resource's container IPath parentPath = resource instanceof IFile ? resource.getParent().getLocation() : resource.getLocation(); tmpFile = Files.createTempFile( parentPath.toFile().toPath(), ".sc", ".cpp"); // $NON-NLS-1$ //$NON-NLS-2$ commandLine.add(tmpFile.toString()); } return getScannerInfo(buildConfig, commandLine, buildDirectory, tmpFile); } catch (IOException e) { Activator.log(e); return null; } }