jps: common modules metadata compiler
(cherry picked from commit cde333d)
This commit is contained in:
@@ -62,6 +62,8 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
|
|||||||
import org.jetbrains.kotlin.incremental.withIC
|
import org.jetbrains.kotlin.incremental.withIC
|
||||||
import org.jetbrains.kotlin.jps.model.JpsKotlinCompilerSettings
|
import org.jetbrains.kotlin.jps.model.JpsKotlinCompilerSettings
|
||||||
import org.jetbrains.kotlin.jps.build.KotlinJpsBuildTest.LibraryDependency.*
|
import org.jetbrains.kotlin.jps.build.KotlinJpsBuildTest.LibraryDependency.*
|
||||||
|
import org.jetbrains.kotlin.jps.model.kotlinCommonCompilerArguments
|
||||||
|
import org.jetbrains.kotlin.jps.model.kotlinCompilerArguments
|
||||||
import org.jetbrains.kotlin.jps.platforms.KotlinJsModuleBuildTarget
|
import org.jetbrains.kotlin.jps.platforms.KotlinJsModuleBuildTarget
|
||||||
import org.jetbrains.kotlin.jps.platforms.clearKotlinModuleBuildTargetDataBindings
|
import org.jetbrains.kotlin.jps.platforms.clearKotlinModuleBuildTargetDataBindings
|
||||||
import org.jetbrains.kotlin.jps.platforms.kotlinData
|
import org.jetbrains.kotlin.jps.platforms.kotlinData
|
||||||
@@ -525,9 +527,9 @@ open class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
|||||||
|
|
||||||
assertEquals(1, myProject.modules.size)
|
assertEquals(1, myProject.modules.size)
|
||||||
val module = myProject.modules.first()
|
val module = myProject.modules.first()
|
||||||
val args = JpsKotlinCompilerSettings.getCommonCompilerArguments(module)
|
val args = module.kotlinCompilerArguments
|
||||||
args.apiVersion = "1.2"
|
args.apiVersion = "1.2"
|
||||||
JpsKotlinCompilerSettings.setCommonCompilerArguments(myProject, args)
|
myProject.kotlinCommonCompilerArguments = args
|
||||||
|
|
||||||
buildAllModules().assertSuccessful()
|
buildAllModules().assertSuccessful()
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -27,6 +27,8 @@ import kotlin.reflect.KMutableProperty1
|
|||||||
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS
|
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS
|
||||||
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_ENABLED_PROPERTY
|
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_ENABLED_PROPERTY
|
||||||
import org.jetbrains.kotlin.daemon.common.isDaemonEnabled
|
import org.jetbrains.kotlin.daemon.common.isDaemonEnabled
|
||||||
|
import org.jetbrains.kotlin.jps.model.kotlinCommonCompilerArguments
|
||||||
|
import org.jetbrains.kotlin.jps.model.kotlinCompilerArguments
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
|
class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
|
||||||
@@ -138,11 +140,11 @@ class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
|
|||||||
|
|
||||||
assertEquals(1, myProject.modules.size)
|
assertEquals(1, myProject.modules.size)
|
||||||
val module = myProject.modules.first()
|
val module = myProject.modules.first()
|
||||||
val args = JpsKotlinCompilerSettings.getCommonCompilerArguments(module)
|
val args = module.kotlinCompilerArguments
|
||||||
|
|
||||||
fun setVersion(newVersion: String) {
|
fun setVersion(newVersion: String) {
|
||||||
versionProperty.set(args, newVersion)
|
versionProperty.set(args, newVersion)
|
||||||
JpsKotlinCompilerSettings.setCommonCompilerArguments(myProject, args)
|
myProject.kotlinCommonCompilerArguments = args
|
||||||
}
|
}
|
||||||
|
|
||||||
assertNull(args.apiVersion)
|
assertNull(args.apiVersion)
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
val arguments = mergeBeans(commonArguments, XmlSerializerUtil.createCopy(k2MetadataArguments))
|
val arguments = mergeBeans(commonArguments, XmlSerializerUtil.createCopy(k2MetadataArguments))
|
||||||
arguments.freeArgs = sourceFiles.map { it.absolutePath }
|
arguments.freeArgs = sourceFiles.map { it.absolutePath }
|
||||||
withCompilerSettings(compilerSettings) {
|
withCompilerSettings(compilerSettings) {
|
||||||
runCompiler(K2JVM_COMPILER, arguments, environment)
|
runCompiler(K2METADATA_COMPILER, arguments, environment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
compilerSettings: CompilerSettings,
|
compilerSettings: CompilerSettings,
|
||||||
environment: JpsCompilerEnvironment,
|
environment: JpsCompilerEnvironment,
|
||||||
sourceFiles: Collection<File>,
|
sourceFiles: Collection<File>,
|
||||||
sourceRoots: Collection<File>,
|
sourceMapRoots: Collection<File>,
|
||||||
libraries: List<String>,
|
libraries: List<String>,
|
||||||
friendModules: List<String>,
|
friendModules: List<String>,
|
||||||
outputFile: File
|
outputFile: File
|
||||||
@@ -130,7 +130,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
|
|
||||||
setupK2JsArguments(outputFile, sourceFiles, libraries, friendModules, arguments)
|
setupK2JsArguments(outputFile, sourceFiles, libraries, friendModules, arguments)
|
||||||
if (arguments.sourceMap) {
|
if (arguments.sourceMap) {
|
||||||
arguments.sourceMapBaseDirs = sourceRoots.joinToString(File.pathSeparator) { it.path }
|
arguments.sourceMapBaseDirs = sourceMapRoots.joinToString(File.pathSeparator) { it.path }
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("K2JS: arguments after setup" + ArgumentUtils.convertArgumentsToStringList(arguments))
|
log.debug("K2JS: arguments after setup" + ArgumentUtils.convertArgumentsToStringList(arguments))
|
||||||
|
|||||||
@@ -274,7 +274,8 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
||||||
outputConsumer: ModuleLevelBuilder.OutputConsumer
|
outputConsumer: ModuleLevelBuilder.OutputConsumer
|
||||||
): ModuleLevelBuilder.ExitCode {
|
): ModuleLevelBuilder.ExitCode {
|
||||||
if (chunk.isDummy(context)) return NOTHING_DONE
|
if (chunk.isDummy(context))
|
||||||
|
return NOTHING_DONE
|
||||||
|
|
||||||
val messageCollector = MessageCollectorAdapter(context)
|
val messageCollector = MessageCollectorAdapter(context)
|
||||||
val fsOperations = FSOperationsHelper(context, chunk, LOG)
|
val fsOperations = FSOperationsHelper(context, chunk, LOG)
|
||||||
@@ -359,7 +360,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
val start = System.nanoTime()
|
val start = System.nanoTime()
|
||||||
val outputItemCollector = doCompileModuleChunk(
|
val outputItemCollector = doCompileModuleChunk(
|
||||||
allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder,
|
allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder,
|
||||||
environment, filesToCompile, incrementalCaches, project
|
environment, filesToCompile, incrementalCaches, fsOperations
|
||||||
)
|
)
|
||||||
|
|
||||||
statisticsLogger.registerStatistic(chunk, System.nanoTime() - start)
|
statisticsLogger.registerStatistic(chunk, System.nanoTime() - start)
|
||||||
@@ -510,10 +511,15 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
chunk.representativeTarget().module.kotlinCompilerArguments
|
chunk.representativeTarget().module.kotlinCompilerArguments
|
||||||
|
|
||||||
private fun doCompileModuleChunk(
|
private fun doCompileModuleChunk(
|
||||||
allCompiledFiles: MutableSet<File>, chunk: ModuleChunk, commonArguments: CommonCompilerArguments, context: CompileContext,
|
allCompiledFiles: MutableSet<File>,
|
||||||
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>, environment: JpsCompilerEnvironment,
|
chunk: ModuleChunk,
|
||||||
filesToCompile: MultiMap<ModuleBuildTarget, File>, incrementalCaches: Map<ModuleBuildTarget, IncrementalJvmCache>,
|
commonArguments: CommonCompilerArguments,
|
||||||
project: JpsProject
|
context: CompileContext,
|
||||||
|
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
||||||
|
environment: JpsCompilerEnvironment,
|
||||||
|
filesToCompile: MultiMap<ModuleBuildTarget, File>,
|
||||||
|
incrementalCaches: Map<ModuleBuildTarget, IncrementalJvmCache>,
|
||||||
|
fsOperations: FSOperationsHelper
|
||||||
): OutputItemsCollector? {
|
): OutputItemsCollector? {
|
||||||
|
|
||||||
val representativeTarget = chunk.representativeTarget()
|
val representativeTarget = chunk.representativeTarget()
|
||||||
@@ -545,7 +551,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
|
|
||||||
val isDoneSomething = representativeTarget.kotlinData?.compileModuleChunk(
|
val isDoneSomething = representativeTarget.kotlinData?.compileModuleChunk(
|
||||||
allCompiledFiles, chunk, commonArguments, context,
|
allCompiledFiles, chunk, commonArguments, context,
|
||||||
dirtyFilesHolder, environment, filesToCompile
|
dirtyFilesHolder, environment, filesToCompile, fsOperations
|
||||||
) ?: false
|
) ?: false
|
||||||
|
|
||||||
return if (isDoneSomething) environment.outputItemsCollector else null
|
return if (isDoneSomething) environment.outputItemsCollector else null
|
||||||
@@ -561,7 +567,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
register(LookupTracker::class.java, lookupTracker)
|
register(LookupTracker::class.java, lookupTracker)
|
||||||
register(
|
register(
|
||||||
IncrementalCompilationComponents::class.java,
|
IncrementalCompilationComponents::class.java,
|
||||||
IncrementalCompilationComponentsImpl(incrementalCaches.mapKeys { it.key.kotlinData!!.moduleId })
|
IncrementalCompilationComponentsImpl(incrementalCaches.mapKeys { it.key.kotlinData!!.targetId })
|
||||||
)
|
)
|
||||||
register(CompilationCanceledStatus::class.java, object : CompilationCanceledStatus {
|
register(CompilationCanceledStatus::class.java, object : CompilationCanceledStatus {
|
||||||
override fun checkCanceled() {
|
override fun checkCanceled() {
|
||||||
@@ -628,9 +634,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
fun SimpleOutputItem.target() =
|
fun SimpleOutputItem.target() =
|
||||||
sourceFiles.firstOrNull()?.let { sourceToTarget[it] } ?: chunk.targets.singleOrNull {
|
sourceFiles.firstOrNull()?.let { sourceToTarget[it] } ?: chunk.targets.singleOrNull {
|
||||||
it.outputDir?.let {
|
it.outputDir?.let {
|
||||||
outputFile.startsWith(
|
outputFile.startsWith(it)
|
||||||
it
|
|
||||||
)
|
|
||||||
} ?: false
|
} ?: false
|
||||||
} ?: representativeTarget
|
} ?: representativeTarget
|
||||||
|
|
||||||
@@ -870,14 +874,15 @@ fun getAllCompiledFilesContainer(context: CompileContext): MutableSet<File> {
|
|||||||
// TODO: investigate thread safety
|
// TODO: investigate thread safety
|
||||||
private val PROCESSED_TARGETS_WITH_REMOVED_FILES = Key.create<MutableSet<ModuleBuildTarget>>("_processed_targets_with_removed_files_")
|
private val PROCESSED_TARGETS_WITH_REMOVED_FILES = Key.create<MutableSet<ModuleBuildTarget>>("_processed_targets_with_removed_files_")
|
||||||
|
|
||||||
fun getProcessedTargetsWithRemovedFilesContainer(context: CompileContext): MutableSet<ModuleBuildTarget> {
|
val CompileContext.processedTargetsWithRemovedFilesContainer: MutableSet<ModuleBuildTarget>
|
||||||
var set = PROCESSED_TARGETS_WITH_REMOVED_FILES.get(context)
|
get() {
|
||||||
if (set == null) {
|
var set = PROCESSED_TARGETS_WITH_REMOVED_FILES.get(this)
|
||||||
set = HashSet()
|
if (set == null) {
|
||||||
PROCESSED_TARGETS_WITH_REMOVED_FILES.set(context, set)
|
set = HashSet()
|
||||||
|
PROCESSED_TARGETS_WITH_REMOVED_FILES.set(this, set)
|
||||||
|
}
|
||||||
|
return set
|
||||||
}
|
}
|
||||||
return set
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun hasKotlinDirtyOrRemovedFiles(
|
private fun hasKotlinDirtyOrRemovedFiles(
|
||||||
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
||||||
|
|||||||
@@ -50,11 +50,6 @@ object KotlinSourceFileCollector {
|
|||||||
.getRemovedFiles(target)
|
.getRemovedFiles(target)
|
||||||
.mapNotNull { if (FileUtilRt.extensionEquals(it, "kt")) File(it) else null }
|
.mapNotNull { if (FileUtilRt.extensionEquals(it, "kt")) File(it) else null }
|
||||||
|
|
||||||
private fun getRelevantSourceRoots(target: ModuleBuildTarget): Iterable<JpsModuleSourceRoot> {
|
|
||||||
val sourceRootType = if (target.isTests) JavaSourceRootType.TEST_SOURCE else JavaSourceRootType.SOURCE
|
|
||||||
return target.module.getSourceRoots<JavaSourceRootProperties>(sourceRootType)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun isKotlinSourceFile(file: File): Boolean {
|
internal fun isKotlinSourceFile(file: File): Boolean {
|
||||||
return FileUtilRt.extensionEquals(file.name, "kt")
|
return FileUtilRt.extensionEquals(file.name, "kt")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,13 @@ import org.jetbrains.jps.ModuleChunk
|
|||||||
import org.jetbrains.jps.builders.DirtyFilesHolder
|
import org.jetbrains.jps.builders.DirtyFilesHolder
|
||||||
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.FSOperations
|
||||||
import org.jetbrains.jps.incremental.ModuleBuildTarget
|
import org.jetbrains.jps.incremental.ModuleBuildTarget
|
||||||
|
import org.jetbrains.jps.incremental.fs.CompilationRound
|
||||||
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.build.FSOperationsHelper
|
||||||
import org.jetbrains.kotlin.jps.model.k2MetadataCompilerArguments
|
import org.jetbrains.kotlin.jps.model.k2MetadataCompilerArguments
|
||||||
import org.jetbrains.kotlin.jps.model.kotlinCompilerSettings
|
import org.jetbrains.kotlin.jps.model.kotlinCompilerSettings
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -28,11 +31,15 @@ class KotlinCommonModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) :
|
|||||||
context: CompileContext,
|
context: CompileContext,
|
||||||
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
||||||
environment: JpsCompilerEnvironment,
|
environment: JpsCompilerEnvironment,
|
||||||
filesToCompile: MultiMap<ModuleBuildTarget, File>
|
filesToCompile: MultiMap<ModuleBuildTarget, File>,
|
||||||
|
fsOperations: FSOperationsHelper
|
||||||
): Boolean {
|
): Boolean {
|
||||||
require(chunk.representativeTarget() == jpsModuleBuildTarget)
|
require(chunk.representativeTarget() == jpsModuleBuildTarget)
|
||||||
if (reportAndSkipCircular(chunk, environment)) return false
|
if (reportAndSkipCircular(chunk, environment)) return false
|
||||||
|
|
||||||
|
// Incremental compilation is not supported, so mark all dependents as dirty
|
||||||
|
FSOperations.markDirtyRecursively(context, CompilationRound.CURRENT, chunk)
|
||||||
|
|
||||||
JpsKotlinCompilerRunner().runK2MetadataCompiler(
|
JpsKotlinCompilerRunner().runK2MetadataCompiler(
|
||||||
commonArguments,
|
commonArguments,
|
||||||
module.k2MetadataCompilerArguments,
|
module.k2MetadataCompilerArguments,
|
||||||
@@ -41,7 +48,6 @@ class KotlinCommonModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) :
|
|||||||
sources
|
sources
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Compile metadata
|
return true
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +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.build.FSOperationsHelper
|
||||||
import org.jetbrains.kotlin.jps.model.k2JsCompilerArguments
|
import org.jetbrains.kotlin.jps.model.k2JsCompilerArguments
|
||||||
import org.jetbrains.kotlin.jps.model.kotlinCompilerSettings
|
import org.jetbrains.kotlin.jps.model.kotlinCompilerSettings
|
||||||
import org.jetbrains.kotlin.jps.model.productionOutputFilePath
|
import org.jetbrains.kotlin.jps.model.productionOutputFilePath
|
||||||
@@ -28,26 +29,93 @@ import java.io.File
|
|||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
|
||||||
class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : KotlinModuleBuilderTarget(jpsModuleBuildTarget) {
|
class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : KotlinModuleBuilderTarget(jpsModuleBuildTarget) {
|
||||||
|
override fun compileModuleChunk(
|
||||||
|
allCompiledFiles: MutableSet<File>,
|
||||||
|
chunk: ModuleChunk,
|
||||||
|
commonArguments: CommonCompilerArguments,
|
||||||
|
context: CompileContext,
|
||||||
|
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
||||||
|
environment: JpsCompilerEnvironment,
|
||||||
|
filesToCompile: MultiMap<ModuleBuildTarget, File>,
|
||||||
|
fsOperations: FSOperationsHelper
|
||||||
|
): Boolean {
|
||||||
|
require(chunk.representativeTarget() == jpsModuleBuildTarget)
|
||||||
|
if (reportAndSkipCircular(chunk, environment)) return false
|
||||||
|
|
||||||
|
val sources = sources
|
||||||
|
if (sources.isEmpty()) return false
|
||||||
|
|
||||||
|
val libraries = libraryFiles + dependenciesMetaFiles
|
||||||
|
|
||||||
|
JpsKotlinCompilerRunner().runK2JsCompiler(
|
||||||
|
commonArguments,
|
||||||
|
module.k2JsCompilerArguments,
|
||||||
|
module.kotlinCompilerSettings,
|
||||||
|
environment,
|
||||||
|
sources,
|
||||||
|
sourceMapRoots,
|
||||||
|
libraries,
|
||||||
|
friendBuildTargetsMetaFiles,
|
||||||
|
outputFile
|
||||||
|
)
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun doAfterBuild() {
|
||||||
|
copyJsLibraryFilesIfNeeded()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun copyJsLibraryFilesIfNeeded() {
|
||||||
|
if (module.kotlinCompilerSettings.copyJsLibraryFiles) {
|
||||||
|
val outputLibraryRuntimeDirectory = File(outputDir, module.kotlinCompilerSettings.outputDirectoryForJsLibraryFiles).absolutePath
|
||||||
|
JsLibraryUtils.copyJsFilesFromLibraries(
|
||||||
|
libraryFiles, outputLibraryRuntimeDirectory,
|
||||||
|
copySourceMap = module.k2JsCompilerArguments.sourceMap
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val sourceMapRoots: List<File>
|
||||||
|
get() {
|
||||||
|
// 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
|
||||||
|
return if (module.k2JsCompilerArguments.sourceMapPrefix.isNullOrBlank()) emptyList()
|
||||||
|
else module.contentRootsList.urls
|
||||||
|
.map { URI.create(it) }
|
||||||
|
.filter { it.scheme == "file" }
|
||||||
|
.map { File(it.path) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val friendBuildTargetsMetaFiles
|
||||||
|
get() = friendBuildTargets.mapNotNull {
|
||||||
|
(it as? KotlinJsModuleBuildTarget)?.outputMetaFile?.absoluteFile?.toString()
|
||||||
|
}
|
||||||
|
|
||||||
val outputFile
|
val outputFile
|
||||||
get() = explicitOutputPath?.let { File(it) } ?: implicitOutputFile
|
get() = explicitOutputPath?.let { File(it) } ?: implicitOutputFile
|
||||||
|
|
||||||
val explicitOutputPath
|
private val explicitOutputPath
|
||||||
get() = if (isTests) module.testOutputFilePath else module.productionOutputFilePath
|
get() = if (isTests) module.testOutputFilePath else module.productionOutputFilePath
|
||||||
|
|
||||||
val implicitOutputFile: File
|
private val implicitOutputFile: File
|
||||||
get() {
|
get() {
|
||||||
val suffix = if (isTests) "_test" else ""
|
val suffix = if (isTests) "_test" else ""
|
||||||
|
|
||||||
return File(outputDir, module.name + suffix + JS_EXT)
|
return File(outputDir, module.name + suffix + JS_EXT)
|
||||||
}
|
}
|
||||||
|
|
||||||
val outputFileBaseName: String
|
private val outputFileBaseName: String
|
||||||
get() = outputFile.path.substringBeforeLast(".")
|
get() = outputFile.path.substringBeforeLast(".")
|
||||||
|
|
||||||
val outputMetaFile: File
|
val outputMetaFile: File
|
||||||
get() = File(outputFileBaseName + META_JS_SUFFIX)
|
get() = File(outputFileBaseName + META_JS_SUFFIX)
|
||||||
|
|
||||||
val libraryFiles: List<String>
|
private val libraryFiles: List<String>
|
||||||
get() = mutableListOf<String>().also { result ->
|
get() = mutableListOf<String>().also { result ->
|
||||||
for (library in allDependencies.libraries) {
|
for (library in allDependencies.libraries) {
|
||||||
for (root in library.getRoots(JpsOrderRootType.COMPILED)) {
|
for (root in library.getRoots(JpsOrderRootType.COMPILED)) {
|
||||||
@@ -56,12 +124,12 @@ class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val dependenciesMetaFiles: List<String>
|
private val dependenciesMetaFiles: List<String>
|
||||||
get() = mutableListOf<String>().also { result ->
|
get() = mutableListOf<String>().also { result ->
|
||||||
allDependencies.processModules { module ->
|
allDependencies.processModules { module ->
|
||||||
if (isTests) addDependencyMetaFile(module, result, isTests = true)
|
if (isTests) addDependencyMetaFile(module, result, isTests = true)
|
||||||
|
|
||||||
// production targets should be also added as dependency to test targets
|
// note: production targets should be also added as dependency to test targets
|
||||||
addDependencyMetaFile(module, result, isTests = false)
|
addDependencyMetaFile(module, result, isTests = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,72 +151,4 @@ class KotlinJsModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun compileModuleChunk(
|
|
||||||
allCompiledFiles: MutableSet<File>,
|
|
||||||
chunk: ModuleChunk,
|
|
||||||
commonArguments: CommonCompilerArguments,
|
|
||||||
context: CompileContext,
|
|
||||||
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
|
||||||
environment: JpsCompilerEnvironment,
|
|
||||||
filesToCompile: MultiMap<ModuleBuildTarget, File>
|
|
||||||
): Boolean {
|
|
||||||
require(chunk.representativeTarget() == jpsModuleBuildTarget)
|
|
||||||
if (reportAndSkipCircular(chunk, environment)) return false
|
|
||||||
|
|
||||||
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 (k2JsCompilerArguments.sourceMapPrefix.isNullOrBlank()) {
|
|
||||||
emptyList()
|
|
||||||
} else {
|
|
||||||
module.contentRootsList.urls
|
|
||||||
.map { URI.create(it) }
|
|
||||||
.filter { it.scheme == "file" }
|
|
||||||
.map { File(it.path) }
|
|
||||||
}
|
|
||||||
|
|
||||||
val friendPaths = friendBuildTargets.mapNotNull {
|
|
||||||
(it as? KotlinJsModuleBuildTarget)?.outputMetaFile?.absoluteFile?.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
val libraries = libraryFiles + dependenciesMetaFiles
|
|
||||||
|
|
||||||
val compilerRunner = JpsKotlinCompilerRunner()
|
|
||||||
compilerRunner.runK2JsCompiler(
|
|
||||||
commonArguments,
|
|
||||||
k2JsCompilerArguments,
|
|
||||||
module.kotlinCompilerSettings,
|
|
||||||
environment,
|
|
||||||
sources,
|
|
||||||
sourceRoots,
|
|
||||||
libraries,
|
|
||||||
friendPaths,
|
|
||||||
outputFile
|
|
||||||
)
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun doAfterBuild() {
|
|
||||||
copyJsLibraryFilesIfNeeded()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun copyJsLibraryFilesIfNeeded() {
|
|
||||||
if (module.kotlinCompilerSettings.copyJsLibraryFiles) {
|
|
||||||
val outputLibraryRuntimeDirectory = File(outputDir, module.kotlinCompilerSettings.outputDirectoryForJsLibraryFiles).absolutePath
|
|
||||||
JsLibraryUtils.copyJsFilesFromLibraries(
|
|
||||||
libraryFiles, outputLibraryRuntimeDirectory,
|
|
||||||
copySourceMap = module.k2JsCompilerArguments.sourceMap
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,10 @@ 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.build.*
|
import org.jetbrains.kotlin.jps.build.FSOperationsHelper
|
||||||
|
import org.jetbrains.kotlin.jps.build.KotlinBuilder
|
||||||
|
import org.jetbrains.kotlin.jps.build.KotlinSourceFileCollector
|
||||||
|
import org.jetbrains.kotlin.jps.build.processedTargetsWithRemovedFilesContainer
|
||||||
import org.jetbrains.kotlin.jps.model.k2JvmCompilerArguments
|
import org.jetbrains.kotlin.jps.model.k2JvmCompilerArguments
|
||||||
import org.jetbrains.kotlin.jps.model.kotlinCompilerSettings
|
import org.jetbrains.kotlin.jps.model.kotlinCompilerSettings
|
||||||
import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder
|
import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder
|
||||||
@@ -39,7 +42,8 @@ class KotlinJvmModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotl
|
|||||||
context: CompileContext,
|
context: CompileContext,
|
||||||
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
||||||
environment: JpsCompilerEnvironment,
|
environment: JpsCompilerEnvironment,
|
||||||
filesToCompile: MultiMap<ModuleBuildTarget, File>
|
filesToCompile: MultiMap<ModuleBuildTarget, File>,
|
||||||
|
fsOperations: FSOperationsHelper
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (chunk.modules.size > 1) {
|
if (chunk.modules.size > 1) {
|
||||||
environment.messageCollector.report(
|
environment.messageCollector.report(
|
||||||
@@ -52,7 +56,7 @@ class KotlinJvmModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotl
|
|||||||
|
|
||||||
allCompiledFiles.addAll(filesToCompile.values())
|
allCompiledFiles.addAll(filesToCompile.values())
|
||||||
|
|
||||||
val processedTargetsWithRemoved = getProcessedTargetsWithRemovedFilesContainer(context)
|
val processedTargetsWithRemoved = context.processedTargetsWithRemovedFilesContainer
|
||||||
|
|
||||||
var totalRemovedFiles = 0
|
var totalRemovedFiles = 0
|
||||||
for (target in chunk.targets) {
|
for (target in chunk.targets) {
|
||||||
@@ -131,7 +135,7 @@ class KotlinJvmModuleBuildTarget(jpsModuleBuildTarget: ModuleBuildTarget) : Kotl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val kotlinModuleId = target.moduleId
|
val kotlinModuleId = target.targetId
|
||||||
builder.addModule(
|
builder.addModule(
|
||||||
kotlinModuleId.name,
|
kotlinModuleId.name,
|
||||||
outputDir.absolutePath,
|
outputDir.absolutePath,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.jps.platforms
|
package org.jetbrains.kotlin.jps.platforms
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtilRt
|
|
||||||
import com.intellij.util.containers.MultiMap
|
import com.intellij.util.containers.MultiMap
|
||||||
import org.jetbrains.jps.ModuleChunk
|
import org.jetbrains.jps.ModuleChunk
|
||||||
import org.jetbrains.jps.builders.DirtyFilesHolder
|
import org.jetbrains.jps.builders.DirtyFilesHolder
|
||||||
@@ -21,6 +20,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.cli.common.messages.CompilerMessageSeverity
|
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.build.FSOperationsHelper
|
||||||
import org.jetbrains.kotlin.jps.build.KotlinSourceFileCollector
|
import org.jetbrains.kotlin.jps.build.KotlinSourceFileCollector
|
||||||
import org.jetbrains.kotlin.jps.model.kotlinFacet
|
import org.jetbrains.kotlin.jps.model.kotlinFacet
|
||||||
import org.jetbrains.kotlin.jps.model.productionOutputFilePath
|
import org.jetbrains.kotlin.jps.model.productionOutputFilePath
|
||||||
@@ -29,6 +29,9 @@ import org.jetbrains.kotlin.modules.TargetId
|
|||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Properties and actions for Kotlin test / production module build target.
|
||||||
|
*/
|
||||||
abstract class KotlinModuleBuilderTarget(val jpsModuleBuildTarget: ModuleBuildTarget) {
|
abstract class KotlinModuleBuilderTarget(val jpsModuleBuildTarget: ModuleBuildTarget) {
|
||||||
val module: JpsModule
|
val module: JpsModule
|
||||||
get() = jpsModuleBuildTarget.module
|
get() = jpsModuleBuildTarget.module
|
||||||
@@ -36,7 +39,7 @@ abstract class KotlinModuleBuilderTarget(val jpsModuleBuildTarget: ModuleBuildTa
|
|||||||
val isTests: Boolean
|
val isTests: Boolean
|
||||||
get() = jpsModuleBuildTarget.isTests
|
get() = jpsModuleBuildTarget.isTests
|
||||||
|
|
||||||
val moduleId: TargetId
|
val targetId: TargetId
|
||||||
get() {
|
get() {
|
||||||
// Since IDEA 2016 each gradle source root is imported as a separate module.
|
// Since IDEA 2016 each gradle source root is imported as a separate module.
|
||||||
// One gradle module X is imported as two JPS modules:
|
// One gradle module X is imported as two JPS modules:
|
||||||
@@ -75,7 +78,7 @@ abstract class KotlinModuleBuilderTarget(val jpsModuleBuildTarget: ModuleBuildTa
|
|||||||
JpsJavaExtensionService.getInstance().getOutputDirectory(it.module, false)
|
JpsJavaExtensionService.getInstance().getOutputDirectory(it.module, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
val relatedProductionModule: JpsModule?
|
private val relatedProductionModule: JpsModule?
|
||||||
get() = JpsJavaExtensionService.getInstance().getTestModuleProperties(module)?.productionModule
|
get() = JpsJavaExtensionService.getInstance().getTestModuleProperties(module)?.productionModule
|
||||||
|
|
||||||
val allDependencies by lazy {
|
val allDependencies by lazy {
|
||||||
@@ -95,11 +98,6 @@ abstract class KotlinModuleBuilderTarget(val jpsModuleBuildTarget: ModuleBuildTa
|
|||||||
.map { ModuleBuildTarget(it, isTests).kotlinData!! }
|
.map { ModuleBuildTarget(it, isTests).kotlinData!! }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRemovedKotlinFiles(dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>): List<File> =
|
|
||||||
dirtyFilesHolder
|
|
||||||
.getRemovedFiles(jpsModuleBuildTarget)
|
|
||||||
.mapNotNull { if (FileUtilRt.extensionEquals(it, "kt")) File(it) else null }
|
|
||||||
|
|
||||||
val sources by lazy {
|
val sources by lazy {
|
||||||
mutableListOf<File>().also { result ->
|
mutableListOf<File>().also { result ->
|
||||||
// add all common libs sources
|
// add all common libs sources
|
||||||
@@ -139,7 +137,8 @@ abstract class KotlinModuleBuilderTarget(val jpsModuleBuildTarget: ModuleBuildTa
|
|||||||
context: CompileContext,
|
context: CompileContext,
|
||||||
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
||||||
environment: JpsCompilerEnvironment,
|
environment: JpsCompilerEnvironment,
|
||||||
filesToCompile: MultiMap<ModuleBuildTarget, File>
|
filesToCompile: MultiMap<ModuleBuildTarget, File>,
|
||||||
|
fsOperations: FSOperationsHelper
|
||||||
): Boolean
|
): Boolean
|
||||||
|
|
||||||
protected fun reportAndSkipCircular(
|
protected fun reportAndSkipCircular(
|
||||||
|
|||||||
Reference in New Issue
Block a user