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

1. Dependency tracking mechanism in Internal Builder

2. Build Model fixes
This commit is contained in:
Mikhail Sennikovsky 2006-10-09 16:44:55 +00:00
parent ead46b18a7
commit d6c3820f2a
8 changed files with 348 additions and 29 deletions

View file

@ -24,6 +24,9 @@ import org.eclipse.cdt.managedbuilder.internal.buildmodel.DefaultBuildDescriptio
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@ -36,12 +39,26 @@ import org.eclipse.core.runtime.Path;
*
*/
public class BuildDescriptionManager {
public static final int REMOVED = 0x01;
public static final int REBUILD = 0x02;
public static final int DEPS = 0x04;
public static final int DEPS_CMODEL = DEPS | 0x08;
public static final int DEPS_DEPGEN = DEPS | 0x10;
public static final int DEPS_DEPFILE_INFO = DEPS | 0x20;
/**
* include information on removed resources into the build model
*/
public static final int REMOVED = 1;
/**
* include the rebuild state information into the build model
*/
public static final int REBUILD = 1 << 1;
/**
* include dependencies information into the build model.
* the method to be used for calculation is determined by the manager
*/
public static final int DEPS = 1 << 2;
/**
* include the dependency file (.d) information in the build model.
*/
public static final int DEPFILES = 1 << 3;
private Set fVisitedSteps = new HashSet();
private boolean fUp;
@ -63,15 +80,12 @@ public class BuildDescriptionManager {
* BuildDescriptionManager.REBUILD,
* BuildDescriptionManager.REMOVED,
* BuildDescriptionManager.DEPS,
* BuildDescriptionManager.DEPS_CMODEL,
* BuildDescriptionManager.DEPS_DEPGEN,
*
* BuildDescriptionManager.DEPFILES
*
* @see BuildDescriptionManager#REBUILD
* @see BuildDescriptionManager#REMOVED
* @see BuildDescriptionManager#DEPS
* @see BuildDescriptionManager#DEPS_CMODEL
* @see BuildDescriptionManager#DEPS_DEPGEN
* @see BuildDescriptionManager#DEPFILES
* @return IBuildDescription
* @throws CoreException if the build description creation fails
*/
@ -217,11 +231,11 @@ public class BuildDescriptionManager {
* @return IResource
*/
public static IResource findResourceForBuildResource(IBuildResource bRc){
IProject project = bRc.getBuildDescription().getConfiguration().getOwner().getProject();
IPath path = bRc.getFullPath();
if(path != null)
return project.findMember(path.removeFirstSegments(1));
if(path != null){
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
return root.findMember(path);
}
return null;
}
@ -237,6 +251,9 @@ public class BuildDescriptionManager {
List failList = new ArrayList();
for(int i = 0; i < bRcs.length; i++){
if(!bRcs[i].isProjectResource())
continue;
IResource rc = findResourceForBuildResource(bRcs[i]);
if(rc != null){
try {

View file

@ -32,15 +32,13 @@ public interface IBuildDescriptionFactory {
* BuildDescriptionManager.REBUILD,
* BuildDescriptionManager.REMOVED,
* BuildDescriptionManager.DEPS,
* BuildDescriptionManager.DEPS_CMODEL,
* BuildDescriptionManager.DEPS_DEPGEN,
* BuildDescriptionManager.DEPFILES,
*
*
* @see BuildDescriptionManager#REBUILD
* @see BuildDescriptionManager#REMOVED
* @see BuildDescriptionManager#DEPS
* @see BuildDescriptionManager#DEPS_CMODEL
* @see BuildDescriptionManager#DEPS_DEPGEN
* @see BuildDescriptionManager#DEPFILES
* @return IBuildDescription
* @throws CoreException if the build description creation fails
*/
@ -55,8 +53,7 @@ public interface IBuildDescriptionFactory {
* @see BuildDescriptionManager#REBUILD
* @see BuildDescriptionManager#REMOVED
* @see BuildDescriptionManager#DEPS
* @see BuildDescriptionManager#DEPS_CMODEL
* @see BuildDescriptionManager#DEPS_DEPGEN *
* @see BuildDescriptionManager#DEPFILES
*
* @return int
*/

View file

@ -49,11 +49,14 @@ import org.eclipse.cdt.managedbuilder.internal.macros.OptionContextData;
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyCalculator;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyCommands;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGenerator;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGenerator2;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGeneratorType;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyInfo;
import org.eclipse.cdt.managedbuilder.pdomdepgen.PDOMDependencyGenerator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
@ -106,6 +109,8 @@ public class BuildDescription implements IBuildDescription {
private Map fEnvironment;
private PDOMDependencyGenerator fPdomDepGen;
class ToolAndType{
ITool fTool;
IInputType fType;
@ -1202,7 +1207,7 @@ public class BuildDescription implements IBuildDescription {
buildArg.addResource(outRc);
}
if(checkFlags(BuildDescriptionManager.DEPS_DEPFILE_INFO)){
if(checkFlags(BuildDescriptionManager.DEPFILES)){
if(tool != null && buildRc != null){
IInputType type = action.getInputType();
String ext = null;
@ -1475,7 +1480,132 @@ public class BuildDescription implements IBuildDescription {
}
} else {
}
}
calculateDeps(step);
}
private void calculateDeps(BuildStep step){
BuildResource rcs[] = (BuildResource[])step.getInputResources();
Set depSet = new HashSet();
for(int i = 0; i < rcs.length; i++){
IManagedDependencyCalculator depCalc = getDependencyCalculator(step, rcs[i]);
if(depCalc != null){
IPath paths[] = depCalc.getDependencies();
for(int j = 0; j < paths.length; j++){
depSet.add(paths[j]);
}
}
}
if(depSet.size() > 0){
BuildIOType ioType = step.createIOType(true, false, null);
for(Iterator iter = depSet.iterator(); iter.hasNext();){
addInput((IPath)iter.next(), ioType);
}
}
}
protected IManagedDependencyCalculator getDependencyCalculator(BuildStep step, BuildResource bRc){
if(!checkFlags(BuildDescriptionManager.DEPS))
return null;
final ITool tool = step.getTool();
if(tool == null)
return null;
IManagedDependencyCalculator depCalc = null;
IManagedDependencyGeneratorType depGenType = tool.getDependencyGeneratorForExtension(bRc.getLocation().getFileExtension());
IManagedDependencyGeneratorType depGen = null;
if(depGenType != null){
switch(depGenType.getCalculatorType()){
case IManagedDependencyGeneratorType.TYPE_NODEPS:
case IManagedDependencyGeneratorType.TYPE_NODEPENDENCIES:
//no dependencies
break;
case IManagedDependencyGeneratorType.TYPE_INDEXER:
case IManagedDependencyGeneratorType.TYPE_EXTERNAL:
case IManagedDependencyGeneratorType.TYPE_CUSTOM:
depGen = depGenType;
break;
case IManagedDependencyGeneratorType.TYPE_COMMAND:
case IManagedDependencyGeneratorType.TYPE_BUILD_COMMANDS:
case IManagedDependencyGeneratorType.TYPE_PREBUILD_COMMANDS:
//TODO: may implement the .d file parsing for deps calculation here
//break;
default:
depGen = getPDOMDependencyGenerator();
break;
}
} else {
depGen = getPDOMDependencyGenerator();
}
if(depGen != null){
final IResource rc = BuildDescriptionManager.findResourceForBuildResource(bRc);
IBuildObject bo = tool.getParent();
if(bo instanceof IToolChain)
bo = ((IToolChain)bo).getParent();
if(rc != null){
if(depGen instanceof IManagedDependencyGenerator2){
IManagedDependencyInfo srcInfo = ((IManagedDependencyGenerator2)depGen).getDependencySourceInfo(
rc.getLocation(),
rc,
bo,
tool,
getTopBuildDirLocation());
if(srcInfo instanceof IManagedDependencyCalculator)
depCalc = (IManagedDependencyCalculator)srcInfo;
} else if (depGen instanceof IManagedDependencyGenerator){
IResource rcs[] = ((IManagedDependencyGenerator)depGen).findDependencies(rc, fProject);
if(rcs != null && rcs.length > 0){
final IPath paths[] = new IPath[rcs.length];
final IBuildObject bof = bo;
for(int i = 0; i < paths.length; i++){
paths[i] = rcs[i].getLocation();
}
depCalc = new IManagedDependencyCalculator(){
public IPath[] getAdditionalTargets() {
return null;
}
public IPath[] getDependencies() {
return paths;
}
public IBuildObject getBuildContext() {
return bof;
}
public IPath getSource() {
return rc.getLocation();
}
public ITool getTool() {
return tool;
}
public IPath getTopBuildDirectory() {
return getTopBuildDirectory();
}
};
}
}
}
}
return depCalc;
}
protected PDOMDependencyGenerator getPDOMDependencyGenerator(){
if(fPdomDepGen == null)
fPdomDepGen = new PDOMDependencyGenerator();
return fPdomDepGen;
}
public String[] getLibs(BuildStep step) {
@ -1585,8 +1715,20 @@ public class BuildDescription implements IBuildDescription {
if(inFullPath.isAbsolute()){
inLocation = inFullPath;
if(!fProject.getLocation().isPrefixOf(inLocation))
inFullPath = null;
inFullPath = null;
IFile files[] = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(inLocation);
for(int i = 0; i < files.length; i++){
IPath fl = files[i].getFullPath();
if(fl.segment(0).equals(fProject.getName())){
inFullPath = fl;
break;
}
}
if(inFullPath == null && files.length > 0)
inFullPath = files[0].getFullPath();
if(inFullPath == null && fProject.getLocation().isPrefixOf(inLocation)){
inFullPath = fProject.getFullPath().append(inLocation.removeFirstSegments(fProject.getLocation().segmentCount()));
}
} else {
IPath projPath = inFullPath;
inFullPath = fProject.getFullPath().append(inFullPath);

View file

@ -42,7 +42,10 @@ public class DefaultBuildDescriptionFactory implements IBuildDescriptionFactory
* @see org.eclipse.cdt.managedbuilder.builddescription.IBuildDescriptionFactory#getSupportedMethods()
*/
public int getSupportedMethods() {
return BuildDescriptionManager.REMOVED | BuildDescriptionManager.REBUILD | BuildDescriptionManager.DEPS_DEPFILE_INFO;
return BuildDescriptionManager.REMOVED
| BuildDescriptionManager.REBUILD
| BuildDescriptionManager.DEPFILES
| BuildDescriptionManager.DEPS;
}
}

View file

@ -155,6 +155,9 @@ public class StepBuilder implements IBuildModelBuilder {
IBuildResource bRcs[] = fStep.getOutputResources();
for(int i = 0; i < bRcs.length; i++){
if(!bRcs[i].isProjectResource())
continue;
IResource rc = BuildDescriptionManager.findResourceForBuildResource(bRcs[i]);
if(rc != null){
try {

View file

@ -451,7 +451,7 @@ public class GeneratedMakefileBuilder extends ACBuilder {
//use a build desacription model to calculate the resources to be cleaned
//only in case there are some changes to the project sources or build information
try{
int flags = BuildDescriptionManager.REBUILD | BuildDescriptionManager.DEPS_DEPFILE_INFO;
int flags = BuildDescriptionManager.REBUILD | BuildDescriptionManager.DEPFILES | BuildDescriptionManager.DEPS;
if(delta != null)
flags |= BuildDescriptionManager.REMOVED;
@ -1207,7 +1207,7 @@ public class GeneratedMakefileBuilder extends ACBuilder {
IResourceDelta delta = null;
if(buildIncrementaly){
flags = BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED;
flags = BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED | BuildDescriptionManager.DEPS;
delta = getDelta(currentProject);
}
@ -1370,7 +1370,7 @@ public class GeneratedMakefileBuilder extends ACBuilder {
IResourceDelta delta = null;
if(buildIncrementaly){
flags = BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED;
flags = BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED | BuildDescriptionManager.DEPS;
delta = getDelta(currentProject);
}

View file

@ -0,0 +1,98 @@
/**********************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX Software Systems - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.managedbuilder.pdomdepgen;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyCalculator;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
* @author Doug Schaefer
*/
public class PDOMDependencyCalculator implements IManagedDependencyCalculator {
private final IPath source;
private final IResource resource;
private final IBuildObject buildContext;
private final ITool tool;
private final IPath topBuildDirectory;
private IPath[] dependencies;
public PDOMDependencyCalculator(IPath source, IResource resource, IBuildObject buildContext, ITool tool, IPath topBuildDirectory) {
this.source = source;
this.resource = resource;
this.buildContext = buildContext;
this.tool = tool;
this.topBuildDirectory = topBuildDirectory;
}
public IPath[] getAdditionalTargets() {
return null;
}
public IPath[] getDependencies() {
if (dependencies == null) {
if (resource != null) {
ICProject project = CoreModel.getDefault().create(resource.getProject());
try {
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
PDOMFile file = pdom.getFile(resource.getLocation());
if (file != null) {
PDOMFile[] includes = file.getAllIncludes();
List/*<IPath>*/ list = new ArrayList/*<IPath>*/();
for (int i = 0; i < includes.length; ++i)
list.add(new Path(includes[i].getFileName().getString()));
dependencies = (IPath[])list.toArray(new IPath[list.size()]);
} else
dependencies = new IPath[0];
} catch (CoreException e) {
// Activator.getDefault().getLog().log(e.getStatus());
dependencies = new IPath[0];
}
} else
dependencies = new IPath[0];
}
return dependencies;
}
public IBuildObject getBuildContext() {
return buildContext;
}
public IPath getSource() {
return source;
}
public ITool getTool() {
return tool;
}
public IPath getTopBuildDirectory() {
return topBuildDirectory;
}
}

View file

@ -0,0 +1,59 @@
/**********************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX Software Systems - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.managedbuilder.pdomdepgen;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGenerator2;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyInfo;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
/**
* @author Doug Schaefer
*
*/
public class PDOMDependencyGenerator implements IManagedDependencyGenerator2 {
public int getCalculatorType() {
return IManagedDependencyGenerator2.TYPE_CUSTOM;
}
public String getDependencyFileExtension(IConfiguration buildContext, ITool tool) {
return "";
}
public IManagedDependencyInfo getDependencySourceInfo(IPath source, IBuildObject buildContext, ITool tool, IPath topBuildDirectory) {
return getDependencySourceInfo(source, null, buildContext, tool, topBuildDirectory);
}
public IManagedDependencyInfo getDependencySourceInfo(IPath source, IResource resource, IBuildObject buildContext, ITool tool, IPath topBuildDirectory) {
if(resource == null && source != null){
if(!source.isAbsolute())
source = topBuildDirectory.append(source);
IFile files[] = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(source);
if(files.length > 0)
resource = files[0];
}
return new PDOMDependencyCalculator(source, resource, buildContext, tool, topBuildDirectory);
}
public boolean postProcessDependencyFile(IPath dependencyFile, IConfiguration buildContext, ITool tool, IPath topBuildDirectory) {
return false;
}
}