Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/kotlin/com/github/youta1119/kotlin/cli/K2DotNetCompiler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.github.youta1119.kotlin.cli | ||
|
||
import com.github.youta1119.kotlin.compiler.DotNetConfigurationKeys | ||
import com.intellij.openapi.Disposable | ||
import org.jetbrains.kotlin.cli.common.CLICompiler | ||
import org.jetbrains.kotlin.cli.common.CommonCompilerPerformanceManager | ||
import org.jetbrains.kotlin.cli.common.ExitCode | ||
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
import org.jetbrains.kotlin.config.Services | ||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion | ||
import org.jetbrains.kotlin.utils.KotlinPaths | ||
|
||
class K2DotNetCompiler : CLICompiler<K2DotNetCompilerArguments>() { | ||
|
||
override val performanceManager: CommonCompilerPerformanceManager by lazy { | ||
K2DotNetCompilerPerformanceManager() | ||
} | ||
|
||
override fun doExecute( | ||
arguments: K2DotNetCompilerArguments, | ||
configuration: CompilerConfiguration, | ||
rootDisposable: Disposable, | ||
paths: KotlinPaths? | ||
): ExitCode { | ||
return ExitCode.OK | ||
} | ||
|
||
override fun setupPlatformSpecificArgumentsAndServices( | ||
configuration: CompilerConfiguration, | ||
arguments: K2DotNetCompilerArguments, | ||
services: Services | ||
) { | ||
val commonSources = arguments.commonSources?.toSet().orEmpty() | ||
arguments.freeArgs.forEach { | ||
configuration.addKotlinSourceRoot(it, it in commonSources) | ||
} | ||
with(DotNetConfigurationKeys) { | ||
with(configuration) { | ||
arguments.outputName?.let { put(OUTPUT_NAME, it) } | ||
} | ||
} | ||
} | ||
|
||
override fun createArguments(): K2DotNetCompilerArguments = | ||
K2DotNetCompilerArguments() | ||
|
||
override fun createMetadataVersion(versionArray: IntArray): BinaryVersion = | ||
K2DotNetMetadataVersion() | ||
|
||
override fun executableScriptFileName(): String = "kotlinc-dotnet" | ||
|
||
class K2DotNetCompilerPerformanceManager : CommonCompilerPerformanceManager("Kotlin to .Net Compiler") | ||
class K2DotNetMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) { | ||
override fun isCompatible(): Boolean = false | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
doMain(K2DotNetCompiler(), args) | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/github/youta1119/kotlin/cli/K2DotNetCompilerArguments.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.github.youta1119.kotlin.cli | ||
|
||
import org.jetbrains.kotlin.cli.common.arguments.Argument | ||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments | ||
|
||
class K2DotNetCompilerArguments: CommonCompilerArguments() { | ||
@Argument(value = "-output", shortName = "-o", valueDescription = "<name>", description = "Output name") | ||
var outputName: String? = null | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/github/youta1119/kotlin/compiler/DotNetConfigurationKeys.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.github.youta1119.kotlin.compiler | ||
|
||
import org.jetbrains.kotlin.config.CompilerConfigurationKey | ||
|
||
class DotNetConfigurationKeys { | ||
companion object { | ||
val OUTPUT_NAME: CompilerConfigurationKey<String?> = CompilerConfigurationKey.create("write name") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package com.github.youta1119.kotlin | ||
|
||
import com.github.youta1119.kotlin.cli.K2DotNetCompiler | ||
|
||
fun main() { | ||
println("hello world") | ||
} | ||
|
||
fun main(args: Array<String>) = K2DotNetCompiler.main(args) |