From a3767b2d5ce3b717d6a99768b0534f179587c8f4 Mon Sep 17 00:00:00 2001 From: Chris Recoskie Date: Wed, 6 May 2009 12:00:31 +0000 Subject: [PATCH] fix for 275137 (Internal builder claims nothing needs to be built) --- .../buildmodel/IBuildResource.java | 6 +- .../internal/buildmodel/BuildDescription.java | 73 +++++++++++++------ .../internal/buildmodel/BuildResource.java | 24 ++++-- .../makegen/gnu/GnuMakefileGenerator.java | 2 +- 4 files changed, 73 insertions(+), 32 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildResource.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildResource.java index 43a3b4c2a40..d17b1c89b25 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildResource.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildResource.java @@ -21,14 +21,16 @@ import org.eclipse.core.runtime.IPath; */ public interface IBuildResource { /** - * Returns the resource location + * Returns the absolute path to the resource as seen on the target machine. * * @return IPath */ IPath getLocation(); /** - * Returns the full path to the build resource as seen on the target machine. + * In case the resource is a workspace resource, + * returns the full workspace path for the resource + * otherwise returns null * * @return IPath */ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildDescription.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildDescription.java index 736b365bfea..05edfea353a 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildDescription.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildDescription.java @@ -71,6 +71,7 @@ import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyInfo; import org.eclipse.cdt.managedbuilder.pdomdepgen.PDOMDependencyGenerator; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -254,6 +255,8 @@ public class BuildDescription implements IBuildDescription { } protected IPath calcResourceLocation(IResource rc){ + + //return rc.getFullPath(); IPath rcLocation = rc.getLocation(); if(rcLocation == null){ IPath fullPath = rc.getFullPath(); @@ -1020,29 +1023,42 @@ public class BuildDescription implements IBuildDescription { List list = new ArrayList(); for(int k = 0; k < paths.length; k++){ IPath outFullPath = paths[k]; - IPath outLocation; - + IPath outWorkspacePath = paths[k]; + IPath outProjPath; + IPath projLocation = new Path(fProject.getLocationURI().getPath()); if(outFullPath.isAbsolute()){ - outLocation = outFullPath; - - IPath projLocation = new Path(fProject.getLocationURI().getPath()); - - if(projLocation.isPrefixOf(outLocation)) - outFullPath = projLocation.append(outLocation.removeFirstSegments(projLocation.segmentCount())); - else - outFullPath = null; + outProjPath = outFullPath; + + if(projLocation.isPrefixOf(outProjPath)) { + // absolute location really points to same place the project lives, so it IS a project file + outProjPath = outProjPath.removeFirstSegments(projLocation.segmentCount()); + outFullPath = projLocation.append(outProjPath.removeFirstSegments(projLocation.segmentCount())); + outWorkspacePath = fProject.getFullPath().append(outProjPath); + } + else { + // absolute path to somewhere outside the workspace + outProjPath = null; + outWorkspacePath = null; + } } else { if (outFullPath.segmentCount() == 1) { - outFullPath = outDirPath.append(outFullPath); - outLocation = getProjectLocation().append(outFullPath.removeFirstSegments(1)); + outFullPath = projLocation.append(outDirPath.removeFirstSegments(1).append(outFullPath)); + outProjPath = outDirPath.removeFirstSegments(1).append(outWorkspacePath); + outWorkspacePath = fProject.getFullPath().append(outProjPath); } else { - outLocation = getTopBuildDirLocation().append(outFullPath); - outFullPath = getTopBuildDirFullPath().append(outFullPath); + outProjPath = fProject.getFullPath().removeFirstSegments(1).append(outDirPath.removeFirstSegments(1).append(outWorkspacePath)); + + if(outDirPath.isPrefixOf(outFullPath)) { + outFullPath.removeFirstSegments(outDirPath.segmentCount()); + } + + outFullPath = projLocation.append(outDirPath.removeFirstSegments(1).append(outFullPath.lastSegment())); + outWorkspacePath = fProject.getFullPath().append(outProjPath);; } } - BuildResource outRc = createResource(outLocation, getURIForFullPath(outFullPath)); + BuildResource outRc = createResource(outWorkspacePath, getURIForFullPath(outFullPath)); list.add(outRc); buildArg.addResource(outRc); @@ -1056,10 +1072,22 @@ public class BuildDescription implements IBuildDescription { // Basically, assume that we use the same type of URI that the project uses. // Create one using the same info, except point the path at the path provided. URI projURI = fProject.getLocationURI(); + + try { + IFileStore projStore = EFS.getStore(projURI); + + if(projStore.toLocalFile(EFS.NONE, null) != null) { + // local file + return URIUtil.toURI(fullPath); + } + } catch (CoreException e1) { + ManagedBuilderCorePlugin.log(e1); + return null; + } + try { URI newURI = new URI(projURI.getScheme(), projURI.getUserInfo(), - projURI.getHost(), projURI.getPort(), fullPath - .toPortableString(), projURI.getQuery(), projURI + projURI.getHost(), projURI.getPort(), fullPath.toString(), projURI.getQuery(), projURI .getFragment()); return newURI; } catch (URISyntaxException e) { @@ -1938,7 +1966,8 @@ public class BuildDescription implements IBuildDescription { inLocation = calcResourceLocation(res); } - BuildResource rc = createResource(inLocation, getURIForFullPath(inFullPath)); + + BuildResource rc = createResource(inFullPath, getURIForFullPath(inLocation)); buildArg.addResource(rc); return rc; @@ -1975,15 +2004,15 @@ public class BuildDescription implements IBuildDescription { } public BuildResource createResource(IResource rc){ - return createResource(calcResourceLocation(rc), rc.getLocationURI()); + return createResource(rc.getFullPath(), rc.getLocationURI()); } - public BuildResource createResource(IPath projPath, URI locationURI){ + public BuildResource createResource(IPath fullWorkspacePath, URI locationURI){ - BuildResource rc = (BuildResource)getBuildResource(projPath); + BuildResource rc = (BuildResource)getBuildResource(fullWorkspacePath); if(rc == null) - rc = new BuildResource(this, projPath, locationURI); + rc = new BuildResource(this, fullWorkspacePath, locationURI); return rc; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildResource.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildResource.java index 57ed9b47575..e4a5efa500f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildResource.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildResource.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.managedbuilder.buildmodel.IBuildIOType; import org.eclipse.cdt.managedbuilder.buildmodel.IBuildResource; import org.eclipse.cdt.managedbuilder.buildmodel.IBuildStep; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -30,7 +31,7 @@ public class BuildResource implements IBuildResource { private BuildIOType fProducerArg; private boolean fNeedsRebuild; private boolean fIsRemoved; - private IPath fLocation; + private IPath fFullWorkspacePath; private boolean fIsProjectRc; private BuildDescription fInfo; private URI fLocationURI; @@ -39,35 +40,44 @@ public class BuildResource implements IBuildResource { this(info, info.calcResourceLocation(rc), rc.getLocationURI()); } - protected BuildResource(BuildDescription info, IPath projectPath, URI locationURI){ + protected BuildResource(BuildDescription info, IPath fullWorkspacePath, URI locationURI){ if(locationURI == null) throw new IllegalArgumentException(); // must point to somewhere! fLocationURI = locationURI; - fLocation = projectPath; + fFullWorkspacePath = fullWorkspacePath; fInfo = info; - fIsProjectRc = (projectPath != null); + fIsProjectRc = (fullWorkspacePath != null); info.resourceCreated(this); if(DbgUtil.DEBUG) - DbgUtil.trace("resource " + projectPath + " created"); //$NON-NLS-1$ //$NON-NLS-2$ + DbgUtil.trace("resource " + fullWorkspacePath + " created"); //$NON-NLS-1$ //$NON-NLS-2$ } /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildResource#getLocation() */ public IPath getLocation() { - return fLocation; + IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(fFullWorkspacePath); + if(resource == null) { + return new Path(fLocationURI.getPath()); + } + + if(resource.getLocation() != null) + return resource.getLocation(); + else + return new Path(fLocationURI.getPath()); } /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildResource#getFullPath() */ public IPath getFullPath() { - return new Path(fLocationURI.getPath()); + return fFullWorkspacePath; + //return new Path(getLocationURI().getPath().toString()); } /* (non-Javadoc) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java index 2490898e74b..77b397e8cad 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java @@ -2438,7 +2438,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator2 { if(localFile != null) { // it's a local file... use project location for proper path formatting - projectLocation = project.getLocation().addTrailingSeparator().toOSString(); + projectLocation = project.getLocation().addTrailingSeparator().toString(); } else { // remote... get the path from the URI