Repository: JetBrains/kotlin
File: kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt (Kotlin)

Code before:

    manifestAddend?.parentFile?.mkdirs()
    manifestAddend?.let { def.manifestAddendProperties.storeProperties(it) }

    val compilerArgs = stubIrContext.libraryForCStubs.compilerArgs.toTypedArray()
    val nativeOutputPath: String = when (flavor) {
        KotlinPlatform.JVM -> {
            val outOFile = tempFiles.create(libName,".o")
            val compilerCmd = arrayOf(compiler, *compilerArgs,
                    "-c", outCFile.absolutePath, "-o", outOFile.absolutePath)
            runCmd(compilerCmd, verbose)
            val linkerOpts =
                    def.config.linkerOpts.toTypedArray() +
                            tool.getDefaultCompilerOptsForLanguage(library.language) +
                            additionalLinkerOpts
            val outLib = File(nativeLibsDir, System.mapLibraryName(libName))
            val linkerCmd = arrayOf(linker,
                    outOFile.absolutePath, "-shared", "-o", outLib.absolutePath,
                    *linkerOpts)
            runCmd(linkerCmd, verbose)
            outOFile.absolutePath
        }
        KotlinPlatform.NATIVE -> {
            val outLib = File(nativeLibsDir, "$libName.bc")
            val compilerCmd = arrayOf(compiler, *compilerArgs,
                    "-emit-llvm", "-x", "c", "-c", "-", "-o", outLib.absolutePath)
            runCmd(compilerCmd, verbose, redirectInputFile = File(outCFile.absolutePath))
            outLib.absolutePath
        }
    }

    val compiledFiles = compileSources(nativeLibsDir, tool, cinteropArguments)

    return when (stubIrOutput) {
        is StubIrDriver.Result.SourceCode -> {
            val bitcodePaths = compiledFiles.map {  listOf("-native-library", it) }.flatten()
            argsToCompiler(staticLibraries, libraryPaths) + bitcodePaths
        }
        is StubIrDriver.Result.Metadata -> {
            val stdlibDependency = resolver.resolveWithDependencies(
                    emptyList(),
                    noDefaultLibs = true,
                    noEndorsedLibs = true
            ).getFullList()

            val nopack = cinteropArguments.nopack
            val outputPath = cinteropArguments.output.let {
                val suffix = CompilerOutputKind.LIBRARY.suffix(tool.target)
                if (nopack) it.removeSuffixIfPresent(suffix) else it.suffixIfNot(suffix)
            }


Review comment (suggestion):
The `outCFile` (despite its name) is not always in C, sometimes it is in Objective-C or C++, see the variable definition.

Code after:
        def.manifestAddendProperties[ForeignExceptionMode.manifestKey] =
                ForeignExceptionMode.byValue(it).value   // may throw IllegalArgumentException
    }

    manifestAddend?.parentFile?.mkdirs()
    manifestAddend?.let { def.manifestAddendProperties.storeProperties(it) }

    val compilerArgs = stubIrContext.libraryForCStubs.compilerArgs.toTypedArray()
    val nativeOutputPath: String = when (flavor) {
        KotlinPlatform.JVM -> {
            val outOFile = tempFiles.create(libName,".o")
            val compilerCmd = arrayOf(compiler, *compilerArgs,
                    "-c", outCFile.absolutePath, "-o", outOFile.absolutePath)
            runCmd(compilerCmd, verbose)
            val linkerOpts =
                    def.config.linkerOpts.toTypedArray() +
                            tool.getDefaultCompilerOptsForLanguage(library.language) +
                            additionalLinkerOpts
            val outLib = File(nativeLibsDir, System.mapLibraryName(libName))
            val linkerCmd = arrayOf(linker,
                    outOFile.absolutePath, "-shared", "-o", outLib.absolutePath,
                    *linkerOpts)
            runCmd(linkerCmd, verbose)
            outOFile.absolutePath
        }
        KotlinPlatform.NATIVE -> {
            val outLib = File(nativeLibsDir, "$libName.bc")
            // Note that the output bitcode contains the source file path, which can lead to non-deterministc builds (see KT-54284).
            // The source file is passed in via stdin to ensure the output library is deterministic.
            val compilerCmd = arrayOf(compiler, *compilerArgs,
                    "-emit-llvm", "-x", library.language.clangLanguageName, "-c", "-", "-o", outLib.absolutePath)
            runCmd(compilerCmd, verbose, redirectInputFile = File(outCFile.absolutePath))
            outLib.absolutePath
        }
    }

    val compiledFiles = compileSources(nativeLibsDir, tool, cinteropArguments)

    return when (stubIrOutput) {
        is StubIrDriver.Result.SourceCode -> {
            val bitcodePaths = compiledFiles.map {  listOf("-native-library", it) }.flatten()
            argsToCompiler(staticLibraries, libraryPaths) + bitcodePaths
        }
        is StubIrDriver.Result.Metadata -> {
            val stdlibDependency = resolver.resolveWithDependencies(
                    emptyList(),
                    noDefaultLibs = true,
                    noEndorsedLibs = true
            ).getFullList()

            val nopack = cinteropArguments.nopack