diff options
author | Leo Treggiari | 2005-06-08 15:00:35 +0000 |
---|---|---|
committer | Leo Treggiari | 2005-06-08 15:00:35 +0000 |
commit | 1eb10a46a0557db040085203edd85b33f11279dd (patch) | |
tree | 54e39dc8a2a1c6463c3c87010f4f76881989b727 /build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse | |
parent | d3db562481176d203e083f9605c9d74cd55e06e6 (diff) | |
download | org.eclipse.cdt-1eb10a46a0557db040085203edd85b33f11279dd.tar.gz org.eclipse.cdt-1eb10a46a0557db040085203edd85b33f11279dd.tar.xz org.eclipse.cdt-1eb10a46a0557db040085203edd85b33f11279dd.zip |
Apply Bill Hilliard's patch for adding resource specific custom build steps
Diffstat (limited to 'build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse')
8 files changed, 546 insertions, 84 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java index a26ba57a70b..9ae489ba75f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java @@ -26,6 +26,16 @@ public interface IResourceConfiguration extends IBuildObject { public static final String RESOURCE_CONFIGURATION_ELEMENT_NAME = "resourceConfiguration"; //$NON-NLS-1$ public static final String RESOURCE_PATH = "resourcePath"; //$NON-NLS-1$ public static final String EXCLUDE = "exclude"; //$NON-NLS-1$ + public static final String RCBS_APPLICABILITY = "rcbsApplicability"; //$NON-NLS-1$ + public static final String TOOLS_TO_INVOKE = "toolsToInvoke"; //$NON-NLS-1$ + public static final String APPLY_RCBS_TOOL_AS_OVERRIDE = "override"; //$NON-NLS-1$ + public static final int KIND_APPLY_RCBS_TOOL_AS_OVERRIDE = 1; + public static final String APPLY_RCBS_TOOL_BEFORE = "before"; //$NON-NLS-1$ + public static final int KIND_APPLY_RCBS_TOOL_BEFORE = 2; + public static final String APPLY_RCBS_TOOL_AFTER = "after"; //$NON-NLS-1$ + public static final int KIND_APPLY_RCBS_TOOL_AFTER = 3; + public static final String DISABLE_RCBS_TOOL = "disable"; //$NON-NLS-1$ + public static final int KIND_DISABLE_RCBS_TOOL = 4; //TODO: Set name and ID in the constructors to be // configuration-name#resource-path @@ -55,6 +65,30 @@ public interface IResourceConfiguration extends IBuildObject { public String getResourcePath(); /** + * Returns an integer constant representing the users desire for ordering the application of + * a resource custom build step tool. + * + * @return int + */ + public int getRcbsApplicability(); + + /** + * Returns the list of tools currently defined for the project resource that + * this element references. Updates the String attribute toolsToInvoke. + * + * @return String + */ + public ITool[] getToolsToInvoke(); + + /** + * Sets the new value representing the users desire for ordering the application of + * a resource custom build step tool. + * + * @param int + */ + public void setRcbsApplicability(int value); + + /** * Sets the "excluded" flag for the resource. * If <code>true</code>, the project resource identified by the resoursePath * attribute is excluded from the build of the parent configuration. @@ -100,6 +134,13 @@ public interface IResourceConfiguration extends IBuildObject { public ITool getTool(String id); /** + * Removes the Tool from the Tool list and map + * + * @param Tool + */ + public void removeTool(ITool tool); + + /** * Creates a <code>Tool</code> child for this resource configuration. * * @param ITool The superClass, if any diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuilderCorePlugin.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuilderCorePlugin.java index 3f5f96cb6eb..c88e226d496 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuilderCorePlugin.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuilderCorePlugin.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2003, 2004 IBM Corporation and others. + * Copyright (c) 2003, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v0.5 * which accompanies this distribution, and is available at @@ -16,6 +16,11 @@ import org.eclipse.cdt.managedbuilder.internal.scannerconfig.ManagedBuildPathEnt import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.osgi.framework.BundleContext; +// NOTE: The code below is for tracking resource renaming and deleting. This is needed to keep +// ResourceConfiguration elements up to date. It may also be needed by AdditionalInput +// elements +//import org.eclipse.cdt.managedbuilder.internal.core.ResourceChangeHandler; +//import org.eclipse.core.resources.*; public class ManagedBuilderCorePlugin extends Plugin { @@ -27,6 +32,10 @@ public class ManagedBuilderCorePlugin extends Plugin { public static final String COMMANDLINEGEN_ID = "commandlineGenerator"; //$NON-NLS-1$ // The unique id for all managed make projects public static final String MANAGED_MAKE_PROJECT_ID = ManagedBuilderCorePlugin.getUniqueIdentifier() + ".managedMake"; //$NON-NLS-1$ + // NOTE: The code below is for tracking resource renaming and deleting. This is needed to keep + // ResourceConfiguration elements up to date. It may also be needed by AdditionalInput + // elements + //private static ResourceChangeHandler listener; /** * @param descriptor @@ -60,6 +69,31 @@ public class ManagedBuilderCorePlugin extends Plugin { // Turn on logging for plugin when debugging super.start(context); configurePluginDebugOptions(); + + // NOTE: The code below is for tracking resource renaming and deleting. This is needed to keep + // ResourceConfiguration elements up to date. It may also be needed by AdditionalInput + // elements + + // Set up a listener for resource change events + //listener = new ResourceChangeHandler(); + //ResourcesPlugin.getWorkspace().addResourceChangeListener( + // listener, IResourceChangeEvent.POST_CHANGE /*| IResourceChangeEvent.POST_BUILD*/); + //ISavedState lastState = + // ResourcesPlugin.getWorkspace().addSaveParticipant(plugin, listener); + //if (lastState != null) { + // lastState.processResourceChangeEvents(listener); + //} + + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + // NOTE: The code below is for tracking resource renaming and deleting. This is needed to keep + // ResourceConfiguration elements up to date. It may also be needed by AdditionalInput + // elements + //ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener); } private static final String PATH_ENTRY = ManagedBuilderCorePlugin.getUniqueIdentifier() + "/debug/pathEntry"; //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java index 4b1f8094a1a..753f1fac141 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java @@ -644,7 +644,9 @@ public class InputType extends BuildObject implements IInputType { String[] paths = current.getPaths(); if (paths != null) { for (int i = 0; i < paths.length; i++) { - deps.add(Path.fromOSString(paths[i])); + if (paths[i].length() > 0) { + deps.add(Path.fromOSString(paths[i])); + } } } } @@ -666,7 +668,9 @@ public class InputType extends BuildObject implements IInputType { String[] paths = current.getPaths(); if (paths != null) { for (int i = 0; i < paths.length; i++) { - ins.add(Path.fromOSString(paths[i])); + if (paths[i].length() > 0) { + ins.add(Path.fromOSString(paths[i])); + } } } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java index 88e9731dadb..9122d805cd2 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java @@ -46,6 +46,8 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi // Managed Build model attributes private String resPath; private Boolean isExcluded; + private Integer rcbsApplicability; + private String toolsToInvoke; // Miscellaneous private boolean isExtensionResourceConfig = false; private boolean isDirty = false; @@ -124,6 +126,8 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi resPath = path; isDirty = false; isExcluded = new Boolean(false); + toolsToInvoke = EMPTY_STRING; + rcbsApplicability = new Integer(KIND_DISABLE_RCBS_TOOL); } /** @@ -148,7 +152,13 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi if (cloneConfig.isExcluded != null) { isExcluded = new Boolean(cloneConfig.isExcluded.booleanValue()); } - + if (cloneConfig.toolsToInvoke != null) { + toolsToInvoke = new String(cloneConfig.toolsToInvoke); + } + if (cloneConfig.rcbsApplicability != null) { + rcbsApplicability = new Integer(cloneConfig.rcbsApplicability.intValue()); + } + // Clone the resource configuration's tool children if (cloneConfig.toolList != null) { Iterator iter = cloneConfig.getToolList().listIterator(); @@ -226,6 +236,20 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi if (excludeStr != null){ isExcluded = new Boolean("true".equals(excludeStr)); //$NON-NLS-1$ } + // toolsToInvoke + toolsToInvoke = element.getAttribute(IResourceConfiguration.TOOLS_TO_INVOKE); + + // rcbsApplicability + String rcbsApplicabilityStr = element.getAttribute(IResourceConfiguration.RCBS_APPLICABILITY); + if (rcbsApplicabilityStr == null || rcbsApplicabilityStr.equals(DISABLE_RCBS_TOOL)) { + rcbsApplicability = new Integer(KIND_DISABLE_RCBS_TOOL); + } else if (rcbsApplicabilityStr.equals(APPLY_RCBS_TOOL_BEFORE)) { + rcbsApplicability = new Integer(KIND_APPLY_RCBS_TOOL_BEFORE); + } else if (rcbsApplicabilityStr.equals(APPLY_RCBS_TOOL_AFTER)) { + rcbsApplicability = new Integer(KIND_APPLY_RCBS_TOOL_AFTER); + } else if (rcbsApplicabilityStr.equals(APPLY_RCBS_TOOL_AS_OVERRIDE)) { + rcbsApplicability = new Integer(KIND_APPLY_RCBS_TOOL_AS_OVERRIDE); + } } /* (non-Javadoc) @@ -256,6 +280,25 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi if (element.hasAttribute(IResourceConfiguration.RESOURCE_PATH)) { resPath = element.getAttribute(IResourceConfiguration.RESOURCE_PATH); } + + // toolsToInvoke + if (element.hasAttribute(IResourceConfiguration.TOOLS_TO_INVOKE)) { + toolsToInvoke = element.getAttribute(IResourceConfiguration.TOOLS_TO_INVOKE); + } + + // rcbsApplicability + if (element.hasAttribute(IResourceConfiguration.RCBS_APPLICABILITY)) { + String rcbsApplicabilityStr = element.getAttribute(IResourceConfiguration.RCBS_APPLICABILITY); + if (rcbsApplicabilityStr == null || rcbsApplicabilityStr.equals(DISABLE_RCBS_TOOL)) { + rcbsApplicability = new Integer(KIND_DISABLE_RCBS_TOOL); + } else if (rcbsApplicabilityStr.equals(APPLY_RCBS_TOOL_BEFORE)) { + rcbsApplicability = new Integer(KIND_APPLY_RCBS_TOOL_BEFORE); + } else if (rcbsApplicabilityStr.equals(APPLY_RCBS_TOOL_AFTER)) { + rcbsApplicability = new Integer(KIND_APPLY_RCBS_TOOL_AFTER); + } else if (rcbsApplicabilityStr.equals(APPLY_RCBS_TOOL_AS_OVERRIDE)) { + rcbsApplicability = new Integer(KIND_APPLY_RCBS_TOOL_AS_OVERRIDE); + } + } } /** @@ -280,6 +323,32 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi element.setAttribute(IResourceConfiguration.RESOURCE_PATH, resPath); } + if (toolsToInvoke != null) { + element.setAttribute(IResourceConfiguration.TOOLS_TO_INVOKE, toolsToInvoke); + } + + if (rcbsApplicability != null) { + String str; + switch (getRcbsApplicability()) { + case KIND_APPLY_RCBS_TOOL_BEFORE: + str = APPLY_RCBS_TOOL_BEFORE; + break; + case KIND_APPLY_RCBS_TOOL_AFTER: + str = APPLY_RCBS_TOOL_AFTER; + break; + case KIND_APPLY_RCBS_TOOL_AS_OVERRIDE: + str = APPLY_RCBS_TOOL_AS_OVERRIDE; + break; + case KIND_DISABLE_RCBS_TOOL: + str = DISABLE_RCBS_TOOL; + break; + default: + str = DISABLE_RCBS_TOOL; + break; + } + element.setAttribute(IResourceConfiguration.RCBS_APPLICABILITY, str); + } + // Serialize my children List toolElements = getToolList(); Iterator iter = toolElements.listIterator(); @@ -361,6 +430,16 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi getToolMap().put(tool.getId(), tool); } + /* (non-Javadoc) + * Removes the Tool from the Tool list and map + * + * @param Tool + */ + public void removeTool(ITool tool) { + getToolList().remove(tool); + getToolMap().remove(tool); + } + /* * M O D E L A T T R I B U T E A C C E S S O R S */ @@ -387,6 +466,180 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi } /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IResourceConfiguration#getRcbsApplicability() + */ + public int getRcbsApplicability() { + /* + * rcbsApplicability is an integer constant that represents how the user wants to + * order the application of a resource custom build step tool. + * Defaults to disable rcbs tool. + * Choices are before, after, or override other tools, or disable rcbs tool. + */ + if (rcbsApplicability == null) { + return KIND_DISABLE_RCBS_TOOL; + } + return rcbsApplicability.intValue(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IResourceConfiguration#getToolsToInvoke() + */ + public ITool[] getToolsToInvoke() { + /* + * toolsToInvoke is an ordered list of tool ids for the currently defined tools in + * the resource configuration. + * Defaults to all tools in the order found. + * Modified by the presence of an rcbs tool and the currently assigned applicability of that tool. + * The attribute is implemented as a String of a semicolon separated list of tool ids. + * An empty string implies treat as if no resource configuration, i.e., use project level tool. + * This getter routine returns an ITool[] to consumers (i.e., the makefile generator). + */ + String t_ToolsToInvoke = EMPTY_STRING; + ITool[] resConfigTools; + ITool[] tools; + String id; + String rcbsToolId = EMPTY_STRING; + int len; + int j; + int rcbsToolIdx=-1; + resConfigTools = getTools(); + + /* + * Evaluate the tools currently defined in the resource configuration. + * Update the current state of the toolsToInvoke attribute. + * Build and return an ITool[] for consumers. + */ + + /* + * If no tools are currently defined, return a zero lengh array of ITool. + */ + if (resConfigTools.length == 0) { + toolsToInvoke = EMPTY_STRING; + tools = new ITool[0]; + return tools; + } + + /* + * See if there is an rcbs tool defined. There should only be one at most. + */ + for ( int i = 0; i < resConfigTools.length; i++ ){ + if (resConfigTools[i].getCustomBuildStep() && !resConfigTools[i].isExtensionElement()) { + rcbsToolId = resConfigTools[i].getId(); + rcbsToolIdx = i; + break; + } + } + if (!rcbsToolId.equals(EMPTY_STRING)){ + /* + * Here if an rcbs tool is defined. + * Apply the tools according to the current rcbsApplicability setting. + */ + switch(rcbsApplicability.intValue()){ + case KIND_APPLY_RCBS_TOOL_AS_OVERRIDE: + toolsToInvoke = rcbsToolId; + tools = new ITool[1]; + tools[0] = resConfigTools[rcbsToolIdx]; + break; + case KIND_APPLY_RCBS_TOOL_AFTER: + j = 0; + tools = new ITool[resConfigTools.length]; + for ( int i = 0; i < resConfigTools.length; i++ ){ + if (resConfigTools[i].getId() != rcbsToolId) { + t_ToolsToInvoke += resConfigTools[i].getId() + ";"; //$NON-NLS-1$ + tools[j++] = resConfigTools[i]; + } + } + t_ToolsToInvoke += rcbsToolId; + tools[j++] = resConfigTools[rcbsToolIdx]; + toolsToInvoke = t_ToolsToInvoke; + break; + case KIND_APPLY_RCBS_TOOL_BEFORE: + j = 0; + tools = new ITool[resConfigTools.length]; + t_ToolsToInvoke = rcbsToolId + ";"; //$NON-NLS-1$ + tools[j++] = resConfigTools[rcbsToolIdx]; + for ( int i = 0; i < resConfigTools.length; i++ ){ + if (resConfigTools[i].getId() != rcbsToolId) { + t_ToolsToInvoke += resConfigTools[i].getId() + ";"; //$NON-NLS-1$ + tools[j++] = resConfigTools[i]; + } + } + len = t_ToolsToInvoke.length(); + t_ToolsToInvoke = t_ToolsToInvoke.substring(0,len-1); + toolsToInvoke = t_ToolsToInvoke; + break; + case KIND_DISABLE_RCBS_TOOL: + /* + * If the rcbs tool is the only tool and the user has disabled it, + * there are no tools to invoke in the resource configuration. + */ + if(resConfigTools.length == 1){ + tools = new ITool[0]; + toolsToInvoke = EMPTY_STRING; + break; + } + j = 0; + tools = new ITool[resConfigTools.length-1]; + for ( int i = 0; i < resConfigTools.length; i++ ){ + if (resConfigTools[i].getId() != rcbsToolId) { + t_ToolsToInvoke += resConfigTools[i].getId() + ";"; //$NON-NLS-1$ + tools[j++] = resConfigTools[i]; + } + } + len = t_ToolsToInvoke.length(); + t_ToolsToInvoke = t_ToolsToInvoke.substring(0,len-1); + toolsToInvoke = t_ToolsToInvoke; + break; + default: + /* + * If we get an unexpected value, apply all tools in the order found. + */ + tools = new ITool[resConfigTools.length]; + for ( int i = 0; i < resConfigTools.length; i++ ){ + t_ToolsToInvoke += resConfigTools[i].getId() + ";"; //$NON-NLS-1$ + tools[i] = resConfigTools[i]; + } + len = t_ToolsToInvoke.length(); + t_ToolsToInvoke = t_ToolsToInvoke.substring(0,len-1); + toolsToInvoke = t_ToolsToInvoke; + break; + } + } + else { + /* + * Here if no rcbs tool is defined, but there are other tools in the resource configuration. + * Specify all tools in the order found. + */ + tools = new ITool[resConfigTools.length]; + for ( int i = 0; i < resConfigTools.length; i++ ){ + t_ToolsToInvoke += resConfigTools[i].getId() + ";"; //$NON-NLS-1$ + tools[i] = resConfigTools[i]; + } + len = t_ToolsToInvoke.length(); + t_ToolsToInvoke = t_ToolsToInvoke.substring(0,len-1); + toolsToInvoke = t_ToolsToInvoke; + } + return tools; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IResourceConfiguration#getRcbsApplicability() + */ + public void setRcbsApplicability(int newValue) { + /* + * rcbsApplicability is an integer constant that represents how the user wants to + * order the application of a resource custom build step tool. + * Defaults to override all other tools. + * Choices are before, after, or override other tools, or disable rcbs tool. + */ + if (rcbsApplicability == null || !(rcbsApplicability.intValue() == newValue)) { + rcbsApplicability = new Integer(newValue); + isDirty = true; + } + } + + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IResourceConfiguration#setExclude() */ public void setExclude(boolean excluded) { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/MbsMacroSupplier.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/MbsMacroSupplier.java index 2fea7ee20a4..58b1f2b2695 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/MbsMacroSupplier.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/MbsMacroSupplier.java @@ -559,7 +559,7 @@ public class MbsMacroSupplier implements IBuildMacroSupplier { ITool buildTools[] = null; IResourceConfiguration rcCfg = cfg.getResourceConfiguration(inputPath.toOSString()); if(rcCfg != null) - buildTools = rcCfg.getTools(); + buildTools = rcCfg.getToolsToInvoke(); else buildTools = cfg.getFilteredTools(); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator.java index d914272c940..0a91d25a821 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator.java @@ -114,7 +114,7 @@ public class DefaultGCCDependencyCalculator implements IManagedDependencyGenerat String outputPrefix = ""; //$NON-NLS-1$ String outputFile = ""; //$NON-NLS-1$ if( resConfig != null) { - ITool[] tools = resConfig.getTools(); + ITool[] tools = resConfig.getToolsToInvoke(); String cmd = tools[0].getToolCommand(); //try to resolve the build macros in the tool command try{ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java index c4d74d09f4a..1ee2a17d853 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java @@ -202,17 +202,23 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { // Is this a resource we should even consider if (proxy.getType() == IResource.FILE) { - // Check extension to see if build model should build this file + // If this resource has a Resource Configuration and is not excluded or + // if it has a file extension that one of the tools builds, add the sudirectory to the list IResource resource = proxy.requestResource(); - String ext = resource.getFileExtension(); - if (info.buildsFileType(ext)) { - // If this file resource is a generated resource, then it is uninteresting - if (!generator.isGeneratedResource(resource)) { - // If this file resource is excluded from build, then it is uninteresting - IResourceConfiguration resConfig = config.getResourceConfiguration(resource.getFullPath().toString()); - if ((resConfig == null) || (!(resConfig.isExcluded()))) { - generator.appendBuildSubdirectory(resource); - } + boolean willBuild = false; + IResourceConfiguration resConfig = config.getResourceConfiguration(resource.getFullPath().toString()); + if (resConfig != null) willBuild = true; + if (!willBuild) { + String ext = resource.getFileExtension(); + if (info.buildsFileType(ext) && + // If this file resource is a generated resource, then it is uninteresting + !generator.isGeneratedResource(resource)) { + willBuild = true; + } + } + if (willBuild) { + if ((resConfig == null) || (!(resConfig.isExcluded()))) { + generator.appendBuildSubdirectory(resource); } } return false; @@ -567,7 +573,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { } /* (non-Javadoc) - * @see org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator#getTopBuildDir() + * @see org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator#getBuildWorkingDir() */ public IPath getBuildWorkingDir() { if (topBuildDir != null) { @@ -1814,7 +1820,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { if( (resConfig != null) && (resConfig.isExcluded()) ) continue; addFragmentMakefileEntriesForSource(buildVarToRuleStringMap, ruleBuffer, - folder, relativePath, resource, resource.getLocation(), null, false); + folder, relativePath, resource, resource.getLocation(), resConfig, null, false); } } @@ -1832,19 +1838,30 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { * @param relativePath build output directory relative path of the current output directory * @param resource the source file for this invocation of the tool - this may be null for a generated output * @param sourceLocation the full path of the source + * @param resConfig the IResourceConfiguration associated with this file or null * @param varName the build variable to add this invocation's outputs to * if <code>null</code>, use the file extension to find the name * @param generatedSource if <code>true</code>, this file was generated by another tool in the tool-chain */ protected void addFragmentMakefileEntriesForSource (LinkedHashMap buildVarToRuleStringMap, StringBuffer ruleBuffer, - IFolder folder, String relativePath, IResource resource, IPath sourceLocation, String varName, boolean generatedSource) { + IFolder folder, String relativePath, IResource resource, IPath sourceLocation, IResourceConfiguration resConfig, + String varName, boolean generatedSource) { // Determine which tool, if any, builds files with this extension String ext = sourceLocation.getFileExtension(); - boolean toolFound = false; + ITool tool = null; + + // Use the tool from the resource configuration if there is one + if (resConfig != null) { + ITool[] tools = resConfig.getToolsToInvoke(); + if (tools != null && tools.length > 0) { + tool = tools[0]; + } + } for (int j=0; j<buildTools.length; j++) { if (buildTools[j].buildsFileType(ext)) { - toolFound = true; - ITool tool = buildTools[j]; + if (tool == null) { + tool = buildTools[j]; + } // look for the extension in the map StringBuffer bufferForExtension = new StringBuffer(); if (varName == null) { @@ -1865,58 +1882,78 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { } if (!buildVarToRuleStringMap.containsKey(varName)) { // TODO - is this an error? - continue; + } else { + // Add the resource name to the makefile line that adds resources to the build variable + addMacroAdditionFile(buildVarToRuleStringMap, varName, relativePath, sourceLocation, generatedSource); } - // Add the resource name to the makefile line that adds resources to the build variable - addMacroAdditionFile(buildVarToRuleStringMap, varName, relativePath, sourceLocation, generatedSource); + break; + } + } - // Generate the rule to build this source file - IInputType primaryInputType = tool.getPrimaryInputType(); - IInputType inputType = tool.getInputType(ext); - if ((primaryInputType != null && !primaryInputType.getMultipleOfType()) || - (inputType == null && !(tool == info.getToolFromOutputExtension(buildTargetExt)))) { - - // Try to add the rule for the file - StringBuffer generatedDepFile = new StringBuffer(); - Vector generatedOutputs = new Vector(); - addRuleForSource(relativePath, ruleBuffer, resource, sourceLocation, generatedSource, generatedDepFile, generatedOutputs); - - // If the rule generates a dependency file, add the file to the DEPS variable - if (generatedDepFile.length() > 0) { - addMacroAdditionFile(buildVarToRuleStringMap, DEPS_MACRO, generatedDepFile.toString()); - } + if (tool != null) { + // Generate the rule to build this source file + IInputType primaryInputType = tool.getPrimaryInputType(); + IInputType inputType = tool.getInputType(ext); + if ((primaryInputType != null && !primaryInputType.getMultipleOfType()) || + (inputType == null && !(tool == info.getToolFromOutputExtension(buildTargetExt)))) { - // If the generated outputs of this tool are input to another tool, - // 1. add the output to the appropriate macro - // 2. If the tool does not have multipleOfType input, generate the rule. - - IOutputType outType = tool.getPrimaryOutputType(); - String buildVariable = null; - if (outType != null) { - buildVariable = outType.getBuildVariable(); + // Try to add the rule for the file + StringBuffer generatedDepFile = new StringBuffer(); + Vector generatedOutputs = new Vector(); + addRuleForSource(relativePath, ruleBuffer, resource, sourceLocation, resConfig, generatedSource, generatedDepFile, generatedOutputs); + + // If the rule generates a dependency file, add the file to the DEPS variable + if (generatedDepFile.length() > 0) { + addMacroAdditionFile(buildVarToRuleStringMap, DEPS_MACRO, generatedDepFile.toString()); + } + + // If the generated outputs of this tool are input to another tool, + // 1. add the output to the appropriate macro + // 2. If the tool does not have multipleOfType input, generate the rule. + + IOutputType outType = tool.getPrimaryOutputType(); + String buildVariable = null; + if (outType != null) { + if (tool.getCustomBuildStep()) { + // TODO: This is somewhat of a hack since a custom build step + // tool does not currently define a build variable + if (generatedOutputs.size() > 0) { + IPath firstOutput = (IPath)generatedOutputs.get(0); + String firstExt = firstOutput.getFileExtension(); + for (int j=0; j<buildTools.length; j++) { + if (buildTools[j].buildsFileType(firstExt)) { + String bV = buildTools[j].getPrimaryInputType().getBuildVariable(); + if (bV.length() > 0) { + buildVariable = bV; + break; + } + } + } + } } else { - // For support of pre-CDT 3.0 integrations. - buildVariable = OBJS_MACRO; + buildVariable = outType.getBuildVariable(); } - - for (int k=0; k<generatedOutputs.size(); k++) { - IPath generatedOutput; - if (((IPath)generatedOutputs.get(k)).isAbsolute()) { - // TODO: Should we use relative paths when possible (e.g., see MbsMacroSupplier.calculateRelPath) - generatedOutput = (IPath)generatedOutputs.get(k); - } else { - generatedOutput = project.getLocation().append(getBuildWorkingDir()).append((IPath)generatedOutputs.get(k)); - } - // If this file has an absolute path, then the generateOutputResource will not be correct - // because the file is not under the project. We use this resource in the calls to the dependency generator - IResource generateOutputResource = project.getFile(generatedOutput); - addFragmentMakefileEntriesForSource(buildVarToRuleStringMap, ruleBuffer, - folder, relativePath, generateOutputResource, generatedOutput, buildVariable, true); - } + } else { + // For support of pre-CDT 3.0 integrations. + buildVariable = OBJS_MACRO; } - } - } - if (!toolFound) { + + for (int k=0; k<generatedOutputs.size(); k++) { + IPath generatedOutput; + if (((IPath)generatedOutputs.get(k)).isAbsolute()) { + // TODO: Should we use relative paths when possible (e.g., see MbsMacroSupplier.calculateRelPath) + generatedOutput = (IPath)generatedOutputs.get(k); + } else { + generatedOutput = project.getLocation().append(getBuildWorkingDir()).append((IPath)generatedOutputs.get(k)); + } + // If this file has an absolute path, then the generateOutputResource will not be correct + // because the file is not under the project. We use this resource in the calls to the dependency generator + IResource generateOutputResource = project.getFile(generatedOutput); + addFragmentMakefileEntriesForSource(buildVarToRuleStringMap, ruleBuffer, + folder, relativePath, generateOutputResource, generatedOutput, null, buildVariable, true); + } + } + } else { // If this generated output is identified as a secondary output, add the file to the build variable if (varName != null) { IOutputType[] secondaryOutputs = config.getToolChain().getSecondaryOutputs(); @@ -1961,26 +1998,23 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { * @param buffer buffer to populate with the build rule * @param resource the source file for this invocation of the tool * @param generatedSource <code>true</code> if the resource is a generated output + * @param sourceLocation the full path of the source + * @param resConfig the IResourceConfiguration associated with this file or null * @param generatedDepFile passed in as an empty string; append the dependency file name * to it if one is generated by the rule * @param enumeratedOutputs vector of the filenames that are the output of this rule */ protected void addRuleForSource(String relativePath, StringBuffer buffer, IResource resource, - IPath sourceLocation, boolean generatedSource, StringBuffer generatedDepFile, Vector enumeratedOutputs) { + IPath sourceLocation, IResourceConfiguration resConfig, + boolean generatedSource, StringBuffer generatedDepFile, Vector enumeratedOutputs) { String fileName = sourceLocation.removeFileExtension().lastSegment(); String inputExtension = sourceLocation.getFileExtension(); String outputExtension = info.getOutputExtension(inputExtension); - // We need to check whether we have any resource specific build information. - IResourceConfiguration resConfig = null; - if( !generatedSource && config != null ) { - resConfig = config.getResourceConfiguration(resource.getFullPath().toString()); - } - ITool tool; if( resConfig != null) { - ITool[] tools = resConfig.getTools(); + ITool[] tools = resConfig.getToolsToInvoke(); tool = tools[0]; } else { tool = info.getToolFromInputExtension(inputExtension); @@ -2130,8 +2164,19 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { // Other additional inputs // Get any additional dependencies specified for the tool in other InputType elements and AdditionalInput elements IPath[] addlDepPaths = tool.getAdditionalDependencies(); - for (int i=0; i<addlDepPaths.length; i++) { - buildRule += WHITESPACE + addlDepPaths[i].toString(); + for (int i=0; i<addlDepPaths.length; i++) { + // Translate the path from project relative to + // build directory relative + IPath addlPath = addlDepPaths[i]; + if (!(addlPath.toString().startsWith("$("))) { //$NON-NLS-1$ + if (!addlPath.isAbsolute()) { + IPath tempPath = project.getLocation().append(addlPath); + if (tempPath != null) { + addlPath = calculateRelativePath(getTopBuildDir(), tempPath); + } + } + } + buildRule += WHITESPACE + addlPath.toString(); } // No duplicates in a makefile. If we already have this rule, return @@ -2169,7 +2214,18 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { // Get any additional dependencies specified for the tool in other InputType elements and AdditionalInput elements IPath[] addlInputPaths = tool.getAdditionalResources(); for (int i=0; i<addlInputPaths.length; i++) { - inputs.add(addlDepPaths[i].toString()); + // Translate the path from project relative to + // build directory relative + IPath addlPath = addlInputPaths[i]; + if (!(addlPath.toString().startsWith("$("))) { //$NON-NLS-1$ + if (!addlPath.isAbsolute()) { + IPath tempPath = project.getLocation().append(addlPath); + if (tempPath != null) { + addlPath = calculateRelativePath(getTopBuildDir(), tempPath); + } + } + } + inputs.add(addlPath.toString()); } // Call the command line generator IManagedCommandLineGenerator cmdLGen = tool.getCommandLineGenerator(); @@ -2193,7 +2249,18 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { // Get any additional dependencies specified for the tool in other InputType elements and AdditionalInput elements IPath[] addlInputPaths = tool.getAdditionalResources(); for (int i=0; i<addlInputPaths.length; i++) { - inputs.add(addlDepPaths[i].toString()); + // Translate the path from project relative to + // build directory relative + IPath addlPath = addlInputPaths[i]; + if (!(addlPath.toString().startsWith("$("))) { //$NON-NLS-1$ + if (!addlPath.isAbsolute()) { + IPath tempPath = project.getLocation().append(addlPath); + if (tempPath != null) { + addlPath = calculateRelativePath(getTopBuildDir(), tempPath); + } + } + } + inputs.add(addlPath.toString()); } // Call the command line generator cmdLInfo = info.generateToolCommandLineInfo( inputExtension, flags, outflag, outputPrefix, @@ -3270,4 +3337,43 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { } } + /** + * Return the configuration's top build directory + */ + public IPath getTopBuildDir() { + return project.getLocation().append(getBuildWorkingDir()); + } + + /** + * Calculate a relative path given the full path to a folder and a file + */ + public IPath calculateRelativePath(IPath container, IPath contents){ + IPath path = contents; + if(container.isPrefixOf(contents)){ + path = contents.setDevice(null).removeFirstSegments(container.segmentCount()); + } else { + String file = null; + container = container.addTrailingSeparator(); + if(!contents.hasTrailingSeparator()){ + file = contents.lastSegment(); + contents = contents.removeLastSegments(1); + contents = contents.addTrailingSeparator(); + } + + IPath prefix = contents; + for(;prefix.segmentCount() > 0 && !prefix.isPrefixOf(container);prefix = prefix.removeLastSegments(1)){ + } + if(prefix.segmentCount() > 0){ + int diff = container.segmentCount() - prefix.segmentCount(); + StringBuffer buff = new StringBuffer(); + while(diff-- > 0) + buff.append("../"); //$NON-NLS-1$ + path = new Path(buff.toString()).append(contents.removeFirstSegments(prefix.segmentCount())); + if(file != null) + path = path.append(file); + } + } + return path; + } + } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/ManagedBuildGnuToolInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/ManagedBuildGnuToolInfo.java index bc75cfad967..ccdb97805cf 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/ManagedBuildGnuToolInfo.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/ManagedBuildGnuToolInfo.java @@ -272,8 +272,20 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo { String[] paths = addlInput.getPaths(); if (paths != null) { for (int k = 0; k < paths.length; k++) { - myCommandInputs.add(paths[k]); - myEnumeratedInputs.add(paths[k]); + // Translate the path from project relative to + // build directory relative + String path = paths[k]; + if (!(path.startsWith("$("))) { //$NON-NLS-1$ + IResource addlResource = project.getFile(path); + if (addlResource != null) { + IPath addlPath = addlResource.getLocation(); + if (addlPath != null) { + path = makeGen.calculateRelativePath(makeGen.getTopBuildDir(), addlPath).toString(); + } + } + } + myCommandInputs.add(path); + myEnumeratedInputs.add(path); } } } @@ -635,8 +647,20 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo { String[] paths = addlInput.getPaths(); if (paths != null) { for (int k = 0; k < paths.length; k++) { - myCommandDependencies.add(paths[k]); - //myEnumeratedInputs.add(pathTokens[k]); + // Translate the path from project relative to + // build directory relative + String path = paths[k]; + if (!(path.startsWith("$("))) { //$NON-NLS-1$ + IResource addlResource = project.getFile(path); + if (addlResource != null) { + IPath addlPath = addlResource.getLocation(); + if (addlPath != null) { + path = makeGen.calculateRelativePath(makeGen.getTopBuildDir(), addlPath).toString(); + } + } + } + myCommandDependencies.add(path); + //myEnumeratedInputs.add(path); } } } |