Skip to content

Kotlin upgrade to 1.7.0 and apple silicon m1 support #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 17, 2022
Merged
15 changes: 12 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
with:
candidate: gradle
version: 7.4.2

- name: Install Kotlin
run: |
curl -o kotlin-compiler.zip -L https://github.com/JetBrains/kotlin/releases/download/v1.5.10/kotlin-compiler-1.5.10.zip
curl -o kotlin-compiler.zip -L https://github.com/JetBrains/kotlin/releases/download/v1.7.0/kotlin-compiler-1.7.0.zip

if [[ "$OSTYPE" != "darwin"* ]]
then
Expand All @@ -34,7 +34,16 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: '14'


- name: Install libncurses5
run: |
if [[ "$OSTYPE" == "darwin"* ]]
then
brew install ncurses
else
sudo apt-get install libncurses5
fi

- name: Install Danger JS
run: npm install -g danger

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

-->
## Master
- Update `Kotlin` to `1.7.0` and added support for Apple Silicon Chipset [@gianluz] - [#231](https://github.com/danger/kotlin/pull/231)

# 1.1.0

Expand Down
2 changes: 1 addition & 1 deletion Dangerfile.df.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Repository("https://repo.maven.apache.org")
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:DependsOn("org.apache.commons:commons-text:1.6")

import systems.danger.kotlin.*
Expand Down
2 changes: 1 addition & 1 deletion Dangerfile_ci.df.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* Use external dependencies using the following annotations:
*/
@file:Repository("https://repo.maven.apache.org")
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:DependsOn("org.apache.commons:commons-text:1.6")

//Testing plugin
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN apt-get update && \
# Install danger-kotlin globally
COPY . /usr/local/_danger-kotlin
RUN cd /usr/lib && \
wget -q https://github.com/JetBrains/kotlin/releases/download/v1.5.0/kotlin-compiler-1.5.0.zip && \
wget -q https://github.com/JetBrains/kotlin/releases/download/v1.7.0/kotlin-compiler-1.7.0.zip && \
unzip kotlin-compiler-*.zip && \
rm kotlin-compiler-*.zip && \
cd /usr/local/_danger-kotlin && \
Expand Down
3 changes: 2 additions & 1 deletion danger-kotlin-kts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ apply from: file('version.gradle')
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-script-runtime:$versionKotlin"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2"

includeJar "org.jetbrains.kotlin:kotlin-main-kts:$versionKotlin"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package systems.danger.kts

import kotlinx.coroutines.runBlocking
import org.jetbrains.kotlin.mainKts.*
import org.jetbrains.kotlin.mainKts.impl.IvyResolver
import java.io.File
import kotlin.script.dependencies.ScriptContents
import kotlin.script.dependencies.ScriptDependenciesResolver
import kotlin.script.experimental.annotations.KotlinScript
import kotlin.script.experimental.api.*
import kotlin.script.experimental.dependencies.*
import kotlin.script.experimental.dependencies.maven.MavenDependenciesResolver
import kotlin.script.experimental.host.FileBasedScriptSource
import kotlin.script.experimental.host.FileScriptSource
import kotlin.script.experimental.impl.internalScriptingRunSuspend
import kotlin.script.experimental.jvm.compat.mapLegacyDiagnosticSeverity
import kotlin.script.experimental.jvm.compat.mapLegacyScriptPosition
import kotlin.script.experimental.jvm.dependenciesFromClassContext
Expand All @@ -32,7 +32,7 @@ abstract class DangerFileScript(val args: Array<String>)

object DangerFileScriptDefinition : ScriptCompilationConfiguration(
{
defaultImports(DependsOn::class, Repository::class, Import::class, CompilerOptions::class)
defaultImports(DependsOn::class, Repository::class, Import::class, CompilerOptions::class, ScriptFileLocation::class)
jvm {
dependenciesFromClassContext(
DangerFileScriptDefinition::class,
Expand All @@ -49,6 +49,8 @@ object DangerFileScriptDefinition : ScriptCompilationConfiguration(
CompilerOptions::class,
handler = DangerFileKtsConfigurator()
)
onAnnotations(ScriptFileLocation::class, handler = ScriptFileLocationCustomConfigurator())
beforeCompiling(::configureScriptFileLocationPathVariablesForCompilation)
beforeCompiling(::configureProvidedPropertiesFromJsr223Context)
}
ide {
Expand All @@ -64,7 +66,8 @@ class DangerFileKtsConfigurator : RefineScriptCompilationConfigurationHandler {

private val resolver = CompoundDependenciesResolver(
FileSystemDependenciesResolver(DANGER_LIBS_FLAT_DIR),
IvyResolver()
FileSystemDependenciesResolver(),
MavenDependenciesResolver()
)

override operator fun invoke(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics<ScriptCompilationConfiguration> =
Expand All @@ -89,28 +92,44 @@ class DangerFileKtsConfigurator : RefineScriptCompilationConfigurationHandler {
?: return context.compilationConfiguration.asSuccess()

val scriptBaseDir = (context.script as? FileBasedScriptSource)?.file?.parentFile
val importedSources = annotations.filterByAnnotationType<Import>().flatMap {
it.annotation.paths.map { sourceName ->
FileScriptSource(scriptBaseDir?.resolve(sourceName) ?: File(sourceName))
val importedSources = linkedMapOf<String, Pair<File, String>>()
var hasImportErrors = false
annotations.filterByAnnotationType<Import>().forEach { scriptAnnotation ->
scriptAnnotation.annotation.paths.forEach { sourceName ->
val file = (scriptBaseDir?.resolve(sourceName) ?: File(sourceName)).normalize()
val keyPath = file.absolutePath
val prevImport = importedSources.put(keyPath, file to sourceName)
if (prevImport != null) {
diagnostics.add(
ScriptDiagnostic(
ScriptDiagnostic.unspecifiedError, "Duplicate imports: \"${prevImport.second}\" and \"$sourceName\"",
sourcePath = context.script.locationId, location = scriptAnnotation.location?.locationInText
)
)
hasImportErrors = true
}
}
}
if (hasImportErrors) return ResultWithDiagnostics.Failure(diagnostics)

val compileOptions = annotations.filterByAnnotationType<CompilerOptions>().flatMap {
it.annotation.options.toList()
}

val resolveResult = try {
runBlocking {
@Suppress("DEPRECATION_ERROR")
internalScriptingRunSuspend {
resolver.resolveFromScriptSourceAnnotations(annotations.filter { it.annotation is DependsOn || it.annotation is Repository })
}

} catch (e: Throwable) {
ResultWithDiagnostics.Failure(*diagnostics.toTypedArray(), e.asDiagnostics(path = context.script.locationId))
diagnostics.add(e.asDiagnostics(path = context.script.locationId))
ResultWithDiagnostics.Failure(diagnostics)
}

return resolveResult.onSuccess { resolvedClassPath ->
ScriptCompilationConfiguration(context.compilationConfiguration) {
updateClasspath(resolvedClassPath)
if (importedSources.isNotEmpty()) importScripts.append(importedSources)
if (importedSources.isNotEmpty()) importScripts.append(importedSources.values.map { FileScriptSource(it.first) })
if (compileOptions.isNotEmpty()) compilerOptions.append(compileOptions)
}.asSuccess()
}
Expand Down
4 changes: 2 additions & 2 deletions danger-kotlin-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ test {
}

compileKotlin {
kotlinOptions.jvmTarget = "1.6"
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.6"
kotlinOptions.jvmTarget = "1.8"
}

publishing {
Expand Down
2 changes: 1 addition & 1 deletion danger-kotlin-sample-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

plugins {
id 'org.jetbrains.kotlin.jvm' version '1.5.0'
id 'org.jetbrains.kotlin.jvm' version '1.7.0'
}

apply plugin: 'danger-kotlin-plugin-installer'
Expand Down
1 change: 1 addition & 0 deletions danger-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ kotlin {
val hostTarget = when (val hostOs = System.getProperty("os.name")) {
"Mac OS X" -> macosX64("runner")
"Linux" -> linuxX64("runner")
"Mac OS X Apple silicon" -> macosArm64("runner")
else -> throw GradleException("Host OS '$hostOs' is not supported.") as Throwable
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private fun readLine(file: CPointer<FILE>): String? {
var ch = getc(file)
var lineBuffer: Array<Char> = arrayOf()

while ((ch != '\n'.toInt()) && (ch != EOF)) {
while ((ch != '\n'.code) && (ch != EOF)) {
lineBuffer += ch.toChar()

ch = getc(file)
Expand Down
6 changes: 3 additions & 3 deletions dependencyVersions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ project.ext.groupIdOkio = 'com.squareup.okio'
project.ext.artifactIdOkio = 'okio'

// Kotlin
project.ext.versionKotlin = '1.5.10'
project.ext.versionKotlin = '1.7.0'
project.ext.groupIdKotlin = 'org.jetbrains.kotlin'
project.ext.groupIdKotlinx = 'org.jetbrains.kotlinx'
project.ext.artifactIdKotlinMain = 'kotlin-main-kts'
project.ext.artifactIdKotlinSerializationJson = 'kotlinx-serialization-json'
project.ext.artifactIdKotlinDatetime = "kotlinx-datetime"
project.ext.artifactIdKotlinCoroutines = "kotlinx-coroutines-core"
project.ext.versionKotlinSerializationJson = '1.2.1'
project.ext.versionKotlinSerializationJson = '1.3.2'
project.ext.versionKotlinDatetime = '0.2.0'
project.ext.versionKotlinCoroutines = '1.5.0'
project.ext.versionKotlinCoroutines = '1.6.2'

ext.kotlin = [
mainKts: "$groupIdKotlin:$artifactIdKotlinMain:$versionKotlin",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
kotlinVersion=1.5.10
kotlinVersion=1.7.0
kotlin.code.style=official
systemProp.org.gradle.internal.publish.checksums.insecure=true