Skip to content

Commit 8b6e31b

Browse files
authored
Merge pull request #82 from Locutus18/refactor
Moved the project subshell initialization values from CcConfiguration
2 parents b337e8d + d530c73 commit 8b6e31b

File tree

3 files changed

+26
-35
lines changed

3 files changed

+26
-35
lines changed

eclipse-plugin/eclipse/cc.codechecker.eclipse.plugin/src/cc/codechecker/plugin/config/CcConfiguration.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,43 +64,18 @@ public CcConfiguration(IProject project) {
6464
}
6565
}
6666

67-
public void modifyProjectEnvironmentVariables(final IProject project, final File dir, final String location) {
67+
public void modifyProjectEnvironmentVariables(final IProject project, final Map<String, String> environmentAdd) {
6868
IContributedEnvironment ice = CCorePlugin.getDefault().getBuildEnvironmentManager()
6969
.getContributedEnvironment();
7070
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(project, true);
7171
ICConfigurationDescription cfgd = prjd.getActiveConfiguration();
72-
boolean pythonEnvPresent;
73-
if(getGlobal()) {
74-
pythonEnvPresent = getGlobalPythonEnv().isPresent();
75-
} else {
76-
pythonEnvPresent = getProjectPythonEnv().isPresent();
77-
}
78-
Map<String, String> environmentAdd = new HashMap<String, String>(){{
79-
put("LD_LIBRARY_PATH", location + "/ld_logger/lib");
80-
put("_", location + "/bin/CodeChecker");
81-
put("CC_LOGGER_GCC_LIKE", "gcc:g++:clang:cc:c++");
82-
put("LD_PRELOAD","ldlogger.so");
83-
put("CC_LOGGER_FILE", dir.toString() + "/" + project.getName() + "/compilation_commands.json.javarunner");
84-
put("CC_LOGGER_BIN", location + "/bin/ldlogger");
85-
}};
86-
if(pythonEnvPresent) {
87-
String pythonEnvironment;
88-
if(getGlobal()) {
89-
pythonEnvironment = getGlobalPythonEnv().get();
90-
} else {
91-
pythonEnvironment = getProjectPythonEnv().get();
92-
}
93-
environmentAdd.put("PATH", pythonEnvironment + "/bin:");
94-
environmentAdd.put("VIRTUAL_ENV", pythonEnvironment);
95-
}
9672
for(String key : environmentAdd.keySet()) {
9773
if(key.equals("PATH")) {
9874
ice.addVariable(key, environmentAdd.get(key), IEnvironmentVariable.ENVVAR_PREPEND,"", cfgd);
9975
} else {
10076
ice.addVariable(key, environmentAdd.get(key), IEnvironmentVariable.ENVVAR_REPLACE,"", cfgd);
10177
}
10278
}
103-
10479
try {
10580
CoreModel.getDefault().setProjectDescription(project, prjd);
10681
} catch (CoreException e) {
@@ -251,7 +226,7 @@ public void updateServer(IProject project, CodecheckerServerThread server) {
251226

252227
server.setCodecheckerEnvironment(ccec);
253228

254-
modifyProjectEnvironmentVariables(project, dir, location);
229+
modifyProjectEnvironmentVariables(project, ccec.environmentAddList);
255230
ConsoleFactory.consoleWrite(project.getName() + ": Started server for project (port: "+ server.serverPort + ")");
256231
} catch (Exception e) {
257232
ConsoleFactory.consoleWrite(project.getName() + ": Failed to start server");

eclipse-plugin/eclipse/cc.codechecker.eclipse.plugin/src/cc/codechecker/plugin/config/CodeCheckerContext.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public synchronized CodecheckerServerThread getServerObject(final IProject proje
182182

183183
@Override
184184
public void built() {
185-
cleanCache(project);
185+
cleanCache();
186186
Display.getDefault().asyncExec(new Runnable() {
187187
@Override
188188
public void run() {
@@ -200,10 +200,8 @@ public void run() {
200200

201201
/**
202202
* Clean cache.
203-
*
204-
* @param project the project, the user change his/her view to
205203
*/
206-
public void cleanCache(IProject project) {
204+
public void cleanCache() {
207205
jobRunner.getActionCacheFilter().removeAll();
208206
logger.log(Level.DEBUG, "SERVER_GUI_MSG >> CLEARING CACHE");
209207
}

eclipse-plugin/service/cc.codechecker.service.api/src/main/java/cc/codechecker/api/runtime/CodeCheckEnvironmentChecker.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cc.codechecker.api.runtime;
22

33
import com.google.common.base.Optional;
4-
import com.google.common.collect.ImmutableList;
54
import com.google.common.collect.ImmutableMap;
65

76
import org.apache.log4j.Logger;
@@ -10,6 +9,8 @@
109

1110
import java.io.File;
1211
import java.io.IOException;
12+
import java.util.HashMap;
13+
import java.util.Map;
1314
import java.util.Objects;
1415
import java.lang.Math;
1516

@@ -27,8 +28,10 @@ public class CodeCheckEnvironmentChecker {
2728
// can be used to run CodeChecker
2829
public final ImmutableMap<String, String> environmentDuringChecks; // this can be added to
2930

30-
public CodeCheckEnvironmentChecker(Optional<String> pythonEnvironment,
31-
String codeCheckerParameter, String workspaceName, String checkerCommand) {
31+
public Map<String, String> environmentAddList;
32+
33+
public CodeCheckEnvironmentChecker(Optional<String> pythonEnvironment, final String codeCheckerParameter,
34+
final String workspaceName, String checkerCommand) {
3235
this.pythonEnvironment = pythonEnvironment;
3336
this.codeCheckerParameter = codeCheckerParameter;
3437
this.workspaceName = workspaceName;
@@ -39,6 +42,21 @@ public CodeCheckEnvironmentChecker(Optional<String> pythonEnvironment,
3942

4043
environmentDuringChecks = modifyLogfileName(getCheckerEnvironment(environmentBefore,
4144
codeCheckerCommand, workspaceName));
45+
46+
environmentAddList = new HashMap<String, String>(){{
47+
put("LD_LIBRARY_PATH", codeCheckerParameter + "/ld_logger/lib");
48+
put("_", codeCheckerParameter + "/bin/CodeChecker");
49+
put("CC_LOGGER_GCC_LIKE", "gcc:g++:clang:clang++:cc:c++");
50+
put("LD_PRELOAD","ldlogger.so");
51+
put("CC_LOGGER_FILE", workspaceName + "/compilation_commands.json.javarunner");
52+
put("CC_LOGGER_BIN", codeCheckerParameter + "/bin/ldlogger");
53+
}};
54+
55+
if(pythonEnvironment.isPresent()) {
56+
String pythonEnv = pythonEnvironment.get();
57+
environmentAddList.put("PATH", pythonEnv + "/bin:");
58+
environmentAddList.put("VIRTUAL_ENV", pythonEnv);
59+
}
4260
}
4361

4462
private static ImmutableMap<String, String> getCheckerEnvironment(
@@ -116,7 +134,7 @@ public void setCheckerCommand(String checkerCommand) {
116134
}
117135

118136
public String getLogFileLocation() {
119-
return environmentDuringChecks.get("CC_LOGGER_FILE"); // hackis ...
137+
return workspaceName + "/compilation_commands.json.javarunner";
120138
}
121139

122140
// renames the logfile, to avoid concurrency issues

0 commit comments

Comments
 (0)