@Override
public void compile(CompileContext context, Chunk<Module> moduleChunk, VirtualFile[] files, OutputSink outputSink) {
context.getProgressIndicator().pushState();
context.getProgressIndicator().setText("Hardcore compile action...");
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.setWorkDirectory(PathUtil.getParentPath(context.getProject().getProjectFilePath()));
commandLine.setPassParentEnvironment(true);
for (Module module : moduleChunk.getNodes()) {
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
for (VirtualFile sourceRoot : moduleRootManager.getSourceRoots()) {
commandLine.addParameter("-I");
String path = sourceRoot.getCanonicalPath();
if (path != null) {
commandLine.addParameter(path);
}
}
VirtualFile outDir = context.getModuleOutputDirectory(module);
if (outDir == null) {
context.addMessage(CompilerMessageCategory.ERROR, "No output dir for module: " + module.getName(), null, -1, -1);
return;
}
commandLine.setWorkDirectory(outDir.getCanonicalPath());
for (VirtualFile o : files) {
String canonicalPath = o.getCanonicalPath();
if (canonicalPath == null) continue;
commandLine.addParameter(canonicalPath);
}
// commandLine.addParameters("+warn_unused_vars", "+nowarn_shadow_vars", "+warn_unused_import");
Sdk sdk = moduleRootManager.getSdk();
if (sdk == null) {
context.addMessage(CompilerMessageCategory.ERROR, "No SDK for module: " + module.getName(), null, -1, -1);
return;
}
if (sdk.getSdkType() != ErlangSdkType.getInstance()) {
context.addMessage(CompilerMessageCategory.ERROR, "Not a Erlang SDK for module: " + module.getName(), null, -1, -1);
return;
}
String sdkHomePath = sdk.getHomePath();
if (sdkHomePath == null) {
context.addMessage(CompilerMessageCategory.ERROR, "No home path for Erlang SDK: " + sdk.getName(), null, -1, -1);
return;
}
String erlc = FileUtil.toSystemDependentName(JpsErlangSdkType.getByteCodeCompilerExecutable(sdkHomePath).getAbsolutePath());
commandLine.setExePath(erlc);
// System.out.println(commandLine.getCommandLineString());
ProcessOutput output = null;
try {
output = new CapturingProcessHandler(commandLine.createProcess(), Charset.defaultCharset(), commandLine.getCommandLineString()).runProcess();
} catch (ExecutionException e) {
context.addMessage(CompilerMessageCategory.ERROR, "process throw exception: " + e.getMessage(), null, -1, -1);
}
if (output != null) {