Daniel Below | b4ebb47 | 2021-06-02 22:58:41 +0200 | [diff] [blame] | 1 | // 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 | |
| 25 | import { KotlinParser } from './argument-parsers'; |
| 26 | import { JavaCompiler } from './java'; |
| 27 | |
| 28 | export class KotlinCompiler extends JavaCompiler { |
| 29 | static get key() { |
| 30 | return 'kotlin'; |
| 31 | } |
| 32 | |
Austin Morton | 8101349 | 2021-10-05 00:21:32 -0400 | [diff] [blame] | 33 | constructor(compilerInfo, env) { |
| 34 | super(compilerInfo, env); |
| 35 | this.javaHome = this.compilerProps(`compiler.${this.compiler.id}.java_home`); |
| 36 | } |
| 37 | |
Daniel Below | b4ebb47 | 2021-06-02 22:58:41 +0200 | [diff] [blame] | 38 | getDefaultExecOptions() { |
| 39 | const execOptions = super.getDefaultExecOptions(); |
Austin Morton | 8101349 | 2021-10-05 00:21:32 -0400 | [diff] [blame] | 40 | if (this.javaHome) { |
| 41 | execOptions.env.JAVA_HOME = this.javaHome; |
Daniel Below | b4ebb47 | 2021-06-02 22:58:41 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | return execOptions; |
| 45 | } |
| 46 | |
Mats Larsen | e2a8e7c | 2021-07-06 15:11:32 +0200 | [diff] [blame] | 47 | getMainClassName() { |
| 48 | return 'ExampleKt'; |
| 49 | } |
| 50 | |
Daniel Below | b4ebb47 | 2021-06-02 22:58:41 +0200 | [diff] [blame] | 51 | filterUserOptions(userOptions) { |
| 52 | // filter options without extra arguments |
Mats Larsen | f3be741 | 2021-07-06 16:42:21 +0200 | [diff] [blame] | 53 | userOptions = (userOptions || []).filter(option => |
Daniel Below | b4ebb47 | 2021-06-02 22:58:41 +0200 | [diff] [blame] | 54 | 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 | } |