Kotlin Facet: Use facet configuration in JPS build
This commit is contained in:
@@ -19,10 +19,14 @@ package org.jetbrains.kotlin.jps
|
|||||||
import org.jetbrains.jps.model.JpsProject
|
import org.jetbrains.jps.model.JpsProject
|
||||||
import org.jetbrains.jps.model.ex.JpsElementBase
|
import org.jetbrains.jps.model.ex.JpsElementBase
|
||||||
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase
|
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase
|
||||||
|
import org.jetbrains.jps.model.module.JpsModule
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
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.CompilerSettings
|
||||||
|
import org.jetbrains.kotlin.config.JVMPlatform
|
||||||
|
import org.jetbrains.kotlin.jps.model.kotlinFacetExtension
|
||||||
|
|
||||||
class JpsKotlinCompilerSettings : JpsElementBase<JpsKotlinCompilerSettings>() {
|
class JpsKotlinCompilerSettings : JpsElementBase<JpsKotlinCompilerSettings>() {
|
||||||
private var commonCompilerArguments: CommonCompilerArguments = CommonCompilerArguments.DummyImpl()
|
private var commonCompilerArguments: CommonCompilerArguments = CommonCompilerArguments.DummyImpl()
|
||||||
@@ -57,25 +61,45 @@ class JpsKotlinCompilerSettings : JpsElementBase<JpsKotlinCompilerSettings>() {
|
|||||||
return settings
|
return settings
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCommonCompilerArguments(project: JpsProject) = getSettings(project).commonCompilerArguments
|
fun getCommonCompilerArguments(module: JpsModule): CommonCompilerArguments {
|
||||||
|
val defaultArguments = getSettings(module.project).commonCompilerArguments
|
||||||
|
val facetSettings = module.kotlinFacetExtension?.settings ?: return defaultArguments
|
||||||
|
val (languageLevel, apiLevel) = facetSettings.versionInfo
|
||||||
|
return facetSettings.compilerInfo.commonCompilerArguments?.apply {
|
||||||
|
languageVersion = languageLevel?.description
|
||||||
|
apiVersion = apiLevel?.description
|
||||||
|
} ?: defaultArguments
|
||||||
|
}
|
||||||
|
|
||||||
fun setCommonCompilerArguments(project: JpsProject, commonCompilerSettings: CommonCompilerArguments) {
|
fun setCommonCompilerArguments(project: JpsProject, commonCompilerSettings: CommonCompilerArguments) {
|
||||||
getOrCreateSettings(project).commonCompilerArguments = commonCompilerSettings
|
getOrCreateSettings(project).commonCompilerArguments = commonCompilerSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getK2JvmCompilerArguments(project: JpsProject) = getSettings(project).k2JvmCompilerArguments
|
fun getK2JvmCompilerArguments(module: JpsModule): K2JVMCompilerArguments {
|
||||||
|
val defaultArguments = getSettings(module.project).k2JvmCompilerArguments
|
||||||
|
val facetSettings = module.kotlinFacetExtension?.settings ?: return defaultArguments
|
||||||
|
val targetPlatform = facetSettings.versionInfo.targetPlatformKindKind as? JVMPlatform ?: return defaultArguments
|
||||||
|
return copyBean(defaultArguments).apply {
|
||||||
|
jvmTarget = targetPlatform.version.description
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun setK2JvmCompilerArguments(project: JpsProject, k2JvmCompilerArguments: K2JVMCompilerArguments) {
|
fun setK2JvmCompilerArguments(project: JpsProject, k2JvmCompilerArguments: K2JVMCompilerArguments) {
|
||||||
getOrCreateSettings(project).k2JvmCompilerArguments = k2JvmCompilerArguments
|
getOrCreateSettings(project).k2JvmCompilerArguments = k2JvmCompilerArguments
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getK2JsCompilerArguments(project: JpsProject) = getSettings(project).k2JsCompilerArguments
|
fun getK2JsCompilerArguments(module: JpsModule): K2JSCompilerArguments {
|
||||||
|
return module.kotlinFacetExtension?.settings?.compilerInfo?.k2jsCompilerArguments
|
||||||
|
?: getSettings(module.project).k2JsCompilerArguments
|
||||||
|
}
|
||||||
|
|
||||||
fun setK2JsCompilerArguments(project: JpsProject, k2JsCompilerArguments: K2JSCompilerArguments) {
|
fun setK2JsCompilerArguments(project: JpsProject, k2JsCompilerArguments: K2JSCompilerArguments) {
|
||||||
getOrCreateSettings(project).k2JsCompilerArguments = k2JsCompilerArguments
|
getOrCreateSettings(project).k2JsCompilerArguments = k2JsCompilerArguments
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCompilerSettings(project: JpsProject) = getSettings(project).compilerSettings
|
fun getCompilerSettings(module: JpsModule): CompilerSettings {
|
||||||
|
return module.kotlinFacetExtension?.settings?.compilerInfo?.compilerSettings ?: getSettings(module.project).compilerSettings
|
||||||
|
}
|
||||||
|
|
||||||
fun setCompilerSettings(project: JpsProject, compilerSettings: CompilerSettings) {
|
fun setCompilerSettings(project: JpsProject, compilerSettings: CompilerSettings) {
|
||||||
getOrCreateSettings(project).compilerSettings = compilerSettings
|
getOrCreateSettings(project).compilerSettings = compilerSettings
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
return ABORT
|
return ABORT
|
||||||
}
|
}
|
||||||
|
|
||||||
val commonArguments = JpsKotlinCompilerSettings.getCommonCompilerArguments(project)
|
val commonArguments = JpsKotlinCompilerSettings.getCommonCompilerArguments(chunk.representativeTarget().module)
|
||||||
commonArguments.verbose = true // Make compiler report source to output files mapping
|
commonArguments.verbose = true // Make compiler report source to output files mapping
|
||||||
|
|
||||||
val allCompiledFiles = getAllCompiledFilesContainer(context)
|
val allCompiledFiles = getAllCompiledFilesContainer(context)
|
||||||
@@ -618,11 +618,12 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
|
|
||||||
val outputDir = KotlinBuilderModuleScriptGenerator.getOutputDirSafe(representativeTarget)
|
val outputDir = KotlinBuilderModuleScriptGenerator.getOutputDirSafe(representativeTarget)
|
||||||
|
|
||||||
val moduleName = representativeTarget.module.name
|
val representativeModule = representativeTarget.module
|
||||||
|
val moduleName = representativeModule.name
|
||||||
val outputFile = JpsJsModuleUtils.getOutputFile(outputDir, moduleName)
|
val outputFile = JpsJsModuleUtils.getOutputFile(outputDir, moduleName)
|
||||||
val libraryFiles = JpsJsModuleUtils.getLibraryFilesAndDependencies(representativeTarget)
|
val libraryFiles = JpsJsModuleUtils.getLibraryFilesAndDependencies(representativeTarget)
|
||||||
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(project)
|
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(representativeModule)
|
||||||
val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(project)
|
val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(representativeModule)
|
||||||
|
|
||||||
KotlinCompilerRunner.runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, messageCollector, environment, outputItemCollector, sourceFiles, libraryFiles, outputFile)
|
KotlinCompilerRunner.runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, messageCollector, environment, outputItemCollector, sourceFiles, libraryFiles, outputFile)
|
||||||
return outputItemCollector
|
return outputItemCollector
|
||||||
@@ -631,7 +632,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
private fun copyJsLibraryFilesIfNeeded(chunk: ModuleChunk, project: JpsProject) {
|
private fun copyJsLibraryFilesIfNeeded(chunk: ModuleChunk, project: JpsProject) {
|
||||||
val representativeTarget = chunk.representativeTarget()
|
val representativeTarget = chunk.representativeTarget()
|
||||||
val outputDir = KotlinBuilderModuleScriptGenerator.getOutputDirSafe(representativeTarget)
|
val outputDir = KotlinBuilderModuleScriptGenerator.getOutputDirSafe(representativeTarget)
|
||||||
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(project)
|
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(representativeTarget.module)
|
||||||
if (compilerSettings.copyJsLibraryFiles) {
|
if (compilerSettings.copyJsLibraryFiles) {
|
||||||
val outputLibraryRuntimeDirectory = File(outputDir, compilerSettings.outputDirectoryForJsLibraryFiles).absolutePath
|
val outputLibraryRuntimeDirectory = File(outputDir, compilerSettings.outputDirectoryForJsLibraryFiles).absolutePath
|
||||||
val libraryFilesToCopy = arrayListOf<String>()
|
val libraryFilesToCopy = arrayListOf<String>()
|
||||||
@@ -682,9 +683,9 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
val project = context.projectDescriptor.project
|
val module = chunk.representativeTarget().module
|
||||||
val k2JvmArguments = JpsKotlinCompilerSettings.getK2JvmCompilerArguments(project)
|
val k2JvmArguments = JpsKotlinCompilerSettings.getK2JvmCompilerArguments(module)
|
||||||
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(project)
|
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)")
|
||||||
|
|||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 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.model
|
||||||
|
|
||||||
|
import com.intellij.util.xmlb.XmlSerializer
|
||||||
|
import org.jdom.Element
|
||||||
|
import org.jetbrains.jps.model.JpsElement
|
||||||
|
import org.jetbrains.jps.model.module.JpsModule
|
||||||
|
import org.jetbrains.jps.model.serialization.facet.JpsFacetConfigurationSerializer
|
||||||
|
import org.jetbrains.kotlin.config.KotlinFacetSettings
|
||||||
|
|
||||||
|
object JpsKotlinFacetConfigurationSerializer : JpsFacetConfigurationSerializer<JpsKotlinFacetModuleExtension>(
|
||||||
|
JpsKotlinFacetModuleExtension.KIND,
|
||||||
|
JpsKotlinFacetModuleExtension.FACET_TYPE_ID,
|
||||||
|
JpsKotlinFacetModuleExtension.FACET_NAME
|
||||||
|
) {
|
||||||
|
override fun loadExtension(
|
||||||
|
facetConfigurationElement: Element,
|
||||||
|
name: String,
|
||||||
|
parent: JpsElement?,
|
||||||
|
module: JpsModule
|
||||||
|
): JpsKotlinFacetModuleExtension {
|
||||||
|
return JpsKotlinFacetModuleExtension(XmlSerializer.deserialize(facetConfigurationElement, KotlinFacetSettings::class.java)!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun saveExtension(
|
||||||
|
extension: JpsKotlinFacetModuleExtension?,
|
||||||
|
facetConfigurationTag: Element,
|
||||||
|
module: JpsModule
|
||||||
|
) {
|
||||||
|
XmlSerializer.serializeInto((extension as JpsKotlinFacetModuleExtension).settings, facetConfigurationTag)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 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.model
|
||||||
|
|
||||||
|
import org.jetbrains.jps.model.ex.JpsElementBase
|
||||||
|
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase
|
||||||
|
import org.jetbrains.jps.model.module.JpsModule
|
||||||
|
import org.jetbrains.kotlin.config.KotlinFacetSettings
|
||||||
|
|
||||||
|
class JpsKotlinFacetModuleExtension(settings: KotlinFacetSettings) : JpsElementBase<JpsKotlinFacetModuleExtension>() {
|
||||||
|
var settings = settings
|
||||||
|
private set
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val KIND = JpsElementChildRoleBase.create<JpsKotlinFacetModuleExtension>("kotlin facet extension")
|
||||||
|
// These must be changed in sync with KotlinFacetType.TYPE_ID and KotlinFacetType.NAME
|
||||||
|
val FACET_TYPE_ID = "kotlin-language"
|
||||||
|
val FACET_NAME = "Kotlin"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createCopy() = JpsKotlinFacetModuleExtension(settings)
|
||||||
|
|
||||||
|
override fun applyChanges(modified: JpsKotlinFacetModuleExtension) {
|
||||||
|
this.settings = modified.settings
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val JpsModule.kotlinFacetExtension: JpsKotlinFacetModuleExtension?
|
||||||
|
get() = container.getChild(JpsKotlinFacetModuleExtension.KIND)
|
||||||
@@ -19,8 +19,10 @@ package org.jetbrains.kotlin.jps.model;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;
|
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;
|
||||||
import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer;
|
import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer;
|
||||||
|
import org.jetbrains.jps.model.serialization.facet.JpsFacetConfigurationSerializer;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class KotlinModelSerializerService extends JpsModelSerializerExtension {
|
public class KotlinModelSerializerService extends JpsModelSerializerExtension {
|
||||||
@@ -32,4 +34,10 @@ public class KotlinModelSerializerService extends JpsModelSerializerExtension {
|
|||||||
new Kotlin2JsCompilerArgumentsSerializer(),
|
new Kotlin2JsCompilerArgumentsSerializer(),
|
||||||
new KotlinCompilerSettingsSerializer());
|
new KotlinCompilerSettingsSerializer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<? extends JpsFacetConfigurationSerializer<?>> getFacetConfigurationSerializers() {
|
||||||
|
return Collections.singletonList(JpsKotlinFacetConfigurationSerializer.INSTANCE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user