[Gradle, JS] Make NodeJsSetup cc-compatible
This commit is contained in:
+4
@@ -32,6 +32,10 @@ open class NodeJsRootPlugin : Plugin<Project> {
|
|||||||
val setupTask = registerTask<NodeJsSetupTask>(NodeJsSetupTask.NAME) {
|
val setupTask = registerTask<NodeJsSetupTask>(NodeJsSetupTask.NAME) {
|
||||||
it.group = TASKS_GROUP_NAME
|
it.group = TASKS_GROUP_NAME
|
||||||
it.description = "Download and install a local node/npm version"
|
it.description = "Download and install a local node/npm version"
|
||||||
|
it.configuration = provider {
|
||||||
|
this.project.configurations.detachedConfiguration(this.project.dependencies.create(it.ivyDependency))
|
||||||
|
.also { conf -> conf.isTransitive = false }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val rootClean = project.rootProject.tasks.named(BasePlugin.CLEAN_TASK_NAME)
|
val rootClean = project.rootProject.tasks.named(BasePlugin.CLEAN_TASK_NAME)
|
||||||
|
|||||||
+49
-39
@@ -1,10 +1,11 @@
|
|||||||
package org.jetbrains.kotlin.gradle.targets.js.nodejs
|
package org.jetbrains.kotlin.gradle.targets.js.nodejs
|
||||||
|
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.tasks.CacheableTask
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.gradle.api.tasks.Input
|
import org.gradle.api.file.ArchiveOperations
|
||||||
import org.gradle.api.tasks.OutputDirectory
|
import org.gradle.api.file.FileSystemOperations
|
||||||
import org.gradle.api.tasks.TaskAction
|
import org.gradle.api.provider.Provider
|
||||||
|
import org.gradle.api.tasks.*
|
||||||
import org.jetbrains.kotlin.gradle.logging.kotlinInfo
|
import org.jetbrains.kotlin.gradle.logging.kotlinInfo
|
||||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||||
import org.jetbrains.kotlin.statistics.metrics.NumericalMetrics
|
import org.jetbrains.kotlin.statistics.metrics.NumericalMetrics
|
||||||
@@ -15,6 +16,8 @@ import java.net.URI
|
|||||||
open class NodeJsSetupTask : DefaultTask() {
|
open class NodeJsSetupTask : DefaultTask() {
|
||||||
private val settings = NodeJsRootPlugin.apply(project.rootProject)
|
private val settings = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
private val env by lazy { settings.requireConfigured() }
|
private val env by lazy { settings.requireConfigured() }
|
||||||
|
private val fs = services.get(FileSystemOperations::class.java)
|
||||||
|
private val archives = services.get(ArchiveOperations::class.java)
|
||||||
|
|
||||||
val ivyDependency: String
|
val ivyDependency: String
|
||||||
@Input get() = env.ivyDependency
|
@Input get() = env.ivyDependency
|
||||||
@@ -22,6 +25,41 @@ open class NodeJsSetupTask : DefaultTask() {
|
|||||||
val destination: File
|
val destination: File
|
||||||
@OutputDirectory get() = env.nodeDir
|
@OutputDirectory get() = env.nodeDir
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
@get:Internal
|
||||||
|
internal lateinit var configuration: Provider<Configuration>
|
||||||
|
|
||||||
|
private val _nodeJsDist by lazy {
|
||||||
|
configuration.get().files.single()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("unused") // as it called by Gradle before task execution and used to resolve artifact
|
||||||
|
@get:Classpath
|
||||||
|
val nodeJsDist: File
|
||||||
|
get() {
|
||||||
|
@Suppress("UnstableApiUsage", "DEPRECATION")
|
||||||
|
val repo = project.repositories.ivy { repo ->
|
||||||
|
repo.name = "Node Distributions at ${settings.nodeDownloadBaseUrl}"
|
||||||
|
repo.url = URI(settings.nodeDownloadBaseUrl)
|
||||||
|
|
||||||
|
repo.patternLayout {
|
||||||
|
it.artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]")
|
||||||
|
it.ivy("v[revision]/ivy.xml")
|
||||||
|
}
|
||||||
|
repo.metadataSources { it.artifact() }
|
||||||
|
repo.content { it.includeModule("org.nodejs", "node") }
|
||||||
|
}
|
||||||
|
val startDownloadTime = System.currentTimeMillis()
|
||||||
|
val dist = _nodeJsDist
|
||||||
|
val downloadDuration = System.currentTimeMillis() - startDownloadTime
|
||||||
|
if (downloadDuration > 0) {
|
||||||
|
KotlinBuildStatsService.getInstance()
|
||||||
|
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
|
||||||
|
}
|
||||||
|
project.repositories.remove(repo)
|
||||||
|
return dist
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
onlyIf {
|
onlyIf {
|
||||||
@@ -32,37 +70,9 @@ open class NodeJsSetupTask : DefaultTask() {
|
|||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun exec() {
|
fun exec() {
|
||||||
@Suppress("UnstableApiUsage", "DEPRECATION")
|
logger.kotlinInfo("Using node distribution from '$_nodeJsDist'")
|
||||||
val repo = project.repositories.ivy { repo ->
|
|
||||||
repo.name = "Node Distributions at ${settings.nodeDownloadBaseUrl}"
|
|
||||||
repo.url = URI(settings.nodeDownloadBaseUrl)
|
|
||||||
|
|
||||||
repo.patternLayout {
|
unpackNodeArchive(_nodeJsDist, destination.parentFile) // parent because archive contains name already
|
||||||
it.artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]")
|
|
||||||
it.ivy("v[revision]/ivy.xml")
|
|
||||||
}
|
|
||||||
repo.metadataSources { it.artifact() }
|
|
||||||
repo.content { it.includeModule("org.nodejs", "node") }
|
|
||||||
}
|
|
||||||
|
|
||||||
val dep = this.project.dependencies.create(ivyDependency)
|
|
||||||
val conf = this.project.configurations.detachedConfiguration(dep)
|
|
||||||
conf.isTransitive = false
|
|
||||||
|
|
||||||
val startDownloadTime = System.currentTimeMillis()
|
|
||||||
val result = conf.resolve().single()
|
|
||||||
|
|
||||||
val downloadDuration = System.currentTimeMillis() - startDownloadTime
|
|
||||||
if (downloadDuration > 0) {
|
|
||||||
KotlinBuildStatsService.getInstance()
|
|
||||||
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, result.length() * 1000 / downloadDuration)
|
|
||||||
}
|
|
||||||
|
|
||||||
project.repositories.remove(repo)
|
|
||||||
|
|
||||||
project.logger.kotlinInfo("Using node distribution from '$result'")
|
|
||||||
|
|
||||||
unpackNodeArchive(result, destination.parentFile) // parent because archive contains name already
|
|
||||||
|
|
||||||
if (!env.isWindows) {
|
if (!env.isWindows) {
|
||||||
File(env.nodeExecutable).setExecutable(true)
|
File(env.nodeExecutable).setExecutable(true)
|
||||||
@@ -70,16 +80,16 @@ open class NodeJsSetupTask : DefaultTask() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun unpackNodeArchive(archive: File, destination: File) {
|
private fun unpackNodeArchive(archive: File, destination: File) {
|
||||||
project.logger.kotlinInfo("Unpacking $archive to $destination")
|
logger.kotlinInfo("Unpacking $archive to $destination")
|
||||||
|
|
||||||
when {
|
when {
|
||||||
archive.name.endsWith("zip") -> project.copy {
|
archive.name.endsWith("zip") -> fs.copy {
|
||||||
it.from(project.zipTree(archive))
|
it.from(archives.zipTree(archive))
|
||||||
it.into(destination)
|
it.into(destination)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
project.copy {
|
fs.copy {
|
||||||
it.from(project.tarTree(archive))
|
it.from(archives.tarTree(archive))
|
||||||
it.into(destination)
|
it.into(destination)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user