diff --git a/build.gradle.kts b/build.gradle.kts index a762fffd6c8..cd388300272 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -64,8 +64,6 @@ allprojects { extra["kotlin_root"] = rootDir val bootstrapCompileCfg = configurations.create("bootstrapCompile") -val scriptCompileCfg = configurations.create("scriptCompile").extendsFrom(bootstrapCompileCfg) -val scriptRuntimeCfg = configurations.create("scriptRuntime").extendsFrom(scriptCompileCfg) repositories { for (repo in (rootProject.extra["repos"] as List)) { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 4a3c6669f62..4672c1e5dae 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -45,6 +45,7 @@ dependencies { // TODO: adding the dep to the plugin breaks the build unexpectedly, resolve and uncomment // compile("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["bootstrap_kotlin_version"]}") compile("com.github.jengelman.gradle.plugins:shadow:${property("versions.shadow")}") + compile("org.ow2.asm:asm-all:6.0_BETA") } samWithReceiver { diff --git a/generators/infrastructure/strip-kotlin-annotations.kts b/buildSrc/src/main/kotlin/stripMetadata.kt similarity index 53% rename from generators/infrastructure/strip-kotlin-annotations.kts rename to buildSrc/src/main/kotlin/stripMetadata.kt index 9b010b48d64..b784cd1270a 100644 --- a/generators/infrastructure/strip-kotlin-annotations.kts +++ b/buildSrc/src/main/kotlin/stripMetadata.kt @@ -1,20 +1,7 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +@file:Suppress("unused") // usages in build scripts are not tracked properly -import org.jetbrains.org.objectweb.asm.* +import org.gradle.api.logging.Logger +import org.objectweb.asm.* import java.io.BufferedOutputStream import java.io.File import java.io.FileOutputStream @@ -22,24 +9,13 @@ import java.util.jar.JarFile import java.util.zip.ZipOutputStream /** - * Removes metadata annotations from Kotlin classes + * Removes @kotlin.Metadata annotations from compiled Kotlin classes */ - -fun main(args: Array) { - if (args.size != 4) { - error("Usage: kotlinc -script strip-kotlin-annotations.kts ") - } - - val annotationRegex = args[0].toRegex() - val classRegex = args[1].toRegex() - val inFile = File(args[2]) - val outFile = File(args[3]) +fun stripMetadata(logger: Logger, classNamePattern: String, inFile: File, outFile: File) { + val classRegex = classNamePattern.toRegex() assert(inFile.exists()) { "Input file not found at $inFile" } - println("Stripping annotations from all classes in $inFile") - println("Input file size: ${inFile.length()} bytes") - fun transform(entryName: String, bytes: ByteArray): ByteArray { if (!entryName.endsWith(".class")) return bytes if (!classRegex.matches(entryName.removeSuffix(".class"))) return bytes @@ -48,7 +24,7 @@ fun main(args: Array) { val classWriter = ClassWriter(0) val classVisitor = object : ClassVisitor(Opcodes.ASM5, classWriter) { override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? { - if (annotationRegex.matches(Type.getType(desc).getInternalName())) { + if (Type.getType(desc).internalName == "kotlin/Metadata") { changed = true return null } @@ -61,8 +37,7 @@ fun main(args: Array) { return classWriter.toByteArray() } - ZipOutputStream(BufferedOutputStream(FileOutputStream(outFile))).use { - outJar -> + ZipOutputStream(BufferedOutputStream(FileOutputStream(outFile))).use { outJar -> JarFile(inFile).use { inJar -> for (entry in inJar.entries()) { val inBytes = inJar.getInputStream(entry).readBytes() @@ -80,8 +55,9 @@ fun main(args: Array) { } } - println("Output written to $outFile") - println("Output file size: ${outFile.length()} bytes") + logger.info("Stripping @kotlin.Metadata annotations from all classes in $inFile") + logger.info("Class name pattern: $classNamePattern") + logger.info("Input file size: ${inFile.length()} bytes") + logger.info("Output written to $outFile") + logger.info("Output file size: ${outFile.length()} bytes") } - -main(args) diff --git a/compiler/tests/org/jetbrains/kotlin/code/CodeConformanceTest.kt b/compiler/tests/org/jetbrains/kotlin/code/CodeConformanceTest.kt index 1a1a46a7eeb..77bcd1cf220 100644 --- a/compiler/tests/org/jetbrains/kotlin/code/CodeConformanceTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/code/CodeConformanceTest.kt @@ -28,6 +28,7 @@ class CodeConformanceTest : TestCase() { private val SOURCES_FILE_PATTERN = Pattern.compile("(.+\\.java|.+\\.kt|.+\\.js)") private val EXCLUDED_FILES_AND_DIRS = listOf( "android.tests.dependencies", + "buildSrc", "core/reflection.jvm/src/kotlin/reflect/jvm/internal/pcollections", "libraries/kotlin.test/js/it/.gradle", "libraries/kotlin.test/js/it/node_modules", diff --git a/gradle/project-schema.json b/gradle/project-schema.json index 4f261e64155..09de8dd341b 100644 --- a/gradle/project-schema.json +++ b/gradle/project-schema.json @@ -4,9 +4,7 @@ }, "configurations": [ - "bootstrapCompile", - "scriptCompile", - "scriptRuntime" + "bootstrapCompile" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", diff --git a/libraries/commonConfiguration.gradle b/libraries/commonConfiguration.gradle index 88c6d94e918..77540a12a82 100644 --- a/libraries/commonConfiguration.gradle +++ b/libraries/commonConfiguration.gradle @@ -206,22 +206,3 @@ ext.createPreprocessorTask = { Project project, def name, def sourceDir, def tar args = [sourceDir, targetDir, profile] } } - -ext.createScriptTask = { Project project, def name, Closure configureClosure = null -> - JavaExec task = project.tasks.create(name, JavaExec) - return project.configure(task) { -// dependsOn(rootProject.prepareBootstrap) - classpath = rootProject.configurations.scriptCompile - main = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" - args = [ - "-script", - "-version", - "-no-stdlib", - "-cp", rootProject.configurations.scriptRuntime.asPath] - - if (configureClosure != null) { - configureClosure.delegate = it - configureClosure.call() - } - } -} diff --git a/libraries/tools/kotlin-reflect/build.gradle b/libraries/tools/kotlin-reflect/build.gradle index d6b75dc372d..f3aea29e219 100644 --- a/libraries/tools/kotlin-reflect/build.gradle +++ b/libraries/tools/kotlin-reflect/build.gradle @@ -89,11 +89,11 @@ task reflectShadowJar(type: ShadowJar) { version = null manifestAttributes(manifest, project, 'Main') - from (sourceSets.main.output) - from ("${core}/descriptors.jvm/src") { + from(sourceSets.main.output) + from(project(":core:descriptors.jvm").sourceSets.main.resources) { include 'META-INF/services/**' } - from ("${core}/deserialization/src") { + from(project(":core:deserialization").sourceSets.main.resources) { include 'META-INF/services/**' } @@ -103,19 +103,15 @@ task reflectShadowJar(type: ShadowJar) { mergeServiceFiles() } -createScriptTask(project, "stripMetadata") { +task stripMetadata { dependsOn reflectShadowJar def inputJar = reflectShadowJar.archivePath - def outputJar = "${libsDir}/kotlin-reflect-stripped.jar" + def outputJar = new File("${libsDir}/kotlin-reflect-stripped.jar") inputs.file(inputJar) outputs.file(outputJar) - args += [ - "${rootDir}/generators/infrastructure/strip-kotlin-annotations.kts", - "kotlin/Metadata", - "kotlin/reflect/jvm/internal/impl/.*", - inputJar, - outputJar - ] + doLast { + StripMetadataKt.stripMetadata(logger, "kotlin/reflect/jvm/internal/impl/.*", inputJar, outputJar) + } } def mainArchiveName = "${archivesBaseName}-${project.version}.jar"