[KLIB tool] Rename "contents" to "dump-metadata"

To make KLIB tool command names more uniform.
This commit is contained in:
Dmitriy Dolovov
2023-10-05 13:47:21 +02:00
committed by Space Team
parent d8d95fdf4b
commit 02f52371c1
6 changed files with 41 additions and 34 deletions
@@ -72,7 +72,8 @@ fun printUsage() {
Note that this command renders the signatures from the metadata. Signatures for certain
declarations in the metadata and in IR may differ if compiler plugins (such as Compose)
were applied during library compilation.
contents Dump the metadata of all public declarations in the library in the form of Kotlin-alike code
dump-metadata Dump the metadata of all public declarations in the library in the form of Kotlin-alike code
contents [DEPRECATED] Renamed to "dump-metadata". Please, use new command name
and the options are:
-repository <path> [DEPRECATED] Usage of KLIB repositories will be dropped soon. See https://youtrack.jetbrains.com/issue/KT-61098
@@ -81,7 +82,7 @@ fun printUsage() {
Render IR signatures of a specific version. By default, the most up-to-date signature version
supported in the library is used.
-print-signatures {true|false}
Print IR signature for every declaration (only for "contents" and "dump-ir" commands)
Print IR signature for every declaration (only for "dump-metadata" and "dump-ir" commands)
""".trimIndent()
)
}
@@ -293,6 +294,11 @@ class Library(val libraryNameOrPath: String, val requestedRepository: String?) {
}
fun contents(output: Appendable, printSignatures: Boolean) {
logWarning("\"contents\" has been renamed to \"dump-metadata\"")
dumpMetadata(output, printSignatures)
}
fun dumpMetadata(output: Appendable, printSignatures: Boolean) {
val module = loadModule()
val signatureRenderer = if (printSignatures) DefaultKlibSignatureRenderer("// Signature: ") else KlibSignatureRenderer.NO_SIGNATURE
val printer = DeclarationPrinter(output, DefaultDeclarationHeaderRenderer, signatureRenderer)
@@ -301,7 +307,7 @@ class Library(val libraryNameOrPath: String, val requestedRepository: String?) {
}
fun signatures(output: Appendable) {
logWarning("\"signatures\" is deprecated. Please, use \"dump-ir-signatures\" instead\n")
logWarning("\"signatures\" is deprecated. Please, use \"dump-ir-signatures\" instead")
val module = loadModule()
val printer = SignaturePrinter(output, DefaultKlibSignatureRenderer())
@@ -380,6 +386,7 @@ fun main(args: Array<String>) {
when (command.verb) {
"dump-ir" -> library.ir(System.out, printSignatures)
"dump-ir-signatures" -> library.dumpIrSignatures(System.out, signatureVersion)
"dump-metadata" -> library.dumpMetadata(System.out, printSignatures)
"contents" -> library.contents(System.out, printSignatures)
"signatures" -> library.signatures(System.out)
"info" -> library.info()
@@ -12,21 +12,21 @@ import org.jetbrains.kotlin.konan.target.Distribution
import org.jetbrains.kotlin.konan.target.HostManager
import java.nio.file.Paths
class ContentsTest {
class DumpMetadataTest {
private fun testLibrary(name: String) = LIBRARY_DIRECTORY.resolve("$name.klib").toFile().absolutePath
private fun klibContents(library: String, printOutput: Boolean = false, expected: () -> String) {
private fun dumpMetadata(library: String, printOutput: Boolean = false, expected: () -> String) {
val output = StringBuilder()
val lib = Library(library, null)
lib.contents(output, false)
lib.dumpMetadata(output, false)
if (printOutput) {
println(output.trim().toString())
}
assertEquals(
StringUtil.convertLineSeparators(expected()),
StringUtil.convertLineSeparators(output.trim().toString()),
"klib contents test failed for library: $library"
"klib \"dump-metadata\" test failed for library: $library"
)
}
@@ -34,11 +34,11 @@ class ContentsTest {
fun `Stdlib content should be printed without exceptions`() {
val output = StringBuilder()
val distributionPath = System.getProperty("konan.home")
Library(Distribution(distributionPath).stdlib, null).contents(output, false)
Library(Distribution(distributionPath).stdlib, null).dumpMetadata(output, false)
}
@Test
fun topLevelFunctions() = klibContents(testLibrary("TopLevelFunctions")) {
fun topLevelFunctions() = dumpMetadata(testLibrary("TopLevelFunctions")) {
"""
package <root> {
annotation class A constructor() : Annotation
@@ -65,7 +65,7 @@ class ContentsTest {
}
@Test
fun constructors() = klibContents(testLibrary("Constructors")) {
fun constructors() = dumpMetadata(testLibrary("Constructors")) {
"""
package <root> {
annotation class A constructor() : Annotation
@@ -95,7 +95,7 @@ class ContentsTest {
}
@Test
fun objects() = klibContents(testLibrary("Objects")) {
fun objects() = dumpMetadata(testLibrary("Objects")) {
"""
package <root> {
@@ -128,7 +128,7 @@ class ContentsTest {
}
@Test
fun classes() = klibContents(testLibrary("Classes")) {
fun classes() = dumpMetadata(testLibrary("Classes")) {
"""
package <root> {
@@ -193,7 +193,7 @@ class ContentsTest {
}
@Test
fun methodModality() = klibContents(testLibrary("MethodModality")) {
fun methodModality() = dumpMetadata(testLibrary("MethodModality")) {
"""
package <root> {
@@ -223,7 +223,7 @@ class ContentsTest {
}
@Test
fun functionModifiers() = klibContents(testLibrary("FunctionModifiers")) {
fun functionModifiers() = dumpMetadata(testLibrary("FunctionModifiers")) {
"""
package <root> {
@@ -242,7 +242,7 @@ class ContentsTest {
@Test
// TODO: Support enum entry methods in serialization/deserialization.
fun enum() = klibContents(testLibrary("Enum")) {
fun enum() = dumpMetadata(testLibrary("Enum")) {
"""
package <root> {
@@ -262,7 +262,7 @@ class ContentsTest {
@Test
// TODO: Support getter/setter annotations in serialization/deserialization.
fun accessors() = klibContents(testLibrary("Accessors")) {
fun accessors() = dumpMetadata(testLibrary("Accessors")) {
"""
package custom.pkg {
annotation class A constructor() : Annotation
@@ -287,7 +287,7 @@ class ContentsTest {
}
@Test
fun topLevelPropertiesCustomPackage() = klibContents(testLibrary("TopLevelPropertiesCustomPackage")) {
fun topLevelPropertiesCustomPackage() = dumpMetadata(testLibrary("TopLevelPropertiesCustomPackage")) {
"""
package custom.pkg {
typealias MyTransformer = (String) -> Int
@@ -300,7 +300,7 @@ class ContentsTest {
}
@Test
fun topLevelPropertiesRootPackage() = klibContents(testLibrary("TopLevelPropertiesRootPackage")) {
fun topLevelPropertiesRootPackage() = dumpMetadata(testLibrary("TopLevelPropertiesRootPackage")) {
"""
package <root> {
typealias MyTransformer = (String) -> Int
@@ -313,7 +313,7 @@ class ContentsTest {
}
@Test
fun topLevelPropertiesWithClassesCustomPackage() = klibContents(testLibrary("TopLevelPropertiesWithClassesCustomPackage")) {
fun topLevelPropertiesWithClassesCustomPackage() = dumpMetadata(testLibrary("TopLevelPropertiesWithClassesCustomPackage")) {
"""
package custom.pkg {
object Bar
@@ -328,7 +328,7 @@ class ContentsTest {
}
@Test
fun topLevelPropertiesWithClassesRootPackage() = klibContents(testLibrary("TopLevelPropertiesWithClassesRootPackage")) {
fun topLevelPropertiesWithClassesRootPackage() = dumpMetadata(testLibrary("TopLevelPropertiesWithClassesRootPackage")) {
"""
package <root> {
object Bar