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

Bug fix patch from Bob Monteleone

Fixes to make file generation
This commit is contained in:
Leo Treggiari 2005-05-23 20:30:12 +00:00
parent d916648fee
commit d2122bb6df
5 changed files with 109 additions and 72 deletions

View file

@ -68,7 +68,8 @@ public class GeneratedMakefileBuilder extends ACBuilder {
public class ResourceDeltaVisitor implements IResourceDeltaVisitor { public class ResourceDeltaVisitor implements IResourceDeltaVisitor {
private String buildGoalName; private String buildGoalName;
private IManagedBuildInfo buildInfo; private IManagedBuildInfo buildInfo;
private boolean buildNeeded = true; private boolean incrBuildNeeded = false;
private boolean fullBuildNeeded = false;
private List reservedNames; private List reservedNames;
/** /**
@ -103,7 +104,7 @@ public class GeneratedMakefileBuilder extends ACBuilder {
} }
if (ext.length() > 0) { if (ext.length() > 0) {
buildGoalName = buildInfo.getOutputPrefix(ext) + name + "." + ext; //$NON-NLS-1$ buildGoalName = buildInfo.getOutputPrefix(ext) + name + IManagedBuilderMakefileGenerator.DOT + ext;
} else { } else {
buildGoalName = name; buildGoalName = name;
} }
@ -135,8 +136,12 @@ public class GeneratedMakefileBuilder extends ACBuilder {
return reservedNames.contains(resource.getName()); return reservedNames.contains(resource.getName());
} }
public boolean shouldBuild() { public boolean shouldBuildIncr() {
return buildNeeded; return incrBuildNeeded;
}
public boolean shouldBuildFull() {
return fullBuildNeeded;
} }
public boolean visit(IResourceDelta delta) throws CoreException { public boolean visit(IResourceDelta delta) throws CoreException {
@ -151,28 +156,53 @@ public class GeneratedMakefileBuilder extends ACBuilder {
} else { } else {
String name = changedResource.getName(); String name = changedResource.getName();
String ext = changedResource.getFileExtension(); String ext = changedResource.getFileExtension();
// There are some things we don't care about and some we do
if (name.equals(buildGoalName)) { if ((!name.equals(buildGoalName) &&
buildNeeded = true; // TODO: Also need to check for secondary outputs
break; (changedResource.isDerived() ||
} else if (resource.isDerived()) { (isProjectFile(changedResource)) ||
buildNeeded |= false; (isGeneratedResource(changedResource))))) {
} else if (isGeneratedResource(changedResource)) { // The resource that changed has attributes which make it uninteresting,
buildNeeded |= false; // so don't do anything
} else if (buildInfo.buildsFileType(ext) || buildInfo.isHeaderFile(ext)) { ;
// We do care and there is no point checking anythings else }
buildNeeded = true; else {
break; // TODO: Should we do extra checks here to determine if a build is really needed,
} else if (isProjectFile(changedResource)) { // or do you just do exclusion checks like above?
buildNeeded |= false; // We could check for:
} else { // o The build goal name
buildNeeded = true; // o A secondary output
// o An input file to a tool:
// o Has an extension of a source file used by a tool
// o Has an extension of a header file used by a tool
// o Has the name of an input file specified in an InputType via:
// o An Option
// o An AdditionalInput
//
//if (resourceName.equals(buildGoalName) ||
// (buildInfo.buildsFileType(ext) || buildInfo.isHeaderFile(ext))) {
// We need to do an incremental build, at least
incrBuildNeeded = true;
if (kids[index].getKind() == IResourceDelta.REMOVED) {
// If a meaningful resource was removed, then force a full build
// This is required because an incremental build will trigger make to
// do nothing for a missing source, since the state after the file
// removal is uptodate, as far as make is concerned
// A full build will clean, and ultimately trigger a relink without
// the object generated from the deleted source, which is what we want
fullBuildNeeded = true;
// There is no point in checking anything else since we have
// decided to do a full build anyway
break;
}
//}
} }
} }
} }
return false; return false;
} }
return true; return true;
} }
} }
@ -275,7 +305,10 @@ public class GeneratedMakefileBuilder extends ACBuilder {
} }
else { else {
delta.accept(visitor); delta.accept(visitor);
if (visitor.shouldBuild()) { if (visitor.shouldBuildFull()) {
outputTrace(getProject().getName(), "Incremental build requested, full build needed"); //$NON-NLS-1$
fullBuild(info, generator, monitor);
} else if (visitor.shouldBuildIncr()) {
outputTrace(getProject().getName(), "Incremental build requested"); //$NON-NLS-1$ outputTrace(getProject().getName(), "Incremental build requested"); //$NON-NLS-1$
incrementalBuild(delta, info, generator, monitor); incrementalBuild(delta, info, generator, monitor);
} }

View file

@ -718,19 +718,7 @@ public class InputType extends BuildObject implements IInputType {
if (superClass != null) { if (superClass != null) {
return superClass.getBuildVariable(); return superClass.getBuildVariable();
} else { } else {
if (getMultipleOfType()) { return EMPTY_STRING;
// Use default name
String name = getName();
if (name == null || name.length() == 0) {
name = getId();
}
String defaultName = name.toUpperCase();
defaultName = defaultName.replaceAll("\\W", "_"); //$NON-NLS-1$ //$NON-NLS-2$
defaultName += "_INPUTS"; //$NON-NLS-1$
return defaultName;
} else {
return EMPTY_STRING;
}
} }
} }
return buildVariable; return buildVariable;

View file

@ -74,7 +74,11 @@ public class ManagedCommandLineGenerator implements
int start = 0; int start = 0;
int stop = 0; int stop = 0;
while( (start = commandLinePattern.indexOf( VAR_FIRST_CHAR, start )) >= 0 ) { while( (start = commandLinePattern.indexOf( VAR_FIRST_CHAR, start )) >= 0 ) {
if( commandLinePattern.charAt( start + 1 ) != VAR_SECOND_CHAR ) continue; if( commandLinePattern.charAt( start + 1 ) != VAR_SECOND_CHAR ) {
sb.append(VAR_FIRST_CHAR);
start++;
continue;
}
if( start > stop ) { if( start > stop ) {
sb.append( commandLinePattern.substring(stop, start) ); sb.append( commandLinePattern.substring(stop, start) );
} }

View file

@ -20,6 +20,10 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; // Note: We use LinkedHashMap instead of HashMap
// only to keep the generation of makefiles constant
// for our test set. Make itself doesn't care
// about the order.
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -275,7 +279,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
// Maps of macro names (String) to values (List) // Maps of macro names (String) to values (List)
private HashMap buildSrcVars = new HashMap(); private HashMap buildSrcVars = new HashMap();
private HashMap buildOutVars = new HashMap(); private HashMap buildOutVars = new HashMap();
private HashMap topBuildOutVars = new HashMap(); private LinkedHashMap topBuildOutVars = new LinkedHashMap();
public GnuMakefileGenerator() { public GnuMakefileGenerator() {
super(); super();
@ -1582,22 +1586,24 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
for (int i=0; i<outTypes.length; i++) { for (int i=0; i<outTypes.length; i++) {
String[] outExts = outTypes[i].getOutputExtensions(); String[] outExts = outTypes[i].getOutputExtensions();
String outVariable = outTypes[i].getBuildVariable(); String outVariable = outTypes[i].getBuildVariable();
for (int j=0; j<outExts.length; j++) { if (outExts != null) {
for (int k=0; k<buildTools.length; k++) { for (int j=0; j<outExts.length; j++) {
ITool tool = buildTools[k]; for (int k=0; k<buildTools.length; k++) {
if (!buildToolsUsed[k]) { ITool tool = buildTools[k];
// Also has to match build variables if specified if (!buildToolsUsed[k]) {
IInputType inType = tool.getInputType(outExts[j]); // Also has to match build variables if specified
if (inType != null) { IInputType inType = tool.getInputType(outExts[j]);
String inVariable = inType.getBuildVariable(); if (inType != null) {
if ((outVariable == null && inVariable == null) || String inVariable = inType.getBuildVariable();
(outVariable != null && inVariable != null && if ((outVariable == null && inVariable == null) ||
outVariable.equals(inVariable))) { (outVariable != null && inVariable != null &&
if (addRuleForTool(buildTools[k], buffer, false, null, null, outVariable.equals(inVariable))) {
outputVarsAdditionsList, null, false)) { if (addRuleForTool(buildTools[k], buffer, false, null, null,
buildToolsUsed[k] = true; outputVarsAdditionsList, null, false)) {
// Look for tools that consume the output buildToolsUsed[k] = true;
generateRulesForConsumers(buildTools[k], outputVarsAdditionsList, buffer); // Look for tools that consume the output
generateRulesForConsumers(buildTools[k], outputVarsAdditionsList, buffer);
}
} }
} }
} }
@ -1759,7 +1765,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
// For build macros in the configuration, create a map which will map them // For build macros in the configuration, create a map which will map them
// to a string which holds its list of sources. // to a string which holds its list of sources.
HashMap buildVarToRuleStringMap = new HashMap(); LinkedHashMap buildVarToRuleStringMap = new LinkedHashMap();
// Add statements that add the source files in this folder, // Add statements that add the source files in this folder,
// and generated source files, and generated dependency files // and generated source files, and generated dependency files
@ -1817,7 +1823,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
* @param varName the build variable to add this invocation's outputs to * @param varName the build variable to add this invocation's outputs to
* if <code>null</code>, use the file extension to find the name * if <code>null</code>, use the file extension to find the name
*/ */
protected void addFragmentMakefileEntriesForSource (HashMap buildVarToRuleStringMap, StringBuffer ruleBuffer, protected void addFragmentMakefileEntriesForSource (LinkedHashMap buildVarToRuleStringMap, StringBuffer ruleBuffer,
IFolder folder, String relativePath, IResource resource, String varName, boolean generatedSource) { IFolder folder, String relativePath, IResource resource, String varName, boolean generatedSource) {
// Determine which tool, if any, builds files with this extension // Determine which tool, if any, builds files with this extension
String ext = resource.getFileExtension(); String ext = resource.getFileExtension();
@ -1848,8 +1854,9 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
addMacroAdditionFile(buildVarToRuleStringMap, varName, relativePath, resource, generatedSource); addMacroAdditionFile(buildVarToRuleStringMap, varName, relativePath, resource, generatedSource);
// Generate the rule to build this source file // Generate the rule to build this source file
IInputType primaryInputType = tool.getPrimaryInputType();
IInputType inputType = tool.getInputType(ext); IInputType inputType = tool.getInputType(ext);
if ((inputType != null && !inputType.getMultipleOfType()) || if ((primaryInputType != null && !primaryInputType.getMultipleOfType()) ||
(inputType == null && !(tool == info.getToolFromOutputExtension(buildTargetExt)))) { (inputType == null && !(tool == info.getToolFromOutputExtension(buildTargetExt)))) {
// Try to add the rule for the file // Try to add the rule for the file
@ -2530,7 +2537,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
* C_SRCS += \ * C_SRCS += \
* ${addprefix $(ROOT)/, \ * ${addprefix $(ROOT)/, \
*/ */
protected void addMacroAdditionPrefix(HashMap map, String macroName, String relativePath, boolean addPrefix) { protected void addMacroAdditionPrefix(LinkedHashMap map, String macroName, String relativePath, boolean addPrefix) {
// there is no entry in the map, so create a buffer for this macro // there is no entry in the map, so create a buffer for this macro
StringBuffer tempBuffer = new StringBuffer(); StringBuffer tempBuffer = new StringBuffer();
tempBuffer.append(macroName + WHITESPACE + MACRO_ADDITION_PREFIX_SUFFIX); tempBuffer.append(macroName + WHITESPACE + MACRO_ADDITION_PREFIX_SUFFIX);
@ -2600,7 +2607,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
/* (non-Javadoc) /* (non-Javadoc)
* Write all macro addition entries in a map to the buffer * Write all macro addition entries in a map to the buffer
*/ */
protected StringBuffer writeAdditionMacros(HashMap map) { protected StringBuffer writeAdditionMacros(LinkedHashMap map) {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
// Add the comment // Add the comment
buffer.append(COMMENT_SYMBOL + WHITESPACE + ManagedMakeMessages.getResourceString(MOD_VARS) + NEWLINE); buffer.append(COMMENT_SYMBOL + WHITESPACE + ManagedMakeMessages.getResourceString(MOD_VARS) + NEWLINE);
@ -2710,7 +2717,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
} }
// Initialize the build output variable to file additions map // Initialize the build output variable to file additions map
HashMap map = getTopBuildOutputVars(); LinkedHashMap map = getTopBuildOutputVars();
Iterator iterator = buildOutVars.entrySet().iterator(); Iterator iterator = buildOutVars.entrySet().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry)iterator.next(); Map.Entry entry = (Map.Entry)iterator.next();
@ -2832,7 +2839,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
* *
* @return HashMap * @return HashMap
*/ */
public HashMap getTopBuildOutputVars() { public LinkedHashMap getTopBuildOutputVars() {
return topBuildOutVars; return topBuildOutVars;
} }

View file

@ -220,24 +220,30 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo {
// Calculate myEnumeratedInputs using the file extensions and the resources in the project // Calculate myEnumeratedInputs using the file extensions and the resources in the project
// Note: This is only correct for tools with multipleOfType == true, but for other tools // Note: This is only correct for tools with multipleOfType == true, but for other tools
// it gives us an input resource for generating default names // it gives us an input resource for generating default names
String[] exts = tool.getAllInputExtensions(); // Determine the set of source input macros to use
HashSet handledInputExtensions = new HashSet();
String[] exts = type.getSourceExtensions();
if (projResources != null) { if (projResources != null) {
for (int j=0; j<projResources.length; j++) { for (int j=0; j<projResources.length; j++) {
if (projResources[i].getType() == IResource.FILE) { if (projResources[j].getType() == IResource.FILE) {
String fileExt = projResources[i].getFileExtension(); String fileExt = projResources[j].getFileExtension();
for (int k=0; k<exts.length; k++) { for (int k=0; k<exts.length; k++) {
if (fileExt.equals(exts[k])) { if (fileExt.equals(exts[k])) {
// TODO - is project relative correct? // TODO - is project relative correct?
if (!useFileExts) { if (!useFileExts) {
myCommandInputs.add(projResources[i].getProjectRelativePath()); if(!handledInputExtensions.contains(fileExt)) {
if (primaryInput) { handledInputExtensions.add(fileExt);
myCommandDependencies.add(0, projResources[i].getProjectRelativePath()); String buildMacro = "$(" + makeGen.getSourceMacroName(fileExt).toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
} else { myCommandInputs.add(buildMacro);
myCommandDependencies.add(projResources[i].getProjectRelativePath()); if (primaryInput) {
} myCommandDependencies.add(0, buildMacro);
} else {
myCommandDependencies.add(buildMacro);
}
}
} }
if (type.getMultipleOfType() || myEnumeratedInputs.size() == 0) { if (type.getMultipleOfType() || myEnumeratedInputs.size() == 0) {
myEnumeratedInputs.add(projResources[i].getProjectRelativePath()); myEnumeratedInputs.add(projResources[j].getProjectRelativePath().toString());
} }
break; break;
} }
@ -559,7 +565,6 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo {
if (inTypes != null && inTypes.length > 0) { if (inTypes != null && inTypes.length > 0) {
for (int i=0; i<inTypes.length; i++) { for (int i=0; i<inTypes.length; i++) {
IInputType type = inTypes[i]; IInputType type = inTypes[i];
String variable = type.getBuildVariable();
IManagedDependencyGenerator depGen = type.getDependencyGenerator(); IManagedDependencyGenerator depGen = type.getDependencyGenerator();
if (depGen != null) { if (depGen != null) {