Add js.translator dependency to cli. Draft K2JSCompiler (just a placeholder)
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
<pathelement path="${idea.sdk}/lib/resources_en.jar"/>
|
||||
|
||||
<fileset dir="${basedir}/lib" includes="**/*.jar"/>
|
||||
<fileset dir="${basedir}/js/js.translator/lib" includes="*.jar"/>
|
||||
<pathelement path="${output}/classes/runtime"/>
|
||||
</path>
|
||||
|
||||
@@ -36,6 +37,9 @@
|
||||
<include name="util/src"/>
|
||||
<include name="jet.as.java.psi/src"/>
|
||||
</dirset>
|
||||
<dirset dir="${basedir}/js/js.translator">
|
||||
<include name="src"/>
|
||||
</dirset>
|
||||
</path>
|
||||
|
||||
<target name="init" depends="clean">
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<orderEntry type="module" module-name="jet.as.java.psi" />
|
||||
<orderEntry type="library" name="intellij-core" level="project" />
|
||||
<orderEntry type="library" name="asm" level="project" />
|
||||
<orderEntry type="module" module-name="js.translator" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.cli.js;
|
||||
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.CompileEnvironmentConfig;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class K2JSCompileEnvironmentConfiguration extends CompileEnvironmentConfig {
|
||||
/**
|
||||
* NOTE: It's very important to call dispose for every object of this class or there will be memory leaks.
|
||||
*
|
||||
* @see Disposer
|
||||
*/
|
||||
public K2JSCompileEnvironmentConfiguration(@NotNull MessageCollector messageCollector) {
|
||||
super(messageCollector);
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,83 @@
|
||||
|
||||
package org.jetbrains.jet.cli.js;
|
||||
|
||||
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.jvm.compiler.CompileEnvironmentUtil;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
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;
|
||||
|
||||
import static org.jetbrains.jet.cli.common.messages.CompilerMessageLocation.NO_LOCATION;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class K2JSCompiler {
|
||||
public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompileEnvironmentConfiguration> {
|
||||
|
||||
public static void main(String... args) {
|
||||
//TODO
|
||||
doMain(new K2JSCompiler(), args);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected K2JSCompilerArguments createArguments() {
|
||||
return new K2JSCompilerArguments();
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@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));
|
||||
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);
|
||||
}
|
||||
|
||||
stream.print(renderer.render(CompilerMessageSeverity.ERROR, "Greeting", NO_LOCATION));
|
||||
return ExitCode.OK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,16 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Chunk;
|
||||
import jet.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.plugin.project.JsModuleDetector;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import static org.jetbrains.jet.plugin.compiler.CompilerUtils.invokeExecMethod;
|
||||
import static org.jetbrains.jet.plugin.compiler.CompilerUtils.outputCompilerMessagesAndHandleExitCode;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
@@ -47,8 +53,45 @@ public final class K2JSCompiler implements TranslatingCompiler {
|
||||
|
||||
@Override
|
||||
public void compile(final CompileContext context, Chunk<Module> moduleChunk, final VirtualFile[] files, OutputSink sink) {
|
||||
context.addMessage(CompilerMessageCategory.INFORMATION, "Some useful code will be there", null, -1, -1);
|
||||
//TODO:
|
||||
if (files.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (moduleChunk.getNodes().size() != 1) {
|
||||
context.addMessage(CompilerMessageCategory.ERROR, "K2JSCompiler does not support multiple modules.", null, -1, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
Module module = moduleChunk.getNodes().iterator().next();
|
||||
final CompilerEnvironment environment = CompilerEnvironment.getEnvironmentFor(context, module, /*tests = */ false);
|
||||
if (!environment.success()) {
|
||||
environment.reportErrorsTo(context);
|
||||
return;
|
||||
}
|
||||
|
||||
CompilerUtils.OutputItemsCollectorImpl collector = new CompilerUtils.OutputItemsCollectorImpl(environment.getOutput().getPath());
|
||||
outputCompilerMessagesAndHandleExitCode(context, collector, new Function1<PrintStream, Integer>() {
|
||||
@Override
|
||||
public Integer invoke(PrintStream stream) {
|
||||
return execInProcess(context, environment, stream);
|
||||
}
|
||||
});
|
||||
sink.add(environment.getOutput().getPath(), collector.getOutputs(), collector.getSources().toArray(VirtualFile.EMPTY_ARRAY));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Integer execInProcess(@NotNull CompileContext context,
|
||||
@NotNull CompilerEnvironment environment, @NotNull PrintStream out) {
|
||||
try {
|
||||
String[] commandLineArgs = {"-tags", "-verbose", "-version"};
|
||||
Object rc = invokeExecMethod(environment, out, context, commandLineArgs,
|
||||
"org.jetbrains.jet.cli.js.K2JSCompiler");
|
||||
return CompilerUtils.getReturnCodeFromObject(rc);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
context.addMessage(CompilerMessageCategory.ERROR, "Fail!", null, -1, -1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user