Skip to content

Commit

Permalink
Make use of OS-Lib's new literal multi-segment subpaths (#3508)
Browse files Browse the repository at this point in the history
Introduced in com-lihaoyi/os-lib#297, these
allow conciseness when working with literal paths/path-segments while
limiting it to compile-time literals to avoid potential path traversal
issues that may arise from parsing dynamic paths
  • Loading branch information
lihaoyi authored Sep 10, 2024
1 parent 40b1920 commit 7248cb3
Show file tree
Hide file tree
Showing 59 changed files with 245 additions and 245 deletions.
2 changes: 1 addition & 1 deletion build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ object Deps {
val junitInterface = ivy"com.github.sbt:junit-interface:0.13.3"
val commonsIO = ivy"commons-io:commons-io:2.16.1"
val log4j2Core = ivy"org.apache.logging.log4j:log4j-core:2.23.1"
val osLib = ivy"com.lihaoyi::os-lib:0.10.7-M1"
val osLib = ivy"com.lihaoyi::os-lib:0.10.7-M2"
val pprint = ivy"com.lihaoyi::pprint:0.9.0"
val mainargs = ivy"com.lihaoyi::mainargs:0.7.4"
val millModuledefsVersion = "0.11.0-M2"
Expand Down
16 changes: 8 additions & 8 deletions contrib/bloop/test/src/mill/contrib/bloop/BloopTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ object BloopTests extends TestSuite {

// Ensuring that bloop config generation didn't trigger compilation
assert(os.exists(workspaceOut / "scalaModule"))
assert(!os.exists(workspaceOut / "scalaModule" / "compile"))
assert(!os.exists(workspaceOut / "scalaModule/compile"))
assert(os.exists(workspaceOut / "scalaModule2"))
assert(!os.exists(workspaceOut / "scalaModule2" / "compile"))
assert(!os.exists(workspaceOut / "scalaModule2/compile"))
}

test("scalaModule") {
Expand All @@ -126,7 +126,7 @@ object BloopTests extends TestSuite {

assert(name == "scalaModule")
assert(workspaceDir == Some(workdir.wrapped))
assert(sources == List(workdir / "scalaModule" / "src"))
assert(sources == List(workdir / "scalaModule/src"))
assert(options.contains("-language:higherKinds"))
assert(version == "2.12.8")
assert(
Expand Down Expand Up @@ -171,7 +171,7 @@ object BloopTests extends TestSuite {
val mainModuleClasspath = scalaModuleConfig.project.classpath
assert(name == "scalaModule.test")
assert(workspaceDir == Some(workdir.wrapped))
assert(sources == List(workdir / "scalaModule" / "test" / "src"))
assert(sources == List(workdir / "scalaModule/test/src"))
assert(framework == "utest.runner.Framework")
assert(dep == "scalaModule")
assert(
Expand Down Expand Up @@ -228,7 +228,7 @@ object BloopTests extends TestSuite {

assert(name == "scalajsModule")
assert(workspaceDir == Some(workdir.wrapped))
assert(sources == List(workdir / "scalajsModule" / "src"))
assert(sources == List(workdir / "scalajsModule/src"))
assert(version == build.scalajsModule.sv)
assert(platform.config.emitSourceMaps)
assert(platform.config.kind == BloopConfig.ModuleKindJS.CommonJSModule)
Expand All @@ -237,7 +237,7 @@ object BloopTests extends TestSuite {
test("scalanativeModule") {
scalanativeModuleConfig match {
case None =>
val exists = os.exists(workdir / ".bloop" / "scalanativeModule.json")
val exists = os.exists(workdir / ".bloop/scalanativeModule.json")
assert(exists == false)
case Some(scalanativeModuleConfig) =>
val p = scalanativeModuleConfig.project
Expand All @@ -252,14 +252,14 @@ object BloopTests extends TestSuite {

assert(name == "scalanativeModule")
assert(workspaceDir == Some(workdir.wrapped))
assert(sources == List(workdir / "scalanativeModule" / "src"))
assert(sources == List(workdir / "scalanativeModule/src"))
assert(version == build.scalanativeModule.sv)
assert(platform.config.mode == BloopConfig.LinkerMode.Debug)
assert(platform.config.clang == clang.value.toNIO)
}
}
test("skipped") {
val exists = os.exists(workdir / ".bloop" / "skippedModule.json")
val exists = os.exists(workdir / ".bloop/skippedModule.json")
assert(exists == false)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ object BuildInfoTests extends TestSuite {
val testModuleSourcesPath: Path = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "buildinfo"

def buildInfoSourcePath(eval: UnitTester) =
eval.outPath / "buildInfoSources.dest" / "foo" / "BuildInfo.scala"
eval.outPath / "buildInfoSources.dest/foo/BuildInfo.scala"

def buildInfoResourcePath(eval: UnitTester) =
eval.outPath / "buildInfoResources.dest" / "foo" / "BuildInfo.buildinfo.properties"
eval.outPath / "buildInfoResources.dest/foo/BuildInfo.buildinfo.properties"
def tests: Tests = Tests {

test("notCreateEmptySourcefile") - UnitTester(
Expand Down Expand Up @@ -144,9 +144,9 @@ object BuildInfoTests extends TestSuite {
val Right(result) = eval.apply(BuildInfoSettings.buildInfoSources)
val path = result.value.head.path

assert(os.exists(path / "foo" / "bar.scala"))
assert(os.exists(path / "foo/bar.scala"))

val found = os.read(path / "foo" / "bar.scala").replaceAll("(\r\n)|\r", "\n")
val found = os.read(path / "foo/bar.scala").replaceAll("(\r\n)|\r", "\n")
assert(found.contains("object bar"))
}

Expand Down Expand Up @@ -200,7 +200,7 @@ object BuildInfoTests extends TestSuite {
test("java-static") - UnitTester(BuildInfoJavaStatic, testModuleSourcesPath / "java").scoped {
eval =>
val runResult = eval.outPath / "hello-mill"
val generatedSrc = eval.outPath / "buildInfoSources.dest" / "foo" / "BuildInfo.java"
val generatedSrc = eval.outPath / "buildInfoSources.dest/foo/BuildInfo.java"
val Right(_) =
eval.apply(BuildInfoJavaStatic.run(T.task(Args(runResult.toString))))

Expand Down
2 changes: 1 addition & 1 deletion contrib/flyway/src/mill/contrib/flyway/FlywayModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ trait FlywayModule extends JavaModule {
def flywayUser: T[String] = T("")
def flywayPassword: T[String] = T("")
def flywayFileLocations: T[Seq[PathRef]] = T {
resources().map(pr => PathRef(pr.path / "db" / "migration", pr.quick))
resources().map(pr => PathRef(pr.path / "db/migration", pr.quick))
}

def flywayDriverDeps: T[Agg[Dep]]
Expand Down
4 changes: 2 additions & 2 deletions contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ object PlayModuleTests extends TestSuite with PlayTestSuite {
os.RelPath("views/html/main$.class"),
os.RelPath("views/html/main.class")
).map(
eval.outPath / "core" / scalaVersion / playVersion / "compile.dest" / "classes" / _
eval.outPath / "core" / scalaVersion / playVersion / "compile.dest/classes" / _
)
assert(
result.value.classes.path == eval.outPath / "core" / scalaVersion / playVersion / "compile.dest" / "classes",
result.value.classes.path == eval.outPath / "core" / scalaVersion / playVersion / "compile.dest/classes",
outputClassFiles.nonEmpty,
outputClassFiles.forall(expectedClassfiles.contains),
outputClassFiles.size == 15,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ object PlaySingleApiModuleTests extends TestSuite with PlayTestSuite {
os.RelPath("router/RoutesPrefix$.class"),
os.RelPath("router/RoutesPrefix.class")
).map(
eval.outPath / "compile.dest" / "classes" / _
eval.outPath / "compile.dest/classes" / _
)
assert(
result.value.classes.path == eval.outPath / "compile.dest" / "classes",
result.value.classes.path == eval.outPath / "compile.dest/classes",
outputFiles.nonEmpty,
outputFiles.forall(expectedClassfiles.contains),
outputFiles.size == 11,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ object PlaySingleModuleTests extends TestSuite with PlayTestSuite {
os.RelPath("views/html/main$.class"),
os.RelPath("views/html/main.class")
).map(
eval.outPath / "compile.dest" / "classes" / _
eval.outPath / "compile.dest/classes" / _
)
assert(
result.value.classes.path == eval.outPath / "compile.dest" / "classes",
result.value.classes.path == eval.outPath / "compile.dest/classes",
outputFiles.nonEmpty,
outputFiles.forall(expectedClassfiles.contains),
outputFiles.size == 15,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ object TutorialTests extends TestSuite {
object TutorialWithSpecificSources extends TutorialBase {
object core extends TutorialModule {
override def scalaPBSources: T[Seq[PathRef]] = T.sources {
millSourcePath / "protobuf" / "tutorial" / "Tutorial.proto"
millSourcePath / "protobuf/tutorial/Tutorial.proto"
}

override def scalaPBSearchDeps = true
override def scalaPBIncludePath = Seq(
PathRef(millSourcePath / "protobuf" / "tutorial")
PathRef(millSourcePath / "protobuf/tutorial")
)
}
}

val resourcePath: os.Path = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER"))

def protobufOutPath(eval: UnitTester): os.Path =
eval.outPath / "core" / "compileScalaPB.dest" / "com" / "example" / "tutorial"
eval.outPath / "core/compileScalaPB.dest/com/example/tutorial"

def compiledSourcefiles: Seq[os.RelPath] = Seq[os.RelPath](
os.rel / "AddressBook.scala",
Expand Down Expand Up @@ -92,7 +92,7 @@ object TutorialTests extends TestSuite {
val expectedSourcefiles = compiledSourcefiles.map(outPath / _)

assert(
result.value.path == eval.outPath / "core" / "compileScalaPB.dest",
result.value.path == eval.outPath / "core/compileScalaPB.dest",
outputFiles.nonEmpty,
outputFiles.forall(expectedSourcefiles.contains),
outputFiles.size == 5,
Expand Down Expand Up @@ -123,7 +123,7 @@ object TutorialTests extends TestSuite {
).map(outPath / _)

assert(
result.value.path == eval.outPath / "core" / "compileScalaPB.dest",
result.value.path == eval.outPath / "core/compileScalaPB.dest",
outputFiles.nonEmpty,
outputFiles.forall(expectedSourcefiles.contains),
outputFiles.size == 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SonatypeCentralPublisher(
val (_, releases) = mappings.partition(_._1.isSnapshot)

val releaseGroups = releases.groupBy(_._1.group)
val wd = os.pwd / "out" / "publish-central"
val wd = os.pwd / "out/publish-central"
os.makeDir.all(wd)

singleBundleName.fold {
Expand Down
14 changes: 7 additions & 7 deletions contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ trait HelloWorldTests extends TestSuite {

def resourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER"))
def compileClassfiles: Seq[os.RelPath] = Seq[os.RelPath](
os.rel / "html" / "hello.template.scala",
os.rel / "html" / "wrapper.template.scala",
os.rel / "svg" / "test.template.scala"
os.rel / "html/hello.template.scala",
os.rel / "html/wrapper.template.scala",
os.rel / "svg/test.template.scala"
)

def expectedDefaultImports: Seq[String] = Seq(
Expand Down Expand Up @@ -85,11 +85,11 @@ trait HelloWorldTests extends TestSuite {

val outputFiles = os.walk(result.value.classes.path).filter(_.last.endsWith(".scala"))
val expectedClassfiles = compileClassfiles.map(
eval.outPath / "core" / "compileTwirl.dest" / _
eval.outPath / "core/compileTwirl.dest" / _
)

assert(
result.value.classes.path == eval.outPath / "core" / "compileTwirl.dest",
result.value.classes.path == eval.outPath / "core/compileTwirl.dest",
outputFiles.nonEmpty,
outputFiles.forall(expectedClassfiles.contains),
outputFiles.size == 3,
Expand Down Expand Up @@ -126,7 +126,7 @@ trait HelloWorldTests extends TestSuite {

val outputFiles = os.walk(result.value.classes.path).filter(_.last.endsWith(".scala"))
val expectedClassfiles = compileClassfiles.map(name =>
eval.outPath / "core" / "compileTwirl.dest" / name / os.RelPath.up / name.last.replace(
eval.outPath / "core/compileTwirl.dest" / name / os.RelPath.up / name.last.replace(
".template.scala",
"$$TwirlInclusiveDot.template.scala"
)
Expand All @@ -135,7 +135,7 @@ trait HelloWorldTests extends TestSuite {
println(s"outputFiles: $outputFiles")

assert(
result.value.classes.path == eval.outPath / "core" / "compileTwirl.dest",
result.value.classes.path == eval.outPath / "core/compileTwirl.dest",
outputFiles.nonEmpty,
outputFiles.forall(expectedClassfiles.contains),
outputFiles.size == 3,
Expand Down
2 changes: 1 addition & 1 deletion example/depth/tasks/11-module-run-task/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object foo extends ScalaModule {

object bar extends ScalaModule{
def scalaVersion = "2.13.8"
def ivyDeps = Agg(ivy"com.lihaoyi::os-lib:0.9.1")
def ivyDeps = Agg(ivy"com.lihaoyi::os-lib:0.10.7-M2")
}

// This example demonstrates using Mill ``ScalaModule``s as build tasks: rather
Expand Down
2 changes: 1 addition & 1 deletion example/extending/imports/3-import-ivy/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import $ivy.`com.lihaoyi::scalatags:0.12.0`, scalatags.Text.all._
object `package` extends RootModule with ScalaModule {
def scalaVersion = "2.13.8"

def ivyDeps = Agg(ivy"com.lihaoyi::os-lib:0.9.1")
def ivyDeps = Agg(ivy"com.lihaoyi::os-lib:0.10.7-M2")
def htmlSnippet = T{ div(h1("hello"), p("world")).toString }
def resources = T.sources{
os.write(T.dest / "snippet.txt", htmlSnippet())
Expand Down
2 changes: 1 addition & 1 deletion example/extending/metabuild/4-meta-build/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object `package` extends RootModule with ScalaModule {
def scalaVersion = "2.13.4"
def ivyDeps = Agg(
ivy"com.lihaoyi::scalatags:${millbuild.DepVersions.scalatagsVersion}",
ivy"com.lihaoyi::os-lib:0.9.1"
ivy"com.lihaoyi::os-lib:0.10.7-M2"
)

def htmlSnippet = T{ h1("hello").toString }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mill._, scalalib._
object `package` extends RootModule with ScalaModule {
def scalaVersion = millbuild.ScalaVersion.myScalaVersion
def sources = T.sources{
super.sources() ++ Seq(PathRef(millSourcePath / "mill-build" / "src"))
super.sources() ++ Seq(PathRef(millSourcePath / "mill-build/src"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object myplugin extends ScalaModule with PublishModule {
def ivyDeps = Agg(ivy"com.lihaoyi:mill-dist:$millVersion")
def mainClass = Some("mill.runner.client.MillClientMain")
def resources = T{
val p = T.dest / "mill" / "local-test-overrides" / s"com.lihaoyi-${myplugin.artifactId()}"
val p = T.dest / "mill/local-test-overrides" / s"com.lihaoyi-${myplugin.artifactId()}"
os.write(p, myplugin.localClasspath().map(_.path).mkString("\n"), createFolders = true)
Seq(PathRef(T.dest))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object IntegrationTests extends TestSuite {
assert(res2.out.contains("Line Count: 17"))
assert(tester.out("lineCount").value[Int] == 17)

tester.modifyFile(tester.workspacePath / "src" / "foo" / "Foo.java", _ + "\n")
tester.modifyFile(tester.workspacePath / "src/foo/Foo.java", _ + "\n")

val res3 = tester.eval("run") // Additional newline forces recompile and increases line count
assert(res3.err.contains("compiling 1 Java source"))
Expand Down
2 changes: 1 addition & 1 deletion example/scalalib/builds/1-common-config/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object `package` extends RootModule with ScalaModule {
// You can have arbitrary numbers of third-party dependencies
def ivyDeps = Agg(
ivy"com.lihaoyi::scalatags:0.8.2",
ivy"com.lihaoyi::os-lib:0.9.1",
ivy"com.lihaoyi::os-lib:0.10.7-M2",
)

// Choose a main class to use for `.run` if there are multiple present
Expand Down
2 changes: 1 addition & 1 deletion example/scalalib/module/11-assembly-config/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mill.scalalib.Assembly._
object foo extends ScalaModule {
def moduleDeps = Seq(bar)
def scalaVersion = "2.13.8"
def ivyDeps = Agg(ivy"com.lihaoyi::os-lib:0.9.1")
def ivyDeps = Agg(ivy"com.lihaoyi::os-lib:0.10.7-M2")
def assemblyRules = Seq(
// all application.conf files will be concatenated into single file
Rule.Append("application.conf"),
Expand Down
2 changes: 1 addition & 1 deletion example/scalalib/module/5-resources/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mill._, scalalib._
object foo extends ScalaModule {
def scalaVersion = "2.13.8"
def ivyDeps = Agg(
ivy"com.lihaoyi::os-lib:0.9.1"
ivy"com.lihaoyi::os-lib:0.10.7-M2"
)

object test extends ScalaTests {
Expand Down
2 changes: 1 addition & 1 deletion example/scalalib/web/2-webapp-cache-busting/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object `package` extends RootModule with ScalaModule {
def ivyDeps = Agg(
ivy"com.lihaoyi::cask:0.9.1",
ivy"com.lihaoyi::scalatags:0.12.0",
ivy"com.lihaoyi::os-lib:0.9.1"
ivy"com.lihaoyi::os-lib:0.10.7-M2"
)

def resources = T {
Expand Down
4 changes: 2 additions & 2 deletions example/scalalib/web/4-webapp-scalajs/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ object `package` extends RootModule with ScalaModule {
val jsPath = client.fastLinkJS().dest.path
// Move main.js[.map]into the proper filesystem position
// in the resource folder for the web server code to pick up
os.copy(jsPath / "main.js", T.dest / "webapp" / "main.js")
os.copy(jsPath / "main.js.map", T.dest / "webapp" / "main.js.map")
os.copy(jsPath / "main.js", T.dest / "webapp/main.js")
os.copy(jsPath / "main.js.map", T.dest / "webapp/main.js.map")
super.resources() ++ Seq(PathRef(T.dest))
}

Expand Down
4 changes: 2 additions & 2 deletions example/scalalib/web/5-webapp-scalajs-shared/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ object `package` extends RootModule with AppScalaModule {
def resources = T{
os.makeDir(T.dest / "webapp")
val jsPath = client.fastLinkJS().dest.path
os.copy(jsPath / "main.js", T.dest / "webapp" / "main.js")
os.copy(jsPath / "main.js.map", T.dest / "webapp" / "main.js.map")
os.copy(jsPath / "main.js", T.dest / "webapp/main.js")
os.copy(jsPath / "main.js.map", T.dest / "webapp/main.js.map")
super.resources() ++ Seq(PathRef(T.dest))
}

Expand Down
Loading

0 comments on commit 7248cb3

Please sign in to comment.