Add -keep command line option to JS DCE tool

This commit is contained in:
Alexey Andreev
2017-04-26 18:15:08 +03:00
parent 9181140387
commit 522a56947c
6 changed files with 44 additions and 1 deletions
@@ -26,6 +26,13 @@ class K2JSDceArguments : CommonToolArguments() {
@JvmField
var outputDirectory: String? = null
@field:Argument(
value = "-keep",
valueDescription = "<fully.qualified.name[,]>",
description = "List of fully-qualified names of declarations that shouldn't be eliminated")
@JvmField
var declarationsToKeep: Array<String>? = null
@field:GradleOption(DefaultValues.BooleanFalseDefault::class)
@field:Argument(value = "-Xprint-reachability-info", description = "Print declarations marked as reachable")
@JvmField
@@ -49,7 +49,9 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
return ExitCode.COMPILATION_ERROR
}
val dceResult = DeadCodeElimination.run(files, emptySet()) {
val includedDeclarations = arguments.declarationsToKeep.orEmpty().toSet()
val dceResult = DeadCodeElimination.run(files, includedDeclarations) {
messageCollector.report(CompilerMessageSeverity.LOGGING, it)
}
val nodes = dceResult.reachableNodes