K2JSCompiler generates output file

This commit is contained in:
pTalanov
2012-05-04 20:55:40 +04:00
parent ded589249f
commit d23cca223d
3 changed files with 11 additions and 8 deletions
@@ -76,19 +76,20 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
} }
}, sources); }, sources);
if (analyzerWithCompilerReport.hasErrors()) { if (analyzerWithCompilerReport.hasErrors()) {
return ExitCode.COMPILATION_ERROR; return ExitCode.COMPILATION_ERROR;
} }
if (arguments.outputDir != null) { if (arguments.outputDir != null) {
try { try {
K2JSTranslator.translateWithCallToMainAndSaveToFile(environmentForJS.getSourceFiles(), arguments.outputDir, config, environmentForJS.getProject()); K2JSTranslator.translateWithCallToMainAndSaveToFile(sources, arguments.outputDir, config, environmentForJS.getProject());
} }
catch (Exception e) { catch (Exception e) {
messageCollector.report(CompilerMessageSeverity.ERROR, "Exception while translating:\n" + e.getMessage(),
CompilerMessageLocation.NO_LOCATION);
return ExitCode.INTERNAL_ERROR; return ExitCode.INTERNAL_ERROR;
} }
} else { } else {
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify output directory via -output", CompilerMessageLocation.NO_LOCATION); messageCollector.report(CompilerMessageSeverity.ERROR, "Specify output file via -output", CompilerMessageLocation.NO_LOCATION);
return ExitCode.INTERNAL_ERROR; return ExitCode.INTERNAL_ERROR;
} }
return ExitCode.OK; return ExitCode.OK;
@@ -28,6 +28,7 @@ import com.intellij.util.Chunk;
import jet.Function1; import jet.Function1;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.JetFileType; import org.jetbrains.jet.plugin.JetFileType;
import org.jetbrains.jet.plugin.k2jsrun.K2JSRunnerUtils;
import org.jetbrains.jet.plugin.project.JsModuleDetector; import org.jetbrains.jet.plugin.project.JsModuleDetector;
import java.io.PrintStream; import java.io.PrintStream;
@@ -90,20 +91,21 @@ public final class K2JSCompiler implements TranslatingCompiler {
-1); -1);
return -1; return -1;
} }
String[] commandLineArgs = constructArguments(context.getModuleOutputDirectory(module), roots[0]); String[] commandLineArgs = constructArguments(context.getProject(), context.getModuleOutputDirectory(module), roots[0]);
Object rc = invokeExecMethod(environment, out, context, commandLineArgs, "org.jetbrains.jet.cli.js.K2JSCompiler"); Object rc = invokeExecMethod(environment, out, context, commandLineArgs, "org.jetbrains.jet.cli.js.K2JSCompiler");
return CompilerUtils.getReturnCodeFromObject(rc); return CompilerUtils.getReturnCodeFromObject(rc);
} }
catch (Throwable e) { catch (Throwable e) {
context.addMessage(CompilerMessageCategory.ERROR, "Exception while executing: " + e.getMessage(), null, -1, -1); context.addMessage(CompilerMessageCategory.ERROR, "Exception while executing compiler: " + e.getMessage(), null, -1, -1);
} }
return -1; return -1;
} }
private static String[] constructArguments(@NotNull VirtualFile outDir, @NotNull VirtualFile srcDir) { private static String[] constructArguments(@NotNull Project project, @NotNull VirtualFile outDir, @NotNull VirtualFile srcDir) {
String srcPath = srcDir.getPath(); String srcPath = srcDir.getPath();
String outPath = outDir.getPath(); String outPath = outDir.getPath();
return new String[] {"-tags", "-verbose", "-version", "-srcdir", srcPath, "-output", outPath}; String outFile = K2JSRunnerUtils.constructPathToGeneratedFile(project, outPath);
return new String[] {"-tags", "-verbose", "-version", "-srcdir", srcPath, "-output", outFile};
} }
@NotNull @NotNull
@@ -70,7 +70,7 @@ public final class K2JSRunnerUtils {
notifySuccess(outputDirPath); notifySuccess(outputDirPath);
} }
private static String constructPathToGeneratedFile(Project project, String outputDirPath) { public static String constructPathToGeneratedFile(@NotNull Project project, @NotNull String outputDirPath) {
return outputDirPath + "/" + project.getName() + ".js"; return outputDirPath + "/" + project.getName() + ".js";
} }