Skip to content

Commit b1229dc

Browse files
committed
Implement some review feedback, some polish of my own
Reworks #438
1 parent 29da91a commit b1229dc

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

contribute/hacker-guide.md

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ You need the following tools:
108108

109109
OS X and Linux builds should work. Windows is supported, but it might have issues. Please report to [the issue tracker](https://issues.scala-lang.org/) if you encounter any.
110110

111-
Building Scala is as easy as running `sbt dist/mkPack` in the root of your cloned repository. Be prepared to wait for a while -- a full "clean" build
112-
takes 5+ minutes depending on your machine (longer on older machines with less memory). Incremental builds are usually within 20-120 seconds range (again, your mileage might vary
113-
with your hardware).
111+
Building Scala is as easy as running `sbt dist/mkPack` in the root of your cloned repository. In general, it's much more efficient to enter the `sbt` shell once and run the various tasks from there, instead of running each task by launching `sbt some-task` on your command prompt.
112+
113+
Be prepared to wait for a while -- a full "clean" build takes 5+ minutes depending on your machine (longer on older machines with less memory). On a recent laptop, incremental builds usually complete within 10-30 seconds.
114114

115115
### IDE
116116

@@ -155,31 +155,33 @@ Now, implement your bugfix or new feature!
155155

156156
Here are also some tips & tricks that have proven useful in Scala development:
157157

158-
* Even on solid state drives packaging Scala distribution (i.e. creating jars from class files) is a non-trivial task. To save time here, some people in our team do `sbt compile` instead of `sbt dist/mkPack` and then create custom scripts using `sbt/mkBin` to launch Scala from `./build/quick/bin/`. Also see [the Scala README](https://github.com/scala/scala#incremental-compilation) for tips on speeding up compile times.
159-
* If after introducing changes or updating your clone, you get `AbstractMethodError` or other linkage exceptions, try doing `sbt clean` and building again.
158+
* After building your working copy with the `compile` sbt task, there's no need to leave the comfort of your sbt shell to try it out: the REPL is available as the `scala` task, and you can also run the compiler using the `scalac` task. If you prefer to run the REPL outside sbt, you can generate the scripts in `build/quick/bin` using the `dist/mkQuick` task.
159+
* The sbt workflow is also great for debugging, as you can simply create a remote debugging session in your favorite IDE, and then activate the JVM options for the next time you run the `scala` or `scalac` tasks using:
160+
161+
```
162+
> set javaOptions in compiler := List("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8002")
163+
> scalac test.scala
164+
[info] Running scala.tools.nsc.Main -usejavacp test.scala
165+
Listening for transport dt_socket at address: 8002
166+
```
167+
168+
* Also see [the Scala README](https://github.com/scala/scala#incremental-compilation) for tips on speeding up compile times.
169+
* If after introducing changes or updating your clone, you get `AbstractMethodError` or other linkage exceptions, try the `clean` task and building again.
160170
* Don't underestimate the power of `print`. When starting with Scala, I spent a lot of time in the debugger trying to figure out how
161171
things work. However later I found out that print-based debugging is often more effective than jumping around. While it might be obvious
162-
to some, I'd like to explicitly mention that it's also useful to print stack traces to understand the flow of execution. When working with `Trees`, you might want to use the Scala `showRaw` to get the `AST` representation.
163-
* You can publish your newly-built scala version locally using `sbt publishLocal`. Then, you can invoke a REPL using your version:
164-
165-
$ sbt publishLocal // This may take a while
166-
...
167-
$ sbt
168-
...
169-
> scala
170-
[info] Running scala.tools.nsc.MainGenericRunner -usejavacp
171-
Welcome to Scala 2.12.0-20160613-195040-cd85531 (OpenJDK 64-Bit Server VM, Java 1.8.0_91).
172-
Type in expressions for evaluation. Or try :help.
173-
174-
scala>
175-
176-
Alternatively, you can invoke a REPL using the bash script in `./build/quick/bin/`:
177-
178-
$ ./build/quick/bin/scala
179-
Welcome to Scala 2.12.0-20160613-195040-cd85531 (OpenJDK 64-Bit Server VM, Java 1.8.0_91).
180-
Type in expressions for evaluation. Or try :help.
181-
182-
scala>
172+
to some, I'd like to explicitly mention that it's also useful to print stack traces to understand the flow of execution. When working with `Trees`, you might want to use `showRaw` to get the `AST` representation.
173+
* You can publish your newly-built scala version locally using the `publishLocal` task in sbt.
174+
* It's convenient to enable the following local settings to speed up your workflow (put these in `local.sbt` in your working copy):
175+
```
176+
// skip docs for local publishing
177+
publishArtifact in (Compile, packageDoc) in ThisBuild := false
178+
// set version based on current sha, so that you can easily consume this build from another sbt project
179+
baseVersionSuffix := s"local-${Process("tools/get-scala-commit-sha").lines.head.substring(0, 7)}"
180+
// show more logging during a partest run
181+
testOptions in IntegrationTest in LocalProject("test") ++= Seq(Tests.Argument("--show-log"), Tests.Argument("--show-diff"))
182+
// if incremental compilation is compiling too much (should be fine under sbt 0.13.13)
183+
// antStyle := true
184+
```
183185

184186
* Adding a macro to the `Predef` object is a pretty involved task. Due to bootstrapping, you cannot just throw a macro into it. For this reason, the process is more involved. You might want to follow the way `StringContext.f` itself is added. In short, you need to define your macro under `src/compiler/scala/tools/reflect/` and provide no implementation in `Predef` (`def fn = macro ???`). Now you have to set up the wiring. Add the name of your macro to `src/reflect/scala/reflect/internal/StdNames.scala`, add the needed links to it to `src/reflect/scala/reflect/internal/Definitions.scala`, and finally specify the bindings in `src/compiler/scala/tools/reflect/FastTrack.scala`. [Here's](https://github.com/folone/scala/commit/59536ea833ca16c985339727baed5d70e577b0fe) an example of adding a macro.
185187

0 commit comments

Comments
 (0)