mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 398353: Environment variables not evaluated in CDT GCC Builtin Compiler Settings
This commit is contained in:
parent
310ad6c995
commit
1d28b9bce9
2 changed files with 41 additions and 0 deletions
|
@ -13,6 +13,8 @@
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
|
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||||
|
@ -102,6 +104,7 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// check ${COMMAND} and ${INPUTS}
|
||||||
MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal();
|
MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal();
|
||||||
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}});
|
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}});
|
||||||
detector.setCommand("${COMMAND} -E -P -v -dD ${INPUTS}");
|
detector.setCommand("${COMMAND} -E -P -v -dD ${INPUTS}");
|
||||||
|
@ -111,6 +114,7 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase {
|
||||||
assertTrue(resolvedCommand.endsWith("spec.c"));
|
assertTrue(resolvedCommand.endsWith("spec.c"));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// check ${EXT}
|
||||||
MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal();
|
MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal();
|
||||||
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}});
|
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}});
|
||||||
detector.setCommand("${COMMAND} -E -P -v -dD file.${EXT}");
|
detector.setCommand("${COMMAND} -E -P -v -dD file.${EXT}");
|
||||||
|
@ -119,6 +123,34 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase {
|
||||||
assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD "));
|
assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD "));
|
||||||
assertTrue(resolvedCommand.endsWith("file.c"));
|
assertTrue(resolvedCommand.endsWith("file.c"));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
// check expansion of environment variables
|
||||||
|
MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal();
|
||||||
|
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}});
|
||||||
|
String command = "cmd --env1=${CWD} --env2=${OS}";
|
||||||
|
detector.setCommand(command);
|
||||||
|
String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C);
|
||||||
|
|
||||||
|
ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager();
|
||||||
|
String expected = varManager.resolveValue(command, "", null, null);
|
||||||
|
// confirm that "expected" expanded
|
||||||
|
assertFalse(command.equals(expected));
|
||||||
|
assertEquals(expected, resolvedCommand);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// check expansion of eclipse and MBS variables
|
||||||
|
MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal();
|
||||||
|
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}});
|
||||||
|
String command = "cmd --eclipse-var=${workspace_loc} --mbs-var=${WorkspaceDirPath}";
|
||||||
|
detector.setCommand(command);
|
||||||
|
String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C);
|
||||||
|
|
||||||
|
ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager();
|
||||||
|
String expected = varManager.resolveValue(command, "", null, null);
|
||||||
|
// confirm that "expected" expanded
|
||||||
|
assertFalse(command.equals(expected));
|
||||||
|
assertEquals(expected, resolvedCommand);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.cdt.core.ICommandLauncher;
|
||||||
import org.eclipse.cdt.core.IConsoleParser;
|
import org.eclipse.cdt.core.IConsoleParser;
|
||||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||||
import org.eclipse.cdt.core.ProblemMarkerInfo;
|
import org.eclipse.cdt.core.ProblemMarkerInfo;
|
||||||
|
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
|
||||||
import org.eclipse.cdt.core.envvar.EnvironmentVariable;
|
import org.eclipse.cdt.core.envvar.EnvironmentVariable;
|
||||||
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
|
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
|
||||||
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
|
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
|
||||||
|
@ -314,6 +315,14 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
|
||||||
if (specFileExt != null)
|
if (specFileExt != null)
|
||||||
cmd = cmd.replace(SPEC_EXT_MACRO, specFileExt);
|
cmd = cmd.replace(SPEC_EXT_MACRO, specFileExt);
|
||||||
}
|
}
|
||||||
|
if (cmd.contains("${")) { //$NON-NLS-1$
|
||||||
|
ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager();
|
||||||
|
try {
|
||||||
|
cmd = varManager.resolveValue(cmd, "", null, currentCfgDescription); //$NON-NLS-1$
|
||||||
|
} catch (Exception e) {
|
||||||
|
ManagedBuilderCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue