Skip to content

Commit

Permalink
Set workspace dir to os.tmp for virtual sources
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Jan 12, 2023
1 parent a809da5 commit bbc4e42
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
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,30 @@ 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"
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 msg = "Hello"
val inputs = TestInputs(
os.rel / "Hello.scala" ->
s"""object Hello {
| val hello = $msg
|}""".stripMargin
)
inputs.fromRoot { root =>
val quotation = TestUtil.argQuotationMark
os.proc(TestUtil.cli, "-e", s"println($quotation$msg$quotation)", ".", extraOptions)
.call(cwd = root)
.out.trim()
expect(os.exists(root / Constants.workspaceDirName))
}
}
}

0 comments on commit bbc4e42

Please sign in to comment.