[KLIB tool] Introduce a '-test-mode' CLI option
This is an option that allows running the commands that support it in a special "test mode". The "test mode" means (but not limited to) that a command may, for example, sort the output which is unsorted by default, and this way guarantee stable output. This is essentially helpful for tests, which rely on the command output. ^KT-62340
This commit is contained in:
committed by
Space Team
parent
82115c1f26
commit
5b7c11ae39
@@ -13,4 +13,5 @@ internal class KlibToolArguments(
|
|||||||
val repository: String?,
|
val repository: String?,
|
||||||
val printSignatures: Boolean,
|
val printSignatures: Boolean,
|
||||||
val signatureVersion: KotlinIrSignatureVersion?,
|
val signatureVersion: KotlinIrSignatureVersion?,
|
||||||
|
val testMode: Boolean,
|
||||||
)
|
)
|
||||||
|
|||||||
+12
-1
@@ -41,6 +41,7 @@ internal class KlibToolArgumentsParser {
|
|||||||
repository = extraArgs[ExtraOption.REPOSITORY]?.last(),
|
repository = extraArgs[ExtraOption.REPOSITORY]?.last(),
|
||||||
printSignatures = extraArgs[ExtraOption.PRINT_SIGNATURES]?.last()?.toBoolean() == true,
|
printSignatures = extraArgs[ExtraOption.PRINT_SIGNATURES]?.last()?.toBoolean() == true,
|
||||||
signatureVersion,
|
signatureVersion,
|
||||||
|
testMode = extraArgs[ExtraOption.INTERNAL_TEST_MODE]?.last()?.toBoolean() == true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +106,17 @@ internal class KlibToolArgumentsParser {
|
|||||||
private enum class ExtraOption(val option: String) {
|
private enum class ExtraOption(val option: String) {
|
||||||
REPOSITORY("-repository"),
|
REPOSITORY("-repository"),
|
||||||
PRINT_SIGNATURES("-print-signatures"),
|
PRINT_SIGNATURES("-print-signatures"),
|
||||||
SIGNATURE_VERSION("-signature-version");
|
SIGNATURE_VERSION("-signature-version"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is an option that allows running the commands that support it in a special "test mode".
|
||||||
|
* The "test mode" means (but not limited to) that a command may, for example, sort the output
|
||||||
|
* which is unsorted by default, and this way guarantee stable output. This is essentially helpful
|
||||||
|
* for tests, which rely on the command output.
|
||||||
|
*
|
||||||
|
* NOTE: This option is not supposed to be advertised in KLIB tool's "usage info".
|
||||||
|
*/
|
||||||
|
INTERNAL_TEST_MODE("-test-mode");
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun parseOrNull(option: String): ExtraOption? = entries.firstOrNull { it.option == option }
|
fun parseOrNull(option: String): ExtraOption? = entries.firstOrNull { it.option == option }
|
||||||
|
|||||||
+6
@@ -40,6 +40,12 @@ internal class KotlinpBasedMetadataDumper(
|
|||||||
|
|
||||||
private val printer = Printer(output)
|
private val printer = Printer(output)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param testMode if `true` then a special pre-processing is performed towards the metadata before rendering:
|
||||||
|
* - empty package fragments are removed
|
||||||
|
* - package fragments with the same package FQN are merged
|
||||||
|
* - classes are sorted in alphabetical order
|
||||||
|
*/
|
||||||
fun dumpLibrary(library: KotlinLibrary, testMode: Boolean) {
|
fun dumpLibrary(library: KotlinLibrary, testMode: Boolean) {
|
||||||
val moduleMetadata = loadModuleMetadata(library)
|
val moduleMetadata = loadModuleMetadata(library)
|
||||||
.let { originalModuleMetadata -> if (testMode) preprocessMetadataForTests(originalModuleMetadata) else originalModuleMetadata }
|
.let { originalModuleMetadata -> if (testMode) preprocessMetadataForTests(originalModuleMetadata) else originalModuleMetadata }
|
||||||
|
|||||||
@@ -198,14 +198,8 @@ internal class KlibToolCommand(private val args: KlibToolArguments) {
|
|||||||
printer.print(module)
|
printer.print(module)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
fun dumpMetadata(output: Appendable) {
|
||||||
* @param testMode if `true` then a special pre-processing is performed towards the metadata before rendering:
|
KotlinpBasedMetadataDumper(output, args.printSignatures, args.signatureVersion).dumpLibrary(libraryInCurrentDir(args.libraryNameOrPath), args.testMode)
|
||||||
* - empty package fragments are removed
|
|
||||||
* - package fragments with the same package FQN are merged
|
|
||||||
* - classes are sorted in alphabetical order
|
|
||||||
*/
|
|
||||||
fun dumpMetadata(output: Appendable, testMode: Boolean) {
|
|
||||||
KotlinpBasedMetadataDumper(output, args.printSignatures, args.signatureVersion).dumpLibrary(libraryInCurrentDir(args.libraryNameOrPath), testMode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun signatures(output: Appendable) {
|
fun signatures(output: Appendable) {
|
||||||
@@ -258,7 +252,7 @@ fun main(rawArgs: Array<String>) {
|
|||||||
"dump-abi" -> command.dumpAbi(System.out)
|
"dump-abi" -> command.dumpAbi(System.out)
|
||||||
"dump-ir" -> command.dumpIr(System.out)
|
"dump-ir" -> command.dumpIr(System.out)
|
||||||
"dump-ir-signatures" -> command.dumpIrSignatures(System.out)
|
"dump-ir-signatures" -> command.dumpIrSignatures(System.out)
|
||||||
"dump-metadata" -> command.dumpMetadata(System.out, testMode = false)
|
"dump-metadata" -> command.dumpMetadata(System.out)
|
||||||
"dump-metadata-signatures" -> command.dumpMetadataSignatures(System.out)
|
"dump-metadata-signatures" -> command.dumpMetadataSignatures(System.out)
|
||||||
"contents" -> command.contents(System.out)
|
"contents" -> command.contents(System.out)
|
||||||
"signatures" -> command.signatures(System.out)
|
"signatures" -> command.signatures(System.out)
|
||||||
|
|||||||
Reference in New Issue
Block a user