[Gradle] Rename ResolvedDependencyGraph to LazyResolvedConfiguration
This give better understanding of the purpose of the class ^KT-49933
This commit is contained in:
committed by
Space Team
parent
396ed3642e
commit
bf8ef74b37
+3
-3
@@ -163,7 +163,7 @@ constructor(
|
|||||||
val exportLibraries: FileCollection get() = exportLibrariesResolvedGraph?.files ?: objectFactory.fileCollection()
|
val exportLibraries: FileCollection get() = exportLibrariesResolvedGraph?.files ?: objectFactory.fileCollection()
|
||||||
|
|
||||||
private val exportLibrariesResolvedGraph = if (binary is AbstractNativeLibrary) {
|
private val exportLibrariesResolvedGraph = if (binary is AbstractNativeLibrary) {
|
||||||
ResolvedDependencyGraph(project.configurations.getByName(binary.exportConfigurationName))
|
LazyResolvedConfiguration(project.configurations.getByName(binary.exportConfigurationName))
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@@ -247,7 +247,7 @@ constructor(
|
|||||||
protected val friendModule: FileCollection = objectFactory.fileCollection().from({ compilation.friendPaths })
|
protected val friendModule: FileCollection = objectFactory.fileCollection().from({ compilation.friendPaths })
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
private val resolvedDependencyGraph = ResolvedDependencyGraph(
|
private val resolvedConfiguration = LazyResolvedConfiguration(
|
||||||
project.configurations.getByName(compilation.compileDependencyConfigurationName)
|
project.configurations.getByName(compilation.compileDependencyConfigurationName)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -315,7 +315,7 @@ constructor(
|
|||||||
settings = cacheBuilderSettings,
|
settings = cacheBuilderSettings,
|
||||||
konanPropertiesService = konanPropertiesService.get()
|
konanPropertiesService = konanPropertiesService.get()
|
||||||
)
|
)
|
||||||
addAll(cacheBuilder.buildCompilerArgs(resolvedDependencyGraph))
|
addAll(cacheBuilder.buildCompilerArgs(resolvedConfiguration))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-8
@@ -757,20 +757,20 @@ internal class CacheBuilder(
|
|||||||
get() = PARTIAL_LINKAGE in settings.toolOptions.freeCompilerArgs.get()
|
get() = PARTIAL_LINKAGE in settings.toolOptions.freeCompilerArgs.get()
|
||||||
|
|
||||||
private fun getCacheDirectory(
|
private fun getCacheDirectory(
|
||||||
resolvedDependencyGraph: ResolvedDependencyGraph,
|
resolvedConfiguration: LazyResolvedConfiguration,
|
||||||
dependency: ResolvedDependencyResult
|
dependency: ResolvedDependencyResult
|
||||||
): File = getCacheDirectory(
|
): File = getCacheDirectory(
|
||||||
rootCacheDirectory = rootCacheDirectory,
|
rootCacheDirectory = rootCacheDirectory,
|
||||||
dependency = dependency,
|
dependency = dependency,
|
||||||
artifact = null,
|
artifact = null,
|
||||||
resolvedDependencyGraph = resolvedDependencyGraph,
|
resolvedConfiguration = resolvedConfiguration,
|
||||||
partialLinkage = partialLinkage
|
partialLinkage = partialLinkage
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun needCache(libraryPath: String) =
|
private fun needCache(libraryPath: String) =
|
||||||
libraryPath.startsWith(settings.gradleUserHomeDir.absolutePath) && libraryPath.endsWith(".klib")
|
libraryPath.startsWith(settings.gradleUserHomeDir.absolutePath) && libraryPath.endsWith(".klib")
|
||||||
|
|
||||||
private fun ResolvedDependencyGraph.ensureDependencyPrecached(
|
private fun LazyResolvedConfiguration.ensureDependencyPrecached(
|
||||||
dependency: ResolvedDependencyResult,
|
dependency: ResolvedDependencyResult,
|
||||||
visitedDependencies: MutableSet<ResolvedDependencyResult>
|
visitedDependencies: MutableSet<ResolvedDependencyResult>
|
||||||
) {
|
) {
|
||||||
@@ -792,7 +792,7 @@ internal class CacheBuilder(
|
|||||||
rootCacheDirectory = rootCacheDirectory,
|
rootCacheDirectory = rootCacheDirectory,
|
||||||
dependency = dependency,
|
dependency = dependency,
|
||||||
considerArtifact = false,
|
considerArtifact = false,
|
||||||
resolvedDependencyGraph = this,
|
resolvedConfiguration = this,
|
||||||
partialLinkage = partialLinkage
|
partialLinkage = partialLinkage
|
||||||
) ?: return
|
) ?: return
|
||||||
|
|
||||||
@@ -916,17 +916,17 @@ internal class CacheBuilder(
|
|||||||
ensureCompilerProvidedLibPrecached(platformLibName, platformLibs, visitedLibs)
|
ensureCompilerProvidedLibPrecached(platformLibName, platformLibs, visitedLibs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildCompilerArgs(resolvedDependencyGraph: ResolvedDependencyGraph): List<String> = mutableListOf<String>().apply {
|
fun buildCompilerArgs(resolvedConfiguration: LazyResolvedConfiguration): List<String> = mutableListOf<String>().apply {
|
||||||
if (konanCacheKind != NativeCacheKind.NONE && !optimized && konanPropertiesService.cacheWorksFor(konanTarget)) {
|
if (konanCacheKind != NativeCacheKind.NONE && !optimized && konanPropertiesService.cacheWorksFor(konanTarget)) {
|
||||||
rootCacheDirectory.mkdirs()
|
rootCacheDirectory.mkdirs()
|
||||||
ensureCompilerProvidedLibsPrecached()
|
ensureCompilerProvidedLibsPrecached()
|
||||||
add("-Xcache-directory=${rootCacheDirectory.absolutePath}")
|
add("-Xcache-directory=${rootCacheDirectory.absolutePath}")
|
||||||
val visitedDependencies = mutableSetOf<ResolvedDependencyResult>()
|
val visitedDependencies = mutableSetOf<ResolvedDependencyResult>()
|
||||||
val allCacheDirectories = mutableSetOf<String>()
|
val allCacheDirectories = mutableSetOf<String>()
|
||||||
for (root in resolvedDependencyGraph.root.dependencies.filterIsInstance<ResolvedDependencyResult>()) {
|
for (root in resolvedConfiguration.root.dependencies.filterIsInstance<ResolvedDependencyResult>()) {
|
||||||
resolvedDependencyGraph.ensureDependencyPrecached(root, visitedDependencies)
|
resolvedConfiguration.ensureDependencyPrecached(root, visitedDependencies)
|
||||||
for (dependency in listOf(root) + getAllDependencies(root)) {
|
for (dependency in listOf(root) + getAllDependencies(root)) {
|
||||||
val cacheDirectory = getCacheDirectory(resolvedDependencyGraph, dependency)
|
val cacheDirectory = getCacheDirectory(resolvedConfiguration, dependency)
|
||||||
if (cacheDirectory.exists())
|
if (cacheDirectory.exists())
|
||||||
allCacheDirectories += cacheDirectory.absolutePath
|
allCacheDirectories += cacheDirectory.absolutePath
|
||||||
}
|
}
|
||||||
|
|||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 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.gradle.utils
|
||||||
|
|
||||||
|
import org.gradle.api.artifacts.ArtifactCollection
|
||||||
|
import org.gradle.api.artifacts.Configuration
|
||||||
|
import org.gradle.api.artifacts.result.DependencyResult
|
||||||
|
import org.gradle.api.artifacts.result.ResolvedArtifactResult
|
||||||
|
import org.gradle.api.artifacts.result.ResolvedComponentResult
|
||||||
|
import org.gradle.api.artifacts.result.ResolvedDependencyResult
|
||||||
|
import org.gradle.api.file.FileCollection
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a Gradle Configuration that was resolved after configuration time.
|
||||||
|
* But still can be accessed during Configuration time, triggering configuration resolution
|
||||||
|
*
|
||||||
|
* Serializable to configuration cache. So it can be stored in task state and be accessed during execution time.
|
||||||
|
*
|
||||||
|
* Has similar API as non-configuration cache friendly Gradle's [ResolvedConfiguration]
|
||||||
|
*/
|
||||||
|
internal class LazyResolvedConfiguration
|
||||||
|
private constructor(
|
||||||
|
private val resolvedComponentsRootProvider: Lazy<ResolvedComponentResult>,
|
||||||
|
private val artifactCollection: ArtifactCollection
|
||||||
|
) {
|
||||||
|
constructor(configuration: Configuration) : this(
|
||||||
|
// Calling resolutionResult doesn't actually trigger resolution. But accessing its root ResolvedComponentResult
|
||||||
|
// via ResolutionResult::root does. ResolutionResult can't be serialised for Configuration Cache
|
||||||
|
// but ResolvedComponentResult can. Wrapping it in `lazy` makes it resolve upon serialisation.
|
||||||
|
resolvedComponentsRootProvider = configuration.incoming.resolutionResult.let { rr -> lazy { rr.root } },
|
||||||
|
artifactCollection = configuration.incoming.artifacts // lazy ArtifactCollection
|
||||||
|
)
|
||||||
|
|
||||||
|
val root get() = resolvedComponentsRootProvider.value
|
||||||
|
val files: FileCollection get() = artifactCollection.artifactFiles
|
||||||
|
val artifacts get() = artifactCollection.artifacts
|
||||||
|
|
||||||
|
private val artifactsByComponentId by TransientLazy { artifacts.groupBy { it.id.componentIdentifier } }
|
||||||
|
|
||||||
|
val allDependencies: List<DependencyResult> get() {
|
||||||
|
fun DependencyResult.allDependenciesRecursive(): List<DependencyResult> =
|
||||||
|
if (this is ResolvedDependencyResult) {
|
||||||
|
listOf(this) + selected.dependencies.flatMap { it.allDependenciesRecursive() }
|
||||||
|
} else {
|
||||||
|
listOf(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
return root.dependencies.flatMap { it.allDependenciesRecursive() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun dependencyArtifacts(dependency: ResolvedDependencyResult): List<ResolvedArtifactResult> {
|
||||||
|
val componentId = dependency.selected.id
|
||||||
|
return artifactsByComponentId[componentId] ?: emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-7
@@ -18,7 +18,7 @@ internal fun getCacheDirectory(
|
|||||||
rootCacheDirectory: File,
|
rootCacheDirectory: File,
|
||||||
dependency: ResolvedDependencyResult,
|
dependency: ResolvedDependencyResult,
|
||||||
artifact: ResolvedArtifactResult?,
|
artifact: ResolvedArtifactResult?,
|
||||||
resolvedDependencyGraph: ResolvedDependencyGraph,
|
resolvedConfiguration: LazyResolvedConfiguration,
|
||||||
partialLinkage: Boolean
|
partialLinkage: Boolean
|
||||||
): File {
|
): File {
|
||||||
val moduleCacheDirectory = File(rootCacheDirectory, dependency.selected.moduleVersion?.name ?: "undefined")
|
val moduleCacheDirectory = File(rootCacheDirectory, dependency.selected.moduleVersion?.name ?: "undefined")
|
||||||
@@ -41,17 +41,17 @@ internal fun getCacheDirectory(
|
|||||||
versionCacheDirectory.resolve(hash)
|
versionCacheDirectory.resolve(hash)
|
||||||
} else versionCacheDirectory
|
} else versionCacheDirectory
|
||||||
|
|
||||||
return File(cacheDirectory, computeDependenciesHash(dependency, resolvedDependencyGraph, partialLinkage))
|
return File(cacheDirectory, computeDependenciesHash(dependency, resolvedConfiguration, partialLinkage))
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ByteArray.toHexString() = joinToString("") { (0xFF and it.toInt()).toString(16).padStart(2, '0') }
|
internal fun ByteArray.toHexString() = joinToString("") { (0xFF and it.toInt()).toString(16).padStart(2, '0') }
|
||||||
|
|
||||||
private fun computeDependenciesHash(dependency: ResolvedDependencyResult, resolvedDependencyGraph: ResolvedDependencyGraph, partialLinkage: Boolean): String {
|
private fun computeDependenciesHash(dependency: ResolvedDependencyResult, resolvedConfiguration: LazyResolvedConfiguration, partialLinkage: Boolean): String {
|
||||||
val hashedValue = buildString {
|
val hashedValue = buildString {
|
||||||
if (partialLinkage) append("#__PL__#")
|
if (partialLinkage) append("#__PL__#")
|
||||||
|
|
||||||
(listOf(dependency) + getAllDependencies(dependency))
|
(listOf(dependency) + getAllDependencies(dependency))
|
||||||
.flatMap { resolvedDependencyGraph.dependencyArtifacts(it) }
|
.flatMap { resolvedConfiguration.dependencyArtifacts(it) }
|
||||||
.map { it.file.absolutePath }
|
.map { it.file.absolutePath }
|
||||||
.distinct()
|
.distinct()
|
||||||
.sortedBy { it }
|
.sortedBy { it }
|
||||||
@@ -66,19 +66,19 @@ private fun computeDependenciesHash(dependency: ResolvedDependencyResult, resolv
|
|||||||
internal fun getDependenciesCacheDirectories(
|
internal fun getDependenciesCacheDirectories(
|
||||||
rootCacheDirectory: File,
|
rootCacheDirectory: File,
|
||||||
dependency: ResolvedDependencyResult,
|
dependency: ResolvedDependencyResult,
|
||||||
resolvedDependencyGraph: ResolvedDependencyGraph,
|
resolvedConfiguration: LazyResolvedConfiguration,
|
||||||
considerArtifact: Boolean,
|
considerArtifact: Boolean,
|
||||||
partialLinkage: Boolean
|
partialLinkage: Boolean
|
||||||
): List<File>? {
|
): List<File>? {
|
||||||
return getAllDependencies(dependency)
|
return getAllDependencies(dependency)
|
||||||
.flatMap { childDependency ->
|
.flatMap { childDependency ->
|
||||||
resolvedDependencyGraph.dependencyArtifacts(childDependency).map {
|
resolvedConfiguration.dependencyArtifacts(childDependency).map {
|
||||||
if (libraryFilter(it)) {
|
if (libraryFilter(it)) {
|
||||||
val cacheDirectory = getCacheDirectory(
|
val cacheDirectory = getCacheDirectory(
|
||||||
rootCacheDirectory = rootCacheDirectory,
|
rootCacheDirectory = rootCacheDirectory,
|
||||||
dependency = childDependency,
|
dependency = childDependency,
|
||||||
artifact = if (considerArtifact) it else null,
|
artifact = if (considerArtifact) it else null,
|
||||||
resolvedDependencyGraph = resolvedDependencyGraph,
|
resolvedConfiguration = resolvedConfiguration,
|
||||||
partialLinkage = partialLinkage
|
partialLinkage = partialLinkage
|
||||||
)
|
)
|
||||||
if (!cacheDirectory.exists()) return null
|
if (!cacheDirectory.exists()) return null
|
||||||
|
|||||||
-47
@@ -5,15 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.utils
|
package org.jetbrains.kotlin.gradle.utils
|
||||||
|
|
||||||
import org.gradle.api.Project
|
|
||||||
import org.gradle.api.artifacts.ArtifactCollection
|
|
||||||
import org.gradle.api.artifacts.Configuration
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.gradle.api.artifacts.result.DependencyResult
|
|
||||||
import org.gradle.api.artifacts.result.ResolvedArtifactResult
|
|
||||||
import org.gradle.api.artifacts.result.ResolvedComponentResult
|
|
||||||
import org.gradle.api.artifacts.result.ResolvedDependencyResult
|
|
||||||
import org.gradle.api.file.FileCollection
|
|
||||||
import org.gradle.api.provider.Provider
|
|
||||||
|
|
||||||
const val COMPILE_ONLY = "compileOnly"
|
const val COMPILE_ONLY = "compileOnly"
|
||||||
const val COMPILE = "compile"
|
const val COMPILE = "compile"
|
||||||
@@ -23,45 +15,6 @@ const val RUNTIME_ONLY = "runtimeOnly"
|
|||||||
const val RUNTIME = "runtime"
|
const val RUNTIME = "runtime"
|
||||||
internal const val INTRANSITIVE = "intransitive"
|
internal const val INTRANSITIVE = "intransitive"
|
||||||
|
|
||||||
/**
|
|
||||||
* Gradle Configuration Cache-friendly representation of resolved Configuration
|
|
||||||
*/
|
|
||||||
internal class ResolvedDependencyGraph
|
|
||||||
private constructor(
|
|
||||||
private val resolvedComponentsRootProvider: Lazy<ResolvedComponentResult>,
|
|
||||||
private val artifactCollection: ArtifactCollection
|
|
||||||
) {
|
|
||||||
constructor(configuration: Configuration) : this(
|
|
||||||
// Calling resolutionResult doesn't actually trigger resolution. But accessing its root ResolvedComponentResult
|
|
||||||
// via ResolutionResult::root does. ResolutionResult can't be serialised for Configuration Cache
|
|
||||||
// but ResolvedComponentResult can. Wrapping it in `lazy` makes it resolve upon serialisation.
|
|
||||||
resolvedComponentsRootProvider = configuration.incoming.resolutionResult.let { rr -> lazy { rr.root } },
|
|
||||||
artifactCollection = configuration.incoming.artifacts // lazy ArtifactCollection
|
|
||||||
)
|
|
||||||
|
|
||||||
val root get() = resolvedComponentsRootProvider.value
|
|
||||||
val files: FileCollection get() = artifactCollection.artifactFiles
|
|
||||||
val artifacts get() = artifactCollection.artifacts
|
|
||||||
|
|
||||||
private val artifactsByComponentId by TransientLazy { artifacts.groupBy { it.id.componentIdentifier } }
|
|
||||||
|
|
||||||
val allDependencies: List<DependencyResult> get() {
|
|
||||||
fun DependencyResult.allDependenciesRecursive(): List<DependencyResult> =
|
|
||||||
if (this is ResolvedDependencyResult) {
|
|
||||||
listOf(this) + selected.dependencies.flatMap { it.allDependenciesRecursive() }
|
|
||||||
} else {
|
|
||||||
listOf(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
return root.dependencies.flatMap { it.allDependenciesRecursive() }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun dependencyArtifacts(dependency: ResolvedDependencyResult): List<ResolvedArtifactResult> {
|
|
||||||
val componentId = dependency.selected.id
|
|
||||||
return artifactsByComponentId[componentId] ?: emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun Configuration.markConsumable(): Configuration = apply {
|
internal fun Configuration.markConsumable(): Configuration = apply {
|
||||||
this.isCanBeConsumed = true
|
this.isCanBeConsumed = true
|
||||||
this.isCanBeResolved = false
|
this.isCanBeResolved = false
|
||||||
|
|||||||
Reference in New Issue
Block a user