Skip to content

Commit 7a9a613

Browse files
author
user
committed
Added lazyval
1 parent f8fa0f8 commit 7a9a613

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

core/api/src/mill/api/PathUtils.scala

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import java.io.File;
1111
* Defines a trait which handles deerialization of paths, in a way that can be used by both path refs and paths
1212
*/
1313
trait PathUtils {
14-
//TEMPORARY! A better solution needs to be found.
14+
// TEMPORARY! A better solution needs to be found.
1515
def findOutRoot(): os.Path = {
1616
val outFolderName = OutFiles.out
1717
val root = os.Path(new File("").getCanonicalPath().toString)
1818
var currentPath = root
1919

20-
for (i <- 1 to 100){
20+
for (i <- 1 to 100) {
2121
if (os.exists(currentPath / "mill-java-home")) {
2222
return currentPath
2323
} else {
@@ -29,13 +29,15 @@ trait PathUtils {
2929
}
3030
}
3131
root
32-
}
32+
}
33+
34+
lazy val outFolderRoot: os.Path = findOutRoot()
35+
3336
/*
3437
* Returns a list of paths and their variables to be substituted with.
3538
*/
3639
implicit def substitutions(): List[(os.Path, String)] = {
37-
val out = findOutRoot()
38-
var result = List((out, "*$WorkplaceRoot*"))
40+
var result = List((outFolderRoot, "*$WorkplaceRoot*"))
3941
val javaHome = os.Path(System.getProperty("java.home"))
4042
result = result :+ (javaHome, "*$JavaHome*")
4143

@@ -79,7 +81,7 @@ trait PathUtils {
7981
var result = a
8082
var depth = 0
8183
subs.foreach { case (path, sub) =>
82-
val pathDepth = path.segments.length
84+
val pathDepth = path.segments.length
8385
val pathString = path.toString
8486
// In the case that a path is in the folder of another path, it picks the path with the most depth
8587
if (result.startsWith(sub) && pathDepth >= depth) {
@@ -90,5 +92,5 @@ trait PathUtils {
9092

9193
// println(s"2!! $a -> $result")
9294
os.Path(result)
93-
}
95+
}
9496
}

0 commit comments

Comments
 (0)