Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2015-02-06 18:23:24 -0500
committerJeff Johnston2015-02-09 14:37:32 -0500
commit09e475f6ac9b626261de29935063e819af76d5b0 (patch)
tree0e86e82803f1a954171e2fa36342d4f81ec27787
parent9f69476c994bbda942c9aa3eba5d334114047b02 (diff)
downloadorg.eclipse.linuxtools-09e475f6ac9b626261de29935063e819af76d5b0.tar.gz
org.eclipse.linuxtools-09e475f6ac9b626261de29935063e819af76d5b0.tar.xz
org.eclipse.linuxtools-09e475f6ac9b626261de29935063e819af76d5b0.zip
Fix gcov for Windows
- add check for Cygwin or MingW paths and translate to paths that Java File I/O can use (System paths) Change-Id: Id3b943568fe26ccdb211adc367d2b7581473446d Reviewed-on: https://git.eclipse.org/r/41343 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> Tested-by: Jeff Johnston <jjohnstn@redhat.com>
-rw-r--r--gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/CovManager.java146
1 files changed, 96 insertions, 50 deletions
diff --git a/gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/CovManager.java b/gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/CovManager.java
index 3f5d45d6c0..269a377944 100644
--- a/gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/CovManager.java
+++ b/gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/CovManager.java
@@ -11,6 +11,7 @@
package org.eclipse.linuxtools.internal.gcov.parser;
import java.io.BufferedInputStream;
+import java.io.BufferedReader;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.File;
@@ -33,6 +34,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.binutils.utils.STSymbolManager;
import org.eclipse.linuxtools.internal.gcov.Activator;
@@ -55,6 +57,9 @@ public class CovManager implements Serializable {
*
*/
private static final long serialVersionUID = 5582066617970911413L;
+
+ private static String winOSType = ""; //$NON-NLS-1$
+
// input
private final String binaryPath;
// results
@@ -250,58 +255,99 @@ public class CovManager implements Serializable {
}
}
- // transform String path to stream
- private DataInput openTraceFileStream(String filePath, String extension, Map<File, File> sourcePath)
- throws FileNotFoundException {
- File f = new File(filePath).getAbsoluteFile();
- String filename = f.getName();
- if (f.isFile() && f.canRead()) {
- FileInputStream fis = new FileInputStream(f);
- InputStream inputStream = new BufferedInputStream(fis);
- return new DataInputStream(inputStream);
- } else {
- String postfix = ""; //$NON-NLS-1$
- File dir = null;
- do {
- if (postfix.isEmpty()) {
- postfix = f.getName();
- } else {
- postfix = f.getName() + File.separator + postfix;
- }
- f = f.getParentFile();
- if (f != null) {
- dir = sourcePath.get(f);
- } else {
- break;
- }
- } while (dir == null);
+ // Get the Windows OS Type. We might have to change a path over to Windows format
+ // and this is different on Cygwin vs MingW.
+ private String getWinOSType() {
+ if (winOSType.equals("")) { //$NON-NLS-1$
+ try {
+ Process process = Runtime.getRuntime().exec(new String[] {"sh", "-c", "echo $OSTYPE"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ @SuppressWarnings("resource")
+ BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ String firstLine = null;
+ try {
+ firstLine = stdout.readLine();
+ } finally {
+ stdout.close();
+ }
+ if (firstLine != null)
+ winOSType = firstLine.trim();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ return winOSType;
+ }
- if (dir != null) {
- f = new File(dir, postfix);
- if (f.isFile() && f.canRead()) {
- return openTraceFileStream(f.getAbsolutePath(), extension, sourcePath);
- }
- }
+ // Get the OS path string. For Cygwin, translate We add a Win check to handle MingW.
+ // For MingW, we would rather represent C:\a\b as /C/a/b which
+ // doesn't cause Makefile to choke. For Cygwin we use /cygdrive/C/a/b
+ private String getTransformedPathString(IPath path) {
+ String s = path.toOSString();
+ if (Platform.getOS().equals(Platform.OS_WIN32)) {
+ if (getWinOSType().equals("cygwin")) { //$NON-NLS-1$
+ s = s.replaceAll("^\\\\cygdrive\\\\([a-zA-Z])", "$1:"); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ s = s.replaceAll("^\\\\([a-zA-Z])", "$1:"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ return s;
+ }
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- FileDialog fg = new FileDialog(shell, SWT.OPEN);
- fg.setFilterExtensions(new String[] { "*" + extension, "*.*", "*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- fg.setFileName(filename);
- fg.setText(NLS.bind(Messages.CovManager_No_FilePath_Error, new Object[] { filePath, filename }));
- String s = fg.open();
- if (s == null) {
- return null;
- } else {
- f = new File(s).getAbsoluteFile();
- addSourceLookup(sourcePath, f, new File(filePath).getAbsoluteFile());
- if (f.isFile() && f.canRead()) {
- FileInputStream fis = new FileInputStream(f);
- InputStream inputStream = new BufferedInputStream(fis);
- return new DataInputStream(inputStream);
- }
- }
- }
- return null;
+ // transform String path to stream
+ private DataInput openTraceFileStream(String filePath, String extension, Map<File, File> sourcePath)
+ throws FileNotFoundException {
+ Path p = new Path(filePath);
+ // get the file path transformed to work on local OS (e.g. Windows)
+ filePath = getTransformedPathString(p);
+ File f = new File(filePath).getAbsoluteFile();
+ String filename = f.getName();
+ if (f.isFile() && f.canRead()) {
+ FileInputStream fis = new FileInputStream(f);
+ InputStream inputStream = new BufferedInputStream(fis);
+ return new DataInputStream(inputStream);
+ } else {
+ String postfix = ""; //$NON-NLS-1$
+ File dir = null;
+ do {
+ if (postfix.isEmpty()) {
+ postfix = f.getName();
+ } else {
+ postfix = f.getName() + File.separator + postfix;
+ }
+ f = f.getParentFile();
+ if (f != null) {
+ dir = sourcePath.get(f);
+ } else {
+ break;
+ }
+ } while (dir == null);
+
+ if (dir != null) {
+ f = new File(dir, postfix);
+ if (f.isFile() && f.canRead()) {
+ return openTraceFileStream(f.getAbsolutePath(), extension, sourcePath);
+ }
+ }
+
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ FileDialog fg = new FileDialog(shell, SWT.OPEN);
+ fg.setFilterExtensions(new String[] { "*" + extension, "*.*", "*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ fg.setFileName(filename);
+ fg.setText(NLS.bind(Messages.CovManager_No_FilePath_Error, new Object[] { filePath, filename }));
+ String s = fg.open();
+ if (s == null) {
+ return null;
+ } else {
+ f = new File(s).getAbsoluteFile();
+ addSourceLookup(sourcePath, f, new File(filePath).getAbsoluteFile());
+ if (f.isFile() && f.canRead()) {
+ FileInputStream fis = new FileInputStream(f);
+ InputStream inputStream = new BufferedInputStream(fis);
+ return new DataInputStream(inputStream);
+ }
+ }
+ }
+ return null;
}
public ArrayList<SourceFile> getAllSrcs() {

Back to the top