override fun compile()

in hot-reload-core/src/testFixtures/kotlin/org/jetbrains/compose/reload/core/testFixtures/compileCode.kt [87:131]


    override fun compile(code: Map<String, String>): Map<String, ByteArray> {
        code.forEach { path, sourceCode ->
            workingDir.resolve(path).createParentDirectories().writeText(sourceCode)
        }

        val classesDir = workingDir.resolve("classes")

        val arguments = K2JVMCompilerArguments()
        arguments.moduleName = "testModule"
        arguments.noStdlib = true
        arguments.kotlinHome = null
        arguments.jvmTarget = "11"
        arguments.destinationAsFile = workingDir.resolve("classes").toFile()

        arguments.classpathAsList = System.getProperty("testCompilerClasspath")
            .split(File.pathSeparator)
            .map { absolutePath -> File(absolutePath) }

        arguments.pluginClasspaths = System.getProperty("testComposeCompilerClasspath")
            .split(File.pathSeparator)
            .toTypedArray()

        arguments.pluginOptions = listOfNotNull(
            "plugin:androidx.compose.compiler.plugins.kotlin:featureFlag=-OptimizeNonSkippingGroups"
                .takeIf { options[CompilerOption.OptimizeNonSkippingGroups] == false },
            "plugin:androidx.compose.compiler.plugins.kotlin:generateFunctionKeyMetaAnnotations=true"
                .takeIf { options[CompilerOption.GenerateFunctionKeyMetaAnnotations] == true },
        ).toTypedArray()

        arguments.freeArgs = code.keys.map { path -> workingDir.resolve(path).absolutePathString() }

        val result = K2JVMCompiler().exec(
            PrintingMessageCollector(System.err, MessageRenderer.GRADLE_STYLE, true),
            Services.EMPTY,
            arguments
        )

        if (result.code != 0) {
            error("Failed compiling code (${result.code})")
        }

        return classesDir.listDirectoryEntries("*.class").associate { path ->
            path.relativeTo(classesDir).pathString to path.readBytes()
        }
    }