diff options
author | Mikhail Sennikovsky | 2006-04-06 09:20:00 +0000 |
---|---|---|
committer | Mikhail Sennikovsky | 2006-04-06 09:20:00 +0000 |
commit | 8f100afd6ce737232888384980887c4369742169 (patch) | |
tree | 40624a3c1c86f3d9e746047678f6dce717ce9be3 /build/org.eclipse.cdt.managedbuilder.core/src | |
parent | d431889736c03b1e5793435a40251306ed1f11c0 (diff) | |
download | org.eclipse.cdt-8f100afd6ce737232888384980887c4369742169.tar.gz org.eclipse.cdt-8f100afd6ce737232888384980887c4369742169.tar.xz org.eclipse.cdt-8f100afd6ce737232888384980887c4369742169.zip |
MBS Internal Builder implementation. This functionality is experimental and is disabled for now.
Fixes for the Build Model implementation.
Diffstat (limited to 'build/org.eclipse.cdt.managedbuilder.core/src')
14 files changed, 977 insertions, 58 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/BuildDescriptionManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/BuildDescriptionManager.java index 8ac6c1895ee..141a9d18c20 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/BuildDescriptionManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/BuildDescriptionManager.java @@ -121,7 +121,7 @@ public class BuildDescriptionManager { } if(proceed && !fVisitedSteps.contains(action)){ - proceed = visitor.visit(action); + proceed = visitor.visit(action) == IStepVisitor.VISIT_CONTINUE; fVisitedSteps.add(action); } @@ -215,7 +215,7 @@ public class BuildDescriptionManager { * @param bRc build resource * @return IResource */ - public static IResource getResourceFromBuildResource(IBuildResource bRc){ + public static IResource findResourceForBuildResource(IBuildResource bRc){ IProject project = bRc.getBuildDescription().getConfiguration().getOwner().getProject(); IPath path = bRc.getFullPath(); @@ -236,7 +236,7 @@ public class BuildDescriptionManager { List failList = new ArrayList(); for(int i = 0; i < bRcs.length; i++){ - IResource rc = getResourceFromBuildResource(bRcs[i]); + IResource rc = findResourceForBuildResource(bRcs[i]); if(rc != null){ try { rc.delete(true, null); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildDescription.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildDescription.java index b056751af4b..99507491d68 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildDescription.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildDescription.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.managedbuilder.buildmodel; import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; /** @@ -42,8 +43,17 @@ public interface IBuildDescription { * * @return the IBuildResource or null if not found */ - IBuildResource getResourceForLocation(IPath location); - + IBuildResource getBuildResource(IPath location); + + /** + * Returns the Build resource for the given resource + * + * @param location + * + * @return the IBuildResource or null if not found + */ + IBuildResource getBuildResource(IResource resource); + /** * Returns all resources used in the build * diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IStepVisitor.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IStepVisitor.java index fa37a1e9c71..08ebee65dbe 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IStepVisitor.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IStepVisitor.java @@ -21,6 +21,8 @@ import org.eclipse.core.runtime.CoreException; * */ public interface IStepVisitor { + public static final int VISIT_CONTINUE = 1; + public static final int VISIT_STOP = 2; /** * this call-back method is called by the build description @@ -32,5 +34,5 @@ public interface IStepVisitor { * @return * @throws CoreException */ - boolean visit(IBuildStep step) throws CoreException; + int visit(IBuildStep step) throws CoreException; } 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 e1ed2b9b0e9..f92ddda5cd6 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 @@ -23,6 +23,7 @@ import java.util.Vector; import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager; import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildIOType; import org.eclipse.cdt.managedbuilder.buildmodel.IBuildResource; import org.eclipse.cdt.managedbuilder.buildmodel.IBuildStep; import org.eclipse.cdt.managedbuilder.buildmodel.IStepVisitor; @@ -40,6 +41,7 @@ import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable; import org.eclipse.cdt.managedbuilder.internal.core.Configuration; import org.eclipse.cdt.managedbuilder.internal.macros.FileContextData; import org.eclipse.cdt.managedbuilder.internal.macros.OptionContextData; @@ -52,6 +54,7 @@ import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IResourceDeltaVisitor; import org.eclipse.core.resources.IResourceProxy; import org.eclipse.core.resources.IResourceProxyVisitor; +import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -95,6 +98,8 @@ public class BuildDescription implements IBuildDescription { private Map fExtToToolAndTypeListMap = new HashMap(); + private Map fEnvironment; + class ToolAndType{ ITool fTool; IInputType fType; @@ -109,7 +114,14 @@ public class BuildDescription implements IBuildDescription { private class RcVisitor implements IResourceProxyVisitor, IResourceDeltaVisitor{ + private boolean fPostProcessMode; + RcVisitor(){ + setMode(false); + } + + public void setMode(boolean postProcess){ + fPostProcessMode = postProcess; } public boolean visit(IResourceProxy proxy) throws CoreException { @@ -121,17 +133,65 @@ public class BuildDescription implements IBuildDescription { return !isGenerated(proxy.requestFullPath()); } - - public boolean visit(IResourceDelta delta) throws CoreException { + + protected boolean postProcessVisit(IResourceDelta delta){ IResource rc = delta.getResource(); if(rc.getType() == IResource.FILE){ - if(delta.getKind() == IResourceDelta.REMOVED - && getResourceForLocation(rc.getLocation()) == null) - doVisitFile(rc); + IPath rcLocation = calcResourceLocation(rc); + BuildResource bRc = (BuildResource)getBuildResource(rcLocation); + if(bRc != null){ + if(bRc.getProducerIOType() != null + && bRc.getProducerIOType().getStep() == fInputStep){ + if(delta.getKind() == IResourceDelta.REMOVED){ + if(checkFlags(BuildDescriptionManager.REMOVED)){ + bRc.setRemoved(true); + } + } else { + if(checkFlags(BuildDescriptionManager.REBUILD)){ + bRc.setRebuildState(true); + } + } + } else { + if(checkFlags(BuildDescriptionManager.REBUILD)){ + bRc.setRebuildState(true); + IBuildIOType type = bRc.getProducerIOType(); + if(type != null){ + ((BuildStep)type.getStep()).setRebuildState(true); + } + } + } + } + return false; + } + return true; + } + + public boolean removedCalcVisit(IResourceDelta delta) throws CoreException { + IResource rc = delta.getResource(); + if(rc.getType() == IResource.FILE){ + if(!isGenerated(rc.getFullPath())){ + //this is a project source, check the removed state + if(delta.getKind() == IResourceDelta.REMOVED + && checkFlags(BuildDescriptionManager.REMOVED)){ + IPath rcLocation = calcResourceLocation(rc); + BuildResource bRc = (BuildResource)getBuildResource(rcLocation); + + if(bRc == null){ + doVisitFile(rc); + } + } + } return false; } - return !isGenerated(rc.getFullPath()); + return true;//!isGenerated(rc.getFullPath()); + } + + + public boolean visit(IResourceDelta delta) throws CoreException { + if(fPostProcessMode) + return postProcessVisit(delta); + return removedCalcVisit(delta); } private void doVisitFile(IResource res) throws CoreException{ @@ -143,15 +203,31 @@ public class BuildDescription implements IBuildDescription { } + protected IPath calcResourceLocation(IResource rc){ + IPath rcLocation = rc.getLocation(); + if(rcLocation == null){ + IPath fullPath = rc.getFullPath(); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IProject proj = root.getProject(fullPath.segment(0)); + rcLocation = proj.getLocation(); + if(rcLocation != null){ + rcLocation = rcLocation.append(fullPath.removeFirstSegments(1)); + } else { + rcLocation = root.getLocation().append(fullPath); + } + } + return rcLocation; + } + private class StepCollector implements IStepVisitor{ private Set fStepSet = new HashSet(); - public boolean visit(IBuildStep action) throws CoreException { + public int visit(IBuildStep action) throws CoreException { if(DbgUtil.DEBUG){ DbgUtil.traceln("StepCollector: visiting step " + DbgUtil.stepName(action)); //$NON-NLS-1$ } fStepSet.add(action); - return true; + return VISIT_CONTINUE; } public BuildStep[] getSteps(){ @@ -172,7 +248,7 @@ public class BuildDescription implements IBuildDescription { /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.builddescription.IStepVisitor#visit(org.eclipse.cdt.managedbuilder.builddescription.IBuildStep) */ - public boolean visit(IBuildStep a) throws CoreException { + public int visit(IBuildStep a) throws CoreException { BuildStep action = (BuildStep)a; BuildResource rcs[] = (BuildResource[])action.getInputResources(); boolean rebuild = action.needsRebuild(); @@ -236,7 +312,7 @@ public class BuildDescription implements IBuildDescription { if(DbgUtil.DEBUG) DbgUtil.traceln("setting remove state for resource " + locationToRel(outRcs[i].getLocation()).toString()); //$NON-NLS-1$ - ((BuildResource)outRcs[i]).setRemoved(); + ((BuildResource)outRcs[i]).setRemoved(true); } } else if(rebuild){ @@ -258,7 +334,7 @@ public class BuildDescription implements IBuildDescription { if(DbgUtil.DEBUG) DbgUtil.traceln("<<leaving.."); //$NON-NLS-1$ - return true; + return VISIT_CONTINUE; } } @@ -305,7 +381,7 @@ public class BuildDescription implements IBuildDescription { initBase(cfg, null, 0); } - private void synchRebuildState() throws CoreException{ + public void synchRebuildState() throws CoreException{ if(DbgUtil.DEBUG) DbgUtil.traceln("--->Synch started"); //$NON-NLS-1$ @@ -600,10 +676,18 @@ public class BuildDescription implements IBuildDescription { fProject.accept(visitor, IResource.NONE); - if(checkFlags(BuildDescriptionManager.REMOVED) && fDelta != null) + if(checkFlags(BuildDescriptionManager.REMOVED) + && fDelta != null) fDelta.accept(visitor); handleMultiSteps(); + + visitor.setMode(true); + if((checkFlags(BuildDescriptionManager.REMOVED) + || checkFlags(BuildDescriptionManager.REBUILD)) + && fDelta != null) + fDelta.accept(visitor); + completeLinking(); synchRebuildState(); //TODO: trim(); @@ -1101,7 +1185,7 @@ public class BuildDescription implements IBuildDescription { String outExt = tool.getOutputExtension(inExt); outFullPath = resolvePercent(outFullPath.addFileExtension(outExt), buildRc.getLocation()); - outLocation = outLocation = fProject.getLocation().append(outFullPath.removeFirstSegments(1)); + outLocation = fProject.getLocation().append(outFullPath.removeFirstSegments(1)); BuildIOType buildArg = action.createIOType(false, true, null); @@ -1131,7 +1215,7 @@ public class BuildDescription implements IBuildDescription { return location; } - public IBuildResource getResourceForLocation(IPath location) { + public IBuildResource getBuildResource(IPath location) { return (BuildResource)fLocationToRcMap.get(location); } @@ -1158,6 +1242,23 @@ public class BuildDescription implements IBuildDescription { public IConfiguration getConfiguration() { return fCfg; } + + public Map getEnvironment(){ + if(fEnvironment == null) + fEnvironment = calculateEnvironment(); + return fEnvironment; + } + + protected Map calculateEnvironment(){ + IBuildEnvironmentVariable variables[] = ManagedBuildManager.getEnvironmentVariableProvider().getVariables(fCfg,true,true); + Map map = new HashMap(); + + for(int i = 0; i < variables.length; i++){ + IBuildEnvironmentVariable var = variables[i]; + map.put(var.getName(), var.getValue()); + } + return map; + } public IProject getProject() { return fProject; @@ -1417,11 +1518,13 @@ public class BuildDescription implements IBuildDescription { IPath projPath = inFullPath; inFullPath = fProject.getFullPath().append(inFullPath); - IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(inFullPath); - if(res != null) + IResource res = ResourcesPlugin.getWorkspace().getRoot().getFile(inFullPath);//.findMember(inFullPath); + inLocation = calcResourceLocation(res); +/* if(res != null) inLocation = res.getLocation(); else inLocation = fProject.getLocation().append(projPath); +*/ } BuildResource rc = createResource(inLocation, inFullPath); @@ -1444,12 +1547,12 @@ public class BuildDescription implements IBuildDescription { } public BuildResource createResource(IResource rc){ - return createResource(rc.getLocation(), rc.getFullPath()); + return createResource(calcResourceLocation(rc), rc.getFullPath()); } public BuildResource createResource(IPath location, IPath fullPath){ - BuildResource rc = (BuildResource)getResourceForLocation(location); + BuildResource rc = (BuildResource)getBuildResource(location); if(rc == null) rc = new BuildResource(this, location, fullPath); @@ -1628,7 +1731,7 @@ public class BuildDescription implements IBuildDescription { return fGeneratedPaths; } - private boolean isGenerated(IPath path){ + protected boolean isGenerated(IPath path){ IPath paths[] = getGeneratedPaths(); for(int i = 0; i < paths.length; i++){ if(paths[i].isPrefixOf(path)) @@ -1691,4 +1794,11 @@ public class BuildDescription implements IBuildDescription { public IBuildStep[] getSteps() { return (BuildStep[])fStepList.toArray(new BuildStep[fStepList.size()]); } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription#findBuildResource(org.eclipse.core.resources.IResource) + */ + public IBuildResource getBuildResource(IResource resource){ + return getBuildResource(calcResourceLocation(resource)); + } } 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 f3ae58809ef..aa80105ad65 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 @@ -31,7 +31,7 @@ public class BuildResource implements IBuildResource { private BuildDescription fInfo; protected BuildResource(BuildDescription info, IResource rc){ - this(info, rc.getLocation(), rc.getFullPath()); + this(info, info.calcResourceLocation(rc), rc.getFullPath()); } protected BuildResource(BuildDescription info, IPath location, IPath fullPath){ @@ -41,17 +41,6 @@ public class BuildResource implements IBuildResource { if(fFullPath != null) fIsProjectRc = fFullPath.segment(0).equals(info.getProject().getName()); - IResourceDelta delta = fInfo.getDelta(); - if(delta != null && isProjectResource()){ - IResourceDelta rcDelta = delta.findMember(getFullPath().removeFirstSegments(1)); - if(rcDelta != null){ - setRebuildState(true); - - if(rcDelta.getKind() == IResourceDelta.REMOVED) - setRemoved(); - } - - } info.resourceCreated(this); if(DbgUtil.DEBUG) @@ -99,28 +88,33 @@ public class BuildResource implements IBuildResource { return fIsRemoved; } - public void setRemoved() { - fIsRemoved = true; - fNeedsRebuild = false; + public void setRemoved(boolean removed) { + if(DbgUtil.DEBUG){ + if(removed) + DbgUtil.traceln("REMOVED state: resource " + DbgUtil.resourceName(this)); + } + fIsRemoved = removed; + if(fIsRemoved) + fNeedsRebuild = false; } public void setRebuildState(boolean rebuild){ fNeedsRebuild = rebuild; } - void addToArg(BuildIOType arg){ + protected void addToArg(BuildIOType arg){ if(arg.isInput()){ fDepArgs.add(arg); } else { - if(fProducerArg == null) + if(fProducerArg == null){ fProducerArg = arg; - else { + } else { String err = "ProducerArgument not null!!!\n"; //$NON-NLS-1$ if(DbgUtil.DEBUG){ err = err + "curent producer: " + DbgUtil.dumpStep(fProducerArg.getStep()) + "\n producer attempt: " + DbgUtil.dumpStep(arg.getStep()); //$NON-NLS-1$ //$NON-NLS-2$ } - throw new AssertionError(err); + throw new IllegalArgumentException(err); } } } @@ -129,10 +123,10 @@ public class BuildResource implements IBuildResource { if(arg.isInput()){ fDepArgs.remove(arg); } else { - if(fProducerArg == arg) + if(fProducerArg == arg){ fProducerArg = null; - else - throw new AssertionError("Resource is not produced by this arg!!!"); //$NON-NLS-1$ + }else + throw new IllegalArgumentException("Resource is not produced by this arg!!!"); //$NON-NLS-1$ } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildStep.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildStep.java index d9843a0b532..17804859008 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildStep.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildStep.java @@ -25,9 +25,11 @@ import org.eclipse.cdt.managedbuilder.buildmodel.IBuildResource; import org.eclipse.cdt.managedbuilder.buildmodel.IBuildStep; import org.eclipse.cdt.managedbuilder.core.BuildException; import org.eclipse.cdt.managedbuilder.core.IBuildObject; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator; import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo; +import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.internal.core.Configuration; @@ -50,6 +52,7 @@ public class BuildStep implements IBuildStep { private BuildDescription fBuildDescription; private IInputType fInputType; private ITool fLibTool; + private boolean fAssignToCalculated; protected BuildStep(BuildDescription des, ITool tool, IInputType inputType){ fTool = tool; @@ -240,13 +243,19 @@ public class BuildStep implements IBuildStep { if(fTool == null) return null; + if(cwd == null) + cwd = fBuildDescription.getDefaultBuildDirLocation(); + if(!cwd.isAbsolute()) cwd = fBuildDescription.getConfiguration().getOwner().getProject().getLocation().append(cwd); + performAsignToOption(cwd); + BuildResource inRc = getRcForMacros(true); BuildResource outRc = getRcForMacros(false); IPath inRcPath = inRc != null ? BuildDescriptionManager.getRelPath(cwd, inRc.getLocation()) : null; IPath outRcPath = outRc != null ? BuildDescriptionManager.getRelPath(cwd, outRc.getLocation()) : null; + IManagedCommandLineGenerator gen = fTool.getCommandLineGenerator(); FileContextData data = new FileContextData(inRcPath, outRcPath, null, fTool); IManagedCommandLineInfo info = gen.generateCommandLineInfo(fTool, @@ -258,16 +267,65 @@ public class BuildStep implements IBuildStep { resourcesToStrings(cwd, getPrimaryResources(true)), fTool.getCommandLinePattern()); - return createCommandsFromString(info.getCommandLine(), cwd); + return createCommandsFromString(info.getCommandLine(), cwd, getEnvironment()); + } + + protected Map getEnvironment(){ + return fBuildDescription.getEnvironment(); } - protected IBuildCommand[] createCommandsFromString(String cmd, IPath cwd){ - String[] cmds = cmd.split(" "); //$NON-NLS-1$ - IPath c = new Path(cmds[0]); - String[] args = new String[cmds.length - 1]; - System.arraycopy(cmds, 1, args, 0, args.length); + protected IBuildCommand[] createCommandsFromString(String cmd, IPath cwd, Map env){ + char arr[] = cmd.toCharArray(); + char expect = 0; + char prev = 0; +// int start = 0; + List list = new ArrayList(); + StringBuffer buf = new StringBuffer(); + for(int i = 0; i < arr.length; i++){ + char ch = arr[i]; + switch(ch){ + case '\'': + case '"': + if(expect == ch){ +// String s = cmd.substring(start, i); +// list.add(s); + expect = 0; +// start = i + 1; + } else if (expect == 0){ +// String s = cmd.substring(start, i); +// list.add(s); + expect = ch; +// start = i + 1; + } else { + buf.append(ch); + } + break; + case ' ': + if(expect == 0){ + if(prev != ' '){ + list.add(buf.toString()); + buf.delete(0, buf.length()); + } +// start = i + 1; + } else { + buf.append(ch); + } + break; + default: + buf.append(ch); + break; + + } + prev = ch; + } + + if(buf.length() > 0) + list.add(buf.toString()); - return new IBuildCommand[]{new BuildCommand(c, args, null, cwd, this)}; + IPath c = new Path((String)list.remove(0)); + String[] args = (String[])list.toArray(new String[list.size()]); + + return new IBuildCommand[]{new BuildCommand(c, args, env, cwd, this)}; } private BuildResource[] getPrimaryResources(boolean input){ @@ -398,4 +456,64 @@ public class BuildStep implements IBuildStep { public ITool getLibTool(){ return fLibTool; } + + protected void performAsignToOption(IPath cwd){ + if(fTool == null && !fAssignToCalculated) + return; + + fAssignToCalculated = true; + + IConfiguration cfg = fBuildDescription.getConfiguration(); + + for(Iterator iter = fInputTypes.iterator(); iter.hasNext();){ + BuildIOType bType = (BuildIOType)iter.next(); + IInputType type = (IInputType)bType.getIoType(); + + if(type == null) + continue; + + IOption option = fTool.getOptionBySuperClassId(type.getOptionId()); + IOption assignToOption = fTool.getOptionBySuperClassId(type.getAssignToOptionId()); + if (assignToOption != null && option == null) { + try { + BuildResource bRcs[] = (BuildResource[])bType.getResources(); + int optType = assignToOption.getValueType(); + if (optType == IOption.STRING) { + String optVal = ""; //$NON-NLS-1$ + for (int j=0; j<bRcs.length; j++) { + if (j != 0) { + optVal += " "; //$NON-NLS-1$ + } + optVal += BuildDescriptionManager.getRelPath(cwd, bRcs[j].getLocation()).toOSString(); + } + ManagedBuildManager.setOption(cfg, fTool, assignToOption, optVal); + } else if ( + optType == IOption.STRING_LIST || + optType == IOption.LIBRARIES || + optType == IOption.OBJECTS || + optType == IOption.INCLUDE_PATH || + optType == IOption.PREPROCESSOR_SYMBOLS){ + // Mote that when using the enumerated inputs, the path(s) must be translated from project relative + // to top build directory relative + String[] paths = new String[bRcs.length]; + for (int j=0; j<bRcs.length; j++) { + paths[j] = BuildDescriptionManager.getRelPath(cwd, bRcs[j].getLocation()).toOSString(); + } + ManagedBuildManager.setOption(cfg, fTool, assignToOption, paths); + } else if (optType == IOption.BOOLEAN) { + if (bRcs.length > 0) { + ManagedBuildManager.setOption(cfg, fTool, assignToOption, true); + } else { + ManagedBuildManager.setOption(cfg, fTool, assignToOption, false); + } + } else if (optType == IOption.ENUMERATED) { + if (bRcs.length > 0) { + ManagedBuildManager.setOption(cfg, fTool, assignToOption, BuildDescriptionManager.getRelPath(cwd, bRcs[0].getLocation()).toOSString()); + } + } + } catch( BuildException ex ) { + } + } + } + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java new file mode 100644 index 00000000000..9155310783e --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2006 Intel 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: + * Intel Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.internal.buildmodel; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.cdt.core.CommandLauncher; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildCommand; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; + +/** + * + * This class implements the IBuildCommand building + * To build the given command, create an instance of this class + * and invoke the build method + * + * NOTE: This class is subject to change and discuss, + * and is currently available in experimental mode only + * + */ +public class CommandBuilder implements IBuildModelBuilder { + private IBuildCommand fCmd; + private Process fProcess; + private String fErrMsg; + + protected class OutputStreamWrapper extends OutputStream { + private OutputStream fOut; + + public OutputStreamWrapper(OutputStream out){ + fOut = out; + } + + public void write(int b) throws IOException { + fOut.write(b); + } + + public void write(byte b[]) throws IOException { + fOut.write(b); + } + + public void write(byte b[], int off, int len) throws IOException { + fOut.write(b, off, len); + } + + public void flush() throws IOException { + fOut.flush(); + } + + public void close() throws IOException { + } + + } + + public CommandBuilder(IBuildCommand cmd){ + fCmd = cmd; + } + + protected OutputStream wrap(OutputStream out){ + return new OutputStreamWrapper(out); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.internal.builddescription.IBuildDescriptionBuilder#build(java.io.OutputStream, java.io.OutputStream, org.eclipse.core.runtime.IProgressMonitor) + */ + public int build(OutputStream out, OutputStream err, + IProgressMonitor monitor){ + + CommandLauncher launcher = new CommandLauncher(); + int status = STATUS_OK; + + launcher.showCommand(true); + + fProcess = launcher.execute(fCmd.getCommand(), fCmd.getArgs(), mapToStringArray(fCmd.getEnvironment()), fCmd.getCWD()); + + if (fProcess != null) { + try { + // Close the input of the process since we will never write to it + fProcess.getOutputStream().close(); + } catch (IOException e) { + } + //wrapping out and err streams to avoid their closure + int st = launcher.waitAndRead(wrap(out), wrap(err), + new SubProgressMonitor(monitor, + IProgressMonitor.UNKNOWN)); + switch(st){ + case CommandLauncher.OK: + if(fProcess.exitValue() != 0) + status = STATUS_ERROR_BUILD; + break; + case CommandLauncher.COMMAND_CANCELED: + status = STATUS_CANCELLED; + break; + default: + status = STATUS_ERROR_LAUNCH; + fErrMsg = launcher.getErrorMessage(); + break; + } + } else { + fErrMsg = launcher.getErrorMessage(); + if(DbgUtil.DEBUG) + DbgUtil.traceln("error launching the command: " + fErrMsg); //$NON-NLS-1$ + + status = STATUS_ERROR_LAUNCH; + } + + return status; + } + + public String getErrMsg(){ + return fErrMsg; + } + + private String[] mapToStringArray(Map map){ + if(map == null) + return null; + + List list = new ArrayList(); + + for(Iterator iter = map.entrySet().iterator(); iter.hasNext();){ + Map.Entry entry = (Map.Entry)iter.next(); + list.add((String)entry.getKey() + "=" + (String)entry.getValue()); //$NON-NLS-1$ + } + + return (String[])list.toArray(new String[list.size()]); + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/DescriptionBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/DescriptionBuilder.java new file mode 100644 index 00000000000..c8c07788279 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/DescriptionBuilder.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2006 Intel 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: + * Intel Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.internal.buildmodel; + +import java.io.OutputStream; + +import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildStep; +import org.eclipse.cdt.managedbuilder.buildmodel.IStepVisitor; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * + * This class implements the IBuildDescription building, + * that is the build of the entire configuration/project + * To perform a build, create an instance of this class + * and invoke the build method + * + * NOTE: This class is subject to change and discuss, + * and is currently available in experimental mode only + * + */ +public class DescriptionBuilder implements IBuildModelBuilder { + private IBuildDescription fDes; + private IPath fCWD; + private boolean fBuildIncrementaly; + private boolean fResumeOnErrs; + + private class BuildStepVisitor implements IStepVisitor{ + private OutputStream fOut; + private OutputStream fErr; + private IProgressMonitor fMonitor; + private GenDirInfo fDir = new GenDirInfo(fDes.getConfiguration()); + private int fStatus; + + public BuildStepVisitor(OutputStream out, OutputStream err, IProgressMonitor monitor){ + fOut = out; + fErr = err; + fMonitor = monitor; + fStatus = STATUS_OK; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IStepVisitor#visit(org.eclipse.cdt.managedbuilder.builddescription.IBuildStep) + */ + public int visit(IBuildStep action) throws CoreException { + if(fMonitor.isCanceled()) + return VISIT_STOP; + + if(DbgUtil.DEBUG) + DbgUtil.traceln("visiting step " + DbgUtil.stepName(action)); + if(!action.isRemoved() + && (!fBuildIncrementaly || action.needsRebuild())){ + if(DbgUtil.DEBUG) + DbgUtil.traceln("step " + DbgUtil.stepName(action) + " needs rebuild" ); + StepBuilder builder = new StepBuilder(action, fCWD, fResumeOnErrs, fDir); + + switch(builder.build(fOut, fErr, fMonitor)){ + case STATUS_OK: + break; + case STATUS_CANCELLED: + fStatus = STATUS_CANCELLED; + break; + case STATUS_ERROR_BUILD: + case STATUS_ERROR_LAUNCH: + default: + fStatus = STATUS_ERROR_BUILD; + break; + } + } + + if(fStatus != STATUS_CANCELLED + && (fResumeOnErrs || fStatus == STATUS_OK)) + return VISIT_CONTINUE; + return VISIT_STOP; + } + + } + + public DescriptionBuilder(IBuildDescription des){ + this(des, true); + } + + public DescriptionBuilder(IBuildDescription des, boolean buildIncrementaly){ + this(des, buildIncrementaly, true); + } + + public DescriptionBuilder(IBuildDescription des, boolean buildIncrementaly, boolean resumeOnError){ + this(des, buildIncrementaly, resumeOnError, null); + } + + public DescriptionBuilder(IBuildDescription des, boolean buildIncrementaly, boolean resumeOnErrs, IPath cwd){ + fDes = des; + fCWD = cwd; + fBuildIncrementaly = buildIncrementaly; + fResumeOnErrs = resumeOnErrs; + + if(fCWD == null) + fCWD = fDes.getDefaultBuildDirLocation(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.internal.builddescription.IBuildDescriptionBuilder#build(java.io.OutputStream, java.io.OutputStream, org.eclipse.core.runtime.IProgressMonitor) + */ + public int build(OutputStream out, OutputStream err, + IProgressMonitor monitor){ + + BuildStepVisitor visitor = new BuildStepVisitor(out, err, monitor); + try { + BuildDescriptionManager.accept(visitor, + fDes, true); + } catch (CoreException e) { + return STATUS_ERROR_LAUNCH; + } + return visitor.fStatus; + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/GenDirInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/GenDirInfo.java new file mode 100644 index 00000000000..0c7ec2e950b --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/GenDirInfo.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2006 Intel 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: + * Intel Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.internal.buildmodel; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildResource; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * This class represents the generated directory information + * + * NOTE: This class is subject to change and discuss, + * and is currently available in experimental mode only + * + */ +public class GenDirInfo { + private IProject fProject; + private IPath fProjPath; + private Set fDirPathSet = new HashSet(); + + public GenDirInfo(IProject proj){ + fProject = proj; + fProjPath = proj.getFullPath(); + } + + public GenDirInfo(IConfiguration cfg){ + this(cfg.getOwner().getProject()); + } + + public void createDir(IBuildResource rc, IProgressMonitor monitor){ + IPath path = rc.getFullPath(); + if(path != null + && fProjPath.isPrefixOf(path)){ + path = path.removeLastSegments(1).removeFirstSegments(1); + if(fDirPathSet.add(path)){ + IFolder folder = fProject.getFolder(path); + if(!folder.exists()){ + try { + folder.create(true, true, monitor); + folder.setDerived(true); + } catch (CoreException e) { + //TODO: log the error + } + } + } + } + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/IBuildModelBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/IBuildModelBuilder.java new file mode 100644 index 00000000000..23a0c4f06a0 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/IBuildModelBuilder.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2006 Intel 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: + * Intel Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.internal.buildmodel; + +import java.io.OutputStream; + +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * + * This is a generic interface representing the builder + * It is implemented currently by the BuildDescription builder, + * BuildStep builder and BuildCommand builder that are used for building + * the different parts of the build model + * and represent an MBS Internal Builder. + * In the future we might also adopt the external builder invocation + * to the same concept, e.g. the IBuildModelBuilder implementer + * for the external builder invocation might invoke an external builder + * from within its build method + * + * NOTE: This interface is subject to change and discuss, + * and is currently available in experimental mode only + * + */ +public interface IBuildModelBuilder { + public static final int STATUS_OK = 0; + public static final int STATUS_ERROR_BUILD = -1; + public static final int STATUS_ERROR_LAUNCH = -2; + public static final int STATUS_CANCELLED = -3; + + + int build(OutputStream out, + OutputStream err, + IProgressMonitor monitor); + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/StepBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/StepBuilder.java new file mode 100644 index 00000000000..a43eaeac34b --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/StepBuilder.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2006 Intel 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: + * Intel Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.internal.buildmodel; + +import java.io.OutputStream; + +import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildCommand; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildResource; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildStep; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * + * This class implements the IBuildStep building + * To build the step, create an instance of this class + * and invoke the build method + * + * NOTE: This class is subject to change and discuss, + * and is currently available in experimental mode only + * + */ +public class StepBuilder implements IBuildModelBuilder { + private IBuildStep fStep; + private IPath fCWD; + private GenDirInfo fDirs; + private boolean fResumeOnErrs; + + public StepBuilder(IBuildStep step){ + this(step, null); + } + + public StepBuilder(IBuildStep step, IPath cwd){ + this(step, cwd, true, null); + } + + public StepBuilder(IBuildStep step, IPath cwd, boolean resumeOnErrs, GenDirInfo dirs){ + fStep = step; + fCWD = cwd; + fDirs = dirs; + fResumeOnErrs = resumeOnErrs; + + if(fDirs == null) + fDirs = new GenDirInfo(fStep.getBuildDescription().getConfiguration()); + + if(fCWD == null) + fCWD = fStep.getBuildDescription().getDefaultBuildDirLocation(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.internal.builddescription.IBuildDescriptionBuilder#build(java.io.OutputStream, java.io.OutputStream, org.eclipse.core.runtime.IProgressMonitor) + */ + public int build(OutputStream out, OutputStream err, + IProgressMonitor monitor){ + int status = STATUS_OK; + IBuildCommand cmds[] = fStep.getCommands(fCWD, null, null, true); + if(cmds != null){ + createOutDirs(monitor); + + for(int i = 0; + i < cmds.length + && status != STATUS_CANCELLED + && (fResumeOnErrs || status == STATUS_OK); + i++){ + CommandBuilder builder = new CommandBuilder(cmds[i]); + switch(builder.build(out, err, monitor)){ + case STATUS_OK: + break; + case STATUS_CANCELLED: + status = STATUS_CANCELLED; + case STATUS_ERROR_BUILD: + if(status != STATUS_ERROR_LAUNCH) + status = STATUS_ERROR_BUILD; + break; + case STATUS_ERROR_LAUNCH: + default: + status = STATUS_ERROR_LAUNCH; + break; + } + } + } + return postProcess(status); + } + + protected int postProcess(int status){ + switch(status){ + case STATUS_OK: + break; + case STATUS_CANCELLED: + case STATUS_ERROR_BUILD: + case STATUS_ERROR_LAUNCH: + default: + cleanOutputs(); + break; + } + return status; + } + + protected void cleanOutputs(){ + IBuildResource bRcs[] = fStep.getOutputResources(); + for(int i = 0; i < bRcs.length; i++){ + IResource rc = BuildDescriptionManager.findResourceForBuildResource(bRcs[i]); + if(rc != null){ + try { + rc.delete(true, null); + } catch (CoreException e) { + if(DbgUtil.DEBUG){ + DbgUtil.traceln("failed to delete resource " + + rc.getFullPath() + + ", error: " + e.getLocalizedMessage()); + } + } + } + } + } + + protected void createOutDirs(IProgressMonitor monitor){ + IBuildResource rcs[] = fStep.getOutputResources(); + + for(int i = 0; i < rcs.length; i++){ + fDirs.createDir(rcs[i], monitor); + } + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java index 26da8b8ce18..f8f1011e9e1 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java @@ -816,7 +816,7 @@ public class Configuration extends BuildObject implements IConfiguration { getResourceConfigurationList().remove(resConfig); getResourceConfigurationMap().remove(resConfig.getResourcePath()); isDirty = true; -// rebuildNeeded = true; + rebuildNeeded = true; } /* * M O D E L A T T R I B U T E A C C E S S O R S diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java index e9dbd2467b9..283bf75941b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java @@ -33,6 +33,8 @@ import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable; +import org.eclipse.cdt.managedbuilder.internal.buildmodel.DescriptionBuilder; +import org.eclipse.cdt.managedbuilder.internal.buildmodel.IBuildModelBuilder; import org.eclipse.cdt.managedbuilder.macros.BuildMacroException; import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider; import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator; @@ -222,6 +224,13 @@ public class GeneratedMakefileBuilder extends ACBuilder { private static final String TYPE_CLEAN = "ManagedMakeBuilder.type.clean"; //$NON-NLS-1$ private static final String TYPE_INC = "ManagedMakeBuider.type.incremental"; //$NON-NLS-1$ private static final String WARNING_UNSUPPORTED_CONFIGURATION = "ManagedMakeBuilder.warning.unsupported.configuration"; //$NON-NLS-1$ + private static final String BUILD_CANCELLED = "ManagedMakeBuilder.message.cancelled"; //$NON-NLS-1$ + private static final String BUILD_FINISHED_WITH_ERRS = "ManagedMakeBuilder.message.finished.with.errs"; //$NON-NLS-1$ + private static final String BUILD_FAILED_ERR = "ManagedMakeBuilder.message.internal.builder.error"; //$NON-NLS-1$ + private static final String BUILD_STOPPED_ERR = "ManagedMakeBuilder.message.stopped.error"; //$NON-NLS-1$ + private static final String INTERNAL_BUILDER_HEADER_NOTE = "ManagedMakeBuilder.message.internal.builder.header.note"; //$NON-NLS-1$ + private static final String TYPE_REBUILD = "ManagedMakeBuider.type.rebuild"; //$NON-NLS-1$ + private static final String INTERNAL_BUILDER = "ManagedMakeBuilder.message.internal.builder"; //$NON-NLS-1$ public static boolean VERBOSE = false; // Local variables @@ -329,12 +338,24 @@ public class GeneratedMakefileBuilder extends ACBuilder { return referencedProjects; } + IConfiguration cfg = info.getDefaultConfiguration(); + +// Uncomment the below code for using the Internal Builder +// TODO: the info of what builder is to be used +// should be held in and obtained from the Configuration +/* + if(true){ + invokeInternalBuilder(cfg, kind != FULL_BUILD, true, monitor); + + // Scrub the build info the project + info.setRebuildState(false); + return referencedProjects; + } +*/ // Create a makefile generator for the build IManagedBuilderMakefileGenerator generator = ManagedBuildManager.getBuildfileGenerator(info.getDefaultConfiguration()); generator.initialize(getProject(), info, monitor); - IConfiguration cfg = info.getDefaultConfiguration(); - //perform necessary cleaning and build type calculation if(cfg.needsFullRebuild()){ //configuration rebuild state is set to true, @@ -1069,4 +1090,150 @@ public class GeneratedMakefileBuilder extends ACBuilder { } } } + + /** + * called to invoke the MBS Internal Builder for building the given configuration + * + * @param cfg configuration to be built + * @param buildIncrementaly if true, incremental build will be performed, + * only files that need rebuild will be built. + * If false, full rebuild will be performed + * @param resumeOnErr if true, build will continue in case of error while building. + * If false the build will stop on the first error + * @param monitor monitor + */ + protected void invokeInternalBuilder(IConfiguration cfg, + boolean buildIncrementaly, + boolean resumeOnErr, + IProgressMonitor monitor) { + // Get the project and make sure there's a monitor to cancel the build + IProject currentProject = cfg.getOwner().getProject(); + if (monitor == null) { + monitor = new NullProgressMonitor(); + } + + try { + int flags = 0; + IResourceDelta delta = null; + + if(buildIncrementaly){ + flags = BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED; + delta = getDelta(currentProject); + } + + IBuildDescription des = BuildDescriptionManager.createBuildDescription(cfg, delta, flags); + + IBuildModelBuilder builder = new DescriptionBuilder(des, buildIncrementaly, resumeOnErr); + + String[] msgs = new String[2]; + msgs[0] = ManagedMakeMessages.getResourceString(INTERNAL_BUILDER); + msgs[1] = currentProject.getName(); + monitor.subTask(ManagedMakeMessages.getFormattedString(MAKE, msgs)); + + // Get a build console for the project + StringBuffer buf = new StringBuffer(); + IConsole console = CCorePlugin.getDefault().getConsole(); + console.start(currentProject); + ConsoleOutputStream consoleOutStream = console.getOutputStream(); + String[] consoleHeader = new String[3]; + if(buildIncrementaly) + consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_INC); + else + consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_REBUILD); + + consoleHeader[1] = cfg.getName(); + consoleHeader[2] = currentProject.getName(); + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + buf.append(ManagedMakeMessages.getFormattedString(CONSOLE_HEADER, consoleHeader)); + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + + buf.append(ManagedMakeMessages.getResourceString(INTERNAL_BUILDER_HEADER_NOTE)); + buf.append("\n"); //$NON-NLS-1$ + + if(!cfg.isSupported()){ + buf.append(ManagedMakeMessages.getFormattedString(WARNING_UNSUPPORTED_CONFIGURATION,new String[] {cfg.getName(),cfg.getToolChain().getName()})); + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + } + consoleOutStream.write(buf.toString().getBytes()); + consoleOutStream.flush(); + + // Remove all markers for this project + removeAllMarkers(currentProject); + + // Hook up an error parser manager + String[] errorParsers = cfg.getErrorParserList(); + ErrorParserManager epm = new ErrorParserManager(getProject(), des.getDefaultBuildDirLocation(), this, errorParsers); + epm.setOutputStream(consoleOutStream); + // This variable is necessary to ensure that the EPM stream stay open + // until we explicitly close it. See bug#123302. + OutputStream epmOutputStream = epm.getOutputStream(); + + int status = builder.build(epmOutputStream, epmOutputStream, monitor); + + // Force a resync of the projects without allowing the user to cancel. + // This is probably unkind, but short of this there is no way to insure + // the UI is up-to-date with the build results + monitor.subTask(ManagedMakeMessages + .getResourceString(REFRESH)); + try { + currentProject.refreshLocal( + IResource.DEPTH_INFINITE, null); + } catch (CoreException e) { + monitor.subTask(ManagedMakeMessages + .getResourceString(REFRESH_ERROR)); + } + + // Report either the success or failure of our mission + buf = new StringBuffer(); + + switch(status){ + case IBuildModelBuilder.STATUS_OK: + buf.append(ManagedMakeMessages + .getFormattedString(BUILD_FINISHED, + currentProject.getName())); + break; + case IBuildModelBuilder.STATUS_CANCELLED: + buf.append(ManagedMakeMessages + .getResourceString(BUILD_CANCELLED)); + break; + case IBuildModelBuilder.STATUS_ERROR_BUILD: + String msg = resumeOnErr ? + ManagedMakeMessages.getResourceString(BUILD_FINISHED_WITH_ERRS) : + ManagedMakeMessages.getResourceString(BUILD_STOPPED_ERR); + buf.append(msg); + break; + case IBuildModelBuilder.STATUS_ERROR_LAUNCH: + default: + buf.append(ManagedMakeMessages + .getResourceString(BUILD_FAILED_ERR)); + break; + } + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$ + + // Write message on the console + consoleOutStream.write(buf.toString().getBytes()); + consoleOutStream.flush(); + epmOutputStream.close(); + + // Generate any error markers that the build has discovered + monitor.subTask(ManagedMakeMessages + .getResourceString(MARKERS)); + addBuilderMarkers(epm); + epm.reportProblems(); + consoleOutStream.close(); + } catch (Exception e) { + StringBuffer buf = new StringBuffer(); + String errorDesc = ManagedMakeMessages + .getResourceString(BUILD_ERROR); + buf.append(errorDesc); + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$ + buf.append("(").append(e.getLocalizedMessage()).append(")"); //$NON-NLS-1$ //$NON-NLS-2$ + + forgetLastBuiltState(); + } finally { + getGenerationProblems().clear(); + } + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties index 03173c51c76..62249c1c288 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties @@ -16,18 +16,24 @@ ManagedMakeBuilder.message.update.makefiles = Updating makefiles for project {0} ManagedMakeBuilder.message.incremental = Updating makefiles for project {0} ManagedMakeBuilder.message.updating = Updating project files... ManagedMakeBuilder.message.make = Calling {0} for project {1} +ManagedMakeBuilder.message.internal.builder = Internal Builder ManagedMakeBuilder.message.regen.deps = Regenerating dependency files for {0} ManagedMakeBuilder.message.updating.deps = Updating dependency files for {0} ManagedMakeBuilder.message.creating.markers = Generating markers... ManagedMakeBuilder.message.console.header = **** {0} of configuration {1} for project {2} **** +ManagedMakeBuilder.message.internal.builder.header.note = **** Internal Builder is used for build ****\n**** NOTE: Internal Builder is experimental currently **** ManagedMakeBuilder.message.no.build = Nothing to build for {0} ManagedMakeBuilder.message.error = Build error ManagedMakeBuilder.message.error.refresh = Error refreshing project ManagedMakeBuilder.message.finished = Build complete for project {0} +ManagedMakeBuilder.message.cancelled = Build cancelled +ManagedMakeBuilder.message.finished.with.errs = Build completed with errors +ManagedMakeBuilder.message.internal.builder.error = Build failed: Internal builder error occured ManagedMakeBuilder.message.clean.deleting.output=Removing build artifacts from {0} ManagedMakeBuilder.message.clean.build.clean=Trying a make clean in {0} ManagedMakeBuilder.type.clean = Clean-only build ManagedMakeBuider.type.incremental = Build +ManagedMakeBuider.type.rebuild = Rebuild ManagedMakeBuilder.warning.unsupported.configuration=**** WARNING: The "{0}" Configuration may not build ****\n**** because it uses the "{1}" ****\n**** tool-chain that is unsupported on this system. ****\n\n**** Attempting to build... **** # Option exception messages |