Skip to content

Commit 24d703c

Browse files
authored
simple scripts to run non-bootstrapped compiler after 'sbt buildQuick' (#19894)
The current scripts in `bin` are not suitable for iterative development, as they invoke `sbt dist/pack` whenever any source file has a newer timestamp. Also they are full of magic which I don't think I need for compiler development. I know there are `repl` / `scala` / `scalac` sbt tasks, but I highly prefer working in zsh versus sbt shell, for example because I can `cd` to a `sandbox` directory. Then I run `scq A.scala`, `cfr-decompiler A.class`, stuff like that. This PR is a proposal, I'm curious if anyone else would find it useful.
2 parents a21cd82 + 19a453d commit 24d703c

File tree

6 files changed

+33
-0
lines changed

6 files changed

+33
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ testlogs/
6464
local/
6565
compiler/test/debug/Gen.jar
6666

67+
/bin/.cp
68+
6769
before-pickling.txt
6870
after-pickling.txt
6971
bench/compile.txt

bin/commonQ

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cp=$(cat $ROOT/bin/.cp) 2> /dev/null
2+
3+
if [[ "$cp" == "" ]]; then
4+
echo "run 'sbt buildQuick' first"
5+
exit 1
6+
fi

bin/scalaQ

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.."
4+
. $ROOT/bin/commonQ
5+
6+
java -cp $cp dotty.tools.MainGenericRunner -usejavacp "$@"

bin/scalacQ

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.."
4+
. $ROOT/bin/commonQ
5+
6+
java -cp $cp dotty.tools.MainGenericCompiler -usejavacp "$@"

docs/_docs/contributing/getting-started.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ $ scalac tests/pos/HelloWorld.scala
8181
$ scala HelloWorld
8282
```
8383

84+
Note that the `scalac` and `scala` scripts have slow roundtrip times when working on the compiler codebase: whenever
85+
any source file changes they invoke `sbt dist/pack` first.
86+
87+
As an alternative, run the `buildQuick` task in sbt. It builds the compiler and writes its classpath to the `bin/.cp`
88+
file, which enables the `scalacQ` and `scalaQ` scripts in the `bin/` folder.
89+
8490
## Starting a REPL
8591

8692
```bash

project/Build.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ object Build {
210210

211211
val repl = taskKey[Unit]("spawns a repl with the correct classpath")
212212

213+
val buildQuick = taskKey[Unit]("builds the compiler and writes the classpath to bin/.cp to enable the bin/scalacQ and bin/scalaQ scripts")
214+
213215
// Compiles the documentation and static site
214216
val genDocs = inputKey[Unit]("run scaladoc to generate static documentation site")
215217

@@ -2154,6 +2156,11 @@ object Build {
21542156
// default.
21552157
addCommandAlias("publishLocal", "scala3-bootstrapped/publishLocal"),
21562158
repl := (`scala3-compiler-bootstrapped` / repl).value,
2159+
buildQuick := {
2160+
val _ = (`scala3-compiler` / Compile / compile).value
2161+
val cp = (`scala3-compiler` / Compile / fullClasspath).value.map(_.data.getAbsolutePath).mkString(File.pathSeparator)
2162+
IO.write(baseDirectory.value / "bin" / ".cp", cp)
2163+
},
21572164
(Compile / console) := (Compile / console).dependsOn(Def.task {
21582165
import _root_.scala.io.AnsiColor._
21592166
val msg = "`console` uses the reference Scala version. Use `repl` instead."

0 commit comments

Comments
 (0)