From ae3a1417f556d2d5a205dd5491c6a8b79aa7372b Mon Sep 17 00:00:00 2001 From: John Camelon Date: Tue, 29 Jul 2003 14:28:40 +0000 Subject: [PATCH] Patch for Sean Evoy In order to meet certain internal guidelines and to test the makefile generator, the build model replied to some answers with hard-coded information. This patch moves the information into the build model. Tests have been updated to reflect these changes, and the patch has been smoke-tested on Unix. --- core/org.eclipse.cdt.core.tests/ChangeLog | 14 ++++ .../build/managed/tests/AllBuildTests.java | 28 ++++++- core/org.eclipse.cdt.core.tests/plugin.xml | 22 ++++- core/org.eclipse.cdt.core/ChangeLog | 23 +++++- .../cdt/core/build/managed/ITarget.java | 15 ++++ .../core/build/managed/ManagedBuildInfo.java | 13 ++- .../internal/core/build/managed/Target.java | 57 +++++++++++-- .../schema/ManagedBuildTools.exsd | 21 +++++ .../core/GeneratedMakefileBuilder.java | 50 ----------- .../cdt/internal/core/MakefileGenerator.java | 4 +- core/org.eclipse.cdt.ui/ChangeLog | 10 +++ core/org.eclipse.cdt.ui/plugin.xml | 82 +++++++++++++++++++ 12 files changed, 269 insertions(+), 70 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 386e27aa610..607b2b73dc9 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -20,6 +20,20 @@ 2003-07-28 John Camelon Added/moved tests as necessary for bugfix 40842 & 40843. +2003-07-28 Sean Evoy + In order to meet certain internal guidelines and to test the makefile + generator, the build model replied to some answers with hard-coded information. + This patch moves the information into the build model. + + * plugin.xml: + Added information to the target tags to test inheritence and + overridding the make command and clean command attributes. + + * build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java: + Added code to test the make command and clean command attributes in + Targets. Also added a test to insure that sub-sub targets inherit settings + properly. + 2003-07-28 Andrew Niefer This patch creates a new failing test class : FullParseFailedTests. This is for writing failed tests on the parser doing COMPLETE_PARSE. diff --git a/core/org.eclipse.cdt.core.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java b/core/org.eclipse.cdt.core.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java index a971fe8e819..4b024815c0f 100644 --- a/core/org.eclipse.cdt.core.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java +++ b/core/org.eclipse.cdt.core.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java @@ -74,6 +74,7 @@ public class AllBuildTests extends TestCase { public void testExtensions() throws Exception { ITarget testRoot = null; ITarget testSub = null; + ITarget testSubSub = null; // Note secret null parameter which means just extensions ITarget[] targets = ManagedBuildManager.getDefinedTargets(null); @@ -84,17 +85,22 @@ public class AllBuildTests extends TestCase { if (target.getName().equals("Test Root")) { testRoot = target; checkRootTarget(testRoot, "x"); - } else if (target.getName().equals("Test Sub")) { testSub = target; checkSubTarget(testSub); + } else if (target.getName().equals("Test Sub Sub")) { + testSubSub = target; + checkSubSubTarget(testSubSub); } } - + // All these targets are defines in the plugin files, so none + // of them should be null at this point assertNotNull(testRoot); assertNotNull(testSub); + assertNotNull(testSubSub); } + /** * The purpose of this test is to exercise the build path info interface. * To get to that point, a new target/config has to be created in the test @@ -465,8 +471,12 @@ public class AllBuildTests extends TestCase { */ private void checkRootTarget(ITarget target, String oicValue) throws BuildException { // Target stuff + String expectedCleanCmd = "del /myworld"; + String expectedMakeCommand = "make"; assertTrue(target.isTestTarget()); assertEquals(target.getDefaultExtension(), rootExt); + assertEquals(expectedCleanCmd, target.getCleanCommand()); + assertEquals(expectedMakeCommand, target.getMakeCommand()); // Tools ITool[] tools = target.getTools(); @@ -570,6 +580,16 @@ public class AllBuildTests extends TestCase { assertEquals("doIt", tools[0].getToolCommand()); } + /** + * @param testSubSub + */ + private void checkSubSubTarget(ITarget target) { + // Check the inherited clean command + assertEquals("rm -yourworld", target.getCleanCommand()); + assertEquals("nmake", target.getMakeCommand()); + + } + /* * Do a sanity check on the values in the sub-target. Most of the * sanity on the how build model entries are read is performed in @@ -578,6 +598,10 @@ public class AllBuildTests extends TestCase { * in the sub target, the test does a sanity check just to be complete. */ private void checkSubTarget(ITarget target) throws BuildException { + // Check the overridden clan command + assertEquals("rm -yourworld", target.getCleanCommand()); + assertEquals("gmake", target.getMakeCommand()); + // Make sure this is a test target assertTrue(target.isTestTarget()); // Make sure the build artifact extension is there diff --git a/core/org.eclipse.cdt.core.tests/plugin.xml b/core/org.eclipse.cdt.core.tests/plugin.xml index 6fed9577df1..c0fd0d79f94 100644 --- a/core/org.eclipse.cdt.core.tests/plugin.xml +++ b/core/org.eclipse.cdt.core.tests/plugin.xml @@ -27,10 +27,13 @@ name="Tools for Build Test" point="org.eclipse.cdt.core.ManagedBuildInfo"> + makeCommand="gmake" + makeFlags="-d" + parent="test.root"> @@ -122,8 +128,8 @@ + + diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 1b5a2573c50..de42f85c772 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,5 +1,26 @@ +2003-07-28 Sean Evoy + In order to meet certain internal guidelines and to test the makefile + generator, the build model replied to some answers with hard-coded information. + This patch moves the information into the build model. + + * schema/ManagedBuildTools.exsd + * build/org/eclipse/cdt/core/build/managed/ITarget.java + * build/org/eclipse/cdt/internal/core/build/managed/Target.java + * build/org/eclipse/cdt/internal/core/build/managed/ManagedBuildInfo.java: + Added code to correctly extract and persist the make command and clean + command from a Target/ITarget. Added the attributes to the schema. Removed + the hard-coded answers from the ManagedBuildManager. + + * src/org/eclipse/cdt/internal/core/GeneratedMakefileBuilder.java: + Removed two methods that were no longer invoked from the builder. + + * src/org/eclipse/cdt/internal/core/MakefileGenerator.java: + Corrected a bug in the makefile generator whereby the output prefix was applied + twice to library targets, i.e. liblibfoo.a instead of libfoo.a. + + 2003-07-24 Sean Evoy - *src/org/eclipse/cdt/internal/core/MakefileGenerator.java: + * src/org/eclipse/cdt/internal/core/MakefileGenerator.java: Added code to place interproject dependencies in target build rule, added code to properly put output prefixes on library names, and added code to put library link arguments at the end of the depednency list diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java index 2eefd1c879f..163d2d9cc17 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java @@ -46,6 +46,13 @@ public interface ITarget extends IBuildObject { */ public String getArtifactName(); + /** + * Answers the OS-specific command to remove files created by the build + * + * @return + */ + public String getCleanCommand(); + /** * Returns all of the configurations defined by this target. * @return @@ -60,6 +67,13 @@ public interface ITarget extends IBuildObject { */ public String getDefaultExtension(); + /** + * Answers the name of the make utility for the target. + * + * @return + */ + public String getMakeCommand(); + /** * Returns the configuration with the given id, or null if not found. * @@ -110,5 +124,6 @@ public interface ITarget extends IBuildObject { * @param name The name of the build artifact. */ public void setBuildArtifact(String name); + } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ManagedBuildInfo.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ManagedBuildInfo.java index 4aa43626f60..b2c6090d122 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ManagedBuildInfo.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ManagedBuildInfo.java @@ -116,8 +116,11 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo { * @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getCleanCommand() */ public String getCleanCommand() { - // TODO Get from the model - return new String("rm -rf"); + // Get from the model + String command = new String(); + ITarget target = getDefaultTarget(); + command = target.getCleanCommand(); + return command; } /* (non-Javadoc) @@ -276,8 +279,10 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo { * @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getMakeCommand() */ public String getMakeCommand() { - // TODO Don't hard-code this - return new String("make"); + String command = new String(); + ITarget target = getDefaultTarget(); + command = target.getMakeCommand(); + return command; } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java index b01bf3ba74d..4c13d741c83 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java @@ -31,16 +31,18 @@ import org.w3c.dom.Node; */ public class Target extends BuildObject implements ITarget { - private ITarget parent; - private IResource owner; - private List tools; - private Map toolMap; - private List configurations; + private String artifactName; + private String cleanCommand; private Map configMap; + private List configurations; + private String defaultExtension; private boolean isAbstract = false; private boolean isTest = false; - private String artifactName; - private String defaultExtension; + private String makeCommand; + private IResource owner; + private ITarget parent; + private Map toolMap; + private List tools; private static final IConfiguration[] emptyConfigs = new IConfiguration[0]; private static final String EMPTY_STRING = new String(); @@ -66,6 +68,8 @@ public class Target extends BuildObject implements ITarget { this.artifactName = parent.getArtifactName(); this.defaultExtension = parent.getDefaultExtension(); this.isTest = parent.isTestTarget(); + this.cleanCommand = parent.getCleanCommand(); + this.makeCommand = parent.getMakeCommand(); // Hook me up IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(owner, true); @@ -110,6 +114,20 @@ public class Target extends BuildObject implements ITarget { // Is this a test target isTest = ("true".equals(element.getAttribute("isTest"))); + + // Get the clean command + cleanCommand = element.getAttribute("cleanCommand"); + if (cleanCommand == null) { + // See if it defined in the parent + cleanCommand = parent.getCleanCommand(); + } + + // Get the make command + makeCommand = element.getAttribute("makeCommand"); + if (makeCommand == null) { + // See if it defined in the parent + makeCommand = parent.getMakeCommand(); + } IConfigurationElement[] targetElements = element.getChildren(); for (int k = 0; k < targetElements.length; ++k) { @@ -159,6 +177,12 @@ public class Target extends BuildObject implements ITarget { // Is this a test target isTest = ("true".equals(element.getAttribute("isTest"))); + + // Get the clean command + cleanCommand = element.getAttribute("cleanCommand"); + + // Get the make command + makeCommand = element.getAttribute("makeCommand"); Node child = element.getFirstChild(); while (child != null) { @@ -184,6 +208,8 @@ public class Target extends BuildObject implements ITarget { element.setAttribute("artifactName", getArtifactName()); element.setAttribute("defaultExtension", getDefaultExtension()); element.setAttribute("isTest", isTest ? "true" : "false"); + element.setAttribute("cleanCommand", getCleanCommand()); + element.setAttribute("makeCommand", getMakeCommand()); if (configurations != null) for (int i = 0; i < configurations.size(); ++i) { @@ -194,6 +220,14 @@ public class Target extends BuildObject implements ITarget { } } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.ITarget#getMakeCommand() + */ + public String getMakeCommand() { + // Return the name of the make utility + return makeCommand == null ? EMPTY_STRING : makeCommand; + } + public String getName() { return (name == null && parent != null) ? parent.getName() : name; } @@ -267,6 +301,14 @@ public class Target extends BuildObject implements ITarget { return defaultExtension == null ? EMPTY_STRING : defaultExtension; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.ITarget#getCleanCommand() + */ + public String getCleanCommand() { + // Return the command used to remove files + return cleanCommand == null ? EMPTY_STRING : cleanCommand; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.ITarget#getArtifactName() */ @@ -325,4 +367,5 @@ public class Target extends BuildObject implements ITarget { public void setBuildArtifact(String name) { artifactName = name; } + } diff --git a/core/org.eclipse.cdt.core/schema/ManagedBuildTools.exsd b/core/org.eclipse.cdt.core/schema/ManagedBuildTools.exsd index af1df44f8d5..c87d96db2e3 100644 --- a/core/org.eclipse.cdt.core/schema/ManagedBuildTools.exsd +++ b/core/org.eclipse.cdt.core/schema/ManagedBuildTools.exsd @@ -358,6 +358,27 @@ Two additional types exist to flag options of special relevance to the build mod + + + + This attribute maintains the command that removes files for a particular target. For example, on POSIX targets like Linuc, Solaris, or Cygwin, the command would be <code>rm -rf</code> whereas on Win32 platforms it would be <code>del /F /S /Q</code> + + + + + + + + + + + + + + + + + diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/GeneratedMakefileBuilder.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/GeneratedMakefileBuilder.java index 5f81f777a85..0f1dea7e89b 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/GeneratedMakefileBuilder.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/GeneratedMakefileBuilder.java @@ -11,7 +11,6 @@ package org.eclipse.cdt.internal.core; * IBM Rational Software - Initial API and implementation * **********************************************************************/ -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; @@ -31,16 +30,12 @@ import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.cdt.core.resources.ACBuilder; import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.resources.MakeUtil; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.resources.IResourceStatus; import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -195,51 +190,6 @@ public class GeneratedMakefileBuilder extends ACBuilder { monitor.worked(1); } - protected IPath getBuildDirectory(String dirName) throws CoreException { - // Create or get the handle for the build directory - IFolder folder = getProject().getFolder(dirName); - if (!folder.exists()) { - try { - folder.create(false, true, null); - } - catch (CoreException e) { - if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) - folder.refreshLocal(IResource.DEPTH_ZERO, null); - else - throw e; - } - } - return folder.getFullPath(); - } - - /** - * Gets the makefile for the project. It may be empty. - * - * @return The IFile to generate the makefile into. - */ - protected IFile getMakefile(IPath filePath, IProgressMonitor monitor) throws CoreException { - // Create or get the handle for the makefile - IWorkspaceRoot root = CCorePlugin.getWorkspace().getRoot(); - IFile newFile = root.getFileForLocation(filePath); - if (newFile == null) { - newFile = root.getFile(filePath); - } - // Create the file if it does not exist - ByteArrayInputStream contents = new ByteArrayInputStream(new byte[0]); - try { - newFile.create(contents, false, monitor); - } - catch (CoreException e) { - // If the file already existed locally, just refresh to get contents - if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) - newFile.refreshLocal(IResource.DEPTH_ZERO, null); - else - throw e; - } - // TODO handle long running file operation - return newFile; - } - /** * @param makefilePath * @param info diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/MakefileGenerator.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/MakefileGenerator.java index 801371d0dd9..b0f3c820e58 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/MakefileGenerator.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/MakefileGenerator.java @@ -298,7 +298,7 @@ public class MakefileGenerator { * ; make all> * ; make all> * ; make all> - * $(BUILD_TOOL) $(FLAGS) $(OUTPUT_FLAG) $(OUTPUT_PREFIX)$@ $^ $(LIB_DEPS) + * $(BUILD_TOOL) $(FLAGS) $(OUTPUT_FLAG) $@ $^ $(LIB_DEPS) */ String cmd = info.getToolForTarget(extension); String flags = info.getFlagsForTarget(extension); @@ -323,7 +323,7 @@ public class MakefileGenerator { e.printStackTrace(); } - buffer.append(TAB + cmd + WHITESPACE + flags + WHITESPACE + outflag + WHITESPACE + outputPrefix + "$@" + WHITESPACE + "$^"); + buffer.append(TAB + cmd + WHITESPACE + flags + WHITESPACE + outflag + WHITESPACE + "$@" + WHITESPACE + "$^"); String[] libraries = info.getLibsForTarget(extension); for (int i = 0; i < libraries.length; i++) { String lib = libraries[i]; diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index f53f24f1fda..64600fafefc 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,13 @@ +2003-07-28 Sean Evoy + In order to meet certain internal guidelines and to test the makefile + generator, the build model replied to some answers with hard-coded information. + This patch moves the information into the build model. + + * plugin.xml: + Added new attributes to Targets to add make command, clean command and + make flag information. I also added a toolchain specification for Solaris, but + it is turned off for now until I test it. + 2003-07-24 Sean Evoy * plugin.xml: Added new attributes to tools and changed the value type enum for diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index d9a3c013d98..421478d7bce 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -621,9 +621,12 @@ name="Managed Build Tools Description" point="org.eclipse.cdt.core.ManagedBuildInfo"> + + + + + + + + + + + + + + + + + + + + + + + +