Search in sources :

Example 1 with K2JSCompiler

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);
}
Also used : K2JSCompiler(org.jetbrains.kotlin.cli.js.K2JSCompiler) K2JVMCompiler(org.jetbrains.kotlin.cli.jvm.K2JVMCompiler) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with K2JSCompiler

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);
    }
}
Also used : K2JSCompiler(org.jetbrains.kotlin.cli.js.K2JSCompiler) ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) ArrayList(java.util.ArrayList) EcmaVersion(org.jetbrains.kotlin.js.config.EcmaVersion) File(java.io.File)

Aggregations

File (java.io.File)2 K2JSCompiler (org.jetbrains.kotlin.cli.js.K2JSCompiler)2 ArrayList (java.util.ArrayList)1 JarFile (java.util.jar.JarFile)1 NotNull (org.jetbrains.annotations.NotNull)1 ExitCode (org.jetbrains.kotlin.cli.common.ExitCode)1 K2JVMCompiler (org.jetbrains.kotlin.cli.jvm.K2JVMCompiler)1 EcmaVersion (org.jetbrains.kotlin.js.config.EcmaVersion)1 RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile (org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile)1