jps: Refactor module/project settings getters/setters
(cherry picked from commit d29ffa0)
Original commit: a390fc36e2
This commit is contained in:
@@ -20,10 +20,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil
|
|||||||
import org.jetbrains.jps.api.GlobalOptions
|
import org.jetbrains.jps.api.GlobalOptions
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
|
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.*
|
||||||
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.config.CompilerSettings
|
import org.jetbrains.kotlin.config.CompilerSettings
|
||||||
import org.jetbrains.kotlin.config.additionalArgumentsAsList
|
import org.jetbrains.kotlin.config.additionalArgumentsAsList
|
||||||
import org.jetbrains.kotlin.daemon.client.CompileServiceSession
|
import org.jetbrains.kotlin.daemon.client.CompileServiceSession
|
||||||
@@ -86,6 +83,20 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun runK2MetadataCompiler(
|
||||||
|
commonArguments: CommonCompilerArguments,
|
||||||
|
k2MetadataArguments: K2MetadataCompilerArguments,
|
||||||
|
compilerSettings: CompilerSettings,
|
||||||
|
environment: JpsCompilerEnvironment,
|
||||||
|
sourceFiles: Collection<File>
|
||||||
|
) {
|
||||||
|
val arguments = mergeBeans(commonArguments, XmlSerializerUtil.createCopy(k2MetadataArguments))
|
||||||
|
arguments.freeArgs = sourceFiles.map { it.absolutePath }
|
||||||
|
withCompilerSettings(compilerSettings) {
|
||||||
|
runCompiler(K2JVM_COMPILER, arguments, environment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun runK2JvmCompiler(
|
fun runK2JvmCompiler(
|
||||||
commonArguments: CommonCompilerArguments,
|
commonArguments: CommonCompilerArguments,
|
||||||
k2jvmArguments: K2JVMCompilerArguments,
|
k2jvmArguments: K2JVMCompilerArguments,
|
||||||
|
|||||||
@@ -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<JpsKotlinCompilerSettings>() {
|
|
||||||
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<JpsKotlinCompilerSettings>("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
|
|
||||||
}
|
|
||||||
@@ -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<CommonCompilerArguments>()
|
||||||
|
|
||||||
|
val JpsModule.k2MetadataCompilerArguments
|
||||||
|
get() = getCompilerArguments<K2MetadataCompilerArguments>()
|
||||||
|
|
||||||
|
val JpsModule.k2JsCompilerArguments
|
||||||
|
get() = getCompilerArguments<K2JSCompilerArguments>()
|
||||||
|
|
||||||
|
val JpsModule.k2JvmCompilerArguments
|
||||||
|
get() = getCompilerArguments<K2JVMCompilerArguments>()
|
||||||
|
|
||||||
|
private inline fun <reified T : CommonCompilerArguments> 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
|
||||||
|
}
|
||||||
@@ -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<JpsKotlinCompilerSettings>() {
|
||||||
|
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 <T : CommonCompilerArguments> get(compilerArgumentsClass: Class<T>): 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<JpsKotlinCompilerSettings>("Kotlin Compiler Settings")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,7 +27,8 @@ import org.jetbrains.jps.model.library.JpsLibraryRoot;
|
|||||||
import org.jetbrains.jps.model.library.JpsOrderRootType;
|
import org.jetbrains.jps.model.library.JpsOrderRootType;
|
||||||
import org.jetbrains.jps.util.JpsPathUtil;
|
import org.jetbrains.jps.util.JpsPathUtil;
|
||||||
import org.jetbrains.kotlin.config.TargetPlatformKind;
|
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 org.jetbrains.kotlin.utils.LibraryUtils;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -58,7 +59,7 @@ class JpsUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isJsKotlinModuleImpl(@NotNull ModuleBuildTarget target) {
|
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;
|
if (targetPlatform != null) return targetPlatform == TargetPlatformKind.JavaScript.INSTANCE;
|
||||||
|
|
||||||
Set<JpsLibrary> libraries = getAllDependencies(target).getLibraries();
|
Set<JpsLibrary> libraries = getAllDependencies(target).getLibraries();
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ import org.jetbrains.kotlin.config.CompilerRunnerConstants.INTERNAL_ERROR_PREFIX
|
|||||||
import org.jetbrains.kotlin.daemon.common.isDaemonEnabled
|
import org.jetbrains.kotlin.daemon.common.isDaemonEnabled
|
||||||
import org.jetbrains.kotlin.incremental.*
|
import org.jetbrains.kotlin.incremental.*
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
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.incremental.*
|
||||||
import org.jetbrains.kotlin.jps.platforms.KotlinJsModuleBuildTarget
|
import org.jetbrains.kotlin.jps.platforms.KotlinJsModuleBuildTarget
|
||||||
import org.jetbrains.kotlin.jps.platforms.kotlinData
|
import org.jetbrains.kotlin.jps.platforms.kotlinData
|
||||||
@@ -507,7 +507,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun compilerArgumentsForChunk(chunk: ModuleChunk): CommonCompilerArguments =
|
private fun compilerArgumentsForChunk(chunk: ModuleChunk): CommonCompilerArguments =
|
||||||
JpsKotlinCompilerSettings.getCommonCompilerArguments(chunk.representativeTarget().module)
|
chunk.representativeTarget().module.kotlinCompilerArguments
|
||||||
|
|
||||||
private fun doCompileModuleChunk(
|
private fun doCompileModuleChunk(
|
||||||
allCompiledFiles: MutableSet<File>, chunk: ModuleChunk, commonArguments: CommonCompilerArguments, context: CompileContext,
|
allCompiledFiles: MutableSet<File>, chunk: ModuleChunk, commonArguments: CommonCompilerArguments, context: CompileContext,
|
||||||
|
|||||||
+2
-1
@@ -20,11 +20,12 @@ import org.jetbrains.jps.model.JpsProject
|
|||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||||
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION
|
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION
|
||||||
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
||||||
|
import org.jetbrains.kotlin.jps.k2JsCompilerArguments
|
||||||
|
|
||||||
internal class Kotlin2JsCompilerArgumentsSerializer : BaseJpsCompilerSettingsSerializer<K2JSCompilerArguments>(
|
internal class Kotlin2JsCompilerArgumentsSerializer : BaseJpsCompilerSettingsSerializer<K2JSCompilerArguments>(
|
||||||
KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION, ::K2JSCompilerArguments
|
KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION, ::K2JSCompilerArguments
|
||||||
) {
|
) {
|
||||||
override fun onLoad(project: JpsProject, settings: K2JSCompilerArguments) {
|
override fun onLoad(project: JpsProject, settings: K2JSCompilerArguments) {
|
||||||
JpsKotlinCompilerSettings.setK2JsCompilerArguments(project, settings)
|
project.k2JsCompilerArguments = settings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -20,11 +20,12 @@ import org.jetbrains.jps.model.JpsProject
|
|||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||||
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION
|
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION
|
||||||
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
||||||
|
import org.jetbrains.kotlin.jps.k2JvmCompilerArguments
|
||||||
|
|
||||||
internal class Kotlin2JvmCompilerArgumentsSerializer : BaseJpsCompilerSettingsSerializer<K2JVMCompilerArguments>(
|
internal class Kotlin2JvmCompilerArgumentsSerializer : BaseJpsCompilerSettingsSerializer<K2JVMCompilerArguments>(
|
||||||
KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION, ::K2JVMCompilerArguments
|
KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION, ::K2JVMCompilerArguments
|
||||||
) {
|
) {
|
||||||
override fun onLoad(project: JpsProject, settings: K2JVMCompilerArguments) {
|
override fun onLoad(project: JpsProject, settings: K2JVMCompilerArguments) {
|
||||||
JpsKotlinCompilerSettings.setK2JvmCompilerArguments(project, settings)
|
project.k2JvmCompilerArguments = settings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -22,12 +22,13 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
|||||||
import org.jetbrains.kotlin.cli.common.arguments.setApiVersionToLanguageVersionIfNeeded
|
import org.jetbrains.kotlin.cli.common.arguments.setApiVersionToLanguageVersionIfNeeded
|
||||||
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION
|
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION
|
||||||
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
||||||
|
import org.jetbrains.kotlin.jps.kotlinCommonCompilerArguments
|
||||||
|
|
||||||
internal class KotlinCommonCompilerArgumentsSerializer : BaseJpsCompilerSettingsSerializer<CommonCompilerArguments.DummyImpl>(
|
internal class KotlinCommonCompilerArgumentsSerializer : BaseJpsCompilerSettingsSerializer<CommonCompilerArguments.DummyImpl>(
|
||||||
KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION, CommonCompilerArguments::DummyImpl
|
KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION, CommonCompilerArguments::DummyImpl
|
||||||
) {
|
) {
|
||||||
override fun onLoad(project: JpsProject, settings: CommonCompilerArguments.DummyImpl) {
|
override fun onLoad(project: JpsProject, settings: CommonCompilerArguments.DummyImpl) {
|
||||||
settings.setApiVersionToLanguageVersionIfNeeded()
|
settings.setApiVersionToLanguageVersionIfNeeded()
|
||||||
JpsKotlinCompilerSettings.setCommonCompilerArguments(project, settings)
|
project.kotlinCommonCompilerArguments = settings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -20,11 +20,12 @@ import org.jetbrains.jps.model.JpsProject
|
|||||||
import org.jetbrains.kotlin.config.CompilerSettings
|
import org.jetbrains.kotlin.config.CompilerSettings
|
||||||
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMPILER_SETTINGS_SECTION
|
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMPILER_SETTINGS_SECTION
|
||||||
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
||||||
|
import org.jetbrains.kotlin.jps.kotlinCompilerSettings
|
||||||
|
|
||||||
internal class KotlinCompilerSettingsSerializer : BaseJpsCompilerSettingsSerializer<CompilerSettings>(
|
internal class KotlinCompilerSettingsSerializer : BaseJpsCompilerSettingsSerializer<CompilerSettings>(
|
||||||
KOTLIN_COMPILER_SETTINGS_SECTION, ::CompilerSettings
|
KOTLIN_COMPILER_SETTINGS_SECTION, ::CompilerSettings
|
||||||
) {
|
) {
|
||||||
override fun onLoad(project: JpsProject, settings: CompilerSettings) {
|
override fun onLoad(project: JpsProject, settings: CompilerSettings) {
|
||||||
JpsKotlinCompilerSettings.setCompilerSettings(project, settings)
|
project.kotlinCompilerSettings = settings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
@@ -13,10 +13,14 @@ import org.jetbrains.jps.incremental.CompileContext
|
|||||||
import org.jetbrains.jps.incremental.ModuleBuildTarget
|
import org.jetbrains.jps.incremental.ModuleBuildTarget
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||||
import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment
|
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
|
import java.io.File
|
||||||
|
|
||||||
class KotlinCommonModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) :
|
class KotlinCommonModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) :
|
||||||
KotlinModuleBuilderTarget(jpsModuleBuildTarget) {
|
KotlinModuleBuilderTarget(jpsModuleBuildTarget) {
|
||||||
|
|
||||||
override fun compileModuleChunk(
|
override fun compileModuleChunk(
|
||||||
allCompiledFiles: MutableSet<File>,
|
allCompiledFiles: MutableSet<File>,
|
||||||
chunk: ModuleChunk,
|
chunk: ModuleChunk,
|
||||||
@@ -29,6 +33,14 @@ class KotlinCommonModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) :
|
|||||||
require(chunk.representativeTarget() == jpsModuleBuildTarget)
|
require(chunk.representativeTarget() == jpsModuleBuildTarget)
|
||||||
if (reportAndSkipCircular(chunk, environment)) return false
|
if (reportAndSkipCircular(chunk, environment)) return false
|
||||||
|
|
||||||
|
JpsKotlinCompilerRunner().runK2MetadataCompiler(
|
||||||
|
commonArguments,
|
||||||
|
module.k2MetadataCompilerArguments,
|
||||||
|
module.kotlinCompilerSettings,
|
||||||
|
environment,
|
||||||
|
sources
|
||||||
|
)
|
||||||
|
|
||||||
// TODO: Compile metadata
|
// TODO: Compile metadata
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ import org.jetbrains.jps.util.JpsPathUtil
|
|||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||||
import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment
|
import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment
|
||||||
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
|
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
|
||||||
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
import org.jetbrains.kotlin.jps.*
|
||||||
import org.jetbrains.kotlin.jps.productionOutputFilePath
|
|
||||||
import org.jetbrains.kotlin.jps.testOutputFilePath
|
|
||||||
import org.jetbrains.kotlin.utils.JsLibraryUtils
|
import org.jetbrains.kotlin.utils.JsLibraryUtils
|
||||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils.JS_EXT
|
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils.JS_EXT
|
||||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils.META_JS_SUFFIX
|
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils.META_JS_SUFFIX
|
||||||
@@ -27,9 +25,6 @@ import java.io.File
|
|||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
|
||||||
class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : KotlinModuleBuilderTarget(jpsModuleBuildTarget) {
|
class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : KotlinModuleBuilderTarget(jpsModuleBuildTarget) {
|
||||||
val jsCompilerArguments
|
|
||||||
get() = JpsKotlinCompilerSettings.getK2JsCompilerArguments(module)
|
|
||||||
|
|
||||||
val outputFile
|
val outputFile
|
||||||
get() = explicitOutputPath?.let { File(it) } ?: implicitOutputFile
|
get() = explicitOutputPath?.let { File(it) } ?: implicitOutputFile
|
||||||
|
|
||||||
@@ -101,13 +96,15 @@ class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotli
|
|||||||
val sources = sources
|
val sources = sources
|
||||||
if (sources.isEmpty()) return false
|
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:
|
// Compiler starts to produce path relative to base dirs in source maps if at least one statement is true:
|
||||||
// 1) base dirs are specified;
|
// 1) base dirs are specified;
|
||||||
// 2) prefix is specified (i.e. non-empty)
|
// 2) prefix is specified (i.e. non-empty)
|
||||||
// Otherwise compiler produces paths relative to source maps location.
|
// 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.
|
// 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
|
// 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()
|
emptyList()
|
||||||
} else {
|
} else {
|
||||||
module.contentRootsList.urls
|
module.contentRootsList.urls
|
||||||
@@ -125,8 +122,8 @@ class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotli
|
|||||||
val compilerRunner = JpsKotlinCompilerRunner()
|
val compilerRunner = JpsKotlinCompilerRunner()
|
||||||
compilerRunner.runK2JsCompiler(
|
compilerRunner.runK2JsCompiler(
|
||||||
commonArguments,
|
commonArguments,
|
||||||
jsCompilerArguments,
|
k2JsCompilerArguments,
|
||||||
compilerSettings,
|
module.kotlinCompilerSettings,
|
||||||
environment,
|
environment,
|
||||||
sources,
|
sources,
|
||||||
sourceRoots,
|
sourceRoots,
|
||||||
@@ -143,11 +140,11 @@ class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotli
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun copyJsLibraryFilesIfNeeded() {
|
private fun copyJsLibraryFilesIfNeeded() {
|
||||||
if (compilerSettings.copyJsLibraryFiles) {
|
if (module.kotlinCompilerSettings.copyJsLibraryFiles) {
|
||||||
val outputLibraryRuntimeDirectory = File(outputDir, compilerSettings.outputDirectoryForJsLibraryFiles).absolutePath
|
val outputLibraryRuntimeDirectory = File(outputDir, module.kotlinCompilerSettings.outputDirectoryForJsLibraryFiles).absolutePath
|
||||||
JsLibraryUtils.copyJsFilesFromLibraries(
|
JsLibraryUtils.copyJsFilesFromLibraries(
|
||||||
libraryFiles, outputLibraryRuntimeDirectory,
|
libraryFiles, outputLibraryRuntimeDirectory,
|
||||||
copySourceMap = jsCompilerArguments.sourceMap
|
copySourceMap = module.k2JsCompilerArguments.sourceMap
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import com.intellij.util.containers.MultiMap
|
|||||||
import com.intellij.util.io.URLUtil
|
import com.intellij.util.io.URLUtil
|
||||||
import org.jetbrains.jps.ModuleChunk
|
import org.jetbrains.jps.ModuleChunk
|
||||||
import org.jetbrains.jps.builders.DirtyFilesHolder
|
import org.jetbrains.jps.builders.DirtyFilesHolder
|
||||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType
|
|
||||||
import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor
|
import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor
|
||||||
import org.jetbrains.jps.incremental.CompileContext
|
import org.jetbrains.jps.incremental.CompileContext
|
||||||
import org.jetbrains.jps.incremental.ModuleBuildTarget
|
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.JpsCompilerEnvironment
|
||||||
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
|
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
|
||||||
import org.jetbrains.kotlin.config.IncrementalCompilation
|
import org.jetbrains.kotlin.config.IncrementalCompilation
|
||||||
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
|
||||||
import org.jetbrains.kotlin.jps.build.*
|
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 org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@@ -74,8 +74,6 @@ class KotlinJvmModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotl
|
|||||||
}
|
}
|
||||||
|
|
||||||
val module = chunk.representativeTarget().module
|
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"
|
KotlinBuilder.LOG.debug("Compiling to JVM ${filesToCompile.values().size} files"
|
||||||
+ (if (totalRemovedFiles == 0) "" else " ($totalRemovedFiles removed files)")
|
+ (if (totalRemovedFiles == 0) "" else " ($totalRemovedFiles removed files)")
|
||||||
@@ -83,7 +81,13 @@ class KotlinJvmModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotl
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
val compilerRunner = JpsKotlinCompilerRunner()
|
val compilerRunner = JpsKotlinCompilerRunner()
|
||||||
compilerRunner.runK2JvmCompiler(commonArguments, k2JvmArguments, compilerSettings, environment, moduleFile)
|
compilerRunner.runK2JvmCompiler(
|
||||||
|
commonArguments,
|
||||||
|
module.k2JvmCompilerArguments,
|
||||||
|
module.kotlinCompilerSettings,
|
||||||
|
environment,
|
||||||
|
moduleFile
|
||||||
|
)
|
||||||
} finally {
|
} finally {
|
||||||
if (System.getProperty("kotlin.jps.delete.module.file.after.build") != "false") {
|
if (System.getProperty("kotlin.jps.delete.module.file.after.build") != "false") {
|
||||||
moduleFile.delete()
|
moduleFile.delete()
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
|||||||
import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment
|
import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment
|
||||||
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
||||||
import org.jetbrains.kotlin.jps.build.KotlinSourceFileCollector
|
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.model.kotlinFacetExtension
|
||||||
import org.jetbrains.kotlin.jps.productionOutputFilePath
|
import org.jetbrains.kotlin.jps.productionOutputFilePath
|
||||||
import org.jetbrains.kotlin.jps.testOutputFilePath
|
import org.jetbrains.kotlin.jps.testOutputFilePath
|
||||||
@@ -51,8 +52,6 @@ abstract class KotlinModuleBuilderTarget(val jpsModuleBuildTarget: ModuleBuildTa
|
|||||||
return TargetId(name, jpsModuleBuildTarget.targetType.typeId)
|
return TargetId(name, jpsModuleBuildTarget.targetType.typeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
val kotlinFacetExtension by lazy { module.kotlinFacetExtension }
|
|
||||||
|
|
||||||
val outputDir by lazy {
|
val outputDir by lazy {
|
||||||
val explicitOutputPath = if (isTests) module.testOutputFilePath else module.productionOutputFilePath
|
val explicitOutputPath = if (isTests) module.testOutputFilePath else module.productionOutputFilePath
|
||||||
val explicitOutputDir = explicitOutputPath?.let { File(it).absoluteFile.parentFile }
|
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)
|
?: throw ProjectBuildException("No output directory found for " + this)
|
||||||
}
|
}
|
||||||
|
|
||||||
val compilerSettings by lazy { JpsKotlinCompilerSettings.getCompilerSettings(module) }
|
|
||||||
|
|
||||||
val friendBuildTargets: List<KotlinModuleBuilderTarget>
|
val friendBuildTargets: List<KotlinModuleBuilderTarget>
|
||||||
get() {
|
get() {
|
||||||
val result = mutableListOf<KotlinModuleBuilderTarget>()
|
val result = mutableListOf<KotlinModuleBuilderTarget>()
|
||||||
|
|||||||
Reference in New Issue
Block a user