Skip to content

Commit 646675a

Browse files
committed
fix: replace hardcoded absolute path with TaskCtx.workspace, fix sandbox violations
- Replace hardcoded /home/roman/... path with TaskCtx.workspace (Mill's official API for the project root inside tasks) - Remove cliBinPath (wrote outside Task.dest, hit sandbox restriction); buildCliBinary now writes to Task.dest/cli - Fix testLocal sources to use moduleDir instead of os.pwd - Add import mill.api.TaskCtx
1 parent 1acb73d commit 646675a

1 file changed

Lines changed: 7 additions & 26 deletions

File tree

build.mill

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import mill.scalanativelib.api.*
77
import mill.scalalib.publish.*
88
import mill.util.VcsVersionModule
99
import mill.api.Task.Simple
10+
import mill.api.TaskCtx
1011
import os.Path
1112

1213
val scalaVer = "3.8.3"
@@ -25,30 +26,10 @@ val munitVer = "1.3.0"
2526

2627
val upickleVer = "4.4.3"
2728

28-
def cliBinPath: os.Path = {
29-
def normalise(s: String) = s.toLowerCase.replaceAll("[^a-z0-9]+", "")
30-
val props = sys.props.toMap
31-
val osName = normalise(props.getOrElse("os.name", "")) match {
32-
case p if p.startsWith("linux") => "linux"
33-
case p if p.startsWith("windows") => "windows"
34-
case p if p.startsWith("osx") || p.startsWith("macosx") => "macosx"
35-
case _ => "unknown"
36-
}
37-
val arch = (
38-
normalise(props.getOrElse("os.arch", "")),
39-
props.getOrElse("sun.arch.data.model", "64")
40-
) match {
41-
case ("amd64" | "x64" | "x8664" | "x86", bits) => s"x86_$bits"
42-
case ("aarch64" | "arm64", bits) => s"aarch$bits"
43-
case _ => "unknown"
44-
}
45-
os.pwd / "target" / "bin" / s"gcp-codegen-$arch-$osName"
46-
}
47-
48-
/** Build the Scala Native CLI binary and copy it to target/bin/<arch>-<os> */
29+
/** Build the Scala Native CLI binary */
4930
def buildCliBinary: T[PathRef] = Task {
5031
val linked = cli.nativeLink()
51-
val dest = cliBinPath
32+
val dest = Task.dest / "cli"
5233
os.makeDir.all(dest / os.up)
5334
os.copy.over(linked.path, dest)
5435
PathRef(dest)
@@ -131,7 +112,7 @@ object exampleJsoniterJson extends Module {
131112
// ---------------------------------------------------------------------------
132113

133114
object testLocal extends ScalaModule {
134-
override def sources = Task.Sources(os.pwd / "test-local" / "src" / "main" / "scala")
115+
override def sources = Task.Sources(moduleDir / "src" / "main" / "scala")
135116
def scalaVersion = scalaVer
136117
override def moduleDeps = Seq(exampleJsoniterJson.jvm)
137118
override def mvnDeps = Task {
@@ -209,9 +190,9 @@ trait TestModule extends Cross.Module5[String, String, String, String, String] w
209190
val dest = Task.dest
210191
val basePkg = s"gcp.$apiName.$apiVersion.${httpSource}_${jsonCodec}_${arrayType}".toLowerCase()
211192
val outSrcDir = dest / "scala"
193+
val ws = implicitly[TaskCtx].workspace
212194
val specFile =
213-
// os.pwd / "modules" / "test-resources" / "src" / "main" / "resources" / s"${apiName}_${apiVersion}.json"
214-
s"/home/roman/projects/rolang/google-api-codegen/modules/test-resources/src/main/resources/${apiName}_${apiVersion}.json"
195+
ws / "modules" / "test-resources" / "src" / "main" / "resources" / s"${apiName}_${apiVersion}.json"
215196

216197
val cliBin = buildCliBinary()
217198

@@ -225,7 +206,7 @@ trait TestModule extends Cross.Module5[String, String, String, String, String] w
225206
s"-json-codec=$jsonCodec",
226207
s"-array-type=$arrayType",
227208
s"-jsoniter-json-type=_root_.example.jsoniter.Json"
228-
).call(cwd = os.pwd)
209+
).call(cwd = ws)
229210
Seq(PathRef(dest))
230211
}
231212

0 commit comments

Comments
 (0)