Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-debug-dev] Translating cross compiled paths

CDT encounters paths that are a result of cross compiles.

One troublesome example is CygWin cross compilers under Windows.

I'm experimenting with a scheme where I have defined a static method in
a new class org.eclipse.cdt.core.utils.path which creates an instance of
a platform specific class(much like SWT)
org.eclipse.cdt.core.utils.path.PlatformPathGuesser, which tries to
guess the absolute paths based upon the cribs given in e.g. .elf
binaries.

The Windows implementation will be quite convoluted(surprise!) whereas
the Linux version could be quite simple(who in their right mind would
cross compile from Windows to Linux :-)

Attached are some sketchy changes that should communicate the gist of
what I'm trying to do.

Comments?


This is how I create the platform specific version of
PlatformPathGuesser.


+		PathGuesser g;
+		try {
+			g =
(PathGuesser)Class.forName("org.eclipse.cdt.utils.path.PlatformPathGuesser").newInstance();
+		} catch (Throwable  e) {
+			throw new RuntimeException(e);
+		}
+		return g.guess(base, path);



-- 
Øyvind Harboe
http://www.zylin.com

Index: src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/DefaultGnuWinScannerInfoCollector.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/DefaultGnuWinScannerInfoCollector.java,v
retrieving revision 1.1
diff -u -r1.1 DefaultGnuWinScannerInfoCollector.java
--- src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/DefaultGnuWinScannerInfoCollector.java	2 Jun 2004 14:30:28 -0000	1.1
+++ src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/DefaultGnuWinScannerInfoCollector.java	4 Aug 2004 14:43:50 -0000
@@ -14,7 +14,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.eclipse.cdt.make.internal.core.scannerconfig.util.CygpathTranslator;
+import org.eclipse.cdt.utils.path.PathTranslator;
 import org.eclipse.core.resources.IResource;
 
 /**
@@ -62,8 +62,8 @@
 	 */
 	private String convertPath(String includePath) {
 		// Convert a POSIX-style path to Win32
-		String translatedPath = new CygpathTranslator(project, includePath).run();
-		return translatedPath;
+		return PathTranslator.guessAbsolutePath(project.getLocation().toFile().getAbsolutePath(),
+				includePath);
 	}
 
 }
Index: src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoCollector.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoCollector.java,v
retrieving revision 1.14
diff -u -r1.14 ScannerInfoCollector.java
--- src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoCollector.java	29 Jul 2004 13:04:34 -0000	1.14
+++ src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoCollector.java	4 Aug 2004 14:44:01 -0000
@@ -28,8 +28,8 @@
 import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigUtil;
 import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo;
 import org.eclipse.cdt.make.internal.core.MakeMessages;
-import org.eclipse.cdt.make.internal.core.scannerconfig.util.CygpathTranslator;
 import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
+import org.eclipse.cdt.utils.path.PathTranslator;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
@@ -296,9 +296,8 @@
 			IPath realPath = new Path(includePath);
 			if (!realPath.toFile().exists()) {
 				String translatedPath = includePath;
-				if (Platform.getOS().equals(Platform.OS_WIN32)) {
-					translatedPath = new CygpathTranslator(currentProject, includePath).run();
-				}
+				translatedPath = PathTranslator.guessAbsolutePath(currentProject.getLocation().toFile().getAbsolutePath(), 
+						includePath);
 				if (translatedPath != null) {
 					if (!translatedPath.equals(includePath)) {
 						// Check if the translated path exists
Index: src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java
===================================================================
RCS file: src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java
diff -N src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java
--- src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java	18 May 2004 16:06:30 -0000	1.3
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,114 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- * 
- * Contributors: 
- * IBM - Initial API and implementation
- **********************************************************************/
-package org.eclipse.cdt.make.internal.core.scannerconfig.util;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import org.eclipse.cdt.core.CommandLauncher;
-import org.eclipse.cdt.make.core.MakeCorePlugin;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.ISafeRunnable;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-
-/**
- * Executes external command 'cygpath' to translate cygpaths to absolute paths.
- * 
- * @author vhirsl
- */
-public class CygpathTranslator {
-	IProject project;
-	private String orgPath;
-	private String transPath;
-
-	public CygpathTranslator(IProject project, String path) {
-		this.project = project;
-		orgPath = path;
-	}
-	
-	public String run() {
-		ISafeRunnable runnable = new ISafeRunnable() {
-			public void run() throws Exception {
-				transPath = platformRun();
-				if (transPath.startsWith("cygpath:")) {	//$NON-NLS-1$
-					transPath = null;
-				}
-			}
-
-			public void handleException(Throwable exception) {
-				transPath = orgPath;
-				MakeCorePlugin.log(exception);
-			}
-		};
-		Platform.run(runnable);
-		return transPath;
-	}
-
-	/**
-	 * @return
-	 */
-	private String platformRun() {
-		CommandLauncher launcher = new CommandLauncher();
-		launcher.showCommand(false);
-
-		OutputStream output = new ByteArrayOutputStream();
-
-		Process p = launcher.execute(
-			new Path("cygpath"),			//$NON-NLS-1$
-			new String[] {"-m", orgPath},	//$NON-NLS-1$
-			new String[0],//setEnvironment(launcher, "c:/"),//$NON-NLS-1$
-			project.getLocation());				//$NON-NLS-1$
-		if (p != null) {
-			try {
-				// Close the input of the Process explicitely.
-				// We will never write to it.
-				p.getOutputStream().close();
-			}
-			catch (IOException e) {
-			}
-			if (launcher.waitAndRead(output, output) != CommandLauncher.OK) {
-				//String errMsg = launcher.getErrorMessage();
-			}
-			else
-				return output.toString().trim();
-		}
-		return orgPath;
-	}
-
-	/**
-	 * @param launcher
-	 * @return
-	 */
-	private String[] setEnvironment(CommandLauncher launcher, String dir) {
-		// Set the environmennt, some scripts may need the CWD var to be set.
-		IPath workingDirectory = new Path(dir);
-		Properties props = launcher.getEnvironment();
-		props.put("CWD", workingDirectory.toOSString()); //$NON-NLS-1$
-		props.put("PWD", workingDirectory.toOSString()); //$NON-NLS-1$
-		String[] env = null;
-		ArrayList envList = new ArrayList();
-		Enumeration names = props.propertyNames();
-		if (names != null) {
-			while (names.hasMoreElements()) {
-				String key = (String) names.nextElement();
-				envList.add(key + "=" + props.getProperty(key)); //$NON-NLS-1$
-			}
-			env = (String[]) envList.toArray(new String[envList.size()]);
-		}
-		return env;
-	}
-}
Index: MIFrame.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/MIFrame.java,v
retrieving revision 1.3
diff -u -r1.3 MIFrame.java
--- MIFrame.java	25 Jun 2004 14:46:48 -0000	1.3
+++ MIFrame.java	4 Aug 2004 14:44:37 -0000
@@ -10,6 +10,10 @@
  *******************************************************************************/
 package org.eclipse.cdt.debug.mi.core.output;
 
+import java.io.File;
+
+import org.eclipse.cdt.utils.path.PathTranslator;
+
 /**
  * GDB/MI Frame tuple parsing.
  */
@@ -31,7 +35,7 @@
 	}
 
 	public String getFile() {
-		return file;
+		return PathTranslator.guessAbsolutePath(new File(".").getAbsolutePath(), file);
 	}
 
 	public String getFunction() {
Index: src/org/eclipse/cdt/utils/path/CygpathTranslator.java
===================================================================
RCS file: src/org/eclipse/cdt/utils/path/CygpathTranslator.java
diff -N src/org/eclipse/cdt/utils/path/CygpathTranslator.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/utils/path/CygpathTranslator.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,113 @@
+/**********************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ * 
+ * Contributors: 
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.utils.path;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.eclipse.cdt.core.CommandLauncher;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+
+/**
+ * Executes external command 'cygpath' to translate cygpaths to absolute paths.
+ * 
+ * @author vhirsl
+ */
+class CygpathTranslator {
+	IPath baseDir;
+	private String orgPath;
+	private String transPath;
+
+	public CygpathTranslator(IPath baseDir, String path) {
+		this.baseDir = baseDir;
+		orgPath = path;
+	}
+	
+	public String run() {
+		ISafeRunnable runnable = new ISafeRunnable() {
+			public void run() throws Exception {
+				transPath = platformRun();
+				if (transPath.startsWith("cygpath:")) {	//$NON-NLS-1$
+					transPath = null;
+				}
+			}
+
+			public void handleException(Throwable exception) {
+				transPath = orgPath;
+				// FIX!!!!
+				//MakeCorePlugin.log(exception);
+			}
+		};
+		Platform.run(runnable);
+		return transPath;
+	}
+
+	/**
+	 * @return
+	 */
+	private String platformRun() {
+		CommandLauncher launcher = new CommandLauncher();
+		launcher.showCommand(false);
+
+		OutputStream output = new ByteArrayOutputStream();
+
+		Process p = launcher.execute(
+			new Path("cygpath"),			//$NON-NLS-1$
+			new String[] {"-m", orgPath},	//$NON-NLS-1$
+			new String[0],//setEnvironment(launcher, "c:/"),//$NON-NLS-1$
+			baseDir);				//$NON-NLS-1$
+		if (p != null) {
+			try {
+				// Close the input of the Process explicitely.
+				// We will never write to it.
+				p.getOutputStream().close();
+			}
+			catch (IOException e) {
+			}
+			if (launcher.waitAndRead(output, output) != CommandLauncher.OK) {
+				//String errMsg = launcher.getErrorMessage();
+			}
+			else
+				return output.toString().trim();
+		}
+		return orgPath;
+	}
+
+	/**
+	 * @param launcher
+	 * @return
+	 */
+	private String[] setEnvironment(CommandLauncher launcher, String dir) {
+		// Set the environmennt, some scripts may need the CWD var to be set.
+		IPath workingDirectory = new Path(dir);
+		Properties props = launcher.getEnvironment();
+		props.put("CWD", workingDirectory.toOSString()); //$NON-NLS-1$
+		props.put("PWD", workingDirectory.toOSString()); //$NON-NLS-1$
+		String[] env = null;
+		ArrayList envList = new ArrayList();
+		Enumeration names = props.propertyNames();
+		if (names != null) {
+			while (names.hasMoreElements()) {
+				String key = (String) names.nextElement();
+				envList.add(key + "=" + props.getProperty(key)); //$NON-NLS-1$
+			}
+			env = (String[]) envList.toArray(new String[envList.size()]);
+		}
+		return env;
+	}
+}
Index: src/org/eclipse/cdt/utils/path/PlatformPathGuesser.java
===================================================================
RCS file: src/org/eclipse/cdt/utils/path/PlatformPathGuesser.java
diff -N src/org/eclipse/cdt/utils/path/PlatformPathGuesser.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/utils/path/PlatformPathGuesser.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,31 @@
+/*
+ * Created on Aug 4, 2004
+ *
+ */
+package org.eclipse.cdt.utils.path;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.Path;
+
+/**
+ * @author oharboe
+ *
+ */
+public class PlatformPathGuesser implements PathGuesser {
+
+	private String translatedPath;
+
+	public String guess(String base, String path)
+	{
+		File f=new File(new File(base), path);
+		if (f.exists())
+		{
+			return f.getAbsolutePath();
+		} else
+		{
+			String abs=new CygpathTranslator(new Path(base), path).run();
+			return abs;
+		}
+	}
+}
Index: src/org/eclipse/cdt/core/ErrorParserManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java,v
retrieving revision 1.21
diff -u -r1.21 ErrorParserManager.java
--- src/org/eclipse/cdt/core/ErrorParserManager.java	20 May 2004 04:11:24 -0000	1.21
+++ src/org/eclipse/cdt/core/ErrorParserManager.java	4 Aug 2004 14:45:11 -0000
@@ -16,6 +16,7 @@
 import java.util.Vector;
 
 import org.eclipse.cdt.core.resources.ACBuilder;
+import org.eclipse.cdt.utils.path.PathTranslator;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
@@ -25,6 +26,7 @@
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
 
+
 public class ErrorParserManager extends OutputStream {
 
 	private int nOpens;
@@ -247,6 +249,9 @@
 	 * Called by the error parsers.
 	 */
 	public IFile findFilePath(String filePath) {
+
+		filePath = PathTranslator.guessAbsolutePath(fBaseDirectory.toFile().getAbsolutePath(), filePath);
+		
 		IPath path = null;
 		IPath fp = new Path(filePath);
 		if (fp.isAbsolute()) {
Index: utils/org/eclipse/cdt/utils/path/PathGuesser.java
===================================================================
RCS file: utils/org/eclipse/cdt/utils/path/PathGuesser.java
diff -N utils/org/eclipse/cdt/utils/path/PathGuesser.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ utils/org/eclipse/cdt/utils/path/PathGuesser.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,18 @@
+/*
+ * Created on Aug 4, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.eclipse.cdt.utils.path;
+
+/**
+ * @author oharboe
+ *
+ */
+public interface PathGuesser {
+
+	
+	/** guess absolute path */
+	String guess(String base, String path);
+}
Index: utils/org/eclipse/cdt/utils/path/PathTranslator.java
===================================================================
RCS file: utils/org/eclipse/cdt/utils/path/PathTranslator.java
diff -N utils/org/eclipse/cdt/utils/path/PathTranslator.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ utils/org/eclipse/cdt/utils/path/PathTranslator.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,39 @@
+/*
+ * Created on Aug 4, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.eclipse.cdt.utils.path;
+
+/**
+ * @author oharboe
+ *
+ */
+public class PathTranslator {
+	
+	/** translates a relative(or absolute) path found in a persisted
+	 * file (e.g. .elf binary) that could possibly
+	 * originate in a semi-cross compiler like CygWin. 
+	 * 
+	 * The actual implementation is platform specific.
+	 * 
+	 */
+	public static String guessAbsolutePath(
+			/** this base is in native platform speak */
+			String base,
+			/** relative or absolute path. Could be in native speak, but might
+			 * be alien(e.g. CygWin on Windows or even Linux under Windows).
+			 */
+			String path) {
+		PathGuesser g;
+		try {
+			g = (PathGuesser)Class.forName("org.eclipse.cdt.utils.path.PlatformPathGuesser").newInstance();
+		} catch (Throwable  e) {
+			throw new RuntimeException(e);
+		}
+		return g.guess(base, path);
+		
+	}
+
+}

Back to the top