From 493763bbcd8f6a7ccbc48c5ad4f27b98d68462d3 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 1 Dec 2008 09:59:31 +0000 Subject: Added tool options parser. Removed obsolete properties and preferences. --- .../org/rtems/cdt/Activator.java | 1 - .../org/rtems/cdt/Constants.java | 40 ++------- .../org/rtems/cdt/Storage.java | 95 ++++++++++++++++++++-- .../org/rtems/cdt/build/CommandLineGenerator.java | 35 ++++---- .../rtems/cdt/build/RunScannerInfoProvider.java | 5 +- .../cdt/preferences/PreferenceInitializer.java | 2 - .../org/rtems/cdt/preferences/PreferencePage.java | 17 +--- .../org/rtems/cdt/properties/PropertyPage.java | 27 +----- 8 files changed, 123 insertions(+), 99 deletions(-) diff --git a/org.rtems.cdt.toolchain2/org/rtems/cdt/Activator.java b/org.rtems.cdt.toolchain2/org/rtems/cdt/Activator.java index 3376ca1..e04a028 100644 --- a/org.rtems.cdt.toolchain2/org/rtems/cdt/Activator.java +++ b/org.rtems.cdt.toolchain2/org/rtems/cdt/Activator.java @@ -51,7 +51,6 @@ public class Activator extends AbstractUIPlugin { "include $(RTEMS_MAKEFILE_PATH)/Makefile.inc\n" + "include $(RTEMS_CUSTOM)\n" + "include $(PROJECT_ROOT)/make/leaf.cfg\n" - + "\n" + "all:\n" + "\t@echo " + Constants.TOOL_ARCHIVER_KEY + "\n" + "\t@for i in $(AR) ; do printf \"\\t%s\\n\" \"$$i\" ; done\n" diff --git a/org.rtems.cdt.toolchain2/org/rtems/cdt/Constants.java b/org.rtems.cdt.toolchain2/org/rtems/cdt/Constants.java index f18093b..afb7bc1 100644 --- a/org.rtems.cdt.toolchain2/org/rtems/cdt/Constants.java +++ b/org.rtems.cdt.toolchain2/org/rtems/cdt/Constants.java @@ -13,42 +13,16 @@ package org.rtems.cdt; public class Constants { - public static final String [][] TARGETS = { - {"ARM", "arm"}, - {"AVR", "avr"}, - {"Blackfin", "bfin"}, - {"Hitachi H8300", "h8300"}, - {"Intel i386", "i386"}, - {"Intel i686", "i686"}, - {"MIPS", "mips"}, - {"Motorola 68k or Freescale ColdFire", "m68k"}, - {"PowerPC", "powerpc"}, - {"SPARC", "sparc"}, - {"SuperH", "sh"} - }; - public static final String PATH_SEPERATOR = System.getProperty( "path.separator"); public static final String DEFAULT_BASE_PATH = "/opt/rtems-4.9"; - public static final String DEFAULT_VERSION = "4.9"; - - public static final int DEFAULT_TARGET_INDEX = 8; - - public static final String DEFAULT_TARGET_NAME = TARGETS [DEFAULT_TARGET_INDEX][0]; - - public static final String DEFAULT_TARGET = TARGETS [DEFAULT_TARGET_INDEX][1]; - public static final String DEFAULT_BSP_PATH = "/opt/rtems-4.9/powerpc-rtems4.9/psim"; - public static final String KEY_PREFIX = "org.rtems.cdt.key"; + public static final String KEY_PREFIX = "org.rtems.cdt"; public static final String BASE_PATH_KEY = KEY_PREFIX + ".basePath"; - public static final String VERSION_KEY = KEY_PREFIX + ".version"; - - public static final String TARGET_KEY = KEY_PREFIX + ".target"; - public static final String BSP_PATH_KEY = KEY_PREFIX + ".bspPath"; public static final String TOOL_KEY_PREFIX = KEY_PREFIX + ".tool"; @@ -57,13 +31,17 @@ public class Constants { public static final String TOOL_ASSEMBLER_KEY = TOOL_KEY_PREFIX + ".assembler"; - public static final String TOOL_COMPILER_C_KEY = TOOL_KEY_PREFIX + ".compiler.c"; + public static final String COMPILER_KEY_PREFIX = TOOL_KEY_PREFIX + ".compiler"; + + public static final String TOOL_COMPILER_C_KEY = COMPILER_KEY_PREFIX + ".c"; + + public static final String TOOL_COMPILER_CPP_KEY = COMPILER_KEY_PREFIX + ".cpp"; - public static final String TOOL_COMPILER_CPP_KEY = TOOL_KEY_PREFIX + ".compiler.cpp"; + public static final String LINKER_KEY_PREFIX = TOOL_KEY_PREFIX + ".linker"; - public static final String TOOL_LINKER_C_KEY = TOOL_KEY_PREFIX + ".linker.c"; + public static final String TOOL_LINKER_C_KEY = LINKER_KEY_PREFIX + ".c"; - public static final String TOOL_LINKER_CPP_KEY = TOOL_KEY_PREFIX + ".linker.cpp"; + public static final String TOOL_LINKER_CPP_KEY = LINKER_KEY_PREFIX + ".cpp"; public static final String TOOL_OPTIONS_KEY_POSTFIX = ".options"; diff --git a/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java b/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java index 6fce4fe..1cd3818 100644 --- a/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java +++ b/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java @@ -16,6 +16,8 @@ import java.io.BufferedReader; 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.core.resources.IProject; @@ -26,6 +28,18 @@ import org.eclipse.core.runtime.QualifiedName; import org.rtems.cdt.Activator; public class Storage { + private static final String OPTION_SEPARATOR = "\0"; + + private static final String VALUE_START_TOKEN = "\t"; + + private static final int EXPECT_OPTION = 0; + + private static final int EXPECT_COMMAND = 1; + + private static final int EXPECT_KEY = 2; + + private static final int TOOL_COMPLETE = 3; + ; public static String getPristineProperty( IProject project, String key) { String value = null; @@ -43,7 +57,7 @@ public class Storage { if (value == null) { if (key.startsWith( Constants.TOOL_KEY_PREFIX)) { - reloadBSPInformation( project); + updateTools( project); } else { value = Activator.getDefault().getPreferenceStore().getString( key); setProperty( project, key, value); @@ -61,7 +75,7 @@ public class Storage { } } - public static void reloadBSPInformation( IProject project) { + public static void updateTools( IProject project) { // Create make process builder ProcessBuilder pb = new ProcessBuilder( "make"); @@ -77,19 +91,88 @@ public class Storage { pb.directory( Activator.getDefault().getMakefileLocation().toFile()); // Start make process and parse its output + Process p = null; try { - Process p = pb.start(); + p = pb.start(); InputStream is = p.getInputStream(); BufferedReader br = new BufferedReader( new InputStreamReader( is)); - String line; - while ((line = br.readLine()) != null) { - System.out.println(line); + String line = br.readLine(); + String key = null; + String command = null; + List options = new LinkedList(); + int state = EXPECT_KEY; + while (line != null) { + switch (state) { + case EXPECT_OPTION: + if (line.startsWith( VALUE_START_TOKEN)) { + options.add( line.substring( 1)); + } else { + state = TOOL_COMPLETE; + continue; + } + break; + case EXPECT_COMMAND: + if (line.startsWith( VALUE_START_TOKEN)) { + command = line.substring( 1); + state = EXPECT_OPTION; + } else { + throw new IOException( "Unexpected line format"); + } + break; + case EXPECT_KEY: + if (line.length() > Constants.TOOL_KEY_PREFIX.length()) { + key = line; + state = EXPECT_COMMAND; + } else { + throw new IOException( "Unexpected line format"); + } + break; + case TOOL_COMPLETE: + updateTool( project, key, command, options); + options.clear(); + state = EXPECT_KEY; + continue; + default: + throw new IOException( "Unexpected state"); + } + line = br.readLine(); + } + if (state == EXPECT_OPTION) { + updateTool( project, key, command, options); } } catch (IOException e) { e.printStackTrace(); + } finally { + while (true) { + try { + p.waitFor(); + break; + } catch (InterruptedException e) { + continue; + } + } } } + private static void updateTool( IProject project, String toolKey, String command, List options) { + String optionsValue = new String(); + if (!options.isEmpty()) { + optionsValue = options.get( 0); + options.remove( 0); + } + for (String option : options) { + optionsValue += OPTION_SEPARATOR + option; + } + setProperty( project, toolKey, command); + setProperty( project, toolKey + Constants.TOOL_OPTIONS_KEY_POSTFIX, optionsValue); + } + + public static String [] getToolOptions( IProject project, String toolKey) { + String optionsValue = getProperty( project, toolKey + Constants.TOOL_OPTIONS_KEY_POSTFIX); + + return optionsValue.split( OPTION_SEPARATOR); + } + private Storage() { // Do nothing } diff --git a/org.rtems.cdt.toolchain2/org/rtems/cdt/build/CommandLineGenerator.java b/org.rtems.cdt.toolchain2/org/rtems/cdt/build/CommandLineGenerator.java index 4147e61..fbe7420 100644 --- a/org.rtems.cdt.toolchain2/org/rtems/cdt/build/CommandLineGenerator.java +++ b/org.rtems.cdt.toolchain2/org/rtems/cdt/build/CommandLineGenerator.java @@ -24,7 +24,7 @@ public class CommandLineGenerator extends ManagedCommandLineGenerator implements public IManagedCommandLineInfo generateCommandLineInfo( ITool tool, String commandName, - String [] flags, + String [] userOptions, String outputFlag, String outputPrefix, String outputName, @@ -34,32 +34,37 @@ public class CommandLineGenerator extends ManagedCommandLineGenerator implements // Get associated project of the tool IProject project = (IProject) tool.getParentResourceInfo().getParent().getOwner(); - // Determine main command name via the tool ID + // Determine tool key via the tool ID String id = tool.getId(); - String name = "-gcc"; + String toolKey = "gcc"; if (id.contains( "archiver")) { - name = "-ar"; + toolKey = Constants.TOOL_ARCHIVER_KEY; } else if (id.contains( "assembler")) { - name = "-as"; + toolKey = Constants.TOOL_ASSEMBLER_KEY; + } else if (id.contains( "c.compiler")) { + toolKey = Constants.TOOL_COMPILER_C_KEY; } else if (id.contains( "cpp.compiler")) { - name = "-g++"; + toolKey = Constants.TOOL_COMPILER_CPP_KEY; + } else if (id.contains( "c.linker")) { + toolKey = Constants.TOOL_LINKER_C_KEY; } else if (id.contains( "cpp.linker")) { - name = "-g++"; + toolKey = Constants.TOOL_LINKER_CPP_KEY; } - // Create and set command name - commandName = new String( - Storage.getProperty( project, Constants.TARGET_KEY) - + "-rtems" - + Storage.getProperty( project, Constants.VERSION_KEY) - + name - ); + // Set command name + commandName = Storage.getProperty( project, toolKey); tool.setToolCommand( commandName); + + // Combine tool and user options + String [] toolOptions = Storage.getToolOptions( project, toolKey); + String options [] = new String [toolOptions.length + userOptions.length]; + System.arraycopy( toolOptions, 0, options, 0, toolOptions.length); + System.arraycopy( userOptions, 0, options, toolOptions.length, userOptions.length); return super.generateCommandLineInfo( tool, commandName, - flags, + options, outputFlag, outputPrefix, outputName, diff --git a/org.rtems.cdt.toolchain2/org/rtems/cdt/build/RunScannerInfoProvider.java b/org.rtems.cdt.toolchain2/org/rtems/cdt/build/RunScannerInfoProvider.java index 44adf9d..099ab8b 100644 --- a/org.rtems.cdt.toolchain2/org/rtems/cdt/build/RunScannerInfoProvider.java +++ b/org.rtems.cdt.toolchain2/org/rtems/cdt/build/RunScannerInfoProvider.java @@ -51,10 +51,7 @@ public class RunScannerInfoProvider extends GCCSpecsRunSIProvider { ); fCompileCommand = fCompileCommand.append( "bin"); fCompileCommand = fCompileCommand.append( - Storage.getProperty( project, Constants.TARGET_KEY) - + "-rtems" - + Storage.getProperty( project, Constants.VERSION_KEY) - + "-gcc" + Storage.getProperty( project, Constants.TOOL_COMPILER_C_KEY) ); return true; diff --git a/org.rtems.cdt.toolchain2/org/rtems/cdt/preferences/PreferenceInitializer.java b/org.rtems.cdt.toolchain2/org/rtems/cdt/preferences/PreferenceInitializer.java index 0214d46..19d9232 100644 --- a/org.rtems.cdt.toolchain2/org/rtems/cdt/preferences/PreferenceInitializer.java +++ b/org.rtems.cdt.toolchain2/org/rtems/cdt/preferences/PreferenceInitializer.java @@ -21,8 +21,6 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer { public void initializeDefaultPreferences() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); store.setDefault( Constants.BASE_PATH_KEY, Constants.DEFAULT_BASE_PATH); - store.setDefault( Constants.VERSION_KEY, Constants.DEFAULT_VERSION); - store.setDefault( Constants.TARGET_KEY, Constants.DEFAULT_TARGET); store.setDefault( Constants.BSP_PATH_KEY, Constants.DEFAULT_BSP_PATH); } } diff --git a/org.rtems.cdt.toolchain2/org/rtems/cdt/preferences/PreferencePage.java b/org.rtems.cdt.toolchain2/org/rtems/cdt/preferences/PreferencePage.java index edf8580..9848a5d 100644 --- a/org.rtems.cdt.toolchain2/org/rtems/cdt/preferences/PreferencePage.java +++ b/org.rtems.cdt.toolchain2/org/rtems/cdt/preferences/PreferencePage.java @@ -24,7 +24,7 @@ public class PreferencePage public PreferencePage() { super( GRID); setPreferenceStore( Activator.getDefault().getPreferenceStore()); - setDescription( "Select the RTEMS base installation path, the RTEMS version, the target architecture and the board support package (BSP) installation path. This provides the default values for new projects."); + setDescription( "Select the RTEMS base installation path and the board support package (BSP) installation path. This provides the default values for all projects."); } public void createFieldEditors() { @@ -34,21 +34,6 @@ public class PreferencePage "Base path:", getFieldEditorParent() ) - ); - addField( - new StringFieldEditor( - Constants.VERSION_KEY, - "Version:", - getFieldEditorParent() - ) - ); - addField( - new ComboFieldEditor( - Constants.TARGET_KEY, - "Target:", - Constants.TARGETS, - getFieldEditorParent() - ) ); addField( new DirectoryFieldEditor( diff --git a/org.rtems.cdt.toolchain2/org/rtems/cdt/properties/PropertyPage.java b/org.rtems.cdt.toolchain2/org/rtems/cdt/properties/PropertyPage.java index e6973ce..11b5018 100644 --- a/org.rtems.cdt.toolchain2/org/rtems/cdt/properties/PropertyPage.java +++ b/org.rtems.cdt.toolchain2/org/rtems/cdt/properties/PropertyPage.java @@ -16,10 +16,8 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.preference.DirectoryFieldEditor; -import org.eclipse.jface.preference.ComboFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.StringFieldEditor; import org.eclipse.ui.IWorkbenchPropertyPage; import org.eclipse.cdt.core.model.ICElement; import org.rtems.cdt.Activator; @@ -41,7 +39,7 @@ public class PropertyPage extends FieldEditorPreferencePage implements IWorkbenc mStore = new VolatilePreferenceStore(); setPreferenceStore( mStore); - setDescription( "You can change the RTEMS base installation path, the RTEMS version, the target architecture and the board support package (BSP) installation path. This affects only the current project."); + setDescription( "You can change the RTEMS base installation path and the board support package (BSP) installation path. This affects only the current project."); } private void setupStoreValue( IPreferenceStore defaultStore, String key) { @@ -61,8 +59,6 @@ public class PropertyPage extends FieldEditorPreferencePage implements IWorkbenc // Setup store values setupStoreValue( store, Constants.BASE_PATH_KEY); - setupStoreValue( store, Constants.VERSION_KEY); - setupStoreValue( store, Constants.TARGET_KEY); setupStoreValue( store, Constants.BSP_PATH_KEY); // Add field editors @@ -72,21 +68,6 @@ public class PropertyPage extends FieldEditorPreferencePage implements IWorkbenc "Base path:", getFieldEditorParent() ) - ); - addField( - new StringFieldEditor( - Constants.VERSION_KEY, - "Version:", - getFieldEditorParent() - ) - ); - addField( - new ComboFieldEditor( - Constants.TARGET_KEY, - "Target:", - Constants.TARGETS, - getFieldEditorParent() - ) ); addField( new DirectoryFieldEditor( @@ -106,12 +87,10 @@ public class PropertyPage extends FieldEditorPreferencePage implements IWorkbenc // Set the new properties setProperty( Constants.BASE_PATH_KEY); - setProperty( Constants.VERSION_KEY); - setProperty( Constants.TARGET_KEY); setProperty( Constants.BSP_PATH_KEY); - // Reload BSP information - Storage.reloadBSPInformation( mProject); + // Update tools + Storage.updateTools( mProject); return true; } -- cgit v1.2.3