Pack K/N stdlib sources into single zip
With the directory structure similar to one of a multiplatform library, where each source set sources are placed into the directory named after this source set. Do not use legacy projects for building relative paths
This commit is contained in:
committed by
Space Team
parent
fb74c18235
commit
35aa17e1d0
@@ -1,79 +0,0 @@
|
||||
package org.jetbrains.kotlin
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.ConfigurableFileCollection
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFiles
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import java.io.File
|
||||
|
||||
open class CopyCommonSources : DefaultTask() {
|
||||
@Input
|
||||
var zipSources: Boolean = false
|
||||
|
||||
@InputFiles
|
||||
val sourcePaths: ConfigurableFileCollection = project.files()
|
||||
|
||||
@OutputDirectory
|
||||
var outputDir: File = project.layout.buildDirectory.get().asFile.resolve("sources")
|
||||
|
||||
fun zipSources(needToZip: Boolean) {
|
||||
zipSources = needToZip
|
||||
}
|
||||
|
||||
fun outputDir(path: Any) {
|
||||
outputDir = project.file(path)
|
||||
}
|
||||
|
||||
fun sourcePaths(paths: Any) {
|
||||
sourcePaths.setFrom(paths)
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun copySources() {
|
||||
if (zipSources) copyAndZip() else copyPlain()
|
||||
}
|
||||
|
||||
private fun copyPlain() {
|
||||
for (sourcePath in sourcePaths) {
|
||||
sourcePath.copyFilteredTo(outputDir)
|
||||
}
|
||||
}
|
||||
|
||||
private fun copyAndZip() {
|
||||
for (sourcePath in sourcePaths) {
|
||||
val filePrefix = sourcePath.name.replace(Regex("-\\d+.*"), "")
|
||||
val targetFileName = "$filePrefix-sources.zip"
|
||||
|
||||
val tempDir = project.layout.buildDirectory.dir("$name/$filePrefix").get().asFile.also {
|
||||
it.deleteRecursively()
|
||||
it.mkdirs()
|
||||
}
|
||||
|
||||
sourcePath.copyFilteredTo(tempDir)
|
||||
|
||||
project.ant.invokeMethod(
|
||||
"zip",
|
||||
mapOf(
|
||||
"destfile" to outputDir.resolve(targetFileName).absolutePath,
|
||||
"basedir" to tempDir.absolutePath
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun File.copyFilteredTo(destinationDir: File) {
|
||||
val fileTree = if (isFile) project.zipTree(this) else project.fileTree(this)
|
||||
|
||||
project.copy {
|
||||
from(fileTree)
|
||||
includeEmptyDirs = false
|
||||
include("generated/**/*.kt")
|
||||
include("kotlin/**/*.kt")
|
||||
include("kotlin.test/*.kt")
|
||||
into(destinationDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-17
@@ -17,7 +17,6 @@
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.konan.util.*
|
||||
import org.jetbrains.kotlin.CopySamples
|
||||
import org.jetbrains.kotlin.CopyCommonSources
|
||||
import org.jetbrains.kotlin.PlatformInfo
|
||||
import org.jetbrains.kotlin.cpp.CompilationDatabasePlugin
|
||||
import org.jetbrains.kotlin.cpp.CppUsage
|
||||
@@ -169,9 +168,8 @@ dependencies {
|
||||
distPack project(':kotlin-native:utilities:basic-utils')
|
||||
distPack project(':kotlin-native:klib')
|
||||
distPack project(path: ':kotlin-native:endorsedLibraries:kotlinx.cli', configuration: "jvmRuntimeElements")
|
||||
commonSources project(path: ':kotlin-stdlib-common', configuration: 'sources')
|
||||
commonSources project(path: ':kotlin-test:kotlin-test-common', configuration: 'sources')
|
||||
commonSources project(path: ':kotlin-test:kotlin-test-annotations-common', configuration: 'sources')
|
||||
commonSources project(path: ':kotlin-stdlib', configuration: 'metadataSourcesElements')
|
||||
commonSources project(path: ':kotlin-test', configuration: 'metadataSourcesElements')
|
||||
compilationDatabase project(":kotlin-native:common")
|
||||
compilationDatabase project(":kotlin-native:runtime")
|
||||
runtimeBitcode project(":kotlin-native:runtime")
|
||||
@@ -199,30 +197,34 @@ tasks.named("build") {
|
||||
dependsOn 'dist', 'distPlatformLibs'
|
||||
}
|
||||
|
||||
tasks.register("distCommonSources", CopyCommonSources) {
|
||||
outputDir "$distDir/sources"
|
||||
sourcePaths configurations.commonSources
|
||||
zipSources true
|
||||
}
|
||||
|
||||
tasks.register("distNativeSources", Zip) {
|
||||
dependsOn(configurations.commonSources)
|
||||
duplicatesStrategy = DuplicatesStrategy.FAIL
|
||||
destinationDirectory = file("$distDir/sources")
|
||||
archiveFileName = "kotlin-stdlib-native-sources.zip"
|
||||
|
||||
includeEmptyDirs = false
|
||||
include('**/*.kt')
|
||||
|
||||
from(project(':kotlin-native:runtime').file('src/main/kotlin'))
|
||||
from(project(":kotlin-stdlib-common").file('../native-wasm/src/'))
|
||||
from(project(':kotlin-native:Interop:Runtime').file('src/main/kotlin'))
|
||||
from(project(':kotlin-native:Interop:Runtime').file('src/native/kotlin'))
|
||||
from(project(':kotlin-native:Interop:JsRuntime').file('src/main/kotlin')) {
|
||||
into('kotlinx/wasm/jsinterop')
|
||||
from {
|
||||
configurations.commonSources
|
||||
.collect { zipTree(it) }
|
||||
.inject { t1, t2 -> t1 + t2 }
|
||||
}
|
||||
into('nativeWasmMain') {
|
||||
from(project(":kotlin-stdlib").file('native-wasm/src/'))
|
||||
}
|
||||
into('nativeMain') {
|
||||
from(project(':kotlin-native:runtime').file('src/main/kotlin'))
|
||||
from(project(':kotlin-native:Interop:Runtime').file('src/main/kotlin'))
|
||||
from(project(':kotlin-native:Interop:Runtime').file('src/native/kotlin'))
|
||||
from(project(':kotlin-native:Interop:JsRuntime').file('src/main/kotlin')) {
|
||||
into('kotlinx/wasm/jsinterop')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("distSources") {
|
||||
dependsOn(distCommonSources)
|
||||
dependsOn(distNativeSources)
|
||||
}
|
||||
|
||||
|
||||
@@ -507,12 +507,12 @@ tasks.named("clean") {
|
||||
|
||||
// region: Stdlib
|
||||
|
||||
val commonStdlibSrcDirs = project(":kotlin-stdlib-common")
|
||||
val commonStdlibSrcDirs = project(":kotlin-stdlib")
|
||||
.files(
|
||||
"src/kotlin",
|
||||
"src/generated",
|
||||
"../unsigned/src",
|
||||
"../src"
|
||||
"common/src/kotlin",
|
||||
"common/src/generated",
|
||||
"unsigned/src",
|
||||
"src"
|
||||
).files
|
||||
|
||||
val interopRuntimeCommonSrcDir = project(":kotlin-native:Interop:Runtime").file("src/main/kotlin")
|
||||
@@ -521,12 +521,12 @@ val interopSrcDirs = listOf(
|
||||
project(":kotlin-native:Interop:JsRuntime").file("src/main/kotlin")
|
||||
)
|
||||
|
||||
val testAnnotationCommonSrcDir = project(":kotlin-test:kotlin-test-annotations-common").files("src/main/kotlin").files
|
||||
val testCommonSrcDir = project(":kotlin-test:kotlin-test-common").files("src/main/kotlin").files
|
||||
val testAnnotationCommonSrcDir = project(":kotlin-test").files("annotations-common/src/main/kotlin").files
|
||||
val testCommonSrcDir = project(":kotlin-test").files("common/src/main/kotlin").files
|
||||
|
||||
val stdLibSrcDirs = interopSrcDirs + listOf(
|
||||
val stdLibSrcDirs = interopSrcDirs + listOf(
|
||||
project.file("src/main/kotlin"),
|
||||
project(":kotlin-stdlib-common").file("../native-wasm/src/")
|
||||
project(":kotlin-stdlib").file("native-wasm/src/")
|
||||
)
|
||||
|
||||
lateinit var stdlibBuildTask: TaskProvider<Task>
|
||||
|
||||
Reference in New Issue
Block a user