@@ -3,41 +3,41 @@ import os.Path
3
3
import upickle .default .ReadWriter as RW
4
4
import scala .reflect .ClassTag
5
5
import scala .util .matching .Regex
6
- import mill .api .WorkspaceRoot
7
6
import mill .constants .EnvVars
8
7
import mill .constants .{OutFiles }
8
+ import java .io .File ;
9
9
10
10
/**
11
11
* Defines a trait which handles deerialization of paths, in a way that can be used by both path refs and paths
12
12
*/
13
13
trait PathUtils {
14
- // TEMPORARY! A better solution needs to be found.
14
+ // TEMPORARY! A better solution needs to be found.
15
15
def findOutRoot (): os.Path = {
16
16
val outFolderName = OutFiles .out
17
- val root = WorkspaceRoot .workspaceRoot / outFolderName
17
+ val root = os. Path ( new File ( " " ).getCanonicalPath().toString)
18
18
var currentPath = root
19
19
20
- for (i <- 1 to 100 ){
20
+ for (i <- 1 to 100 ) {
21
21
if (os.exists(currentPath / " mill-java-home" )) {
22
22
return currentPath
23
23
} else {
24
- if (currentPath.segments.length == 1 ) {
24
+ if (currentPath == os.root ) {
25
25
return root
26
26
} else {
27
27
currentPath = currentPath / " .."
28
28
}
29
29
}
30
30
}
31
- return root
32
- }
31
+ root
32
+ }
33
+
34
+ lazy val outFolderRoot : os.Path = findOutRoot()
35
+
33
36
/*
34
37
* Returns a list of paths and their variables to be substituted with.
35
38
*/
36
39
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*" ))
41
41
val javaHome = os.Path (System .getProperty(" java.home" ))
42
42
result = result :+ (javaHome, " *$JavaHome*" )
43
43
@@ -81,7 +81,7 @@ trait PathUtils {
81
81
var result = a
82
82
var depth = 0
83
83
subs.foreach { case (path, sub) =>
84
- val pathDepth = path.segments.length
84
+ val pathDepth = path.segments.length
85
85
val pathString = path.toString
86
86
// In the case that a path is in the folder of another path, it picks the path with the most depth
87
87
if (result.startsWith(sub) && pathDepth >= depth) {
@@ -92,5 +92,5 @@ trait PathUtils {
92
92
93
93
// println(s"2!! $a -> $result")
94
94
os.Path (result)
95
- }
95
+ }
96
96
}
0 commit comments