Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2018-02-08 14:58:26 -0500
committerJeff Johnston2018-02-08 15:03:09 -0500
commitba7f4f26eb8f799d45e40cf84fa68b7857f6df3f (patch)
tree14ba65795fdc36c1bb9e0b86fbffcde6034c42ad /build/org.eclipse.cdt.meson.core
parentdb1cd491d62bf7bfa18eaa82a03f5844c20084af (diff)
downloadorg.eclipse.cdt-ba7f4f26eb8f799d45e40cf84fa68b7857f6df3f.tar.gz
org.eclipse.cdt-ba7f4f26eb8f799d45e40cf84fa68b7857f6df3f.tar.xz
org.eclipse.cdt-ba7f4f26eb8f799d45e40cf84fa68b7857f6df3f.zip
Add Run ninja command context menu item for Meson projects
- add new RunNinjaCommandHandler, RunNinja, AbstractMesonCommandHandler, and RunNinjaPage classes to support running ninja manually with env variables added and options specified - add a new build method to MesonBuildConfiguration which specifies ninja options and environment variables - add SWTImagesFactory for supplying the meson logo image - add WizardMessages class for specifying messages for meson ui wizards - add new MesonUtils class and move stripEnvVars from MesonBuildConfiguration to here - add new constants to IMesonConstants interface Change-Id: I8d635b2bd96792800bb07f4b3f1730be6e41eb24
Diffstat (limited to 'build/org.eclipse.cdt.meson.core')
-rw-r--r--build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/MesonBuildConfiguration.java88
-rw-r--r--build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/MesonUtils.java57
-rw-r--r--build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/Messages.java1
-rw-r--r--build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/messages.properties1
-rw-r--r--build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/meson/core/IMesonConstants.java2
5 files changed, 93 insertions, 56 deletions
diff --git a/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/MesonBuildConfiguration.java b/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/MesonBuildConfiguration.java
index 5be0271507..8a7891da60 100644
--- a/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/MesonBuildConfiguration.java
+++ b/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/MesonBuildConfiguration.java
@@ -17,8 +17,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.eclipse.cdt.core.CommandLauncherManager;
import org.eclipse.cdt.core.ConsoleOutputStream;
@@ -102,8 +100,13 @@ public class MesonBuildConfiguration extends CBuildConfiguration {
@Override
public IProject[] build(int kind, Map<String, String> args, IConsole console, IProgressMonitor monitor)
throws CoreException {
+ return build(kind, args, null, null, console, monitor);
+ }
+
+ public IProject[] build(int kind, Map<String, String> args, String[] ninjaEnv, String[] ninjaArgs, IConsole console, IProgressMonitor monitor)
+ throws CoreException {
IProject project = getProject();
-
+
try {
project.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
@@ -117,7 +120,7 @@ public class MesonBuildConfiguration extends CBuildConfiguration {
if (toolChainFile == null && !isLocal()) {
IMesonToolChainManager manager = Activator.getService(IMesonToolChainManager.class);
toolChainFile = manager.getToolChainFileFor(getToolChain());
-
+
if (toolChainFile == null) {
// error
console.getErrorStream().write(Messages.MesonBuildConfiguration_NoToolchainFile);
@@ -133,12 +136,12 @@ public class MesonBuildConfiguration extends CBuildConfiguration {
}
List<String> argsList = new ArrayList<>();
-
+
String userArgs = getProperty(IMesonConstants.MESON_ARGUMENTS);
if (userArgs != null) {
argsList.addAll(Arrays.asList(userArgs.trim().split("\\s+"))); //$NON-NLS-1$
}
-
+
argsList.add(getBuildDirectory().toString());
Map<String, String> envMap = System.getenv();
@@ -148,25 +151,25 @@ public class MesonBuildConfiguration extends CBuildConfiguration {
}
String envStr = getProperty(IMesonConstants.MESON_ENV);
if (envStr != null) {
- envList.addAll(stripEnvVars(envStr));
+ envList.addAll(MesonUtils.stripEnvVars(envStr));
}
String[] env = envList.toArray(new String[0]);
ICommandLauncher launcher = CommandLauncherManager.getInstance().getCommandLauncher(this);
-
+
launcher.setProject(getProject());
if (launcher instanceof ICBuildCommandLauncher) {
((ICBuildCommandLauncher)launcher).setBuildConfiguration(this);
}
monitor.subTask(Messages.MesonBuildConfiguration_RunningMeson);
-
+
org.eclipse.core.runtime.Path mesonPath = new org.eclipse.core.runtime.Path(path.toString());
outStream.write(String.join(" ", envStr != null ? envStr : "", //$NON-NLS-1$ //$NON-NLS-2$
mesonPath.toString(), userArgs, "\n")); //$NON-NLS-1$
outStream.write(getBuildDirectory() + "\n"); //$NON-NLS-1$
org.eclipse.core.runtime.Path workingDir = new org.eclipse.core.runtime.Path(getBuildDirectory().getParent().getParent().toString());
-
+
launcher.execute(mesonPath, argsList.toArray(new String[0]), env, workingDir, monitor);
if (launcher.waitAndRead(outStream, outStream, SubMonitor.convert(monitor)) != ICommandLauncher.OK) {
String errMsg = launcher.getErrorMessage();
@@ -178,28 +181,39 @@ public class MesonBuildConfiguration extends CBuildConfiguration {
try (ErrorParserManager epm = new ErrorParserManager(project, getBuildDirectoryURI(), this,
getToolChain().getErrorParserIds())) {
epm.setOutputStream(console.getOutputStream());
-
+
String buildCommand = getProperty(IMesonConstants.BUILD_COMMAND);
if (buildCommand == null || buildCommand.isEmpty()) {
buildCommand = "ninja";
}
- String[] env = new String[0];
+ Map<String, String> envMap = System.getenv();
+ List<String> envList = new ArrayList<>();
+ for (Map.Entry<String, String> entry : envMap.entrySet()) {
+ envList.add(entry.getKey() + "=" + entry.getValue());
+ }
+ if (ninjaEnv != null) {
+ envList.addAll(Arrays.asList(ninjaEnv));
+ }
+ String[] env = envList.toArray(new String[0]);
ICommandLauncher launcher = CommandLauncherManager.getInstance().getCommandLauncher(this);
-
+
launcher.setProject(getProject());
if (launcher instanceof ICBuildCommandLauncher) {
((ICBuildCommandLauncher)launcher).setBuildConfiguration(this);
}
- monitor.subTask(Messages.MesonBuildConfiguration_RunningMeson);
-
+ monitor.subTask(Messages.MesonBuildConfiguration_RunningNinja);
+
org.eclipse.core.runtime.Path ninjaPath = new org.eclipse.core.runtime.Path(buildCommand);
- outStream.write(String.join(" ", ninjaPath.toString() + '\n')); //$NON-NLS-1$
org.eclipse.core.runtime.Path workingDir = new org.eclipse.core.runtime.Path(getBuildDirectory().toString());
- launcher.execute(ninjaPath, new String[] {"-v"}, env, workingDir, monitor); //$NON-NLS-1$
+ if (ninjaArgs == null) {
+ ninjaArgs = new String[] {"-v"}; //$NON-NLS-1$
+ }
+
+ launcher.execute(ninjaPath, ninjaArgs, env, workingDir, monitor);
if (launcher.waitAndRead(epm.getOutputStream(), epm.getOutputStream(), SubMonitor.convert(monitor)) != ICommandLauncher.OK) {
String errMsg = launcher.getErrorMessage();
console.getErrorStream().write(String.format(Messages.MesonBuildConfiguration_RunningNinjaFailure, errMsg));
@@ -300,44 +314,6 @@ public class MesonBuildConfiguration extends CBuildConfiguration {
}
}
- /**
- * Strip a command of VAR=VALUE pairs that appear ahead or behind the command and add
- * them to a list of environment variables.
- *
- * @param command - command to strip
- * @param envVars - ArrayList to add environment variables to
- * @return stripped command
- */
- public static List<String> stripEnvVars(String envString) {
- Pattern p1 = Pattern.compile("(\\w+[=]\\\".*?\\\").*"); //$NON-NLS-1$
- Pattern p2 = Pattern.compile("(\\w+[=]'.*?').*"); //$NON-NLS-1$
- Pattern p3 = Pattern.compile("(\\w+[=][^\\s]+).*"); //$NON-NLS-1$
- boolean finished = false;
- List<String> envVars = new ArrayList<>();
- while (!finished) {
- Matcher m1 = p1.matcher(envString);
- if (m1.matches()) {
- envString = envString.replaceFirst("\\w+[=]\\\".*?\\\"","").trim(); //$NON-NLS-1$ //$NON-NLS-2$
- String s = m1.group(1).trim();
- envVars.add(s.replaceAll("\\\"", "")); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- Matcher m2 = p2.matcher(envString);
- if (m2.matches()) {
- envString = envString.replaceFirst("\\w+[=]'.*?'", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
- String s = m2.group(1).trim();
- envVars.add(s.replaceAll("'", "")); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- Matcher m3 = p3.matcher(envString);
- if (m3.matches()) {
- envString = envString.replaceFirst("\\w+[=][^\\s]+", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
- envVars.add(m3.group(1).trim());
- } else {
- finished = true;
- }
- }
- }
- }
- return envVars;
- }
+
}
diff --git a/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/MesonUtils.java b/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/MesonUtils.java
new file mode 100644
index 0000000000..bcde5ca869
--- /dev/null
+++ b/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/MesonUtils.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Red Hat Inc. 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
+ *
+ * Red Hat Inc. - initial version
+ *******************************************************************************/
+package org.eclipse.cdt.internal.meson.core;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class MesonUtils {
+
+ /**
+ * Parse a string containing environment variables into individual VAR=VALUE pairs.
+ *
+ * @param envString - String to parse
+ * @return List of var=value Strings
+ */
+ public static List<String> stripEnvVars(String envString) {
+ Pattern p1 = Pattern.compile("(\\w+[=]\\\".*?\\\").*"); //$NON-NLS-1$
+ Pattern p2 = Pattern.compile("(\\w+[=]'.*?').*"); //$NON-NLS-1$
+ Pattern p3 = Pattern.compile("(\\w+[=][^\\s]+).*"); //$NON-NLS-1$
+ boolean finished = false;
+ List<String> envVars = new ArrayList<>();
+ while (!finished) {
+ Matcher m1 = p1.matcher(envString);
+ if (m1.matches()) {
+ envString = envString.replaceFirst("\\w+[=]\\\".*?\\\"","").trim(); //$NON-NLS-1$ //$NON-NLS-2$
+ String s = m1.group(1).trim();
+ envVars.add(s.replaceAll("\\\"", "")); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ Matcher m2 = p2.matcher(envString);
+ if (m2.matches()) {
+ envString = envString.replaceFirst("\\w+[=]'.*?'", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
+ String s = m2.group(1).trim();
+ envVars.add(s.replaceAll("'", "")); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ Matcher m3 = p3.matcher(envString);
+ if (m3.matches()) {
+ envString = envString.replaceFirst("\\w+[=][^\\s]+", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
+ envVars.add(m3.group(1).trim());
+ } else {
+ finished = true;
+ }
+ }
+ }
+ }
+ return envVars;
+ }
+
+}
diff --git a/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/Messages.java b/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/Messages.java
index e3057822ef..9af99b24a1 100644
--- a/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/Messages.java
+++ b/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/Messages.java
@@ -19,6 +19,7 @@ public class Messages extends NLS {
public static String MesonBuildConfiguration_BuildingComplete;
public static String MesonBuildConfiguration_Cleaning;
public static String MesonBuildConfiguration_RunningMeson;
+ public static String MesonBuildConfiguration_RunningNinja;
public static String MesonBuildConfiguration_RunningMesonFailure;
public static String MesonBuildConfiguration_RunningNinjaFailure;
public static String MesonBuildConfiguration_NoToolchainFile;
diff --git a/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/messages.properties b/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/messages.properties
index 44cdce2949..41116f9713 100644
--- a/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/messages.properties
+++ b/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/messages.properties
@@ -12,6 +12,7 @@ MesonBuildConfiguration_BuildingIn=Building in: %s\n
MesonBuildConfiguration_BuildingComplete=Build complete: %s\n
MesonBuildConfiguration_Cleaning=Cleaning %s
MesonBuildConfiguration_RunningMeson=Running meson
+MesonBuildConfiguration_RunningNinja=Running ninja
MesonBuildConfiguration_ProcCompCmds=Processing compile commands %s
MesonBuildConfiguration_ProcCompJson=Processing compile_commands.json
MesonBuildConfiguration_NoToolchainFile=No toolchain file found for this target.
diff --git a/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/meson/core/IMesonConstants.java b/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/meson/core/IMesonConstants.java
index 696e27f5ee..e2aa905a9b 100644
--- a/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/meson/core/IMesonConstants.java
+++ b/build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/meson/core/IMesonConstants.java
@@ -14,6 +14,8 @@ public interface IMesonConstants {
public static final String MESON_ARGUMENTS = "meson.arguments"; //$NON-NLS-1$
public static final String MESON_ENV = "meson.environment"; //$NON-NLS-1$
+ public static final String NINJA_ENV = "meson.ninja.environment"; //$NON-NLS-1$
+ public static final String NINJA_ARGUMENTS = "meson.ninja.arguments"; //$NON-NLS-1$
public static final String MESON_ENV_SEPARATOR = "|"; //$NON-NLS-1$
String MESON_GENERATOR = "meson.generator"; //$NON-NLS-1$
String BUILD_COMMAND = "meson.command.build"; //$NON-NLS-1$

Back to the top