Skip to content

Commit edd3b92

Browse files
author
user
committed
Added lazy val
1 parent 04a6e88 commit edd3b92

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,41 @@ import os.Path
33
import upickle.default.ReadWriter as RW
44
import scala.reflect.ClassTag
55
import scala.util.matching.Regex
6-
import mill.api.WorkspaceRoot
76
import mill.constants.EnvVars
87
import mill.constants.{OutFiles}
8+
import java.io.File;
99

1010
/**
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
17-
val root = WorkspaceRoot.workspaceRoot / outFolderName
17+
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 {
24-
if (currentPath.segments.length == 1) {
24+
if (currentPath == os.root) {
2525
return root
2626
} else {
2727
currentPath = currentPath / ".."
2828
}
2929
}
3030
}
31-
return root
32-
}
31+
root
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-
39-
var result = List((out, "*$WorkplaceRoot*"))
40-
40+
var result = List((outFolderRoot, "*$WorkplaceRoot*"))
4141
val javaHome = os.Path(System.getProperty("java.home"))
4242
result = result :+ (javaHome, "*$JavaHome*")
4343

@@ -81,7 +81,7 @@ trait PathUtils {
8181
var result = a
8282
var depth = 0
8383
subs.foreach { case (path, sub) =>
84-
val pathDepth = path.segments.length
84+
val pathDepth = path.segments.length
8585
val pathString = path.toString
8686
// In the case that a path is in the folder of another path, it picks the path with the most depth
8787
if (result.startsWith(sub) && pathDepth >= depth) {
@@ -92,5 +92,5 @@ trait PathUtils {
9292

9393
// println(s"2!! $a -> $result")
9494
os.Path(result)
95-
}
95+
}
9696
}

0 commit comments

Comments
 (0)