Add srcdir as K2JSCompiler parameter.
This commit is contained in:
@@ -20,12 +20,14 @@ import com.google.common.base.Predicates;
|
|||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import jet.Function0;
|
import jet.Function0;
|
||||||
import jet.modules.Module;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||||
import org.jetbrains.jet.cli.common.CLICompiler;
|
import org.jetbrains.jet.cli.common.CLICompiler;
|
||||||
import org.jetbrains.jet.cli.common.ExitCode;
|
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.CompileEnvironmentUtil;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
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.analyze.AnalyzerFacadeForJS;
|
||||||
import org.jetbrains.k2js.config.Config;
|
import org.jetbrains.k2js.config.Config;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -61,37 +62,36 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
|
|||||||
@Override
|
@Override
|
||||||
protected ExitCode doExecute(PrintStream stream, K2JSCompilerArguments arguments, MessageRenderer renderer) {
|
protected ExitCode doExecute(PrintStream stream, K2JSCompilerArguments arguments, MessageRenderer renderer) {
|
||||||
PrintingMessageCollector messageCollector = new PrintingMessageCollector(stream, renderer, true);
|
PrintingMessageCollector messageCollector = new PrintingMessageCollector(stream, renderer, true);
|
||||||
if (arguments.module == null) {
|
if (arguments.module != null) {
|
||||||
stream.print(renderer.render(CompilerMessageSeverity.ERROR, "Module should be specified", NO_LOCATION));
|
stream.print(renderer.render(CompilerMessageSeverity.ERROR, "Module arg is not supported", NO_LOCATION));
|
||||||
return ExitCode.INTERNAL_ERROR;
|
return ExitCode.INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
File directory = new File(arguments.module).getParentFile();
|
if (arguments.srcdir == null) {
|
||||||
List<Module> modules = CompileEnvironmentUtil
|
stream.print(renderer.render(CompilerMessageSeverity.ERROR, "Specify sources location via -srcdir", NO_LOCATION));
|
||||||
.loadModuleScript(arguments.module, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
|
return ExitCode.INTERNAL_ERROR;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
stream.print(renderer.render(CompilerMessageSeverity.ERROR, "Greeting", NO_LOCATION));
|
||||||
return ExitCode.OK;
|
return ExitCode.OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,12 +23,15 @@ import org.jetbrains.jet.cli.common.CompilerArguments;
|
|||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
*/
|
*/
|
||||||
public class K2JSCompilerArguments extends CompilerArguments {
|
public class K2JSCompilerArguments extends CompilerArguments {
|
||||||
@Argument(value = "output", description = "output directory")
|
@Argument(value = "output", description = "Output directory")
|
||||||
public String outputDir;
|
public String outputDir;
|
||||||
|
|
||||||
@Argument(value = "module", description = "module to compile")
|
@Argument(value = "module", description = "Module to compile")
|
||||||
public String module;
|
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")
|
@Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag")
|
||||||
public boolean tags;
|
public boolean tags;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user