-
-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make builds able to depend on external projects #291
Changes from all commits
6cf77f1
60d1cdc
4216a72
6d2b1f3
1607f78
40dac00
305e2a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,9 +124,12 @@ case class Evaluator[T](home: Path, | |
(newResults, newEvaluated, false) | ||
case Right(labelledNamedTask) => | ||
|
||
val out = if (!labelledNamedTask.task.ctx.external) outPath | ||
else externalOutPath | ||
|
||
val paths = Evaluator.resolveDestPaths( | ||
if (!labelledNamedTask.task.ctx.external) outPath else externalOutPath, | ||
labelledNamedTask.segments | ||
out, | ||
destSegments(labelledNamedTask) | ||
) | ||
|
||
if (!exists(paths.out)) mkdir(paths.out) | ||
|
@@ -191,6 +194,27 @@ case class Evaluator[T](home: Path, | |
} | ||
} | ||
} | ||
|
||
def destSegments(labelledTask : Labelled[_]) : Segments = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the core of the PR I guess. This makes sure that "foreign" modules do not conflict with local modules |
||
import labelledTask.task.ctx | ||
if (ctx.foreign) { | ||
val prefix = "foreign-modules" | ||
// Computing a path in "out" that uniquely reflects the location | ||
// of the foreign module relatively to the current build. | ||
val relative = labelledTask.task | ||
.ctx.millSourcePath | ||
.relativeTo(rootModule.millSourcePath) | ||
// Encoding the number of `/..` | ||
val ups = if (relative.ups > 0) Segments.labels(s"up-${relative.ups}") | ||
else Segments() | ||
Segments.labels(prefix) | ||
.++(ups) | ||
.++(Segments.labels(relative.segments: _*)) | ||
.++(labelledTask.segments.last) | ||
} else labelledTask.segments | ||
} | ||
|
||
|
||
def handleTaskResult(v: Any, | ||
hashCode: Int, | ||
metaPath: Path, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import $file.inner.{build => innerBuild} | ||
import mill._ | ||
import ammonite.ops._ | ||
|
||
// In this build, we have a local module targeting | ||
// the 'inner sub-directory, and an imported foreign | ||
// module in that same directory. Their sourcePaths | ||
// should be the same, but their dest paths should | ||
// be different to avoid both modules over-writing | ||
// each other's caches . | ||
|
||
def checkPaths : T[Unit] = T { | ||
if (innerBuild.millSourcePath != inner.millSourcePath) | ||
throw new Exception("Source paths should be the same") | ||
} | ||
|
||
def checkDests : T[Unit] = T { | ||
if (innerBuild.selfDest == inner.selfDest) | ||
throw new Exception("Dest paths should be different") | ||
} | ||
|
||
object inner extends mill.Module { | ||
def selfDest = T { T.ctx().dest / up / up } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import mill._ | ||
import ammonite.ops._ | ||
|
||
def selfDest = T { T.ctx().dest / up / up } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import $file.inner.build | ||
import mill._ | ||
import ammonite.ops._ | ||
|
||
trait PathAware extends mill.Module { | ||
def selfPath = T { millSourcePath } | ||
} | ||
|
||
trait DestAware extends mill.Module { | ||
def selfDest = T { T.ctx().dest / up / up } | ||
} | ||
|
||
object sub extends PathAware with DestAware { | ||
object sub extends PathAware with DestAware | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import mill._ | ||
import ammonite.ops._ | ||
|
||
trait PathAware extends mill.Module { | ||
def selfPath = T { millSourcePath } | ||
} | ||
|
||
trait DestAware extends mill.Module { | ||
def selfDest = T { T.ctx().dest / up / up } | ||
} | ||
|
||
object sub extends PathAware with DestAware { | ||
object sub extends PathAware with DestAware | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import $file.^.outer.build | ||
import $file.inner.build | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the main test, it checks the consistency of sourcePaths and dest |
||
import ammonite.ops._ | ||
import mill._ | ||
|
||
def assertPaths(p1 : Path, p2 : Path) : Unit = if (p1 != p2) throw new Exception( | ||
s"Paths were not equal : \n- $p1 \n- $p2" | ||
) | ||
|
||
object sub extends PathAware with DestAware { | ||
|
||
object sub extends PathAware with DestAware | ||
|
||
object sub2 extends ^.outer.build.PathAware with ^.outer.build.DestAware | ||
|
||
} | ||
|
||
def checkProjectPaths = T { | ||
val thisPath : Path = millSourcePath | ||
assert(thisPath.last == "project") | ||
assertPaths(sub.selfPath(), thisPath / 'sub) | ||
assertPaths(sub.sub.selfPath(), thisPath / 'sub / 'sub) | ||
assertPaths(sub.sub2.selfPath(), thisPath / 'sub / 'sub2) | ||
} | ||
|
||
def checkInnerPaths = T { | ||
val thisPath : Path = millSourcePath | ||
assertPaths(inner.build.millSourcePath, thisPath / 'inner ) | ||
assertPaths(inner.build.sub.selfPath(), thisPath / 'inner / 'sub) | ||
assertPaths(inner.build.sub.sub.selfPath(), thisPath / 'inner / 'sub / 'sub) | ||
} | ||
|
||
def checkOuterPaths = T { | ||
val thisPath : Path = millSourcePath | ||
assertPaths(^.outer.build.millSourcePath, thisPath / up / 'outer ) | ||
assertPaths(^.outer.build.sub.selfPath(), thisPath / up / 'outer / 'sub) | ||
assertPaths(^.outer.build.sub.sub.selfPath(), thisPath / up / 'outer / 'sub / 'sub) | ||
} | ||
|
||
def checkOuterInnerPaths = T { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checking that importing a foreign build which imports a foreign build works as expected |
||
val thisPath : Path = millSourcePath | ||
assertPaths(^.outer.inner.build.millSourcePath, thisPath / up / 'outer / 'inner ) | ||
assertPaths(^.outer.inner.build.sub.selfPath(), thisPath / up / 'outer / 'inner /'sub) | ||
assertPaths(^.outer.inner.build.sub.sub.selfPath(), thisPath / up / 'outer / 'inner / 'sub / 'sub) | ||
} | ||
|
||
def checkProjectDests = T { | ||
val outPath : Path = millSourcePath / 'out | ||
assertPaths(sub.selfDest(), outPath / 'sub) | ||
assertPaths(sub.sub.selfDest(), outPath / 'sub / 'sub) | ||
assertPaths(sub.sub2.selfDest(), outPath / 'sub / 'sub2) | ||
} | ||
|
||
def checkInnerDests = T { | ||
val foreignOut : Path = millSourcePath / 'out / "foreign-modules" | ||
assertPaths(inner.build.sub.selfDest(), foreignOut / 'inner / 'sub) | ||
assertPaths(inner.build.sub.sub.selfDest(), foreignOut / 'inner / 'sub / 'sub) | ||
} | ||
|
||
def checkOuterDests = T { | ||
val foreignOut : Path = millSourcePath / 'out / "foreign-modules" | ||
assertPaths(^.outer.build.sub.selfDest(), foreignOut / "up-1" / 'outer/ 'sub ) | ||
assertPaths(^.outer.build.sub.sub.selfDest(), foreignOut / "up-1" / 'outer/ 'sub / 'sub) | ||
} | ||
|
||
def checkOuterInnerDests = T { | ||
val foreignOut : Path = millSourcePath / 'out / "foreign-modules" | ||
assertPaths(^.outer.inner.build.sub.selfDest(), foreignOut / "up-1" / 'outer/ 'inner / 'sub) | ||
assertPaths(^.outer.inner.build.sub.sub.selfDest(), foreignOut / "up-1" / 'outer/ 'inner / 'sub / 'sub) | ||
} | ||
|
||
|
||
trait PathAware extends mill.Module { | ||
|
||
def selfPath = T { millSourcePath } | ||
} | ||
|
||
trait DestAware extends mill.Module { | ||
def selfDest = T { T.ctx().dest / up / up } | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to choose a name for the concept "builds that originate from other directories", and External was already taken. Obviously I'm not a native English speaker, so perhaps there's a term that would suit the concept better.