Skip to content

Commit

Permalink
simple scripts to run non-bootstrapped compiler after 'sbt buildQuick' (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
bishabosha authored May 21, 2024
2 parents a21cd82 + 19a453d commit 24d703c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ testlogs/
local/
compiler/test/debug/Gen.jar

/bin/.cp

before-pickling.txt
after-pickling.txt
bench/compile.txt
Expand Down
6 changes: 6 additions & 0 deletions bin/commonQ
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cp=$(cat $ROOT/bin/.cp) 2> /dev/null

if [[ "$cp" == "" ]]; then
echo "run 'sbt buildQuick' first"
exit 1
fi
6 changes: 6 additions & 0 deletions bin/scalaQ
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.."
. $ROOT/bin/commonQ

java -cp $cp dotty.tools.MainGenericRunner -usejavacp "$@"
6 changes: 6 additions & 0 deletions bin/scalacQ
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.."
. $ROOT/bin/commonQ

java -cp $cp dotty.tools.MainGenericCompiler -usejavacp "$@"
6 changes: 6 additions & 0 deletions docs/_docs/contributing/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ $ scalac tests/pos/HelloWorld.scala
$ scala HelloWorld
```

Note that the `scalac` and `scala` scripts have slow roundtrip times when working on the compiler codebase: whenever
any source file changes they invoke `sbt dist/pack` first.

As an alternative, run the `buildQuick` task in sbt. It builds the compiler and writes its classpath to the `bin/.cp`
file, which enables the `scalacQ` and `scalaQ` scripts in the `bin/` folder.

## Starting a REPL

```bash
Expand Down
7 changes: 7 additions & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ object Build {

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

val buildQuick = taskKey[Unit]("builds the compiler and writes the classpath to bin/.cp to enable the bin/scalacQ and bin/scalaQ scripts")

// Compiles the documentation and static site
val genDocs = inputKey[Unit]("run scaladoc to generate static documentation site")

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

0 comments on commit 24d703c

Please sign in to comment.