mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Bug 532917 - env vars in Meson properties causes failures to occur
- fix MesonBuildConfiguration to check if any environment variables have been specified in properties page and if so, to change the command to run /usr/bin/env ENVVARS /bin/sh -c "meson ..." - using env will cause the current env to be used (both locally and in a Container where the env has been set up) and modify it according to what the user specifies Change-Id: Ide3997cf78edf65857dea3119f0a9d71679cfe68
This commit is contained in:
parent
ebab079cbf
commit
407352736a
1 changed files with 16 additions and 12 deletions
|
@ -17,6 +17,8 @@ import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CommandLauncherManager;
|
import org.eclipse.cdt.core.CommandLauncherManager;
|
||||||
import org.eclipse.cdt.core.ConsoleOutputStream;
|
import org.eclipse.cdt.core.ConsoleOutputStream;
|
||||||
|
@ -138,8 +140,18 @@ public class MesonBuildConfiguration extends CBuildConfiguration {
|
||||||
|
|
||||||
boolean runMeson = !Files.exists(buildDir.resolve("build.ninja")); //$NON-NLS-1$
|
boolean runMeson = !Files.exists(buildDir.resolve("build.ninja")); //$NON-NLS-1$
|
||||||
if (runMeson) { // $NON-NLS-1$
|
if (runMeson) { // $NON-NLS-1$
|
||||||
|
org.eclipse.core.runtime.Path cmdPath = new org.eclipse.core.runtime.Path("/bin/sh"); //$NON-NLS-1$
|
||||||
|
|
||||||
List<String> argsList = new ArrayList<>();
|
List<String> argsList = new ArrayList<>();
|
||||||
|
|
||||||
|
// if we have env variables, use "env" command with modifications specified after to
|
||||||
|
// add to environment without replacing it (e.g. losing default path)
|
||||||
|
String envStr = getProperty(IMesonConstants.MESON_ENV);
|
||||||
|
if (envStr != null) {
|
||||||
|
cmdPath = new org.eclipse.core.runtime.Path("/usr/bin/env"); //$NON-NLS-1$
|
||||||
|
argsList.addAll(MesonUtils.stripEnvVars(envStr));
|
||||||
|
argsList.add("/bin/sh"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
argsList.add("-c"); //$NON-NLS-1$
|
argsList.add("-c"); //$NON-NLS-1$
|
||||||
|
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
|
@ -159,13 +171,6 @@ public class MesonBuildConfiguration extends CBuildConfiguration {
|
||||||
b.append(getBuildDirectory().toString());
|
b.append(getBuildDirectory().toString());
|
||||||
argsList.add(b.toString());
|
argsList.add(b.toString());
|
||||||
|
|
||||||
List<String> envList = new ArrayList<>();
|
|
||||||
String envStr = getProperty(IMesonConstants.MESON_ENV);
|
|
||||||
if (envStr != null) {
|
|
||||||
envList.addAll(MesonUtils.stripEnvVars(envStr));
|
|
||||||
}
|
|
||||||
String[] env = envList.toArray(new String[0]);
|
|
||||||
|
|
||||||
ICommandLauncher launcher = CommandLauncherManager.getInstance().getCommandLauncher(this);
|
ICommandLauncher launcher = CommandLauncherManager.getInstance().getCommandLauncher(this);
|
||||||
|
|
||||||
launcher.setProject(getProject());
|
launcher.setProject(getProject());
|
||||||
|
@ -175,12 +180,11 @@ public class MesonBuildConfiguration extends CBuildConfiguration {
|
||||||
|
|
||||||
monitor.subTask(Messages.MesonBuildConfiguration_RunningMeson);
|
monitor.subTask(Messages.MesonBuildConfiguration_RunningMeson);
|
||||||
|
|
||||||
org.eclipse.core.runtime.Path shPath = new org.eclipse.core.runtime.Path("/bin/sh"); //$NON-NLS-1$
|
outStream.write(String.join(" ", envStr != null ? ("env " + envStr) : "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
outStream.write(String.join(" ", envStr != null ? envStr : "", //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
"sh -c \"meson", userArgs != null ? userArgs : "", projOptions != null ? projOptions : "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
"sh -c \"meson", userArgs != null ? userArgs : "", projOptions != null ? projOptions : "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
getBuildDirectory().getParent().getParent().toString() + "\"\n")); //$NON-NLS-1$
|
getBuildDirectory().getParent().getParent().toString() + "\"\n")); //$NON-NLS-1$
|
||||||
org.eclipse.core.runtime.Path workingDir = new org.eclipse.core.runtime.Path(getBuildDirectory().getParent().getParent().toString());
|
org.eclipse.core.runtime.Path workingDir = new org.eclipse.core.runtime.Path(getBuildDirectory().getParent().getParent().toString());
|
||||||
Process p = launcher.execute(shPath, argsList.toArray(new String[0]), env, workingDir, monitor);
|
Process p = launcher.execute(cmdPath, argsList.toArray(new String[0]), new String[0], workingDir, monitor);
|
||||||
if (p == null || launcher.waitAndRead(outStream, outStream, SubMonitor.convert(monitor)) != ICommandLauncher.OK) {
|
if (p == null || launcher.waitAndRead(outStream, outStream, SubMonitor.convert(monitor)) != ICommandLauncher.OK) {
|
||||||
String errMsg = p == null ? "" : launcher.getErrorMessage(); //$NON-NLS-1$
|
String errMsg = p == null ? "" : launcher.getErrorMessage(); //$NON-NLS-1$
|
||||||
console.getErrorStream().write(String.format(Messages.MesonBuildConfiguration_RunningMesonFailure, errMsg));
|
console.getErrorStream().write(String.format(Messages.MesonBuildConfiguration_RunningMesonFailure, errMsg));
|
||||||
|
|
Loading…
Add table
Reference in a new issue