From e6588ee8a49005d510952f7944bcf845e0681cd3 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 4 Feb 2021 13:25:07 +0100 Subject: [PATCH] CLI: include META-INF/services/ from kotlin-reflect with -include-runtime This is an addition to bd205317aae15816783df332eae851483167f3cd where we started to add the contents of kotlin-reflect into the resulting jar if -include-runtime is specified. Apparently kotlin-reflect doesn't work without some services in META-INF/services/, which didn't satisfy the condition for inclusion. The existing test didn't catch that because loading class annotations does not always lead to those services being loaded. --- .../cli/jvm/compiler/CompileEnvironmentUtil.java | 11 +++++++---- .../testData/integration/smoke/reflect/reflect.kt | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java index d46ebc5a4db..cce1bd287c7 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java @@ -33,7 +33,8 @@ import org.jetbrains.kotlin.utils.ExceptionUtilsKt; import org.jetbrains.kotlin.utils.PathUtil; import java.io.*; -import java.util.*; +import java.util.Calendar; +import java.util.GregorianCalendar; import java.util.jar.*; import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR; @@ -144,11 +145,13 @@ public class CompileEnvironmentUtil { JarEntry e = jis.getNextJarEntry(); if (e == null) break; - if ((!FileUtilRt.extensionEquals(e.getName(), "class") && - !FileUtilRt.extensionEquals(e.getName(), BuiltInSerializerProtocol.BUILTINS_FILE_EXTENSION)) || - StringsKt.substringAfterLast(e.getName(), "/", e.getName()).equals("module-info.class")) { + String name = e.getName(); + if (!FileUtilRt.extensionEquals(name, "class") && + !FileUtilRt.extensionEquals(name, BuiltInSerializerProtocol.BUILTINS_FILE_EXTENSION) && + !name.startsWith("META-INF/services/")) { continue; } + if (StringsKt.substringAfterLast(name, "/", name).equals("module-info.class")) continue; if (resetJarTimestamps) { e.setTime(DOS_EPOCH); } diff --git a/compiler/testData/integration/smoke/reflect/reflect.kt b/compiler/testData/integration/smoke/reflect/reflect.kt index 4fb5c0b80cf..4c402f51d00 100644 --- a/compiler/testData/integration/smoke/reflect/reflect.kt +++ b/compiler/testData/integration/smoke/reflect/reflect.kt @@ -1,5 +1,8 @@ package reflect +import kotlin.reflect.jvm.kotlinFunction + fun main() { String::class.annotations -} \ No newline at end of file + KotlinVersion::class.java.methods.first().kotlinFunction +}