From 397635f067736ac992fba8606da891957cced79b Mon Sep 17 00:00:00 2001 From: Leo Treggiari Date: Tue, 27 Sep 2005 23:34:12 +0000 Subject: [PATCH] Add support for InputType, assignToOption attribute --- .../schema/buildDefinitions.exsd | 9 +- .../cdt/managedbuilder/core/IInputType.java | 41 ++- .../cdt/managedbuilder/core/ITool.java | 11 + .../core/ManagedBuildManager.java | 33 ++ .../internal/core/InputType.java | 47 ++- .../internal/core/ManagedBuildInfo.java | 12 +- .../managedbuilder/internal/core/Tool.java | 40 ++- .../internal/core/ToolReference.java | 11 + .../internal/macros/MbsMacroSupplier.java | 38 +-- .../makegen/IManagedDependencyGenerator2.java | 88 ++++++ .../makegen/gnu/GnuMakefileGenerator.java | 282 +++++++++++++----- .../makegen/gnu/ManagedBuildGnuToolInfo.java | 112 +++++-- 12 files changed, 566 insertions(+), 158 deletions(-) create mode 100644 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyGenerator2.java diff --git a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd index f65a814fc8a..d8e3960d68b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd +++ b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd @@ -716,7 +716,14 @@ - The id of an Option element that is used on the command line to identify inputs of this type. The default when not specified is to assign the inputs to the ${Inputs} part of the command line. + The id of an Option element that is used on the command line to identify inputs of this type. If specified, the name(s) of the input files for this input type are taken from the value specified for the option. + + + + + + + The id of an Option element whose value is to be assigned to the file(s) calculated for this input type. The default is not to assign the input file(s) to a command line option but to assign the files to the ${Inputs} part of the command line. Note that the option value is only updated during build file generation and therefore could be out of sync with the project until build file generation occurs. diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IInputType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IInputType.java index 3d740babba2..9db563dff8a 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IInputType.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IInputType.java @@ -28,6 +28,7 @@ public interface IInputType extends IBuildObject { public static final String DEPENDENCY_CONTENT_TYPE = "dependencyContentType"; //$NON-NLS-1$ public static final String DEPENDENCY_EXTENSIONS = "dependencyExtensions"; //$NON-NLS-1$ public static final String OPTION = "option"; //$NON-NLS-1$ + public static final String ASSIGN_TO_OPTION = "assignToOption"; //$NON-NLS-1$ public static final String MULTIPLE_OF_TYPE = "multipleOfType"; //$NON-NLS-1$ public static final String PRIMARY_INPUT = "primaryInput"; //$NON-NLS-1$ public static final String BUILD_VARIABLE = "buildVariable"; //$NON-NLS-1$ @@ -260,22 +261,50 @@ public interface IInputType extends IBuildObject { public boolean isDependencyExtension(ITool tool, String ext); /** - * Returns the id of the option that is associated with this - * input type on the command line. The default is to not use a command - * line option and to assign this input to the ${Inputs} part of the command line. + * Returns the id of the option that is associated with this input + * type on the command line. If specified, the name(s) of the input + * files for this input type are taken from the value specified + * for the option. * * @return String */ public String getOptionId(); /** - * Sets the id of the option that is associated with this - * input type on the command line. + * Sets the id of the option that is associated with this input type on + * the command line. If specified, the name(s) of the input files for + * this input type are taken from the value specified for the option. * * @param optionId */ public void setOptionId(String optionId); - + + /** + * Returns the id of the option whose value is to be assigned to the + * file(s) calculated for this input type. The default is not to + * assign the input file(s) to a command line option but to assign the + * files to the ${Inputs} part of the command line. Note that the + * option value is only updated during build file generation and therefore + * could be out of sync with the project until build file generation + * occurs. + * + * @return String + */ + public String getAssignToOptionId(); + + /** + * Sets the id of the option whose value is to be assigned to the + * file(s) calculated for this input type. The default is not to + * assign the input file(s) to a command line option but to assign the + * files to the ${Inputs} part of the command line. Note that the + * option value is only updated during build file generation and therefore + * could be out of sync with the project until build file generation + * occurs. + * + * @param optionId + */ + public void setAssignToOptionId(String optionId); + /** * Returns true if this inputType can contain multiple input * resources, else false. The inputs can be project resources, diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java index c2e91937418..35648ee55fd 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java @@ -635,6 +635,17 @@ public interface ITool extends IBuildObject, IHoldsOptions { * @return boolean */ public boolean buildsFileType(String extension); + + /** + * Return true if the receiver uses files with the + * specified extension as input, else false. This + * returns true for a superset of the extensions that buildFileType + * returns true for - it includes secondary inputs. + * + * @param extension file extension of the source + * @return boolean + */ + public boolean isInputFileType(String extension); /** * Answers true if the tool considers the file extension to be diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index ada08ff381a..f64a27042e3 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -82,6 +82,7 @@ import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.PluginVersionIdentifier; import org.eclipse.core.runtime.QualifiedName; @@ -2902,4 +2903,36 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI } return false; } + + /** + * Calculate a relative path given the full path to a folder and a file + */ + public static 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/internal/core/InputType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java index 7bfd97df0a6..b9bfb5b3cd5 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 @@ -16,16 +16,10 @@ import java.util.List; import java.util.StringTokenizer; import java.util.Vector; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.runtime.content.*; -import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.managedbuilder.core.ITool; -import org.eclipse.cdt.managedbuilder.core.IToolChain; -import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; -import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IInputOrder; import org.eclipse.cdt.managedbuilder.core.IAdditionalInput; @@ -63,6 +57,7 @@ public class InputType extends BuildObject implements IInputType { private IContentType dependencyContentType; private List dependencyExtensions; private String optionId; + private String assignToOptionId; private String buildVariable; private Boolean multipleOfType; private Boolean primaryInput; @@ -208,6 +203,9 @@ public class InputType extends BuildObject implements IInputType { if (inputType.optionId != null) { optionId = new String(inputType.optionId); } + if (inputType.assignToOptionId != null) { + assignToOptionId = new String(inputType.assignToOptionId); + } if (inputType.buildVariable != null) { buildVariable = new String(inputType.buildVariable); } @@ -290,6 +288,9 @@ public class InputType extends BuildObject implements IInputType { // option optionId = element.getAttribute(IInputType.OPTION); + // assignToOption + assignToOptionId = element.getAttribute(IInputType.ASSIGN_TO_OPTION); + // multipleOfType String isMOT = element.getAttribute(IInputType.MULTIPLE_OF_TYPE); if (isMOT != null){ @@ -382,6 +383,11 @@ public class InputType extends BuildObject implements IInputType { optionId = element.getAttribute(IInputType.OPTION); } + // assignToOption + if (element.hasAttribute(IInputType.ASSIGN_TO_OPTION)) { + assignToOptionId = element.getAttribute(IInputType.ASSIGN_TO_OPTION); + } + // multipleOfType if (element.hasAttribute(IInputType.MULTIPLE_OF_TYPE)) { String isMOT = element.getAttribute(IInputType.MULTIPLE_OF_TYPE); @@ -468,6 +474,10 @@ public class InputType extends BuildObject implements IInputType { element.setAttribute(IInputType.OPTION, optionId); } + if (assignToOptionId != null) { + element.setAttribute(IInputType.ASSIGN_TO_OPTION, assignToOptionId); + } + if (multipleOfType != null) { element.setAttribute(IInputType.MULTIPLE_OF_TYPE, multipleOfType.toString()); } @@ -951,6 +961,31 @@ public class InputType extends BuildObject implements IInputType { } } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IInputType#getAssignToOptionId() + */ + public String getAssignToOptionId() { + if (assignToOptionId == null) { + if (superClass != null) { + return superClass.getAssignToOptionId(); + } else { + return null; + } + } + return assignToOptionId; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IInputType#setAssignToOptionId() + */ + public void setAssignToOptionId(String id) { + if (id == null && assignToOptionId == null) return; + if (id == null || assignToOptionId == null || !(assignToOptionId.equals(id))) { + assignToOptionId = id; + setDirty(true); + } + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IInputType#getSourceContentType() */ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java index 303889d3efa..0a260c4a633 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java @@ -485,9 +485,11 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo { if (getDefaultConfiguration() != null) { IToolChain toolChain = getDefaultConfiguration().getToolChain(); IBuilder builder = toolChain.getBuilder(); - return builder.getArguments(); + if (builder != null) { + return builder.getArguments(); + } } - return EMPTY_STRING; + return new String("-k"); //$NON-NLS-1$ } /* (non-Javadoc) @@ -497,9 +499,11 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo { if (getDefaultConfiguration() != null) { IToolChain toolChain = getDefaultConfiguration().getToolChain(); IBuilder builder = toolChain.getBuilder(); - return builder.getCommand(); + if (builder != null) { + return builder.getCommand(); + } } - return EMPTY_STRING; + return new String("make"); //$NON-NLS-1$ } /* 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 a065a2fbb6c..1f35d65438f 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 @@ -1487,7 +1487,7 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { IInputType[] types = getInputTypes(); for (int i=0; i 0) { + return false; + } + // 3. If the assignToOption attribute is specified, no + if (it.getAssignToOptionId() != null && it.getAssignToOptionId().length() > 0) { + return false; + } + // Else, yes return true; } - // If no InputTypes, check the attribute + // If no InputTypes, check the inputExtensions attribute + if (!hasInputTypes()) { + return getInputExtensionsAttribute().contains(extension); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.ITool#isInputFileType(java.lang.String) + */ + public boolean isInputFileType(String extension) { + if (extension == null) { + return false; + } + IInputType it = getInputType(extension); + if (it != null) { + return true; + } + // If no InputTypes, check the inputExtensions attribute if (!hasInputTypes()) { return getInputExtensionsAttribute().contains(extension); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java index c5b9196942e..9125449199e 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java @@ -290,6 +290,17 @@ public class ToolReference implements IToolReference { return parent.buildsFileType(extension); } + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.ITool#buildsFileType(java.lang.String) + */ + public boolean isInputFileType(String extension) { + if (parent == null) { + // bad reference + return false; + } + return parent.isInputFileType(extension); + } + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IToolReference#createOptionReference(org.eclipse.cdt.managedbuilder.core.IOption) */ 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 009d8d34e9d..7cacb703395 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 @@ -210,7 +210,7 @@ public class MbsMacroSupplier implements IBuildMacroSupplier { if(inputFileLocation != null && inputFileLocation.segmentCount() > 0){ IPath workingDirectory = getBuilderCWD(cfg); if(workingDirectory != null){ - IPath filePath = calculateRelPath(workingDirectory, inputFileLocation); + IPath filePath = ManagedBuildManager.calculateRelativePath(workingDirectory, inputFileLocation); if(filePath != null) value = filePath.toOSString(); } @@ -220,7 +220,7 @@ public class MbsMacroSupplier implements IBuildMacroSupplier { if(inputFileLocation != null && inputFileLocation.segmentCount() > 0){ IPath workingDirectory = getBuilderCWD(cfg); if(workingDirectory != null){ - IPath filePath = calculateRelPath(workingDirectory, inputFileLocation.removeLastSegments(1).addTrailingSeparator()); + IPath filePath = ManagedBuildManager.calculateRelativePath(workingDirectory, inputFileLocation.removeLastSegments(1).addTrailingSeparator()); if(filePath != null) value = filePath.toOSString(); } @@ -239,7 +239,7 @@ public class MbsMacroSupplier implements IBuildMacroSupplier { if(outputFileLocation != null && outputFileLocation.segmentCount() > 0){ IPath workingDirectory = getBuilderCWD(cfg); if(workingDirectory != null){ - IPath filePath = calculateRelPath(workingDirectory, outputFileLocation); + IPath filePath = ManagedBuildManager.calculateRelativePath(workingDirectory, outputFileLocation); if(filePath != null) value = filePath.toOSString(); } @@ -248,7 +248,7 @@ public class MbsMacroSupplier implements IBuildMacroSupplier { if(outputFileLocation != null && outputFileLocation.segmentCount() > 0){ IPath workingDirectory = getBuilderCWD(cfg); if(workingDirectory != null){ - IPath filePath = calculateRelPath(workingDirectory, outputFileLocation.removeLastSegments(1).addTrailingSeparator()); + IPath filePath = ManagedBuildManager.calculateRelativePath(workingDirectory, outputFileLocation.removeLastSegments(1).addTrailingSeparator()); if(filePath != null) value = filePath.toOSString(); } @@ -547,35 +547,6 @@ public class MbsMacroSupplier implements IBuildMacroSupplier { return workingDirectory; } - private IPath calculateRelPath(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; - } - private IPath getOutputFilePath(IPath inputPath, IConfiguration cfg){ ITool buildTools[] = null; IResourceConfiguration rcCfg = cfg.getResourceConfiguration(inputPath.toString()); @@ -838,7 +809,6 @@ public class MbsMacroSupplier implements IBuildMacroSupplier { IToolChain toolChain = null; IConfiguration cfg = null; - String optId = option.getId(); IResourceConfiguration rc = (IResourceConfiguration)bo; cfg = rc.getParent(); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyGenerator2.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyGenerator2.java new file mode 100644 index 00000000000..abf4bb00e53 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/IManagedDependencyGenerator2.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2004, 2005 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation of IManagedDependencyGenerator + * Intel - Initial API and implementation of IManagedDependencyGenerator2 + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.makegen; + +import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.core.runtime.IPath; +import org.eclipse.cdt.managedbuilder.core.ITool; + +/** + * @since 3.0.1 + * + * A Tool dependency calculator must implement this interface. This interface + * replaces IManagedDependencyGenerator which is deprecated. + * + * Note: The IPath arguments to the methods below can be either relative to + * the project directory, or absolute in the file system. + */ +public interface IManagedDependencyGenerator2 { + /** + * Constants returned by getCalculatorType + */ + public int TYPE_NODEPS = 0; + public int TYPE_COMMAND = 1; + public int TYPE_INDEXER = 2; + public int TYPE_EXTERNAL = 3; + + /** + * Returns the type of dependency generator that is implemented. + * + * TYPE_NODEPS indicates a NULL dependency generator + * TYPE_COMMAND indicates that a command line will be returned to be + * used to calculate dependencies. This currently supports compilers + * that generate .d files. + * TYPE_INDEXER indicates that the CDT indexer should be used to + * calculate the dependencies. + * TYPE_EXTERNAL indicates that a custom dependency calculator is + * implemented. + * + * @return int + */ + public int getCalculatorType(); + + /** + * Returns the list of dependencies for this source file. + * The paths can be either relative to the project directory, or absolute + * in the file system. + * + * @param source The source file for which dependencies should be calculated + * @param info The IManagedBuildInfo of the project + * @param tool The tool associated with the source file + * @param topBuildDirectory The top build directory of the project. This is + * the working directory for the tool. + * @return IPath[] + */ + public IPath[] findDependencies( + IPath source, + IManagedBuildInfo info, + ITool tool, + IPath topBuildDirectory); + + /** + * + * Returns the command line to be used to calculate dependencies. + * This currently supports compilers that generate .d files + * + * @param source The source file for which dependencies should be calculated + * @param info The IManagedBuildInfo of the project + * @param tool The tool associated with the source file + * @param topBuildDirectory The top build directory of the project. This is + * the working directory for the tool. + * + * @return String + */ + public String getDependencyCommand( + IPath source, + IManagedBuildInfo info, + ITool tool, + IPath topBuildDirectory); +} 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 c8361e74f31..b91989bbdfd 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 @@ -33,6 +33,7 @@ import java.util.Vector; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.internal.core.model.Util; import org.eclipse.cdt.managedbuilder.core.BuildException; +import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; @@ -43,6 +44,7 @@ import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOutputType; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages; @@ -1849,6 +1851,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { protected void addFragmentMakefileEntriesForSource (LinkedHashMap buildVarToRuleStringMap, StringBuffer ruleBuffer, 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(); ITool tool = null; @@ -1865,29 +1868,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { if (tool == null) { tool = buildTools[j]; } - // look for the extension in the map - if (varName == null) { - varName = getSourceMacroName(ext).toString(); - // Add the resource to the list of all resources associated with a variable. - List varList = (List)buildSrcVars.get(varName); - // Since we don't know how these files will be used, we store them using a "location" - // path rather than a relative path - varList.add(sourceLocation); - } else { - // Add the resource to the list of all resources associated with a variable. - List varList = (List)buildOutVars.get(varName); - if (varList != null) { - // Since we don't know how these files will be used, we store them using a "location" - // path rather than a relative path - varList.add(sourceLocation); - } - } - if (!buildVarToRuleStringMap.containsKey(varName)) { - // TODO - is this an error? - } else { - // Add the resource name to the makefile line that adds resources to the build variable - addMacroAdditionFile(buildVarToRuleStringMap, varName, relativePath, sourceLocation, generatedSource); - } + addToBuildVar(buildVarToRuleStringMap, ext, varName, relativePath, sourceLocation, generatedSource); break; } } @@ -1956,8 +1937,17 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { } } } else { + // If this is a secondary input, add it to build vars + if (varName == null) { + for (int j=0; j 0) { if (isSecondaryOutputVar(secondaryOutputs, varName)) { @@ -1967,6 +1957,44 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { } } } + + /* (non-Javadoc) + * Adds the source file to the appropriate build variable + * + * @param buildVarToRuleStringMap map of build variable names to the list of files assigned to the variable + * @param ext the file extension of the file + * @param varName the build variable to add this invocation's outputs to + * if null, use the file extension to find the name + * @param relativePath build output directory relative path of the current output directory + * @param sourceLocation the full path of the source + * @param generatedSource if true, this file was generated by another tool in the tool-chain + */ + protected void addToBuildVar (LinkedHashMap buildVarToRuleStringMap, String ext, + String varName, String relativePath, IPath sourceLocation, boolean generatedSource) { + // look for the extension in the map + if (varName == null) { + varName = getSourceMacroName(ext).toString(); + // Add the resource to the list of all resources associated with a variable. + List varList = (List)buildSrcVars.get(varName); + // Since we don't know how these files will be used, we store them using a "location" + // path rather than a relative path + varList.add(sourceLocation); + } else { + // Add the resource to the list of all resources associated with a variable. + List varList = (List)buildOutVars.get(varName); + if (varList != null) { + // Since we don't know how these files will be used, we store them using a "location" + // path rather than a relative path + varList.add(sourceLocation); + } + } + if (!buildVarToRuleStringMap.containsKey(varName)) { + // TODO - is this an error? + } else { + // Add the resource name to the makefile line that adds resources to the build variable + addMacroAdditionFile(buildVarToRuleStringMap, varName, relativePath, sourceLocation, generatedSource); + } + } /* (non-Javadoc) * Create a rule for this source file. We create a pattern rule if possible. @@ -2177,7 +2205,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { if (!addlPath.isAbsolute()) { IPath tempPath = project.getLocation().append(addlPath); if (tempPath != null) { - addlPath = calculateRelativePath(getTopBuildDir(), tempPath); + addlPath = ManagedBuildManager.calculateRelativePath(getTopBuildDir(), tempPath); } } } @@ -2206,16 +2234,9 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { buffer.append(TAB + AT + ECHO + WHITESPACE + SINGLE_QUOTE + tool.getAnnouncement() + SINGLE_QUOTE + NEWLINE); outflag = tool.getOutputFlag(); outputPrefix = tool.getOutputPrefix(); - String[] flags = null; - try { - flags = tool.getToolCommandFlags(sourceLocation, outputLocation); - } catch( BuildException ex ) { - // TODO add some routines to catch this - flags = EMPTY_STRING_ARRAY; - } // Other additional inputs // Get any additional dependencies specified for the tool in other InputType elements and AdditionalInput elements - IPath[] addlInputPaths = tool.getAdditionalResources(); + IPath[] addlInputPaths = getAdditionalResourcesForSource(tool); for (int i=0; i 0) { + allRes.add(Path.fromOSString("$(" + type.getBuildVariable() + ")")); //$NON-NLS-1$ //$NON-NLS-2$ + } else { + // Use file extensions + String[] typeExts = type.getSourceExtensions(tool); + for (int j=0; j 0) b = true; + if (toolParent instanceof IToolChain) { + IConfiguration config = ((IToolChain)toolParent).getParent(); + if (config != null) { + ManagedBuildManager.setOption(config, tool, assignToOption, b); + } + } else if (toolParent instanceof IResourceConfiguration) { + ManagedBuildManager.setOption(((IResourceConfiguration)toolParent), tool, assignToOption, b); + } + } else if (optType == IOption.ENUMERATED) { + if (allRes.size() > 0) { + String s = allRes.get(0).toString(); + if (toolParent instanceof IToolChain) { + IConfiguration config = ((IToolChain)toolParent).getParent(); + if (config != null) { + ManagedBuildManager.setOption(config, tool, assignToOption, s); + } + } else if (toolParent instanceof IResourceConfiguration) { + ManagedBuildManager.setOption(((IResourceConfiguration)toolParent), tool, assignToOption, s); + } + } + } + allRes.clear(); + } + } catch( BuildException ex ) { + } + } + } + } + return (IPath[])allRes.toArray(new IPath[allRes.size()]); + } + + /* (non-Javadoc) * Returns the output IPaths for this invocation of the tool with the specified source file /* @@ -2591,7 +2755,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { if (res[i] != null) { IPath addlPath = res[i].getLocation(); if (addlPath != null) { - dep = calculateRelativePath(getTopBuildDir(), addlPath); + dep = ManagedBuildManager.calculateRelativePath(getTopBuildDir(), addlPath); } } if (dep != null) { @@ -3439,36 +3603,4 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { 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 b25c9388d3a..0101f49c651 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 @@ -93,10 +93,12 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo { return inputsCalculated; } + // Command inputs are top build directory relative public Vector getCommandInputs() { return commandInputs; } + // Enumerated inputs are project relative public Vector getEnumeratedInputs() { return enumeratedInputs; } @@ -105,6 +107,7 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo { return outputsCalculated; } + // Command outputs are top build directory relative public Vector getCommandOutputs() { return commandOutputs; } @@ -164,10 +167,14 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo { if (inTypes != null && inTypes.length > 0) { for (int i=0; i 0) { String cmdVariable = variable = "$(" + variable + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - myCommandInputs.add(cmdVariable); + itCommandInputs.add(cmdVariable); if (primaryInput) { - myCommandDependencies.add(0, cmdVariable); + itCommandDependencies.add(0, cmdVariable); } else { - myCommandDependencies.add(cmdVariable); + itCommandDependencies.add(cmdVariable); } // If there is an output variable with the same name, get // the files associated with it. - List outMacroList = makeGen.getBuildVariableList(variable, GnuMakefileGenerator.PROJECT_SUBDIR_RELATIVE, - makeGen.getBuildWorkingDir(), true); + List outMacroList = makeGen.getBuildVariableList(variable, GnuMakefileGenerator.PROJECT_RELATIVE, + null, true); if (outMacroList != null) { - myEnumeratedInputs.addAll(outMacroList); + itEnumeratedInputs.addAll(outMacroList); } else { // If "last chance", then calculate using file extensions below if (lastChance) { @@ -239,7 +246,7 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo { // Use file extensions if (variable.length() == 0 || useFileExts) { //if (type.getMultipleOfType()) { - // Calculate myEnumeratedInputs using the file extensions and the resources in the project + // Calculate EnumeratedInputs using the file extensions and the resources in the project // Note: This is only correct for tools with multipleOfType == true, but for other tools // it gives us an input resource for generating default names // Determine the set of source input macros to use @@ -262,22 +269,17 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo { if(!handledInputExtensions.contains(fileExt)) { handledInputExtensions.add(fileExt); String buildMacro = "$(" + makeGen.getSourceMacroName(fileExt).toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - myCommandInputs.add(buildMacro); + itCommandInputs.add(buildMacro); if (primaryInput) { - myCommandDependencies.add(0, buildMacro); + itCommandDependencies.add(0, buildMacro); } else { - myCommandDependencies.add(buildMacro); + itCommandDependencies.add(buildMacro); } } } - if (type.getMultipleOfType() || myEnumeratedInputs.size() == 0) { - // Return a path that is relative to the build directory - IPath resPath = projResources[j].getLocation(); - IPath bldLocation = project.getLocation().append(makeGen.getBuildWorkingDir()); - if (bldLocation.isPrefixOf(resPath)) { - resPath = resPath.removeFirstSegments(bldLocation.segmentCount()).setDevice(null); - } - myEnumeratedInputs.add(resPath.toString()); + if (type.getMultipleOfType() || itEnumeratedInputs.size() == 0) { + // Add a path that is relative to the project directory + itEnumeratedInputs.add(projResources[j].getProjectRelativePath().toString()); } break; } @@ -300,30 +302,82 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo { String[] paths = addlInput.getPaths(); if (paths != null) { for (int k = 0; k < paths.length; k++) { + String path = paths[k]; + itEnumeratedInputs.add(path); // 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(); + path = ManagedBuildManager.calculateRelativePath(makeGen.getTopBuildDir(), addlPath).toString(); } } } - myCommandInputs.add(path); - myEnumeratedInputs.add(path); + itCommandInputs.add(path); } } } } } + + // If the assignToOption attribute is specified, set the input(s) as the value of that option + if (assignToOption != null && option == null) { + try { + int optType = assignToOption.getValueType(); + if (optType == IOption.STRING) { + String optVal = ""; //$NON-NLS-1$ + for (int j=0; j 0) { + ManagedBuildManager.setOption(config, tool, assignToOption, true); + } else { + ManagedBuildManager.setOption(config, tool, assignToOption, false); + } + } else if (optType == IOption.ENUMERATED) { + if (itCommandInputs.size() > 0) { + ManagedBuildManager.setOption(config, tool, assignToOption, (String)itCommandInputs.firstElement()); + } + } + itCommandInputs.removeAllElements(); + //itEnumeratedInputs.removeAllElements(); + } catch( BuildException ex ) { + } + } + + myCommandInputs.addAll(itCommandInputs); + myCommandDependencies.addAll(itCommandDependencies); + myEnumeratedInputs.addAll(itEnumeratedInputs); } } else { // For support of pre-CDT 3.0 integrations. if (bIsTargetTool) { - // NOTE WELL: This only suuports the case of a single "target tool" + // NOTE WELL: This only supports the case of a single "target tool" // with the following characteristics: // 1. The tool consumes exactly all of the object files produced // by other tools in the build and produces a single output @@ -736,7 +790,7 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo { if (addlResource != null) { IPath addlPath = addlResource.getLocation(); if (addlPath != null) { - path = makeGen.calculateRelativePath(makeGen.getTopBuildDir(), addlPath).toString(); + path = ManagedBuildManager.calculateRelativePath(makeGen.getTopBuildDir(), addlPath).toString(); } } }