Skip to content

Commit

Permalink
Set workspace dir to os.tmp for virtual sources (#1771)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Jan 16, 2023
1 parent 6628baa commit 026e507
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
5 changes: 5 additions & 0 deletions modules/build/src/main/scala/scala/build/input/Inputs.scala
Expand Up @@ -157,6 +157,11 @@ object Inputs {
)
(f.path / os.up, true, WorkspaceOrigin.SourcePaths)
}
}.orElse {
validElems.collectFirst {
case _: Virtual =>
(os.temp.dir(), true, WorkspaceOrigin.VirtualForced)
}
}.getOrElse((os.pwd, true, WorkspaceOrigin.Forced))
}

Expand Down
Expand Up @@ -9,5 +9,6 @@ object WorkspaceOrigin {

case object ResourcePaths extends WorkspaceOrigin

case object HomeDir extends WorkspaceOrigin
case object HomeDir extends WorkspaceOrigin
case object VirtualForced extends WorkspaceOrigin
}
Expand Up @@ -144,4 +144,28 @@ trait RunSnippetTestDefinitions { _: RunTestDefinitions =>
expect(res.out.trim() == expectedOutput)
}
}
test("running a script snippet should not create the workspace dir in cwd") {
emptyInputs.fromRoot { root =>
val quotation = TestUtil.argQuotationMark
val msg = "Hello World from snippet"
os.proc(TestUtil.cli, "-e", s"println($quotation$msg$quotation)", extraOptions)
.call(cwd = root)
.out.trim()
expect(!os.exists(root / Constants.workspaceDirName))
}
}
test("running a script snippet with one source file should create the workspace dir in cwd") {
val inputs = TestInputs(
os.rel / "Hello.scala" ->
s"""object Hello {
| val hello = "Hello World"
|}""".stripMargin
)
inputs.fromRoot { root =>
os.proc(TestUtil.cli, "-e", s"println(Hello.hello)", ".", extraOptions)
.call(cwd = root)
.out.trim()
expect(os.exists(root / Constants.workspaceDirName))
}
}
}
Expand Up @@ -176,11 +176,13 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
passArgumentsScala3()
}

test("setting root dir with no inputs") {
test("setting root dir with virtual input") {
val url = "https://gist.github.com/alexarchambault/7b4ec20c4033690dd750ffd601e540ec"
emptyInputs.fromRoot { root =>
os.proc(TestUtil.cli, extraOptions, escapedUrls(url)).call(cwd = root)
expect(os.exists(root / ".scala-build"))
expect(
!os.exists(root / ".scala-build")
) // virtual source should not create workspace dir in cwd
}
}

Expand Down

0 comments on commit 026e507

Please sign in to comment.