mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Changes to better support output files in non-default locations
Some TODOs remain, particularly, some client interfaces need to change in the future
This commit is contained in:
parent
1a9c0d8eb7
commit
c93b5d938b
6 changed files with 107 additions and 76 deletions
|
@ -673,7 +673,7 @@ public class GeneratedMakefileBuilder extends ACBuilder {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IPath makefile = workingDirectory.addTrailingSeparator().append(generator.getMakefileName());
|
IPath makefile = workingDirectory.append(generator.getMakefileName());
|
||||||
if (root.getFileForLocation(makefile) == null) {
|
if (root.getFileForLocation(makefile) == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -431,7 +431,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
|
||||||
location = new Path("."); //$NON-NLS-1$
|
location = new Path("."); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
IPath root = location.addTrailingSeparator().append(config.getName());
|
IPath root = location.append(config.getName());
|
||||||
ITool[] tools = config.getFilteredTools();
|
ITool[] tools = config.getFilteredTools();
|
||||||
for (int i = 0; i < tools.length; i++) {
|
for (int i = 0; i < tools.length; i++) {
|
||||||
ITool tool = tools[i];
|
ITool tool = tools[i];
|
||||||
|
@ -458,7 +458,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
|
||||||
if (userPath.isAbsolute()) {
|
if (userPath.isAbsolute()) {
|
||||||
paths.add(userPath.toOSString());
|
paths.add(userPath.toOSString());
|
||||||
} else {
|
} else {
|
||||||
IPath absPath = root.addTrailingSeparator().append(userPath);
|
IPath absPath = root.append(userPath);
|
||||||
paths.add(absPath.makeAbsolute().toOSString());
|
paths.add(absPath.makeAbsolute().toOSString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,10 @@ import org.eclipse.core.runtime.MultiStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
|
*
|
||||||
|
* TODO: isGeneratedResource should take an IPath rather than an IResource,
|
||||||
|
* because an output file can be generated outside of the project directory.
|
||||||
|
* This will require a new interface.
|
||||||
*/
|
*/
|
||||||
public interface IManagedBuilderMakefileGenerator {
|
public interface IManagedBuilderMakefileGenerator {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* Copyright (c) 2004 IBM Corporation and others.
|
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Common Public License v1.0
|
* are made available under the terms of the Common Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -16,6 +16,12 @@ import org.eclipse.core.resources.IResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
|
*
|
||||||
|
* TODO: These methods should take IPath's rather than IResource's,
|
||||||
|
* because an output file from one tool can be used as an
|
||||||
|
* input file to another, and it can be generated outside of the
|
||||||
|
* project directory.
|
||||||
|
* This will require a new interface.
|
||||||
*/
|
*/
|
||||||
public interface IManagedDependencyGenerator {
|
public interface IManagedDependencyGenerator {
|
||||||
public int TYPE_NODEPS = 0;
|
public int TYPE_NODEPS = 0;
|
||||||
|
|
|
@ -453,7 +453,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
checkCancel();
|
checkCancel();
|
||||||
|
|
||||||
// Make sure that there is a makefile containing all the folders participating
|
// Make sure that there is a makefile containing all the folders participating
|
||||||
IPath srcsFilePath = topBuildDir.addTrailingSeparator().append(SRCSFILE_NAME);
|
IPath srcsFilePath = topBuildDir.append(SRCSFILE_NAME);
|
||||||
IFile srcsFileHandle = createFile(srcsFilePath);
|
IFile srcsFileHandle = createFile(srcsFilePath);
|
||||||
buildSrcVars.clear();
|
buildSrcVars.clear();
|
||||||
buildOutVars.clear();
|
buildOutVars.clear();
|
||||||
|
@ -472,7 +472,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Make sure a fragment makefile exists
|
// Make sure a fragment makefile exists
|
||||||
IPath fragmentPath = getBuildWorkingDir().append(subdirectory.getProjectRelativePath()).addTrailingSeparator().append(MODFILE_NAME);
|
IPath fragmentPath = getBuildWorkingDir().append(subdirectory.getProjectRelativePath()).append(MODFILE_NAME);
|
||||||
IFile makeFragment = project.getFile(fragmentPath);
|
IFile makeFragment = project.getFile(fragmentPath);
|
||||||
if (!makeFragment.exists()) {
|
if (!makeFragment.exists()) {
|
||||||
// If one or both are missing, then add it to the list to be generated
|
// If one or both are missing, then add it to the list to be generated
|
||||||
|
@ -525,7 +525,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
checkCancel();
|
checkCancel();
|
||||||
|
|
||||||
// Re-create the top-level makefile
|
// Re-create the top-level makefile
|
||||||
IPath makefilePath = topBuildDir.addTrailingSeparator().append(MAKEFILE_NAME);
|
IPath makefilePath = topBuildDir.append(MAKEFILE_NAME);
|
||||||
IFile makefileHandle = createFile(makefilePath);
|
IFile makefileHandle = createFile(makefilePath);
|
||||||
populateTopMakefile(makefileHandle, false);
|
populateTopMakefile(makefileHandle, false);
|
||||||
checkCancel();
|
checkCancel();
|
||||||
|
@ -660,7 +660,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
checkCancel();
|
checkCancel();
|
||||||
|
|
||||||
// Get the list of subdirectories
|
// Get the list of subdirectories
|
||||||
IPath srcsFilePath = topBuildDir.addTrailingSeparator().append(SRCSFILE_NAME);
|
IPath srcsFilePath = topBuildDir.append(SRCSFILE_NAME);
|
||||||
IFile srcsFileHandle = createFile(srcsFilePath);
|
IFile srcsFileHandle = createFile(srcsFilePath);
|
||||||
buildSrcVars.clear();
|
buildSrcVars.clear();
|
||||||
buildOutVars.clear();
|
buildOutVars.clear();
|
||||||
|
@ -687,13 +687,13 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
checkCancel();
|
checkCancel();
|
||||||
|
|
||||||
// Create the top-level makefile
|
// Create the top-level makefile
|
||||||
IPath makefilePath = topBuildDir.addTrailingSeparator().append(MAKEFILE_NAME);
|
IPath makefilePath = topBuildDir.append(MAKEFILE_NAME);
|
||||||
IFile makefileHandle = createFile(makefilePath);
|
IFile makefileHandle = createFile(makefilePath);
|
||||||
populateTopMakefile(makefileHandle, true);
|
populateTopMakefile(makefileHandle, true);
|
||||||
checkCancel();
|
checkCancel();
|
||||||
|
|
||||||
// Now finish up by adding all the object files
|
// Now finish up by adding all the object files
|
||||||
IPath objFilePath = topBuildDir.addTrailingSeparator().append(OBJECTS_MAKFILE);
|
IPath objFilePath = topBuildDir.append(OBJECTS_MAKFILE);
|
||||||
IFile objsFileHandle = createFile(objFilePath);
|
IFile objsFileHandle = createFile(objFilePath);
|
||||||
populateObjectsMakefile(objsFileHandle);
|
populateObjectsMakefile(objsFileHandle);
|
||||||
checkCancel();
|
checkCancel();
|
||||||
|
@ -908,7 +908,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
IPath moduleOutputDir = createDirectory(moduleOutputPath.toString());
|
IPath moduleOutputDir = createDirectory(moduleOutputPath.toString());
|
||||||
|
|
||||||
// Create a module makefile
|
// Create a module makefile
|
||||||
IFile modMakefile = createFile(moduleOutputDir.addTrailingSeparator().append(MODFILE_NAME));
|
IFile modMakefile = createFile(moduleOutputDir.append(MODFILE_NAME));
|
||||||
StringBuffer makeBuf = new StringBuffer();
|
StringBuffer makeBuf = new StringBuffer();
|
||||||
makeBuf.append(addFragmentMakefileHeader());
|
makeBuf.append(addFragmentMakefileHeader());
|
||||||
makeBuf.append(addSources(module));
|
makeBuf.append(addSources(module));
|
||||||
|
@ -1791,7 +1791,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Map.Entry entry = (Map.Entry)iterator.next();
|
Map.Entry entry = (Map.Entry)iterator.next();
|
||||||
String macroName = (String)entry.getKey();
|
String macroName = (String)entry.getKey();
|
||||||
addMacroAdditionPrefix(buildVarToRuleStringMap, macroName, "./" + relativePath, true); //$NON-NLS-1$
|
addMacroAdditionPrefix(buildVarToRuleStringMap, macroName, "./" + relativePath, false); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
// Create an entry for the DEPS macro
|
// Create an entry for the DEPS macro
|
||||||
addMacroAdditionPrefix(buildVarToRuleStringMap, DEPS_MACRO, "./" + relativePath, true); //$NON-NLS-1$
|
addMacroAdditionPrefix(buildVarToRuleStringMap, DEPS_MACRO, "./" + relativePath, true); //$NON-NLS-1$
|
||||||
|
@ -1814,7 +1814,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
if( (resConfig != null) && (resConfig.isExcluded()) )
|
if( (resConfig != null) && (resConfig.isExcluded()) )
|
||||||
continue;
|
continue;
|
||||||
addFragmentMakefileEntriesForSource(buildVarToRuleStringMap, ruleBuffer,
|
addFragmentMakefileEntriesForSource(buildVarToRuleStringMap, ruleBuffer,
|
||||||
folder, relativePath, resource, null, false);
|
folder, relativePath, resource, resource.getLocation(), null, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1830,14 +1830,16 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
* @param ruleBuffer buffer to add generated nmakefile text to
|
* @param ruleBuffer buffer to add generated nmakefile text to
|
||||||
* @param folder the top level build output directory
|
* @param folder the top level build output directory
|
||||||
* @param relativePath build output directory relative path of the current output directory
|
* @param relativePath build output directory relative path of the current output directory
|
||||||
* @param resource the source file for this invocation of the tool
|
* @param resource the source file for this invocation of the tool - this may be null for a generated output
|
||||||
|
* @param sourceLocation the full path of the source
|
||||||
* @param 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
|
||||||
|
* @param generatedSource if <code>true</code>, this file was generated by another tool in the tool-chain
|
||||||
*/
|
*/
|
||||||
protected void addFragmentMakefileEntriesForSource (LinkedHashMap 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, IPath sourceLocation, 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 = sourceLocation.getFileExtension();
|
||||||
boolean toolFound = false;
|
boolean toolFound = false;
|
||||||
for (int j=0; j<buildTools.length; j++) {
|
for (int j=0; j<buildTools.length; j++) {
|
||||||
if (buildTools[j].buildsFileType(ext)) {
|
if (buildTools[j].buildsFileType(ext)) {
|
||||||
|
@ -1851,14 +1853,14 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
List varList = (List)buildSrcVars.get(varName);
|
List varList = (List)buildSrcVars.get(varName);
|
||||||
// Since we don't know how these files will be used, we store them using a "location"
|
// Since we don't know how these files will be used, we store them using a "location"
|
||||||
// path rather than a relative path
|
// path rather than a relative path
|
||||||
varList.add(resource.getLocation());
|
varList.add(sourceLocation);
|
||||||
} else {
|
} else {
|
||||||
// Add the resource to the list of all resources associated with a variable.
|
// Add the resource to the list of all resources associated with a variable.
|
||||||
List varList = (List)buildOutVars.get(varName);
|
List varList = (List)buildOutVars.get(varName);
|
||||||
if (varList != null) {
|
if (varList != null) {
|
||||||
// Since we don't know how these files will be used, we store them using a "location"
|
// Since we don't know how these files will be used, we store them using a "location"
|
||||||
// path rather than a relative path
|
// path rather than a relative path
|
||||||
varList.add(resource.getLocation());
|
varList.add(sourceLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!buildVarToRuleStringMap.containsKey(varName)) {
|
if (!buildVarToRuleStringMap.containsKey(varName)) {
|
||||||
|
@ -1866,7 +1868,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Add the resource name to the makefile line that adds resources to the build variable
|
// Add the resource name to the makefile line that adds resources to the build variable
|
||||||
addMacroAdditionFile(buildVarToRuleStringMap, varName, relativePath, resource, generatedSource);
|
addMacroAdditionFile(buildVarToRuleStringMap, varName, relativePath, sourceLocation, generatedSource);
|
||||||
|
|
||||||
// Generate the rule to build this source file
|
// Generate the rule to build this source file
|
||||||
IInputType primaryInputType = tool.getPrimaryInputType();
|
IInputType primaryInputType = tool.getPrimaryInputType();
|
||||||
|
@ -1877,7 +1879,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
// Try to add the rule for the file
|
// Try to add the rule for the file
|
||||||
StringBuffer generatedDepFile = new StringBuffer();
|
StringBuffer generatedDepFile = new StringBuffer();
|
||||||
Vector generatedOutputs = new Vector();
|
Vector generatedOutputs = new Vector();
|
||||||
addRuleForSource(relativePath, ruleBuffer, resource, generatedSource, generatedDepFile, generatedOutputs);
|
addRuleForSource(relativePath, ruleBuffer, resource, sourceLocation, generatedSource, generatedDepFile, generatedOutputs);
|
||||||
|
|
||||||
// If the rule generates a dependency file, add the file to the DEPS variable
|
// If the rule generates a dependency file, add the file to the DEPS variable
|
||||||
if (generatedDepFile.length() > 0) {
|
if (generatedDepFile.length() > 0) {
|
||||||
|
@ -1898,12 +1900,18 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int k=0; k<generatedOutputs.size(); k++) {
|
for (int k=0; k<generatedOutputs.size(); k++) {
|
||||||
// TODO - this will only work for outputs generated below the build output directory?
|
IPath generatedOutput;
|
||||||
// try an option that generates an output outside of the project
|
if (((IPath)generatedOutputs.get(k)).isAbsolute()) {
|
||||||
IPath generatedOutput = getBuildWorkingDir().addTrailingSeparator().append(relativePath).addTrailingSeparator().append((IPath)generatedOutputs.get(k));
|
// TODO: Should we use relative paths when possible (e.g., see MbsMacroSupplier.calculateRelPath)
|
||||||
|
generatedOutput = (IPath)generatedOutputs.get(k);
|
||||||
|
} else {
|
||||||
|
generatedOutput = project.getLocation().append(getBuildWorkingDir()).append((IPath)generatedOutputs.get(k));
|
||||||
|
}
|
||||||
|
// If this file has an absolute path, then the generateOutputResource will not be correct
|
||||||
|
// because the file is not under the project. We use this resource in the calls to the dependency generator
|
||||||
IResource generateOutputResource = project.getFile(generatedOutput);
|
IResource generateOutputResource = project.getFile(generatedOutput);
|
||||||
addFragmentMakefileEntriesForSource(buildVarToRuleStringMap, ruleBuffer,
|
addFragmentMakefileEntriesForSource(buildVarToRuleStringMap, ruleBuffer,
|
||||||
folder, relativePath, generateOutputResource, buildVariable, true);
|
folder, relativePath, generateOutputResource, generatedOutput, buildVariable, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1914,7 +1922,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
IOutputType[] secondaryOutputs = config.getToolChain().getSecondaryOutputs();
|
IOutputType[] secondaryOutputs = config.getToolChain().getSecondaryOutputs();
|
||||||
if (secondaryOutputs.length > 0) {
|
if (secondaryOutputs.length > 0) {
|
||||||
if (isSecondaryOutputVar(secondaryOutputs, varName)) {
|
if (isSecondaryOutputVar(secondaryOutputs, varName)) {
|
||||||
addMacroAdditionFile(buildVarToRuleStringMap, varName, relativePath, resource, generatedSource);
|
addMacroAdditionFile(buildVarToRuleStringMap, varName, relativePath, sourceLocation, generatedSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1958,15 +1966,17 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
* @param enumeratedOutputs vector of the filenames that are the output of this rule
|
* @param enumeratedOutputs vector of the filenames that are the output of this rule
|
||||||
*/
|
*/
|
||||||
protected void addRuleForSource(String relativePath, StringBuffer buffer, IResource resource,
|
protected void addRuleForSource(String relativePath, StringBuffer buffer, IResource resource,
|
||||||
boolean generatedSource, StringBuffer generatedDepFile, Vector enumeratedOutputs) {
|
IPath sourceLocation, boolean generatedSource, StringBuffer generatedDepFile, Vector enumeratedOutputs) {
|
||||||
|
|
||||||
String resourceName = getFileName(resource);
|
String fileName = sourceLocation.removeFileExtension().lastSegment();
|
||||||
String inputExtension = resource.getFileExtension();
|
String inputExtension = sourceLocation.getFileExtension();
|
||||||
String outputExtension = info.getOutputExtension(inputExtension);
|
String outputExtension = info.getOutputExtension(inputExtension);
|
||||||
|
|
||||||
// We need to check whether we have any resource specific build information.
|
// We need to check whether we have any resource specific build information.
|
||||||
IResourceConfiguration resConfig = null;
|
IResourceConfiguration resConfig = null;
|
||||||
if( config != null ) resConfig = config.getResourceConfiguration(resource.getFullPath().toString());
|
if( !generatedSource && config != null ) {
|
||||||
|
resConfig = config.getResourceConfiguration(resource.getFullPath().toString());
|
||||||
|
}
|
||||||
|
|
||||||
ITool tool;
|
ITool tool;
|
||||||
if( resConfig != null) {
|
if( resConfig != null) {
|
||||||
|
@ -1982,9 +1992,9 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
|
|
||||||
// If the tool creates a dependency file, add it to the list
|
// If the tool creates a dependency file, add it to the list
|
||||||
if (doDepGen) {
|
if (doDepGen) {
|
||||||
String depFile = relativePath + resourceName + DOT + DEP_EXT;
|
String depFile = relativePath + fileName + DOT + DEP_EXT;
|
||||||
getDependencyMakefiles().add(depFile);
|
getDependencyMakefiles().add(depFile);
|
||||||
generatedDepFile.append(resourceName + DOT + DEP_EXT);
|
generatedDepFile.append(fileName + DOT + DEP_EXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out the output paths
|
// Figure out the output paths
|
||||||
|
@ -1995,14 +2005,14 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
Vector ruleOutputs = new Vector();
|
Vector ruleOutputs = new Vector();
|
||||||
Vector enumeratedPrimaryOutputs = new Vector();
|
Vector enumeratedPrimaryOutputs = new Vector();
|
||||||
Vector enumeratedSecondaryOutputs = new Vector();
|
Vector enumeratedSecondaryOutputs = new Vector();
|
||||||
calculateOutputsForSource(tool, relativePath, resource, ruleOutputs, enumeratedPrimaryOutputs, enumeratedSecondaryOutputs);
|
calculateOutputsForSource(tool, relativePath, resource, sourceLocation, ruleOutputs, enumeratedPrimaryOutputs, enumeratedSecondaryOutputs);
|
||||||
enumeratedOutputs.addAll(enumeratedPrimaryOutputs);
|
enumeratedOutputs.addAll(enumeratedPrimaryOutputs);
|
||||||
enumeratedOutputs.addAll(enumeratedSecondaryOutputs);
|
enumeratedOutputs.addAll(enumeratedSecondaryOutputs);
|
||||||
String primaryOutputName = null;
|
String primaryOutputName = null;
|
||||||
if (enumeratedPrimaryOutputs.size() > 0) {
|
if (enumeratedPrimaryOutputs.size() > 0) {
|
||||||
primaryOutputName = ((IPath)enumeratedPrimaryOutputs.get(0)).toString();
|
primaryOutputName = ((IPath)enumeratedPrimaryOutputs.get(0)).toString();
|
||||||
} else {
|
} else {
|
||||||
primaryOutputName = relativePath + resourceName + OptDotExt;
|
primaryOutputName = relativePath + fileName + OptDotExt;
|
||||||
}
|
}
|
||||||
String otherPrimaryOutputs = EMPTY_STRING;
|
String otherPrimaryOutputs = EMPTY_STRING;
|
||||||
for (int i=1; i<enumeratedPrimaryOutputs.size(); i++) { // Starting a 1 is intentional
|
for (int i=1; i<enumeratedPrimaryOutputs.size(); i++) { // Starting a 1 is intentional
|
||||||
|
@ -2017,16 +2027,19 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
* then we must get the actual location of the resource, rather
|
* then we must get the actual location of the resource, rather
|
||||||
* than the relative path.
|
* than the relative path.
|
||||||
*/
|
*/
|
||||||
IPath resourceLocation = resource.getLocation();
|
|
||||||
String projectLocation = project.getLocation().toString();
|
String projectLocation = project.getLocation().toString();
|
||||||
|
|
||||||
// Optput file location needed for the file-specific build macros
|
// Optput file location needed for the file-specific build macros
|
||||||
// TODO: Is primaryOutputName always build directory relative?
|
IPath outputLocation = Path.fromOSString(primaryOutputName);
|
||||||
IPath outputLocation = project.getLocation().append(getBuildWorkingDir()).append(primaryOutputName);
|
if (!outputLocation.isAbsolute()) {
|
||||||
|
outputLocation = project.getLocation().append(getBuildWorkingDir()).append(primaryOutputName);
|
||||||
|
}
|
||||||
|
|
||||||
// A separate rule is needed for the resource in case the explicit file-specific macros
|
// A separate rule is needed for the resource in case the explicit file-specific macros
|
||||||
// are referenced
|
// are referenced
|
||||||
boolean fileExplicitMacrosReferenced = MacroResolver.getReferencedExplitFileMacros(tool).length > 0 ||
|
boolean fileExplicitMacrosReferenced = MacroResolver.getReferencedExplitFileMacros(tool).length > 0 ||
|
||||||
MacroResolver.getReferencedExplitFileMacros(tool.getToolCommand(),IBuildMacroProvider.CONTEXT_FILE, new FileContextData(resourceLocation,outputLocation,null,config.getToolChain())).length > 0;
|
MacroResolver.getReferencedExplitFileMacros(tool.getToolCommand(),IBuildMacroProvider.CONTEXT_FILE,
|
||||||
|
new FileContextData(sourceLocation, outputLocation, null, config.getToolChain())).length > 0;
|
||||||
//get and resolve command
|
//get and resolve command
|
||||||
String cmd = tool.getToolCommand();
|
String cmd = tool.getToolCommand();
|
||||||
try{
|
try{
|
||||||
|
@ -2034,7 +2047,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
EMPTY_STRING,
|
EMPTY_STRING,
|
||||||
WHITESPACE,
|
WHITESPACE,
|
||||||
IBuildMacroProvider.CONTEXT_FILE,
|
IBuildMacroProvider.CONTEXT_FILE,
|
||||||
new FileContextData(resourceLocation,outputLocation,null,info.getDefaultConfiguration().getToolChain()));
|
new FileContextData(sourceLocation, outputLocation, null, info.getDefaultConfiguration().getToolChain()));
|
||||||
if((resolvedCommand = resolvedCommand.trim()).length() > 0)
|
if((resolvedCommand = resolvedCommand.trim()).length() > 0)
|
||||||
cmd = resolvedCommand;
|
cmd = resolvedCommand;
|
||||||
|
|
||||||
|
@ -2048,13 +2061,13 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
boolean patternRule = true;
|
boolean patternRule = true;
|
||||||
//boolean isItLinked = false;
|
//boolean isItLinked = false;
|
||||||
//if (resource.isLinked()) { NOTE: we don't use this since children of linked resources return false
|
//if (resource.isLinked()) { NOTE: we don't use this since children of linked resources return false
|
||||||
if(!resourceLocation.toString().startsWith(projectLocation)) {
|
if(!sourceLocation.toString().startsWith(projectLocation)) {
|
||||||
// it IS linked, so use the actual location
|
// it IS linked, so use the actual location
|
||||||
//isItLinked = true;
|
//isItLinked = true;
|
||||||
resourcePath = resourceLocation.toString();
|
resourcePath = sourceLocation.toString();
|
||||||
// Need a hardcoded rule, not a pattern rule, as a linked file
|
// Need a hardcoded rule, not a pattern rule, as a linked file
|
||||||
// can reside in any path
|
// can reside in any path
|
||||||
defaultOutputName = relativePath + resourceName + OptDotExt;
|
defaultOutputName = relativePath + fileName + OptDotExt;
|
||||||
primaryDependencyName = resourcePath;
|
primaryDependencyName = resourcePath;
|
||||||
patternRule = false;
|
patternRule = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2063,8 +2076,8 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
// The rule and command to add to the makefile
|
// The rule and command to add to the makefile
|
||||||
if( resConfig != null || fileExplicitMacrosReferenced) {
|
if( resConfig != null || fileExplicitMacrosReferenced) {
|
||||||
// Need a hardcoded rule, not a pattern rule
|
// Need a hardcoded rule, not a pattern rule
|
||||||
defaultOutputName = resourcePath + resourceName + OptDotExt;
|
defaultOutputName = resourcePath + fileName + OptDotExt;
|
||||||
primaryDependencyName = home + SEPARATOR + resourcePath + resourceName + DOT + inputExtension;
|
primaryDependencyName = home + SEPARATOR + resourcePath + fileName + DOT + inputExtension;
|
||||||
patternRule = false;
|
patternRule = false;
|
||||||
} else {
|
} else {
|
||||||
defaultOutputName = relativePath + WILDCARD + OptDotExt;
|
defaultOutputName = relativePath + WILDCARD + OptDotExt;
|
||||||
|
@ -2085,7 +2098,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
}
|
}
|
||||||
if (!patternRule) {
|
if (!patternRule) {
|
||||||
// Need to reset the primary dependency to be a filename rather than a pattern
|
// Need to reset the primary dependency to be a filename rather than a pattern
|
||||||
primaryDependencyName = home + SEPARATOR + resourcePath + resourceName + DOT + inputExtension;
|
primaryDependencyName = home + SEPARATOR + resourcePath + fileName + DOT + inputExtension;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2147,7 +2160,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
outputPrefix = tool.getOutputPrefix();
|
outputPrefix = tool.getOutputPrefix();
|
||||||
String[] flags = null;
|
String[] flags = null;
|
||||||
try {
|
try {
|
||||||
flags = tool.getToolCommandFlags(resourceLocation,outputLocation);
|
flags = tool.getToolCommandFlags(sourceLocation, outputLocation);
|
||||||
} catch( BuildException ex ) {
|
} catch( BuildException ex ) {
|
||||||
// TODO add some routines to catch this
|
// TODO add some routines to catch this
|
||||||
flags = EMPTY_STRING_ARRAY;
|
flags = EMPTY_STRING_ARRAY;
|
||||||
|
@ -2170,7 +2183,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
buffer.append(TAB + AT + ECHO + WHITESPACE + SINGLE_QUOTE + tool.getAnnouncement() + SINGLE_QUOTE + NEWLINE);
|
buffer.append(TAB + AT + ECHO + WHITESPACE + SINGLE_QUOTE + tool.getAnnouncement() + SINGLE_QUOTE + NEWLINE);
|
||||||
String buildFlags = EMPTY_STRING;
|
String buildFlags = EMPTY_STRING;
|
||||||
try {
|
try {
|
||||||
buildFlags = tool.getToolCommandFlagsString(resourceLocation,outputLocation);
|
buildFlags = tool.getToolCommandFlagsString(sourceLocation, outputLocation);
|
||||||
} catch (BuildException e) {
|
} catch (BuildException e) {
|
||||||
}
|
}
|
||||||
outflag = info.getOutputFlag(outputExtension);
|
outflag = info.getOutputFlag(outputExtension);
|
||||||
|
@ -2184,7 +2197,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
}
|
}
|
||||||
// Call the command line generator
|
// Call the command line generator
|
||||||
cmdLInfo = info.generateToolCommandLineInfo( inputExtension, flags, outflag, outputPrefix,
|
cmdLInfo = info.generateToolCommandLineInfo( inputExtension, flags, outflag, outputPrefix,
|
||||||
OUT_MACRO + otherPrimaryOutputs, (String[])inputs.toArray(new String[inputs.size()]), resourceLocation, outputLocation );
|
OUT_MACRO + otherPrimaryOutputs, (String[])inputs.toArray(new String[inputs.size()]), sourceLocation, outputLocation );
|
||||||
// The command to build
|
// The command to build
|
||||||
String buildCmd = null;
|
String buildCmd = null;
|
||||||
if( cmdLInfo == null ) buildCmd = cmd + WHITESPACE + buildFlags + WHITESPACE +
|
if( cmdLInfo == null ) buildCmd = cmd + WHITESPACE + buildFlags + WHITESPACE +
|
||||||
|
@ -2256,8 +2269,8 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
* that are relative to the build directory
|
* that are relative to the build directory
|
||||||
*/
|
*/
|
||||||
protected void calculateOutputsForSource(ITool tool, String relativePath, IResource resource,
|
protected void calculateOutputsForSource(ITool tool, String relativePath, IResource resource,
|
||||||
Vector ruleOutputs, Vector enumeratedPrimaryOutputs, Vector enumeratedSecondaryOutputs) {
|
IPath sourceLocation, Vector ruleOutputs, Vector enumeratedPrimaryOutputs, Vector enumeratedSecondaryOutputs) {
|
||||||
String inExt = resource.getFileExtension();
|
String inExt = sourceLocation.getFileExtension();
|
||||||
String outExt = tool.getOutputExtension(inExt);
|
String outExt = tool.getOutputExtension(inExt);
|
||||||
|
|
||||||
IOutputType[] outTypes = tool.getOutputTypes();
|
IOutputType[] outTypes = tool.getOutputTypes();
|
||||||
|
@ -2303,10 +2316,10 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
}
|
}
|
||||||
if (primaryOutput) {
|
if (primaryOutput) {
|
||||||
ruleOutputs.add(j, outPath);
|
ruleOutputs.add(j, outPath);
|
||||||
enumeratedPrimaryOutputs.add(j, resolvePercent(outPath, resource));
|
enumeratedPrimaryOutputs.add(j, resolvePercent(outPath, sourceLocation));
|
||||||
} else {
|
} else {
|
||||||
ruleOutputs.add(outPath);
|
ruleOutputs.add(outPath);
|
||||||
enumeratedSecondaryOutputs.add(resolvePercent(outPath, resource));
|
enumeratedSecondaryOutputs.add(resolvePercent(outPath, sourceLocation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch( BuildException ex ) {}
|
} catch( BuildException ex ) {}
|
||||||
|
@ -2314,7 +2327,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
// 3. If a nameProvider is specified, call it
|
// 3. If a nameProvider is specified, call it
|
||||||
if (nameProvider != null) {
|
if (nameProvider != null) {
|
||||||
IPath[] inPaths = new IPath[1];
|
IPath[] inPaths = new IPath[1];
|
||||||
inPaths[0] = resource.getFullPath();
|
inPaths[0] = sourceLocation;
|
||||||
IPath[] outPaths = nameProvider.getOutputNames(tool, inPaths);
|
IPath[] outPaths = nameProvider.getOutputNames(tool, inPaths);
|
||||||
for (int j=0; j<outPaths.length; j++) {
|
for (int j=0; j<outPaths.length; j++) {
|
||||||
IPath outPath = outPaths[j];
|
IPath outPath = outPaths[j];
|
||||||
|
@ -2324,10 +2337,10 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
}
|
}
|
||||||
if (primaryOutput) {
|
if (primaryOutput) {
|
||||||
ruleOutputs.add(j, outPath);
|
ruleOutputs.add(j, outPath);
|
||||||
enumeratedPrimaryOutputs.add(j, resolvePercent(outPath, resource));
|
enumeratedPrimaryOutputs.add(j, resolvePercent(outPath, sourceLocation));
|
||||||
} else {
|
} else {
|
||||||
ruleOutputs.add(outPath);
|
ruleOutputs.add(outPath);
|
||||||
enumeratedSecondaryOutputs.add(resolvePercent(outPath, resource));
|
enumeratedSecondaryOutputs.add(resolvePercent(outPath, sourceLocation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
@ -2341,10 +2354,10 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
}
|
}
|
||||||
if (primaryOutput) {
|
if (primaryOutput) {
|
||||||
ruleOutputs.add(j, outPath);
|
ruleOutputs.add(j, outPath);
|
||||||
enumeratedPrimaryOutputs.add(j, resolvePercent(outPath, resource));
|
enumeratedPrimaryOutputs.add(j, resolvePercent(outPath, sourceLocation));
|
||||||
} else {
|
} else {
|
||||||
ruleOutputs.add(outPath);
|
ruleOutputs.add(outPath);
|
||||||
enumeratedSecondaryOutputs.add(resolvePercent(outPath, resource));
|
enumeratedSecondaryOutputs.add(resolvePercent(outPath, sourceLocation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2377,10 +2390,10 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
|
|
||||||
if (primaryOutput) {
|
if (primaryOutput) {
|
||||||
ruleOutputs.add(0, namePatternPath);
|
ruleOutputs.add(0, namePatternPath);
|
||||||
enumeratedPrimaryOutputs.add(0, resolvePercent(namePatternPath, resource));
|
enumeratedPrimaryOutputs.add(0, resolvePercent(namePatternPath, sourceLocation));
|
||||||
} else {
|
} else {
|
||||||
ruleOutputs.add(namePatternPath);
|
ruleOutputs.add(namePatternPath);
|
||||||
enumeratedSecondaryOutputs.add(resolvePercent(namePatternPath, resource));
|
enumeratedSecondaryOutputs.add(resolvePercent(namePatternPath, sourceLocation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2398,7 +2411,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
IPath outPath = Path.fromOSString(relativePath + outPrefix + WILDCARD);
|
IPath outPath = Path.fromOSString(relativePath + outPrefix + WILDCARD);
|
||||||
outPath = outPath.addFileExtension(outExt);
|
outPath = outPath.addFileExtension(outExt);
|
||||||
ruleOutputs.add(0, outPath);
|
ruleOutputs.add(0, outPath);
|
||||||
enumeratedPrimaryOutputs.add(0, resolvePercent(outPath, resource));
|
enumeratedPrimaryOutputs.add(0, resolvePercent(outPath, sourceLocation));
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2407,9 +2420,9 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
* If the path contains a %, returns the path resolved using the resource name
|
* If the path contains a %, returns the path resolved using the resource name
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected IPath resolvePercent(IPath outPath, IResource resource) {
|
protected IPath resolvePercent(IPath outPath, IPath sourceLocation) {
|
||||||
// Get the input file name
|
// Get the input file name
|
||||||
String fileName = resource.getFullPath().removeFileExtension().lastSegment();
|
String fileName = sourceLocation.removeFileExtension().lastSegment();
|
||||||
// Replace the % with the file name
|
// Replace the % with the file name
|
||||||
String outName = outPath.toOSString().replaceAll("%", fileName); //$NON-NLS-1$
|
String outName = outPath.toOSString().replaceAll("%", fileName); //$NON-NLS-1$
|
||||||
return Path.fromOSString(outName);
|
return Path.fromOSString(outName);
|
||||||
|
@ -2583,19 +2596,27 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
* example.c, \
|
* example.c, \
|
||||||
*/
|
*/
|
||||||
protected void addMacroAdditionFile(HashMap map, String macroName,
|
protected void addMacroAdditionFile(HashMap map, String macroName,
|
||||||
String relativePath, IResource resource, boolean generatedSource) {
|
String relativePath, IPath sourceLocation, boolean generatedSource) {
|
||||||
// Add the resource name to the makefile line that adds resources to the build variable
|
// Add the source file path to the makefile line that adds source files to the build variable
|
||||||
String srcName;
|
String srcName;
|
||||||
|
IPath projectLocation = project.getLocation();
|
||||||
|
IPath dirLocation = projectLocation;
|
||||||
if (generatedSource) {
|
if (generatedSource) {
|
||||||
srcName = resource.getName();
|
dirLocation = dirLocation.append(getBuildWorkingDir());
|
||||||
|
}
|
||||||
|
if (dirLocation.isPrefixOf(sourceLocation)) {
|
||||||
|
IPath srcPath = sourceLocation.removeFirstSegments(dirLocation.segmentCount()).setDevice(null);
|
||||||
|
if (generatedSource) {
|
||||||
|
srcName = "./" + srcPath.toString(); //$NON-NLS-1$
|
||||||
} else {
|
} else {
|
||||||
String resourceLocation = resource.getLocation().toString();
|
srcName = "$(ROOT)/" + srcPath.toString(); //$NON-NLS-1$
|
||||||
String projectLocation = project.getLocation().toString();
|
}
|
||||||
//if (resource.isLinked()) { NOTE: we don't use this since children of linked resources return false
|
|
||||||
if(!resourceLocation.startsWith(projectLocation)) {
|
|
||||||
srcName = resourceLocation;
|
|
||||||
} else {
|
} else {
|
||||||
srcName = "$(ROOT)/" + relativePath + resource.getName(); //$NON-NLS-1$
|
if (generatedSource && !sourceLocation.isAbsolute()) {
|
||||||
|
srcName = "./" + relativePath + sourceLocation.lastSegment().toString(); // $NON-NLS-1$
|
||||||
|
} else {
|
||||||
|
// TODO: Should we use relative paths when possible (e.g., see MbsMacroSupplier.calculateRelPath)
|
||||||
|
srcName = sourceLocation.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addMacroAdditionFile(map, macroName, srcName);
|
addMacroAdditionFile(map, macroName, srcName);
|
||||||
|
@ -2848,7 +2869,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
IPath path = (IPath)list.get(i);
|
IPath path = (IPath)list.get(i);
|
||||||
if (locationType != ABSOLUTE) {
|
if (locationType != ABSOLUTE) {
|
||||||
if (dirLocation.isPrefixOf(path)) {
|
if (dirLocation.isPrefixOf(path)) {
|
||||||
path = path.removeFirstSegments(dirLocation.matchingFirstSegments(path));
|
path = path.removeFirstSegments(dirLocation.segmentCount()).setDevice(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileList.add(path.toString());
|
fileList.add(path.toString());
|
||||||
|
@ -2932,7 +2953,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
||||||
* deleted. As a result, the directories that are generated for the output
|
* deleted. As a result, the directories that are generated for the output
|
||||||
* should be removed as well.
|
* should be removed as well.
|
||||||
*
|
*
|
||||||
* @param resource
|
* @param container
|
||||||
*/
|
*/
|
||||||
protected void appendDeletedSubdirectory(IContainer container) {
|
protected void appendDeletedSubdirectory(IContainer container) {
|
||||||
// No point in adding a folder if the parent is already there
|
// No point in adding a folder if the parent is already there
|
||||||
|
|
|
@ -247,7 +247,7 @@ public class ManagedBuildGnuToolInfo implements IManagedBuildGnuToolInfo {
|
||||||
IPath resPath = projResources[j].getLocation();
|
IPath resPath = projResources[j].getLocation();
|
||||||
IPath bldLocation = project.getLocation().append(makeGen.getBuildWorkingDir());
|
IPath bldLocation = project.getLocation().append(makeGen.getBuildWorkingDir());
|
||||||
if (bldLocation.isPrefixOf(resPath)) {
|
if (bldLocation.isPrefixOf(resPath)) {
|
||||||
resPath = resPath.removeFirstSegments(bldLocation.matchingFirstSegments(resPath));
|
resPath = resPath.removeFirstSegments(bldLocation.segmentCount()).setDevice(null);
|
||||||
}
|
}
|
||||||
myEnumeratedInputs.add(resPath.toString());
|
myEnumeratedInputs.add(resPath.toString());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue