use of org.jetbrains.kotlin.cli.js.K2JSCompiler in project kotlin by JetBrains.
the class CompileKotlinAgainstCustomBinariesTest method compileKotlin.
@NotNull
private Pair<String, ExitCode> compileKotlin(@NotNull CLICompiler<?> compiler, @NotNull String fileName, @NotNull File output, @NotNull List<String> additionalOptions, @NotNull File... classpath) {
List<String> args = new ArrayList<String>();
File sourceFile = new File(getTestDataDirectory(), fileName);
assert sourceFile.exists() : "Source file does not exist: " + sourceFile.getAbsolutePath();
args.add(sourceFile.getPath());
if (compiler instanceof K2JSCompiler) {
if (classpath.length > 0) {
args.add("-libraries");
args.add(StringsKt.join(Arrays.asList(classpath), File.pathSeparator));
}
args.add("-output");
args.add(output.getPath());
args.add("-meta-info");
} else if (compiler instanceof K2JVMCompiler) {
if (classpath.length > 0) {
args.add("-classpath");
args.add(StringsKt.join(Arrays.asList(classpath), File.pathSeparator));
}
args.add("-d");
args.add(output.getPath());
} else {
throw new UnsupportedOperationException(compiler.toString());
}
args.addAll(additionalOptions);
return AbstractCliTest.executeCompilerGrabOutput(compiler, args);
}
use of org.jetbrains.kotlin.cli.js.K2JSCompiler in project kotlin by JetBrains.
the class CompileMavenGeneratedJSLibrary method generateJavaScriptFiles.
private void generateJavaScriptFiles(@NotNull Iterable<EcmaVersion> ecmaVersions, @NotNull String sourceDir, @NotNull String... stdLibFiles) throws Exception {
List<String> files = Lists.newArrayList();
// now lets add all the files from the definitions and library
//addAllSourceFiles(files, generatedJsDefinitionsDir);
addAllSourceFiles(files, generatedJsLibraryDir);
File stdlibDir = new File(sourceDir);
assertTrue("Cannot find stdlib test source: " + stdlibDir, stdlibDir.exists());
for (String file : stdLibFiles) {
files.add(new File(stdlibDir, file).getPath());
}
// now lets try invoke the compiler
for (EcmaVersion version : ecmaVersions) {
String outputFile = getOutputFilePath(getTestName(false) + ".compiler.kt", version);
System.out.println("Compiling with version: " + version + " to: " + outputFile);
List<String> args = new ArrayList<String>(Arrays.asList("-output", outputFile, "-libraries", generatedJsDefinitionsDir, "-verbose"));
args.addAll(files);
ExitCode answer = new K2JSCompiler().exec(System.out, ArrayUtil.toStringArray(args));
assertEquals("Compile failed", ExitCode.OK, answer);
}
}
Aggregations