1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

New test for external dependency management

This commit is contained in:
Leo Treggiari 2005-09-03 02:52:14 +00:00
parent 7fb7da6e35
commit d743e195a3
4 changed files with 532 additions and 0 deletions

View file

@ -3956,4 +3956,262 @@
</projectType>
</extension>
<extension
id="cdt.test.fortran.toolchain"
name="CDT Test Fortran Toolchain"
point="org.eclipse.cdt.managedbuilder.core.buildDefinitions">
<!-- This tool-chain tests external dependency calulation using Fortran -->
<!-- Compiler tool -->
<tool
natureFilter="both"
name="Test Fortran Compiler"
outputFlag="-c -object:"
command="myfort"
commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}"
id="cdt.test.fortran.compilestep">
<inputType
sources="f,F,for,FOR,f90,F90"
dependencyCalculator="org.eclipse.cdt.managedbuilder.core.tests.DefaultFortranDependencyCalculator"
id="cdt.test.fortran.compilestep.input">
</inputType>
<outputType
outputs="obj"
buildVariable="OBJS"
id="cdt.test.fortran.compilestep.output">
</outputType>
<outputType
outputs="mod"
buildVariable="MODS"
multipleOfType="true"
nameProvider="org.eclipse.cdt.managedbuilder.core.tests.DefaultFortranDependencyCalculator"
id="cdt.test.fortran.compilestep.output.modules">
</outputType>
<!-- pp General -->
<optionCategory
owner="cdt.test.fortran.compilestep"
name="General"
id="cdt.test.fortran.compilestep.category.general">
</optionCategory>
<option
defaultValue="false"
name="Include Debug Information (-debug)"
category="cdt.test.fortran.compilestep.category.general"
command="-debug"
valueType="boolean"
id="cdt.test.fortran.compilestep.general.debug">
</option>
<option
name="Optimization Level"
category="cdt.test.fortran.compilestep.category.general"
valueType="enumerated"
id="cdt.test.fortran.compilestep.general.optimization">
<enumeratedOptionValue
name="Disable (-Od)"
command="-Od"
id="general.opt.none">
</enumeratedOptionValue>
<enumeratedOptionValue
name="Minimize Size (-O1)"
command="-O1"
id="general.opt.size">
</enumeratedOptionValue>
<enumeratedOptionValue
name="Maximize Speed (-O2)"
isDefault="true"
command=""
id="general.opt.speed">
</enumeratedOptionValue>
</option>
<option
name="Additional Include Directories (-I)"
category="cdt.test.fortran.compilestep.category.general"
command="-I"
valueType="includePath"
browseType="directory"
id="cdt.test.fortran.compilestep.preprocessor.includedirectories">
</option>
<!-- pp Compiler Command Line -->
<optionCategory
owner="cdt.test.fortran.compilestep"
name="Command Line"
id="cdt.test.fortran.compilestep.category.comline">
</optionCategory>
<option
name="Additional Options"
category="cdt.test.fortran.compilestep.category.comline"
valueType="string"
id="cdt.test.fortran.compilestep.coptions">
</option>
</tool>
<!-- Linker tool -->
<tool
natureFilter="both"
name="Linker"
outputFlag="-o"
command="mylink"
commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}"
id="cdt.test.fortran.linkstep">
<inputType
sourceContentType="org.eclipse.cdt.managedbuilder.core.compiledObjectFile"
sources="o"
multipleOfType="true"
dependencyCalculator="org.eclipse.cdt.managedbuilder.makegen.internal.DefaultNoDependencyCalculator"
buildVariable="OBJS"
id="cdt.test.fortran.linkstep.input">
<additionalInput
paths="$(USER_OBJS)"
kind="additionalinputdependency">
</additionalInput>
<additionalInput
paths="$(LIBS)"
kind="additionalinput">
</additionalInput>
</inputType>
<outputType
outputs="exe"
buildVariable="EXECUTABLES"
primaryOutput="true"
id="cdt.test.fortran.linkstep.output">
</outputType>
<!-- pp Libraries -->
<optionCategory
owner="cdt.test.fortran.linkstep"
name="Libraries"
id="cdt.test.fortran.linkstep.category.options">
</optionCategory>
<option
name="Additional Libraries (-l)"
category="cdt.test.fortran.linkstep.category.options"
command="-l"
valueType="libs"
id="cdt.test.fortran.linkstep.libname">
</option>
<option
name="Search Directory for Libraries (-L)"
category="cdt.test.fortran.linkstep.category.options"
command="-L"
valueType="stringList"
id="cdt.test.fortran.linkstep.libpath">
</option>
<!-- pp Linker Command Line -->
<optionCategory
owner="cdt.test.fortran.linkstep"
name="Command Line"
id="cdt.test.fortran.linkstep.category.comline">
</optionCategory>
<option
name="Additional Options"
category="cdt.test.fortran.linkstep.category.comline"
valueType="string"
id="cdt.test.fortran.linkstep.loptions">
</option>
</tool>
<!-- Executable project type -->
<projectType
isTest="false"
isAbstract="false"
name="Fortran Executable"
id="cdt.test.fortran.executable">
<configuration
name="Release"
id="cdt.test.fortran.executable.release"
cleanCommand="rm -rf">
<toolChain
id="cdt.test.fortran.toolchain.executable.release"
name="ToolChain.Executable.Release"
targetTool="cdt.test.fortran.linkstep.executable.release"
osList="win32"
archList="x86">
<targetPlatform
id="cdt.test.fortran.platform.executable.release"
name="Platform.Executable.Release"
binaryParser="org.eclipse.cdt.core.PE"
osList="win32"
archList="x86">
</targetPlatform>
<builder
id="cdt.test.fortran.builder.executable.release"
name="Builder.Executable.Release"
command="make"
arguments="-k"
buildfileGenerator="org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator">
</builder>
<tool
id="cdt.test.fortran.compilestep.executable.release"
superClass="cdt.test.fortran.compilestep">
<option
id="cdt.test.fortran.compilestep.general.optimization.executable.release"
defaultValue="general.opt.speed"
superClass="cdt.test.fortran.compilestep.general.optimization">
</option>
<option
id="cdt.test.fortran.compilestep.general.debug.executable.release"
defaultValue="false"
superClass="cdt.test.fortran.compilestep.general.debug">
</option>
</tool>
<tool
id="cdt.test.fortran.linkstep.executable.release"
superClass="cdt.test.fortran.linkstep">
</tool>
</toolChain>
</configuration>
<configuration
name="Debug"
id="cdt.test.fortran.executable.debug"
cleanCommand="rm -rf">
<toolChain
id="cdt.test.fortran.toolchain.executable.debug"
name="ToolChain.Executable.Debug"
targetTool="cdt.test.fortran.linkstep.executable.debug"
osList="win32"
archList="x86">
<targetPlatform
id="cdt.test.fortran.platform.executable.debug"
name="Platform.Executable.Debug"
binaryParser="org.eclipse.cdt.core.PE"
osList="win32"
archList="x86">
</targetPlatform>
<builder
id="cdt.test.fortran.builder.executable.debug"
name="Builder.Executable.Debug"
command="make"
arguments="-k"
buildfileGenerator="org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator">
</builder>
<tool
id="cdt.test.fortran.compilestep.executable.debug"
superClass="cdt.test.fortran.compilestep">
<option
id="cdt.test.fortran.compilestep.general.optimization.executable.debug"
defaultValue="general.opt.none"
superClass="cdt.test.fortran.compilestep.general.optimization">
</option>
<option
id="cdt.test.fortran.compilestep.general.debug.executable.debug"
defaultValue="true"
superClass="cdt.test.fortran.compilestep.general.debug">
</option>
</tool>
<tool
id="cdt.test.fortran.linkstep.executable.debug"
superClass="cdt.test.fortran.linkstep">
</tool>
</toolChain>
</configuration>
</projectType>
<!-- Executable project type end -->
</extension>
</plugin>

View file

@ -0,0 +1,260 @@
/*******************************************************************************
* 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
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.core.tests;
import java.io.*;
import java.lang.String;
import java.util.ArrayList;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.IManagedOutputNameProvider;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGenerator;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
* This class implements the Dependency Manager and Output Name Provider interfaces
* for a very "quick & dirty" ifort tool-chain on Win32
*/
public class DefaultFortranDependencyCalculator implements IManagedDependencyGenerator,
IManagedOutputNameProvider
{
public static final String MODULE_EXTENSION = "mod"; //$NON-NLS-1$
/*
* Return a list of the names of all modules used by a file
*/
private String[] findUsedModuleNames(File file) {
ArrayList names = new ArrayList();
try {
InputStream in = new BufferedInputStream(new FileInputStream(file));
Reader r = new BufferedReader(new InputStreamReader(in));
StreamTokenizer st = new StreamTokenizer(r);
st.commentChar('!');
st.eolIsSignificant(false);
st.slashSlashComments(false);
st.slashStarComments(false);
st.wordChars('_', '_');
while (st.nextToken() != StreamTokenizer.TT_EOF) {
if (st.ttype == StreamTokenizer.TT_WORD) {
if (st.sval.equalsIgnoreCase("use")) {
st.nextToken();
if (st.ttype == StreamTokenizer.TT_WORD) {
names.add(st.sval);
} else {
st.pushBack();
}
}
}
}
}
catch (Exception e) {
return new String[0];
}
return (String[]) names.toArray(new String[names.size()]);
}
/*
* Return a list of the names of all modules defined in a file
*/
private String[] findModuleNames(File file) {
ArrayList names = new ArrayList();
try {
InputStream in = new BufferedInputStream(new FileInputStream(file));
Reader r = new BufferedReader(new InputStreamReader(in));
StreamTokenizer st = new StreamTokenizer(r);
st.commentChar('!');
st.eolIsSignificant(false);
st.slashSlashComments(false);
st.slashStarComments(false);
st.wordChars('_', '_');
while (st.nextToken() != StreamTokenizer.TT_EOF) {
if (st.ttype == StreamTokenizer.TT_WORD) {
if (st.sval.equalsIgnoreCase("module")) {
st.nextToken();
if (st.ttype == StreamTokenizer.TT_WORD) {
names.add(st.sval);
} else {
st.pushBack();
}
}
}
}
}
catch (Exception e) {
return new String[0];
}
return (String[]) names.toArray(new String[names.size()]);
}
/*
* Returns true if the resource is a Fortran source file
*/
private boolean isFortranFile(ITool tool, IResource resource) {
// TODO: Get the file extensions from the tool's primary input type
String ext = resource.getFileExtension();
if (ext != null) {
if (ext.equalsIgnoreCase("f")) return true;
if (ext.equalsIgnoreCase("for")) return true;
if (ext.equalsIgnoreCase("f90")) return true;
}
return false;
}
/*
* Given a set of the module names used by a source file, and a set of resources to search, determine
* if any of the source files implements the module names.
*/
private IResource[] FindModulesInResources(IProject project, ITool tool, IResource resource, IResource[] resourcesToSearch,
String topBuildDir, String[] usedNames) {
ArrayList modRes = new ArrayList();
for (int ir = 0; ir < resourcesToSearch.length; ir++) {
if (resourcesToSearch[ir].equals(resource)) continue;
if (resourcesToSearch[ir].getType() == IResource.FILE) {
File projectFile = resourcesToSearch[ir].getLocation().toFile();
if (!isFortranFile(tool, resourcesToSearch[ir])) continue;
String[] modules = findModuleNames(projectFile);
if (modules != null) {
for (int iu = 0; iu < usedNames.length; iu++) {
boolean foundDependency = false;
for (int im = 0; im < modules.length; im++) {
if (usedNames[iu].equalsIgnoreCase(modules[im])) {
// Get the path to the module file that will be created by the build. By default, ifort appears
// to generate .mod files in the directory from which the compiler is run. For MBS, this
// is the top-level build directory.
// TODO: Support the /module:path option and use that in determining the path of the module file
IPath modName = Path.fromOSString(topBuildDir + Path.SEPARATOR + modules[im] + "." + MODULE_EXTENSION);
modRes.add(project.getFile(modName));
modRes.add(resourcesToSearch[ir]);
foundDependency = true;
break;
}
}
if (foundDependency) break;
}
}
} else if (resourcesToSearch[ir].getType() == IResource.FOLDER) {
try {
IResource[] modFound = FindModulesInResources(project, tool, resource, ((IFolder)resourcesToSearch[ir]).members(),
topBuildDir, usedNames);
if (modFound != null) {
for (int i=0; i<modFound.length; i++) {
modRes.add(modFound[i]);
}
}
} catch(Exception e) {}
}
}
return (IResource[]) modRes.toArray(new IResource[modRes.size()]);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderDependencyCalculator#findDependencies(org.eclipse.core.resources.IResource)
*/
public IResource[] findDependencies(IResource resource, IProject project) {
ArrayList dependencies = new ArrayList();
// TODO: This method should be passed the ITool and the relative path of the top build directory
// For now we'll figure this out from the project.
IManagedBuildInfo mngInfo = ManagedBuildManager.getBuildInfo(project);
IConfiguration config = mngInfo.getDefaultConfiguration();
ITool tool = null;
ITool[] tools = config.getTools();
for (int i=0; i<tools.length; i++) {
if (tools[i].getName().equals("Fortran (ifort) Compiler for Win32")) {
tool = tools[i];
break;
}
}
File file = resource.getLocation().toFile();
try {
if (!isFortranFile(tool, resource)) return null;
// Get the names of the modules USE'd by the source file
String[] usedNames = findUsedModuleNames(file);
if (usedNames.length == 0) return null;
// Search the project files for a Fortran source that creates the module. If we find one, then compiling this
// source file is dependent upon first compiling the found source file.
IResource[] resources = project.members();
IResource[] modRes = FindModulesInResources(project, tool, resource, resources, config.getName(), usedNames);
if (modRes != null) {
for (int i=0; i<modRes.length; i++) {
dependencies.add(modRes[i]);
}
}
}
catch (Exception e)
{
return null;
}
return (IResource[]) dependencies.toArray(new IResource[dependencies.size()]);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderDependencyCalculator#getCalculatorType()
*/
public int getCalculatorType() {
return TYPE_EXTERNAL;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderDependencyCalculator#getDependencyCommand()
*/
public String getDependencyCommand(IResource resource, IManagedBuildInfo info) {
/*
* The type of this IManagedDependencyGenerator is TYPE_EXTERNAL,
* so implement findDependencies() rather than getDependencyCommand().
* */
return null;
}
/*
* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IManagedOutputNameProvider#getOutputNames(org.eclipse.cdt.managedbuilder.core.ITool, org.eclipse.core.runtime.IPath[])
*/
public IPath[] getOutputNames(ITool tool, IPath[] primaryInputNames) {
// TODO: This method should be passed the relative path of the top build directory?
ArrayList outs = new ArrayList();
if (primaryInputNames.length > 0) {
// Get the names of modules created by this source file
String[] modules = findModuleNames(primaryInputNames[0].toFile());
// Add any generated modules
if (modules != null) {
for (int i = 0; i < modules.length; i++) {
// Return the path to the module file that will be created by the build. By default, ifort appears
// to generate .mod files in the directory from which the compiler is run. For MBS, this
// is the top-level build directory.
// TODO: Support the /module:path option and use that in determining the path of the module file
// TODO: The nameProvider documentation should note that the returned path is relative to the top-level
// build directory. HOWEVER, if only a file name is returned, MBS will automatically add on the
// directory path relative to the top-level build directory. The relative path comes from the source
// file location. In order to specify that this output file is always in the top-level build
// directory, regardless of the source file directory structure, return "./path".
IPath modName = Path.fromOSString("." + Path.SEPARATOR + modules[i] + "." + MODULE_EXTENSION);
outs.add(modName);
}
}
}
return (IPath[]) outs.toArray(new IPath[outs.size()]);
}
}

View file

@ -77,6 +77,7 @@ public class ManagedProject30MakefileTests extends TestCase {
suite.addTest(new ManagedProject30MakefileTests("test30_1"));
suite.addTest(new ManagedProject30MakefileTests("test30_2"));
suite.addTest(new ManagedProject30MakefileTests("testTopTC"));
suite.addTest(new ManagedProject30MakefileTests("CDTFortranTest1"));
return suite;
}
@ -542,4 +543,17 @@ public class ManagedProject30MakefileTests extends TestCase {
}
buildDegenerativeProjects(projects, null);
}
/* (non-Javadoc)
* tests external dependency calculation using Fortran modules
*/
public void CDTFortranTest1(){
IPath[] makefiles = {
Path.fromOSString("makefile"),
Path.fromOSString("objects.mk"),
Path.fromOSString("sources.mk"),
Path.fromOSString("subdir.mk")};
IProject[] projects = createProjects("CDTFortranTest1", null, null, true);
buildProjects(projects, makefiles);
}
}