diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/CompilerActionInfo.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/CompilerActionInfo.kt index 480e5a38..f0be2eb5 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/CompilerActionInfo.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/CompilerActionInfo.kt @@ -10,6 +10,5 @@ data class CompilerActionInfo(val directory: String?, val sourceFiles: List, val suffixesBeingCompiled: List, val outputDir: File, - val compilerArgs: List) - - + val compilerArgs: List, + val friendPaths: List) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt index 27cc8f0b..fddcc9eb 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt @@ -170,10 +170,17 @@ class CompilerUtils @Inject constructor(val files: KFiles, // Finally, alter the info with the compiler interceptors before returning it val initialActionInfo = CompilerActionInfo(projectDirectory.path, classpath, allSources, - sourceSuffixes, buildDirectory, emptyList() /* the flags will be provided by flag contributors */) + sourceSuffixes, buildDirectory, emptyList() /* the flags will be provided by flag contributors */, + emptyList()) val result = context.pluginInfo.compilerInterceptors.fold(initialActionInfo, { ai, interceptor -> interceptor.intercept(project, context, ai) }) + + // + // friendPaths + // + val friendPaths = KFiles.joinDir(project.buildDirectory, KFiles.CLASSES_DIR) + return result } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt index 43fc38b4..4d9d2db7 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt @@ -33,8 +33,9 @@ abstract class GenericTestRunner: ITestRunnerContributor { File(this).mkdirs() } - val testClasses = IFileSpec.GlobSpec(toClassPaths(testConfig.testIncludes)) - .toFiles(project.directory, path, testConfig.testExcludes.map { Glob(it) }) + val files = IFileSpec.GlobSpec(toClassPaths(testConfig.testIncludes)) + .toFiles(project.directory, path, testConfig.testExcludes.map { Glob(it) }) + val testClasses = files .filter { ! it.path.contains('$') } .map { File(KFiles.joinDir(project.directory, testClassDir, it.path)) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt index 0aede4b9..8fbef3dd 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt @@ -92,7 +92,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va val dependencies = dependencyManager.calculateDependencies(project, context) val info = CompilerActionInfo(sourceDir.absolutePath, dependencies, listOf(javaFile.absolutePath), listOf("java"), File(sourceDir, "generated"), - listOf()) + listOf(), listOf()) val results = compilerUtils.invokeCompiler(project, context, javaCompiler, info) } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index f3cc93f3..cb7dac33 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -9,10 +9,7 @@ import com.beust.kobalt.internal.KotlinJarFiles import com.beust.kobalt.kotlin.ParentLastClassLoader import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.dependency.FileDependency -import com.beust.kobalt.misc.KFiles -import com.beust.kobalt.misc.KobaltExecutors -import com.beust.kobalt.misc.Strings -import com.beust.kobalt.misc.log +import com.beust.kobalt.misc.* import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation @@ -49,7 +46,7 @@ class KotlinCompiler @Inject constructor( // Don't display the message if compiling Build.kt log(1, " Kotlin $version compiling " + Strings.pluralizeAll(info.sourceFiles.size, "file")) } - val cp = compilerFirst(info.dependencies.map {it.jarFile.get()}) + val cp = compilerFirst(info.dependencies.map { it.jarFile.get() }) val infoDir = info.directory val outputDir = if (infoDir != null) { KFiles.joinDir(infoDir, info.outputDir.path) @@ -76,19 +73,19 @@ class KotlinCompiler @Inject constructor( allArgs.add("-no-stdlib") } -// return invokeCompilerWithCompilerArgs(projectName ?: "kobalt-" + Random().nextInt(), outputDir, classpath, -// info.sourceFiles) - return invokeCompilerWithStringArgs(projectName ?: "kobalt-" + Random().nextInt(), cp, allArgs) + return invokeCompilerWithCompilerArgs(projectName ?: "kobalt-" + Random().nextInt(), outputDir, classpath, + info.sourceFiles, info.friendPaths.toTypedArray()) +// return invokeCompilerWithStringArgs(projectName ?: "kobalt-" + Random().nextInt(), cp, allArgs) } private fun invokeCompilerWithCompilerArgs(projectName: String, outputDir: String?, classpathString: String, - sourceFiles: List): TaskResult { + sourceFiles: List, friends: Array): TaskResult { val args = K2JVMCompilerArguments().apply { moduleName = projectName destination = outputDir classpath = classpathString freeArgs = sourceFiles - friendPaths = arrayOf("kobaltBuild\\classes") + friendPaths = friends } log(1, "Invoking K2JVMCompiler with arguments:" + " -moduleName " + args.moduleName @@ -199,14 +196,26 @@ class KotlinCompiler @Inject constructor( // .map { FileDependency(it) } val dependencies = compileDependencies + otherClasspath.map { FileDependency(it) } - val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args) + + // The friendPaths is a private setting for the Kotlin compiler that enables a compilation unit + // to see internal symbols from another compilation unit. By default, set it to kobaltBuild/classes + // so that tests can see internal from the main code + val friendPaths = + if (project != null) { + listOf(KFiles.joinDir(project.directory, project.buildDirectory, KFiles.CLASSES_DIR)) + } else { + emptyList() + } + val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args, + friendPaths) + return jvmCompiler.doCompile(project, context, compilerAction, info) } } class KConfiguration @Inject constructor(val compiler: KotlinCompiler){ private val classpath = arrayListOf() - val dependencies = arrayListOf() + var dependencies = arrayListOf() var source = arrayListOf() var output: File by Delegates.notNull() val args = arrayListOf()