[K/N] avoid overwriting header when output paths are equal

^KT-65442
This commit is contained in:
Johan Bay
2024-01-08 16:03:10 +01:00
committed by Space Cloud
parent 709076acc9
commit a2516548e4
3 changed files with 12 additions and 4 deletions
@@ -288,7 +288,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
internal val metadataKlib get() = configuration.getBoolean(CommonConfigurationKeys.METADATA_KLIB)
internal val headerKlibPath get() = configuration.get(KonanConfigKeys.HEADER_KLIB)
internal val headerKlibPath get() = configuration.get(KonanConfigKeys.HEADER_KLIB)?.removeSuffixIfPresent(".klib")
internal val produceStaticFramework get() = configuration.getBoolean(KonanConfigKeys.STATIC_FRAMEWORK)
@@ -119,6 +119,9 @@ internal class DynamicCompilerDriver : CompilerDriver() {
if (!headerKlibPath.isNullOrEmpty()) {
val headerKlib = engine.runFir2IrSerializer(FirSerializerInput(fir2IrOutput, produceHeaderKlib = true))
engine.writeKlib(headerKlib, headerKlibPath)
// Don't overwrite the header klib with the full klib and stop compilation here.
// By providing the same path for both regular output and header klib we can skip emitting the full klib.
if (File(config.outputPath).canonicalPath == File(headerKlibPath).canonicalPath) return null
}
engine.runK2SpecialBackendChecks(fir2IrOutput)
@@ -137,9 +140,14 @@ internal class DynamicCompilerDriver : CompilerDriver() {
} else {
engine.runPsiToIr(frontendOutput, isProducingLibrary = true) as PsiToIrOutput.ForKlib
}
if (!config.headerKlibPath.isNullOrEmpty()) {
val headerKlibPath = config.headerKlibPath
if (!headerKlibPath.isNullOrEmpty()) {
val headerKlib = engine.runSerializer(frontendOutput.moduleDescriptor, psiToIrOutput, produceHeaderKlib = true)
engine.writeKlib(headerKlib, config.headerKlibPath)
engine.writeKlib(headerKlib, headerKlibPath)
// Don't overwrite the header klib with the full klib and stop compilation here.
// By providing the same path for both regular output and header klib we can skip emitting the full klib.
if (File(config.outputPath).canonicalPath == File(headerKlibPath).canonicalPath) return null
}
return engine.runSerializer(frontendOutput.moduleDescriptor, psiToIrOutput)
}
@@ -26,7 +26,7 @@ internal val WriteKlibPhase = createSimpleNamedCompilerPhase<PhaseContext, KlibW
) { context, input ->
val config = context.config
val configuration = config.configuration
val outputFiles = OutputFiles(input.customOutputPath?.removeSuffixIfPresent(".klib")
val outputFiles = OutputFiles(input.customOutputPath
?: config.outputPath, config.target, config.produce)
val nopack = configuration.getBoolean(KonanConfigKeys.NOPACK)
val output = outputFiles.klibOutputFileName(!nopack)