Skip to content

Commit

Permalink
✨ implement compiler cli
Browse files Browse the repository at this point in the history
  • Loading branch information
youta1119 committed Dec 13, 2019
1 parent 1ed3be4 commit de6133c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 3 deletions.
@@ -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)
}
}
}
@@ -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
}
@@ -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")
}
}
6 changes: 3 additions & 3 deletions src/main/kotlin/com/github/youta1119/kotlin/main.kt
@@ -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)

0 comments on commit de6133c

Please sign in to comment.