提交 7e58e4d9 编写于 作者: P pTalanov

Add srcdir as K2JSCompiler parameter.

上级 ce929fab
......@@ -20,12 +20,14 @@ import com.google.common.base.Predicates;
import com.intellij.openapi.Disposable;
import com.intellij.psi.PsiFile;
import jet.Function0;
import jet.modules.Module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.cli.common.CLICompiler;
import org.jetbrains.jet.cli.common.ExitCode;
import org.jetbrains.jet.cli.common.messages.*;
import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport;
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
import org.jetbrains.jet.cli.common.messages.MessageRenderer;
import org.jetbrains.jet.cli.common.messages.PrintingMessageCollector;
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.lang.psi.JetFile;
......@@ -34,7 +36,6 @@ import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS;
import org.jetbrains.k2js.config.Config;
import java.io.File;
import java.io.PrintStream;
import java.util.Collections;
import java.util.List;
......@@ -61,37 +62,36 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
@Override
protected ExitCode doExecute(PrintStream stream, K2JSCompilerArguments arguments, MessageRenderer renderer) {
PrintingMessageCollector messageCollector = new PrintingMessageCollector(stream, renderer, true);
if (arguments.module == null) {
stream.print(renderer.render(CompilerMessageSeverity.ERROR, "Module should be specified", NO_LOCATION));
if (arguments.module != null) {
stream.print(renderer.render(CompilerMessageSeverity.ERROR, "Module arg is not supported", NO_LOCATION));
return ExitCode.INTERNAL_ERROR;
}
File directory = new File(arguments.module).getParentFile();
List<Module> modules = CompileEnvironmentUtil
.loadModuleScript(arguments.module, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
for (Module module : modules) {
Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
final JetCoreEnvironment environmentForJS = JetCoreEnvironment.getCoreEnvironmentForJS(rootDisposable);
CompileEnvironmentUtil.addSourcesFromModuleToEnvironment(environmentForJS, module, directory);
AnalyzerWithCompilerReport analyzerWithCompilerReport =
new AnalyzerWithCompilerReport(messageCollector);
final List<JetFile> sources = environmentForJS.getSourceFiles();
analyzerWithCompilerReport.analyzeAndReport(new Function0<AnalyzeExhaust>() {
@Override
public AnalyzeExhaust invoke() {
BindingContext context = AnalyzerFacadeForJS
.analyzeFiles(sources, Predicates.<PsiFile>alwaysTrue(), new Config(environmentForJS.getProject()) {
@NotNull
@Override
protected List<JetFile> generateLibFiles() {
return Collections.emptyList();
}
});
return AnalyzeExhaust.success(context, JetStandardLibrary.getInstance());
}
}, sources);
if (arguments.srcdir == null) {
stream.print(renderer.render(CompilerMessageSeverity.ERROR, "Specify sources location via -srcdir", NO_LOCATION));
return ExitCode.INTERNAL_ERROR;
}
Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
final JetCoreEnvironment environmentForJS = JetCoreEnvironment.getCoreEnvironmentForJS(rootDisposable);
environmentForJS.addSources(arguments.srcdir);
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(messageCollector);
final List<JetFile> sources = environmentForJS.getSourceFiles();
analyzerWithCompilerReport.analyzeAndReport(new Function0<AnalyzeExhaust>() {
@Override
public AnalyzeExhaust invoke() {
BindingContext context = AnalyzerFacadeForJS
.analyzeFiles(sources, Predicates.<PsiFile>alwaysTrue(), new Config(environmentForJS.getProject()) {
@NotNull
@Override
protected List<JetFile> generateLibFiles() {
return Collections.emptyList();
}
});
return AnalyzeExhaust.success(context, JetStandardLibrary.getInstance());
}
}, sources);
stream.print(renderer.render(CompilerMessageSeverity.ERROR, "Greeting", NO_LOCATION));
return ExitCode.OK;
}
......
......@@ -23,12 +23,15 @@ import org.jetbrains.jet.cli.common.CompilerArguments;
* @author Pavel Talanov
*/
public class K2JSCompilerArguments extends CompilerArguments {
@Argument(value = "output", description = "output directory")
@Argument(value = "output", description = "Output directory")
public String outputDir;
@Argument(value = "module", description = "module to compile")
@Argument(value = "module", description = "Module to compile")
public String module;
@Argument(value = "srcdir", description = "Sources directory")
public String srcdir;
@Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag")
public boolean tags;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册