From 3929a1fc8031b6d1fdb034da1b30731bf1a97c11 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Thu, 3 May 2018 14:35:47 -0400 Subject: [PATCH] Add dynamic variable for build directory of active core build config This will allow us to use that value in external tool launches such as those used by the Serial Flash launch configuration. Also removal of the missing src source folder entry in meson.ui.editor. Change-Id: I1033bdc0c18c9822490a9b8602cef83a42f7262d --- .../.classpath | 1 - .../.settings/.api_filters | 142 +++++++++--------- core/org.eclipse.cdt.core/plugin.properties | 1 + core/org.eclipse.cdt.core/plugin.xml | 6 + .../cdt/core/build/CBuildConfiguration.java | 1 + .../cdt/core/build/ICBuildConfiguration2.java | 9 ++ .../core/build/CBuildDirectoryResolver.java | 55 +++++++ 7 files changed, 143 insertions(+), 72 deletions(-) create mode 100644 core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildDirectoryResolver.java diff --git a/build/org.eclipse.cdt.meson.ui.editor/.classpath b/build/org.eclipse.cdt.meson.ui.editor/.classpath index eca7bdba8f0..075009d7745 100644 --- a/build/org.eclipse.cdt.meson.ui.editor/.classpath +++ b/build/org.eclipse.cdt.meson.ui.editor/.classpath @@ -2,6 +2,5 @@ - diff --git a/core/org.eclipse.cdt.core/.settings/.api_filters b/core/org.eclipse.cdt.core/.settings/.api_filters index 23a1d1aab40..98ebe057151 100644 --- a/core/org.eclipse.cdt.core/.settings/.api_filters +++ b/core/org.eclipse.cdt.core/.settings/.api_filters @@ -1,71 +1,71 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/org.eclipse.cdt.core/plugin.properties b/core/org.eclipse.cdt.core/plugin.properties index 4f50e819b40..cfc68c22f90 100755 --- a/core/org.eclipse.cdt.core/plugin.properties +++ b/core/org.eclipse.cdt.core/plugin.properties @@ -95,6 +95,7 @@ binaryFileName=Binary File cdt_pathentry_var.description=CDT PathEntry variable config_name_var.description=The name of the active configuration for the project specified as an argument config_description_var.description=The description of the active configuration for the project specified as an argument +core_build_dir.description=The build directory for the active Core Build configuration for the given project PDOMProviderName=PDOM Provider diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml index 297d15424d6..a2c915f60c8 100644 --- a/core/org.eclipse.cdt.core/plugin.xml +++ b/core/org.eclipse.cdt.core/plugin.xml @@ -608,6 +608,12 @@ resolver="org.eclipse.cdt.internal.core.PathEntryVariableResolver" description="%cdt_pathentry_var.description"> + + diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java index c78536658ee..bc2e24cd2e7 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java @@ -236,6 +236,7 @@ public abstract class CBuildConfiguration extends PlatformObject return buildFolder; } + @Override public URI getBuildDirectoryURI() throws CoreException { return getBuildContainer().getLocationURI(); } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ICBuildConfiguration2.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ICBuildConfiguration2.java index 9471777548d..763e0d88a22 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ICBuildConfiguration2.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ICBuildConfiguration2.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.cdt.core.build; +import java.net.URI; + +import org.eclipse.core.runtime.CoreException; + /** * @since 6.5 */ @@ -20,4 +24,9 @@ public interface ICBuildConfiguration2 { */ void setActive(); + /** + * The URI for the directory in which the build is executed. + */ + URI getBuildDirectoryURI() throws CoreException; + } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildDirectoryResolver.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildDirectoryResolver.java new file mode 100644 index 00000000000..7c5d3cf8c22 --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildDirectoryResolver.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2018 QNX Software Systems 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 + *******************************************************************************/ +package org.eclipse.cdt.internal.core.build; + +import java.io.File; +import java.net.URI; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.build.ICBuildConfiguration; +import org.eclipse.cdt.core.build.ICBuildConfiguration2; +import org.eclipse.cdt.core.build.ICBuildConfigurationManager; +import org.eclipse.core.resources.IBuildConfiguration; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.variables.IDynamicVariable; +import org.eclipse.core.variables.IDynamicVariableResolver; + +public class CBuildDirectoryResolver implements IDynamicVariableResolver { + + @Override + public String resolveValue(IDynamicVariable variable, String argument) throws CoreException { + if (argument == null || argument.isEmpty()) { + return null; + } + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(argument); + if (project == null || !project.exists()) { + return null; + } + + IBuildConfiguration config = project.getActiveBuildConfig(); + + ICBuildConfigurationManager manager = CCorePlugin.getService(ICBuildConfigurationManager.class); + ICBuildConfiguration coreConfig = manager.getBuildConfiguration(config); + if (coreConfig == null) { + return null; + } + + if (coreConfig instanceof ICBuildConfiguration2) { + URI uri = ((ICBuildConfiguration2) coreConfig).getBuildDirectoryURI(); + if (uri != null) { + return new File(uri).getAbsolutePath(); + } + } + + return null; + } + +}