Skip to content

Commit

Permalink
UPDATE_KOTLIN_VERSION: 1.8.0-Beta
Browse files Browse the repository at this point in the history
  • Loading branch information
neetopia committed Nov 17, 2022
1 parent 43444a1 commit 2339405
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 22 deletions.
Expand Up @@ -52,6 +52,7 @@ import org.jetbrains.kotlin.gradle.internal.CompilerArgumentsContributor
import org.jetbrains.kotlin.gradle.internal.compilerArgumentsConfigurationFlags
import org.jetbrains.kotlin.gradle.internal.kapt.incremental.*
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
Expand All @@ -60,6 +61,8 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.enabledOnCurrentHost
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinCompilationData
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinNativeCompilationData
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.isMainCompilationData
import org.jetbrains.kotlin.gradle.targets.js.ir.*
import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.tasks.configuration.AbstractKotlinCompileConfig
Expand All @@ -84,6 +87,9 @@ internal class Configurator : AbstractKotlinCompileConfig<AbstractKotlinCompile<
// work around https://github.com/google/ksp/issues/647
// This will not be necessary once https://youtrack.jetbrains.com/issue/KT-45777 lands
task.ownModuleName.value(kotlinCompile.ownModuleName.map { "$it-ksp" })
(compilation.compilerOptions.options as? KotlinJvmCompilerOptions)?.let {
task.compilerOptions.noJdk.value(it.noJdk)
}
}
if (task is KspTaskJS) {
val libraryCacheService = project.rootProject.gradle.sharedServices.registerIfAbsent(
Expand All @@ -93,6 +99,40 @@ internal class Configurator : AbstractKotlinCompileConfig<AbstractKotlinCompile<
) {}
task.libraryCache.set(libraryCacheService).also { task.libraryCache.disallowChanges() }
task.pluginClasspath.setFrom(objectFactory.fileCollection())
task.outputFileProperty.value(
File(task.destination, "dummyOutput.js")
)
task.enhancedFreeCompilerArgs.value(
(kotlinCompile as Kotlin2JsCompile).compilerOptions.freeCompilerArgs.map { freeArgs ->
freeArgs.toMutableList().apply {
commonJsAdditionalCompilerFlags(compilation)
}
}
).disallowChanges()
}
}
}

// copied from upstream.
protected fun MutableList<String>.commonJsAdditionalCompilerFlags(
compilation: KotlinCompilationData<*>
) {
if (contains(DISABLE_PRE_IR) &&
!contains(PRODUCE_UNZIPPED_KLIB) &&
!contains(PRODUCE_ZIPPED_KLIB)
) {
add(PRODUCE_UNZIPPED_KLIB)
}

if (contains(PRODUCE_JS) ||
contains(PRODUCE_UNZIPPED_KLIB) ||
contains(PRODUCE_ZIPPED_KLIB)
) {
// Configure FQ module name to avoid cyclic dependencies in klib manifests (see KT-36721).
val baseName = if (compilation.isMainCompilationData()) {
project.name
} else {
"${project.name}_${compilation.compilationPurpose}"
}
}
}
Expand Down Expand Up @@ -372,6 +412,10 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
kspTask.doFirst {
kspOutputDir.deleteRecursively()
}
val kspOptions = kspTask.options.get().flatMap { listOf("-P", it.toArg()) }
kspTask.compilerOptions.freeCompilerArgs.value(
kspOptions + kotlinCompileTask.compilerOptions.freeCompilerArgs.get()
)
}
}
}
Expand Down Expand Up @@ -446,7 +490,7 @@ internal inline fun <reified T : Task> Project.locateTask(name: String): TaskPro
internal fun findJavaTaskForKotlinCompilation(compilation: KotlinCompilation<*>): TaskProvider<out JavaCompile>? =
when (compilation) {
is KotlinJvmAndroidCompilation -> compilation.compileJavaTaskProvider
is KotlinWithJavaCompilation -> compilation.compileJavaTaskProvider
is KotlinWithJavaCompilation<*, *> -> compilation.compileJavaTaskProvider
is KotlinJvmCompilation -> compilation.compileJavaTaskProvider // may be null for Kotlin-only JVM target in MPP
else -> null
}
Expand Down Expand Up @@ -493,7 +537,12 @@ interface KspTask : Task {
abstract class KspTaskJvm @Inject constructor(
workerExecutor: WorkerExecutor,
objectFactory: ObjectFactory
) : KotlinCompile(KotlinJvmOptionsImpl(), workerExecutor, objectFactory), KspTask {
) : KotlinCompile(
objectFactory.newInstance(KotlinJvmCompilerOptionsDefault::class.java),
workerExecutor,
objectFactory
),
KspTask {
@get:PathSensitive(PathSensitivity.NONE)
@get:Optional
@get:InputFiles
Expand Down Expand Up @@ -636,6 +685,7 @@ abstract class KspTaskJvm @Inject constructor(
ignoreClasspathResolutionErrors
)
)
(compilerOptions as KotlinJvmCompilerOptionsDefault).fillCompilerArguments(args)
if (blockOtherCompilerPlugins) {
args.blockOtherPlugins(overridePluginClasspath)
}
Expand Down Expand Up @@ -706,7 +756,12 @@ abstract class KspTaskJvm @Inject constructor(
abstract class KspTaskJS @Inject constructor(
objectFactory: ObjectFactory,
workerExecutor: WorkerExecutor
) : Kotlin2JsCompile(KotlinJsOptionsImpl(), objectFactory, workerExecutor), KspTask {
) : Kotlin2JsCompile(
objectFactory.newInstance(KotlinJsCompilerOptionsDefault::class.java),
objectFactory,
workerExecutor
),
KspTask {
private val backendSelectionArgs = listOf(
"-Xir-only",
"-Xir-produce-js",
Expand All @@ -719,9 +774,6 @@ abstract class KspTaskJS @Inject constructor(
kotlinCompile: AbstractKotlinCompile<*>,
) {
kotlinCompile as Kotlin2JsCompile
kotlinOptions.freeCompilerArgs = kotlinCompile.kotlinOptions.freeCompilerArgs.filter {
it in backendSelectionArgs
}
val providerFactory = kotlinCompile.project.providers
compileKotlinArgumentsContributor.set(
providerFactory.provider {
Expand All @@ -747,20 +799,19 @@ abstract class KspTaskJS @Inject constructor(
ignoreClasspathResolutionErrors: Boolean,
) {
// Start with / copy from kotlinCompile.
args.fillDefaultValues()
compileKotlinArgumentsContributor.get().contributeArguments(
args,
compilerArgumentsConfigurationFlags(
defaultsOnly,
ignoreClasspathResolutionErrors
)
)
(compilerOptions as KotlinJsCompilerOptionsDefault).fillCompilerArguments(args)
if (blockOtherCompilerPlugins) {
args.blockOtherPlugins(overridePluginClasspath)
}
args.addPluginOptions(options.get())
args.outputFile = File(destination, "dummyOutput.js").canonicalPath
kotlinOptions.copyFreeCompilerArgsToArgs(args)
args.useK2 = false
}

Expand All @@ -779,6 +830,7 @@ abstract class KspTaskJS @Inject constructor(
} else {
args.addChangedFiles(changedFiles)
}
args.freeArgs = enhancedFreeCompilerArgs.get()
super.callCompilerAsync(args, kotlinSources, inputChanges, taskOutputsBackup)
}

Expand All @@ -800,7 +852,12 @@ abstract class KspTaskJS @Inject constructor(
abstract class KspTaskMetadata @Inject constructor(
workerExecutor: WorkerExecutor,
objectFactory: ObjectFactory
) : KotlinCompileCommon(KotlinMultiplatformCommonOptionsImpl(), workerExecutor, objectFactory), KspTask {
) : KotlinCompileCommon(
objectFactory.newInstance(KotlinMultiplatformCommonCompilerOptionsDefault::class.java),
workerExecutor,
objectFactory
),
KspTask {
override fun configureCompilation(
kotlinCompilation: KotlinCompilationData<*>,
kotlinCompile: AbstractKotlinCompile<*>,
Expand Down Expand Up @@ -831,14 +888,14 @@ abstract class KspTaskMetadata @Inject constructor(
ignoreClasspathResolutionErrors: Boolean,
) {
// Start with / copy from kotlinCompile.
args.apply { fillDefaultValues() }
compileKotlinArgumentsContributor.get().contributeArguments(
args,
compilerArgumentsConfigurationFlags(
defaultsOnly,
ignoreClasspathResolutionErrors
)
)
(compilerOptions as KotlinMultiplatformCommonCompilerOptionsDefault).fillCompilerArguments(args)
if (blockOtherCompilerPlugins) {
args.blockOtherPlugins(overridePluginClasspath)
}
Expand Down Expand Up @@ -886,13 +943,8 @@ abstract class KspTaskNative @Inject constructor(
providerFactory: ProviderFactory,
execOperations: ExecOperations
) : KotlinNativeCompile(compilation, objectFactory, providerFactory, execOperations), KspTask {
override val additionalCompilerOptions: Provider<Collection<String>>
get() {
return project.provider {
val kspOptions = options.get().flatMap { listOf("-P", it.toArg()) }
super.additionalCompilerOptions.get() + kspOptions
}
}
override val compilerOptions: KotlinCommonCompilerOptions =
objectFactory.newInstance(KotlinMultiplatformCommonCompilerOptionsDefault::class.java)

override var compilerPluginClasspath: FileCollection? = null
get() {
Expand Down
Expand Up @@ -96,7 +96,7 @@ class ProcessorClasspathConfigurationsTest {
"""
kotlin {
jvm { }
js { browser() }
js(IR) { browser() }
}
""".trimIndent()
)
Expand Down
Expand Up @@ -82,10 +82,13 @@ class SourceSetConfigurationsTest {
kotlin {
jvm { }
android(name = "foo") { }
js { browser() }
js(BOTH) { browser() }
androidNativeX86 { }
androidNativeX64(name = "bar") { }
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xuse-deprecated-legacy-compiler"
}
""".trimIndent()
)
testRule.appModule.addMultiplatformSource("commonMain", "Foo.kt", "class Foo")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
@@ -1,7 +1,7 @@
# Copied from kotlinc
org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx2200m -Dfile.encoding=UTF-8

kotlinBaseVersion=1.8.0-dev-2843
kotlinBaseVersion=1.8.0-Beta
agpBaseVersion=7.0.0
intellijVersion=203.8084.24
junitVersion=4.12
Expand Down
Expand Up @@ -75,7 +75,7 @@ class KMPImplementedIT {
@Test
fun testJs() {
Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows", ignoreCase = true))
val gradleRunner = GradleRunner.create().withProjectDir(project.root)
val gradleRunner = GradleRunner.create().withDebug(true).withProjectDir(project.root)

gradleRunner.withArguments(
"--configuration-cache-problems=warn",
Expand Down
Expand Up @@ -26,3 +26,7 @@ kotlin {
val commonMain by getting
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xuse-deprecated-legacy-compiler"
}
Expand Up @@ -24,3 +24,7 @@ dependencies {
add("kspJs", project(":test-processor"))
add("kspJsTest", project(":test-processor"))
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xuse-deprecated-legacy-compiler"
}
Expand Up @@ -60,3 +60,7 @@ dependencies {
add("kspMingwX64", project(":test-processor"))
add("kspMingwX64Test", project(":test-processor"))
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xuse-deprecated-legacy-compiler"
}
Expand Up @@ -13,7 +13,7 @@ kotlin {
mingwX64()
macosX64()
ios()
js() {
js(BOTH) {
browser()
nodejs()
}
Expand All @@ -33,3 +33,7 @@ ksp {
arg("option1", "value1")
arg("option2", "value2")
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xuse-deprecated-legacy-compiler"
}

0 comments on commit 2339405

Please sign in to comment.