1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-27 00:38:11 -07:00

Merge branch 'master' of github.com:cbeust/kobalt

This commit is contained in:
Cedric Beust 2015-12-09 18:10:18 -08:00
commit c3dbf616b6
14 changed files with 82 additions and 53 deletions

14
TODO.md
View file

@ -1,5 +1,18 @@
To do: To do:
Android:
- [ ] Dex dependencies into kobaltBuild/intermediates/pre-dexed and preserve those across builds
- [ ] Move the calculated applicationId back into the merged AndroidManifest.xml
- [ ] Dex from android builder
- [ ] Keep exploded aars between runs
- [ ] aars keep being refetched
- [ ] See if there is an android manifest file in builder
General
- [ ] Apt should run from serviceloader
- [ ] Auto add variant
- [ ] The test runner only selects classes with a parameterless constructor, which works for JUnit but not for TestNG - [ ] The test runner only selects classes with a parameterless constructor, which works for JUnit but not for TestNG
factories factories
- [ ] Add a "Auto complete Build.kt" menu in the plug-in - [ ] Add a "Auto complete Build.kt" menu in the plug-in
@ -31,6 +44,7 @@ To do:
Done: Done:
- [x] Compile with javax.tool
- [x] Android: multiple -source/-target flags - [x] Android: multiple -source/-target flags
- [x] Dokka: allow multiple format outputs e.g `outputFormat("html", "javadoc")` - [x] Dokka: allow multiple format outputs e.g `outputFormat("html", "javadoc")`
- [x] Finish abstracting everything in `JvmCompilerPlugin` - [x] Finish abstracting everything in `JvmCompilerPlugin`

View file

@ -1 +1 @@
kobalt.version=0.318 kobalt.version=0.320

View file

@ -3,6 +3,7 @@ package com.beust.kobalt
import com.beust.kobalt.api.* import com.beust.kobalt.api.*
import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log import com.beust.kobalt.misc.log
import com.beust.kobalt.plugin.android.AndroidConfig
import com.beust.kobalt.plugin.android.AndroidPlugin import com.beust.kobalt.plugin.android.AndroidPlugin
import java.io.File import java.io.File
@ -122,23 +123,35 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
return result return result
} }
fun applicationId(androidConfig: AndroidConfig?): String? {
val mainId = productFlavor.applicationId ?: androidConfig?.applicationId
val result =
if (mainId != null) {
mainId + (buildType.applicationIdSuffix ?: "")
} else {
null
}
return result
}
/** /**
* Generate BuildConfig.java if requested. Also look up if any BuildConfig is defined on the current build type, * Generate BuildConfig.java if requested. Also look up if any BuildConfig is defined on the current build type,
* product flavor or main project, and use them to generate any additional field (in that order to * product flavor or main project, and use them to generate any additional field (in that order to
* respect the priorities). Return the generated file if it was generated, null otherwise. * respect the priorities). Return the generated file if it was generated, null otherwise.
*/ */
fun maybeGenerateBuildConfig(project: Project, context: KobaltContext) : File? { fun maybeGenerateBuildConfig(project: Project, context: KobaltContext) : File? {
val buildConfigs = findBuildConfigs(project, context.variant) val buildConfigs = findBuildConfigs(project, this)
if (buildConfigs.size > 0) { if (buildConfigs.size > 0) {
val androidConfig = (Kobalt.findPlugin(AndroidPlugin.PLUGIN_NAME) as AndroidPlugin) val androidConfig = (Kobalt.findPlugin(AndroidPlugin.PLUGIN_NAME) as AndroidPlugin)
.configurationFor(project) .configurationFor(project)
val pkg = androidConfig?.applicationId ?: project.packageName ?: project.group val pkg = applicationId(androidConfig) ?: project.packageName ?: project.group
?: throw KobaltException( ?: throw KobaltException(
"packageName needs to be defined on the project in order to generate BuildConfig") "packageName needs to be defined on the project in order to generate BuildConfig")
val code = project.projectInfo.generateBuildConfig(project, context, pkg, context.variant, buildConfigs) val code = project.projectInfo.generateBuildConfig(project, context, pkg, this, buildConfigs)
val result = KFiles.makeDir(KFiles.generatedSourceDir(project, context.variant, "buildConfig")) val result = KFiles.makeDir(KFiles.generatedSourceDir(project, this, "buildConfig"))
// Make sure the generatedSourceDirectory doesn't contain the project.directory since // Make sure the generatedSourceDirectory doesn't contain the project.directory since
// that directory will be added when trying to find recursively all the sources in it // that directory will be added when trying to find recursively all the sources in it
generatedSourceDirectory = File(result.relativeTo(File(project.directory))) generatedSourceDirectory = File(result.relativeTo(File(project.directory)))

View file

@ -4,5 +4,5 @@ package com.beust.kobalt.api
* Plugins that add compiler flags. * Plugins that add compiler flags.
*/ */
interface ICompilerFlagContributor : IContributor { interface ICompilerFlagContributor : IContributor {
fun flagsFor(project: Project, currentFlags: List<String>): List<String> fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>): List<String>
} }

View file

@ -181,6 +181,7 @@ interface IBuildConfig {
} }
class ProductFlavorConfig(val name: String) : IBuildConfig { class ProductFlavorConfig(val name: String) : IBuildConfig {
var applicationId: String? = null
override var buildConfig : BuildConfig? = BuildConfig() override var buildConfig : BuildConfig? = BuildConfig()
} }
@ -192,6 +193,7 @@ fun Project.productFlavor(name: String, init: ProductFlavorConfig.() -> Unit) =
class BuildTypeConfig(val project: Project?, val name: String) : IBuildConfig { class BuildTypeConfig(val project: Project?, val name: String) : IBuildConfig {
var minifyEnabled = false var minifyEnabled = false
var applicationIdSuffix: String? = null
var proguardFile: String? = null var proguardFile: String? = null
fun getDefaultProguardFile(name: String) : String { fun getDefaultProguardFile(name: String) : String {

View file

@ -31,7 +31,7 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager)
// Plugins that add flags to the compiler // Plugins that add flags to the compiler
val contributorFlags = if (project != null) { val contributorFlags = if (project != null) {
context.pluginInfo.compilerFlagContributors.flatMap { context.pluginInfo.compilerFlagContributors.flatMap {
it.flagsFor(project, info.compilerArgs) it.flagsFor(project, context, info.compilerArgs)
} }
} else { } else {
emptyList() emptyList()

View file

@ -179,7 +179,8 @@ abstract class JvmCompilerPlugin @Inject constructor(
dependencyManager.dependencies(project, context, projects) dependencyManager.dependencies(project, context, projects)
val projectDirectory = File(project.directory) val projectDirectory = File(project.directory)
val buildDirectory = File(project.classesDir(context)) val buildDirectory = if (isTest) KFiles.makeOutputTestDir(project)
else File(project.classesDir(context))
buildDirectory.mkdirs() buildDirectory.mkdirs()
val initialSourceDirectories = arrayListOf<File>() val initialSourceDirectories = arrayListOf<File>()
@ -199,7 +200,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
context.pluginInfo.sourceDirectoriesInterceptors.fold(initialSourceDirectories.toList(), context.pluginInfo.sourceDirectoriesInterceptors.fold(initialSourceDirectories.toList(),
{ sd, interceptor -> interceptor.intercept(project, context, sd) }) { sd, interceptor -> interceptor.intercept(project, context, sd) })
}.filter { }.filter {
it.exists() File(project.directory, it.path).exists()
} }
// Now that we have the final list of source dirs, find source files in them // Now that we have the final list of source dirs, find source files in them

View file

@ -49,7 +49,7 @@ public class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
for (i in 0..Kobalt.repos.size - 1) { for (i in 0..Kobalt.repos.size - 1) {
try { try {
val result = cs.take().get(2000, TimeUnit.MILLISECONDS) val result = cs.take().get(2000, TimeUnit.MILLISECONDS)
log(2, "Result for repo #$i: $result") log(2, " Result for repo #$i: $result")
if (result.found) { if (result.found) {
log(2, "Located $id in ${result.hostConfig.url}") log(2, "Located $id in ${result.hostConfig.url}")
return result return result
@ -70,7 +70,7 @@ public class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
inner class RepoFinderCallable(val id: String, val repo: HostConfig) : Callable<RepoResult> { inner class RepoFinderCallable(val id: String, val repo: HostConfig) : Callable<RepoResult> {
override fun call(): RepoResult { override fun call(): RepoResult {
val repoUrl = repo.url val repoUrl = repo.url
log(2, "Checking $repoUrl for $id") log(2, " Checking $repoUrl for $id")
val mavenId = MavenId(id) val mavenId = MavenId(id)
val groupId = mavenId.groupId val groupId = mavenId.groupId

View file

@ -116,18 +116,17 @@ class AndroidBuild {
// //
// Manifest // Manifest
// //
val mainManifest = File("src/main/AndroidManifest.xml") val manifestOverlays = variant.allDirectories(project).map {
File("src/$it/AndroidManifest.xml")
val appInfo = AppInfo(mainManifest, config) }.filter {
val manifestOverlays = listOf(
File("src/${variant.productFlavor.name}/AndroidManifest.xml"),
File("src/${variant.buildType.name}/AndroidManifest.xml")).filter {
it.exists() it.exists()
} }
val libraries = listOf<ManifestDependency>() val libraries = listOf<ManifestDependency>()
val outManifest = AndroidFiles.mergedManifest(project, variant) val outManifest = AndroidFiles.mergedManifest(project, variant)
val outAaptSafeManifestLocation = KFiles.joinDir(project.directory, project.buildDirectory, "generatedSafeAapt") val outAaptSafeManifestLocation = KFiles.joinDir(project.directory, project.buildDirectory, "generatedSafeAapt")
val reportFile = File(KFiles.joinDir(project.directory, project.buildDirectory, "manifest-merger-report.txt")) val reportFile = File(KFiles.joinDir(project.directory, project.buildDirectory, "manifest-merger-report.txt"))
val mainManifest = File("src/main/AndroidManifest.xml")
val appInfo = AppInfo(mainManifest, config)
androidBuilder.mergeManifests(mainManifest, manifestOverlays, libraries, androidBuilder.mergeManifests(mainManifest, manifestOverlays, libraries,
null /* package override */, null /* package override */,
appInfo.versionCode, appInfo.versionCode,

View file

@ -12,9 +12,8 @@ class AndroidFiles {
fun intermediates(project: Project) = KFiles.joinDir(project.directory, project.buildDirectory, fun intermediates(project: Project) = KFiles.joinDir(project.directory, project.buildDirectory,
"intermediates") "intermediates")
fun manifest(project: Project, context: KobaltContext) : String { fun manifest(project: Project, context: KobaltContext) =
return KFiles.joinDir(project.directory, "src/main", "AndroidManifest.xml") KFiles.joinDir(project.directory, "src", "main", "AndroidManifest.xml")
}
fun mergedManifest(project: Project, variant: Variant) : String { fun mergedManifest(project: Project, variant: Variant) : String {
val dir = KFiles.joinAndMakeDir(intermediates(project), "manifests", "full", variant.toIntermediateDir()) val dir = KFiles.joinAndMakeDir(intermediates(project), "manifests", "full", variant.toIntermediateDir())

View file

@ -164,7 +164,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
* Make sure we compile and generate 1.6 sources unless the build file defined those (which can * Make sure we compile and generate 1.6 sources unless the build file defined those (which can
* happen if the developer is using RetroLambda for example). * happen if the developer is using RetroLambda for example).
*/ */
override fun flagsFor(project: Project, currentFlags: List<String>) : List<String> { override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>) : List<String> {
if (isAndroid(project)) { if (isAndroid(project)) {
var found = currentFlags.any { it == "-source" || it == "-target" } var found = currentFlags.any { it == "-source" || it == "-target" }
val result = arrayListOf<String>().apply { addAll(currentFlags) } val result = arrayListOf<String>().apply { addAll(currentFlags) }
@ -218,7 +218,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
project.compileDependencies).map { project.compileDependencies).map {
it.jarFile.get().path it.jarFile.get().path
}.filterNot { }.filterNot {
it.contains("android.jar") || it.endsWith(".aar") || it.contains("com.android.support") it.contains("android.jar") || it.endsWith(".aar")
|| it.contains("retrolambda") || it.contains("retrolambda")
}.toHashSet().toTypedArray() }.toHashSet().toTypedArray()
@ -367,8 +367,8 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
} }
override fun run(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>): TaskResult { override fun run(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>): TaskResult {
val manifest = AndroidFiles.manifest(project, context) AndroidFiles.mergedManifest(project, context.variant).let { manifestPath ->
FileInputStream(File(manifest)).use { ins -> FileInputStream(File(manifestPath)).use { ins ->
// adb shell am start -n com.package.name/com.package.name.ActivityName // adb shell am start -n com.package.name/com.package.name.ActivityName
val manifest = AndroidManifest(ins) val manifest = AndroidManifest(ins)
RunCommand(adb(project)).useErrorStreamAsErrorIndicator(false).run(args = listOf( RunCommand(adb(project)).useErrorStreamAsErrorIndicator(false).run(args = listOf(
@ -376,6 +376,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
return TaskResult() return TaskResult()
} }
} }
}
/** /**
* Automatically add the "aar" packaging for support libraries. * Automatically add the "aar" packaging for support libraries.

View file

@ -19,14 +19,19 @@ import javax.inject.Singleton
@Singleton @Singleton
public class AptPlugin @Inject constructor(val depFactory: DepFactory) public class AptPlugin @Inject constructor(val depFactory: DepFactory)
: ConfigPlugin<AptConfig>(), ICompilerFlagContributor { : ConfigPlugin<AptConfig>(), ICompilerFlagContributor {
companion object { companion object {
const val PLUGIN_NAME = "Apt" const val PLUGIN_NAME = "Apt"
} }
override val name = PLUGIN_NAME override val name = PLUGIN_NAME
private fun generated(project: Project, context: KobaltContext, outputDir: String) =
KFiles.joinAndMakeDir(project.directory, project.buildDirectory, outputDir,
context.variant.toIntermediateDir())
// ICompilerFlagContributor // ICompilerFlagContributor
override fun flagsFor(project: Project, currentFlags: List<String>) : List<String> { override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>) : List<String> {
val result = arrayListOf<String>() val result = arrayListOf<String>()
configurationFor(project)?.let { config -> configurationFor(project)?.let { config ->
aptDependencies[project.name]?.let { aptDependencies -> aptDependencies[project.name]?.let { aptDependencies ->
@ -44,9 +49,8 @@ public class AptPlugin @Inject constructor(val depFactory: DepFactory)
result.add("-processorpath") result.add("-processorpath")
result.add((dependencyJarFiles + dependencies).joinToString(":")) result.add((dependencyJarFiles + dependencies).joinToString(":"))
val generated = KFiles.joinAndMakeDir(project.directory, project.buildDirectory, config.outputDir)
result.add("-s") result.add("-s")
result.add(generated) result.add(generated(project, context, config.outputDir))
} }
log(2, "New flags from apt: " + result.joinToString(" ")) log(2, "New flags from apt: " + result.joinToString(" "))
} }

View file

@ -9,12 +9,14 @@ import com.beust.kobalt.api.Project
import com.beust.kobalt.internal.ICompilerAction import com.beust.kobalt.internal.ICompilerAction
import com.beust.kobalt.internal.JvmCompiler import com.beust.kobalt.internal.JvmCompiler
import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.warn import com.beust.kobalt.misc.warn
import com.beust.kobalt.plugin.android.forward
import com.google.inject.Inject import com.google.inject.Inject
import com.google.inject.Singleton import com.google.inject.Singleton
import java.io.File import java.io.File
import java.io.PrintWriter
import javax.tools.DiagnosticCollector
import javax.tools.JavaFileObject
import javax.tools.ToolProvider
@Singleton @Singleton
class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) { class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) {
@ -25,31 +27,25 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) {
return TaskResult() return TaskResult()
} }
info.outputDir.mkdirs()
val allArgs = arrayListOf( val allArgs = arrayListOf(
executable.absolutePath,
"-d", KFiles.makeDir(info.directory!!, info.outputDir.path).path) "-d", KFiles.makeDir(info.directory!!, info.outputDir.path).path)
if (info.dependencies.size > 0) { if (info.dependencies.size > 0) {
allArgs.add("-classpath") allArgs.add("-classpath")
allArgs.add(info.dependencies.map {it.jarFile.get()}.joinToString(File.pathSeparator)) allArgs.add(info.dependencies.map { it.jarFile.get() }.joinToString(File.pathSeparator))
} }
allArgs.addAll(info.compilerArgs) allArgs.addAll(info.compilerArgs)
allArgs.addAll(info.sourceFiles)
val pb = ProcessBuilder(allArgs) val compiler = ToolProvider.getSystemJavaCompiler()
// info.directory?.let { val fileManager = compiler.getStandardFileManager(null, null, null)
// pb.directory(File(it)) val fileObjects = fileManager.getJavaFileObjectsFromFiles(info.sourceFiles.map { File(it) })
// } val dc = DiagnosticCollector<JavaFileObject>()
pb.inheritIO() val classes = arrayListOf<String>()
val line = allArgs.joinToString(" ") val task = compiler.getTask(PrintWriter(System.out), fileManager, dc, allArgs, classes, fileObjects)
log(1, " Compiling ${info.sourceFiles.size} files") val result = task.call()
log(2, " Compiling ${line.forward()}")
val process = pb.start()
val errorCode = process.waitFor()
return if (errorCode == 0) TaskResult(true, "Compilation succeeded") return if (result) TaskResult(true, "Compilation succeeded")
else TaskResult(false, "There were errors") else TaskResult(false, "There were errors")
} }
} }

View file

@ -1 +1 @@
kobalt.version=0.318 kobalt.version=0.320