Skip to content

Commit b51fe3d

Browse files
committed
Convenient aliases for the SBT build
The idea here is to avoid the need for switching between the SBT shell and Bash. - Add aliases for partest, scala{,c,p,doc} - Change working directory for these forked processes to the root project base directory, rather than the subprojects base directory. This lets us use relative paths to files in a more familar way. - Don't log the output of forked processes with the `[info] ` prefix, rather pass it through directly to stdout. Demo: ``` > partest --terse test/files/pos/t6231.scala [info] Packaging /Users/jason/code/scala2/build-sbt/pack/lib/scala-partest-javaagent.jar ... [info] Done packaging. Selected 1 tests drawn from specified tests . [info] Passed: Total 1, Failed 0, Errors 0, Passed 1 [success] Total time: 3 s, completed 05/02/2016 12:44:19 PM > scala sandbox/test.scala [info] Running scala.tools.nsc.MainGenericRunner -usejavacp sandbox/test.scala Hello, World! [success] Total time: 4 s, completed 05/02/2016 12:45:08 PM > scalac sandbox/test.scala [info] Running scala.tools.nsc.Main -usejavacp sandbox/test.scala [success] Total time: 3 s, completed 05/02/2016 12:45:15 PM > scala Test [info] Running scala.tools.nsc.MainGenericRunner -usejavacp Test Hello, World! [success] Total time: 1 s, completed 05/02/2016 12:45:20 PM > scala [info] Running scala.tools.nsc.MainGenericRunner -usejavacp Welcome to Scala 2.11.8-20160204-090931-42525ec (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_71). Type in expressions for evaluation. Or try :help. scala> 1.to to toBinaryString toByte toChar toDegrees toDouble toFloat toHexString toInt toLong toOctalString toRadians toShort toString scala> 1.toString res0: String = 1 scala> :quit [success] Total time: 8 s, completed 05/02/2016 12:45:48 PM > ```
1 parent 42525ec commit b51fe3d

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

build.sbt

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,18 @@ lazy val commonSettings = clearSourceAndResourceDirectories ++ publishSettings +
200200
},
201201
// Remove auto-generated manifest attributes
202202
packageOptions in Compile in packageBin := Seq.empty,
203-
packageOptions in Compile in packageSrc := Seq.empty
203+
packageOptions in Compile in packageSrc := Seq.empty,
204+
205+
// Lets us CTRL-C partest without exiting SBT entirely
206+
cancelable in Global := true,
207+
// When we fork subprocesses, use the base directory as the working directory.
208+
// This enables `sbt> partest test/files/run/t1.scala` or `sbt> scalac sandbox/test.scala`
209+
baseDirectory in Compile := (baseDirectory in ThisBuild).value,
210+
baseDirectory in Test := (baseDirectory in ThisBuild).value,
211+
212+
// Don't log process output (e.g. of forked `compiler/runMain ...Main`), just pass it
213+
// directly to stdout
214+
outputStrategy in run := Some(StdoutOutput)
204215
)
205216

206217
/** Extra post-processing for the published POM files. These are needed to create POMs that
@@ -418,7 +429,6 @@ lazy val repl = configureAsSubproject(project)
418429
.settings(
419430
connectInput in run := true,
420431
publishArtifact := false,
421-
outputStrategy in run := Some(StdoutOutput),
422432
run <<= (run in Compile).partialInput(" -usejavacp") // Automatically add this so that `repl/run` works without additional arguments.
423433
)
424434
.dependsOn(compiler, interactive)
@@ -465,7 +475,8 @@ lazy val replJlineEmbedded = Project("repl-jline-embedded", file(".") / "target"
465475
val outdir = (classDirectory in Compile).value
466476
JarJar(inputs, outdir, config)
467477
}),
468-
publishArtifact := false
478+
publishArtifact := false,
479+
connectInput in run := true
469480
)
470481
.dependsOn(replJline)
471482

@@ -819,3 +830,10 @@ def generateServiceProviderResources(services: (String, String)*): Setting[_] =
819830
}.taskValue
820831

821832
buildDirectory in ThisBuild := (baseDirectory in ThisBuild).value / "build-sbt"
833+
834+
// TODO custom argument parsers for these to autocomplete compiler options and paths
835+
addCommandAlias("scalac", "compiler/compile:runMain scala.tools.nsc.Main -usejavacp")
836+
addCommandAlias("scala", "repl-jline-embedded/compile:runMain scala.tools.nsc.MainGenericRunner -usejavacp")
837+
addCommandAlias("scaladoc", "scaladoc/compile:runMain scala.tools.nsc.ScalaDoc -usejavacp")
838+
addCommandAlias("scalap", "scalap/compile:runMain scala.tools.scalap.Main -usejavacp")
839+
addCommandAlias("partest", "test/it:testOnly --")

0 commit comments

Comments
 (0)