diff options
Diffstat (limited to 'org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java')
-rw-r--r-- | org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java | 140 |
1 files changed, 120 insertions, 20 deletions
diff --git a/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java b/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java index 5a4ae30..a1c2190 100644 --- a/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java +++ b/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java @@ -13,11 +13,13 @@ package org.rtems.cdt; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.List; +import java.util.Map; import org.eclipse.cdt.build.core.scannerconfig.CfgInfoContext; import org.eclipse.cdt.build.internal.core.scannerconfig.CfgDiscoveredPathManager; @@ -28,6 +30,8 @@ import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.QualifiedName; @@ -65,9 +69,9 @@ public class Storage { if (value == null) { if (key.startsWith( Constants.TOOL_KEY_PREFIX)) { - updateTools( project); + changePlatform( project, Constants.PLATFORM_DEFAULT); } else { - value = Activator.getDefault().getPreferenceStore().getString( key); + value = getPreference( key); setProperty( project, key, value); } } @@ -104,26 +108,130 @@ public class Storage { return cfg; } - public static void updateTools( IProject project) { - String path = getProperty( project, Constants.BSP_PATH_KEY); + public static String prependToPath( String path, String part) { + if (path == null || path.isEmpty()) { + return part; + } else { + return part + Constants.PATH_SEPARATOR + path; + } + } + + public static String prependToPathByPreference( String path, String key) { + String basePath = getPreference( key); + + if (basePath != null) { + IPath part = new Path( basePath).append( "bin"); + + return prependToPath( path, part.toOSString()); + } + + return path; + } + + public static String prependToPathByProperty( IProject project, String path, String key) { + String basePath = getProperty( project, key); + + if (basePath != null) { + IPath part = new Path( basePath).append( "bin"); + + return prependToPath( path, part.toOSString()); + } + + return path; + } + + public static void clearPlatform( IProject project) { + setProperty( project, Constants.PLATFORM_KEY, null); + + // Delete discovered paths for all configurations of the project + for (IConfiguration cfg : getConfigurations( project)) { + CfgDiscoveredPathManager.getInstance().removeDiscoveredInfo( + project, + new CfgInfoContext( cfg) + ); + } + } + + public static String getPlatform( IProject project) { + return getPristineProperty( project, Constants.PLATFORM_KEY); + } + + public static void changePlatform( IProject project, String newPlatform) { + String platform = getPlatform( project); + + // Check if we have already the requested platform + if (platform != null && platform == newPlatform) { + // Nothing to do + return; + } + + // Set new platform + setProperty( project, Constants.PLATFORM_KEY, newPlatform); + + // Update path prepends + String path = null; + if (Platform.getOS().equals( Platform.OS_WIN32)) { + if (newPlatform.equals( Constants.PLATFORM_CYGWIN)) { + path = prependToPathByPreference( path, Constants.CYGWIN_PATH_KEY); + } else { + path = prependToPathByPreference( path, Constants.MINGW_PATH_KEY); + path = prependToPathByPreference( path, Constants.MSYS_PATH_KEY); + } + } + path = prependToPathByProperty( project, path, Constants.BASE_PATH_KEY); + setProperty( project, Constants.PATH_PREPEND_KEY, path); + + // Update tools + updateTools( project, newPlatform); + } + + private static void updateTools( IProject project, String platform) { + String bspPath = getProperty( project, Constants.BSP_PATH_KEY); + IPath make = new Path( "make"); // Translate path if necessary if (Platform.getOS().equals( Platform.OS_WIN32)) { - // FIXME: MinGW? - - String device = path.split( ":") [0]; - path = path.replaceFirst( "^" + device + ":", "/cygdrive/" + device).replaceAll( "\\\\", "/"); + if (platform.equals( Constants.PLATFORM_CYGWIN)) { + String s [] = bspPath.split( ":"); + if (s.length > 0) { + bspPath = bspPath.replaceFirst( "^" + s [0] + ":", "/cygdrive/" + s [0]); + } + } + bspPath = bspPath.replaceAll( "\\\\", "/"); } // Create make process builder - ProcessBuilder pb = new ProcessBuilder( - "make", - Constants.BSP_PATH_MAKE_VARIABLE + "=" + path - ); + ProcessBuilder pb = new ProcessBuilder(); // Change working directory to the Makefile location pb.directory( Activator.getDefault().getMakefileLocation().toFile()); + // Update path environment variable + Map<String, String> env = pb.environment(); + String path = env.get( Constants.PATH_VARIABLE_NAME); + String part = getProperty( project, Constants.PATH_PREPEND_KEY); + path = Storage.prependToPath( path, part); + env.put( Constants.PATH_VARIABLE_NAME, path); + + // On windows we have to search for the make program in the new path environment + if (Platform.getOS().equals( Platform.OS_WIN32)) { + String parts [] = path.split( Constants.PATH_SEPARATOR); + for (String p : parts) { + IPath makeCandidate = new Path( p).append( "make.exe"); + File file = new File( makeCandidate.toOSString()); + if (file.exists()) { + make = makeCandidate; + break; + } + } + } + + // Set command line + pb.command( + make.toOSString(), + Constants.BSP_PATH_MAKE_VARIABLE + "=" + bspPath + ); + // Start make process and parse its output Process p = null; try { @@ -186,14 +294,6 @@ public class Storage { } } } - - // Delete discovered paths for all configurations of the project - for (IConfiguration cfg : getConfigurations( project)) { - CfgDiscoveredPathManager.getInstance().removeDiscoveredInfo( - project, - new CfgInfoContext( cfg) - ); - } } private static void updateTool( IProject project, String toolKey, String command, List<String> options) { |