From accfa032aa7e4f22b96510709bcaca12525740d7 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Mon, 15 Dec 2014 00:01:13 +0100 Subject: [PATCH] Bug 389536 - NPE in AdditionalInput for projects containing files with custom build-steps. Tools for custom build steps normally don't belong to a tool chain. We assume now that the inputs don't need to be rebuilt rather than provoking a NPE. The actual fix is similiar to the patch added to the mentioned bug originally been created by Piotr Aniola. It has been extended with a test case demonstrating the problem (and the fix). Change-Id: I5f17248cbe8e84779144bb5f1873c5b9456baa16 Signed-off-by: Sebastian Bauer Reviewed-on: https://git.eclipse.org/r/38206 Tested-by: Hudson CI Reviewed-by: Elena Laskavaia --- .../tests/BuildDescriptionModelTests.java | 24 +++++++++++++++++++ .../internal/core/AdditionalInput.java | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) 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 index adf45e6c086..4a1cbdb9860 100644 --- 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 @@ -2368,6 +2368,30 @@ public class BuildDescriptionModelTests extends TestCase { } } + public void testDesRebuildStateWithCustomBuildStep() { + /* This test captures Bug 389536 */ + 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 testYFile = ManagedBuildTestHelper.createFile(project, "test.y"); + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IManagedProject mProj = info.getManagedProject(); + IConfiguration cfg = mProj.getConfigurations()[0]; + + IResourceConfiguration testYCfg = cfg.createResourceConfiguration(testYFile); + ITool bisonTool = testYCfg.createTool(null, "tool.bison", "Bison", false); + bisonTool.setCustomBuildStep(true); + IInputType bisonInputType = bisonTool.createInputType(null, "inputtype.bison", "Bison Inputfiles", false); + bisonInputType.createAdditionalInput(""); + cfg.setRebuildState(false); + assertFalse(cfg.needsRebuild()); + } + private void doTestTool(ITool tool){ IBuildObject obj = tool.getParent(); IConfiguration cfg; 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 e7535c98a39..a38ec593c2a 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 @@ -342,7 +342,8 @@ public class AdditionalInput implements IAdditionalInput { || fKind.intValue() == IAdditionalInput.KIND_ADDITIONAL_INPUT_DEPENDENCY || isLibrariesInput()) { IToolChain toolChain = getToolChain(); - if (!toolChain.isExtensionElement()) { + /* toolChain can be null e.g. in tools for custom build steps */ + if (toolChain != null && !toolChain.isExtensionElement()) { long artifactTimeStamp = getArtifactTimeStamp(toolChain); if (0 != artifactTimeStamp) { String[] paths = getPaths();