Skip to content

Commit

Permalink
allow DirectoryDependencies on BuildBuilds
Browse files Browse the repository at this point in the history
this fixes a bug where finalBuild would over eagerly go down all the way
down to the outermost build instead of stopping at the one requested.
Now it checks the new argument and stops there.

This is necessary to allow having one build depend on another build in
order to embed it in a type-safe way and have access to it’s tasks.
  • Loading branch information
cvogt committed Feb 18, 2017
1 parent 632f3d0 commit 3c135b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
8 changes: 6 additions & 2 deletions compatibility/BuildInterface.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package cbt;
import java.io.*;

public abstract class BuildInterface implements Dependency{
public abstract BuildInterface finalBuild(); // needed to propagage through build builds. Maybe we can get rid of this.
public interface BuildInterface extends Dependency{
// needed to propagage through build builds. Maybe we can get rid of this.
public default BuildInterface finalBuild(File current){
return finalBuild(); // legacy forwarder
}
public abstract File[] triggerLoopFilesArray(); // needed for watching files across composed builds

// deprecated methods, which clients are still allowed to implement, but not required
public abstract BuildInterface finalBuild(); // needed to propagage through build builds. Maybe we can get rid of this.
public abstract BuildInterface copy(Context context);
public abstract String scalaVersion();
public abstract String[] crossScalaVersionsArray();
Expand Down
5 changes: 5 additions & 0 deletions stage2/BasicBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,12 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
*/

// ========== cbt internals ==========
@deprecated("use finalbuild(File)","")
def finalBuild: BuildInterface = this
override def finalBuild( current: File ): BuildInterface = {
//assert( current.getCanonicalFile == projectDirectory.getCanonicalFile, s"$current == $projectDirectory" )
this
}
override def show = this.getClass.getSimpleName ++ "(" ++ projectDirectory.string ++ ")"

// a method that can be called only to trigger any side-effects
Expand Down
9 changes: 8 additions & 1 deletion stage2/BuildBuild.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cbt
import java.nio.file._
import java.io.File

trait BuildBuild extends BuildBuildWithoutEssentials{
override def dependencies =
Expand Down Expand Up @@ -97,5 +98,11 @@ trait BuildBuildWithoutEssentials extends BaseBuild{
}
}
override def triggerLoopFiles = super.triggerLoopFiles ++ managedBuild.triggerLoopFiles
override def finalBuild: BuildInterface = if( projectDirectory == context.cwd ) this else managedBuild.finalBuild
@deprecated("use finalbuild(File)","")
override def finalBuild: BuildInterface = finalBuild( context.cwd )
override def finalBuild( current: File ): BuildInterface = {
val p = projectDirectory.getCanonicalFile
val c = current.getCanonicalFile
if( c == p ) this else managedBuild.finalBuild( current )
}
}
6 changes: 3 additions & 3 deletions stage2/Stage2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.util._

object Stage2 extends Stage2Base{
def getBuild(context: Context) = {
new Lib( context.logger ).loadRoot( context ).finalBuild
new Lib( context.logger ).loadRoot( context ).finalBuild( context.cwd )
}

def run( args: Stage2Args ): ExitCode = {
Expand Down Expand Up @@ -39,7 +39,7 @@ object Stage2 extends Stage2Base{
null
)
val first = lib.loadRoot( context )
val build = first.finalBuild
val build = first.finalBuild( context.cwd )

val res =
if (loop) {
Expand All @@ -57,7 +57,7 @@ object Stage2 extends Stage2Base{
scala.util.control.Breaks.break

case file if triggerFiles.exists(file.toString startsWith _.toString) =>
val build = lib.loadRoot(context).finalBuild
val build = lib.loadRoot(context).finalBuild( context.cwd )
logger.loop(s"Re-running $task for " ++ build.show)
lib.callReflective(build, task)
}
Expand Down

0 comments on commit 3c135b4

Please sign in to comment.