Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.targets
import org.jetbrains.jps.ModuleChunk
import org.jetbrains.jps.builders.storage.BuildDataPaths
import org.jetbrains.jps.incremental.CompileContext
import org.jetbrains.jps.incremental.ModuleBuildTarget
import org.jetbrains.jps.incremental.ModuleLevelBuilder
import org.jetbrains.jps.incremental.ProjectBuildException
import org.jetbrains.jps.model.java.JpsJavaClasspathKind
import org.jetbrains.jps.model.java.JpsJavaExtensionService
import org.jetbrains.jps.model.module.JpsModule
import org.jetbrains.jps.util.JpsPathUtil
import org.jetbrains.kotlin.build.*
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.incremental.ChangesCollector
import org.jetbrains.kotlin.incremental.ExpectActualTrackerImpl
import org.jetbrains.kotlin.incremental.components.*
import org.jetbrains.kotlin.jps.KotlinJpsBundle
import org.jetbrains.kotlin.jps.build.*
import org.jetbrains.kotlin.jps.incremental.CacheAttributesDiff
import org.jetbrains.kotlin.jps.incremental.JpsIncrementalCache
import org.jetbrains.kotlin.jps.incremental.loadDiff
import org.jetbrains.kotlin.jps.incremental.localCacheVersionManager
import org.jetbrains.kotlin.jps.model.productionOutputFilePath
import org.jetbrains.kotlin.jps.model.testOutputFilePath
import org.jetbrains.kotlin.modules.TargetId
import org.jetbrains.kotlin.progress.CompilationCanceledException
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.utils.addIfNotNull
import java.io.File
import java.nio.file.Files
/**
* Properties and actions for Kotlin test / production module build target.
*/
abstract class KotlinModuleBuildTarget internal constructor(
val kotlinContext: KotlinCompileContext,
val jpsModuleBuildTarget: ModuleBuildTarget
) {
/**
* Note: beware of using this context for getting compilation round dependent data:
* for example groovy can provide temp source roots with stubs, and it will be visible
* only in round local compile context.
*
* TODO(1.2.80): got rid of jpsGlobalContext and replace it with kotlinContext
*/
val jpsGlobalContext: CompileContext
get() = kotlinContext.jpsContext
// Initialized in KotlinCompileContext.loadTargets
lateinit var chunk: KotlinChunk
abstract val globalLookupCacheId: String
abstract val isIncrementalCompilationEnabled: Boolean
open fun isEnabled(chunkCompilerArguments: Lazy): Boolean = true
@Suppress("LeakingThis")
val localCacheVersionManager = localCacheVersionManager(
kotlinContext.dataPaths.getTargetDataRoot(jpsModuleBuildTarget).toPath(),
isIncrementalCompilationEnabled
)
val initialLocalCacheAttributesDiff: CacheAttributesDiff<*> = localCacheVersionManager.loadDiff()
val module: JpsModule
get() = jpsModuleBuildTarget.module
val isTests: Boolean
get() = jpsModuleBuildTarget.isTests
open val targetId: TargetId
get() {
// Since IDEA 2016 each gradle source root is imported as a separate module.
// One gradle module X is imported as two JPS modules:
// 1. X-production with one production target;
// 2. X-test with one test target.
// This breaks kotlin code since internal members' names are mangled using module name.
// For example, a declaration of a function 'f' in 'X-production' becomes 'fXProduction', but a call 'f' in 'X-test' becomes 'fXTest()'.
// The workaround is to replace a name of such test target with the name of corresponding production module.
// See KT-11993.
val name = relatedProductionModule?.name ?: jpsModuleBuildTarget.id
return TargetId(name, jpsModuleBuildTarget.targetType.typeId)
}
val outputDir by lazy {
val explicitOutputPath = if (isTests) module.testOutputFilePath else module.productionOutputFilePath
val explicitOutputDir = explicitOutputPath?.let { File(it).absoluteFile.parentFile }
return@lazy explicitOutputDir
?: jpsModuleBuildTarget.outputDir
?: throw ProjectBuildException(KotlinJpsBundle.message("error.message.no.output.directory.found.for.0", this))
}
val friendBuildTargets: List>
get() {
val result = mutableListOf>()
if (isTests) {
result.addIfNotNull(kotlinContext.targetsBinding[module.productionBuildTarget])
result.addIfNotNull(kotlinContext.targetsBinding[relatedProductionModule?.productionBuildTarget])
}
return result.filter { it.sources.isNotEmpty() }
}
val friendOutputDirs: List
get() = friendBuildTargets.mapNotNull {
JpsJavaExtensionService.getInstance().getOutputDirectory(it.module, false)
}
private val relatedProductionModule: JpsModule?
get() = JpsJavaExtensionService.getInstance().getTestModuleProperties(module)?.productionModule
data class Dependency(
val src: KotlinModuleBuildTarget<*>,
val target: KotlinModuleBuildTarget<*>,
val exported: Boolean
)
// TODO(1.2.80): try replace allDependencies with KotlinChunk.collectDependentChunksRecursivelyExportedOnly
val allDependencies by lazy {
JpsJavaExtensionService.dependencies(module).recursively().exportedOnly()
.includedIn(JpsJavaClasspathKind.compile(isTests))
}
/**
* All sources of this target (including non dirty).
*
* Lazy initialization is required since value is required only in rare cases.
*
* Before first round initialized lazily based on global context.
* This is required for friend build targets, when friends are not compiled in this build run.
*
* Lazy value will be invalidated on each round (should be recalculated based on round local context).
* Update required since source roots can be changed, for example groovy can provide new temporary source roots with stubs.
*
* Ugly delegation to lazy is used to capture local compile context and reset calculated value.
*/
val sources: Map
get() = _sources.value
@Volatile
private var _sources: Lazy