diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml index 4a2d6a5be88..34d2b2accb0 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml @@ -6119,5 +6119,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/resources/testBuildDescriptionProjects/test30_1/test30_1.zip b/build/org.eclipse.cdt.managedbuilder.core.tests/resources/testBuildDescriptionProjects/test30_1/test30_1.zip new file mode 100644 index 00000000000..eb52f1cd66c Binary files /dev/null and b/build/org.eclipse.cdt.managedbuilder.core.tests/resources/testBuildDescriptionProjects/test30_1/test30_1.zip differ diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java index 02dd27c4288..ad9f2e58321 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 Intel Corporation and others. + * Copyright (c) 2004, 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 @@ -16,6 +16,8 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; import java.util.zip.ZipFile; import junit.framework.Assert; @@ -23,14 +25,24 @@ import junit.framework.TestCase; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICDescriptor; +import org.eclipse.cdt.managedbuilder.core.BuildException; +import org.eclipse.cdt.managedbuilder.core.IAdditionalInput; +import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; +import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; import org.eclipse.cdt.managedbuilder.core.IManagedProject; +import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IProjectType; +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.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; @@ -50,6 +62,14 @@ import org.eclipse.ui.wizards.datatransfer.ImportOperation; import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider; public class ManagedBuildTestHelper { + private static final String rcbsToolId = new String("org.eclipse.cdt.managedbuilder.ui.rcbs"); //$NON-NLS-1$ + private static final String rcbsToolName = new String("Resource Custom Build Step"); //$NON-NLS-1$ + private static final String rcbsToolInputTypeId = new String("org.eclipse.cdt.managedbuilder.ui.rcbs.inputtype"); //$NON-NLS-1$ + private static final String rcbsToolInputTypeName = new String("Resource Custom Build Step Input Type"); //$NON-NLS-1$ + private static final String rcbsToolOutputTypeId = new String("org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype"); //$NON-NLS-1$ + private static final String rcbsToolOutputTypeName = new String("Resource Custom Build Step Output Type"); //$NON-NLS-1$ + private static final String PATH_SEPERATOR = ";"; //$NON-NLS-1$ + /* (non-Javadoc) * Create a new project named name or return the project in @@ -118,8 +138,16 @@ public class ManagedBuildTestHelper { static public IFile createFile(IProject project, String name){ IFile file = project.getFile(name); - if( file.exists() ){ + if( !file.exists() ){ try { + IPath dirPath = file.getFullPath().removeLastSegments(1).removeFirstSegments(1); + if(dirPath.segmentCount() > 0){ + IFolder rc = project.getFolder(dirPath); + if(!rc.exists()){ + rc.create(true, true, null); + } + } + // file.create( new ByteArrayInputStream( "#include \n extern void bar(); \n int main() { \nprintf(\"Hello, World!!\"); \n bar();\n return 0; }".getBytes() ), false, null ); file.create( new ByteArrayInputStream( new byte[0] ), false, null ); } catch (CoreException e) { @@ -156,6 +184,25 @@ public class ManagedBuildTestHelper { } } + public static IProject loadProject(String name, String path){ + IPath zipPath = new Path("resources").append(path).append(name).append(name).addFileExtension("zip"); + File zipFile = CTestPlugin.getFileInPlugin(zipPath); + if(zipFile == null) { + Assert.fail("zip file " + zipPath.toString() + " is missing."); + return null; + } + + + try{ + return createProject(name, zipFile, null, null); + } + catch(Exception e){ + Assert.fail("fail to create the project: " + e.getLocalizedMessage()); + } + + return null; + } + static public IProject createProject(String projectName, File zip, IPath location, String projectTypeId) throws CoreException, InvocationTargetException, IOException { IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); IProject project= root.getProject(projectName); @@ -236,6 +283,11 @@ public class ManagedBuildTestHelper { } } ManagedBuildManager.setDefaultConfiguration(project, defaultConfig); + + IConfiguration cfgs[] = newProject.getConfigurations(); + for(int i = 0; i < cfgs.length; i++){ + cfgs[i].setArtifactName(newProject.getDefaultArtifactName()); + } } }; NullProgressMonitor monitor = new NullProgressMonitor(); @@ -342,7 +394,7 @@ public class ManagedBuildTestHelper { try { input = new FileReader(fullPath.toFile()); } catch (Exception e) { - Assert.fail("File " + fullPath.toString() + " could not be read."); + Assert.fail("File " + fullPath.toString() + " could not be read: " + e.getLocalizedMessage()); } //InputStream input = file.getContents(true); // A different way to read the file... int c; @@ -462,4 +514,186 @@ public class ManagedBuildTestHelper { } b = dir.delete(); } + + public static ITool createRcbsTool(IConfiguration cfg, String file, String inputs, String outputs, String cmds){ + IProject project = cfg.getOwner().getProject(); + IResource f = project.findMember(file); + + Assert.assertTrue("file does not exist", f != null); + Assert.assertEquals("resource is not a file", f.getType(), IResource.FILE); + + return createRcbsTool(cfg, (IFile)f, inputs, outputs, cmds); + } + + public static ITool createRcbsTool(IConfiguration cfg, IFile file, String inputs, String outputs, String cmds){ + IResourceConfiguration rcCfg = cfg.getResourceConfiguration(file.getFullPath().toString()); + if(rcCfg == null) + rcCfg = cfg.createResourceConfiguration(file); + + Assert.assertTrue("failed to create resource configuration", rcCfg != null); + + ITool tool = getRcbsTool(rcCfg, true); + + setRcbsInputs(tool, inputs); + setRcbsOutputs(tool, outputs); + tool.setToolCommand(cmds); + tool.setAnnouncement("default test rcbs announcement"); + + rcCfg.setRcbsApplicability(IResourceConfiguration.KIND_APPLY_RCBS_TOOL_AS_OVERRIDE); + return tool; + } + + public static ITool setRcbsInputs(ITool tool, String inputs){ + tool.getInputTypes()[0].getAdditionalInputs()[0].setPaths(inputs); + return tool; + } + + public static ITool setRcbsOutputs(ITool tool, String outputs){ + tool.getOutputTypes()[0].setOutputNames(outputs); + return tool; + } + + public static ITool getRcbsTool(IResourceConfiguration rcConfig, boolean create){ + ITool rcbsTools[] = getRcbsTools(rcConfig); + ITool rcbsTool = null; + if(rcbsTools != null) + rcbsTool = rcbsTools[0]; + else if (create) { + rcbsTool = rcConfig.createTool(null,rcbsToolId + "." + ManagedBuildManager.getRandomNumber(),rcbsToolName,false); //$NON-NLS-1$ + rcbsTool.setCustomBuildStep(true); + IInputType rcbsToolInputType = rcbsTool.createInputType(null,rcbsToolInputTypeId + "." + ManagedBuildManager.getRandomNumber(),rcbsToolInputTypeName,false); //$NON-NLS-1$ + IAdditionalInput rcbsToolInputTypeAdditionalInput = rcbsToolInputType.createAdditionalInput(new String()); + rcbsToolInputTypeAdditionalInput.setKind(IAdditionalInput.KIND_ADDITIONAL_INPUT_DEPENDENCY); + rcbsTool.createOutputType(null,rcbsToolOutputTypeId + "." + ManagedBuildManager.getRandomNumber(),rcbsToolOutputTypeName,false); //$NON-NLS-1$ + } + return rcbsTool; + } + + public static ITool[] getRcbsTools(IResourceConfiguration rcConfig){ + List list = new ArrayList(); + ITool tools[] = rcConfig.getTools(); + for (int i = 0; i < tools.length; i++) { + ITool tool = tools[i]; + if (tool.getCustomBuildStep() && !tool.isExtensionElement()) { + list.add(tool); + } + } + if(list.size() != 0) + return (ITool[])list.toArray(new ITool[list.size()]); + return null; + } + + public static boolean setObjs(IConfiguration cfg, String[] objs){ + return setOption(cfg, IOption.OBJECTS, objs); + } + + public static boolean setLibs(IConfiguration cfg, String[] objs){ + return setOption(cfg, IOption.LIBRARIES, objs); + } + + public static boolean setOption(IConfiguration cfg, int type, Object value){ + return setOption(cfg.getFilteredTools(), type, value); + } + + public static boolean setOption(IResourceConfiguration rcCfg, int type, Object value){ + return setOption(rcCfg.getToolsToInvoke()[0], type, value); + } + + public static boolean setOption(ITool tools[], int type, Object value){ + for(int i = 0; i < tools.length; i++){ + if(setOption(tools[i], type, value)) + return true; + } + return false; + } + + public static IBuildObject[] getOption(IConfiguration cfg, int type){ + return getOption(cfg.getFilteredTools(), type); + } + + public static IBuildObject[] getOption(IResourceConfiguration rcCfg, int type, Object value){ + return getOption(new ITool[]{rcCfg.getToolsToInvoke()[0]}, type); + } + + public static IBuildObject[] getOption(ITool tools[], int type){ + for(int i = 0; i < tools.length; i++){ + IOption option = getOption(tools[i], type); + if(option != null) + return new IBuildObject[]{tools[i],option}; + } + return null; + } + + public static IOption getOption(IHoldsOptions tool, int type){ + IOption opts[] = tool.getOptions(); + + for(int i = 0; i < opts.length; i++){ + IOption option = opts[i]; + try { + if(option.getValueType() == type){ + return option; + } + } catch (BuildException e) { + } + } + return null; + } + + public static boolean setOption(ITool tool, int type, Object value){ + IOption option = getOption(tool, type); + + if(option == null) + return false; + IBuildObject obj = tool.getParent(); + IConfiguration cfg = null; + IResourceConfiguration rcCfg = null; + if(obj instanceof IToolChain) + cfg = ((IToolChain)obj).getParent(); + else + rcCfg = (IResourceConfiguration)obj; + + try { + if(option.getValueType() == type){ + switch(type){ + case IOption.BOOLEAN: + { + boolean val = ((Boolean)value).booleanValue(); + if(rcCfg != null) + rcCfg.setOption(tool, option, val); + else + cfg.setOption(tool, option, val); + } + return true; + case IOption.ENUMERATED: + case IOption.STRING: + { + String val = (String)value; + if(rcCfg != null) + rcCfg.setOption(tool, option, val); + else + cfg.setOption(tool, option, val); + } + return true; + case IOption.STRING_LIST: + case IOption.INCLUDE_PATH: + case IOption.PREPROCESSOR_SYMBOLS: + case IOption.LIBRARIES: + case IOption.OBJECTS: + { + String val[] = (String[])value; + if(rcCfg != null) + rcCfg.setOption(tool, option, val); + else + cfg.setOption(tool, option, val); + } + return true; + default: + Assert.fail("wrong option type passed"); + } + } + } catch (BuildException e) { + } + return false; + } + } diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java index 508703ababc..785514bc365 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,12 +14,13 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.managedbuilder.core.tests.BuildDescriptionModelTests; import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildCoreTests; import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildCoreTests20; import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildCoreTests_SharedToolOptions; +import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildDependencyCalculatorTests; import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildEnvironmentTests; import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildMacrosTests; -import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildDependencyCalculatorTests; import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildTCSupportedTest; import org.eclipse.cdt.managedbuilder.core.tests.ManagedCommandLineGeneratorTest; import org.eclipse.cdt.managedbuilder.core.tests.ManagedProject21MakefileTests; @@ -46,7 +47,7 @@ public class AllManagedBuildTests { TestSuite suite = new TestSuite( "Test for org.eclipse.cdt.managedbuild.core.tests"); //$JUnit-BEGIN$ -// TODO uncoment this +// TODO uncoment this suite.addTest(ManagedBuildCoreTests20.suite()); suite.addTest(ManagedBuildCoreTests.suite()); suite.addTest(ManagedProjectUpdateTests.suite()); @@ -61,6 +62,7 @@ public class AllManagedBuildTests { suite.addTest(MultiVersionSupportTests.suite()); suite.addTest(OptionEnablementTests.suite()); suite.addTest(ManagedBuildDependencyCalculatorTests.suite()); + suite.addTest(BuildDescriptionModelTests.suite()); //$JUnit-END$ return suite; } diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/BuildDescriptionModelTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/BuildDescriptionModelTests.java new file mode 100644 index 00000000000..c2b39ccc0a4 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/BuildDescriptionModelTests.java @@ -0,0 +1,2536 @@ +/******************************************************************************* + * 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.core.tests; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.CCProjectNature; +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.core.BuildException; +import org.eclipse.cdt.managedbuilder.core.IAdditionalInput; +import org.eclipse.cdt.managedbuilder.core.IBuildObject; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; +import org.eclipse.cdt.managedbuilder.core.IInputType; +import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.IManagedProject; +import org.eclipse.cdt.managedbuilder.core.IOption; +import org.eclipse.cdt.managedbuilder.core.IOutputType; +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.internal.buildmodel.BuildDescription; +import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildIOType; +import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildResource; +import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildStep; +import org.eclipse.cdt.managedbuilder.internal.buildmodel.DbgUtil; +import org.eclipse.cdt.managedbuilder.internal.core.Configuration; +import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +public class BuildDescriptionModelTests extends TestCase { + private static final String PREFIX = "BuildDescription_"; + private static final String PROJ_PATH = "testBuildDescriptionProjects"; + + private CompositeCleaner fCompositeCleaner = new CompositeCleaner(); + private Runnable fCleaner = fCompositeCleaner; + + private class CompositeCleaner implements Runnable{ + private List fRunnables = new ArrayList(); + + public void addRunnable(Runnable r){ + fRunnables.add(r); + } + + public void run() { + for(Iterator iter = fRunnables.iterator(); iter.hasNext();){ + Runnable r = (Runnable)iter.next(); + r.run(); + } + fRunnables.clear(); + } + + } + private class ProjectCleaner implements Runnable{ + List fProjList = new ArrayList(); + + public ProjectCleaner(){ + } + + public ProjectCleaner(String name){ + addProject(name); + } + + public ProjectCleaner(IProject project){ + addProject(project); + } + + public void addProject(IProject project){ + addProject(project.getName()); + } + + public void addProject(String name){ + fProjList.add(name); + } + + public void run() { + for(Iterator iter = fProjList.iterator(); iter.hasNext();){ + String name = (String)iter.next(); + ManagedBuildTestHelper.removeProject(name); + } + fProjList.clear(); + } + + } + + public static Test suite() { + return new TestSuite(BuildDescriptionModelTests.class); + } + + public void testDes_Model(){ + IProject project = createProject(PREFIX + "1", "test30_2.tar"); + IFile aAsm = ManagedBuildTestHelper.createFile(project, "a.asm"); + ManagedBuildTestHelper.createFile(project, "b.asm"); + ManagedBuildTestHelper.createFile(project, "c.cpp"); + ManagedBuildTestHelper.createFile(project, "d.cpp"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + cfg.setArtifactExtension("tmp"); + String cName = cfg.getName(); + + BuildDescription des = new BuildDescription(cfg); + + BuildResource aAsmRc = des.createResource("a.asm"); + assertNotNull("failed to create resource a.asm", aAsmRc); + + if(aAsmRc != des.createResource(aAsm)) + fail("new build resource created for the same resource"); + + if(aAsmRc != des.createResource("a.asm")) + fail("new build resource created for the same resource"); + + if(aAsmRc != des.createResource(aAsm.getLocation(), aAsm.getFullPath())) + fail("new build resource created for the same resource"); + + assertEquals(aAsmRc.getProducerIOType(), null); + assertEquals(aAsmRc.getDependentIOTypes().length, 0); + + BuildStep inStep = (BuildStep)des.getInputStep(); + assertEquals("input step has inputs", inStep.getInputIOTypes().length, 0); + assertEquals("initial input step has outputs", inStep.getOutputIOTypes().length, 0); + + BuildIOType type = inStep.createIOType(false, true, null); + if(type == null) + fail("failed to create output type"); + + assertEquals(type.getStep(), inStep); + + type.addResource(aAsmRc); + + assertEquals(aAsmRc.getProducerIOType(), type); + assertEquals(aAsmRc.getDependentIOTypes().length, 0); + + assertEquals("input step has inputs", inStep.getInputIOTypes().length, 0); + assertEquals(inStep.getOutputIOTypes().length, 1); + assertEquals(inStep.getOutputIOTypes()[0], type); + + assertEquals(type.getResources().length, 1); + assertEquals(type.getResources()[0], aAsmRc); + + BuildResource bAsmRc = des.createResource("b.asm"); + assertEquals(bAsmRc.getProducerIOType(), null); + assertEquals(bAsmRc.getDependentIOTypes().length, 0); + + type.addResource(bAsmRc); + assertEquals(bAsmRc.getProducerIOType(), type); + assertEquals(bAsmRc.getDependentIOTypes().length, 0); + + assertEquals("input step has inputs", inStep.getInputIOTypes().length, 0); + assertEquals(inStep.getOutputIOTypes().length, 1); + assertEquals(inStep.getOutputIOTypes()[0], type); + + assertEquals(type.getResources().length, 2); + + BuildStep step = des.createStep(null, null); + assertEquals("new step has inputs", inStep.getInputIOTypes().length, 0); + assertEquals("new step has outputs", inStep.getOutputIOTypes().length, 1); + + BuildIOType iType = step.createIOType(true, true, null); + if(iType == null) + fail("failed to create in type"); + + assertEquals(iType.getStep(), step); + + assertEquals(aAsmRc.getProducerIOType(), type); + assertEquals(aAsmRc.getDependentIOTypes().length, 0); + + iType.addResource(aAsmRc); + + assertEquals(aAsmRc.getProducerIOType(), type); + assertEquals(aAsmRc.getDependentIOTypes().length, 1); + assertEquals(aAsmRc.getDependentIOTypes()[0], iType); + + assertEquals("input step has inputs", inStep.getInputIOTypes().length, 0); + assertEquals(inStep.getOutputIOTypes().length, 1); + assertEquals(inStep.getOutputIOTypes()[0], type); + + assertEquals(iType.getResources().length, 1); + assertEquals(iType.getResources()[0], aAsmRc); + + assertEquals(bAsmRc.getProducerIOType(), type); + assertEquals(bAsmRc.getDependentIOTypes().length, 0); + + iType.addResource(bAsmRc); + assertEquals(bAsmRc.getProducerIOType(), type); + assertEquals(bAsmRc.getDependentIOTypes().length, 1); + assertEquals(bAsmRc.getDependentIOTypes()[0], iType); + + assertEquals("input step has inputs", inStep.getInputIOTypes().length, 0); + assertEquals(inStep.getOutputIOTypes().length, 1); + assertEquals(inStep.getOutputIOTypes()[0], type); + + assertEquals(type.getResources().length, 2); + + +// ManagedBuildTestHelper.removeProject(PREFIX + "1"); + } + + public void testDesTest30_2_asm_only(){ + IProject project = createProject(PREFIX + "1", "test30_2.tar"); + ManagedBuildTestHelper.createFile(project, "a.asm"); + ManagedBuildTestHelper.createFile(project, "b.asm"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + cfg.setArtifactExtension("tmp"); + String cName = cfg.getName(); + + BuildDescription tDes = new BuildDescription(cfg); + + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + doTestBuildDescription(des, tDes); + +// ManagedBuildTestHelper.removeProject(PREFIX + "1"); + } + + + public void testDesTest30_2_empty(){ + IProject project = createProject(PREFIX + "1", "test30_2.tar"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + cfg.setArtifactExtension("tmp"); + String cName = cfg.getName(); + + BuildDescription tDes = new BuildDescription(cfg); + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + doTestBuildDescription(des, tDes); + +// ManagedBuildTestHelper.removeProject(PREFIX + "1"); + } + + public void testDesDesTest30_2_cpp_only(){ + IProject project = createProject(PREFIX + "1", "test30_2.tar"); + ManagedBuildTestHelper.createFile(project, "c.cpp"); + ManagedBuildTestHelper.createFile(project, "d.cpp"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + cfg.setArtifactExtension("tmp"); + String cName = cfg.getName(); + + BuildDescription tDes = new BuildDescription(cfg); + BuildStep step; + BuildIOType type; + + // + step = (BuildStep)tDes.getInputStep(); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("c.cpp")); + type.addResource(tDes.createResource("d.cpp")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource("c.cpp")); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/new.tar")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/new.tar")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/new.log")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/new.log")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/" + cfg.getArtifactName() + ".tmp")); + // + // + step = (BuildStep)tDes.getOutputStep(); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/" + cfg.getArtifactName() + ".tmp")); + // + + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + doTestBuildDescription(des, tDes); + +// ManagedBuildTestHelper.removeProject(PREFIX + "1"); + } + + public void testDesTest30_1(){ + IProject project = loadProject("test30_1"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IConfiguration cfg = info.getDefaultConfiguration(); + String out = cfg.getName() + "/"; + + BuildDescription tDes = new BuildDescription(cfg); + BuildStep step; + BuildIOType type; + + // + step = (BuildStep)tDes.getOutputStep(); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(out + "Test30_1.so.4.5.6")); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource(out + "CDT.jpeg")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "CDT.jpeg")); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(out + "CDT.bmp")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource(out + "f1.c")); + type.addResource(tDes.createResource(out + "f2.c")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource(out + "test_ar.h")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource(out + "CDT.bmp")); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("test.tar")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "Test30_1.so.4.5.6")); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(out + "test30_1.so.1.2.3")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "test30_1.so.1.2.3")); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(out + "f1.o")); + type.addResource(tDes.createResource(out + "f2.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "f1.o")); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(out + "f1.oprestripped")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "f2.o")); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(out + "f2.oprestripped")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "f1.oprestripped")); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(out + "f1.c")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "f2.oprestripped")); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(out + "f2.c")); + // + // + step = (BuildStep)tDes.getInputStep(); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource("test.tar")); + // + // + + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + doTestBuildDescription(des, tDes); + + } + + public void testDesTest30_2(){ + IProject project = createProject(PREFIX + "1", "test30_2.tar"); + ManagedBuildTestHelper.createFile(project, "a.asm"); + ManagedBuildTestHelper.createFile(project, "b.asm"); + ManagedBuildTestHelper.createFile(project, "c.cpp"); + ManagedBuildTestHelper.createFile(project, "d.cpp"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + cfg.setArtifactExtension("tmp"); + String cName = cfg.getName(); + + BuildDescription tDes = new BuildDescription(cfg); + BuildStep step; + BuildIOType type; + + // + step = (BuildStep)tDes.getInputStep(); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("a.asm")); + type.addResource(tDes.createResource("b.asm")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("c.cpp")); + type.addResource(tDes.createResource("d.cpp")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource("c.cpp")); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("a.asm")); + type.addResource(tDes.createResource("b.asm")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/new.tar")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/new.tar")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/new.log")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/new.log")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/" + cfg.getArtifactName() + ".tmp")); + // + // + step = (BuildStep)tDes.getOutputStep(); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/" + cfg.getArtifactName() + ".tmp")); + // + + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + doTestBuildDescription(des, tDes); + +// ManagedBuildTestHelper.removeProject(PREFIX + "1"); + } +/* + private void doTestStep(IBuildStep step, StepDes testStep){ + IBuildIOType iTs[] = step.getInputIOTypes(); + TypeDes tITs[] = testStep.fInTypes; + + IBuildIOType oTs[] = step.getOutputIOTypes(); + TypeDes tOTs[] = testStep.fOutTypes; + + assertEquals(iTs.length, tITs.length); + assertEquals(oTs.length, tOTs.length); + + + } +*/ + private void doTestStep(IBuildStep step, IBuildStep oStep, boolean up){ + Map inMap = new HashMap(); + Map outMap = new HashMap(); + + stepsMatch(step, oStep, inMap, outMap, true); + + Map map = up ? outMap : inMap; + + for(Iterator iter = map.entrySet().iterator();iter.hasNext();){ + Map.Entry entry = (Map.Entry)iter.next(); + doTestType((IBuildIOType)entry.getKey(), (IBuildIOType)entry.getValue()); + } + } + + private void doTestType(IBuildIOType type, IBuildIOType oType){ + Map map = new HashMap(); + + typesMatch(type, oType, map, true); + + for(Iterator iter = map.entrySet().iterator();iter.hasNext();){ + Map.Entry entry = (Map.Entry)iter.next(); + doTestResource((IBuildResource)entry.getKey(), (IBuildResource)entry.getValue(), !type.isInput()); + } + } + + private void doTestResource(IBuildResource rc, IBuildResource oRc, boolean up){ + Map outMap = new HashMap(); + + doTestResourceMatch(rc, oRc, outMap); + + if(!up){ + typesMatch(rc.getProducerIOType(), oRc.getProducerIOType(), null, true); + doTestStep(rc.getProducerIOType().getStep(), oRc.getProducerIOType().getStep(), up); + } else { + Set stepSet = new HashSet(); + + for(Iterator iter = outMap.entrySet().iterator(); iter.hasNext();){ + Map.Entry entry = (Map.Entry)iter.next(); + IBuildIOType type = (IBuildIOType)entry.getKey(); + + IBuildStep step = type.getStep(); + if(stepSet.add(step)){ + IBuildIOType oType = (IBuildIOType)entry.getValue(); + typesMatch(type, oType, null, true); + doTestStep(step, oType.getStep(), up); + } + } + } + } + + private void doTestResourceMatch(IBuildResource rc, IBuildResource oRc, Map outTypeMap){ + + doTrace("matching resource " + DbgUtil.resourceName(rc)); + + if(!rc.getLocation().equals(oRc.getLocation())) + doFail("different resource locsations", rc, oRc); + + IBuildIOType inType = rc.getProducerIOType(); + IBuildIOType oInType = oRc.getProducerIOType(); + + typesMatch(inType, oInType, null, true); + + + IBuildIOType outTypes[] = rc.getDependentIOTypes(); + IBuildIOType oOutTypes[] = oRc.getDependentIOTypes(); + + if(outTypes.length != oOutTypes.length) + doFail("resources do not match: different number of output types", rc, oRc); + + for(int i = 0; i < outTypes.length; i++){ + IBuildIOType oType = getCorType(outTypes[i], oOutTypes); + if(oType == null) + doFail("resources not match: no cor dep type found", rc, oRc); + + Object obj = outTypeMap.put(outTypes[i], oType); + + if(obj != null){ + doFail("there was corresponding type",rc, oRc); + } + } + + doTrace("end matching resource"); + } + + + private boolean stepsMatch(IBuildStep step, IBuildStep oStep, Map inTypeMap, Map outTypeMap, boolean failOnErr){ + return stepsMatch(step, oStep, inTypeMap, outTypeMap, true, failOnErr); + } + + private boolean stepsMatch(IBuildStep step, IBuildStep oStep, Map inTypeMap, Map outTypeMap, boolean checkSteps, boolean failOnErr){ + IBuildIOType inTypes[] = step.getInputIOTypes(); + IBuildIOType oInTypes[] = oStep.getInputIOTypes(); + + doTrace("matching step " + DbgUtil.stepName(step)); + + if(inTypes.length != oInTypes.length){ + if(failOnErr) + doFail("steps do not match: different number of input types",step, oStep); + return false; + } + for(int i = 0; i < inTypes.length; i++){ + IBuildIOType oType = getCorType(inTypes[i], oInTypes, null, checkSteps); + if(oType == null){ + if(failOnErr) + doFail("steps not match, no corresponding input type found", step, oStep); + return false; + } + + Object obj = inTypeMap.put(inTypes[i], oType); + + if(obj != null){ + if(failOnErr) + doFail("there was already corresponding input type", step, oStep); + return false; + } + } + + IBuildIOType outTypes[] = step.getOutputIOTypes(); + IBuildIOType oOutTypes[] = oStep.getOutputIOTypes(); + + if(outTypes.length != oOutTypes.length){ + if(failOnErr) + doFail("steps do not match: different number of output types", step, oStep); + return false; + } + + for(int i = 0; i < outTypes.length; i++){ + IBuildIOType oType = getCorType(outTypes[i], oOutTypes, null, checkSteps); + if(oType == null){ + if(failOnErr) + doFail("steps not match, no corresponding output type found", step, oStep); + return false; + } + + Object obj = outTypeMap.put(outTypes[i], oType); + + if(obj != null){ + if(failOnErr) + doFail("there was already corresponding output type", step, oStep); + return false; + } + } + + doTrace("end matching step"); + + return true; + } + + private IBuildIOType getCorType(IBuildIOType type, IBuildIOType oTypes[]){ + return getCorType(type, oTypes, null, true); + } + + private IBuildIOType getCorType(IBuildIOType type, IBuildIOType oTypes[], Map rcMap, boolean checkSteps){ + for(int i = 0; i < oTypes.length; i++){ + if(typesMatch(type, oTypes[i], rcMap, checkSteps, false)) + return oTypes[i]; + + if(rcMap != null) + rcMap.clear(); + } + + return null; +/* + IBuildStep step = type.getStep(); + IBuildResource rcs[] = type.getResources(); + for(int i = 0; i < oTypes.length; i++){ + if(type.isInput() != oTypes[i].isInput()) + continue; + + IBuildResource oRcs[] = oTypes[i].getResources(); + + if(rcs.length != oRcs.length) + continue; + + if(resourcesMatch(rcs, oRcs, null)){ + if(!checkSteps) + return oTypes[i]; + IBuildIOType oType = oTypes[i]; + IBuildStep step = type.getStep(); + IBuildStep oStep = oType.getStep(); + + if(typesMatch(step.get)) + for(int j = 0; j < ) + } + } + return null; +*/ + } + + private boolean typesMatch(IBuildIOType type, IBuildIOType oType, Map rcMap, boolean failOnError){ + return typesMatch(type, oType, rcMap, true, failOnError); + } + + private boolean typesMatch(IBuildIOType type, IBuildIOType oType, Map rcMap, boolean checkStep, boolean failOnError){ + +// doTrace("matching io type"); + if(type.isInput() != oType.isInput()){ + if(failOnError){ + doFail("types have different I/O property", type, oType); + } + return false; + } + + IBuildResource rcs[] = type.getResources(); + IBuildResource oRcs[] = oType.getResources(); + if(rcs.length != oRcs.length) + return false; + + if(resourcesMatch(rcs, oRcs, rcMap)){ + Map inMap = new HashMap(); + Map outMap = new HashMap(); + if(!checkStep) + return true; + return stepsMatch(type.getStep(), oType.getStep(), inMap, outMap, false, failOnError); + } else if(failOnError) { + doFail("resources not match", type, oType); + } +// doTrace("end matching io type"); + + return false; + } + + private boolean resourcesMatch(IBuildResource rcs[], IBuildResource oRcs[], Map rcMap){ + if(rcs.length != oRcs.length) + return false; + + for(int j = 0; j < rcs.length; j++){ + IPath location = rcs[j].getLocation(); + int k; + for(k = 0; k < oRcs.length; k++){ + if(oRcs[k].getLocation().equals(location)){ + if(rcMap != null) + rcMap.put(rcs[j], oRcs[k]); + break; + } + } + if(k == oRcs.length) + return false; + } + return true; + } + + private void doFail(String dump, IBuildIOType type, IBuildIOType oType){ + doFail(dump + "\nType:\n" + DbgUtil.dumpType(type) + "\noType:\n" + DbgUtil.dumpType(oType)); + } + + private void doFail(String dump, IBuildResource rc, IBuildResource oRc){ + doFail(dump + "\nRc:\n" + DbgUtil.dumpResource(rc) + "\noRc:\n" + DbgUtil.dumpResource(oRc)); + } + + private void doFail(String dump, IBuildStep step, IBuildStep oStep){ + doFail(dump + "\nStep:\n" + DbgUtil.dumpStep(step) + "\noStep:\n" + DbgUtil.dumpStep(oStep)); + } + + private void doFail(String dump){ + doTrace(dump); + fail(dump); + } + + private void doTrace(String str){ + if(DbgUtil.DEBUG) + DbgUtil.traceln(str); + } + + private void doTestBuildDescription(IBuildDescription des, IBuildDescription tDes){ + assertEquals(des.getConfiguration(), tDes.getConfiguration()); + + assertNotNull(des.getConfiguration()); + + IProject project = des.getConfiguration().getOwner().getProject(); + + IBuildStep inStep = des.getInputStep(); + IBuildStep outStep = des.getOutputStep(); + + if(inStep.getInputIOTypes().length != 0){ + doFail("input step contains inputs, " + DbgUtil.dumpStep(inStep)); + } + if(outStep.getOutputIOTypes().length != 0){ + doFail("output step contains outputs, " + DbgUtil.dumpStep(outStep)); + } + + IBuildStep tInStep = tDes.getInputStep(); + IBuildStep tOutStep = tDes.getOutputStep(); + + doTrace("*****testing down to up.."); + doTestStep(inStep, tInStep, true); + doTrace("*****down to up passed"); + + doTrace("*****testing up to down.."); + doTestStep(outStep, tOutStep, false); + doTrace("*****up to down passed"); + } + + protected void tearDown() throws Exception { + fCleaner.run(); + if(DbgUtil.DEBUG) + DbgUtil.flush(); + } + + private IProject createProject(String name, String id){ + IProject proj = ManagedBuildTestHelper.createProject(name, id); + if(proj != null) + fCompositeCleaner.addRunnable(new ProjectCleaner(proj)); + + return proj; + } + + private IProject loadProject(String name){ + IProject proj = ManagedBuildTestHelper.loadProject(name, PROJ_PATH); + if(proj != null) + fCompositeCleaner.addRunnable(new ProjectCleaner(proj)); + + return proj; + } + + + public void testDes_gnu30_exe(){ + IProject project = createProject(PREFIX + "1", "cdt.managedbuild.target.gnu30.exe"); + try { + CCProjectNature.addCCNature(project, null); + } catch (CoreException e1) { + fail("fail to add CC nature"); + } + + ManagedBuildTestHelper.createFile(project, "a.c"); + ManagedBuildTestHelper.createFile(project, "b.c"); + ManagedBuildTestHelper.createFile(project, "c.cpp"); + ManagedBuildTestHelper.createFile(project, "d.cpp"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + String art = cfg.getArtifactName(); + String ext = cfg.getArtifactExtension(); + if(ext != null && ext.length() > 0) + art = art + "." + ext; + + String cName = cfg.getName(); + + BuildDescription tDes = new BuildDescription(cfg); + BuildStep step; + BuildIOType type; + + // + step = (BuildStep)tDes.getInputStep(); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("c.cpp")); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("a.c")); + type.addResource(tDes.createResource("b.c")); + + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("a.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("b.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/b.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("c.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/c.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/d.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + type.addResource(tDes.createResource(cName + "/b.o")); + type.addResource(tDes.createResource(cName + "/c.o")); + type.addResource(tDes.createResource(cName + "/d.o")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + // + step = (BuildStep)tDes.getOutputStep(); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + doTestBuildDescription(des, tDes); + } + + + public void testDesTestgnu21_exe(){ + IProject project = createProject(PREFIX + "1", "cdt.managedbuild.target.testgnu21.exe"); + try { + CCProjectNature.addCCNature(project, null); + } catch (CoreException e1) { + fail("fail to add CC nature"); + } + + ManagedBuildTestHelper.createFile(project, "a.c"); + ManagedBuildTestHelper.createFile(project, "b.c"); + ManagedBuildTestHelper.createFile(project, "c.cpp"); + ManagedBuildTestHelper.createFile(project, "d.cpp"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + String art = cfg.getArtifactName(); + String ext = cfg.getArtifactExtension(); + if(ext != null && ext.length() > 0) + art = art + "." + ext; + + String cName = cfg.getName(); + + BuildDescription tDes = new BuildDescription(cfg); + BuildStep step; + BuildIOType type; + + // + step = (BuildStep)tDes.getInputStep(); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("c.cpp")); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("a.c")); + type.addResource(tDes.createResource("b.c")); + + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("a.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("b.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/b.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("c.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/c.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/d.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + type.addResource(tDes.createResource(cName + "/b.o")); + type.addResource(tDes.createResource(cName + "/c.o")); + type.addResource(tDes.createResource(cName + "/d.o")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + // + step = (BuildStep)tDes.getOutputStep(); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + doTestBuildDescription(des, tDes); + } + + public void testDesRcCfg(){ + IProject project = createProject(PREFIX + "1", "cdt.managedbuild.target.gnu30.exe"); + try { + CCProjectNature.addCCNature(project, null); + } catch (CoreException e1) { + fail("fail to add CC nature"); + } + + IFile ac = ManagedBuildTestHelper.createFile(project, "a.c"); + IFile bc = ManagedBuildTestHelper.createFile(project, "b.c"); + IFile ccpp = ManagedBuildTestHelper.createFile(project, "c.cpp"); + IFile dcpp = ManagedBuildTestHelper.createFile(project, "d.cpp"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + String art = cfg.getArtifactName(); + String ext = cfg.getArtifactExtension(); + if(ext != null && ext.length() > 0) + art = art + "." + ext; + + String cName = cfg.getName(); + IResourceConfiguration rcCfg = cfg.createResourceConfiguration(ac); + assertNotNull(rcCfg); + rcCfg = cfg.createResourceConfiguration(ccpp); + assertNotNull(rcCfg); + + BuildDescription tDes = new BuildDescription(cfg); + BuildStep step; + BuildIOType type; + + // + step = (BuildStep)tDes.getInputStep(); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("c.cpp")); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("a.c")); + type.addResource(tDes.createResource("b.c")); + + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("a.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("b.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/b.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("c.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/c.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/d.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + type.addResource(tDes.createResource(cName + "/b.o")); + type.addResource(tDes.createResource(cName + "/c.o")); + type.addResource(tDes.createResource(cName + "/d.o")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + // + step = (BuildStep)tDes.getOutputStep(); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + doTestBuildDescription(des, tDes); + + } + + public void testDesRcbs(){ + IProject project = createProject(PREFIX + "1", "cdt.managedbuild.target.gnu30.exe"); + try { + CCProjectNature.addCCNature(project, null); + } catch (CoreException e1) { + fail("fail to add CC nature"); + } + + IFile ac = ManagedBuildTestHelper.createFile(project, "a.c"); + IFile bc = ManagedBuildTestHelper.createFile(project, "b.c"); + IFile ccpp = ManagedBuildTestHelper.createFile(project, "c.cpp"); + IFile dcpp = ManagedBuildTestHelper.createFile(project, "d.cpp"); + IFile er = ManagedBuildTestHelper.createFile(project, "e.r"); + IFile fr = ManagedBuildTestHelper.createFile(project, "f.r"); + IFile gr = ManagedBuildTestHelper.createFile(project, "dir1/g.r"); + IFile hr = ManagedBuildTestHelper.createFile(project, "dir2/h.r"); + IFile ir = ManagedBuildTestHelper.createFile(project, "dir2/i.r"); + + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + String art = cfg.getArtifactName(); + String ext = cfg.getArtifactExtension(); + if(ext != null && ext.length() > 0) + art = art + "." + ext; + + String cName = cfg.getName(); + String out = cName + "/"; + + + ManagedBuildTestHelper.createRcbsTool(cfg, ccpp, "f.r;dir1/g.r;dir2/h.r", "q.o;w.o;e.o", "a;b;c"); + ManagedBuildTestHelper.createRcbsTool(cfg, er, "f.r;dir1/g.r;dir2/h.r;dir2/i.r", "z.cpp;x.c", "d;e;f"); +// IResourceConfiguration rcCfg = cfg.createResourceConfiguration(ac); +// assertNotNull(rcCfg); +// rcCfg = cfg.createResourceConfiguration(ccpp); +// assertNotNull(rcCfg); + + BuildDescription tDes = new BuildDescription(cfg); + BuildStep step; + BuildIOType type; + + // + step = (BuildStep)tDes.getInputStep(); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("c.cpp")); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("a.c")); + type.addResource(tDes.createResource("b.c")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("e.r")); + type.addResource(tDes.createResource("f.r")); + type.addResource(tDes.createResource("dir1/g.r")); + type.addResource(tDes.createResource("dir2/h.r")); + type.addResource(tDes.createResource("dir2/i.r")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("a.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("b.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/b.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("c.cpp")); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("f.r")); + type.addResource(tDes.createResource("dir1/g.r")); + type.addResource(tDes.createResource("dir2/h.r")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/q.o")); + type.addResource(tDes.createResource(cName + "/w.o")); + type.addResource(tDes.createResource(cName + "/e.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/d.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("e.r")); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("f.r")); + type.addResource(tDes.createResource("dir1/g.r")); + type.addResource(tDes.createResource("dir2/h.r")); + type.addResource(tDes.createResource("dir2/i.r")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "z.cpp")); + type.addResource(tDes.createResource(out + "x.c")); +// type.addResource(tDes.createResource(out + "r.o")); +// type.addResource(tDes.createResource(out + "t.o")); +// type.addResource(tDes.createResource(out + "y.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource(out + "z.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/z.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource(out + "x.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/x.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + type.addResource(tDes.createResource(cName + "/b.o")); +// type.addResource(tDes.createResource(cName + "/c.o")); + type.addResource(tDes.createResource(cName + "/d.o")); + type.addResource(tDes.createResource(cName + "/q.o")); + type.addResource(tDes.createResource(cName + "/w.o")); + type.addResource(tDes.createResource(cName + "/e.o")); + type.addResource(tDes.createResource(cName + "/z.o")); + type.addResource(tDes.createResource(cName + "/x.o")); +// type.addResource(tDes.createResource(cName + "/r.o")); +// type.addResource(tDes.createResource(cName + "/t.o")); +// type.addResource(tDes.createResource(cName + "/y.o")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + // + step = (BuildStep)tDes.getOutputStep(); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + doTestBuildDescription(des, tDes); + + } + + public void testDesAddlInVarUserObjs(){ + IProject project = createProject(PREFIX + "1", "cdt.managedbuild.target.gnu30.exe"); + try { + CCProjectNature.addCCNature(project, null); + } catch (CoreException e1) { + fail("fail to add CC nature"); + } + + IFile ac = ManagedBuildTestHelper.createFile(project, "a.c"); + IFile bc = ManagedBuildTestHelper.createFile(project, "b.c"); + IFile ccpp = ManagedBuildTestHelper.createFile(project, "c.cpp"); + IFile dcpp = ManagedBuildTestHelper.createFile(project, "d.cpp"); + IFile er = ManagedBuildTestHelper.createFile(project, "e.r"); + IFile fr = ManagedBuildTestHelper.createFile(project, "f.r"); + IFile gr = ManagedBuildTestHelper.createFile(project, "dir1/g.r"); + IFile hr = ManagedBuildTestHelper.createFile(project, "dir2/h.r"); + IFile ir = ManagedBuildTestHelper.createFile(project, "dir2/i.r"); + IFile o1 = ManagedBuildTestHelper.createFile(project, "o1.o"); + IFile o2 = ManagedBuildTestHelper.createFile(project, "dir3/o2.o"); + + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + String art = cfg.getArtifactName(); + String ext = cfg.getArtifactExtension(); + if(ext != null && ext.length() > 0) + art = art + "." + ext; + + String cName = cfg.getName(); + String out = cName + "/"; + + ManagedBuildTestHelper.setObjs(cfg, new String[]{"o1.o", "dir3/o2.o", "dir4/d/o3.o"}); + + + ManagedBuildTestHelper.createRcbsTool(cfg, ccpp, "f.r;dir1/g.r;dir2/h.r", "q.o;w.o;e.o", "a;b;c"); + ManagedBuildTestHelper.createRcbsTool(cfg, er, "f.r;dir1/g.r;dir2/h.r;dir2/i.r", "z.cpp;x.c", "d;e;f"); +// IResourceConfiguration rcCfg = cfg.createResourceConfiguration(ac); +// assertNotNull(rcCfg); +// rcCfg = cfg.createResourceConfiguration(ccpp); +// assertNotNull(rcCfg); + + BuildDescription tDes = new BuildDescription(cfg); + BuildStep step; + BuildIOType type; + + // + step = (BuildStep)tDes.getInputStep(); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("c.cpp")); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("a.c")); + type.addResource(tDes.createResource("b.c")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("e.r")); + type.addResource(tDes.createResource("f.r")); + type.addResource(tDes.createResource("dir1/g.r")); + type.addResource(tDes.createResource("dir2/h.r")); + type.addResource(tDes.createResource("dir2/i.r")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("o1.o")); + type.addResource(tDes.createResource("dir3/o2.o")); + type.addResource(tDes.createResource("dir4/d/o3.o")); + + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("a.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("b.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/b.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("c.cpp")); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("f.r")); + type.addResource(tDes.createResource("dir1/g.r")); + type.addResource(tDes.createResource("dir2/h.r")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/q.o")); + type.addResource(tDes.createResource(cName + "/w.o")); + type.addResource(tDes.createResource(cName + "/e.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/d.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("e.r")); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("f.r")); + type.addResource(tDes.createResource("dir1/g.r")); + type.addResource(tDes.createResource("dir2/h.r")); + type.addResource(tDes.createResource("dir2/i.r")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "z.cpp")); + type.addResource(tDes.createResource(out + "x.c")); +// type.addResource(tDes.createResource(out + "r.o")); +// type.addResource(tDes.createResource(out + "t.o")); +// type.addResource(tDes.createResource(out + "y.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource(out + "z.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/z.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource(out + "x.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/x.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + type.addResource(tDes.createResource(cName + "/b.o")); +// type.addResource(tDes.createResource(cName + "/c.o")); + type.addResource(tDes.createResource(cName + "/d.o")); + type.addResource(tDes.createResource(cName + "/q.o")); + type.addResource(tDes.createResource(cName + "/w.o")); + type.addResource(tDes.createResource(cName + "/e.o")); + type.addResource(tDes.createResource(cName + "/z.o")); + type.addResource(tDes.createResource(cName + "/x.o")); +// type.addResource(tDes.createResource(cName + "/r.o")); +// type.addResource(tDes.createResource(cName + "/t.o")); +// type.addResource(tDes.createResource(cName + "/y.o")); + + // type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("o1.o")); + type.addResource(tDes.createResource("dir3/o2.o")); + type.addResource(tDes.createResource("dir4/d/o3.o")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + // + step = (BuildStep)tDes.getOutputStep(); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + doTestBuildDescription(des, tDes); + + } + + public void testDesAddlInVar(){ + IProject project = createProject(PREFIX + "1", "cdt.managedbuild.target.bdm.exe"); + try { + CCProjectNature.addCCNature(project, null); + } catch (CoreException e1) { + fail("fail to add CC nature"); + } + + ManagedBuildTestHelper.createFile(project, "a.c"); + ManagedBuildTestHelper.createFile(project, "b.c"); + ManagedBuildTestHelper.createFile(project, "c.cpp"); + ManagedBuildTestHelper.createFile(project, "d.cpp"); + ManagedBuildTestHelper.createFile(project, "e.s1"); + ManagedBuildTestHelper.createFile(project, "dir/f.s1"); + ManagedBuildTestHelper.createFile(project, "g.s2"); + ManagedBuildTestHelper.createFile(project, "dir/h.s2"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + String art = cfg.getArtifactName(); + String ext = cfg.getArtifactExtension(); + if(ext != null && ext.length() > 0) + art = art + "." + ext; + + String cName = cfg.getName(); + String out = cName + "/"; + + BuildDescription tDes = new BuildDescription(cfg); + BuildStep step; + BuildIOType type; + + // + step = (BuildStep)tDes.getInputStep(); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("c.cpp")); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("a.c")); + type.addResource(tDes.createResource("b.c")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("e.s1")); + type.addResource(tDes.createResource("dir/f.s1")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("g.s2")); + type.addResource(tDes.createResource("dir/h.s2")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("e.s1")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "e.o1")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("dir/f.s1")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "dir/f.o1")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("g.s2")); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource(out + "e.o1")); + type.addResource(tDes.createResource(out + "dir/f.o1")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "g.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("dir/h.s2")); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource(out + "e.o1")); + type.addResource(tDes.createResource(out + "dir/f.o1")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(out + "dir/h.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("a.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("b.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/b.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("c.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/c.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/d.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + type.addResource(tDes.createResource(cName + "/b.o")); + type.addResource(tDes.createResource(cName + "/c.o")); + type.addResource(tDes.createResource(cName + "/d.o")); + type.addResource(tDes.createResource(out + "g.o")); + type.addResource(tDes.createResource(out + "dir/h.o")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + // + step = (BuildStep)tDes.getOutputStep(); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + doTestBuildDescription(des, tDes); + } + + public void testDes_gnu30_exe_objsInProj(){ + IProject project = createProject(PREFIX + "1", "cdt.managedbuild.target.gnu30.exe"); + try { + CCProjectNature.addCCNature(project, null); + } catch (CoreException e1) { + fail("fail to add CC nature"); + } + + ManagedBuildTestHelper.createFile(project, "a.c"); + ManagedBuildTestHelper.createFile(project, "b.c"); + ManagedBuildTestHelper.createFile(project, "c.cpp"); + ManagedBuildTestHelper.createFile(project, "d.cpp"); + ManagedBuildTestHelper.createFile(project, "e.o"); + ManagedBuildTestHelper.createFile(project, "dir/f.o"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + String art = cfg.getArtifactName(); + String ext = cfg.getArtifactExtension(); + if(ext != null && ext.length() > 0) + art = art + "." + ext; + + String cName = cfg.getName(); + + BuildDescription tDes = new BuildDescription(cfg); + BuildStep step; + BuildIOType type; + + // + step = (BuildStep)tDes.getInputStep(); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("c.cpp")); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource("a.c")); + type.addResource(tDes.createResource("b.c")); + + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("a.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("b.c")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/b.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("c.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/c.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, false, null); + type.addResource(tDes.createResource("d.cpp")); + + type = step.createIOType(false, true, null); + type.addResource(tDes.createResource(cName + "/d.o")); + // + // + step = tDes.createStep(null, null); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/a.o")); + type.addResource(tDes.createResource(cName + "/b.o")); + type.addResource(tDes.createResource(cName + "/c.o")); + type.addResource(tDes.createResource(cName + "/d.o")); + + type = step.createIOType(false, false, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + // + step = (BuildStep)tDes.getOutputStep(); + + type = step.createIOType(true, true, null); + type.addResource(tDes.createResource(cName + "/" + art)); + // + + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + doTestBuildDescription(des, tDes); + } + + public void testDesRebuildState(){ + IProject project = createProject(PREFIX + "1", "cdt.managedbuild.target.gnu30.exe"); + try { + CCProjectNature.addCCNature(project, null); + } catch (CoreException e1) { + fail("fail to add CC nature"); + } + + ManagedBuildTestHelper.createFile(project, "a.c"); + ManagedBuildTestHelper.createFile(project, "b.c"); + ManagedBuildTestHelper.createFile(project, "c.cpp"); + ManagedBuildTestHelper.createFile(project, "d.cpp"); + ManagedBuildTestHelper.createFile(project, "e.o"); + ManagedBuildTestHelper.createFile(project, "dir/f.o"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + + cfg.setRebuildState(false); + + assertFalse(cfg.needsRebuild()); + + ITool targetTool = ((Configuration)cfg).calculateTargetTool(); + + cfg.setArtifactName("asdafasdfasdfasdfasdf"); + assertTrue(targetTool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + targetTool.setRebuildState(false); + assertFalse(targetTool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + cfg.setBuildArguments("-fgsdfg -sdfg -sdfg -sfdg"); +// assertFalse(targetTool.needsRebuild()); +// assertTrue(cfg.needsRebuild()); +// cfg.setRebuildState(false); +// assertFalse(targetTool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + cfg.setBuildCommand("fdgsdfbvvcbsdfvcx"); + assertFalse(cfg.needsRebuild()); + + cfg.setCleanCommand("sadgvfcxvsdfgvxc"); + assertFalse(cfg.needsRebuild()); + + cfg.setDescription("sfgsdfgsdfcxbvxcbxcvb"); + assertFalse(cfg.needsRebuild()); + + cfg.setErrorParserIds("fgdsfgsdfgsdfgsdfgsdfgdfs;sdfg;sdfg;sdg;g;sdg"); + assertFalse(cfg.needsRebuild()); + + cfg.setName("sdfgsdfgsdfgsdfgsdfgdsfgsdf"); +// assertFalse(targetTool.needsRebuild()); +// assertTrue(cfg.needsRebuild()); +// cfg.setRebuildState(false); + assertFalse(targetTool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + cfg.setPostannouncebuildStep("sdfasdfasdfsdfadfasf"); + assertFalse(cfg.needsRebuild()); + + cfg.setPostbuildStep("asdf;asdf;asdf;asdf;asdf"); + assertFalse(cfg.needsRebuild()); + + cfg.setPreannouncebuildStep("sdfgsdgsdhnbvxcvbxcv"); + assertFalse(cfg.needsRebuild()); + + cfg.setPrebuildStep("sdfg;sdfg;sdfg;sdfgvnbcvbn"); + assertFalse(cfg.needsRebuild()); + + ITool tools[] = cfg.getFilteredTools(); + ITool tool = null; + + for(int i = 0; i < tools.length; i++){ + tool = tools[i]; + if(tool != targetTool) + break; + } + + cfg.setToolCommand(tool, "sdgsdcxvzcxvzxc"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + cfg.setArtifactExtension("adsfasdfasdfasdfasdf"); + assertTrue(targetTool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + targetTool.setRebuildState(false); + assertFalse(targetTool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + +// public static final int BOOLEAN = 0; +// public static final int ENUMERATED = 1; +// public static final int STRING = 2; +// public static final int STRING_LIST = 3; +// public static final int INCLUDE_PATH = 4; +// public static final int PREPROCESSOR_SYMBOLS = 5; +// public static final int LIBRARIES = 6; +// public static final int OBJECTS = 7; + + IBuildObject obj[] = ManagedBuildTestHelper.getOption(cfg, IOption.BOOLEAN); + if(obj != null){ + IHoldsOptions ho = (IHoldsOptions)obj[0]; + IOption o = (IOption)obj[1]; + + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + try { + cfg.setOption(ho, o, !o.getBooleanValue()); + } catch (BuildException e) { + fail("failed to set the option: " + e.getLocalizedMessage()); + } + + assertTrue(ho.needsRebuild()); + assertTrue(cfg.needsRebuild()); + ho.setRebuildState(false); + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + } + + obj = ManagedBuildTestHelper.getOption(cfg, IOption.ENUMERATED); + if(obj != null){ + IHoldsOptions ho = (IHoldsOptions)obj[0]; + IOption o = (IOption)obj[1]; + + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + try { + cfg.setOption(ho, o, "sdfgsdfcvsdfgvxcsdf"); + } catch (BuildException e) { + fail("failed to set the option: " + e.getLocalizedMessage()); + } + + assertTrue(ho.needsRebuild()); + assertTrue(cfg.needsRebuild()); + ho.setRebuildState(false); + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + } + + obj = ManagedBuildTestHelper.getOption(cfg, IOption.STRING); + if(obj != null){ + IHoldsOptions ho = (IHoldsOptions)obj[0]; + IOption o = (IOption)obj[1]; + + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + try { + cfg.setOption(ho, o, "sdfgsdfcvsdfgvxcfdgvsdf"); + } catch (BuildException e) { + fail("failed to set the option: " + e.getLocalizedMessage()); + } + + assertTrue(ho.needsRebuild()); + assertTrue(cfg.needsRebuild()); + ho.setRebuildState(false); + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + } + + obj = ManagedBuildTestHelper.getOption(cfg, IOption.STRING_LIST); + if(obj != null){ + IHoldsOptions ho = (IHoldsOptions)obj[0]; + IOption o = (IOption)obj[1]; + + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + try { + cfg.setOption(ho, o, new String[]{"sdfgsd","fcvsdfgvxcfdgvsdf"}); + } catch (BuildException e) { + fail("failed to set the option: " + e.getLocalizedMessage()); + } + + assertTrue(ho.needsRebuild()); + assertTrue(cfg.needsRebuild()); + ho.setRebuildState(false); + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + } + + obj = ManagedBuildTestHelper.getOption(cfg, IOption.INCLUDE_PATH); + if(obj != null){ + IHoldsOptions ho = (IHoldsOptions)obj[0]; + IOption o = (IOption)obj[1]; + + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + try { + cfg.setOption(ho, o, new String[]{"sdfgsd","fcvsdfgvxcfdgvsdf"}); + } catch (BuildException e) { + fail("failed to set the option: " + e.getLocalizedMessage()); + } + + assertTrue(ho.needsRebuild()); + assertTrue(cfg.needsRebuild()); + ho.setRebuildState(false); + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + } + + + obj = ManagedBuildTestHelper.getOption(cfg, IOption.PREPROCESSOR_SYMBOLS); + if(obj != null){ + IHoldsOptions ho = (IHoldsOptions)obj[0]; + IOption o = (IOption)obj[1]; + + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + try { + cfg.setOption(ho, o, new String[]{"sdfgsd","fcvsdfgvxcfdgvsdf"}); + } catch (BuildException e) { + fail("failed to set the option: " + e.getLocalizedMessage()); + } + + assertTrue(ho.needsRebuild()); + assertTrue(cfg.needsRebuild()); + ho.setRebuildState(false); + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + } + + obj = ManagedBuildTestHelper.getOption(cfg, IOption.LIBRARIES); + if(obj != null){ + IHoldsOptions ho = (IHoldsOptions)obj[0]; + IOption o = (IOption)obj[1]; + + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + try { + cfg.setOption(ho, o, new String[]{"sdfgsd","fcvsdfgvxcfdgvsdf"}); + } catch (BuildException e) { + fail("failed to set the option: " + e.getLocalizedMessage()); + } + + assertTrue(ho.needsRebuild()); + assertTrue(cfg.needsRebuild()); + ho.setRebuildState(false); + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + } + + obj = ManagedBuildTestHelper.getOption(cfg, IOption.OBJECTS); + if(obj != null){ + IHoldsOptions ho = (IHoldsOptions)obj[0]; + IOption o = (IOption)obj[1]; + + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + try { + cfg.setOption(ho, o, new String[]{"sdfgsd","fcvsdfgvxcfdgvsdf"}); + } catch (BuildException e) { + fail("failed to set the option: " + e.getLocalizedMessage()); + } + + assertTrue(ho.needsRebuild()); + assertTrue(cfg.needsRebuild()); + ho.setRebuildState(false); + assertFalse(ho.needsRebuild()); + assertFalse(cfg.needsRebuild()); + } + + IToolChain tch = cfg.getToolChain(); + tch.setRebuildState(true); + assertTrue(tch.needsRebuild()); + assertTrue(cfg.needsRebuild()); + + tch.setRebuildState(false); + assertFalse(tch.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + for(int i = 0; i < tools.length; i++){ + doTestTool(tools[i]); + } + + IResourceConfiguration rcCfgs[] = cfg.getResourceConfigurations(); + for(int i = 0; i < rcCfgs.length; i++){ + IResourceConfiguration rcCfg = rcCfgs[i]; + + assertFalse(rcCfg.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + rcCfg.setRebuildState(true); + assertTrue(rcCfg.needsRebuild()); + assertTrue(cfg.needsRebuild()); + + rcCfg.setRebuildState(false); + assertFalse(rcCfg.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + rcCfg.setExclude(!rcCfg.isExcluded()); + assertTrue(rcCfg.needsRebuild()); + assertTrue(cfg.needsRebuild()); + + rcCfg.setRebuildState(false); + assertFalse(rcCfg.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + rcCfg.setExclude(rcCfg.isExcluded()); + assertFalse(rcCfg.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + int appl = rcCfg.getRcbsApplicability() + 1; + if(appl > 4) + appl = 1; + rcCfg.setRcbsApplicability(appl); + assertTrue(rcCfg.needsRebuild()); + assertTrue(cfg.needsRebuild()); + rcCfg.setRebuildState(false); + assertFalse(rcCfg.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + rcCfg.setRcbsApplicability(rcCfg.getRcbsApplicability()); + assertFalse(rcCfg.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + ITool t = rcCfg.getToolsToInvoke()[0]; + assertFalse(t.needsRebuild()); + rcCfg.setToolCommand(t, "sdsdcdsffewffdvcx"); + assertTrue(t.needsRebuild()); + assertTrue(rcCfg.needsRebuild()); + assertTrue(cfg.needsRebuild()); + t.setRebuildState(false); + assertFalse(t.needsRebuild()); + assertFalse(rcCfg.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + rcCfg.setToolCommand(t, t.getToolCommand()); + assertFalse(t.needsRebuild()); + assertFalse(rcCfg.needsRebuild()); + assertFalse(cfg.needsRebuild()); + } + } + + private void doTestTool(ITool tool){ + IBuildObject obj = tool.getParent(); + IConfiguration cfg; + if(obj instanceof IResourceConfiguration) + cfg = ((IResourceConfiguration)obj).getParent(); + else + cfg = ((IToolChain)obj).getParent(); + + cfg.setRebuildState(false); + + assertFalse(tool.needsRebuild()); + + tool.setRebuildState(true); + assertTrue(tool.needsRebuild()); + + assertTrue(cfg.needsRebuild()); + + cfg.setRebuildState(false); + + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + tool.setRebuildState(true); + assertTrue(tool.needsRebuild()); + + assertTrue(cfg.needsRebuild()); + + tool.setRebuildState(false); + + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + tool.setCommandLinePattern("asdfasdfasdfasdfasdfasdsdfghdsfg"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + tool.setOutputFlag("asdfasdfasdfasdgsdf"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + tool.setOutputPrefix("afgsdfgfadcvwerfdvsdczxv"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + tool.setRebuildState(true); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + tool.setToolCommand("dfacvzxcgrsedfxcvsdfcgv"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + IInputType iTypes[] = tool.getInputTypes(); + + for(int i = 0; i < iTypes.length; i++){ + IInputType iType = iTypes[i]; + + if(iType.isExtensionElement()) + continue; + + iType.setAssignToOptionId("qwertyuiop"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + iType.setBuildVariable("asdfghjkl"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + iType.setMultipleOfType(!iType.getMultipleOfType()); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + iType.setOptionId("zxcvbnm"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + iType.setPrimaryInput(!iType.getPrimaryInput()); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + IAdditionalInput addlIns[] = iType.getAdditionalInputs(); + for(int j = 0; j < addlIns.length; j++){ + IAdditionalInput a = addlIns[j]; + + a.setPaths("as;sd;fgl;fg;qw;er;ty;ui;op"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + } + } + + IOutputType oTypes[] = tool.getOutputTypes(); + + for(int i = 0; i < oTypes.length; i++){ + IOutputType oType = oTypes[i]; + + if(oType.isExtensionElement()) + continue; + + oType.setBuildVariable("qwertyuiop"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + oType.setMultipleOfType(!oType.getMultipleOfType()); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + oType.setNamePattern("qwerytuuioioyuioghjgfd"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + oType.setOptionId("asdfghjklkxcvx"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + oType.setOutputNames("asdf;dfgh;hj;jk;ghjk;fgg;sdaf;asdf"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + oType.setOutputPrefix("asdfscvbdfgsdfgsdfvcx"); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + + oType.setPrimaryOutput(!oType.getPrimaryOutput()); + assertTrue(tool.needsRebuild()); + assertTrue(cfg.needsRebuild()); + tool.setRebuildState(false); + assertFalse(tool.needsRebuild()); + assertFalse(cfg.needsRebuild()); + } + } + + public void testDesRebuildStateInDescription(){ + IProject project = createProject(PREFIX + "1", "cdt.managedbuild.target.bdm.exe"); + try { + CCProjectNature.addCCNature(project, null); + } catch (CoreException e1) { + fail("fail to add CC nature"); + } + + IFile ac = ManagedBuildTestHelper.createFile(project, "a.c"); + IFile bc = ManagedBuildTestHelper.createFile(project, "b.c"); + IFile ccpp = ManagedBuildTestHelper.createFile(project, "c.cpp"); + IFile dcpp = ManagedBuildTestHelper.createFile(project, "d/d.cpp"); + IFile es2 = ManagedBuildTestHelper.createFile(project, "d2/e.s2"); + IFile fs2 = ManagedBuildTestHelper.createFile(project, "f.s2"); + + ManagedBuildTestHelper.createFile(project, "e.o"); + ManagedBuildTestHelper.createFile(project, "dir/f.o"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + Configuration cfg = (Configuration)mProj.getConfigurations()[0]; + String out = cfg.getName() + "/"; + + cfg.setRebuildState(false); + + IBuildDescription des = null; + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + + IBuildResource rcs[] = BuildDescriptionManager.filterBuildResources(des.getResources(), BuildDescriptionManager.REBUILD); + assertEquals(rcs.length, 0); + + rcs = BuildDescriptionManager.filterBuildResources(des.getResources(), BuildDescriptionManager.REMOVED); + assertEquals(rcs.length, 0); + + rcs = BuildDescriptionManager.filterBuildResources(des.getResources(), BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + assertEquals(rcs.length, 0); + + //target + ITool tool = cfg.calculateTargetTool(); + + tool.setToolCommand("fgdfgcvbcbv"); + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + rcs = BuildDescriptionManager.filterBuildResources(des.getResources(), BuildDescriptionManager.REBUILD); + IBuildResource oRcs[] = des.getOutputStep().getInputResources(); + IBuildResource targetRc; + assertEquals(rcs.length, 1); + assertEquals(oRcs.length, 1); + if(rcs[0] != oRcs[0]) + fail("rebuild resources do not match"); + + targetRc = oRcs[0]; + + rcs = BuildDescriptionManager.filterBuildResources(des.getResources(), BuildDescriptionManager.REMOVED); + assertEquals(rcs.length, 0); + + rcs = BuildDescriptionManager.filterBuildResources(des.getResources(), BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + assertEquals(rcs.length, 1); + assertEquals(oRcs.length, 1); + if(rcs[0] != oRcs[0]) + fail("rebuild resources do not match"); + + cfg.setRebuildState(false); + + //cpp + tool = getToolForInExt(cfg, "cpp"); + tool.setToolCommand("sdfgzxcvzxcvzxv"); + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + rcs = BuildDescriptionManager.filterBuildResources(des.getResources(), BuildDescriptionManager.REBUILD); + oRcs = des.getOutputStep().getInputResources(); + assertEquals(oRcs.length, 1); + targetRc = oRcs[0]; + + oRcs = new IBuildResource[5]; + oRcs[0] = getResourceForProjPath(des, out + "c.o"); + assertNotNull(oRcs[0]); + oRcs[1] = getResourceForProjPath(des, out + "d/d.o"); + assertNotNull(oRcs[1]); + oRcs[2] = targetRc; + oRcs[3] = getResourceForProjPath(des, out + "a.o"); + assertNotNull(oRcs[0]); + oRcs[4] = getResourceForProjPath(des, out + "b.o"); + assertNotNull(oRcs[1]); + + assertEquals(rcs.length, 5); + assertEquals(oRcs.length, 5); + if(!resourcesEqual(rcs, oRcs)) + fail("rebuild resources do not match"); + + + rcs = BuildDescriptionManager.filterBuildResources(des.getResources(), BuildDescriptionManager.REMOVED); + assertEquals(rcs.length, 0); + + rcs = BuildDescriptionManager.filterBuildResources(des.getResources(), BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + assertEquals(rcs.length, 5); + if(!resourcesEqual(rcs, oRcs)) + fail("rebuild resources do not match"); + + cfg.setRebuildState(false); + + //s2 + tool = getToolForInExt(cfg, "s2"); + tool.setToolCommand("sdfgzxcvzxcvzxv"); + try { + des = BuildDescriptionManager.createBuildDescription(cfg, null, BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + } catch (CoreException e) { + fail("build description creation failed: " + e.getLocalizedMessage()); + } + rcs = BuildDescriptionManager.filterBuildResources(des.getResources(), BuildDescriptionManager.REBUILD); + oRcs = des.getOutputStep().getInputResources(); + assertEquals(oRcs.length, 1); + targetRc = oRcs[0]; + + oRcs = new IBuildResource[3]; + oRcs[0] = getResourceForProjPath(des, out + "d2/e.o"); + assertNotNull(oRcs[0]); + oRcs[1] = getResourceForProjPath(des, out + "f.o"); + assertNotNull(oRcs[1]); + oRcs[2] = targetRc; + + assertEquals(rcs.length, 3); + assertEquals(oRcs.length, 3); + if(!resourcesEqual(rcs, oRcs)) + fail("rebuild resources do not match"); + + + rcs = BuildDescriptionManager.filterBuildResources(des.getResources(), BuildDescriptionManager.REMOVED); + assertEquals(rcs.length, 0); + + rcs = BuildDescriptionManager.filterBuildResources(des.getResources(), BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED); + assertEquals(rcs.length, 3); + if(!resourcesEqual(rcs, oRcs)) + fail("rebuild resources do not match"); + + cfg.setRebuildState(false); + + } + + private IBuildResource getResourceForProjPath(IBuildDescription des, String path){ + return getResourceForProjPath(des, new Path(path)); + } + + private IBuildResource getResourceForProjPath(IBuildDescription des, IPath path){ + IPath location = des.getConfiguration().getOwner().getProject().getLocation().append(path); + return des.getResourceForLocation(location); + } + + private ITool getToolForInExt(IConfiguration cfg, String ext){ + ITool tools[] = cfg.getFilteredTools(); + for(int i = 0; i < tools.length; i++){ + if(tools[i].buildsFileType(ext)) + return tools[i]; + } + return null; + } + + private boolean resourcesEqual(IBuildResource rcs[], IBuildResource oRcs[]){ + if(rcs.length != oRcs.length) + return false; + + for(int j = 0; j < rcs.length; j++){ + int k; + for(k = 0; k < oRcs.length; k++){ + if(oRcs[k] == rcs[j]){ + break; + } + } + if(k == oRcs.length) + return false; + } + return true; + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF index babc1b3384f..cc7ab0e0d1e 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF @@ -6,8 +6,10 @@ Bundle-Version: 3.1.0.qualifier Bundle-Activator: org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin -Export-Package: org.eclipse.cdt.managedbuilder.core, +Export-Package: org.eclipse.cdt.managedbuilder.buildmodel, + org.eclipse.cdt.managedbuilder.core, org.eclipse.cdt.managedbuilder.envvar, + org.eclipse.cdt.managedbuilder.internal.buildmodel, org.eclipse.cdt.managedbuilder.internal.core, org.eclipse.cdt.managedbuilder.internal.envvar, org.eclipse.cdt.managedbuilder.internal.macros, 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 new file mode 100644 index 00000000000..8ac6c1895ee --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/BuildDescriptionManager.java @@ -0,0 +1,283 @@ +/******************************************************************************* + * 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.buildmodel; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildMultiStatus; +import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildStatus; +import org.eclipse.cdt.managedbuilder.internal.buildmodel.DbgUtil; +import org.eclipse.cdt.managedbuilder.internal.buildmodel.DefaultBuildDescriptionFactory; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +/** + * + * This class represents the build description manager + * Te build description manager is the entry point + * for all build description-related operations + * + */ +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; + + private Set fVisitedSteps = new HashSet(); + private boolean fUp; + private IBuildDescription fInfo; + + private BuildDescriptionManager(boolean up, IBuildDescription info){ + fUp = up; + fInfo = info; + } + + /** + * creates the build description + * @param cfg the build configuration for which the description is to be + * created + * @param delta the resource delta or null if none + * @param flags specifies how the build description should be generated + * and what information it should contain. + * Can contain the following flags: + * BuildDescriptionManager.REBUILD, + * BuildDescriptionManager.REMOVED, + * BuildDescriptionManager.DEPS, + * BuildDescriptionManager.DEPS_CMODEL, + * BuildDescriptionManager.DEPS_DEPGEN, + * + * + * @see BuildDescriptionManager#REBUILD + * @see BuildDescriptionManager#REMOVED + * @see BuildDescriptionManager#DEPS + * @see BuildDescriptionManager#DEPS_CMODEL + * @see BuildDescriptionManager#DEPS_DEPGEN + * @return IBuildDescription + * @throws CoreException if the build description creation fails + */ + static public IBuildDescription createBuildDescription(IConfiguration cfg, + IResourceDelta delta, + int flags) throws CoreException { + return DefaultBuildDescriptionFactory.getInstance().createBuildDescription(cfg, delta, flags); + } + + /** + * runs though all steps in build description in the dependency order + * and notifies the visitor callback + * the order in which steps are enumerated depends on the "up" argument + * + * @param visitor represents the visitor callback + * @param des represents the build description + * @param up specifies the order in which build steps are to be enumerated + * if true, enumeration will be performed starting from the input step and + * ending with the output state. Otherwise enumeration will be performed + * in the reversed order + * + * @throws CoreException if the operation fails + */ + static public void accept(IStepVisitor visitor, IBuildDescription des, boolean up) throws CoreException { + BuildDescriptionManager util = new BuildDescriptionManager(up, des); + + util.doAccept(visitor); + } + + private void doAccept(IStepVisitor visitor) throws CoreException{ + IBuildStep action = fUp ? fInfo.getInputStep() : fInfo.getOutputStep(); + + doAccept(visitor, action, true); + } + + private boolean doAccept(IStepVisitor visitor, IBuildStep action, boolean doNext) throws CoreException{ + + IBuildStep[] actions = getSteps(action, fUp); + boolean proceed = true; + + for(int i = 0; i < actions.length; i++){ + if(!fVisitedSteps.contains(actions[i])){ + if(!doAccept(visitor, actions[i], false)){ + proceed = false; + break; + } + } + } + + if(proceed && !fVisitedSteps.contains(action)){ + proceed = visitor.visit(action); + fVisitedSteps.add(action); + } + + if(doNext){ + IBuildStep[] nextActions = getSteps(action, !fUp); + for(int i = 0; i < nextActions.length; i++){ + if(!fVisitedSteps.contains(nextActions[i])){ + if(!doAccept(visitor, nextActions[i], true)){ + proceed = false; + break; + } + } + } + } + + return proceed; + } + + public static IBuildStep[] getSteps(IBuildStep step, boolean input){ + Set set = new HashSet(); + + IBuildIOType args[] = input ? + step.getInputIOTypes() : + step.getOutputIOTypes(); + + for(int i = 0; i < args.length; i++){ + IBuildResource rcs[] = args[i].getResources(); + for(int j = 0; j < rcs.length; j++){ + if(input){ + IBuildIOType arg = rcs[j].getProducerIOType(); + if(arg != null && arg.getStep() != null) + set.add(arg.getStep()); + } else { + IBuildIOType depArgs[] = rcs[j].getDependentIOTypes(); + for(int k = 0; k < depArgs.length; k++){ + IBuildIOType arg = depArgs[k]; + if(arg != null && arg.getStep() != null) + set.add(arg.getStep()); + } + } + } + } + + return (IBuildStep[])set.toArray(new IBuildStep[set.size()]); + } + + public static IBuildResource[] filterBuildResources(IBuildResource rc[], int rcState){ + List list = new ArrayList(); + + addBuildResources(rc, list, rcState); + return (IBuildResource[])list.toArray(new IBuildResource[list.size()]); + } + + private static void addBuildResources(IBuildResource rcs[], List list, int rcState){ + if(rcs.length == 0) + return; + IBuildStep inputAction = rcs[0].getBuildDescription().getInputStep(); + + if(DbgUtil.DEBUG) + DbgUtil.traceln(">>found resources to clean:"); //$NON-NLS-1$ + + for(int i = 0; i < rcs.length; i++){ + IBuildResource buildRc = rcs[i]; + IPath path = buildRc.getFullPath(); + if(path != null + && ((checkFlags(rcState, REBUILD) && buildRc.needsRebuild()) + || (checkFlags(rcState, REMOVED) && buildRc.isRemoved())) + && buildRc.getProducerIOType() != null + && buildRc.getProducerIOType().getStep() != inputAction + && buildRc.isProjectResource()){ + + if(DbgUtil.DEBUG) + DbgUtil.traceln(path.toString()); + + list.add(buildRc); + } + } + + if(DbgUtil.DEBUG) + DbgUtil.traceln("<<"); //$NON-NLS-1$ + } + + private static boolean checkFlags(int var, int flags){ + return (var & flags) == flags; + } + + /** + * returns the project resource for the given build resource or null + * if the project does not contain the build resource + * + * @param bRc build resource + * @return IResource + */ + public static IResource getResourceFromBuildResource(IBuildResource bRc){ + IProject project = bRc.getBuildDescription().getConfiguration().getOwner().getProject(); + + IPath path = bRc.getFullPath(); + if(path != null) + return project.findMember(path.removeFirstSegments(1)); + + return null; + } + + /** + * cleans the resources to be rebuilt + * + * @param des build description + * @throws CoreException + */ + public static void cleanRebuildResources(IBuildDescription des) throws CoreException{ + IBuildResource bRcs[] = filterBuildResources(des.getResources(), REMOVED | REBUILD); + List failList = new ArrayList(); + + for(int i = 0; i < bRcs.length; i++){ + IResource rc = getResourceFromBuildResource(bRcs[i]); + if(rc != null){ + try { + rc.delete(true, null); + } catch (CoreException e) { + failList.add(new Object[]{rc,e}); + } + } + } + + if(failList.size() != 0){ + BuildMultiStatus status = new BuildMultiStatus("failed to remove resources", null); //$NON-NLS-1$ + for(Iterator iter = failList.iterator(); iter.hasNext();){ + Object[] err = (Object[])iter.next(); + IResource rc = (IResource)err[0]; + CoreException e = (CoreException)err[1]; + status.add(new BuildStatus(rc.getFullPath().toString(), e)); + } + throw new CoreException(status); + } + } + + public static IPath getRelPath(IPath cwd, IPath location){ + if(!location.isAbsolute()) + return location; + + IPath path = null; + IPath tmp = cwd; + while(tmp.segmentCount() != 0){ + if(tmp.isPrefixOf(location)){ + IPath p = location.removeFirstSegments(tmp.segmentCount()).setDevice(null); + if(path == null) + return p; + return path.append(p); + } + if(path == null) + path = new Path(".."); //$NON-NLS-1$ + else + path.append(".."); //$NON-NLS-1$ + tmp = tmp.removeLastSegments(1); + } + + return location; + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildCommand.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildCommand.java new file mode 100644 index 00000000000..b14328a5758 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildCommand.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * 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.buildmodel; + +import java.util.Map; + +import org.eclipse.core.runtime.IPath; + +/** + * + * This interface represents a command to be invoked for building the step + * + */ +public interface IBuildCommand { + + /** + * returns the executable path + * the paths could be either relative or absolute + * + * @return IPath + */ + IPath getCommand(); + + /** + * Returns the array of arguments to be passed to the executable + * + * @return String[] + */ + String[] getArgs(); + + /** + * Returns the Map representing the environment to be used for the executable process + * The map conntains the String to String pairs representing the variable name and value respectively + * + * @return Map + */ + Map getEnvironment(); + + /** + * Returns the working directory to be used for the process + * + * @return IPath + */ + IPath getCWD(); +} 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 new file mode 100644 index 00000000000..b056751af4b --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildDescription.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * 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.buildmodel; + +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.core.runtime.IPath; + +/** + * + * This Build representation holds the hierarchy of inter-related + * build actions and resources + * + */ +public interface IBuildDescription { + + /** + * Returns the main input action + * + * @return IBuildAction + */ + IBuildStep getInputStep(); + + /** + * Returns the main output action + * + * @return IBuildAction + */ + IBuildStep getOutputStep(); + + /** + * Returns the Build resource for the given resource location + * + * @param location + * + * @return the IBuildResource or null if not found + */ + IBuildResource getResourceForLocation(IPath location); + + /** + * Returns all resources used in the build + * + * @return IBuildResource[] + */ + IBuildResource[] getResources(); + + /** + * Returns all build steps used in the build + * + * @return IBuildResource[] + */ + IBuildStep[] getSteps(); + + /** + * Returns the build configuration this representation was created for + * + * @return IProject + */ + IConfiguration getConfiguration(); + + /** + * Returns the default build directory location + * + * @return IPath + */ + IPath getDefaultBuildDirLocation(); +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildDescriptionFactory.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildDescriptionFactory.java new file mode 100644 index 00000000000..c1c7ab00d2f --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildDescriptionFactory.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.buildmodel; + +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.runtime.CoreException; + +/** + * + * this interface represents the build description factory + * + */ +public interface IBuildDescriptionFactory { + + /** + * creates the build description + * @param cfg the build configuration for which the description is to be + * created + * @param delta the resource delta or null if none + * @param flags specifies how the build description should be generated + * and what information it should contain. + * Can contain the following flags: + * BuildDescriptionManager.REBUILD, + * BuildDescriptionManager.REMOVED, + * BuildDescriptionManager.DEPS, + * BuildDescriptionManager.DEPS_CMODEL, + * BuildDescriptionManager.DEPS_DEPGEN, + * + * + * @see BuildDescriptionManager#REBUILD + * @see BuildDescriptionManager#REMOVED + * @see BuildDescriptionManager#DEPS + * @see BuildDescriptionManager#DEPS_CMODEL + * @see BuildDescriptionManager#DEPS_DEPGEN + * @return IBuildDescription + * @throws CoreException if the build description creation fails + */ + IBuildDescription createBuildDescription(IConfiguration cfg, + IResourceDelta delta, + int flags) throws CoreException; + + /** + * + * returns the supported methods of generation the build description + * + * @see BuildDescriptionManager#REBUILD + * @see BuildDescriptionManager#REMOVED + * @see BuildDescriptionManager#DEPS + * @see BuildDescriptionManager#DEPS_CMODEL + * @see BuildDescriptionManager#DEPS_DEPGEN * + * + * @return int + */ + int getSupportedMethods(); +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildGroup.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildGroup.java new file mode 100644 index 00000000000..5d30be6c19a --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildGroup.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.buildmodel; + +/** + * + * This interface represents the build group. + * The build group is a group of actions + * + */ +public interface IBuildGroup { + /** + * + * Returns the array of build steps that belong to this group + * + * @return IBuildStep[] + */ + IBuildStep[] getSteps(); + + /** + * + * Returns true if the build group contains the given step, + * false - otherwise + * + * @param action + * @return boolean + */ + boolean contains(IBuildStep action); + + /** + * returns true is the build group needs rebuild, + * false - otherwise + * + * @return boolean + */ + boolean needsRebuild(); +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildIOType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildIOType.java new file mode 100644 index 00000000000..35cbc144719 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildIOType.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * 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.buildmodel; + +/** + * + * This interface is used to combine a set of build resources + * that are inputs or outputs for the given action + * into one group + * + */ +public interface IBuildIOType { + /** + * Specifies whether this argument is Action input or output + * + * @return boolean + */ + boolean isInput(); + + /** + * Specifies a set of resources associated with this argument + * + * @return IBuildResource[] + */ + IBuildResource[] getResources(); + + /** + * Specifies the build action this argument belongs to + * + * @return IBuildAction + */ + IBuildStep getStep(); +} 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 new file mode 100644 index 00000000000..c88ed1623d2 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildResource.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * 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.buildmodel; + +import org.eclipse.core.runtime.IPath; + +/** + * + * This interface represents the resource used in the build + * + */ +public interface IBuildResource { + /** + * Returns the resource location + * + * @return IPath + */ + IPath getLocation(); + + /** + * Returns the resource path related to the project directory + * or an absolute path(location) in case the resource + * is located outside the project directory + * + * @return IPath + */ + IPath getFullPath(); + + /** + * Returns the output argument of the action + * That generates this resource. + * In case the resource is the project source, + * The main input action is returned + * @see IBuildRepresentation.getInputAction() + * + * @return IBuildArgument + */ + IBuildIOType getProducerIOType(); + + /** + * Returns an array of arguments where this resource is used as an input + * + * @return IBuildArgument[] + */ + IBuildIOType[] getDependentIOTypes(); + + /** + * Returns true if the resource needs rebuild + * + * @return boolean + */ + boolean needsRebuild(); + + /** + * Returns true if this resource belongs to the project + * + * @return boolean + * + */ + boolean isProjectResource(); + + /** + * Returns true if the resource was removed from the build + * Note: the removed state represents is BUILD state rather than + * a file system state. + * If the build resouces is marked as removed that does not mean the + * resource is removed in the file system + * The removed state specifies that the resource is no longer used in the + * build process. + * E.g. the object file could be marked as removed if the source file was deleted + * in the file system + * The removed state information is used primarily for calculation + * of the project part that is to be rebuild + * + * @return boolean + */ + boolean isRemoved(); + + /** + * returns a build description that holds this step + * + * @return IBuildDescription + */ + IBuildDescription getBuildDescription(); +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildStep.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildStep.java new file mode 100644 index 00000000000..63cd2c0f90b --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IBuildStep.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * 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.buildmodel; + +import java.util.Map; + +import org.eclipse.core.runtime.IPath; + + +/** + * + * This interface is used to represent the build action + * + */ +public interface IBuildStep { + /** + * Returns an array of input arguments for this action + * @see IBuildIOType + * + * @return IBuildIOType[] + */ + IBuildIOType[] getInputIOTypes(); + + /** + * Returns an array of input arguments for this action + * @see IBuildIOType + * + * @return IBuildIOType[] + */ + IBuildIOType[] getOutputIOTypes(); + + /** + * Returns true if the action needs rebuild, false - otherwise + * + * @return boolean + */ + boolean needsRebuild(); + + /** + * Returns the complete set of input resources for this action + * + * @return IBuildResource[] + */ + IBuildResource[] getInputResources(); + + /** + * Returns the complete set of output resources for this action + * + * @return IBuildResource[] + */ + IBuildResource[] getOutputResources(); + + /** + * Returns true if the action is removed (due to removal + * of the project resources that were ised in thie action) + * + * @return boolean + */ + boolean isRemoved(); + + /** + * returns a build description that holds this step + * + * @return IBuildDescription + */ + IBuildDescription getBuildDescription(); + + /** + * + * Returns the set of commands used for building the step + * + * NOTE: This is a preliminary method + * + * @param cwd + * @param inStepMap + * @param outStepMap + * @param resolveAll + * @return + */ + IBuildCommand[] getCommands(IPath cwd, Map inStepMap, Map outStepMap, boolean resolveAll); +} 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 new file mode 100644 index 00000000000..fa37a1e9c71 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/buildmodel/IStepVisitor.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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.buildmodel; + +import org.eclipse.core.runtime.CoreException; + +/** + * + * This interface is used for the build description visitor mechanism + * to represent the visitor + * + * @see BuildDescriptionManager#accept(IStepVisitor, IBuildDescription, boolean) + * + */ +public interface IStepVisitor { + + /** + * this call-back method is called by the build description + * visitor mechanism for each step in the build description + * + * @see BuildDescriptionManager#accept(IStepVisitor, IBuildDescription, boolean) + * + * @param step + * @return + * @throws CoreException + */ + boolean visit(IBuildStep step) throws CoreException; +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java index e17eb5f556e..1ca572e51a0 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. + * Copyright (c) 2003, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -499,5 +499,13 @@ public interface IConfiguration extends IBuildObject { * @return boolean */ public boolean isTemporary(); + + + /** + * Returns whether this configuration requires a full rebuild + * + * @return boolean + */ + public boolean needsFullRebuild(); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IHoldsOptions.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IHoldsOptions.java index 6a33dadb796..ccc4756e53c 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IHoldsOptions.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IHoldsOptions.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 Symbian Ltd and others. + * Copyright (c) 2005, 2006 Symbian Ltd 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 @@ -156,4 +156,17 @@ public interface IHoldsOptions extends IBuildObject { * Note: changing this option will affect all non-extension configurations using this option! */ IOption getOptionToSet(IOption option, boolean adjustExtension) throws BuildException; + + /** + * specifies whether the option holder is modified and needs rebuild + * + * @return boolean + */ + public boolean needsRebuild(); + + /** + * sets the holder rebuild state + * @param rebuild + */ + public void setRebuildState(boolean rebuild); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java index 5ff61e7e67a..297b4b66efe 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 Intel Corporation and others. + * Copyright (c) 2004, 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 @@ -218,5 +218,17 @@ public interface IResourceConfiguration extends IBuildObject { * @return IResource */ public IResource getOwner(); - + + /** + * specifies whether the resource configuration is modified and needs rebuild + * + * @return boolean + */ + public boolean needsRebuild(); + + /** + * sets the resource configuration rebuild state + * @param rebuild + */ + void setRebuildState(boolean rebuild); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildCommand.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildCommand.java new file mode 100644 index 00000000000..4c3795b3dda --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildCommand.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * 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.HashMap; +import java.util.Map; + +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildCommand; +import org.eclipse.core.runtime.IPath; + +/** + * + */ +public class BuildCommand implements IBuildCommand { + private IPath fCmd; + private String fArgs[]; + private Map fEnv; + private IPath fCWD; + private BuildStep fStep; + + public BuildCommand(IPath cmd, String args[], Map env, IPath cwd, BuildStep step){ + fCmd = cmd; + if(args != null) + fArgs = (String[])args.clone(); + if(env != null) + fEnv = new HashMap(env); + + fCWD = cwd; + + fStep = step; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildCommand#getCommand() + */ + public IPath getCommand() { + return fCmd; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildCommand#getArgs() + */ + public String[] getArgs() { + if(fArgs != null) + return (String[])fArgs.clone(); + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildCommand#getEnvironment() + */ + public Map getEnvironment() { + if(fEnv != null) + return new HashMap(fEnv); + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildCommand#getCWD() + */ + public IPath getCWD() { + return fCWD; + } + +} 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 new file mode 100644 index 00000000000..e1ed2b9b0e9 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildDescription.java @@ -0,0 +1,1694 @@ +/******************************************************************************* + * 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.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Vector; + +import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildResource; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildStep; +import org.eclipse.cdt.managedbuilder.buildmodel.IStepVisitor; +import org.eclipse.cdt.managedbuilder.core.BuildException; +import org.eclipse.cdt.managedbuilder.core.IAdditionalInput; +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.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.IManagedOutputNameProvider; +import org.eclipse.cdt.managedbuilder.core.IOption; +import org.eclipse.cdt.managedbuilder.core.IOptionApplicability; +import org.eclipse.cdt.managedbuilder.core.IOutputType; +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.internal.core.Configuration; +import org.eclipse.cdt.managedbuilder.internal.macros.FileContextData; +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.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.IResourceProxy; +import org.eclipse.core.resources.IResourceProxyVisitor; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +public class BuildDescription implements IBuildDescription { + private final static String DOT = "."; //$NON-NLS-1$ + private final static String WILDCARD = "%"; //$NON-NLS-1$ + private final static String VAR_USER_OBJS = "USER_OBJS"; //$NON-NLS-1$ + private final static String VAR_LIBS = "LIBS"; //$NON-NLS-1$ + + + private Configuration fCfg; + private IResourceDelta fDelta; + + private Map fInTypeToGroupMap = new HashMap(); + private Map fToolToMultiStepMap = new HashMap(); + private BuildStep fOrderedMultiActions[]; + + private Map fLocationToRcMap = new HashMap(); + + private Map fVarToAddlInSetMap = new HashMap(); + + private List fStepList = new ArrayList(); + + private BuildStep fTargetStep; + + private IManagedBuilderMakefileGenerator fMakeGen; + private IProject fProject; + private IManagedBuildInfo fInfo; + private IPath fTopBuildDirFullPath; + private IPath fGeneratedPaths[]; + private int fFlags; + + private BuildStep fInputStep; + private BuildStep fOutputStep; + + private Map fToolOrderMap = new HashMap(); + private Set fToolInProcesSet = new HashSet(); + private ITool fOrderedTools[]; + + private Map fExtToToolAndTypeListMap = new HashMap(); + + class ToolAndType{ + ITool fTool; + IInputType fType; + String fExt; + + ToolAndType(ITool tool, IInputType inputType, String ext){ + fTool = tool; + fType = inputType; + fExt = ext; + } + } + + private class RcVisitor implements IResourceProxyVisitor, + IResourceDeltaVisitor{ + RcVisitor(){ + } + + public boolean visit(IResourceProxy proxy) throws CoreException { + + if(proxy.getType() == IResource.FILE){ + doVisitFile(proxy.requestResource()); + return false; + } + + return !isGenerated(proxy.requestFullPath()); + } + + public boolean visit(IResourceDelta delta) throws CoreException { + IResource rc = delta.getResource(); + if(rc.getType() == IResource.FILE){ + if(delta.getKind() == IResourceDelta.REMOVED + && getResourceForLocation(rc.getLocation()) == null) + doVisitFile(rc); + return false; + } + + return !isGenerated(rc.getFullPath()); + } + + private void doVisitFile(IResource res) throws CoreException{ + BuildResource rc = createResource(res); + + composeOutputs(fInputStep, null, rc); + + } + + } + + private class StepCollector implements IStepVisitor{ + private Set fStepSet = new HashSet(); + + public boolean visit(IBuildStep action) throws CoreException { + if(DbgUtil.DEBUG){ + DbgUtil.traceln("StepCollector: visiting step " + DbgUtil.stepName(action)); //$NON-NLS-1$ + } + fStepSet.add(action); + return true; + } + + public BuildStep[] getSteps(){ + return (BuildStep[])fStepSet.toArray(new BuildStep[fStepSet.size()]); + } + + public Set getStepSet(){ + return fStepSet; + } + + public void clear(){ + fStepSet.clear(); + } + } + + private class RebuildStateSynchronizer implements IStepVisitor{ + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IStepVisitor#visit(org.eclipse.cdt.managedbuilder.builddescription.IBuildStep) + */ + public boolean visit(IBuildStep a) throws CoreException { + BuildStep action = (BuildStep)a; + BuildResource rcs[] = (BuildResource[])action.getInputResources(); + boolean rebuild = action.needsRebuild(); + boolean removed = action.isRemoved(); + + if(DbgUtil.DEBUG){ + DbgUtil.trace(">>visiting action for tool = "); //$NON-NLS-1$ + if(((BuildStep)action).getTool() != null) + DbgUtil.traceln(action.getTool().getName()); + else + DbgUtil.traceln(""); //$NON-NLS-1$ + } + + if(!removed){ + BuildIOType args[] = action.getPrimaryTypes(true); + int j = 0; + if(args.length > 0){ + for(j = 0; j < args.length; j++){ + BuildResource[] ress = (BuildResource[])args[j].getResources(); + if(ress.length > 0){ + int k = 0; + for(k = 0; k < ress.length; k++){ + if(!ress[k].isRemoved()) + break; + } + if(k != ress.length) + break; + } + } + if(j == args.length) + removed = true; + } + + } + + if(!removed && !rebuild){ + for(int i = 0; i < rcs.length; i++){ + if(rcs[i].needsRebuild()){ + if(DbgUtil.DEBUG) + DbgUtil.traceln("resource " + locationToRel(rcs[i].getLocation()).toString() + " needs rebuild"); //$NON-NLS-1$ //$NON-NLS-2$ + rebuild = true; + break; + } else if(rcs[i].isRemoved()){ + if(DbgUtil.DEBUG) + DbgUtil.traceln("resource " + locationToRel(rcs[i].getLocation()).toString() + " is removed"); //$NON-NLS-1$ //$NON-NLS-2$ + rebuild = true; + break; + } + } + } + + if(removed){ + if(DbgUtil.DEBUG) + DbgUtil.traceln("action to be removed"); //$NON-NLS-1$ + + action.setRemoved(); + + IBuildResource[] outRcs = action.getOutputResources(); + + for(int i = 0; i < outRcs.length; i++){ + if(DbgUtil.DEBUG) + DbgUtil.traceln("setting remove state for resource " + locationToRel(outRcs[i].getLocation()).toString()); //$NON-NLS-1$ + + ((BuildResource)outRcs[i]).setRemoved(); + } + + } else if(rebuild){ + if(DbgUtil.DEBUG) + DbgUtil.traceln("action needs rebuild"); //$NON-NLS-1$ + + action.setRebuildState(true); + + IBuildResource[] outRcs = action.getOutputResources(); + + for(int i = 0; i < outRcs.length; i++){ + if(DbgUtil.DEBUG) + DbgUtil.traceln("setting rebuild state for resource " + locationToRel(outRcs[i].getLocation()).toString()); //$NON-NLS-1$ + + ((BuildResource)outRcs[i]).setRebuildState(true); + } + } + + if(DbgUtil.DEBUG) + DbgUtil.traceln("<Synch started"); //$NON-NLS-1$ + + BuildDescriptionManager.accept(new RebuildStateSynchronizer(), this, true); + + if(DbgUtil.DEBUG) + DbgUtil.traceln("<---Synch stopped"); //$NON-NLS-1$ + } + + private BuildIOType findTypeForExtension(BuildStep step, boolean input, String ext){ + if(ext == null) + return null; + + BuildIOType types[] = input ? (BuildIOType[])step.getInputIOTypes() : (BuildIOType[])step.getOutputIOTypes(); + + for(int i = 0; i < types.length; i++){ + IBuildResource rcs[] = types[i].getResources(); + for(int j = 0; j < rcs.length; j++){ + String e = rcs[j].getLocation().getFileExtension(); + if(e == null){ + if(ext.length() == 0) + return types[i]; + } else { + if(ext.equals(e)) + return types[i]; + } + } + } + return null; + } + + private void initToolAndTypeMap(){ + ITool tools[] = fCfg.getFilteredTools(); + for(int i = 0; i < tools.length; i++){ + ITool tool = tools[i]; + IInputType types[] = tool.getInputTypes(); + if(types.length != 0){ + for(int j = 0; j < types.length; j++){ + IInputType type = types[j]; + String exts[] = type.getSourceExtensions(tool); + for(int k = 0; k < exts.length; k++){ + String ext = exts[k]; + if(tool.buildsFileType(ext)){ + List list = (List)fExtToToolAndTypeListMap.get(ext); + if(list == null){ + list = new ArrayList(); + fExtToToolAndTypeListMap.put(ext, list); + } + list.add(new ToolAndType(tool, type, ext)); + } + } + } + } else { + String exts[] = tool.getAllInputExtensions(); + for(int k = 0; k < exts.length; k++){ + String ext = exts[k]; + if(tool.buildsFileType(ext)){ + List list = (List)fExtToToolAndTypeListMap.get(ext); + if(list == null){ + list = new ArrayList(); + fExtToToolAndTypeListMap.put(ext, list); + } + list.add(new ToolAndType(tool, null, ext)); + } + } + } + } + } + + ToolAndType getToolAndType(BuildResource rc, boolean checkVar){ + String locString = rc.getLocation().toString(); + BuildIOType arg = (BuildIOType)rc.getProducerIOType(); + String linkId = (checkVar && arg != null) ? arg.getLinkId() : null; + + for(Iterator iter = fExtToToolAndTypeListMap.entrySet().iterator(); iter.hasNext();){ + Map.Entry entry = (Map.Entry)iter.next(); + String ext = (String)entry.getKey(); + if(locString.endsWith("." + ext)){ //$NON-NLS-1$ + List list = (List)entry.getValue(); + for(Iterator itt = list.iterator(); itt.hasNext();){ + ToolAndType tt = (ToolAndType)itt.next(); + + if(!checkVar) + return tt; + + IInputType type = tt.fType; + if(type == null) + return tt; + + String var = type.getBuildVariable(); + if(var == null || var.length() == 0) + return tt; + + if(linkId == null){ + if(var == null || var.length() == 0) + return tt; + } else if(linkId.equals(var)){ + return tt; + } + } + } + } + + return null; + } + + private void composeOutputs(BuildStep inputAction, BuildIOType inputActionArg, BuildResource rc) throws CoreException{ + + boolean isSource = inputActionArg == null; + + if(!isSource){ + if(inputAction != null && inputAction == fTargetStep){ + BuildIOType arg = (BuildIOType)rc.getProducerIOType(); + if(arg.isPrimary()){ + BuildIOType oArg = findTypeForExtension(fOutputStep,true,rc.getLocation().getFileExtension()); + if(oArg == null || !arg.isPrimary()) + oArg = fOutputStep.createIOType(true, true, null); + oArg.addResource(rc); + } + + return; + } else { + IOutputType[] secondaryOutputs = fCfg.getToolChain().getSecondaryOutputs(); + for(int i = 0; i < secondaryOutputs.length; i++){ + if(secondaryOutputs[i] == inputActionArg.getIoType()){ + BuildIOType arg = findTypeForExtension(fOutputStep,true,rc.getLocation().getFileExtension()); + if(arg == null || arg.isPrimary()){ + arg = fOutputStep.createIOType(true, false, null); + } + arg.addResource(rc); + } + } + } + } + + IPath location = rc.getLocation(); + + IResourceConfiguration rcCfg = rc.getFullPath() != null ? + fCfg.getResourceConfiguration(rc.getFullPath().toString()) : + null; + ITool tool = null; + IInputType inputType = null; + String ext = null; + boolean stepRemoved = false; + if(rcCfg != null){ + if(rcCfg.isExcluded()){ + if(rcCfg.needsRebuild()) + stepRemoved = true; + else + return; + } + + tool = rcCfg.getToolsToInvoke()[0]; + String exts[] = tool.getAllInputExtensions(); + String locString = location.toString(); + for(int i = 0; i < exts.length; i++){ + String e = exts[i]; + if(locString.endsWith(e)){ + inputType = tool.getInputType(e); + ext = e; + } + } + } + else { + ToolAndType tt = getToolAndType(rc, true); + if(tt != null){ + tool = tt.fTool; + inputType = tt.fType; + ext = tt.fExt; + } + + } + + if(ext == null) + ext = location.getFileExtension(); + + if(tool != null) { + // Generate the step to build this source file + IInputType primaryInputType = tool.getPrimaryInputType(); + if ((primaryInputType != null && !primaryInputType.getMultipleOfType()) || + (inputType == null && tool != fInfo.getToolFromOutputExtension(fCfg.getArtifactExtension()))){ + + BuildStep action = null; + BuildIOType argument = null; + BuildGroup group = null; + if(rcCfg == null) + group = createGroup(inputType, ext); + + action = createStep(tool, inputType);//new BuildStep(this, tool, inputType); + if(stepRemoved) + action.setRemoved(); + if(group != null) + group.addAction(action); + argument = action.createIOType(true, true, inputType); + + argument.addResource(rc); + + if(inputActionArg == null){ + inputActionArg = findTypeForExtension(inputAction,false,rc.getLocation().getFileExtension()); + if(inputActionArg == null) + inputActionArg = inputAction.createIOType(false, false, null); + inputActionArg.addResource(rc); + } + + calculateInputs(action); + + calculateOutputs(action, argument, rc); + + BuildIOType outputs[] = (BuildIOType[])action.getOutputIOTypes(); + + for(int i = 0; i < outputs.length; i++){ + BuildResource rcs[] = (BuildResource[])outputs[i].getResources(); + for(int j = 0; j < rcs.length; j++){ + composeOutputs(action, outputs[i], rcs[j]); + } + } + } else { + + if(inputType != null ? inputType.getMultipleOfType() : tool == fCfg.calculateTargetTool()){ + BuildStep step = (BuildStep)fToolToMultiStepMap.get(tool); + + if(step != null){ + BuildIOType argument = step.getIOTypeForType(inputType, true); + if(argument == null) + argument = step.createIOType(true, true, inputType); + + argument.addResource(rc); + + if(inputActionArg == null){ + inputActionArg = findTypeForExtension(inputAction,false,rc.getLocation().getFileExtension());; + if(inputActionArg == null) + inputActionArg = inputAction.createIOType(false, false, null); + inputActionArg.addResource(rc); + } + } + } else { + + } + } + } + } + + private BuildGroup createGroup(IInputType inType, String ext){ + String key = inType != null ? + inType.getId() : "ext:"+ext; //$NON-NLS-1$ + BuildGroup group = (BuildGroup)fInTypeToGroupMap.get(key); + if(group == null){ + group = new BuildGroup(); + fInTypeToGroupMap.put(key, group); + } + return group; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildDescription#getInputStep() + */ + public IBuildStep getInputStep() { + return fInputStep; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildDescription#getOutputStep() + */ + public IBuildStep getOutputStep() { + return fOutputStep; + } + + private boolean checkFlags(int flags){ + return (fFlags & flags) == flags; + } + + protected void initBase(IConfiguration cfg, IResourceDelta delta, int flags){ + fCfg = (Configuration)cfg; + fDelta = delta; + fProject = cfg.getOwner().getProject(); + fInfo = ManagedBuildManager.getBuildInfo(fProject); + fFlags = flags; + + fInputStep = createStep(null,null); + fOutputStep = createStep(null,null); + } + + protected void initDescription() throws CoreException{ + if(fCfg.needsFullRebuild()) + fInputStep.setRebuildState(true); + + initToolAndTypeMap(); + + initMultiSteps(); + + RcVisitor visitor = new RcVisitor(); + fProject.accept(visitor, IResource.NONE); + + + if(checkFlags(BuildDescriptionManager.REMOVED) && fDelta != null) + fDelta.accept(visitor); + + handleMultiSteps(); + completeLinking(); + synchRebuildState(); + //TODO: trim(); + } + + protected void init(IConfiguration cfg, IResourceDelta delta, int flags) throws CoreException { + initBase(cfg, delta, flags); + + initDescription(); + } + + protected void stepRemoved(BuildStep step){ + fStepList.remove(step); + + if(fTargetStep == step){ + fTargetStep = null; + } + } + + public BuildResource[][] removeStep(BuildStep step){ + return step.remove(); + } + + public BuildIOType[][] removeResource(BuildResource rc){ + return rc.remove(); + } + + private void handleMultiSteps() throws CoreException{ + for(int i = 0; i < fOrderedMultiActions.length; i++){ + BuildStep action = fOrderedMultiActions[i]; + + calculateInputs(action); + + calculateOutputs(action, action.getPrimaryTypes(true)[0], null); + + if(action.getOutputResources().length == 0){ + removeStep(action); + } + BuildIOType args[] = (BuildIOType[])action.getOutputIOTypes(); + + for(int j = 0; j < args.length; j++){ + BuildIOType arg = args[j]; + BuildResource rcs[] = (BuildResource[])arg.getResources(); + for(int k = 0; k < rcs.length; k++){ + BuildResource rc = rcs[k]; + composeOutputs(action, arg, rc); + } + } + } + } + + private void initMultiSteps(){ + ITool tools[] = fCfg.getFilteredTools(); + ITool targetTool = fCfg.calculateTargetTool(); + + for(int i = 0; i < tools.length; i++){ + ITool tool = tools[i]; + IInputType type = tool.getPrimaryInputType(); + BuildStep action = null; + if(type != null ? type.getMultipleOfType() : tool == targetTool){ + action = createStep(tool,type);//new BuildStep(this, tool, type); + action.createIOType(true, true, type); + fToolToMultiStepMap.put(tool, action); + } + + } + + fOrderedMultiActions = new BuildStep[fToolToMultiStepMap.size()]; + ITool orderedTools[] = getOrderedTools(); + int index = 0; + for(int i = 0; i < orderedTools.length; i++){ + BuildStep action = (BuildStep)fToolToMultiStepMap.get(orderedTools[i]); + if(action != null) + fOrderedMultiActions[index++] = action; + } + } + + + + private void completeLinking() throws CoreException{ + boolean foundUnused = false; + + do{ + BuildStep steps[] = (BuildStep[])getSteps(); + foundUnused = false; + for(int k = 0; k < steps.length; k++){ + BuildStep step = steps[k]; + if(step == fOutputStep || step == fInputStep) + continue; + + IBuildResource rcs[] = step.getResources(false); + int i; + for(i = 0; i < rcs.length; i++){ + if(rcs[i].getDependentIOTypes().length != 0) + break; + } + if(i == rcs.length){ + if(DbgUtil.DEBUG){ + DbgUtil.traceln("unused step found: " + DbgUtil.stepName(step)); //$NON-NLS-1$ + } + + foundUnused = true; + if(step.needsRebuild() + && step.getTool() != null + && step.getTool().getCustomBuildStep()){ + if(DbgUtil.DEBUG){ + DbgUtil.traceln("unused step is an RCBS needing rebuild, settings input step rebuild state to true"); //$NON-NLS-1$ + } + fInputStep.setRebuildState(true); + } + removeStep(step); + } + } + }while(foundUnused); + + Set set = fLocationToRcMap.entrySet(); + List list = new ArrayList(); + for(Iterator iter = set.iterator();iter.hasNext();){ + Map.Entry entry = (Map.Entry)iter.next(); + + BuildResource rc = (BuildResource)entry.getValue(); + boolean doRemove = false; + BuildIOType producerArg = (BuildIOType)rc.getProducerIOType(); + if(producerArg == null){ + if(rc.getDependentIOTypes().length == 0) + doRemove = true; + else { + producerArg = findTypeForExtension(fInputStep,false,rc.getLocation().getFileExtension()); + if(producerArg == null) + producerArg = fInputStep.createIOType(false, false, null); + producerArg.addResource(rc); + } + } else if(producerArg.getStep() == fInputStep + && rc.getDependentIOTypes().length == 0) { + doRemove = true; + } + + if(doRemove) + list.add(rc); + } + + for(Iterator iter = list.iterator(); iter.hasNext();){ + BuildIOType[][] types = removeResource((BuildResource)iter.next()); + + BuildIOType producer = types[0][0]; + if(producer != null && producer.getResources().length == 0){ + ((BuildStep)producer.getStep()).removeIOType(producer); + } + + BuildIOType deps[] = types[1]; + for(int i = 0; i < deps.length; i++){ + if(deps[i].getResources().length == 0) + ((BuildStep)deps[i].getStep()).removeIOType(deps[i]); + } + } + + } + + protected void resourceRemoved(BuildResource rc){ + fLocationToRcMap.remove(rc.getLocation()); + } + + protected void resourceCreated(BuildResource rc){ + fLocationToRcMap.put(rc.getLocation(), rc); + } + + private IManagedBuilderMakefileGenerator getMakeGenInitialized(){ + if(fMakeGen == null){ + fMakeGen = ManagedBuildManager.getBuildfileGenerator(fCfg); + fMakeGen.initialize(fProject, fInfo, null); + } + return fMakeGen; + } + + private IPath getTopBuildDirFullPath(){ + if(fTopBuildDirFullPath == null) + fTopBuildDirFullPath = fProject.getFullPath().append(getMakeGenInitialized().getBuildWorkingDir()).addTrailingSeparator(); + return fTopBuildDirFullPath; + } + + private IPath getTopBuildDirLocation(){ + return fProject.getLocation().append(getTopBuildDirFullPath().removeFirstSegments(1)); + } + + private BuildResource[] addOutputs(IPath paths[], BuildIOType buildArg, IPath outDirPath){ + if(paths != null){ + List list = new ArrayList(); + for(int k = 0; k < paths.length; k++){ + IPath outFullPath = paths[k]; + IPath outLocation; + + + if(outFullPath.isAbsolute()){ + outLocation = outFullPath; + if(!fProject.getLocation().isPrefixOf(outLocation)) + outFullPath = null; + } else { + if (outFullPath.segmentCount() == 1) { + outFullPath = outDirPath.append(outFullPath); + } + + outLocation = fProject.getLocation().append(outFullPath.removeFirstSegments(1)); + } + + BuildResource outRc = createResource(outLocation, outFullPath); + list.add(outRc); + buildArg.addResource(outRc); + + } + return (BuildResource[])list.toArray(new BuildResource[list.size()]); + } + return null; + } + + private void calculateOutputs(BuildStep action, BuildIOType arg, BuildResource buildRc) throws CoreException { + BuildResource rcs[] = null; + ITool tool = action.getTool(); + + boolean isMultiAction = action.isMultiAction(); + + IPath resPath = null; + + if(!isMultiAction){ + resPath = buildRc.getFullPath(); + if(resPath == null) + resPath = buildRc.getLocation(); + } else { + rcs = (BuildResource[])action.getPrimaryTypes(true)[0].getResources(); + if(rcs.length == 0) + return; + } + + IPath outDirPath = isMultiAction ? + getTopBuildDirFullPath() : + buildRc.getProducerIOType().getStep() == fInputStep ? + getTopBuildDirFullPath().append(resPath.removeFirstSegments(1).removeLastSegments(1)).addTrailingSeparator() : + resPath.removeLastSegments(1).addTrailingSeparator(); + IInputType inType = (IInputType)arg.getIoType(); + String linkId = inType != null ? inType.getBuildVariable() : null; + if(linkId != null && linkId.length() == 0) + linkId = null; + + IOutputType[] outTypes = tool.getOutputTypes(); + // 1. If the tool is the build target and this is the primary output, + // use artifact name & extension + if (fTargetStep == action){ + String artifactName = fCfg.getArtifactName(); + try { + String tmp = ManagedBuildManager.getBuildMacroProvider().resolveValue(artifactName, "", " ", IBuildMacroProvider.CONTEXT_CONFIGURATION, fCfg); //$NON-NLS-1$ //$NON-NLS-2$ + if((tmp = tmp.trim()).length() > 0) + artifactName = tmp; + } catch (BuildMacroException e){ + } + + String artifactExt = fCfg.getArtifactExtension(); + try { + String tmp = ManagedBuildManager.getBuildMacroProvider() + .resolveValue(artifactExt, "", " ", IBuildMacroProvider.CONTEXT_CONFIGURATION, fCfg); //$NON-NLS-1$ //$NON-NLS-2$ + if((tmp = tmp.trim()).length() > 0) + artifactExt = tmp; + } catch (BuildMacroException e) { + } + + IPath path = new Path(artifactName); + if(artifactExt != null && artifactExt.length() != 0) + path = path.addFileExtension(artifactExt); + + IOutputType type = action.getTool().getPrimaryOutputType(); + BuildIOType ioType = action.getIOTypeForType(type, false); + if(ioType == null) + ioType = action.createIOType(false, true, type); + addOutputs(new IPath[]{path}, ioType, outDirPath); + } else if (outTypes != null && outTypes.length > 0) { + for (int i=0; i 0){ + + // try to resolve the build macros in the output + // names + try { + +//TODO + val = ManagedBuildManager + .getBuildMacroProvider() + .resolveValue( + val, + "", //$NON-NLS-1$ + " ", //$NON-NLS-1$ + IBuildMacroProvider.CONTEXT_FILE, + new FileContextData( + resPath, + null, option, tool)); + } catch (BuildMacroException e){ + } + + if((val = val.trim()).length() > 0){ + pathStrings = new String[]{outputPrefix + val}; + } + } + } else if ( + optType == IOption.STRING_LIST || + optType == IOption.LIBRARIES || + optType == IOption.OBJECTS) { + List outputList = (List)option.getValue(); + // Add outputPrefix to each if necessary + if(outputList != null && outputList.size() > 0){ +//TODO + try{ + pathStrings = ManagedBuildManager + .getBuildMacroProvider() + .resolveStringListValues( + (String[])outputList.toArray(new String[outputList.size()]), + "", //$NON-NLS-1$ + " ", //$NON-NLS-1$ + IBuildMacroProvider.CONTEXT_FILE, + new FileContextData( + resPath, + null, option, tool)); + } catch (BuildMacroException e){ + } + } + + + if(pathStrings != null && pathStrings.length > 0 && outputPrefix.length() > 0){ + for (int j=0; jmake. + if (multOfType || isMultiAction) { + // This case is not handled - a nameProvider or outputNames must be specified + // TODO - report error + } else { + String namePattern = type.getNamePattern(); + IPath namePatternPath = null; + String inExt = resPath.getFileExtension(); + String outExt = tool.getOutputExtension(inExt); + if (namePattern == null || namePattern.length() == 0) { + namePattern = /*outDirPath.toOSString() +*/ outputPrefix + IManagedBuilderMakefileGenerator.WILDCARD; + if (outExt != null && outExt.length() > 0) { + namePattern += DOT + outExt; + } + namePatternPath = Path.fromOSString(namePattern); + } + else { + if (outputPrefix.length() > 0) { + namePattern = outputPrefix + namePattern; + } + namePatternPath = Path.fromOSString(namePattern); + // If only a file name is specified, add the relative path of this output directory + if (namePatternPath.segmentCount() == 1) { + namePatternPath = Path.fromOSString(/*outDirPath.toOSString() +*/ namePatternPath.toString()); + } + } + + paths = new IPath[]{resolvePercent(namePatternPath, buildRc.getLocation())}; + + } + } + + if(paths == null && pathStrings != null){ + paths = new IPath[pathStrings.length]; + for(int k = 0; k < pathStrings.length; k++){ + paths[k] = Path.fromOSString(pathStrings[k]); + } + } + + + if(paths != null){ + if(buildArg == null) + buildArg = action.createIOType(false, primaryOutput, type); + + addOutputs(paths, buildArg, outDirPath); + } + + } + } else { + // For support of pre-CDT 3.0 integrations. + // NOTE WELL: This only supports the case of a single "target tool" + // that consumes exactly all of the object files, $OBJS, produced + // by other tools in the build and produces a single output. + // In this case, the output file name is the input file name with + // the output extension. + + String outPrefix = tool.getOutputPrefix(); + IPath outFullPath = Path.fromOSString(outDirPath.toOSString() + outPrefix + WILDCARD); + IPath outLocation; + String inExt = resPath.getFileExtension(); + String outExt = tool.getOutputExtension(inExt); + outFullPath = resolvePercent(outFullPath.addFileExtension(outExt), buildRc.getLocation()); + + outLocation = outLocation = fProject.getLocation().append(outFullPath.removeFirstSegments(1)); + + BuildIOType buildArg = action.createIOType(false, true, null); + + BuildResource outRc = createResource(outLocation, outFullPath); + buildArg.addResource(outRc); + } + } + + + /* (non-Javadoc) + * If the path contains a %, returns the path resolved using the resource name + * + */ + protected IPath resolvePercent(IPath outPath, IPath sourceLocation) { + // Get the input file name + String fileName = sourceLocation.removeFileExtension().lastSegment(); + // Replace the % with the file name + String outName = outPath.toOSString().replaceAll("%", fileName); //$NON-NLS-1$ + return Path.fromOSString(outName); + } + + + private IPath locationToRel(IPath location){ + if(fProject.getLocation().isPrefixOf(location)) + return location.removeFirstSegments(fProject.getLocation().segmentCount()).setDevice(null); + //TODO + return location; + } + + public IBuildResource getResourceForLocation(IPath location) { + return (BuildResource)fLocationToRcMap.get(location); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildDescription#getResources() + */ + public IBuildResource[] getResources(){ + Collection c = fLocationToRcMap.values(); + List list = new ArrayList(); + for(Iterator iter = c.iterator();iter.hasNext();){ + Object obj = iter.next(); + + if(obj instanceof BuildResource) + list.add(obj); + else if(obj instanceof List) + list.addAll((List)obj); + } + return (IBuildResource[])list.toArray(new IBuildResource[list.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildDescription#getConfiguration() + */ + public IConfiguration getConfiguration() { + return fCfg; + } + + public IProject getProject() { + return fProject; + } + + private void calculateInputs(BuildStep step) throws CoreException { + // Get the inputs for this tool invocation + // Note that command inputs that are also dependencies are also added to the command dependencies list + + /* The priorities for determining the names of the inputs of a tool are: + * 1. If an option is specified, use the value of the option. + * 2. If a build variable is specified, use the files that have been added to the build variable as + * the output(s) of other build steps. + * 3. Use the file extensions and the resources in the project + */ + ITool tool = step.getTool(); + IInputType[] inTypes = tool.getInputTypes(); + if (inTypes != null && inTypes.length > 0) { + for (int i=0; i 0) + inputName = resolved; + } catch (BuildMacroException e) { + } + + if(arg == null) + arg = step.createIOType(true, primaryInput, type); + + addInput(inputName, arg); + } + } catch( BuildException ex ) { + } + + } + + // Get any additional inputs specified in the manifest file or the project file + IAdditionalInput[] addlInputs = type.getAdditionalInputs(); + if (addlInputs != null) { + for (int j=0; j 0){ + for(int k = 0; k < resolved.length; k++){ + String string = resolved[k]; + if(string.length() > 0) + libs.add(command + string); + } + } + } catch (BuildMacroException e) { + // TODO: report error + continue; + } + + } + } + } + } catch (BuildException e) { + // TODO: report error + continue; + } + } + } + return (String[])libs.toArray(new String[libs.size()]); + } + + public String[] getUserObjs(BuildStep step) { + Vector objs = new Vector(); + ITool tool = fCfg.getTargetTool(); + if(tool == null) + tool = step.getTool(); + + if(tool != null){ + IOption[] opts = tool.getOptions(); + // Look for the user object option type + for (int i = 0; i < opts.length; i++) { + IOption option = opts[i]; + try { + if (option.getValueType() == IOption.OBJECTS) { + String unresolved[] = option.getUserObjects(); + if(unresolved != null && unresolved.length > 0){ + for(int k = 0; k < unresolved.length; k++){ + try { + String resolved[] = ManagedBuildManager.getBuildMacroProvider().resolveStringListValueToMakefileFormat( + unresolved[k], + "", //$NON-NLS-1$ + " ", //$NON-NLS-1$ + IBuildMacroProvider.CONTEXT_OPTION, + new OptionContextData(option, tool)); + if(resolved != null && resolved.length > 0) + objs.addAll(Arrays.asList(resolved)); + } catch (BuildMacroException e) { + // TODO: report error + continue; + } + } + } + } + } catch (BuildException e) { + // TODO: report error + continue; + } + } + } + return (String[])objs.toArray(new String[objs.size()]); + } + + private BuildResource addInput(String path, BuildIOType buildArg){ + if(path.length() > 0){ + IPath pPath = Path.fromOSString(path); + return addInput(pPath, buildArg); + } + return null; + } + + private BuildResource addInput(IPath path, BuildIOType buildArg){ + IPath inFullPath = path; + IPath inLocation; + + if(inFullPath.isAbsolute()){ + inLocation = inFullPath; + if(!fProject.getLocation().isPrefixOf(inLocation)) + inFullPath = null; + } else { + IPath projPath = inFullPath; + inFullPath = fProject.getFullPath().append(inFullPath); + + IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(inFullPath); + if(res != null) + inLocation = res.getLocation(); + else + inLocation = fProject.getLocation().append(projPath); + } + + BuildResource rc = createResource(inLocation, inFullPath); + buildArg.addResource(rc); + + return rc; + } + + + void typeCreated(BuildIOType arg){ + } + + public BuildResource createResource(String projPath){ + Path path = new Path(projPath); + return createResource(path); + } + + public BuildResource createResource(IPath projPath){ + return createResource(fProject.getLocation().append(projPath),fProject.getFullPath().append(projPath)); + } + + public BuildResource createResource(IResource rc){ + return createResource(rc.getLocation(), rc.getFullPath()); + } + + public BuildResource createResource(IPath location, IPath fullPath){ + + BuildResource rc = (BuildResource)getResourceForLocation(location); + + if(rc == null) + rc = new BuildResource(this, location, fullPath); + + return rc; + } + + public IResourceDelta getDelta(){ + return fDelta; + } + + private ITool[] getOrderedTools(){ + if(fOrderedTools == null){ + ITool tools[] = fCfg.getFilteredTools(); + for(int i = 0; i < tools.length; i++){ + for(int j = i; j < tools.length; j++){ + ITool tool = tools[j]; + ToolOrderEstimation order = getToolOrder(tool); + ITool deps[] = order.getDeps(); + boolean put = deps.length == 0; + if(!put && deps.length <= i){ + put = true; + for(int k = 0; k < deps.length; k++){ + if(indexOf(deps[k], tools, 0, i) == -1){ + put = false; + break; + } + } + } + if(put){ + if(i != j){ + ITool tmp = tools[i]; + tools[i] = tools[j]; + tools[j] = tmp; + } + break; + } + } + } + fOrderedTools = tools; + } + return fOrderedTools; + } + + private int indexOf(Object obj, Object array[]){ + return indexOf(obj, array, 0, -1); + } + + private int indexOf(Object obj, Object array[], int start, int stop){ + if(start < 0) + start = 0; + if(stop == -1) + stop = array.length; + + if(start < stop){ + for(int i = start; i < stop; i++){ + if(obj == array[i]) + return i; + } + } + return -1; + } + + private ToolOrderEstimation getToolOrder(ITool tool){ + ToolOrderEstimation order = (ToolOrderEstimation)fToolOrderMap.get(tool.getId()); + if(order == null){ + order = new ToolOrderEstimation(tool); + fToolOrderMap.put(tool.getId(), order); + } + return order; + } + + private ITool[] doCalcDeps(ITool tool){ + if(!fToolInProcesSet.add(tool)){ + //TODO throw error? + if(DbgUtil.DEBUG) + DbgUtil.traceln("loop dependency for tool" + tool.getName()); //$NON-NLS-1$ + return new ITool[0]; + } + + String exts[] = tool.getAllInputExtensions(); + + ITool tools[] = fCfg.getFilteredTools(); + Set set = new HashSet(); + for(int i = 0; i < tools.length; i++){ + ITool t = tools[i]; + if(t == tool) + continue; + + for(int j = 0; j < exts.length; j++){ + String e = exts[j]; + if(t.producesFileType(e)){ + IInputType inType = tool.getInputType(e); + IOutputType outType = t.getOutputType(e); + if((inType == null && outType == null) + || (inType.getBuildVariable().equals(outType.getBuildVariable()))){ + + set.add(t); + ToolOrderEstimation est = getToolOrder(t); + ITool deps[] = est.getDeps(); + for(int k = 0; k < deps.length; k++){ + if(deps[k] != tool) + set.add(deps[k]); + else{ + if(DbgUtil.DEBUG) + DbgUtil.traceln("loop dependency for tool" + tool.getName()); //$NON-NLS-1$ + //TODO throw error + } + } + } + } + } + } + + fToolInProcesSet.remove(tool); + return (ITool[])set.toArray(new ITool[set.size()]); + } + + private ITool[] doCalcConsumers(ITool tool){ + if(!fToolInProcesSet.add(tool)){ + //TODO throw error? + if(DbgUtil.DEBUG) + DbgUtil.traceln("loop dependency for tool" + tool.getName()); //$NON-NLS-1$ + return new ITool[0]; + } + + String exts[] = tool.getAllOutputExtensions(); + + ITool tools[] = fCfg.getFilteredTools(); + Set set = new HashSet(); + for(int i = 0; i < tools.length; i++){ + ITool t = tools[i]; + if(t == tool) + continue; + + for(int j = 0; j < exts.length; j++){ + String e = exts[j]; + if(t.buildsFileType(e)){ + IOutputType inType = tool.getOutputType(e); + IInputType outType = t.getInputType(e); + if((inType == null && outType == null) + || (inType.getBuildVariable().equals(outType.getBuildVariable()))){ + + set.add(t); + ToolOrderEstimation est = getToolOrder(t); + ITool consumers[] = est.getConsumers(); + for(int k = 0; k < consumers.length; k++){ + if(consumers[k] != tool) + set.add(consumers[k]); + else{ + if(DbgUtil.DEBUG) + DbgUtil.traceln("loop dependency for tool" + tool.getName()); //$NON-NLS-1$ + //TODO throw error + } + } + } + } + } + } + + fToolInProcesSet.remove(tool); + return (ITool[])set.toArray(new ITool[set.size()]); + } + + private IPath[] getGeneratedPaths(){ + if(fGeneratedPaths == null){ + IConfiguration cfgs[] = fCfg.getManagedProject().getConfigurations(); + fGeneratedPaths = new IPath[cfgs.length]; + //TODO: this is a temporary hack for obtaining the top generated dirs + //for all configurations. We can not use the buildfile generator here + //since it can only be used for the default configuration + for(int i = 0; i < cfgs.length; i++){ + fGeneratedPaths[i] = fProject.getFullPath().append(cfgs[i].getName()); + } + } + return fGeneratedPaths; + } + + private boolean isGenerated(IPath path){ + IPath paths[] = getGeneratedPaths(); + for(int i = 0; i < paths.length; i++){ + if(paths[i].isPrefixOf(path)) + return true; + } + + return getTopBuildDirFullPath().isPrefixOf(path); + } + + protected void stepCreated(BuildStep step){ + fStepList.add(step); + ITool tool = step.getTool(); + if(tool != null + && tool == fCfg.calculateTargetTool() + // && (prym == null || step.getInputType() == prym) + ){ + if(fTargetStep != null){ + //TODO: this is an error case, log or perform some special handling + if(DbgUtil.DEBUG) + DbgUtil.traceln("ERROR: target action already created"); //$NON-NLS-1$ + } + fTargetStep = step; + } + } + + public BuildStep createStep(ITool tool, IInputType type){ + return new BuildStep(this, tool, type); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildDescription#getDefaultBuildDirLocation() + */ + public IPath getDefaultBuildDirLocation() { + return getTopBuildDirLocation(); + } + + protected void resourceAddedToType(BuildIOType type, BuildResource rc){ + if(!type.isInput()){ + String var = type.getLinkId(); + if(var == null) + var = new String(); + + Set set = (Set)fVarToAddlInSetMap.get(var); + if(set != null){ + for(Iterator iter = set.iterator(); iter.hasNext();){ + BuildIOType t = (BuildIOType)iter.next(); + t.addResource(rc); + } + } + } + } + + protected void resourceRemovedFromType(BuildIOType type, BuildResource rc){ + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildDescription#getSteps() + */ + public IBuildStep[] getSteps() { + return (BuildStep[])fStepList.toArray(new BuildStep[fStepList.size()]); + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildGroup.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildGroup.java new file mode 100644 index 00000000000..b716a1e2953 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildGroup.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.Iterator; +import java.util.Set; + +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildGroup; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildResource; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildStep; + +public class BuildGroup implements IBuildGroup { + private Set fActions = new HashSet(); + private boolean fNeedsRebuild; + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildGroup#getSteps() + */ + public IBuildStep[] getSteps() { + return (IBuildStep[])fActions.toArray(new IBuildStep[fActions.size()]); + } + + public void addAction(BuildStep action){ + fActions.add(action); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildGroup#contains(org.eclipse.cdt.managedbuilder.builddescription.IBuildStep) + */ + public boolean contains(IBuildStep action) { + return fActions.contains(action); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildGroup#needsRebuild() + */ + public boolean needsRebuild() { + return fNeedsRebuild; + } + + public void setRebuildState(boolean rebuild){ + fNeedsRebuild = rebuild; + + for(Iterator iter = fActions.iterator(); iter.hasNext();){ + BuildStep action = (BuildStep)iter.next(); + + action.setRebuildState(rebuild); + } + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildIOType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildIOType.java new file mode 100644 index 00000000000..6e80c24fa2d --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildIOType.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * 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.ArrayList; +import java.util.List; + +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.core.IBuildObject; +import org.eclipse.cdt.managedbuilder.core.IInputType; +import org.eclipse.cdt.managedbuilder.core.IOutputType; + +public class BuildIOType implements IBuildIOType { + private BuildStep fStep; + private List fResources = new ArrayList(); + private boolean fIsInput; + private boolean fIsPrimary; + private String fLinkId; + private IBuildObject fIoType; + + protected BuildIOType(BuildStep action, boolean input, boolean primary,/* BuildPattern pattern,*/ IBuildObject ioType ) { + fStep = action; + fIsInput = input; + fIsPrimary = primary; + if(ioType != null){ + if(input){ + if(ioType instanceof IInputType) + fLinkId = ((IInputType)ioType).getBuildVariable(); + else + throw new IllegalArgumentException("wrong arg"); //$NON-NLS-1$ + } else { + if(ioType instanceof IOutputType) { + fLinkId = ((IOutputType)ioType).getBuildVariable(); + } else + throw new IllegalArgumentException("wrong arg"); //$NON-NLS-1$ + } + fIoType = ioType; + } else { + //TODO + } + ((BuildDescription)fStep.getBuildDescription()).typeCreated(this); + } + + public IBuildResource[] getResources() { + return (BuildResource[])fResources.toArray(new BuildResource[fResources.size()]); + } + + public IBuildStep getStep() { + return fStep; + } + + public void addResource(BuildResource rc){ + fResources.add(rc); + rc.addToArg(this); + if(DbgUtil.DEBUG) + DbgUtil.traceln("resource " + DbgUtil.resourceName(rc) + " added as " //$NON-NLS-1$ //$NON-NLS-2$ + + (fIsInput ? "input" : "output") //$NON-NLS-1$ //$NON-NLS-2$ + + " to the action " + DbgUtil.stepName(fStep)); //$NON-NLS-1$ + + ((BuildDescription)fStep.getBuildDescription()).resourceAddedToType(this, rc); + } + + public void removeResource(BuildResource rc){ + fResources.remove(rc); + rc.removeFromArg(this); + + if(DbgUtil.DEBUG) + DbgUtil.traceln("resource " + DbgUtil.resourceName(rc) + " removed as " //$NON-NLS-1$ //$NON-NLS-2$ + + (fIsInput ? "input" : "output") //$NON-NLS-1$ //$NON-NLS-2$ + + " from the action " + DbgUtil.stepName(fStep)); //$NON-NLS-1$ + + ((BuildDescription)fStep.getBuildDescription()).resourceRemovedFromType(this, rc); + } + + public boolean isInput() { + return fIsInput; + } + + public boolean isPrimary(){ + return fIsPrimary; + } + + public String getLinkId(){ + if(!fIsInput && fStep.getTool() != null && /*(fLinkId == null || fLinkId.length() == 0) && */ + fStep.getTool().getCustomBuildStep()){ + IBuildResource rcs[] = getResources(); + if(rcs.length != 0){ + BuildDescription.ToolAndType tt = ((BuildDescription)fStep.getBuildDescription()).getToolAndType((BuildResource)rcs[0], false); + if(tt != null){ + IInputType type = tt.fTool.getPrimaryInputType(); + if(type != null) + fLinkId = type.getBuildVariable(); + } else { + } + } + + } + return fLinkId; + } + + public IBuildObject getIoType(){ + return fIoType; + } + + BuildResource[] remove(){ + BuildResource rcs[] = (BuildResource[])getResources(); + + for(int i = 0; i < rcs.length; i++){ + removeResource(rcs[i]); + } + + fStep = null; + return rcs; + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildMultiStatus.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildMultiStatus.java new file mode 100644 index 00000000000..2ad6de730ca --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildMultiStatus.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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 org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; +import org.eclipse.core.runtime.MultiStatus; + +/** + * + */ +public class BuildMultiStatus extends MultiStatus { + + public BuildMultiStatus(String message, Throwable exception){ + super(ManagedBuilderCorePlugin.getUniqueIdentifier(), 0, message, exception); + } + +} 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 new file mode 100644 index 00000000000..f3ae58809ef --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildResource.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * 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.ArrayList; +import java.util.List; + +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildIOType; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildResource; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.runtime.IPath; + +public class BuildResource implements IBuildResource { + private List fDepArgs = new ArrayList(); + private BuildIOType fProducerArg; + private boolean fNeedsRebuild; + private boolean fIsRemoved; + private IPath fLocation; + private IPath fFullPath; + private boolean fIsProjectRc; + private BuildDescription fInfo; + + protected BuildResource(BuildDescription info, IResource rc){ + this(info, rc.getLocation(), rc.getFullPath()); + } + + protected BuildResource(BuildDescription info, IPath location, IPath fullPath){ + fLocation = location; + fInfo = info; + fFullPath = fullPath; + 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) + DbgUtil.traceln("resource " + location + " created"); //$NON-NLS-1$ //$NON-NLS-2$ + } + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildResource#getLocation() + */ + public IPath getLocation() { + return fLocation; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildResource#getFullPath() + */ + public IPath getFullPath() { + return fFullPath; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildResource#getProducerIOType() + */ + public IBuildIOType getProducerIOType() { + return fProducerArg; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildResource#getDependentIOTypes() + */ + public IBuildIOType[] getDependentIOTypes() { + return (BuildIOType[])fDepArgs.toArray(new BuildIOType[fDepArgs.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildResource#needsRebuild() + */ + public boolean needsRebuild() { + return fNeedsRebuild; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildResource#isRemoved() + */ + public boolean isRemoved() { + return fIsRemoved; + } + + public void setRemoved() { + fIsRemoved = true; + fNeedsRebuild = false; + } + + public void setRebuildState(boolean rebuild){ + fNeedsRebuild = rebuild; + } + + void addToArg(BuildIOType arg){ + if(arg.isInput()){ + fDepArgs.add(arg); + } else { + if(fProducerArg == null) + fProducerArg = arg; + 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); + } + } + } + + void removeFromArg(BuildIOType arg){ + if(arg.isInput()){ + fDepArgs.remove(arg); + } else { + if(fProducerArg == arg) + fProducerArg = null; + else + throw new AssertionError("Resource is not produced by this arg!!!"); //$NON-NLS-1$ + } + } + + public boolean isProjectResource() { + return fIsProjectRc; + } + + BuildIOType[][] clear(){ + BuildIOType types[][] = new BuildIOType[2][]; + types[0] = new BuildIOType[1]; + types[0][0] = fProducerArg; + BuildIOType outs[] = (BuildIOType[])getDependentIOTypes(); + types[1] = outs; + + if(fProducerArg != null) + fProducerArg.removeResource(this); + for(int i = 0; i < outs.length; i++){ + outs[i].removeResource(this); + } + + return types; + } + + BuildIOType[][] remove(){ + BuildIOType types[][] = clear(); + + if(DbgUtil.DEBUG) + DbgUtil.traceln("resource " + DbgUtil.resourceName(this) + " removed"); //$NON-NLS-1$ //$NON-NLS-2$ + + fInfo.resourceRemoved(this); + fInfo = null; + + return types; + } + + public IBuildDescription getBuildDescription(){ + return fInfo; + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildStatus.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildStatus.java new file mode 100644 index 00000000000..3efa4b379a8 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildStatus.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * 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 org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +public class BuildStatus extends Status { + + public BuildStatus(String message, Throwable exception) { + super(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), 0, message, exception); + } + +} 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 new file mode 100644 index 00000000000..d9843a0b532 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildStep.java @@ -0,0 +1,401 @@ +/******************************************************************************* + * 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.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildCommand; +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.core.BuildException; +import org.eclipse.cdt.managedbuilder.core.IBuildObject; +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.ITool; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.internal.core.Configuration; +import org.eclipse.cdt.managedbuilder.internal.core.Tool; +import org.eclipse.cdt.managedbuilder.internal.macros.DefaultMacroSubstitutor; +import org.eclipse.cdt.managedbuilder.internal.macros.FileContextData; +import org.eclipse.cdt.managedbuilder.macros.BuildMacroException; +import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider; +import org.eclipse.cdt.managedbuilder.macros.IFileContextData; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +public class BuildStep implements IBuildStep { + private List fInputTypes = new ArrayList(); + private List fOutputTypes = new ArrayList(); + private ITool fTool; + private BuildGroup fBuildGroup; + private boolean fNeedsRebuild; + private boolean fIsRemoved; + private BuildDescription fBuildDescription; + private IInputType fInputType; + private ITool fLibTool; + + protected BuildStep(BuildDescription des, ITool tool, IInputType inputType){ + fTool = tool; + fInputType = inputType; + fBuildDescription = des; + + if(DbgUtil.DEBUG) + DbgUtil.traceln("step " + DbgUtil.stepName(this) + " created"); //$NON-NLS-1$ //$NON-NLS-2$ + + des.stepCreated(this); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildStep#getInputIOTypes() + */ + public IBuildIOType[] getInputIOTypes() { + return (BuildIOType[])fInputTypes.toArray(new BuildIOType[fInputTypes.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildStep#getOutputIOTypes() + */ + public IBuildIOType[] getOutputIOTypes() { + return (BuildIOType[])fOutputTypes.toArray(new BuildIOType[fOutputTypes.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildStep#needsRebuild() + */ + public boolean needsRebuild() { + if(fNeedsRebuild + || (fTool != null && fTool.needsRebuild()) + || (fLibTool != null && fLibTool.needsRebuild())) + return true; + + if(fBuildGroup != null && fBuildGroup.needsRebuild()) + return true; + + return false; + } + + public void setRebuildState(boolean rebuild){ + fNeedsRebuild = rebuild; + } + + public BuildResource[] removeIOType(BuildIOType type) { + + BuildResource rcs[] = type.remove(); + + if(type.isInput()) + fInputTypes.remove(type); + else + fOutputTypes.remove(type); + + return rcs; + } + + BuildResource[][] remove(){ + BuildResource[][] rcs = clear(); + + if(DbgUtil.DEBUG) + DbgUtil.traceln("step " + DbgUtil.stepName(this) + " removed"); //$NON-NLS-1$ //$NON-NLS-2$ + + fBuildDescription.stepRemoved(this); + fBuildDescription = null; + + return rcs; + } + + BuildResource[][] clear(){ + BuildResource[][] rcs = new BuildResource[2][]; + + rcs[0] = (BuildResource[])getInputResources(); + rcs[1] = (BuildResource[])getOutputResources(); + + BuildIOType types[] = (BuildIOType[])getInputIOTypes(); + for(int i = 0; i < types.length; i++){ + removeIOType(types[i]); + } + + types = (BuildIOType[])getOutputIOTypes(); + for(int i = 0; i < types.length; i++){ + removeIOType(types[i]); + } + + return rcs; + } + + public BuildIOType createIOType(boolean input, boolean primary, /*String ext,*/ IBuildObject ioType) { + if(input){ + if(fBuildDescription.getInputStep() == this) + throw new IllegalArgumentException("input step can not have inputs"); //$NON-NLS-1$ + } else { + if(fBuildDescription.getOutputStep() == this) + throw new IllegalArgumentException("input step can not have outputs"); //$NON-NLS-1$ + } + + BuildIOType arg = new BuildIOType(this, input, primary, /*ext,*/ ioType); + if(input) + fInputTypes.add(arg); + else + fOutputTypes.add(arg); + + return arg; + } + + public void setTool(ITool tool){ + fTool = tool; + } + + public ITool getTool(){ + return fTool; + } + + public BuildIOType[] getPrimaryTypes(boolean input){ + Iterator iter = input ? + fInputTypes.iterator() : + fOutputTypes.iterator(); + + List list = new ArrayList(); + while(iter.hasNext()){ + BuildIOType arg = (BuildIOType)iter.next(); + if(arg.isPrimary()) + list.add(arg); + } + return (BuildIOType[])list.toArray(new BuildIOType[list.size()]); + } + + public BuildIOType getIOTypeForType(IBuildObject ioType, boolean input){ + List list; + if(input) + list = fInputTypes; + else + list = fOutputTypes; + + if(ioType != null){ + for(Iterator iter = list.iterator();iter.hasNext();){ + BuildIOType arg = (BuildIOType)iter.next(); + if(arg.getIoType() == ioType) + return arg; + } + } else { + if(list.size() > 0) + return (BuildIOType)list.get(0); + } + return null; + } + + protected void setGroup(BuildGroup group){ + fBuildGroup = group; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildStep#getInputResources() + */ + public IBuildResource[] getInputResources() { + return getResources(true); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildStep#getOutputResources() + */ + public IBuildResource[] getOutputResources() { + return getResources(false); + } + + public IBuildResource[] getResources(boolean input){ + Iterator iter = input ? + fInputTypes.iterator() : + fOutputTypes.iterator(); + + Set set = new HashSet(); + + while(iter.hasNext()){ + IBuildResource rcs[] = ((BuildIOType)iter.next()).getResources(); + for(int j = 0; j < rcs.length; j++){ + set.add(rcs[j]); + } + } + return (BuildResource[])set.toArray(new BuildResource[set.size()]); + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildStep#getCommands(org.eclipse.core.runtime.IPath, java.util.Map, java.util.Map, boolean) + */ + public IBuildCommand[] getCommands(IPath cwd, Map inputArgValues, Map outputArgValues, boolean resolveAll) { + if(fTool == null) + return null; + + if(!cwd.isAbsolute()) + cwd = fBuildDescription.getConfiguration().getOwner().getProject().getLocation().append(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, + resolveMacros(fTool.getToolCommand(), data, true), + getCommandFlags(inRcPath, outRcPath, resolveAll), + resolveMacros(fTool.getOutputFlag(), data, true), + resolveMacros(fTool.getOutputPrefix(), data, true), + listToString(resourcesToStrings(cwd, getPrimaryResources(false)), " "), //$NON-NLS-1$ + resourcesToStrings(cwd, getPrimaryResources(true)), + fTool.getCommandLinePattern()); + + return createCommandsFromString(info.getCommandLine(), cwd); + } + + 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); + + return new IBuildCommand[]{new BuildCommand(c, args, null, cwd, this)}; + } + + private BuildResource[] getPrimaryResources(boolean input){ + BuildIOType[] types = getPrimaryTypes(input); + if(types.length == 0) + types = input ? (BuildIOType[])getInputIOTypes() : (BuildIOType[])getOutputIOTypes(); + List list = new ArrayList(); + + for(int i = 0; i < types.length; i++){ + BuildResource [] rcs = (BuildResource[])types[i].getResources(); + + for(int j = 0; j < rcs.length; j++){ + list.add(rcs[j]); + } + } + + return (BuildResource[])list.toArray(new BuildResource[list.size()]); + } + + private String[] resourcesToStrings(IPath cwd, BuildResource rcs[]){ + List list = new ArrayList(rcs.length); + + for(int i = 0; i < rcs.length; i++){ + list.add(BuildDescriptionManager.getRelPath(cwd, rcs[i].getLocation()).toOSString()); + } + return (String[])list.toArray(new String[list.size()]); + } + + private String resolveMacros(String str, IFileContextData fileData, boolean resolveAll){ + try { + String tmp = resolveAll ? ManagedBuildManager.getBuildMacroProvider().resolveValue(str, "", " ", IBuildMacroProvider.CONTEXT_FILE, fileData) //$NON-NLS-1$ //$NON-NLS-2$ + : + ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(str, "", " ", IBuildMacroProvider.CONTEXT_FILE, fileData); //$NON-NLS-1$ //$NON-NLS-2$ + if((tmp = tmp.trim()).length() != 0) + str = tmp; + } catch (BuildMacroException e) { + } + + return str; + } + + private String[] getCommandFlags(IPath inRcPath, IPath outRcPath, boolean resolveAll){ + try { + return resolveAll ? + ((Tool)fTool).getToolCommandFlags(inRcPath, outRcPath, + new DefaultMacroSubstitutor(IBuildMacroProvider.CONTEXT_FILE, new FileContextData(inRcPath, outRcPath, null, fTool), "", " ")) //$NON-NLS-1$ //$NON-NLS-2$ + : + fTool.getToolCommandFlags(inRcPath, outRcPath); + } catch (BuildException e) { + } + return new String[0]; + } + + private String listToString(String[] list, String delimiter){ + if(list == null || list.length == 0) + return new String(); + + StringBuffer buf = new StringBuffer(list[0]); + + for(int i = 1; i < list.length; i++){ + buf.append(delimiter).append(list[i]); + } + + return buf.toString(); + } + + private BuildResource getRcForMacros(boolean input){ + IBuildIOType types[] = getPrimaryTypes(input); + if(types.length != 0){ + for(int i = 0; i < types.length; i++){ + IBuildResource rcs[] = types[i].getResources(); + if(rcs.length != 0) + return (BuildResource)rcs[0]; + } + } + + types = input ? getInputIOTypes() : getOutputIOTypes(); + if(types.length != 0){ + for(int i = 0; i < types.length; i++){ + IBuildResource rcs[] = types[i].getResources(); + if(rcs.length != 0) + return (BuildResource)rcs[0]; + } + } + + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildStep#isRemoved() + */ + public boolean isRemoved(){ + return fIsRemoved; + } + + public void setRemoved() { + fIsRemoved = true; + fNeedsRebuild = false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildStep#getBuildDescription() + */ + public IBuildDescription getBuildDescription(){ + return fBuildDescription; + } + + boolean isMultiAction(){ + BuildIOType args[] = getPrimaryTypes(true); + BuildIOType arg = args.length > 0 ? args[0] : null; + + if(arg != null){ + if(arg.getIoType() != null) + return ((IInputType)arg.getIoType()).getMultipleOfType(); + return fTool != null && fTool == ((Configuration)fBuildDescription.getConfiguration()).calculateTargetTool(); + } + return false; + } + + public IInputType getInputType(){ + return fInputType; + } + + public void setLibTool(ITool libTool){ + fLibTool = libTool; + } + + public ITool getLibTool(){ + return fLibTool; + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/DbgUtil.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/DbgUtil.java new file mode 100644 index 00000000000..c65fc7e0899 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/DbgUtil.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.PrintStream; +import java.util.HashSet; +import java.util.Set; + +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.core.ITool; + +/* + * this is the build description debug utility class + */ +public class DbgUtil { + public static final boolean DEBUG = false; + private static PrintStream out = System.out; + + public static void trace(String str){ + out.print(str); + } + + public static void traceln(String str){ + out.println(str); + } + + public static String stepName(IBuildStep action){ + ITool tool = action instanceof BuildStep ? ((BuildStep)action).getTool() : null; + if(tool != null) + return tool.getName(); + if(action.getBuildDescription().getInputStep() == action) + return "input step"; //$NON-NLS-1$ + if(action.getBuildDescription().getOutputStep() == action) + return "output step"; //$NON-NLS-1$ + return ""; //$NON-NLS-1$ + } + + public static String resourceName(IBuildResource rc){ + if(rc.getFullPath() != null) + return rc.getFullPath().toString(); + return rc.getLocation().toString(); + } + + public static String dumpType(IBuildIOType type){ + StringBuffer buf = new StringBuffer(); + + buf.append("dumping type: "); //$NON-NLS-1$ + buf.append(type.isInput() ? "INPUT" : "OUTPUT"); //$NON-NLS-1$ //$NON-NLS-2$ + buf.append(ioTypeResources(type)); + buf.append("end dumping type"); //$NON-NLS-1$ + + return buf.toString(); + } + + public static String ioTypeResources(IBuildIOType type){ + StringBuffer buf = new StringBuffer(); + + IBuildResource rcs[] = type.getResources(); + + buf.append("\n"); //$NON-NLS-1$ + + for(int i = 0; i < rcs.length; i++){ + buf.append(resourceName(rcs[i])); + buf.append("\n"); //$NON-NLS-1$ + } + + return buf.toString(); + } + + public static String dumpStep(IBuildStep step, boolean inputs) { + StringBuffer buf = new StringBuffer(); + + buf.append("dumping step ").append(stepName(step)).append(inputs ? " inputs" : " outputs"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + IBuildIOType types[] = inputs ? step.getInputIOTypes() : step.getOutputIOTypes(); + + buf.append("\n"); //$NON-NLS-1$ + + for(int i = 0; i < types.length; i++){ + buf.append("ioType " + i + ":"); //$NON-NLS-1$ //$NON-NLS-2$ + buf.append(ioTypeResources(types[i])); + } + + buf.append("end dump step\n"); //$NON-NLS-1$ + return buf.toString(); + } + + public static String dumpStep(IBuildStep step){ + return dumpStep(step, true) + dumpStep(step, false); + } + + public static String dumpResource(IBuildResource rc){ + return dumpResource(rc, true) + dumpResource(rc, false); + } + + public static String dumpResource(IBuildResource rc, boolean producer){ + StringBuffer buf = new StringBuffer(); + + buf.append("dumping resource ").append(resourceName(rc)).append(producer ? " producer:" : " deps:"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + if(producer){ + if(rc.getProducerIOType() != null) + buf.append(dumpStep(rc.getProducerIOType().getStep())); + else + buf.append("\nresourse has no producer\n"); //$NON-NLS-1$ + } else { + IBuildIOType types[] = rc.getDependentIOTypes(); + + if(types.length > 0){ + Set set = new HashSet(); + + for(int i = 0; i < types.length; i++){ + if(set.add(types[i].getStep())){ + buf.append(dumpStep(types[i].getStep())); + } + } + } else { + buf.append("\n resource has no deps\n"); //$NON-NLS-1$ + } + + } + + buf.append("end dump resource\n"); //$NON-NLS-1$ + return buf.toString(); + } + + public static void flush(){ + out.flush(); + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/DefaultBuildDescriptionFactory.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/DefaultBuildDescriptionFactory.java new file mode 100644 index 00000000000..b2e0c300b34 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/DefaultBuildDescriptionFactory.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * 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 org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescriptionFactory; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.runtime.CoreException; + +public class DefaultBuildDescriptionFactory implements IBuildDescriptionFactory { + static private DefaultBuildDescriptionFactory fInstance; + protected DefaultBuildDescriptionFactory(){ + + } + + public static DefaultBuildDescriptionFactory getInstance(){ + if(fInstance == null) + fInstance = new DefaultBuildDescriptionFactory(); + return fInstance; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildDescriptionFactory#createBuildDescription(org.eclipse.cdt.managedbuilder.core.IConfiguration, org.eclipse.core.resources.IResourceDelta, int) + */ + public IBuildDescription createBuildDescription(IConfiguration cfg, IResourceDelta delta, int flags) throws CoreException { + BuildDescription info = new BuildDescription(); + info.init(cfg, delta, flags); + return info; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.builddescription.IBuildDescriptionFactory#getSupportedMethods() + */ + public int getSupportedMethods() { + return BuildDescriptionManager.REMOVED | BuildDescriptionManager.REBUILD; + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/AdditionalInput.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/AdditionalInput.java index fc98b215a07..fd81fd1eb5b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/AdditionalInput.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/AdditionalInput.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 Intel Corporation and others. + * Copyright (c) 2005, 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 @@ -30,6 +30,7 @@ public class AdditionalInput implements IAdditionalInput { private boolean isExtensionAdditionalInput = false; private boolean isDirty = false; private boolean resolved = true; + private boolean rebuildState; /* * C O N S T R U C T O R S @@ -65,6 +66,7 @@ public class AdditionalInput implements IAdditionalInput { isExtensionAdditionalInput = isExtensionElement; if (!isExtensionElement) { setDirty(true); + setRebuildState(true); } } @@ -103,6 +105,7 @@ public class AdditionalInput implements IAdditionalInput { } setDirty(true); + setRebuildState(true); } /* @@ -226,6 +229,7 @@ public class AdditionalInput implements IAdditionalInput { if (paths == null || newPaths == null || !(paths.equals(newPaths))) { paths = newPaths; isDirty = true; + setRebuildState(true); } } @@ -246,6 +250,7 @@ public class AdditionalInput implements IAdditionalInput { if (kind == null || !(kind.intValue() == newKind)) { kind = new Integer(newKind); isDirty = true; + setRebuildState(true); } } @@ -285,4 +290,15 @@ public class AdditionalInput implements IAdditionalInput { } } + public boolean needsRebuild(){ + return rebuildState; + } + + public void setRebuildState(boolean rebuild){ + if(isExtensionElement() && rebuild) + return; + + rebuildState = rebuild; + } + } 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 b63813bc2d2..be81748487d 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. + * Copyright (c) 2003, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -346,7 +346,7 @@ public class Configuration extends BuildObject implements IConfiguration { // Hook me up managedProject.addConfiguration(this); setDirty(true); - rebuildNeeded = true; + setRebuildState(true); } /* @@ -719,7 +719,7 @@ public class Configuration extends BuildObject implements IConfiguration { if (option.getBooleanValue() != value) { retOpt = holder.getOptionToSet(option, false); retOpt.setValue(value); - rebuildNeeded = true; +// rebuildNeeded = true; } return retOpt; } @@ -734,7 +734,7 @@ public class Configuration extends BuildObject implements IConfiguration { if (oldValue != null && !oldValue.equals(value)) { retOpt = holder.getOptionToSet(option, false); retOpt.setValue(value); - rebuildNeeded = true; +// rebuildNeeded = true; } return retOpt; } @@ -769,7 +769,7 @@ public class Configuration extends BuildObject implements IConfiguration { if(!Arrays.equals(value, oldValue)) { retOpt = holder.getOptionToSet(option, false); retOpt.setValue(value); - rebuildNeeded = true; +// rebuildNeeded = true; } return retOpt; } @@ -807,7 +807,7 @@ public class Configuration extends BuildObject implements IConfiguration { getResourceConfigurationList().add(resConfig); getResourceConfigurationMap().put(resConfig.getResourcePath(), resConfig); isDirty = true; - rebuildNeeded = true; +// rebuildNeeded = true; } public void removeResourceConfiguration(IResourceConfiguration resConfig) { @@ -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 @@ -1060,7 +1060,15 @@ public class Configuration extends BuildObject implements IConfiguration { if (extension == null && artifactExtension == null) return; if (artifactExtension == null || extension == null || !artifactExtension.equals(extension)) { artifactExtension = extension; - rebuildNeeded = true; +// rebuildNeeded = true; + if(!isExtensionElement()){ + ITool tool = calculateTargetTool(); + if(tool != null){ + tool.setRebuildState(true); + } else { + setRebuildState(true); + } + } isDirty = true; } } @@ -1072,7 +1080,15 @@ public class Configuration extends BuildObject implements IConfiguration { if (name == null && artifactName == null) return; if (artifactName == null || name == null || !artifactName.equals(name)) { artifactName = name; - rebuildNeeded = true; + if(!isExtensionElement()){ + ITool tool = calculateTargetTool(); + if(tool != null) { + tool.setRebuildState(true); + } else { + setRebuildState(true); + } + } +// rebuildNeeded = true; isDirty = true; } } @@ -1120,7 +1136,7 @@ public class Configuration extends BuildObject implements IConfiguration { if(makeArgs == null){ //resetting the build arguments if(!builder.isExtensionElement()){ builder.setArguments(makeArgs); - rebuildNeeded = true; +// rebuildNeeded = true; } }else if(!makeArgs.equals(builder.getArguments())){ if (builder.isExtensionElement()) { @@ -1129,7 +1145,7 @@ public class Configuration extends BuildObject implements IConfiguration { builder = toolChain.createBuilder(builder, subId, builderName, false); } builder.setArguments(makeArgs); - rebuildNeeded = true; +// rebuildNeeded = true; } } @@ -1142,7 +1158,7 @@ public class Configuration extends BuildObject implements IConfiguration { if(command == null){ //resetting the build command if(!builder.isExtensionElement()){ builder.setCommand(command); - rebuildNeeded = true; +// rebuildNeeded = true; } } else if(!command.equals(builder.getCommand())){ if (builder.isExtensionElement()) { @@ -1151,7 +1167,7 @@ public class Configuration extends BuildObject implements IConfiguration { builder = toolChain.createBuilder(builder, subId, builderName, false); } builder.setCommand(command); - rebuildNeeded = true; +// rebuildNeeded = true; } } @@ -1162,7 +1178,7 @@ public class Configuration extends BuildObject implements IConfiguration { if (step == null && prebuildStep == null) return; if (prebuildStep == null || step == null || !prebuildStep.equals(step)) { prebuildStep = step; - rebuildNeeded = true; +// rebuildNeeded = true; isDirty = true; } } @@ -1175,7 +1191,7 @@ public class Configuration extends BuildObject implements IConfiguration { if (step == null && postbuildStep == null) return; if (postbuildStep == null || step == null || !postbuildStep.equals(step)) { postbuildStep = step; - rebuildNeeded = true; +// rebuildNeeded = true; isDirty = true; } } @@ -1187,7 +1203,7 @@ public class Configuration extends BuildObject implements IConfiguration { if (announceStep == null && preannouncebuildStep == null) return; if (preannouncebuildStep == null || announceStep == null || !preannouncebuildStep.equals(announceStep)) { preannouncebuildStep = announceStep; - rebuildNeeded = true; +// rebuildNeeded = true; isDirty = true; } } @@ -1199,7 +1215,7 @@ public class Configuration extends BuildObject implements IConfiguration { if (announceStep == null && postannouncebuildStep == null) return; if (postannouncebuildStep == null || announceStep == null || !postannouncebuildStep.equals(announceStep)) { postannouncebuildStep = announceStep; - rebuildNeeded = true; +// rebuildNeeded = true; isDirty = true; } } @@ -1290,7 +1306,39 @@ public class Configuration extends BuildObject implements IConfiguration { * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#needsRebuild() */ public boolean needsRebuild() { - return rebuildNeeded; + return needsRebuild(true); + } + + public boolean needsFullRebuild() { + return needsRebuild(false); + } + + public boolean needsRebuild(boolean checkChildren) { + if(rebuildNeeded || !checkChildren) + return rebuildNeeded; + + if(toolChain.needsRebuild()) + return true; + + for(Iterator iter = resourceConfigurationList.iterator();iter.hasNext();){ + IResourceConfiguration rcCfg = (IResourceConfiguration)iter.next(); + if(rcCfg.needsRebuild()) + return true; + + ITool tools[] = rcCfg.getToolsToInvoke(); + for(int i = 0; i < tools.length; i++){ + if(tools[i].needsRebuild()) + return true; + } + } + + ITool tools[] = getFilteredTools(); + for(int i = 0; i < tools.length; i++){ + if(tools[i].needsRebuild()) + return true; + } + + return false; } /* (non-Javadoc) @@ -1314,9 +1362,29 @@ public class Configuration extends BuildObject implements IConfiguration { * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#setRebuildState(boolean) */ public void setRebuildState(boolean rebuild) { + if(isExtensionElement() && rebuild) + return; + rebuildNeeded = rebuild; - if(rebuild && !isTemporary()) - ((EnvironmentVariableProvider)ManagedBuildManager.getEnvironmentVariableProvider()).checkBuildPathVariables(this); + + if(!rebuildNeeded){ + toolChain.setRebuildState(false); + + for(Iterator iter = resourceConfigurationList.iterator();iter.hasNext();){ + IResourceConfiguration rcCfg = (IResourceConfiguration)iter.next(); + rcCfg.setRebuildState(false); + + ITool tools[] = rcCfg.getToolsToInvoke(); + for(int i = 0; i < tools.length; i++){ + tools[i].setRebuildState(false); + } + } + + ITool tools[] = getFilteredTools(); + for(int i = 0; i < tools.length; i++){ + tools[i].setRebuildState(false); + } + } } /* (non-Javadoc) @@ -1390,7 +1458,7 @@ public class Configuration extends BuildObject implements IConfiguration { toolChain.removeOption(opts[j]); } - rebuildNeeded = true; +// rebuildNeeded = true; } /* @@ -1486,4 +1554,32 @@ public class Configuration extends BuildObject implements IConfiguration { setDirty(true); } } + + public ITool calculateTargetTool(){ + ITool tool = getTargetTool(); + + if(tool == null){ + IConfiguration extCfg; + for(extCfg = this; + extCfg != null && !extCfg.isExtensionElement(); + extCfg = extCfg.getParent()){ + + } + + String ext = extCfg != null ? extCfg.getArtifactExtension() : + getArtifactExtension(); + + // Get all the tools for the current config + ITool[] tools = getFilteredTools(); + for (int index = 0; index < tools.length; index++) { + ITool t = tools[index]; + if (t.producesFileType(ext)) { + tool = t; + break; + } + } + } + + return tool; + } } 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 2eaf2707108..4a39efc0dbb 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 @@ -27,7 +27,9 @@ import org.eclipse.cdt.core.IMarkerGenerator; 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.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager; +import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription; +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; @@ -61,7 +63,6 @@ import org.eclipse.core.runtime.SubProgressMonitor; * @since 1.2 */ public class GeneratedMakefileBuilder extends ACBuilder { - /** * @since 1.2 */ @@ -327,13 +328,72 @@ public class GeneratedMakefileBuilder extends ACBuilder { outputError(getProject().getName(), "Build information is not valid"); //$NON-NLS-1$ 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, + //full rebuild is needed in any case + //clean first, then make a full build + outputTrace(getProject().getName(), "config rebuild state is set to true, making a full rebuild"); //$NON-NLS-1$ + clean(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN)); + fullBuild(info, generator, monitor); + } else { + boolean fullBuildNeeded = info.needsRebuild(); + IBuildDescription des = null; + + IResourceDelta delta = kind == FULL_BUILD ? null : getDelta(getProject()); + if(delta == null) + fullBuildNeeded = true; + if(cfg.needsRebuild() || delta != null){ + //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; + if(delta != null) + flags |= BuildDescriptionManager.REMOVED; + + outputTrace(getProject().getName(), "using a build description.."); //$NON-NLS-1$ + + des = BuildDescriptionManager.createBuildDescription(info.getDefaultConfiguration(), getDelta(getProject()), flags); + + BuildDescriptionManager.cleanRebuildResources(des); + } catch (Throwable e){ + //TODO: log error + outputError(getProject().getName(), "error occured while build description calculation: " + e.getLocalizedMessage()); //$NON-NLS-1$ + //in case an error occured, make it behave in the old stile: + if(info.needsRebuild()){ + //make a full clean if an info needs a rebuild + clean(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN)); + fullBuildNeeded = true; + } + else if(delta != null && !fullBuildNeeded){ + // Create a delta visitor to detect the build type + ResourceDeltaVisitor visitor = new ResourceDeltaVisitor(info); + delta.accept(visitor); + if (visitor.shouldBuildFull()) { + fullBuildNeeded = true; + } + } + } + } + + if(fullBuildNeeded){ + outputTrace(getProject().getName(), "performing a full build"); //$NON-NLS-1$ + fullBuild(info, generator, monitor); + } else { + outputTrace(getProject().getName(), "performing an incremental build"); //$NON-NLS-1$ + incrementalBuild(delta, info, generator, monitor); + } + } +/* // So let's figure out why we got called - if (kind == FULL_BUILD || info.needsRebuild()) { + if (kind == FULL_BUILD) { outputTrace(getProject().getName(), "Full build needed/requested"); //$NON-NLS-1$ fullBuild(info, generator, monitor); } @@ -385,6 +445,7 @@ public class GeneratedMakefileBuilder extends ACBuilder { } } } +*/ // Scrub the build info the project info.setRebuildState(false); // Ask build mechanism to compute deltas for project dependencies next time @@ -505,7 +566,7 @@ public class GeneratedMakefileBuilder extends ACBuilder { //in case one or more of the generated makefiles (e.g. dep files) are corrupted, //the builder invocation might fail because of the possible syntax errors, so e.g. "make clean" will not work //we need to explicitly clean the generated directories - clean(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN)); +// clean(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN)); // Regenerate the makefiles for this project checkCancel(monitor); @@ -913,10 +974,18 @@ public class GeneratedMakefileBuilder extends ACBuilder { } catch (IOException e) { } - if (launcher.waitAndRead(epm.getOutputStream(), epm.getOutputStream(), + int state = launcher.waitAndRead(epm.getOutputStream(), epm.getOutputStream(), new SubProgressMonitor(monitor, - IProgressMonitor.UNKNOWN)) != CommandLauncher.OK) { + IProgressMonitor.UNKNOWN)); + if(state != CommandLauncher.OK){ errMsg = launcher.getErrorMessage(); + + if(state == CommandLauncher.COMMAND_CANCELED){ + //TODO: the better way of handling cancel is needed + //currently the rebuild state is set to true forcing the full rebuild + //on the next builder invocation + info.getDefaultConfiguration().setRebuildState(true); + } } // Force a resync of the projects without allowing the user to cancel. diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HoldsOptions.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HoldsOptions.java index 08dcc9189b0..461af6aa688 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HoldsOptions.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HoldsOptions.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 Symbian Ltd and others. + * Copyright (c) 2005, 2006 Symbian Ltd 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 @@ -62,6 +62,7 @@ public class HoldsOptions extends BuildObject implements IHoldsOptions { private Map optionMap; // Miscellaneous private boolean isDirty = false; + private boolean rebuildState; /* * C O N S T R U C T O R S @@ -189,8 +190,10 @@ public class HoldsOptions extends BuildObject implements IHoldsOptions { public IOption createOption(IOption superClass, String Id, String name, boolean isExtensionElement) { Option option = new Option(this, superClass, Id, name, isExtensionElement); addOption(option); - if(!isExtensionElement) + if(!isExtensionElement){ setDirty(true); + setRebuildState(true); + } return option; } @@ -214,6 +217,7 @@ public class HoldsOptions extends BuildObject implements IHoldsOptions { getOptionList().remove(option); getOptionMap().remove(option.getId()); setDirty(true); + setRebuildState(true); } /* (non-Javadoc) @@ -509,6 +513,9 @@ public class HoldsOptions extends BuildObject implements IHoldsOptions { } } + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#getOptionToSet(org.eclipse.cdt.managedbuilder.core.IOption, boolean) + */ public IOption getOptionToSet(IOption option, boolean adjustExtension) throws BuildException{ IOption setOption = null; if(option.getOptionHolder() != this) @@ -565,4 +572,40 @@ public class HoldsOptions extends BuildObject implements IHoldsOptions { } return setOption; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#needsRebuild() + */ + public boolean needsRebuild() { + if(rebuildState) + return true; + + // Otherwise see if any options need saving + List optionElements = getOptionList(); + Iterator iter = optionElements.listIterator(); + while (iter.hasNext()) { + Option option = (Option) iter.next(); + if (option.needsRebuild()) return true; + } + + return rebuildState; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#setRebuildState(boolean) + */ + public void setRebuildState(boolean rebuild) { + rebuildState = rebuild; + + // Propagate "false" to the children + if (!rebuildState) { + List optionElements = getOptionList(); + Iterator iter = optionElements.listIterator(); + while (iter.hasNext()) { + Option option = (Option) iter.next(); + if(!option.isExtensionElement()) + option.setRebuildState(false); + } + } + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputOrder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputOrder.java index a6c769d8e2d..84517d40f5f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputOrder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputOrder.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 Intel Corporation and others. + * Copyright (c) 2005, 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 @@ -10,8 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.core; -import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IInputOrder; +import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -31,6 +31,7 @@ public class InputOrder implements IInputOrder { private boolean isExtensionInputOrder = false; private boolean isDirty = false; private boolean resolved = true; + private boolean rebuildState; /* * C O N S T R U C T O R S @@ -108,6 +109,7 @@ public class InputOrder implements IInputOrder { } setDirty(true); + setRebuildState(true); } /* @@ -216,6 +218,7 @@ public class InputOrder implements IInputOrder { if (path == null || newPath == null || !(path.equals(newPath))) { path = newPath; isDirty = true; + setRebuildState(true); } } @@ -234,6 +237,7 @@ public class InputOrder implements IInputOrder { if (order == null || newOrder == null || !(order.equals(newOrder))) { order = newOrder; isDirty = true; + setRebuildState(true); } } @@ -251,6 +255,7 @@ public class InputOrder implements IInputOrder { if (excluded == null || !(b == excluded.booleanValue())) { excluded = new Boolean(b); setDirty(true); + setRebuildState(true); } } @@ -291,4 +296,14 @@ public class InputOrder implements IInputOrder { } } + public boolean needsRebuild(){ + return rebuildState; + } + + public void setRebuildState(boolean rebuild){ + if(isExtensionElement() && rebuild) + return; + + rebuildState = rebuild; + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java index f828fa58e4a..5c0df40bd47 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java @@ -67,6 +67,7 @@ public class InputType extends BuildObject implements IInputType { private boolean isExtensionInputType = false; private boolean isDirty = false; private boolean resolved = true; + private boolean rebuildState; /* * C O N S T R U C T O R S @@ -131,6 +132,7 @@ public class InputType extends BuildObject implements IInputType { ManagedBuildManager.addExtensionInputType(this); } else { setDirty(true); + setRebuildState(true); } } @@ -237,6 +239,7 @@ public class InputType extends BuildObject implements IInputType { } setDirty(true); + setRebuildState(true); } /* @@ -756,6 +759,7 @@ public class InputType extends BuildObject implements IInputType { if (buildVariable == null || variableName == null || !(variableName.equals(buildVariable))) { buildVariable = variableName; setDirty(true); + setRebuildState(true); } } @@ -785,6 +789,7 @@ public class InputType extends BuildObject implements IInputType { dependencyContentTypeId = null; } setDirty(true); + setRebuildState(true); } } @@ -817,6 +822,7 @@ public class InputType extends BuildObject implements IInputType { } } setDirty(true); + setRebuildState(true); } /* (non-Javadoc) @@ -908,6 +914,7 @@ public class InputType extends BuildObject implements IInputType { public void setDependencyGeneratorElement(IConfigurationElement element) { dependencyGeneratorElement = element; setDirty(true); + setRebuildState(true); } /* (non-Javadoc) @@ -931,6 +938,7 @@ public class InputType extends BuildObject implements IInputType { if (multipleOfType == null || !(b == multipleOfType.booleanValue())) { multipleOfType = new Boolean(b); setDirty(true); + setRebuildState(true); } } @@ -955,6 +963,7 @@ public class InputType extends BuildObject implements IInputType { if (primaryInput == null || !(b == primaryInput.booleanValue())) { primaryInput = new Boolean(b); setDirty(true); + setRebuildState(true); } } @@ -980,6 +989,7 @@ public class InputType extends BuildObject implements IInputType { if (id == null || optionId == null || !(optionId.equals(id))) { optionId = id; setDirty(true); + setRebuildState(true); } } @@ -1005,6 +1015,7 @@ public class InputType extends BuildObject implements IInputType { if (id == null || assignToOptionId == null || !(assignToOptionId.equals(id))) { assignToOptionId = id; setDirty(true); + setRebuildState(true); } } @@ -1034,6 +1045,7 @@ public class InputType extends BuildObject implements IInputType { sourceContentTypeId = null; } setDirty(true); + setRebuildState(true); } } @@ -1064,6 +1076,7 @@ public class InputType extends BuildObject implements IInputType { } } setDirty(true); + setRebuildState(true); } /* (non-Javadoc) @@ -1218,4 +1231,45 @@ public class InputType extends BuildObject implements IInputType { public void setVersion(PluginVersionIdentifier version) { // Do nothing } + + public boolean needsRebuild(){ + if(rebuildState) + return true; + + Iterator typeIter = getInputOrderList().iterator(); + while (typeIter.hasNext()) { + InputOrder current = (InputOrder)typeIter.next(); + if (current.needsRebuild()) return true; + } + typeIter = getAdditionalInputList().iterator(); + while (typeIter.hasNext()) { + AdditionalInput current = (AdditionalInput)typeIter.next(); + if (current.needsRebuild()) return true; + } + + return rebuildState; + } + + public void setRebuildState(boolean rebuild){ + if(isExtensionElement() && rebuild) + return; + + rebuildState = rebuild; + + // Propagate "false" to the children + if (!rebuild) { + Iterator typeIter = getInputOrderList().iterator(); + while (typeIter.hasNext()) { + InputOrder current = (InputOrder)typeIter.next(); + current.setRebuildState(false); + } + typeIter = getAdditionalInputList().iterator(); + while (typeIter.hasNext()) { + AdditionalInput current = (AdditionalInput)typeIter.next(); + current.setRebuildState(false); + } + } + + } + } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java index 5c21fe68dd5..9ad4fa25895 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java @@ -949,6 +949,9 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo { // Save it defaultConfig = configuration; defaultConfigId = configuration.getId(); + + defaultConfig.setRebuildState(true); + // TODO: is this appropriate? persistDefaultConfiguration(); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java index 73b2e2e5679..8dff3980578 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. + * Copyright (c) 2003, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -86,6 +86,7 @@ public class Option extends BuildObject implements IOption { * MBS 2.0 model OptionReference element */ private boolean isUdjusted = false; + private boolean rebuildState; /* * C O N S T R U C T O R S @@ -137,6 +138,7 @@ public class Option extends BuildObject implements IOption { ManagedBuildManager.addExtensionOption(this); } else { setDirty(true); + setRebuildState(true); } } @@ -264,8 +266,10 @@ public class Option extends BuildObject implements IOption { valueHandlerExtraArgument = new String(option.valueHandlerExtraArgument); } - if(!isExtensionElement()) + if(!isExtensionElement()){ setDirty(true); + setRebuildState(true); + } } /* @@ -1337,8 +1341,10 @@ public class Option extends BuildObject implements IOption { */ public void setDefaultValue(Object v) { defaultValue = v; - if(!isExtensionElement()) + if(!isExtensionElement()){ setDirty(true); + rebuildState = true; + } } /* (non-Javadoc) @@ -1352,8 +1358,10 @@ public class Option extends BuildObject implements IOption { } else { categoryId = null; } - if(!isExtensionElement()) + if(!isExtensionElement()){ setDirty(true); + rebuildState = true; + } } } @@ -1364,8 +1372,10 @@ public class Option extends BuildObject implements IOption { if (cmd == null && command == null) return; if (cmd == null || command == null || !cmd.equals(command)) { command = cmd; - if(!isExtensionElement()) + if(!isExtensionElement()){ isDirty = true; + rebuildState = true; + } } } @@ -1376,8 +1386,10 @@ public class Option extends BuildObject implements IOption { if (cmd == null && commandFalse == null) return; if (cmd == null || commandFalse == null || !cmd.equals(commandFalse)) { commandFalse = cmd; - if(!isExtensionElement()) - isDirty = true; + if(!isExtensionElement()){ + isDirty = true; + rebuildState = true; + } } } @@ -1388,8 +1400,10 @@ public class Option extends BuildObject implements IOption { if (tooltip == null && tip == null) return; if (tooltip == null || tip == null || !tooltip.equals(tip)) { tip = tooltip; - if(!isExtensionElement()) + if(!isExtensionElement()){ isDirty = true; + rebuildState = true; + } } } @@ -1399,8 +1413,10 @@ public class Option extends BuildObject implements IOption { public void setResourceFilter(int filter) { if (resourceFilter == null || !(filter == resourceFilter.intValue())) { resourceFilter = new Integer(filter); - if(!isExtensionElement()) + if(!isExtensionElement()){ isDirty = true; + rebuildState = true; + } } } @@ -1410,8 +1426,10 @@ public class Option extends BuildObject implements IOption { public void setBrowseType(int type) { if (browseType == null || !(type == browseType.intValue())) { browseType = new Integer(type); - if(!isExtensionElement()) + if(!isExtensionElement()){ isDirty = true; + rebuildState = true; + } } } @@ -1424,8 +1442,10 @@ public class Option extends BuildObject implements IOption { } else { throw new BuildException(ManagedMakeMessages.getResourceString("Option.error.bad_value_type")); //$NON-NLS-1$ } - if(!isExtensionElement()) + if(!isExtensionElement()){ setDirty(true); + rebuildState = true; + } } @@ -1439,8 +1459,10 @@ public class Option extends BuildObject implements IOption { } else { throw new BuildException(ManagedMakeMessages.getResourceString("Option.error.bad_value_type")); //$NON-NLS-1$ } - if(!isExtensionElement()) + if(!isExtensionElement()){ setDirty(true); + rebuildState = true; + } } @@ -1463,8 +1485,10 @@ public class Option extends BuildObject implements IOption { else { throw new BuildException(ManagedMakeMessages.getResourceString("Option.error.bad_value_type")); //$NON-NLS-1$ } - if(!isExtensionElement()) + if(!isExtensionElement()){ setDirty(true); + rebuildState = true; + } } /* (non-Javadoc) @@ -1472,8 +1496,10 @@ public class Option extends BuildObject implements IOption { */ public void setValue(Object v) { value = v; - if(!isExtensionElement()) + if(!isExtensionElement()){ setDirty(true); + rebuildState = true; + } } /* (non-Javadoc) @@ -1483,8 +1509,10 @@ public class Option extends BuildObject implements IOption { // TODO: Verify that this is a valid type if (valueType == null || valueType.intValue() != type) { valueType = new Integer(type); - if(!isExtensionElement()) + if(!isExtensionElement()){ setDirty(true); + rebuildState = true; + } } } @@ -1505,8 +1533,10 @@ public class Option extends BuildObject implements IOption { */ public void setValueHandlerElement(IConfigurationElement element) { valueHandlerElement = element; - if(!isExtensionElement()) + if(!isExtensionElement()){ setDirty(true); + rebuildState = true; + } } /* (non-Javadoc) @@ -1557,8 +1587,10 @@ public class Option extends BuildObject implements IOption { valueHandlerExtraArgument == null || !extraArgument.equals(valueHandlerExtraArgument)) { valueHandlerExtraArgument = extraArgument; - if(!isExtensionElement()) + if(!isExtensionElement()){ isDirty = true; + rebuildState = true; + } } } @@ -1864,4 +1896,14 @@ public class Option extends BuildObject implements IOption { } } + public boolean needsRebuild() { + return rebuildState; + } + + public void setRebuildState(boolean rebuild) { + if(isExtensionElement() && rebuild) + return; + + rebuildState = rebuild; + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OutputType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OutputType.java index 809bdc25f00..a63cf61136d 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OutputType.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OutputType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 Intel Corporation and others. + * Copyright (c) 2005, 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 @@ -60,6 +60,7 @@ public class OutputType extends BuildObject implements IOutputType { private boolean isExtensionOutputType = false; private boolean isDirty = false; private boolean resolved = true; + private boolean rebuildState; /* * C O N S T R U C T O R S @@ -110,6 +111,7 @@ public class OutputType extends BuildObject implements IOutputType { ManagedBuildManager.addExtensionOutputType(this); } else { setDirty(true); + setRebuildState(true); } } @@ -186,6 +188,7 @@ public class OutputType extends BuildObject implements IOutputType { nameProvider = outputType.nameProvider; setDirty(true); + setRebuildState(true); } /* @@ -468,6 +471,7 @@ public class OutputType extends BuildObject implements IOutputType { if (buildVariable == null || variableName == null || !(variableName.equals(buildVariable))) { buildVariable = variableName; setDirty(true); + setRebuildState(true); } } @@ -492,6 +496,7 @@ public class OutputType extends BuildObject implements IOutputType { if (multipleOfType == null || !(b == multipleOfType.booleanValue())) { multipleOfType = new Boolean(b); setDirty(true); + setRebuildState(true); } } @@ -518,6 +523,7 @@ public class OutputType extends BuildObject implements IOutputType { if (namePattern == null || pattern == null || !(pattern.equals(namePattern))) { namePattern = pattern; setDirty(true); + setRebuildState(true); } } @@ -539,6 +545,7 @@ public class OutputType extends BuildObject implements IOutputType { public void setNameProviderElement(IConfigurationElement element) { nameProviderElement = element; setDirty(true); + setRebuildState(true); } /* (non-Javadoc) @@ -582,6 +589,7 @@ public class OutputType extends BuildObject implements IOutputType { if (id == null || optionId == null || !(optionId.equals(id))) { optionId = id; setDirty(true); + setRebuildState(true); } } @@ -611,6 +619,7 @@ public class OutputType extends BuildObject implements IOutputType { outputContentTypeId = null; } setDirty(true); + setRebuildState(true); } } @@ -636,6 +645,7 @@ public class OutputType extends BuildObject implements IOutputType { if (outputs == null || exts == null || !(exts.equals(outputs))) { outputs = exts; setDirty(true); + setRebuildState(true); } } @@ -687,6 +697,7 @@ public class OutputType extends BuildObject implements IOutputType { if (outputPrefix == null || prefix == null || !(prefix.equals(outputPrefix))) { outputPrefix = prefix; setDirty(true); + setRebuildState(true); } } @@ -715,6 +726,7 @@ public class OutputType extends BuildObject implements IOutputType { if (outputNames == null || names == null || !(names.equals(outputNames))) { outputNames = names; setDirty(true); + setRebuildState(true); } } @@ -746,6 +758,7 @@ public class OutputType extends BuildObject implements IOutputType { primaryInputTypeId = null; } setDirty(true); + setRebuildState(true); } } @@ -770,6 +783,7 @@ public class OutputType extends BuildObject implements IOutputType { if (primaryOutput == null || !(b == primaryOutput.booleanValue())) { primaryOutput = new Boolean(b); setDirty(true); + setRebuildState(true); } } @@ -859,4 +873,15 @@ public class OutputType extends BuildObject implements IOutputType { public void setVersion(PluginVersionIdentifier version) { // Do nothing } + + public boolean needsRebuild(){ + return rebuildState; + } + + public void setRebuildState(boolean rebuild){ + if(isExtensionElement() && rebuild) + return; + + rebuildState = rebuild; + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java index a9749482531..6c0a0f99fb2 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 Intel Corporation and others. + * Copyright (c) 2005, 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 @@ -407,8 +407,9 @@ public class ResourceChangeHandler implements IResourceChangeListener, ISavePart if(rcCfg != null && !oldPath.equals(newPath)){ config.removeResourceConfiguration(rcCfg); rcCfg.setResourcePath(newPath.toString()); + rcCfg.setRebuildState(true); ((Configuration)config).addResourceConfiguration((ResourceConfiguration)rcCfg); - config.setRebuildState(true); +// config.setRebuildState(true); return true; } return false; @@ -418,7 +419,7 @@ public class ResourceChangeHandler implements IResourceChangeListener, ISavePart IResourceConfiguration rcCfg = config.getResourceConfiguration(path.toString()); if(rcCfg != null){ config.removeResourceConfiguration(rcCfg); - config.setRebuildState(true); +// config.setRebuildState(true); return true; } return false; diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java index 02f52f76fbc..54814e89593 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 Intel Corporation and others. + * Copyright (c) 2005, 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 @@ -21,11 +21,10 @@ 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.IHoldsOptions; -import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler; +import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.ITool; -import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.core.resources.IResource; @@ -52,6 +51,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi private boolean isExtensionResourceConfig = false; private boolean isDirty = false; private boolean resolved = true; + private boolean rebuildState; /* * C O N S T R U C T O R S @@ -128,6 +128,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi isExcluded = new Boolean(false); toolsToInvoke = EMPTY_STRING; rcbsApplicability = new Integer(KIND_DISABLE_RCBS_TOOL); + setRebuildState(true); } /** @@ -203,6 +204,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi } setDirty(true); + setRebuildState(true); } /* @@ -424,6 +426,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi public void addTool(Tool tool) { getToolList().add(tool); getToolMap().put(tool.getId(), tool); + setRebuildState(true); } /* (non-Javadoc) @@ -434,6 +437,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi public void removeTool(ITool tool) { getToolList().remove(tool); getToolMap().remove(tool); + setRebuildState(true); } /* @@ -631,6 +635,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi if (rcbsApplicability == null || !(rcbsApplicability.intValue() == newValue)) { rcbsApplicability = new Integer(newValue); isDirty = true; + setRebuildState(true); } } @@ -641,7 +646,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi if (isExcluded == null || excluded != isExcluded.booleanValue()) { isExcluded = new Boolean(excluded); setDirty(true); - parent.setRebuildState(true); + setRebuildState(true); } } @@ -654,6 +659,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi if (resPath == null || !path.equals(resPath)) { resPath = path; setDirty(true); + setRebuildState(true); } } @@ -770,7 +776,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi retOpt.setValue(value); // TODO: This causes the entire project to be rebuilt. Is there a way to only have this // file rebuilt? "Clean" its output? Change its modification date? - parent.setRebuildState(true); +// parent.setRebuildState(true); } return retOpt; } @@ -786,7 +792,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi retOpt.setValue(value); // TODO: This causes the entire project to be rebuilt. Is there a way to only have this // file rebuilt? "Clean" its output? Change its modification date? - parent.setRebuildState(true); +// parent.setRebuildState(true); } return retOpt; } @@ -823,7 +829,7 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi retOpt.setValue(value); // TODO: This causes the entire project to be rebuilt. Is there a way to only have this // file rebuilt? "Clean" its output? Change its modification date? - parent.setRebuildState(true); +// parent.setRebuildState(true); } return retOpt; } @@ -858,4 +864,38 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi ((Tool)iter.next()).updateManagedBuildRevision(revision); } } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IResourceConfiguration#needsRebuild() + */ + public boolean needsRebuild() { + if(rebuildState) + return true; + + ITool tools[] = getToolsToInvoke(); + for(int i = 0; i < tools.length; i++){ + if(tools[i].needsRebuild()) + return true; + } + + return rebuildState; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IResourceConfiguration#setRebuildState(boolean) + */ + public void setRebuildState(boolean rebuild) { + if(isExtensionResourceConfiguration() && rebuild) + return; + + rebuildState = rebuild; + + if(!rebuildState){ + ITool tools[] = getToolsToInvoke(); + for(int i = 0; i < tools.length; i++){ + tools[i].setRebuildState(false); + } + } + + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java index 36c8dc24405..b955d3cda9d 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java @@ -125,6 +125,7 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { private boolean resolved = resolvedDefault; private IConfigurationElement previousMbsVersionConversionElement = null; private IConfigurationElement currentMbsVersionConversionElement = null; + private boolean rebuildState; /* * C O N S T R U C T O R S @@ -216,6 +217,7 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { ManagedBuildManager.addExtensionTool(this); } else { setDirty(true); + setRebuildState(true); } } @@ -248,6 +250,7 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { ManagedBuildManager.addExtensionTool(this); } else { setDirty(true); + setRebuildState(true); } } @@ -421,6 +424,7 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { } setDirty(true); + setRebuildState(true); } /* @@ -2004,6 +2008,7 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { if (cmd == null || command == null || !cmd.equals(command)) { command = cmd; isDirty = true; + setRebuildState(true); return true; } else { return false; @@ -2017,6 +2022,7 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { if (pattern == null && commandLinePattern == null) return; if (pattern == null || commandLinePattern == null || !pattern.equals(commandLinePattern)) { commandLinePattern = pattern; + setRebuildState(true); isDirty = true; } } @@ -2028,6 +2034,7 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { if (flag == null && outputFlag == null) return; if (outputFlag == null || flag == null || !(flag.equals(outputFlag))) { outputFlag = flag; + setRebuildState(true); isDirty = true; } } @@ -2039,6 +2046,7 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { if (prefix == null && outputPrefix == null) return; if (outputPrefix == null || prefix == null || !(prefix.equals(outputPrefix))) { outputPrefix = prefix; + setRebuildState(true); isDirty = true; } } @@ -2822,4 +2830,58 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { return globalSpecs; } + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.internal.core.HoldsOptions#needsRebuild() + */ + public boolean needsRebuild() { + if(rebuildState) + return true; + + // Check my children + List typeElements = getInputTypeList(); + Iterator iter = typeElements.listIterator(); + while (iter.hasNext()) { + InputType type = (InputType) iter.next(); + if (type.needsRebuild()) return true; + } + typeElements = getOutputTypeList(); + iter = typeElements.listIterator(); + while (iter.hasNext()) { + OutputType type = (OutputType) iter.next(); + if (type.needsRebuild()) return true; + } + + return super.needsRebuild(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.internal.core.HoldsOptions#setRebuildState(boolean) + */ + public void setRebuildState(boolean rebuild) { + if(isExtensionElement() && rebuild) + return; + + rebuildState = rebuild; + + if(!rebuild){ + super.setRebuildState(rebuild); + + if (!rebuild) { + List typeElements = getInputTypeList(); + Iterator iter = typeElements.listIterator(); + while (iter.hasNext()) { + InputType type = (InputType) iter.next(); + type.setRebuildState(false); + } + typeElements = getOutputTypeList(); + iter = typeElements.listIterator(); + while (iter.hasNext()) { + OutputType type = (OutputType) iter.next(); + type.setRebuildState(false); + } + } + } + + + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java index 64de0749ff1..f963c02f86a 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 Intel Corporation and others. + * Copyright (c) 2004, 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 @@ -92,6 +92,7 @@ public class ToolChain extends HoldsOptions implements IToolChain { private IConfigurationElement previousMbsVersionConversionElement = null; private IConfigurationElement currentMbsVersionConversionElement = null; + private boolean rebuildState; /* * C O N S T R U C T O R S @@ -185,6 +186,7 @@ public class ToolChain extends HoldsOptions implements IToolChain { ManagedBuildManager.addExtensionToolChain(this); } else { setDirty(true); + setRebuildState(true); } } @@ -363,6 +365,7 @@ public class ToolChain extends HoldsOptions implements IToolChain { } setDirty(true); + setRebuildState(true); } /* @@ -1727,4 +1730,25 @@ public class ToolChain extends HoldsOptions implements IToolChain { builder.updateManagedBuildRevision(revision); } + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.internal.core.HoldsOptions#needsRebuild() + */ + public boolean needsRebuild() { + if(rebuildState) + return true; + return super.needsRebuild(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.internal.core.HoldsOptions#setRebuildState(boolean) + */ + public void setRebuildState(boolean rebuild) { + if(isExtensionElement() && rebuild) + return; + + rebuildState = rebuild; + + if(!rebuild) + super.setRebuildState(rebuild); + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java index cb150d7e7d8..f3e9eaa2f7b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java @@ -1251,4 +1251,17 @@ public class ToolReference implements IToolReference { public IOption getOptionToSet(IOption option, boolean adjustExtension){ return null; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#needsRebuild() + */ + public boolean needsRebuild() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#setRebuildState(boolean) + */ + public void setRebuildState(boolean rebuild) { + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/UserDefinedEnvironmentSupplier.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/UserDefinedEnvironmentSupplier.java index a68d1f160b1..614bbcadfab 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/UserDefinedEnvironmentSupplier.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/UserDefinedEnvironmentSupplier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 Intel Corporation and others. + * Copyright (c) 2005, 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 @@ -273,12 +273,12 @@ public class UserDefinedEnvironmentSupplier extends if(context == null) return; if(context instanceof IConfiguration){ - ((IConfiguration)context).setRebuildState(true); + cfgVarsModified((IConfiguration)context); } else if(context instanceof IManagedProject){ IConfiguration cfgs[] = ((IManagedProject)context).getConfigurations(); for(int i = 0; i < cfgs.length; i++){ - cfgs[i].setRebuildState(true); + cfgVarsModified(cfgs[i]); } } else if(context instanceof IWorkspace){ @@ -289,7 +289,7 @@ public class UserDefinedEnvironmentSupplier extends if(info != null){ IConfiguration cfgs[] = info.getManagedProject().getConfigurations(); for(int j = 0; j < cfgs.length; j++){ - cfgs[j].setRebuildState(true); + cfgVarsModified(cfgs[j]); } } } @@ -297,6 +297,11 @@ public class UserDefinedEnvironmentSupplier extends } } + + protected void cfgVarsModified(IConfiguration cfg){ + cfg.setRebuildState(true); + EnvironmentVariableProvider.getDefault().checkBuildPathVariables(cfg); + } protected String getValidName(String name){ if(name == null || (name = name.trim()).length() == 0) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/BuildMacroProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/BuildMacroProvider.java index ec1d39ac6f3..116f6886f85 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/BuildMacroProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/BuildMacroProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 Intel Corporation and others. + * Copyright (c) 2005, 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 @@ -334,4 +334,26 @@ public class BuildMacroProvider implements IBuildMacroProvider { public boolean canKeepMacrosInBuildfile(IBuilder builder){ return MacroResolver.canKeepMacrosInBuildfile(builder); } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider#resolveStringListValues(java.lang.String[], java.lang.String, java.lang.String, int, java.lang.Object) + */ + public String[] resolveStringListValues(String[] value, String nonexistentMacrosValue, String listDelimiter, int contextType, Object contextData) throws BuildMacroException { + IMacroContextInfo info = getMacroContextInfo(contextType,contextData); + if(info != null) + return MacroResolver.resolveStringListValues(value, + getMacroSubstitutor(info,nonexistentMacrosValue, listDelimiter), true); + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider#resolveStringListValuesToMakefileFormat(java.lang.String[], java.lang.String, java.lang.String, int, java.lang.Object) + */ + public String[] resolveStringListValuesToMakefileFormat(String[] value, String nonexistentMacrosValue, String listDelimiter, int contextType, Object contextData) throws BuildMacroException { + IMacroContextInfo info = getMacroContextInfo(contextType,contextData); + if(info != null) + return MacroResolver.resolveStringListValues(value, + getBuildfileMacroSubstitutor(info,nonexistentMacrosValue, listDelimiter), true); + return null; + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/macros/IBuildMacroProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/macros/IBuildMacroProvider.java index dc4958c3fa3..137b046c4e8 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/macros/IBuildMacroProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/macros/IBuildMacroProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 Intel Corporation and others. + * Copyright (c) 2005, 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 @@ -114,6 +114,18 @@ public interface IBuildMacroProvider{ int contextType, Object contextData) throws BuildMacroException; + /** + * + * resolves macros in the array of string-list values + * + * @see isStringListValue + */ + public String[] resolveStringListValues(String value[], + String nonexistentMacrosValue, + String listDelimiter, + int contextType, + Object contextData) throws BuildMacroException; + /** * * resolves all macros in the string to the makefile format. That is: @@ -155,6 +167,18 @@ public interface IBuildMacroProvider{ int contextType, Object contextData) throws BuildMacroException; + /** + * resolves macros in the array of string-list values + * macros are resolved to the makefile format + * + * @see isStringListValue + */ + public String[] resolveStringListValuesToMakefileFormat(String value[], + String nonexistentMacrosValue, + String listDelimiter, + int contextType, + Object contextData) throws BuildMacroException; + /** * diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ResourceCustomBuildStepBlock.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ResourceCustomBuildStepBlock.java index ee7b8add7d7..ec68e31df05 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ResourceCustomBuildStepBlock.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ResourceCustomBuildStepBlock.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 Intel Corporation and others. + * Copyright (c) 2005, 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 @@ -510,7 +510,7 @@ public class ResourceCustomBuildStepBlock extends AbstractCOptionPage { } if (rebuildNeeded && !rcbsStillDisabledSoNoRebuild) { - rcConfig.getParent().setRebuildState(true); +// rcConfig.getParent().setRebuildState(true); } setDirty(false); diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ToolsSettingsBlock.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ToolsSettingsBlock.java index e8a64d763ca..fd352c01738 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ToolsSettingsBlock.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ToolsSettingsBlock.java @@ -657,7 +657,7 @@ public class ToolsSettingsBlock extends AbstractCOptionPage { // file rebuilt? "Clean" its output? Change its modification date? //realCfg.setRebuildState(true); //} else { - realCfg.setRebuildState(true); +// realCfg.setRebuildState(true); //} } currentValue = ((ITool)realHo).getCommandLinePattern(); @@ -668,7 +668,7 @@ public class ToolsSettingsBlock extends AbstractCOptionPage { // file rebuilt? "Clean" its output? Change its modification date? //realCfg.setRebuildState(true); //} else { - realCfg.setRebuildState(true); +// realCfg.setRebuildState(true); //} } } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ResourceBuildPropertyPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ResourceBuildPropertyPage.java index d46972252cd..c6d5d138166 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ResourceBuildPropertyPage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ResourceBuildPropertyPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 Intel Corporation and others. + * Copyright (c) 2004, 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 @@ -487,7 +487,7 @@ public class ResourceBuildPropertyPage extends AbstractBuildPropertyPage impleme ManagedBuildManager.setDefaultConfiguration(getProject(), getSelectedConfiguration()); if (getCurrentResourceConfigClone().isDirty()) { - selectedConfiguration.setRebuildState(true); +// selectedConfiguration.setRebuildState(true); getCurrentResourceConfigClone().setDirty(false); }