blob: 6b95a4c7d90949f76f5c8e7653c827574ed905fd [file] [log] [blame] [raw]
Daniel Belowb4ebb472021-06-02 22:58:41 +02001// Copyright (c) 2021, Compiler Explorer Authors
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are met:
6//
7// * Redistributions of source code must retain the above copyright notice,
8// this list of conditions and the following disclaimer.
9// * Redistributions in binary form must reproduce the above copyright
10// notice, this list of conditions and the following disclaimer in the
11// documentation and/or other materials provided with the distribution.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23// POSSIBILITY OF SUCH DAMAGE.
24
25import { KotlinParser } from './argument-parsers';
26import { JavaCompiler } from './java';
27
28export class KotlinCompiler extends JavaCompiler {
29 static get key() {
30 return 'kotlin';
31 }
32
Austin Morton81013492021-10-05 00:21:32 -040033 constructor(compilerInfo, env) {
34 super(compilerInfo, env);
35 this.javaHome = this.compilerProps(`compiler.${this.compiler.id}.java_home`);
36 }
37
Daniel Belowb4ebb472021-06-02 22:58:41 +020038 getDefaultExecOptions() {
39 const execOptions = super.getDefaultExecOptions();
Austin Morton81013492021-10-05 00:21:32 -040040 if (this.javaHome) {
41 execOptions.env.JAVA_HOME = this.javaHome;
Daniel Belowb4ebb472021-06-02 22:58:41 +020042 }
43
44 return execOptions;
45 }
46
Mats Larsene2a8e7c2021-07-06 15:11:32 +020047 getMainClassName() {
48 return 'ExampleKt';
49 }
50
Daniel Belowb4ebb472021-06-02 22:58:41 +020051 filterUserOptions(userOptions) {
52 // filter options without extra arguments
Mats Larsenf3be7412021-07-06 16:42:21 +020053 userOptions = (userOptions || []).filter(option =>
Daniel Belowb4ebb472021-06-02 22:58:41 +020054 option !== '-script' && option !== '-progressive' && !option.startsWith('-Xjavac'));
55
56 const oneArgForbiddenList = new Set([
57 // -d directory
58 // Destination for generated class files
59 '-d',
60 // -jdk-home path
61 // Include a custom JDK from the specified location
62 // into the classpath instead of the default JAVA_HOME
63 '-jdk-home',
64 // -kotlin-home path
65 // Path to the home directory of Kotlin compiler used for
66 // discovery of runtime libraries
67 '-kotlin-home',
68 ]);
69
70 // filter options with one argument
71 return super.filterUserOptionsWithArg(userOptions, oneArgForbiddenList);
72 }
73
74 optionsForFilter(filters) {
75 // Forcibly enable javap
76 filters.binary = true;
77
78 return [
79 '-Xjavac-arguments="-Xlint:all"',
80 ];
81 }
82
83 getArgumentParser() {
84 return KotlinParser;
85 }
86}