mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Fix bug mixing R.java on Kotlin sources.
Fix https://github.com/cbeust/kobalt-android/issues/6
This commit is contained in:
parent
933b50c39c
commit
3bec28e8e0
4 changed files with 34 additions and 12 deletions
|
@ -28,6 +28,11 @@ interface ICompiler : Comparable<ICompiler> {
|
||||||
val priority: Int get() = DEFAULT_PRIORITY
|
val priority: Int get() = DEFAULT_PRIORITY
|
||||||
|
|
||||||
override fun compareTo(other: ICompiler) = priority.compareTo(other.priority)
|
override fun compareTo(other: ICompiler) = priority.compareTo(other.priority)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can this compiler be passed directories or does it need individual source files?
|
||||||
|
*/
|
||||||
|
val canCompileDirectories: Boolean get() = false
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ICompilerContributor : IProjectAffinity {
|
interface ICompilerContributor : IProjectAffinity {
|
||||||
|
|
|
@ -207,7 +207,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
if (sourceFiles.size > 0) {
|
if (sourceFiles.size > 0) {
|
||||||
// TODO: createCompilerActionInfo recalculates the source files, only compute them
|
// TODO: createCompilerActionInfo recalculates the source files, only compute them
|
||||||
// once and pass them
|
// once and pass them
|
||||||
val info = createCompilerActionInfo(project, context, isTest, sourceDirectories,
|
val info = createCompilerActionInfo(project, context, compiler, isTest, sourceDirectories,
|
||||||
sourceSuffixes = compiler.sourceSuffixes)
|
sourceSuffixes = compiler.sourceSuffixes)
|
||||||
val thisResult = compiler.compile(project, context, info)
|
val thisResult = compiler.compile(project, context, info)
|
||||||
results.add(thisResult)
|
results.add(thisResult)
|
||||||
|
@ -239,11 +239,13 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
fun taskJavadoc(project: Project): TaskResult {
|
fun taskJavadoc(project: Project): TaskResult {
|
||||||
val docGenerator = ActorUtils.selectAffinityActor(project, context, context.pluginInfo.docContributors)
|
val docGenerator = ActorUtils.selectAffinityActor(project, context, context.pluginInfo.docContributors)
|
||||||
if (docGenerator != null) {
|
if (docGenerator != null) {
|
||||||
val contributors = ActorUtils.selectAffinityActors(project, context, context.pluginInfo.compilerContributors)
|
val contributors =
|
||||||
|
ActorUtils.selectAffinityActors(project, context, context.pluginInfo.compilerContributors)
|
||||||
var result: TaskResult? = null
|
var result: TaskResult? = null
|
||||||
contributors.forEach {
|
contributors.forEach {
|
||||||
it.compilersFor(project, context).forEach { compiler ->
|
it.compilersFor(project, context).forEach { compiler ->
|
||||||
result = docGenerator.generateDoc(project, context, createCompilerActionInfo(project, context,
|
result = docGenerator.generateDoc(project, context, createCompilerActionInfo(project, context,
|
||||||
|
compiler,
|
||||||
isTest = false, sourceDirectories = sourceDirectories,
|
isTest = false, sourceDirectories = sourceDirectories,
|
||||||
sourceSuffixes = compiler.sourceSuffixes))
|
sourceSuffixes = compiler.sourceSuffixes))
|
||||||
}
|
}
|
||||||
|
@ -267,8 +269,8 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
* Create a CompilerActionInfo (all the information that a compiler needs to know) for the given parameters.
|
* Create a CompilerActionInfo (all the information that a compiler needs to know) for the given parameters.
|
||||||
* Runs all the contributors and interceptors relevant to that task.
|
* Runs all the contributors and interceptors relevant to that task.
|
||||||
*/
|
*/
|
||||||
protected fun createCompilerActionInfo(project: Project, context: KobaltContext, isTest: Boolean,
|
protected fun createCompilerActionInfo(project: Project, context: KobaltContext, compiler: ICompiler,
|
||||||
sourceDirectories: List<File>, sourceSuffixes: List<String>): CompilerActionInfo {
|
isTest: Boolean, sourceDirectories: List<File>, sourceSuffixes: List<String>): CompilerActionInfo {
|
||||||
copyResources(project, SourceSet.of(isTest))
|
copyResources(project, SourceSet.of(isTest))
|
||||||
|
|
||||||
val fullClasspath = if (isTest) dependencyManager.testDependencies(project, context)
|
val fullClasspath = if (isTest) dependencyManager.testDependencies(project, context)
|
||||||
|
@ -286,12 +288,14 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
|
|
||||||
val initialSourceDirectories = ArrayList<File>(sourceDirectories)
|
val initialSourceDirectories = ArrayList<File>(sourceDirectories)
|
||||||
// Source directories from the contributors
|
// Source directories from the contributors
|
||||||
initialSourceDirectories.addAll(
|
val contributedSourceDirs =
|
||||||
if (isTest) {
|
if (isTest) {
|
||||||
context.pluginInfo.testSourceDirContributors.flatMap { it.testSourceDirectoriesFor(project, context) }
|
context.pluginInfo.testSourceDirContributors.flatMap { it.testSourceDirectoriesFor(project, context) }
|
||||||
} else {
|
} else {
|
||||||
context.pluginInfo.sourceDirContributors.flatMap { it.sourceDirectoriesFor(project, context) }
|
context.pluginInfo.sourceDirContributors.flatMap { it.sourceDirectoriesFor(project, context) }
|
||||||
})
|
}
|
||||||
|
|
||||||
|
initialSourceDirectories.addAll(contributedSourceDirs)
|
||||||
|
|
||||||
// Transform them with the interceptors, if any
|
// Transform them with the interceptors, if any
|
||||||
val allSourceDirectories =
|
val allSourceDirectories =
|
||||||
|
@ -308,9 +312,13 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
|
|
||||||
// Now that we have all the source directories, find all the source files in them
|
// Now that we have all the source directories, find all the source files in them
|
||||||
val projectDirectory = File(project.directory)
|
val projectDirectory = File(project.directory)
|
||||||
val sourceFiles = files.findRecursively(projectDirectory, allSourceDirectories,
|
val sourceFiles = if (compiler.canCompileDirectories) {
|
||||||
|
allSourceDirectories.map { it.path }
|
||||||
|
} else {
|
||||||
|
files.findRecursively(projectDirectory, allSourceDirectories,
|
||||||
{ file -> sourceSuffixes.any { file.endsWith(it) } })
|
{ file -> sourceSuffixes.any { file.endsWith(it) } })
|
||||||
.map { File(projectDirectory, it).path }
|
.map { File(projectDirectory, it).path }
|
||||||
|
}
|
||||||
|
|
||||||
// Special treatment if we are compiling Kotlin files and the project also has a java source
|
// Special treatment if we are compiling Kotlin files and the project also has a java source
|
||||||
// directory. In this case, also pass that java source directory to the Kotlin compiler as is
|
// directory. In this case, also pass that java source directory to the Kotlin compiler as is
|
||||||
|
@ -333,8 +341,10 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extraSourceFiles.addAll(contributedSourceDirs.filter { it.exists() }.map { it.path })
|
||||||
|
val allSources= (sourceFiles + extraSourceFiles).distinct()
|
||||||
// Finally, alter the info with the compiler interceptors before returning it
|
// Finally, alter the info with the compiler interceptors before returning it
|
||||||
val initialActionInfo = CompilerActionInfo(projectDirectory.path, classpath, sourceFiles + extraSourceFiles,
|
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 */)
|
||||||
val result = context.pluginInfo.compilerInterceptors.fold(initialActionInfo, { ai, interceptor ->
|
val result = context.pluginInfo.compilerInterceptors.fold(initialActionInfo, { ai, interceptor ->
|
||||||
interceptor.intercept(project, context, ai)
|
interceptor.intercept(project, context, ai)
|
||||||
|
|
|
@ -44,7 +44,11 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) {
|
||||||
allArgs.addAll(info.compilerArgs)
|
allArgs.addAll(info.compilerArgs)
|
||||||
|
|
||||||
val fileManager = compiler.getStandardFileManager(null, null, null)
|
val fileManager = compiler.getStandardFileManager(null, null, null)
|
||||||
val fileObjects = fileManager.getJavaFileObjectsFromFiles(info.sourceFiles.map { File(it) })
|
val fileObjects = fileManager.getJavaFileObjectsFromFiles(info.sourceFiles.map {
|
||||||
|
File(it)
|
||||||
|
}.filter {
|
||||||
|
it.isFile
|
||||||
|
})
|
||||||
val dc = DiagnosticCollector<JavaFileObject>()
|
val dc = DiagnosticCollector<JavaFileObject>()
|
||||||
val classes = arrayListOf<String>()
|
val classes = arrayListOf<String>()
|
||||||
val writer = PrintWriter(System.out)
|
val writer = PrintWriter(System.out)
|
||||||
|
|
|
@ -121,6 +121,9 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depen
|
||||||
|
|
||||||
override val sourceDirectory = "kotlin"
|
override val sourceDirectory = "kotlin"
|
||||||
|
|
||||||
|
/** kotlinc can be passed directories */
|
||||||
|
override val canCompileDirectories = true
|
||||||
|
|
||||||
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo): TaskResult {
|
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo): TaskResult {
|
||||||
val result =
|
val result =
|
||||||
if (info.sourceFiles.size > 0) {
|
if (info.sourceFiles.size > 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue