1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Add support for InputType, assignToOption attribute

This commit is contained in:
Leo Treggiari 2005-09-27 23:34:12 +00:00
parent bbe7b9da0e
commit 397635f067
12 changed files with 566 additions and 158 deletions

View file

@ -716,7 +716,14 @@
<attribute name="option" type="string">
<annotation>
<documentation>
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.
</documentation>
</annotation>
</attribute>
<attribute name="assignToOption" type="string">
<annotation>
<documentation>
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.
</documentation>
</annotation>
</attribute>

View file

@ -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 <code>true</code> if this inputType can contain multiple input
* resources, else <code>false</code>. The inputs can be project resources,

View file

@ -635,6 +635,17 @@ public interface ITool extends IBuildObject, IHoldsOptions {
* @return boolean
*/
public boolean buildsFileType(String extension);
/**
* Return <code>true</code> if the receiver uses files with the
* specified extension as input, else <code>false</code>. 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 <code>true</code> if the tool considers the file extension to be

View file

@ -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;
}
}

View file

@ -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()
*/

View file

@ -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$
}
/*

View file

@ -1487,7 +1487,7 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory {
IInputType[] types = getInputTypes();
for (int i=0; i<types.length; i++) {
IInputType type = types[i];
// Additional dependencies come from 2 places.
// Additional resources come from 2 places.
// 1. From AdditionalInput childen
IPath[] res = type.getAdditionalResources();
for (int j=0; j<res.length; j++) {
@ -2216,10 +2216,44 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory {
if (extension == null) {
return false;
}
if (getInputType(extension) != null) {
IInputType it = getInputType(extension);
if (it != null) {
// Decide whether we "build" this type of file
//
// 1. If this is the primary input, yes
if (it == getPrimaryInputType()) {
return true;
}
// 2. If the option attribute is specified, no
if (it.getOptionId() != null && it.getOptionId().length() > 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);
}

View file

@ -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)
*/

View file

@ -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();

View file

@ -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);
}

View file

@ -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<buildTools.length; j++) {
if (buildTools[j].isInputFileType(ext)) {
addToBuildVar(buildVarToRuleStringMap, ext, varName, relativePath, sourceLocation, generatedSource);
break;
}
}
}
// If this generated output is identified as a secondary output, add the file to the build variable
if (varName != null) {
else {
IOutputType[] secondaryOutputs = config.getToolChain().getSecondaryOutputs();
if (secondaryOutputs.length > 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 <code>null</code>, 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 <code>true</code>, 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<addlInputPaths.length; i++) {
// Translate the path from project relative to
// build directory relative
@ -2224,12 +2245,20 @@ 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);
}
}
}
inputs.add(addlPath.toString());
}
String[] flags = null;
// Get the tool command line options
try {
flags = tool.getToolCommandFlags(sourceLocation, outputLocation);
} catch( BuildException ex ) {
// TODO add some routines to catch this
flags = EMPTY_STRING_ARRAY;
}
// Call the command line generator
IManagedCommandLineGenerator cmdLGen = tool.getCommandLineGenerator();
cmdLInfo = cmdLGen.generateCommandLineInfo( tool, cmd, flags, outflag, outputPrefix,
@ -2240,17 +2269,11 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
buffer.append(TAB + AT + buildCmd);
} else {
buffer.append(TAB + AT + ECHO + WHITESPACE + SINGLE_QUOTE + tool.getAnnouncement() + SINGLE_QUOTE + NEWLINE);
String buildFlags = EMPTY_STRING;
try {
buildFlags = tool.getToolCommandFlagsString(sourceLocation, outputLocation);
} catch (BuildException e) {
}
outflag = info.getOutputFlag(outputExtension);
outputPrefix = info.getOutputPrefix(outputExtension);
String[] flags = buildFlags.split( "\\s" ); //$NON-NLS-1$
// 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<addlInputPaths.length; i++) {
// Translate the path from project relative to
// build directory relative
@ -2259,12 +2282,19 @@ 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);
}
}
}
inputs.add(addlPath.toString());
}
// Get the tool command line options
String buildFlags = EMPTY_STRING;
try {
buildFlags = tool.getToolCommandFlagsString(sourceLocation, outputLocation);
} catch (BuildException e) {
}
String[] flags = buildFlags.split( "\\s" ); //$NON-NLS-1$
// Call the command line generator
cmdLInfo = info.generateToolCommandLineInfo( inputExtension, flags, outflag, outputPrefix,
OUT_MACRO + otherPrimaryOutputs, (String[])inputs.toArray(new String[inputs.size()]), sourceLocation, outputLocation );
@ -2344,6 +2374,140 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
}
/* (non-Javadoc)
* Returns any additional resources specified for the tool in other InputType elements and AdditionalInput elements
*/
protected IPath[] getAdditionalResourcesForSource(ITool tool) {
List allRes = new ArrayList();
IInputType[] types = tool.getInputTypes();
for (int i=0; i<types.length; i++) {
IInputType type = types[i];
// Additional resources come from 2 places.
// 1. From AdditionalInput childen
IPath[] res = type.getAdditionalResources();
for (int j=0; j<res.length; j++) {
allRes.add(res[j]);
}
// 2. From InputTypes that other than the primary input type
if (type != tool.getPrimaryInputType()) {
String var = type.getBuildVariable();
if (var != null && var.length() > 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<projectResources.length; j++) {
if (projectResources[j].getType() == IResource.FILE) {
String fileExt = projectResources[j].getFileExtension();
if(fileExt == null) {
fileExt = ""; //$NON-NLS-1$
}
for (int k=0; k<typeExts.length; k++) {
if (fileExt.equals(typeExts[k])) {
allRes.add(projectResources[j].getProjectRelativePath());
break;
}
}
}
}
}
// If an assignToOption has been specified, set the value of the option to the inputs
IOption assignToOption = tool.getOptionBySuperClassId(type.getAssignToOptionId());
IOption option = tool.getOptionBySuperClassId(type.getOptionId());
if (assignToOption != null && option == null) {
try {
int optType = assignToOption.getValueType();
IBuildObject toolParent = tool.getParent();
if (toolParent != null) {
if (optType == IOption.STRING) {
String optVal = ""; //$NON-NLS-1$
for (int j=0; j<allRes.size(); j++) {
if (j != 0) {
optVal += " "; //$NON-NLS-1$
}
String resPath = allRes.get(j).toString();
if (!resPath.startsWith("$(")) { //$NON-NLS-1$
IResource addlResource = project.getFile(resPath);
if (addlResource != null) {
IPath addlPath = addlResource.getLocation();
if (addlPath != null) {
resPath = ManagedBuildManager.calculateRelativePath(getTopBuildDir(), addlPath).toString();
}
}
}
optVal += ManagedBuildManager.calculateRelativePath(getTopBuildDir(), Path.fromOSString(resPath)).toString();
}
if (toolParent instanceof IToolChain) {
IConfiguration config = ((IToolChain)toolParent).getParent();
if (config != null) {
ManagedBuildManager.setOption(config, tool, assignToOption, optVal);
}
} else if (toolParent instanceof IResourceConfiguration) {
ManagedBuildManager.setOption(((IResourceConfiguration)toolParent), tool, assignToOption, optVal);
}
} else if (
optType == IOption.STRING_LIST ||
optType == IOption.LIBRARIES ||
optType == IOption.OBJECTS) {
// Note that the path(s) must be translated from project relative
// to top build directory relative
String[] paths = new String[allRes.size()];
for (int j=0; j<allRes.size(); j++) {
paths[j] = allRes.get(j).toString();
if (!paths[j].startsWith("$(")) { //$NON-NLS-1$
IResource addlResource = project.getFile(paths[j]);
if (addlResource != null) {
IPath addlPath = addlResource.getLocation();
if (addlPath != null) {
paths[j] = ManagedBuildManager.calculateRelativePath(getTopBuildDir(), addlPath).toString();
}
}
}
}
if (toolParent instanceof IToolChain) {
IConfiguration config = ((IToolChain)toolParent).getParent();
if (config != null) {
ManagedBuildManager.setOption(config, tool, assignToOption, paths);
}
} else if (toolParent instanceof IResourceConfiguration) {
ManagedBuildManager.setOption(((IResourceConfiguration)toolParent), tool, assignToOption, paths);
}
} else if (optType == IOption.BOOLEAN) {
boolean b = false;
if (allRes.size() > 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 <code>IPath</code>s 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;
}
}

View file

@ -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<inTypes.length; i++) {
IInputType type = inTypes[i];
Vector itCommandInputs = new Vector(); // Inputs for the tool command line for this input-type
Vector itCommandDependencies = new Vector(); // Dependencies for the make rule for this input-type
Vector itEnumeratedInputs = new Vector(); // Complete list of individual inputs for this input-type
String variable = type.getBuildVariable();
boolean primaryInput = type.getPrimaryInput();
boolean useFileExts = false;
IOption option = tool.getOptionBySuperClassId(type.getOptionId());
IOption assignToOption = tool.getOptionBySuperClassId(type.getAssignToOptionId());
// Option?
if (option != null) {
@ -198,33 +205,33 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo {
}
if (primaryInput) {
myCommandDependencies.add(j, inputName);
itCommandDependencies.add(j, inputName);
} else {
myCommandDependencies.add(inputName);
itCommandDependencies.add(inputName);
}
// NO - myCommandInputs.add(inputName);
// NO - myEnumeratedInputs.add(inputName);
// NO - itCommandInputs.add(inputName);
// NO - itEnumeratedInputs.add(inputName);
}
} catch( BuildException ex ) {
}
} else {
// Build Variable?
if (variable.length() > 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<itCommandInputs.size(); j++) {
if (j != 0) {
optVal += " "; //$NON-NLS-1$
}
optVal += itCommandInputs.get(j);
}
ManagedBuildManager.setOption(config, tool, assignToOption, optVal);
} else if (
optType == IOption.STRING_LIST ||
optType == IOption.LIBRARIES ||
optType == IOption.OBJECTS) {
// Mote that when using the enumerated inputs, the path(s) must be translated from project relative
// to top build directory relative
String[] paths = new String[itEnumeratedInputs.size()];
for (int j=0; j<itEnumeratedInputs.size(); j++) {
paths[j] = (String)itEnumeratedInputs.get(j);
IResource enumResource = project.getFile(paths[j]);
if (enumResource != null) {
IPath enumPath = enumResource.getLocation();
if (enumPath != null) {
paths[j] = ManagedBuildManager.calculateRelativePath(makeGen.getTopBuildDir(), enumPath).toString();
}
}
}
ManagedBuildManager.setOption(config, tool, assignToOption, paths);
} else if (optType == IOption.BOOLEAN) {
if (itEnumeratedInputs.size() > 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();
}
}
}