1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

Fix handling of exported bash functions in environment

This commit is contained in:
Anton Leherbauer 2015-12-16 09:34:00 +01:00
parent 44f0083f72
commit e7939cc360

View file

@ -78,8 +78,10 @@ public class Env {
// The full provided variable in form "name=value" // The full provided variable in form "name=value"
String envpPart = envp[i]; String envpPart = envp[i];
// Split the variable // Split the variable
String[] parts = envpPart.split("=");//$NON-NLS-1$ int eqIdx = envpPart.indexOf('=');
String name = parts[0].trim(); if (eqIdx < 1)
continue;
String name = envpPart.substring(0, eqIdx);
// Map the variable name to the real environment name (Windows only) // Map the variable name to the real environment name (Windows only)
if (Platform.OS_WIN32.equals(Platform.getOS())) { if (Platform.OS_WIN32.equals(Platform.getOS())) {
if (k2n.containsKey(name.toLowerCase())) { if (k2n.containsKey(name.toLowerCase())) {
@ -88,12 +90,12 @@ public class Env {
name = candidate; name = candidate;
} }
// Filter out environment variables with bad names // Filter out environment variables with bad names
if ("".equals(name.trim()) || name.contains("=") || name.contains(":")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if ("".equals(name.trim()) || name.contains(":")) { //$NON-NLS-1$ //$NON-NLS-2$
continue; continue;
} }
} }
// Get the variable value // Get the variable value
String value = parts.length > 1 ? parts[1].trim() : ""; //$NON-NLS-1$ String value = envpPart.substring(eqIdx+1);
// Don't overwrite the TERM variable if in terminal mode // Don't overwrite the TERM variable if in terminal mode
if (terminal && "TERM".equals(name)) continue; //$NON-NLS-1$ if (terminal && "TERM".equals(name)) continue; //$NON-NLS-1$
// If a variable with the name does not exist, just append it // If a variable with the name does not exist, just append it
@ -172,21 +174,22 @@ public class Env {
BufferedReader reader = new BufferedReader(isreader); BufferedReader reader = new BufferedReader(isreader);
try { try {
String line = reader.readLine(); String line = reader.readLine();
String key = null;
String value = null;
while (line != null) { while (line != null) {
String key = null;
String value = null;
int func = line.indexOf("=()"); //$NON-NLS-1$ int func = line.indexOf("=()"); //$NON-NLS-1$
if (func > 0) { if (func > 0) {
key = line.substring(0, func); key = line.substring(0, func);
// scan until we find the closing '}' with no following chars // scan until we find the closing '}' with no following chars
value = "'" + line.substring(func + 1); //$NON-NLS-1$ value = line.substring(func + 1);
while (line != null && !line.equals("}")) { //$NON-NLS-1$ do {
line = reader.readLine(); line = reader.readLine();
if (line != null) { if (line == null)
value += " " + line; //$NON-NLS-1$ break;
} if (line.equals("}")) //$NON-NLS-1$
} value += ';';
value += "'"; //$NON-NLS-1$ value += ' ' + line;
} while (!line.equals("}")); //$NON-NLS-1$
line = reader.readLine(); line = reader.readLine();
} else { } else {
int separator = line.indexOf('='); int separator = line.indexOf('=');
@ -214,8 +217,6 @@ public class Env {
} }
if (key != null) { if (key != null) {
cache.put(key, value); cache.put(key, value);
key = null;
value = null;
} else { } else {
line = reader.readLine(); line = reader.readLine();
} }