Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pluginManagement {
logger.info("A custom Kotlin repository ${additionalRepositoryProperty.get()} was added")
}
mavenLocal()
maven("https://redirector.kotlinlang.org/maven/dev")
}
}

Expand All @@ -28,6 +29,7 @@ dependencyResolutionManagement {
logger.info("A custom Kotlin repository ${additionalRepositoryProperty.get()} was added")
}
mavenLocal()
maven("https://redirector.kotlinlang.org/maven/dev")
}

versionCatalogs {
Expand Down
23 changes: 19 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ version = "${libs.versions.kotlin.get()}-SNAPSHOT"
val propertyFile = "application.properties"

plugins {
alias(libs.plugins.spring.dependency.management)
alias(libs.plugins.spring.boot)
alias(libs.plugins.spring.dependency.management)
alias(libs.plugins.kotlin.plugin.spring)
id("base-kotlin-jvm-conventions")
}
Expand All @@ -36,11 +36,15 @@ val resourceDependency: Configuration by configurations.creating {
}

dependencies {
annotationProcessor("org.springframework:spring-context-indexer")
implementation("com.google.code.gson:gson")
annotationProcessor(libs.spring.context.indexer)
implementation("org.springframework.boot:spring-boot-starter-web")
implementation(libs.springdoc)
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation(libs.aws.springboot.container)
implementation(libs.springdoc)
implementation(libs.gson)
implementation(libs.kotlinx.serialization.json)
implementation(libs.kotlin.compiler.arguments.description)
implementation(libs.kotlin.tooling.core)
implementation(libs.junit)
implementation(libs.logback.logstash.encoder)
implementation(libs.kotlin.reflect)
Expand Down Expand Up @@ -70,6 +74,8 @@ fun buildPropertyFile() {

fun generateProperties(prefix: String = "") = """
# this file is autogenerated by build.gradle.kts
server.error.include-message=always
server.error.include-binding-errors=always
kotlin.version=${kotlinVersion}
policy.file=${prefix + policy}
libraries.folder.jvm=${prefix + libJVM}
Expand Down Expand Up @@ -147,4 +153,13 @@ tasks.withType<Test> {
doFirst {
this@withType.environment("kotlin.wasm.node.path", executablePath)
}

// We disable this on TeamCity, because we don't want to fail this test,
// when compiler server's test run as a K2 user project.
// But for our pull requests we still need to run this test, so we add it to our GitHub action.
if (System.getenv("TEAMCITY_VERSION") != null) {
filter {
excludeTestsMatching("com.compiler.server.CompilerArguments*")
}
}
}
11 changes: 9 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ kotlin-stdlib-wasm-js = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" }
kotlin-test-junit = { group = "org.jetbrains.kotlin", name = "kotlin-test-junit", version.ref = "kotlin" }
kotlin-compiler = { group = "org.jetbrains.kotlin", name = "kotlin-compiler", version.ref = "kotlin" }
kotlin-tooling-core = { group = "org.jetbrains.kotlin", name = "kotlin-tooling-core", version.ref = "kotlin" }
kotlin-compiler-arguments-description = { group = "org.jetbrains.kotlin", name = "kotlin-compiler-arguments-description", version.ref = "kotlin" }
kotlin-script-runtime = { group = "org.jetbrains.kotlin", name = "kotlin-script-runtime", version.ref = "kotlin" }
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-dom-api-compat = { group = "org.jetbrains.kotlin", name = "kotlin-dom-api-compat", version.ref = "kotlin" }
Expand All @@ -35,10 +37,9 @@ kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-cor
kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinx-datetime" }
kotlinx-io-bytestring = { group = "org.jetbrains.kotlinx", name = "kotlinx-io-bytestring", version.ref = "kotlinx-io" }
kotlinx-io-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-io-core", version.ref = "kotlinx-io" }
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
kotlinx-serialization-json-jvm = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json-jvm", version.ref = "kotlinx-serialization" }
kotlinx-serialization-core-jvm = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-core-jvm", version.ref = "kotlinx-serialization" }
springdoc = { group = "org.springdoc", name = "springdoc-openapi-starter-webmvc-ui", version.ref = "springdoc" }
aws-springboot-container = { group = "com.amazonaws.serverless", name = "aws-serverless-java-container-springboot3", version.ref = "aws-serverless-java-container-springboot3" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
logback-logstash-encoder = { group = "net.logstash.logback", name = "logstash-logback-encoder", version.ref = "logstash-logback-encoder" }
skiko-js-wasm-runtime = { group = "org.jetbrains.skiko", name = "skiko-js-wasm-runtime", version.ref = "skiko" }
Expand All @@ -57,6 +58,12 @@ compose-material3 = { group = "org.jetbrains.compose.material3", name = "materia
compose-components-resources = { group = "org.jetbrains.compose.components", name = "components-resources", version.ref = "compose" }
kotlin-serialization-plugin = {group= "org.jetbrains.kotlin", name="kotlin-serialization-compiler-plugin", version.ref = "kotlin"}
gradle-develocity = {group = "com.gradle", name= "develocity-gradle-plugin", version.ref = "gradle-develocity"}
gson = { group = "com.google.code.gson", name = "gson"}

#spring stack dependencies
aws-springboot-container = { group = "com.amazonaws.serverless", name = "aws-serverless-java-container-springboot3", version.ref = "aws-serverless-java-container-springboot3" }
spring-context-indexer = { group = "org.springframework", name = "spring-context-indexer"}
springdoc = { group = "org.springdoc", name = "springdoc-openapi-starter-webmvc-ui", version.ref = "springdoc" }

[bundles]
jackson = ["jackson-databind", "jackson-core", "jackson-annotations"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.compiler.server.api

import com.compiler.server.model.ExtendedCompilerArgumentValue
import com.fasterxml.jackson.annotation.JsonTypeInfo

data class CompilerArgumentResponse(val compilerArguments: Set<CompilerArgument>) {

data class CompilerArgument(
val name: String,
val shortName: String?,
val description: String?,
@field:JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "type")
val type: ExtendedCompilerArgumentValue<*>,
val disabled: Boolean,
val predefinedValues: Any?
)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.compiler.server.api

import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoreProperties(ignoreUnknown = true)
data class ProjectFileRequestDto(val text: String = "", val name: String = "")
13 changes: 13 additions & 0 deletions src/main/kotlin/com/compiler/server/api/RunRequest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.compiler.server.api

import com.compiler.server.model.ProjectType
import com.compiler.server.validation.CompilerArgumentsConstraint
import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoreProperties(ignoreUnknown = true)
data class RunRequest(
val args: String = "",
val files: List<ProjectFileRequestDto> = listOf(),
@CompilerArgumentsConstraint(ProjectType.JAVA)
val compilerArguments: Map<String, Any> = emptyMap()
)
13 changes: 13 additions & 0 deletions src/main/kotlin/com/compiler/server/api/TestRequest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.compiler.server.api

import com.compiler.server.model.ProjectType
import com.compiler.server.validation.CompilerArgumentsConstraint
import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoreProperties(ignoreUnknown = true)
data class TestRequest(
val args: String = "",
val files: List<ProjectFileRequestDto> = listOf(),
@CompilerArgumentsConstraint(ProjectType.JAVA)
val compilerArguments: Map<String, Any> = emptyMap()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.compiler.server.api

import com.compiler.server.model.ProjectType
import com.compiler.server.validation.CompilerArgumentsConstraint
import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoreProperties(ignoreUnknown = true)
class TranslateComposeWasmRequest(
val args: String = "",
val files: List<ProjectFileRequestDto> = listOf(),
@CompilerArgumentsConstraint(ProjectType.COMPOSE_WASM)
val firstPhaseCompilerArguments: Map<String, Any> = emptyMap(),
@CompilerArgumentsConstraint(ProjectType.COMPOSE_WASM)
val secondPhaseCompilerArguments: Map<String, Any> = emptyMap()
)
15 changes: 15 additions & 0 deletions src/main/kotlin/com/compiler/server/api/TranslateJsRequest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.compiler.server.api

import com.compiler.server.model.ProjectType
import com.compiler.server.validation.CompilerArgumentsConstraint
import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoreProperties(ignoreUnknown = true)
data class TranslateJsRequest(
val args: String = "",
val files: List<ProjectFileRequestDto> = listOf(),
@CompilerArgumentsConstraint(ProjectType.JS)
val firstPhaseCompilerArguments: Map<String, Any> = emptyMap(),
@CompilerArgumentsConstraint(ProjectType.JS)
val secondPhaseCompilerArguments: Map<String, Any> = emptyMap()
)
15 changes: 15 additions & 0 deletions src/main/kotlin/com/compiler/server/api/TranslateWasmRequest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.compiler.server.api

import com.compiler.server.model.ProjectType
import com.compiler.server.validation.CompilerArgumentsConstraint
import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoreProperties(ignoreUnknown = true)
class TranslateWasmRequest(
val args: String = "",
val files: List<ProjectFileRequestDto> = listOf(),
@CompilerArgumentsConstraint(ProjectType.WASM)
val firstPhaseCompilerArguments: Map<String, Any> = emptyMap(),
@CompilerArgumentsConstraint(ProjectType.WASM)
val secondPhaseCompilerArguments: Map<String, Any> = emptyMap()
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package com.compiler.server.compiler.components

import com.compiler.server.executor.CommandLineArgument
import com.compiler.server.executor.JavaExecutor
import com.compiler.server.model.ExtendedCompilerArgument
import com.compiler.server.model.JvmExecutionResult
import com.compiler.server.model.OutputDirectory
import com.compiler.server.model.ProjectFile
import com.compiler.server.model.bean.LibrariesFile
import com.compiler.server.model.toExceptionDescriptor
import com.compiler.server.utils.CompilerArgumentsUtil
import component.KotlinEnvironment
import executors.JUnitExecutors
import executors.JavaRunnerExecutor
Expand All @@ -32,7 +34,9 @@ class KotlinCompiler(
private val kotlinEnvironment: KotlinEnvironment,
private val javaExecutor: JavaExecutor,
private val librariesFile: LibrariesFile,
@Value("\${policy.file}") private val policyFileName: String
@Value("\${policy.file}") private val policyFileName: String,
private val compilerArgumentsUtil: CompilerArgumentsUtil,
private val jvmCompilerArguments: Set<ExtendedCompilerArgument>,
) {
private val policyFile = File(policyFileName)

Expand All @@ -59,8 +63,8 @@ class KotlinCompiler(
?.joinToString("\n\n")
}

fun run(files: List<ProjectFile>, addByteCode: Boolean, args: String): JvmExecutionResult {
return execute(files, addByteCode) { output, compiled ->
fun run(files: List<ProjectFile>, addByteCode: Boolean, args: String, userCompilerArguments: Map<String, Any>): JvmExecutionResult {
return execute(files, addByteCode, userCompilerArguments) { output, compiled ->
val mainClass = JavaRunnerExecutor::class.java.name
val compiledMainClass = when (compiled.mainClasses.size) {
0 -> return@execute JvmExecutionResult(
Expand All @@ -82,26 +86,21 @@ class KotlinCompiler(
}
}

fun test(files: List<ProjectFile>, addByteCode: Boolean): JvmExecutionResult {
return execute(files, addByteCode) { output, _ ->
fun test(files: List<ProjectFile>, addByteCode: Boolean, userCompilerArguments: Map<String, Any>): JvmExecutionResult {
return execute(files, addByteCode, userCompilerArguments) { output, _ ->
val mainClass = JUnitExecutors::class.java.name
javaExecutor.execute(argsFrom(mainClass, output, listOf(output.path.toString())))
.asJUnitExecutionResult()
}
}

@OptIn(ExperimentalPathApi::class)
fun compile(files: List<ProjectFile>): CompilationResult<JvmClasses> = usingTempDirectory { inputDir ->
fun compile(files: List<ProjectFile>, userCompilerArguments: Map<String, Any>): CompilationResult<JvmClasses> = usingTempDirectory { inputDir ->
val ioFiles = files.writeToIoFiles(inputDir)
usingTempDirectory { outputDir ->
val arguments =
ioFiles.map { it.absolutePathString() } + KotlinEnvironment.additionalCompilerArguments + listOf(
"-cp", kotlinEnvironment.classpath.joinToString(PATH_SEPARATOR) { it.absolutePath },
"-module-name", "web-module",
"-no-stdlib", "-no-reflect",
"-progressive",
"-d", outputDir.absolutePathString(),
) + kotlinEnvironment.compilerPlugins.map { plugin -> "-Xplugin=${plugin.absolutePath}" }
val arguments = ioFiles.map { it.absolutePathString() } +
compilerArgumentsUtil.convertCompilerArgumentsToCompilationString(jvmCompilerArguments, compilerArgumentsUtil.PREDEFINED_JVM_ARGUMENTS, userCompilerArguments) +
listOf("-d", outputDir.absolutePathString())
K2JVMCompiler().tryCompilation(inputDir, ioFiles, arguments) {
val outputFiles = buildMap {
outputDir.visitFileTree {
Expand Down Expand Up @@ -142,9 +141,10 @@ class KotlinCompiler(
private fun execute(
files: List<ProjectFile>,
addByteCode: Boolean,
userCompilerArguments: Map<String, Any>,
block: (output: OutputDirectory, compilation: JvmClasses) -> JvmExecutionResult
): JvmExecutionResult = try {
when (val compilationResult = compile(files)) {
when (val compilationResult = compile(files, userCompilerArguments)) {
is Compiled<JvmClasses> -> {
usingTempDirectory { outputDir ->
val output = write(compilationResult.result, outputDir)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.compiler.server.compiler.components

import com.compiler.server.model.bean.LibrariesFile
import com.compiler.server.model.bean.VersionInfo
import component.CompilerPluginOption
import component.KotlinEnvironment
import org.springframework.context.annotation.Bean
Expand Down
Loading