From a390fc36e2d1f0943af50f07529d3ba6e2cd48d6 Mon Sep 17 00:00:00 2001 From: Sergey Rostov Date: Tue, 10 Apr 2018 13:33:49 +0300 Subject: [PATCH] jps: Refactor module/project settings getters/setters (cherry picked from commit d29ffa0) --- .../compilerRunner/JpsKotlinCompilerRunner.kt | 19 ++- .../kotlin/jps/JpsKotlinCompilerSettings.kt | 132 ------------------ .../jetbrains/kotlin/jps/ModuleSettings.kt | 58 ++++++++ .../jetbrains/kotlin/jps/ProjectSettings.kt | 91 ++++++++++++ .../jetbrains/kotlin/jps/build/JpsUtils.java | 5 +- .../kotlin/jps/build/KotlinBuilder.kt | 4 +- .../Kotlin2JsCompilerArgumentsSerializer.kt | 3 +- .../Kotlin2JvmCompilerArgumentsSerializer.kt | 3 +- ...KotlinCommonCompilerArgumentsSerializer.kt | 3 +- .../model/KotlinCompilerSettingsSerializer.kt | 3 +- .../KotlinCommonModuleBuildTarget.kt | 12 ++ .../platforms/KotlinJsModuleBuildTarget.kt | 21 ++- .../platforms/KotlinJvmModuleBuildTarget.kt | 14 +- .../platforms/KotlinModuleBuilderTarget.kt | 5 +- 14 files changed, 208 insertions(+), 165 deletions(-) delete mode 100644 jps-plugin/src/org/jetbrains/kotlin/jps/JpsKotlinCompilerSettings.kt create mode 100644 jps-plugin/src/org/jetbrains/kotlin/jps/ModuleSettings.kt create mode 100644 jps-plugin/src/org/jetbrains/kotlin/jps/ProjectSettings.kt diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt index 09d289f0d8b..64a2ea2083e 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt @@ -20,10 +20,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil import org.jetbrains.jps.api.GlobalOptions import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY -import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments -import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments -import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments -import org.jetbrains.kotlin.cli.common.arguments.mergeBeans +import org.jetbrains.kotlin.cli.common.arguments.* import org.jetbrains.kotlin.config.CompilerSettings import org.jetbrains.kotlin.config.additionalArgumentsAsList import org.jetbrains.kotlin.daemon.client.CompileServiceSession @@ -86,6 +83,20 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { } ) + fun runK2MetadataCompiler( + commonArguments: CommonCompilerArguments, + k2MetadataArguments: K2MetadataCompilerArguments, + compilerSettings: CompilerSettings, + environment: JpsCompilerEnvironment, + sourceFiles: Collection + ) { + val arguments = mergeBeans(commonArguments, XmlSerializerUtil.createCopy(k2MetadataArguments)) + arguments.freeArgs = sourceFiles.map { it.absolutePath } + withCompilerSettings(compilerSettings) { + runCompiler(K2JVM_COMPILER, arguments, environment) + } + } + fun runK2JvmCompiler( commonArguments: CommonCompilerArguments, k2jvmArguments: K2JVMCompilerArguments, diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/JpsKotlinCompilerSettings.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/JpsKotlinCompilerSettings.kt deleted file mode 100644 index b31103196fa..00000000000 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/JpsKotlinCompilerSettings.kt +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.jps - -import org.jetbrains.jps.model.JpsProject -import org.jetbrains.jps.model.ex.JpsElementBase -import org.jetbrains.jps.model.ex.JpsElementChildRoleBase -import org.jetbrains.jps.model.module.JpsModule -import org.jetbrains.jps.model.module.JpsModuleDependency -import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments -import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments -import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments -import org.jetbrains.kotlin.cli.common.arguments.copyBean -import org.jetbrains.kotlin.config.CompilerSettings -import org.jetbrains.kotlin.config.TargetPlatformKind -import org.jetbrains.kotlin.jps.model.kotlinFacetExtension - -class JpsKotlinCompilerSettings : JpsElementBase() { - private var commonCompilerArguments: CommonCompilerArguments = CommonCompilerArguments.DummyImpl() - private var k2JvmCompilerArguments = K2JVMCompilerArguments() - private var k2JsCompilerArguments = K2JSCompilerArguments() - private var compilerSettings = CompilerSettings() - - override fun createCopy(): JpsKotlinCompilerSettings { - val copy = JpsKotlinCompilerSettings() - copy.commonCompilerArguments = this.commonCompilerArguments - copy.k2JvmCompilerArguments = this.k2JvmCompilerArguments - copy.k2JsCompilerArguments = this.k2JsCompilerArguments - copy.compilerSettings = this.compilerSettings - return copy - } - - override fun applyChanges(modified: JpsKotlinCompilerSettings) { - // do nothing - } - - companion object { - internal val ROLE = JpsElementChildRoleBase.create("Kotlin Compiler Settings") - - fun getSettings(project: JpsProject) = project.container.getChild(ROLE) ?: JpsKotlinCompilerSettings() - - fun getOrCreateSettings(project: JpsProject): JpsKotlinCompilerSettings { - var settings = project.container.getChild(ROLE) - if (settings == null) { - settings = JpsKotlinCompilerSettings() - project.container.setChild(ROLE, settings) - } - return settings - } - - fun getCommonCompilerArguments(module: JpsModule): CommonCompilerArguments { - val defaultArguments = copyBean(getSettings(module.project).commonCompilerArguments) - val facetSettings = module.kotlinFacetExtension?.settings ?: return defaultArguments - if (facetSettings.useProjectSettings) return defaultArguments - val facetArguments = facetSettings.compilerArguments ?: return defaultArguments - return copyBean(facetArguments).apply { - multiPlatform = module - .dependenciesList - .dependencies - .any { (it as? JpsModuleDependency)?.module?.targetPlatform == TargetPlatformKind.Common } - } - } - - fun setCommonCompilerArguments(project: JpsProject, commonCompilerSettings: CommonCompilerArguments) { - getOrCreateSettings(project).commonCompilerArguments = commonCompilerSettings - } - - fun getK2JvmCompilerArguments(module: JpsModule): K2JVMCompilerArguments { - val defaultArguments = copyBean(getSettings(module.project).k2JvmCompilerArguments) - val facetSettings = module.kotlinFacetExtension?.settings ?: return defaultArguments - if (facetSettings.useProjectSettings) return defaultArguments - return facetSettings.compilerArguments as? K2JVMCompilerArguments ?: defaultArguments - } - - fun setK2JvmCompilerArguments(project: JpsProject, k2JvmCompilerArguments: K2JVMCompilerArguments) { - getOrCreateSettings(project).k2JvmCompilerArguments = k2JvmCompilerArguments - } - - fun getK2JsCompilerArguments(module: JpsModule): K2JSCompilerArguments { - val defaultArguments = copyBean(getSettings(module.project).k2JsCompilerArguments) - val facetSettings = module.kotlinFacetExtension?.settings ?: return defaultArguments - if (facetSettings.useProjectSettings) return defaultArguments - return facetSettings.compilerArguments as? K2JSCompilerArguments ?: defaultArguments - } - - fun setK2JsCompilerArguments(project: JpsProject, k2JsCompilerArguments: K2JSCompilerArguments) { - getOrCreateSettings(project).k2JsCompilerArguments = k2JsCompilerArguments - } - - fun getCompilerSettings(module: JpsModule): CompilerSettings { - val defaultSettings = copyBean(getSettings(module.project).compilerSettings) - val facetSettings = module.kotlinFacetExtension?.settings ?: return defaultSettings - if (facetSettings.useProjectSettings) return defaultSettings - return facetSettings.compilerSettings ?: defaultSettings - } - - fun setCompilerSettings(project: JpsProject, compilerSettings: CompilerSettings) { - getOrCreateSettings(project).compilerSettings = compilerSettings - } - } -} - -val JpsModule.targetPlatform: TargetPlatformKind<*>? - get() = kotlinFacetExtension?.settings?.targetPlatformKind - -val JpsModule.productionOutputFilePath: String? - get() { - val facetSettings = kotlinFacetExtension?.settings ?: return null - if (facetSettings.useProjectSettings) return null - return facetSettings.productionOutputPath - } - -val JpsModule.testOutputFilePath: String? - get() { - val facetSettings = kotlinFacetExtension?.settings ?: return null - if (facetSettings.useProjectSettings) return null - return facetSettings.testOutputPath - } \ No newline at end of file diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/ModuleSettings.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/ModuleSettings.kt new file mode 100644 index 00000000000..d85c4b8af3e --- /dev/null +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/ModuleSettings.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.jps + +import org.jetbrains.jps.model.module.JpsModule +import org.jetbrains.kotlin.cli.common.arguments.* +import org.jetbrains.kotlin.config.CompilerSettings +import org.jetbrains.kotlin.config.TargetPlatformKind +import org.jetbrains.kotlin.jps.model.kotlinFacetExtension + +val JpsModule.targetPlatform: TargetPlatformKind<*>? + get() = kotlinFacetExtension?.settings?.targetPlatformKind + +val JpsModule.productionOutputFilePath: String? + get() { + val facetSettings = kotlinFacetExtension?.settings ?: return null + if (facetSettings.useProjectSettings) return null + return facetSettings.productionOutputPath + } + +val JpsModule.testOutputFilePath: String? + get() { + val facetSettings = kotlinFacetExtension?.settings ?: return null + if (facetSettings.useProjectSettings) return null + return facetSettings.testOutputPath + } + +val JpsModule.kotlinCompilerSettings: CompilerSettings + get() { + val defaultSettings = copyBean(project.kotlinCompilerSettings) + val facetSettings = kotlinFacetExtension?.settings ?: return defaultSettings + if (facetSettings.useProjectSettings) return defaultSettings + return facetSettings.compilerSettings ?: defaultSettings + } + +val JpsModule.kotlinCompilerArguments + get() = getCompilerArguments() + +val JpsModule.k2MetadataCompilerArguments + get() = getCompilerArguments() + +val JpsModule.k2JsCompilerArguments + get() = getCompilerArguments() + +val JpsModule.k2JvmCompilerArguments + get() = getCompilerArguments() + +private inline fun JpsModule.getCompilerArguments(): T { + val projectSettings = project.kotlinCompilerSettingsContainer[T::class.java] + val projectSettingsCopy = copyBean(projectSettings) + + val facetSettings = kotlinFacetExtension?.settings ?: return projectSettingsCopy + if (facetSettings.useProjectSettings) return projectSettingsCopy + return facetSettings.compilerArguments as? T ?: projectSettingsCopy +} \ No newline at end of file diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/ProjectSettings.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/ProjectSettings.kt new file mode 100644 index 00000000000..ebfe8eab250 --- /dev/null +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/ProjectSettings.kt @@ -0,0 +1,91 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.jps + +import org.jetbrains.jps.model.JpsProject +import org.jetbrains.jps.model.ex.JpsElementBase +import org.jetbrains.jps.model.ex.JpsElementChildRoleBase +import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments +import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments +import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments +import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments +import org.jetbrains.kotlin.config.CompilerSettings + +var JpsProject.kotlinCompilerSettings + get() = kotlinCompilerSettingsContainer.compilerSettings + internal set(value) { + getOrCreateSettings().compilerSettings = value + } + +var JpsProject.kotlinCommonCompilerArguments + get() = kotlinCompilerSettingsContainer.commonCompilerArguments + internal set(value) { + getOrCreateSettings().commonCompilerArguments = value + } + +var JpsProject.k2MetadataCompilerArguments + get() = kotlinCompilerSettingsContainer.k2MetadataCompilerArguments + internal set(value) { + getOrCreateSettings().k2MetadataCompilerArguments = value + } + +var JpsProject.k2JsCompilerArguments + get() = kotlinCompilerSettingsContainer.k2JsCompilerArguments + internal set(value) { + getOrCreateSettings().k2JsCompilerArguments = value + } + +var JpsProject.k2JvmCompilerArguments + get() = kotlinCompilerSettingsContainer.k2JvmCompilerArguments + internal set(value) { + getOrCreateSettings().k2JvmCompilerArguments = value + } + +internal val JpsProject.kotlinCompilerSettingsContainer + get() = container.getChild(JpsKotlinCompilerSettings.ROLE) ?: JpsKotlinCompilerSettings() + +private fun JpsProject.getOrCreateSettings(): JpsKotlinCompilerSettings { + var settings = container.getChild(JpsKotlinCompilerSettings.ROLE) + if (settings == null) { + settings = JpsKotlinCompilerSettings() + container.setChild(JpsKotlinCompilerSettings.ROLE, settings) + } + return settings +} + +class JpsKotlinCompilerSettings : JpsElementBase() { + internal var commonCompilerArguments: CommonCompilerArguments = CommonCompilerArguments.DummyImpl() + internal var k2MetadataCompilerArguments = K2MetadataCompilerArguments() + internal var k2JvmCompilerArguments = K2JVMCompilerArguments() + internal var k2JsCompilerArguments = K2JSCompilerArguments() + internal var compilerSettings = CompilerSettings() + + @Suppress("UNCHECKED_CAST") + internal operator fun get(compilerArgumentsClass: Class): T = when (compilerArgumentsClass) { + K2MetadataCompilerArguments::class.java -> k2MetadataCompilerArguments as T + K2JVMCompilerArguments::class.java -> k2JvmCompilerArguments as T + K2JSCompilerArguments::class.java -> k2JsCompilerArguments as T + else -> commonCompilerArguments as T + } + + override fun createCopy(): JpsKotlinCompilerSettings { + val copy = JpsKotlinCompilerSettings() + copy.commonCompilerArguments = this.commonCompilerArguments + copy.k2MetadataCompilerArguments = this.k2MetadataCompilerArguments + copy.k2JvmCompilerArguments = this.k2JvmCompilerArguments + copy.k2JsCompilerArguments = this.k2JsCompilerArguments + copy.compilerSettings = this.compilerSettings + return copy + } + + override fun applyChanges(modified: JpsKotlinCompilerSettings) { + // do nothing + } + + companion object { + internal val ROLE = JpsElementChildRoleBase.create("Kotlin Compiler Settings") + } +} \ No newline at end of file diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/JpsUtils.java b/jps-plugin/src/org/jetbrains/kotlin/jps/build/JpsUtils.java index 31e3cbe62f5..a1c3d0c0551 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/JpsUtils.java +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/JpsUtils.java @@ -27,7 +27,8 @@ import org.jetbrains.jps.model.library.JpsLibraryRoot; import org.jetbrains.jps.model.library.JpsOrderRootType; import org.jetbrains.jps.util.JpsPathUtil; import org.jetbrains.kotlin.config.TargetPlatformKind; -import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettingsKt; +import org.jetbrains.kotlin.jps.ModuleSettingsKt; +import org.jetbrains.kotlin.jps.ProjectSettingsKt; import org.jetbrains.kotlin.utils.LibraryUtils; import java.util.Map; @@ -58,7 +59,7 @@ class JpsUtils { } private static boolean isJsKotlinModuleImpl(@NotNull ModuleBuildTarget target) { - TargetPlatformKind targetPlatform = JpsKotlinCompilerSettingsKt.getTargetPlatform(target.getModule()); + TargetPlatformKind targetPlatform = ModuleSettingsKt.getTargetPlatform(target.getModule()); if (targetPlatform != null) return targetPlatform == TargetPlatformKind.JavaScript.INSTANCE; Set libraries = getAllDependencies(target).getLibraries(); diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index 81b6e20bf0f..3f3e5481c85 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -54,7 +54,7 @@ import org.jetbrains.kotlin.config.CompilerRunnerConstants.INTERNAL_ERROR_PREFIX import org.jetbrains.kotlin.daemon.common.isDaemonEnabled import org.jetbrains.kotlin.incremental.* import org.jetbrains.kotlin.incremental.components.LookupTracker -import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings +import org.jetbrains.kotlin.jps.kotlinCompilerArguments import org.jetbrains.kotlin.jps.incremental.* import org.jetbrains.kotlin.jps.platforms.KotlinJsModuleBuildTarget import org.jetbrains.kotlin.jps.platforms.kotlinData @@ -507,7 +507,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { } private fun compilerArgumentsForChunk(chunk: ModuleChunk): CommonCompilerArguments = - JpsKotlinCompilerSettings.getCommonCompilerArguments(chunk.representativeTarget().module) + chunk.representativeTarget().module.kotlinCompilerArguments private fun doCompileModuleChunk( allCompiledFiles: MutableSet, chunk: ModuleChunk, commonArguments: CommonCompilerArguments, context: CompileContext, diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/model/Kotlin2JsCompilerArgumentsSerializer.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/model/Kotlin2JsCompilerArgumentsSerializer.kt index a40d96775a1..3e99dfb09f5 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/model/Kotlin2JsCompilerArgumentsSerializer.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/model/Kotlin2JsCompilerArgumentsSerializer.kt @@ -20,11 +20,12 @@ import org.jetbrains.jps.model.JpsProject import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings +import org.jetbrains.kotlin.jps.k2JsCompilerArguments internal class Kotlin2JsCompilerArgumentsSerializer : BaseJpsCompilerSettingsSerializer( KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION, ::K2JSCompilerArguments ) { override fun onLoad(project: JpsProject, settings: K2JSCompilerArguments) { - JpsKotlinCompilerSettings.setK2JsCompilerArguments(project, settings) + project.k2JsCompilerArguments = settings } } diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/model/Kotlin2JvmCompilerArgumentsSerializer.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/model/Kotlin2JvmCompilerArgumentsSerializer.kt index f0c95a2604e..52c73a904df 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/model/Kotlin2JvmCompilerArgumentsSerializer.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/model/Kotlin2JvmCompilerArgumentsSerializer.kt @@ -20,11 +20,12 @@ import org.jetbrains.jps.model.JpsProject import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings +import org.jetbrains.kotlin.jps.k2JvmCompilerArguments internal class Kotlin2JvmCompilerArgumentsSerializer : BaseJpsCompilerSettingsSerializer( KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION, ::K2JVMCompilerArguments ) { override fun onLoad(project: JpsProject, settings: K2JVMCompilerArguments) { - JpsKotlinCompilerSettings.setK2JvmCompilerArguments(project, settings) + project.k2JvmCompilerArguments = settings } } diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/model/KotlinCommonCompilerArgumentsSerializer.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/model/KotlinCommonCompilerArgumentsSerializer.kt index 928233f1d6d..f50dfaf98b3 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/model/KotlinCommonCompilerArgumentsSerializer.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/model/KotlinCommonCompilerArgumentsSerializer.kt @@ -22,12 +22,13 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.setApiVersionToLanguageVersionIfNeeded import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings +import org.jetbrains.kotlin.jps.kotlinCommonCompilerArguments internal class KotlinCommonCompilerArgumentsSerializer : BaseJpsCompilerSettingsSerializer( KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION, CommonCompilerArguments::DummyImpl ) { override fun onLoad(project: JpsProject, settings: CommonCompilerArguments.DummyImpl) { settings.setApiVersionToLanguageVersionIfNeeded() - JpsKotlinCompilerSettings.setCommonCompilerArguments(project, settings) + project.kotlinCommonCompilerArguments = settings } } diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/model/KotlinCompilerSettingsSerializer.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/model/KotlinCompilerSettingsSerializer.kt index 62e90253631..5dd48230116 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/model/KotlinCompilerSettingsSerializer.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/model/KotlinCompilerSettingsSerializer.kt @@ -20,11 +20,12 @@ import org.jetbrains.jps.model.JpsProject import org.jetbrains.kotlin.config.CompilerSettings import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMPILER_SETTINGS_SECTION import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings +import org.jetbrains.kotlin.jps.kotlinCompilerSettings internal class KotlinCompilerSettingsSerializer : BaseJpsCompilerSettingsSerializer( KOTLIN_COMPILER_SETTINGS_SECTION, ::CompilerSettings ) { override fun onLoad(project: JpsProject, settings: CompilerSettings) { - JpsKotlinCompilerSettings.setCompilerSettings(project, settings) + project.kotlinCompilerSettings = settings } } diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinCommonModuleBuildTarget.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinCommonModuleBuildTarget.kt index 4f1e3681714..5bd1f84de02 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinCommonModuleBuildTarget.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinCommonModuleBuildTarget.kt @@ -13,10 +13,14 @@ import org.jetbrains.jps.incremental.CompileContext import org.jetbrains.jps.incremental.ModuleBuildTarget import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment +import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner +import org.jetbrains.kotlin.jps.k2MetadataCompilerArguments +import org.jetbrains.kotlin.jps.kotlinCompilerSettings import java.io.File class KotlinCommonModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : KotlinModuleBuilderTarget(jpsModuleBuildTarget) { + override fun compileModuleChunk( allCompiledFiles: MutableSet, chunk: ModuleChunk, @@ -29,6 +33,14 @@ class KotlinCommonModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : require(chunk.representativeTarget() == jpsModuleBuildTarget) if (reportAndSkipCircular(chunk, environment)) return false + JpsKotlinCompilerRunner().runK2MetadataCompiler( + commonArguments, + module.k2MetadataCompilerArguments, + module.kotlinCompilerSettings, + environment, + sources + ) + // TODO: Compile metadata return false } diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinJsModuleBuildTarget.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinJsModuleBuildTarget.kt index a0a1eef3557..e8b31d4ad0b 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinJsModuleBuildTarget.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinJsModuleBuildTarget.kt @@ -17,9 +17,7 @@ import org.jetbrains.jps.util.JpsPathUtil import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner -import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings -import org.jetbrains.kotlin.jps.productionOutputFilePath -import org.jetbrains.kotlin.jps.testOutputFilePath +import org.jetbrains.kotlin.jps.* import org.jetbrains.kotlin.utils.JsLibraryUtils import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils.JS_EXT import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils.META_JS_SUFFIX @@ -27,9 +25,6 @@ import java.io.File import java.net.URI class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : KotlinModuleBuilderTarget(jpsModuleBuildTarget) { - val jsCompilerArguments - get() = JpsKotlinCompilerSettings.getK2JsCompilerArguments(module) - val outputFile get() = explicitOutputPath?.let { File(it) } ?: implicitOutputFile @@ -101,13 +96,15 @@ class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotli val sources = sources if (sources.isEmpty()) return false + val k2JsCompilerArguments = module.k2JsCompilerArguments + // Compiler starts to produce path relative to base dirs in source maps if at least one statement is true: // 1) base dirs are specified; // 2) prefix is specified (i.e. non-empty) // Otherwise compiler produces paths relative to source maps location. // We don't have UI to configure base dirs, but we have UI to configure prefix. // If prefix is not specified (empty) in UI, we want to produce paths relative to source maps location - val sourceRoots = if (jsCompilerArguments.sourceMapPrefix.isNullOrBlank()) { + val sourceRoots = if (k2JsCompilerArguments.sourceMapPrefix.isNullOrBlank()) { emptyList() } else { module.contentRootsList.urls @@ -125,8 +122,8 @@ class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotli val compilerRunner = JpsKotlinCompilerRunner() compilerRunner.runK2JsCompiler( commonArguments, - jsCompilerArguments, - compilerSettings, + k2JsCompilerArguments, + module.kotlinCompilerSettings, environment, sources, sourceRoots, @@ -143,11 +140,11 @@ class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotli } private fun copyJsLibraryFilesIfNeeded() { - if (compilerSettings.copyJsLibraryFiles) { - val outputLibraryRuntimeDirectory = File(outputDir, compilerSettings.outputDirectoryForJsLibraryFiles).absolutePath + if (module.kotlinCompilerSettings.copyJsLibraryFiles) { + val outputLibraryRuntimeDirectory = File(outputDir, module.kotlinCompilerSettings.outputDirectoryForJsLibraryFiles).absolutePath JsLibraryUtils.copyJsFilesFromLibraries( libraryFiles, outputLibraryRuntimeDirectory, - copySourceMap = jsCompilerArguments.sourceMap + copySourceMap = module.k2JsCompilerArguments.sourceMap ) } } diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinJvmModuleBuildTarget.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinJvmModuleBuildTarget.kt index 83a2dacaf21..2774f24dc38 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinJvmModuleBuildTarget.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinJvmModuleBuildTarget.kt @@ -13,7 +13,6 @@ import com.intellij.util.containers.MultiMap import com.intellij.util.io.URLUtil import org.jetbrains.jps.ModuleChunk import org.jetbrains.jps.builders.DirtyFilesHolder -import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor import org.jetbrains.jps.incremental.CompileContext import org.jetbrains.jps.incremental.ModuleBuildTarget @@ -25,8 +24,9 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner import org.jetbrains.kotlin.config.IncrementalCompilation -import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings import org.jetbrains.kotlin.jps.build.* +import org.jetbrains.kotlin.jps.k2JvmCompilerArguments +import org.jetbrains.kotlin.jps.kotlinCompilerSettings import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder import java.io.File import java.io.IOException @@ -74,8 +74,6 @@ class KotlinJvmModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotl } val module = chunk.representativeTarget().module - val k2JvmArguments = JpsKotlinCompilerSettings.getK2JvmCompilerArguments(module) - val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(module) KotlinBuilder.LOG.debug("Compiling to JVM ${filesToCompile.values().size} files" + (if (totalRemovedFiles == 0) "" else " ($totalRemovedFiles removed files)") @@ -83,7 +81,13 @@ class KotlinJvmModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotl try { val compilerRunner = JpsKotlinCompilerRunner() - compilerRunner.runK2JvmCompiler(commonArguments, k2JvmArguments, compilerSettings, environment, moduleFile) + compilerRunner.runK2JvmCompiler( + commonArguments, + module.k2JvmCompilerArguments, + module.kotlinCompilerSettings, + environment, + moduleFile + ) } finally { if (System.getProperty("kotlin.jps.delete.module.file.after.build") != "false") { moduleFile.delete() diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinModuleBuilderTarget.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinModuleBuilderTarget.kt index eb9948d596b..77bd36c7eb7 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinModuleBuilderTarget.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/platforms/KotlinModuleBuilderTarget.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings import org.jetbrains.kotlin.jps.build.KotlinSourceFileCollector +import org.jetbrains.kotlin.jps.kotlinCompilerSettings import org.jetbrains.kotlin.jps.model.kotlinFacetExtension import org.jetbrains.kotlin.jps.productionOutputFilePath import org.jetbrains.kotlin.jps.testOutputFilePath @@ -51,8 +52,6 @@ abstract class KotlinModuleBuilderTarget(val jpsModuleBuildTarget: ModuleBuildTa return TargetId(name, jpsModuleBuildTarget.targetType.typeId) } - val kotlinFacetExtension by lazy { module.kotlinFacetExtension } - val outputDir by lazy { val explicitOutputPath = if (isTests) module.testOutputFilePath else module.productionOutputFilePath val explicitOutputDir = explicitOutputPath?.let { File(it).absoluteFile.parentFile } @@ -61,8 +60,6 @@ abstract class KotlinModuleBuilderTarget(val jpsModuleBuildTarget: ModuleBuildTa ?: throw ProjectBuildException("No output directory found for " + this) } - val compilerSettings by lazy { JpsKotlinCompilerSettings.getCompilerSettings(module) } - val friendBuildTargets: List get() { val result = mutableListOf()