aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/build-info-example/build/build.scala15
-rw-r--r--examples/build-info-example/src_generated/BuildInfo.scala (renamed from examples/build-info-example/src/BuildInfo.scala)0
-rw-r--r--ports/migration-manager/build/build.scala12
-rwxr-xr-xshell-integration/cbt-completions.bash6
-rw-r--r--shell-integration/cbt-completions.fish2
-rwxr-xr-xshell-integration/cbt-completions.zsh6
-rw-r--r--stage1/Stage1Lib.scala8
-rw-r--r--stage2/BasicBuild.scala4
-rw-r--r--stage2/GitDependency.scala93
-rw-r--r--stage2/plugins/Dotty.scala6
-rw-r--r--stage2/plugins/Frege.scala6
11 files changed, 92 insertions, 66 deletions
diff --git a/examples/build-info-example/build/build.scala b/examples/build-info-example/build/build.scala
index b5ea86b..cc4c2db 100644
--- a/examples/build-info-example/build/build.scala
+++ b/examples/build-info-example/build/build.scala
@@ -6,9 +6,10 @@ class Build(val context: Context) extends PackageJars{
def groupId = "cbt.examples"
override def defaultScalaVersion = "2.11.8"
def version = "0.1"
- override def compile = {
- val file = (projectDirectory ++ "/BuildInfo.scala").toPath
- val contents = s"""// generated file
+ override def compile = { buildInfo; super.compile }
+ def buildInfo = lib.writeIfChanged(
+ projectDirectory / "src_generated/BuildInfo.scala",
+ s"""// generated file
import java.io._
object BuildInfo{
def artifactId = "$artifactId"
@@ -17,11 +18,5 @@ def version = "$version"
def scalaVersion = "$scalaVersion"
}
"""
- if( exists(file) && contents != new String(readAllBytes(file)) )
- write(
- (projectDirectory ++ "/BuildInfo.scala").toPath,
- contents.getBytes
- )
- super.compile
- }
+ )
}
diff --git a/examples/build-info-example/src/BuildInfo.scala b/examples/build-info-example/src_generated/BuildInfo.scala
index ac0e680..ac0e680 100644
--- a/examples/build-info-example/src/BuildInfo.scala
+++ b/examples/build-info-example/src_generated/BuildInfo.scala
diff --git a/ports/migration-manager/build/build.scala b/ports/migration-manager/build/build.scala
new file mode 100644
index 0000000..43b24f5
--- /dev/null
+++ b/ports/migration-manager/build/build.scala
@@ -0,0 +1,12 @@
+package migration_manager_build
+import cbt._
+class Build(val context: Context) extends BaseBuild{
+ override def dependencies =
+ Resolver( mavenCentral ).bind(
+ MavenDependency( "org.scala-lang", "scala-compiler", "2.11.8" )
+ )
+ def mima = GitDependency.checkout(
+ "git@github.com:typesafehub/migration-manager.git", "92cbce52b4bf04ca1c338f34818ebfb9f0ebc285"
+ )
+ override def generatedSources = Seq( mima / "core" )
+}
diff --git a/shell-integration/cbt-completions.bash b/shell-integration/cbt-completions.bash
index 925ba4b..deb88c1 100755
--- a/shell-integration/cbt-completions.bash
+++ b/shell-integration/cbt-completions.bash
@@ -1,11 +1,13 @@
-#!/bin/bash
+# this does currently not support for completion of nested methods, e.g. snapshot.comp<tab>
+# bash 4 should be able to do that via $READLINE_LINE and $READLINE_POINT, see
+# http://unix.stackexchange.com/questions/106761/simulating-readline-line-in-bash-4-0/106832
__cbt()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
- opts="$(cbt taskNames)"
+ opts="$(cbt complete)"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
diff --git a/shell-integration/cbt-completions.fish b/shell-integration/cbt-completions.fish
index fbca62d..d51114d 100644
--- a/shell-integration/cbt-completions.fish
+++ b/shell-integration/cbt-completions.fish
@@ -1 +1 @@
-complete --command cbt --no-files -a '(cbt taskNames)' #|fzf --height 90% --reverse)'
+complete --command cbt --no-files -a '(cbt complete (commandline --current-buffer) (commandline --cursor))' #|fzf --height 90% --reverse)'
diff --git a/shell-integration/cbt-completions.zsh b/shell-integration/cbt-completions.zsh
index d11307d..d8f2d6d 100755
--- a/shell-integration/cbt-completions.zsh
+++ b/shell-integration/cbt-completions.zsh
@@ -1,7 +1,9 @@
-#! /usr/bin/env zsh
+# this does currently not support for completion of nested methods, e.g. snapshot.comp<tab>
+# zsh should be able to do that via $BUFFER, see
+# http://unix.stackexchange.com/questions/14230/zsh-tab-completion-on-empty-line
_cbt() {
- reply=( "${(ps:\n:)$(cbt taskNames)}" )
+ reply=( "${(ps:\n:)$(cbt complete)}" )
}
compctl -K _cbt cbt
diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala
index f701c72..d99354c 100644
--- a/stage1/Stage1Lib.scala
+++ b/stage1/Stage1Lib.scala
@@ -55,6 +55,8 @@ class Stage1Lib( logger: Logger ) extends BaseLib{
def green(string: String) = scala.Console.GREEN++string++scala.Console.RESET
def write(file: File, content: String, options: OpenOption*): File = Stage0Lib.write(file, content, options:_*)
+ def writeIfChanged(file: File, content: String, options: OpenOption*): File =
+ if( !file.exists || content != file.readAsString ) write(file, content, options:_*) else file
def addHttpCredentials( connection: HttpURLConnection, credentials: String ): Unit = {
val encoding = new sun.misc.BASE64Encoder().encode(credentials.getBytes)
@@ -220,12 +222,16 @@ class Stage1Lib( logger: Logger ) extends BaseLib{
val classpath = d.classpath
val cp = classpath.string
+ def lastModified = (
+ cbtLastModified +: d.lastModified +: sourceFiles.map(_.lastModified)
+ ).max
+
if( sourceFiles.isEmpty ){
None
}else{
val start = System.currentTimeMillis
val lastCompiled = statusFile.lastModified
- if( d.lastModified > lastCompiled || sourceFiles.exists(_.lastModified > lastCompiled) ){
+ if( lastModified > lastCompiled ){
def Resolver(urls: URL*) = MavenResolver(cbtLastModified, mavenCache, urls: _*)
val zinc = Resolver(mavenCentral).bindOne(MavenDependency("com.typesafe.zinc","zinc", zincVersion))
val zincDeps = zinc.transitiveDependencies
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala
index d7bdfee..1308155 100644
--- a/stage2/BasicBuild.scala
+++ b/stage2/BasicBuild.scala
@@ -42,7 +42,9 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
final def help: String = lib.usage(this.getClass, show)
- final def taskNames: String = lib.taskNames(this.getClass).sorted.mkString("\n")
+ final def complete: String = {
+ lib.taskNames(this.getClass).sorted.mkString("\n")
+ }
// ========== meta data ==========
diff --git a/stage2/GitDependency.scala b/stage2/GitDependency.scala
index 028401b..f6812e4 100644
--- a/stage2/GitDependency.scala
+++ b/stage2/GitDependency.scala
@@ -8,14 +8,32 @@ import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
import org.eclipse.jgit.lib.Ref
object GitDependency{
- val GitUrl = "(git:|https:|file:/)//([^/]+)/(.+)".r
+ val GitUrl = "(git@|git://|https://|file:///)([^/:]+)[/:](.+)".r
def apply(
url: String, ref: String, subDirectory: Option[String] = None, // example: git://github.com/cvogt/cbt.git#<some-hash>
pathToNestedBuild: Seq[String] = Seq()
)(implicit context: Context ): BuildInterface = {
+ def moduleKey = (
+ this.getClass.getName
+ ++ "(" ++ url ++ subDirectory.map("/" ++ _).getOrElse("") ++ "#" ++ ref
+ ++ ", "
+ ++ pathToNestedBuild.mkString(", ")
+ ++ ")"
+ )
+
+ val taskCache = new PerClassCache(context.transientCache, moduleKey)(context.logger)
+
+ val c = taskCache[Dependency]("checkout").memoize{ checkout( url, ref ) }
+ DirectoryDependency(
+ context.copy(
+ workingDirectory = subDirectory.map(c / _).getOrElse(c)
+ ),
+ pathToNestedBuild: _*
+ )
+ }
+ def checkout(url: String, ref: String)(implicit context: Context): File = {
// TODO: add support for authentication via ssh and/or https
// See http://www.codeaffine.com/2014/12/09/jgit-authentication/
- val GitUrl( _, domain, path ) = url
val credentialsFile = context.workingDirectory ++ "/git.login"
def authenticate(_git: CloneCommand) =
if(!credentialsFile.exists){
@@ -30,52 +48,33 @@ object GitDependency{
}
val logger = context.logger
-
- def moduleKey = (
- this.getClass.getName
- ++ "(" ++ url ++ subDirectory.map("/" ++ _).getOrElse("") ++ "#" ++ ref
- ++ ", "
- ++ pathToNestedBuild.mkString(", ")
- ++ ")"
- )
-
- val taskCache = new PerClassCache(context.transientCache, moduleKey)(logger)
-
- def checkout: File = taskCache[Dependency]("checkout").memoize{
- val checkoutDirectory = context.cache ++ s"/git/$domain/$path/$ref"
- val _git = if(checkoutDirectory.exists){
- logger.git(s"Found existing checkout of $url#$ref in $checkoutDirectory")
- val _git = new Git(new FileRepository(checkoutDirectory ++ "/.git"))
- val actualRef = _git.getRepository.getBranch
- if(actualRef != ref){
- logger.git(s"actual ref '$actualRef' does not match expected ref '$ref' - fetching and checking out")
- _git.fetch().call()
- _git.checkout().setName(ref).call
- }
- _git
- } else {
- logger.git(s"Cloning $url into $checkoutDirectory")
- val _git = authenticate(
- Git
- .cloneRepository()
- .setURI(url)
- .setDirectory(checkoutDirectory)
- ).call()
-
- logger.git(s"Checking out ref $ref")
- _git.checkout().setName(ref).call()
- _git
- }
+ val GitUrl( _, domain, path ) = url
+ val checkoutDirectory = context.cache / s"git/$domain/${path.stripSuffix(".git")}/$ref"
+ val _git = if(checkoutDirectory.exists){
+ logger.git(s"Found existing checkout of $url#$ref in $checkoutDirectory")
+ val _git = new Git(new FileRepository(checkoutDirectory ++ "/.git"))
val actualRef = _git.getRepository.getBranch
- assert( actualRef == ref, s"actual ref '$actualRef' does not match expected ref '$ref'")
- checkoutDirectory
- }
+ if(actualRef != ref){
+ logger.git(s"actual ref '$actualRef' does not match expected ref '$ref' - fetching and checking out")
+ _git.fetch().call()
+ _git.checkout().setName(ref).call
+ }
+ _git
+ } else {
+ logger.git(s"Cloning $url into $checkoutDirectory")
+ val _git = authenticate(
+ Git
+ .cloneRepository()
+ .setURI(url)
+ .setDirectory(checkoutDirectory)
+ ).call()
- DirectoryDependency(
- context.copy(
- workingDirectory = checkout ++ subDirectory.map("/" ++ _).getOrElse("")
- ),
- pathToNestedBuild: _*
- )
+ logger.git(s"Checking out ref $ref")
+ _git.checkout().setName(ref).call()
+ _git
+ }
+ val actualRef = _git.getRepository.getBranch
+ assert( actualRef == ref, s"actual ref '$actualRef' does not match expected ref '$ref'")
+ checkoutDirectory
}
}
diff --git a/stage2/plugins/Dotty.scala b/stage2/plugins/Dotty.scala
index 01ffa27..0bbaf44 100644
--- a/stage2/plugins/Dotty.scala
+++ b/stage2/plugins/Dotty.scala
@@ -130,12 +130,16 @@ class DottyLib(
val classpath = d.classpath
val cp = classpath.string
+ def lastModified = (
+ cbtLastModified +: d.lastModified +: sourceFiles.map(_.lastModified)
+ ).max
+
if( sourceFiles.isEmpty ){
None
}else{
val start = System.currentTimeMillis
val lastCompiled = statusFile.lastModified
- if( d.lastModified > lastCompiled || sourceFiles.exists(_.lastModified > lastCompiled) ){
+ if( lastModified > lastCompiled ){
val _class = "dotty.tools.dotc.Main"
val dualArgs =
diff --git a/stage2/plugins/Frege.scala b/stage2/plugins/Frege.scala
index 3fcd56b..da5e54f 100644
--- a/stage2/plugins/Frege.scala
+++ b/stage2/plugins/Frege.scala
@@ -66,12 +66,16 @@ class FregeLib(
val classpath = d.classpath
val cp = classpath.string
+ def lastModified = (
+ cbtLastModified +: d.lastModified +: sourceFiles.map(_.lastModified)
+ ).max
+
if( sourceFiles.isEmpty ){
None
} else {
val start = System.currentTimeMillis
val lastCompiled = statusFile.lastModified
- if( d.lastModified > lastCompiled || sourceFiles.exists(_.lastModified > lastCompiled) ){
+ if( lastModified > lastCompiled ){
val _class = "frege.compiler.Main"
val fp = (fregeDependency.classpath.strings ++ fregeDependencies.map(_.classpath.string))