Skip to content

Commit 682a3c5

Browse files
author
jantje
committed
#1268 put the codan parsing command in the environment variables
This reduces the number of calls on SloeberProject It also forces the environment variable provider to get the envars if not yet available Something which I think is good
1 parent b078709 commit 682a3c5

File tree

4 files changed

+50
-46
lines changed

4 files changed

+50
-46
lines changed

io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
204204
}
205205

206206

207+
@SuppressWarnings("nls")
207208
private HashMap<String, String> getEnvVars(ICConfigurationDescription confDesc) {
208209
IProject project = confDesc.getProjectDescription().getProject();
209210

@@ -225,23 +226,29 @@ private HashMap<String, String> getEnvVars(ICConfigurationDescription confDesc)
225226
allVars.putAll(otherOptions.getEnvVars());
226227
}
227228
// set the paths
228-
String pathDelimiter = makeEnvironmentVar("PathDelimiter"); //$NON-NLS-1$
229+
String pathDelimiter = makeEnvironmentVar("PathDelimiter");
229230
if (Common.isWindows) {
230231
allVars.put(SLOEBER_MAKE_LOCATION,
231232
ConfigurationPreferences.getMakePath().addTrailingSeparator().toOSString());
232-
String systemroot = makeEnvironmentVar("SystemRoot"); //$NON-NLS-1$
233-
allVars.put("PATH", //$NON-NLS-1$
233+
String systemroot = makeEnvironmentVar("SystemRoot");
234+
allVars.put("PATH",
234235
makeEnvironmentVar(ENV_KEY_COMPILER_PATH) + pathDelimiter
235-
+ makeEnvironmentVar(ENV_KEY_BUILD_GENERIC_PATH) + pathDelimiter + systemroot + "\\system32" //$NON-NLS-1$
236-
+ pathDelimiter + systemroot + pathDelimiter + systemroot + "\\system32\\Wbem" //$NON-NLS-1$
237-
+ pathDelimiter + makeEnvironmentVar("sloeber_path_extension")); //$NON-NLS-1$
236+
+ makeEnvironmentVar(ENV_KEY_BUILD_GENERIC_PATH) + pathDelimiter + systemroot + "\\system32"
237+
+ pathDelimiter + systemroot + pathDelimiter + systemroot + "\\system32\\Wbem"
238+
+ pathDelimiter + makeEnvironmentVar("sloeber_path_extension"));
238239
} else {
239-
allVars.put("PATH", //$NON-NLS-1$
240+
allVars.put("PATH",
240241
makeEnvironmentVar(ENV_KEY_COMPILER_PATH) + pathDelimiter
241242
+ makeEnvironmentVar(ENV_KEY_BUILD_GENERIC_PATH) + pathDelimiter
242-
+ makeEnvironmentVar("PATH")); //$NON-NLS-1$
243+
+ makeEnvironmentVar("PATH"));
243244
}
244245

246+
// Set the codeAnalyzer compile commands
247+
allVars.put(CODAN_C_to_O,
248+
"${recipe.c.o.pattern.1} -D__IN_ECLIPSE__=1 ${recipe.c.o.pattern.2} ${recipe.c.o.pattern.3} ${sloeber.extra.compile} ${sloeber.extra.c.compile} ${sloeber.extra.all}");
249+
allVars.put(CODAN_CPP_to_O,
250+
"${recipe.cpp.o.pattern.1} -D__IN_ECLIPSE__=1 -x c++ ${recipe.cpp.o.pattern.2} ${recipe.cpp.o.pattern.3} ${sloeber.extra.compile} ${sloeber.extra.cpp.compile} ${sloeber.extra.all}");
251+
245252
return allVars;
246253
}
247254

io.sloeber.core/src/io/sloeber/core/common/Const.java

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public class Const {
104104
public static final String RECIPE_AR = RECIPE + DOT + "ar" + DOT + PATTERN;
105105
public static final String RECIPE_C_COMBINE = RECIPE + DOT + "c.combine" + DOT + PATTERN;
106106

107+
public static final String CODAN = "CODAN";
108+
public static final String CODAN_C_to_O = RECIPE + DOT + "c.o" + DOT + CODAN;
109+
public static final String CODAN_CPP_to_O = RECIPE + DOT + "cpp.o" + DOT + CODAN;
110+
107111
public static final String SLOEBER_OBJCOPY = ENV_KEY_SLOEBER_START + "objcopy";
108112

109113

io.sloeber.core/src/io/sloeber/core/toolchain/ArduinoLanguageProvider.java

+10-28
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
99
import org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector;
1010

11-
import io.sloeber.core.api.CompileDescription;
12-
import io.sloeber.core.api.SloeberProject;
1311
import io.sloeber.core.common.Const;
1412

1513
@SuppressWarnings({"nls","unused"})
@@ -19,48 +17,32 @@ public class ArduinoLanguageProvider extends GCCBuiltinSpecsDetector{
1917

2018
@Override
2119
protected String getCompilerCommand(String languageId) {
22-
String compilerCommand = new String();
20+
String ret = new String();
2321

2422
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(currentProject);
2523
if (prjDesc == null)
26-
return compilerCommand;
27-
28-
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
24+
return ret;
2925
ICConfigurationDescription confDesc = prjDesc.getActiveConfiguration();
30-
SloeberProject sloeberProject = SloeberProject.getSloeberProject(currentProject);
31-
CompileDescription compileOptions = sloeberProject.getCompileDescription(confDesc, false);
32-
if (compileOptions == null) {
33-
compileOptions = new CompileDescription();
34-
}
35-
36-
String recipeKey = new String();
37-
String extraOptions = new String();
3826

27+
String codanVarName = new String();
3928
if (languageId.equals("org.eclipse.cdt.core.gcc")) {
40-
recipeKey = Const.RECIPE_C_to_O;
41-
extraOptions = compileOptions.get_C_CompileOptions();
29+
codanVarName = Const.CODAN_C_to_O;
4230
} else if (languageId.equals("org.eclipse.cdt.core.g++")) {
43-
recipeKey = Const.RECIPE_CPP_to_O;
44-
extraOptions = compileOptions.get_CPP_CompileOptions();
31+
codanVarName = Const.CODAN_CPP_to_O;
4532
} else {
4633
ManagedBuilderCorePlugin.error(
4734
"Unable to find compiler command for language " + languageId + " in toolchain=" + getToolchainId());
4835
}
49-
extraOptions = extraOptions + " " + compileOptions.get_C_andCPP_CompileOptions() + " "
50-
+ compileOptions.get_All_CompileOptions();
36+
5137
try {
52-
compilerCommand = envManager.getVariable(recipeKey + Const.DOT + "1", confDesc, false).getValue();
53-
compilerCommand = compilerCommand
54-
+ envManager.getVariable(recipeKey + Const.DOT + "2", confDesc, false).getValue();
55-
compilerCommand = compilerCommand
56-
+ envManager.getVariable(recipeKey + Const.DOT + "3", confDesc, false).getValue();
38+
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
39+
ret = envManager.getVariable(codanVarName, confDesc, false).getValue();
5740
} catch (Exception e) {
58-
compilerCommand = new String();
41+
ret = new String();
5942
}
6043

61-
compilerCommand = compilerCommand + ' ' + extraOptions;
6244

63-
return compilerCommand.replace(" -o ", " ");
45+
return ret;
6446
}
6547

6648
}

io.sloeber.core/src/io/sloeber/core/toolchain/SloeberConfigurationVariableSupplier.java

+21-10
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
import java.util.Map;
55
import java.util.Map.Entry;
66

7+
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
8+
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
79
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
10+
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
811
import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
912
import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
1013
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
14+
import org.eclipse.core.resources.IProject;
1115

1216
import io.sloeber.core.api.PackageManager;
17+
import io.sloeber.core.api.SloeberProject;
1318

1419
public class SloeberConfigurationVariableSupplier implements IConfigurationEnvironmentVariableSupplier {
1520
// variables per configuration
@@ -18,19 +23,13 @@ public class SloeberConfigurationVariableSupplier implements IConfigurationEnvir
1823
@Override
1924
public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration configuration,
2025
IEnvironmentVariableProvider provider) {
26+
initializeIfNotYetDone(configuration);
2127
Map<String, String> curConfigVars = myConfigValues.get(configuration.getName());
2228
if (null == curConfigVars) {
2329
return null;
24-
// maybe the project is not yet loaded by Sloeber.
25-
// try to load and retry
26-
// ICConfigurationDescription confDesc =
27-
// ManagedBuildManager.getDescriptionForConfiguration(configuration);
28-
// IProject project = confDesc.getProjectDescription().getProject();
29-
// ArduinoProjectDescription.getArduinoProjectDescription(project);
30-
// curConfigVars = myValues.get(configuration.getName());
31-
// if (null == curConfigVars) {
32-
// return null;
33-
// }
30+
// This should only happen if a config is existing Sloeber does not know about
31+
// because we configured the sloeber project above
32+
// So this should not happen
3433
}
3534
String ret = curConfigVars.get(variableName);
3635
if (ret == null) {
@@ -46,6 +45,7 @@ public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration
4645
@Override
4746
public IBuildEnvironmentVariable[] getVariables(IConfiguration configuration,
4847
IEnvironmentVariableProvider provider) {
48+
initializeIfNotYetDone(configuration);
4949
Map<String, String> retVars = new HashMap<>();
5050
Map<String, String> workbenchVars = PackageManager.getEnvironmentVariables();
5151
if (workbenchVars != null) {
@@ -68,4 +68,15 @@ public IBuildEnvironmentVariable[] getVariables(IConfiguration configuration,
6868
public void setEnvVars(IConfiguration configuration, Map<String, String> values) {
6969
myConfigValues.put(configuration.getName(), values);
7070
}
71+
72+
private void initializeIfNotYetDone(IConfiguration configuration) {
73+
if (!myConfigValues.isEmpty()) {
74+
// we have some data; asume it is correct
75+
return;
76+
}
77+
ICConfigurationDescription confDesc = ManagedBuildManager.getDescriptionForConfiguration(configuration);
78+
ICProjectDescription projDesc = confDesc.getProjectDescription();
79+
IProject project = projDesc.getProject();
80+
SloeberProject.getSloeberProject(project, false);
81+
}
7182
}

0 commit comments

Comments
 (0)