Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set workspace dir to os.tmp.dir for virtual sources #1771

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/build/src/main/scala/scala/build/input/Inputs.scala
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
}
Original file line number Diff line number Diff line change
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))
}
}
}
Original file line number Diff line number Diff line change
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