diff options
author | Chris Recoskie | 2011-03-09 02:24:52 +0000 |
---|---|---|
committer | Chris Recoskie | 2011-03-09 02:24:52 +0000 |
commit | 71900424e1b0fceb8fdae6b0d839d2c9f1c357fb (patch) | |
tree | 9cd414155154ccc0e417eca6e35aaff4f2e49383 /build/org.eclipse.cdt.managedbuilder.core | |
parent | e170d35e583e32f41bb33c5a26992500103a6d67 (diff) | |
download | org.eclipse.cdt-71900424e1b0fceb8fdae6b0d839d2c9f1c357fb.tar.gz org.eclipse.cdt-71900424e1b0fceb8fdae6b0d839d2c9f1c357fb.tar.xz org.eclipse.cdt-71900424e1b0fceb8fdae6b0d839d2c9f1c357fb.zip |
Bug 279633 - Add ability to override command-generation for a build-option
Diffstat (limited to 'build/org.eclipse.cdt.managedbuilder.core')
6 files changed, 121 insertions, 1 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd index 0c716456daf..d007f51e9bd 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd +++ b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd @@ -1341,6 +1341,16 @@ Additional special types exist to flag options of special relevance to the build </documentation> </annotation> </attribute> + <attribute name="commandGenerator" type="string"> + <annotation> + <documentation> + Optional class which can be used to override the default command-generation logic for an option. This class must impelment the IOptionCommandGenerator interface. If no generator is specified then the 'comand' attribute is used to generate the option's command. + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn=":org.eclipse.cdt.managedbuilder.core.IOptionCommandGenerator"/> + </appInfo> + </annotation> + </attribute> <attribute name="commandFalse" type="string"> <annotation> <documentation> diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOption.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOption.java index 98605b465ae..49e60826091 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOption.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOption.java @@ -10,6 +10,7 @@ * ARM Ltd. - basic tooltip support * James Blackburn (Broadcom Corp.) * Petri Tuononen - [321040] Get Library Search Paths + * Baltasar Belyavsky (Texas Instruments) - [279633] Custom command-generator support *******************************************************************************/ package org.eclipse.cdt.managedbuilder.core; @@ -85,6 +86,8 @@ public interface IOption extends IBuildObject { public static final String CATEGORY = "category"; //$NON-NLS-1$ public static final String COMMAND = "command"; //$NON-NLS-1$ public static final String COMMAND_FALSE = "commandFalse"; //$NON-NLS-1$ + /** @since 8.0 */ + public static final String COMMAND_GENERATOR = "commandGenerator"; //$NON-NLS-1$ public static final String TOOL_TIP = "tip"; //$NON-NLS-1$ public static final String CONTEXT_ID = "contextId"; //$NON-NLS-1$ public static final String DEFAULT_VALUE = "defaultValue"; //$NON-NLS-1$ @@ -247,6 +250,12 @@ public interface IOption extends IBuildObject { public String getCommand(); /** + * @return an instance of the class that overrides the default command generation for the option + * @since 8.0 + */ + public IOptionCommandGenerator getCommandGenerator(); + + /** * Sets a <code>String</code> containing the actual command line * option associated with the option * diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionCommandGenerator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionCommandGenerator.java new file mode 100644 index 00000000000..da2d6f993bd --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionCommandGenerator.java @@ -0,0 +1,38 @@ +/***************************************************************** + * Copyright (c) 2010, 2011 Texas Instruments and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Texas Instruments - Initial API and implementation + *****************************************************************/ + +package org.eclipse.cdt.managedbuilder.core; + +import org.eclipse.cdt.utils.cdtvariables.IVariableSubstitutor; + + +/** + * This interface can be implemented by clients to contribute custom command-generator + * for a build-option. + * + * The custom command-generator class should be referenced in the <option>/commandGenerator + * attribute of the org.eclipse.cdt.managedbuilder.core.buildDefinitions extension-point. + * + * @since 8.0 + */ +public interface IOptionCommandGenerator +{ + /** + * Generate the command for the given option. + * + * @param option the underlying build-option + * @param macroSubstitutor to be used for expanding macros in option's value + * @return the generated build-option command. May return {@code null} to fall + * back to the default command generation logic. + */ + String generateCommand(IOption option, IVariableSubstitutor macroSubstitutor); + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java index 8bd67325653..58581915a80 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java @@ -9,6 +9,7 @@ * IBM - Initial API and implementation * ARM Ltd. - basic tooltip support * Petri Tuononen - [321040] Get Library Search Paths + * Baltasar Belyavsky (Texas Instruments) - [279633] Custom command-generator support *******************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.core; @@ -29,6 +30,7 @@ import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOptionApplicability; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; +import org.eclipse.cdt.managedbuilder.core.IOptionCommandGenerator; import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.IToolChain; @@ -63,6 +65,8 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest private IOptionCategory category; private String categoryId; private String command; + private IConfigurationElement commandGeneratorElement; + private IOptionCommandGenerator commandGenerator; private String commandFalse; private String tip; private String contextId; @@ -277,6 +281,10 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest } category = option.category; + + commandGeneratorElement = option.commandGeneratorElement; + commandGenerator = option.commandGenerator; + applicabilityCalculatorElement = option.applicabilityCalculatorElement; applicabilityCalculator = option.applicabilityCalculator; @@ -333,6 +341,12 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest // Get the command defined for the option command = element.getAttribute(COMMAND); + // Get the command-generator, if any + String commandGeneratorStr = element.getAttribute(COMMAND_GENERATOR); + if (commandGeneratorStr != null && element instanceof DefaultManagedConfigElement) { + commandGeneratorElement = ((DefaultManagedConfigElement)element).getConfigurationElement(); + } + // Get the command defined for a Boolean option when the value is False commandFalse = element.getAttribute(COMMAND_FALSE); @@ -1180,6 +1194,29 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest } /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IOption#getCommandGenerator() + */ + public IOptionCommandGenerator getCommandGenerator() { + if (commandGenerator == null) { + if (commandGeneratorElement != null) { + try { + if (commandGeneratorElement.getAttribute(COMMAND_GENERATOR) != null) { + commandGenerator = (IOptionCommandGenerator) commandGeneratorElement + .createExecutableExtension(COMMAND_GENERATOR); + } + } catch (CoreException e) { + ManagedBuilderCorePlugin.log(e); + } + } + else if(superClass != null) { + commandGenerator = superClass.getCommandGenerator(); + } + } + + return commandGenerator; + } + + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IOption#getCommandFalse() */ public String getCommandFalse() { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionReference.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionReference.java index 44b4d2a4edb..b53ab702426 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionReference.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionReference.java @@ -9,6 +9,7 @@ * IBM - Initial API and implementation * ARM Ltd. - basic tooltip support * Petri Tuononen - [321040] Get Library Search Paths + * Baltasar Belyavsky (Texas Instruments) - [279633] Custom command-generator support *******************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.core; @@ -23,6 +24,7 @@ import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOptionApplicability; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; +import org.eclipse.cdt.managedbuilder.core.IOptionCommandGenerator; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.OptionStringValue; import org.eclipse.cdt.managedbuilder.macros.IOptionContextData; @@ -312,6 +314,13 @@ public class OptionReference implements IOption { } /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IOption#getCommandGenerator() + */ + public IOptionCommandGenerator getCommandGenerator() { + return option.getCommandGenerator(); + } + + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IOption#getCommandFalse() */ public String getCommandFalse() { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java index e60e3092dc2..63f89c42cab 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2010 IBM Corporation and others. + * Copyright (c) 2003, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Baltasar Belyavsky (Texas Instruments) - [279633] Custom option command-generator support *******************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.core; @@ -47,6 +48,7 @@ import org.eclipse.cdt.managedbuilder.core.IManagedProject; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOptionApplicability; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; +import org.eclipse.cdt.managedbuilder.core.IOptionCommandGenerator; import org.eclipse.cdt.managedbuilder.core.IOptionPathConverter; import org.eclipse.cdt.managedbuilder.core.IOutputType; import org.eclipse.cdt.managedbuilder.core.IProjectType; @@ -2529,6 +2531,20 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory, IMatch } try{ + boolean generateDefaultCommand = true; + IOptionCommandGenerator commandGenerator = option.getCommandGenerator(); + if(commandGenerator != null) { + IMacroContextInfo info = provider.getMacroContextInfo(BuildMacroProvider.CONTEXT_FILE, new FileContextData(inputFileLocation, outputFileLocation, option, this)); + if(info != null) { + macroSubstitutor.setMacroContextInfo(info); + String command = commandGenerator.generateCommand(option, macroSubstitutor); + if(command != null) { + sb.append(command); + generateDefaultCommand = false; + } + } + } + if(generateDefaultCommand) { switch (option.getValueType()) { case IOption.BOOLEAN : String boolCmd; @@ -2612,6 +2628,7 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory, IMatch default : break; } + } if (sb.toString().trim().length() > 0) flags.add(sb.toString().trim()); |