Implement --purge_user_libs konanc and cinterop flag

This commit is contained in:
Svyatoslav Scherbina
2017-11-02 18:36:58 +03:00
committed by SvyatoslavScherbina
parent 68d30205c4
commit 9829605a95
7 changed files with 22 additions and 5 deletions
@@ -120,6 +120,8 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
put(PRINT_LOCATIONS, arguments.printLocations)
put(PRINT_BITCODE, arguments.printBitCode)
put(PURGE_USER_LIBS, arguments.purgeUserLibs)
put(VERIFY_IR, arguments.verifyIr)
put(VERIFY_DESCRIPTORS, arguments.verifyDescriptors)
put(VERIFY_BITCODE, arguments.verifyBitCode)
@@ -121,6 +121,9 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
@Argument(value = "--print_locations", description = "Print locations")
var printLocations: Boolean = false
@Argument(value = "--purge_user_libs", description = "Don't link unused libraries even explicitly specified")
var purgeUserLibs: Boolean = false
@Argument(value = "--time", description = "Report execution time for compiler phases")
var timePhases: Boolean = false
@@ -73,6 +73,9 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
val moduleId: String
get() = configuration.get(KonanConfigKeys.MODULE_NAME) ?: File(outputName).name
internal val purgeUserLibs: Boolean
get() = configuration.getBoolean(KonanConfigKeys.PURGE_USER_LIBS)
private val libraryNames: List<String>
get() = configuration.getList(KonanConfigKeys.LIBRARY_FILES)
@@ -95,7 +98,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
fun librariesWithDependencies(moduleDescriptor: ModuleDescriptor?): List<KonanLibraryReader> {
if (moduleDescriptor == null) error("purgeUnneeded() only works correctly after resolve is over, and we have successfully marked package files as needed or not needed.")
return immediateLibraries.purgeUnneeded().withResolvedDependencies()
return immediateLibraries.purgeUnneeded(this).withResolvedDependencies()
}
private val loadedDescriptors = loadLibMetadata()
@@ -85,6 +85,8 @@ class KonanConfigKeys {
= CompilerConfigurationKey.create("compiler output kind")
val PROPERTY_FILE: CompilerConfigurationKey<String?>
= CompilerConfigurationKey.create("override default property file path")
val PURGE_USER_LIBS: CompilerConfigurationKey<Boolean>
= CompilerConfigurationKey.create("purge user-specified libs too")
val REPOSITORIES: CompilerConfigurationKey<List<String>>
= CompilerConfigurationKey.create("library search path repositories")
val RUNTIME_FILE: CompilerConfigurationKey<String?>
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.backend.konan.library.impl
import org.jetbrains.kotlin.backend.konan.KonanConfig
import org.jetbrains.kotlin.backend.konan.library.KonanLibraryReader
import org.jetbrains.kotlin.backend.konan.createInteropLibrary
import org.jetbrains.kotlin.backend.konan.serialization.emptyPackages
@@ -98,5 +99,6 @@ class LibraryReaderImpl(var libraryFile: File, val currentAbiVersion: Int,
}
internal fun <T: KonanLibraryReader> List<T>.purgeUnneeded(): List<T> = this.filter{ !it.isDefaultLibrary || it.isNeededForLink }
internal fun <T: KonanLibraryReader> List<T>.purgeUnneeded(config: KonanConfig): List<T> =
this.filter{ (!it.isDefaultLibrary && !config.purgeUserLibs) || it.isNeededForLink }
@@ -328,7 +328,7 @@ internal class Llvm(val context: Context, val llvmModule: LLVMModuleRef) {
}
val librariesToLink: List<KonanLibraryReader> get() = context.config.immediateLibraries
.filter { !it.isDefaultLibrary || it in usedLibraries }
.filter { (!it.isDefaultLibrary && !context.config.purgeUserLibs) || it in usedLibraries }
.withResolvedDependencies()
val librariesForLibraryManifest: List<KonanLibraryReader> get() {