[AA] Tests: Improve handling of dependencyPaths

- The name wasn't specific enough.
- Remove default `emptyList()` argument from `CompiledLibraryProvider`
  so that passing `dependencyBinaryRoots` isn't missed. (My changes
  didn't include it in `KtLibraryBinaryModuleFactoryBase` yet, but it
  was actually missed from `KtLibrarySourceModuleFactory` even in the
  original commit.)

^KT-65960
^KT-64994
This commit is contained in:
Marco Pennekamp
2024-02-26 16:11:42 +01:00
committed by Space Team
parent 5663521a36
commit 3f04604187
11 changed files with 27 additions and 22 deletions
@@ -32,7 +32,7 @@ object KtCodeFragmentModuleFactory : KtModuleFactory {
override fun createModule(
testModule: TestModule,
contextModule: KtTestModule?,
dependencyPaths: Collection<Path>,
dependencyBinaryRoots: Collection<Path>,
testServices: TestServices,
project: Project,
): KtTestModule {
@@ -23,11 +23,11 @@ abstract class KtLibraryBinaryModuleFactoryBase : KtModuleFactory {
override fun createModule(
testModule: TestModule,
contextModule: KtTestModule?,
dependencyBinaryRoots: Collection<Path>,
testServices: TestServices,
project: Project,
dependencyPaths: Collection<Path>,
): KtTestModule {
val binaryRoot = testServices.compiledLibraryProvider.compileToLibrary(testModule).artifact
val binaryRoot = testServices.compiledLibraryProvider.compileToLibrary(testModule, dependencyBinaryRoots).artifact
val decompiledFiles = decompileToPsiFiles(binaryRoot, testServices, project)
return KtTestModule(
@@ -25,13 +25,13 @@ object KtLibrarySourceModuleFactory : KtModuleFactory {
override fun createModule(
testModule: TestModule,
contextModule: KtTestModule?,
dependencyPaths: Collection<Path>,
dependencyBinaryRoots: Collection<Path>,
testServices: TestServices,
project: Project,
): KtTestModule {
Assume.assumeFalse("Compilation of multi-platform libraries is not supported", testModule.targetPlatform.isMultiPlatform())
val (libraryJar, librarySourcesJar) = testServices.compiledLibraryProvider.compileToLibrary(testModule)
val (libraryJar, librarySourcesJar) = testServices.compiledLibraryProvider.compileToLibrary(testModule, dependencyBinaryRoots)
require(librarySourcesJar != null)
@@ -20,13 +20,13 @@ fun interface KtModuleFactory : TestService {
* @param contextModule a module to use as a context module. Some kinds of modules (such as dangling file modules) require a
* context module. Modules representing code fragments also require a context element. That is why the [KtTestModule] is passed
* instead of a plain [KtModule][org.jetbrains.kotlin.analysis.project.structure.KtModule].
* @param dependencyPaths The binary roots of [testModule]'s binary library dependencies. This allows avoiding unresolved symbol issues
* when compiling test binary libraries that depend on other test binary libraries.
* @param dependencyBinaryRoots The binary roots of [testModule]'s binary library dependencies. This allows avoiding unresolved symbol
* issues when compiling test binary libraries that depend on other test binary libraries.
*/
fun createModule(
testModule: TestModule,
contextModule: KtTestModule?,
dependencyPaths: Collection<Path>,
dependencyBinaryRoots: Collection<Path>,
testServices: TestServices,
project: Project,
): KtTestModule
@@ -19,7 +19,7 @@ object KtScriptModuleFactory : KtModuleFactory {
override fun createModule(
testModule: TestModule,
contextModule: KtTestModule?,
dependencyPaths: Collection<Path>,
dependencyBinaryRoots: Collection<Path>,
testServices: TestServices,
project: Project,
): KtTestModule {
@@ -19,7 +19,7 @@ object KtSourceModuleFactory : KtModuleFactory {
override fun createModule(
testModule: TestModule,
contextModule: KtTestModule?,
dependencyPaths: Collection<Path>,
dependencyBinaryRoots: Collection<Path>,
testServices: TestServices,
project: Project,
): KtTestModule {
@@ -40,15 +40,15 @@ abstract class CliTestModuleCompiler : TestModuleCompiler() {
override fun compile(
tmpDir: Path,
module: TestModule,
dependencyBinaryRoots: Collection<Path>,
testServices: TestServices,
dependencyPaths: Collection<Path>,
): Path = CompilerExecutor.compileLibrary(
compilerKind,
tmpDir,
buildCompilerOptions(module, testServices),
compilationErrorExpected = Directives.COMPILATION_ERRORS in module.directives,
libraryName = module.name,
extraClasspath = buildExtraClasspath(module, testServices) + dependencyPaths.map { it.pathString },
extraClasspath = buildExtraClasspath(module, dependencyBinaryRoots, testServices),
)
override fun compileTestModuleToLibrarySources(module: TestModule, testServices: TestServices): Path {
@@ -65,8 +65,13 @@ abstract class CliTestModuleCompiler : TestModuleCompiler() {
return librarySourcesPath
}
private fun buildExtraClasspath(module: TestModule, testServices: TestServices): List<String> = buildList {
private fun buildExtraClasspath(
module: TestModule,
dependencyBinaryRoots: Collection<Path>,
testServices: TestServices,
): List<String> = buildList {
addAll(buildPlatformExtraClasspath(module, testServices))
dependencyBinaryRoots.mapTo(this) { it.pathString }
}
protected open fun buildPlatformExtraClasspath(module: TestModule, testServices: TestServices): List<String> = emptyList()
@@ -151,8 +156,8 @@ class DispatchingTestModuleCompiler : TestModuleCompiler() {
CompilerExecutor.CompilerKind.JS to JsKlibTestModuleCompiler(),
)
override fun compile(tmpDir: Path, module: TestModule, testServices: TestServices, dependencyPaths: Collection<Path>): Path {
return getCompiler(module).compileTestModuleToLibrary(module, testServices, dependencyPaths)
override fun compile(tmpDir: Path, module: TestModule, dependencyBinaryRoots: Collection<Path>, testServices: TestServices): Path {
return getCompiler(module).compileTestModuleToLibrary(module, dependencyBinaryRoots, testServices)
}
override fun compileTestModuleToLibrarySources(module: TestModule, testServices: TestServices): Path {
@@ -13,11 +13,11 @@ import java.nio.file.Path
class CompiledLibraryProvider(private val testServices: TestServices) : TestService {
private val libraries = mutableMapOf<String, CompiledLibrary>()
fun compileToLibrary(module: TestModule, dependencyPaths: Collection<Path> = emptyList()): CompiledLibrary {
fun compileToLibrary(module: TestModule, dependencyBinaryRoots: Collection<Path>): CompiledLibrary {
if (module.name in libraries) {
error("Library for module ${module.name} is already compiled")
}
val libraryJar = testServices.testModuleCompiler.compileTestModuleToLibrary(module, testServices, dependencyPaths)
val libraryJar = testServices.testModuleCompiler.compileTestModuleToLibrary(module, dependencyBinaryRoots, testServices)
val librarySourcesJar = testServices.testModuleCompiler.compileTestModuleToLibrarySources(module, testServices)
return CompiledLibrary(libraryJar, librarySourcesJar).also { libraries[module.name] = it }
@@ -18,7 +18,7 @@ import kotlin.io.path.div
import kotlin.io.path.writeText
abstract class TestModuleCompiler : TestService {
fun compileTestModuleToLibrary(module: TestModule, testServices: TestServices, dependencyPaths: Collection<Path> = emptyList()): Path {
fun compileTestModuleToLibrary(module: TestModule, dependencyBinaryRoots: Collection<Path>, testServices: TestServices): Path {
val tmpDir = KtTestUtil.tmpDir("testSourcesToCompile").toPath()
for (testFile in module.files) {
val text = testServices.sourceFileProvider.getContentOfSourceFile(testFile)
@@ -28,14 +28,14 @@ abstract class TestModuleCompiler : TestService {
val tmpSourceFile = filePath.createFile()
tmpSourceFile.writeText(text)
}
return compile(tmpDir, module, testServices, dependencyPaths)
return compile(tmpDir, module, dependencyBinaryRoots, testServices)
}
abstract fun compile(
tmpDir: Path,
module: TestModule,
dependencyBinaryRoots: Collection<Path>,
testServices: TestServices,
dependencyPaths: Collection<Path> = emptyList(),
): Path
abstract fun compileTestModuleToLibrarySources(module: TestModule, testServices: TestServices): Path?