Skip to content

Commit

Permalink
Enable remote debugging capability in development scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpap committed Sep 6, 2013
1 parent f1a06fe commit b4ba7f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 56 deletions.
14 changes: 11 additions & 3 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ object ProjectBuild extends Build {
override lazy val settings = super.settings ++ Seq(
organization := "org.refptr",
version := "0.1",
description := "Scala-language backend for IPython",
scalaVersion := "2.10.2",
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-language:_"),
shellPrompt := { state =>
Expand Down Expand Up @@ -62,6 +63,9 @@ object ProjectBuild extends Build {
val jrebelOptions = SettingKey[Seq[String]]("jrebel-options")
val jrebelCommand = TaskKey[Seq[String]]("jrebel-command")

val debugPort = SettingKey[Int]("debug-port")
val debugCommand = TaskKey[Seq[String]]("debug-command")

val develScripts = TaskKey[Seq[File]]("devel-scripts")
val userScripts = TaskKey[Seq[File]]("user-scripts")

Expand Down Expand Up @@ -115,7 +119,6 @@ object ProjectBuild extends Build {
lazy val projectSettings = Project.defaultSettings ++ pluginSettings ++ {
import SbtAssembly.AssemblyKeys.{assembly,jarName}
Seq(fork in run := true,
javaOptions in run ++= List("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005"),
libraryDependencies ++= {
import Dependencies._
scalaio ++ Seq(ivy, jopt, jeromq, play_json, slick, h2, sqlite, slf4j, specs2)
Expand All @@ -141,11 +144,16 @@ object ProjectBuild extends Build {
jrebelCommand <<= (jrebelJar, jrebelOptions) map { (jar, options) =>
jar.map(jar => Seq("-XX:+CMSClassUnloadingEnabled", "-noverify", s"-javaagent:$jar") ++ options) getOrElse Nil
},
develScripts <<= (fullClasspath in Compile, mainClass in Compile, baseDirectory, ipyCommands, jrebelCommand, streams) map { (fullClasspath, mainClass, base, commands, jrebel, streams) =>
debugPort := 5005,
debugCommand <<= (debugPort) map { (port) =>
Seq("-Xdebug", s"-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:$port")
},
develScripts <<= (fullClasspath in Compile, mainClass in Compile, baseDirectory, ipyCommands, jrebelCommand, debugCommand, streams) map {
(fullClasspath, mainClass, base, commands, jrebel, debug, streams) =>
val classpath = fullClasspath.files.mkString(java.io.File.pathSeparator)
val main = mainClass getOrElse sys.error("unknown main class")

val cmd = Seq("java") ++ jrebel ++ Seq("-cp", classpath, main, "--profile", "{connection_file}", "--parent", "$@")
val cmd = Seq("java") ++ jrebel ++ debug ++ Seq("-cp", classpath, main, "--profile", "{connection_file}", "--parent", "$@")
val kernel_cmd = cmd.map(arg => s"""\\"$arg\\"""").mkString(", ")

val bin = base / "bin"
Expand Down
57 changes: 4 additions & 53 deletions sbt
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
#!/bin/bash

function usage {
echo "Usage: `basename $0` [OPTION]... -- [JAVA OPTION]..."
echo ""
echo " -d Enable remote debugging (e.g. for IntelliJ)"
echo " -R Don't load JRebel when JVM starts"
echo ""
echo "After -- you can specify options directly to JVM. For example:"
echo ""
echo " ./sbt -d -- -Drun.mode=test -Xmx5G"
echo ""
echo "This will run sbt in debug mode, set run.mode system property"
echo "to 'test' and set JVM max heap size to 5 GiB. These arguments"
echo "are stored at the and of JVM's command line, allowing you to"
echo "override any hard-coded defaults."
echo "Usage: `basename $0` [OPTION|COMMAND]... -- [JVM OPTION]..."
}

DEBUG=0
JREBEL=1

while getopts hdR OPT;
do
case "$OPT" in
h)
usage
exit 0
;;
d)
DEBUG=1
;;
R)
JREBEL=0
;;
\?)
usage
exit 1;
Expand All @@ -52,36 +31,8 @@ else
JVM_OPTS=""
fi

JAVA_OPTS="-Dfile.encoding=UTF-8 -Xss8M -Xmx2G -XX:MaxPermSize=1024M -XX:ReservedCodeCacheSize=64M -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled"

if [ $DEBUG = 1 ];
then
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5004"
fi

if [ $JREBEL = 1 -a -e "$HOME/.jrebel/jrebel/jrebel.jar" ];
then
JREBEL_DIR="project/target/jrebel"

if [ ! -e $JREBEL_DIR ]; then
mkdir -p $JREBEL_DIR
fi

JREBEL_OPTS="-noverify -javaagent:$HOME/.jrebel/jrebel/jrebel.jar"

JREBEL_OPTS="$JREBEL_OPTS -Drebel.usage_reporting=false"
JREBEL_OPTS="$JREBEL_OPTS -Drebel.stats=true"
JREBEL_OPTS="$JREBEL_OPTS -Drebel.log=true"
JREBEL_OPTS="$JREBEL_OPTS -Drebel.log.perf=false"
JREBEL_OPTS="$JREBEL_OPTS -Drebel.log.trace=false"
JREBEL_OPTS="$JREBEL_OPTS -Drebel.log.stdout=false"
JREBEL_OPTS="$JREBEL_OPTS -Drebel.log.file=$JREBEL_DIR/jrebel.log"
JREBEL_OPTS="$JREBEL_OPTS -Drebel.temp.dir=$JREBEL_DIR"

JAVA_OPTS="$JAVA_OPTS $JREBEL_OPTS"
fi

JAVA_OPTS="$JAVA_OPTS $JVM_OPTS"
JVM_DEFAULTS="-Dfile.encoding=UTF-8 -Xss8M -Xmx2G -XX:MaxPermSize=1024M -XX:ReservedCodeCacheSize=64M -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled"
JVM_OPTS="$JVM_DEFAULTS $JVM_OPTS"

SBT_VERSION="0.13.0"
SBT_LAUNCHER="$(dirname $0)/project/sbt-launch-$SBT_VERSION.jar"
Expand All @@ -92,5 +43,5 @@ then
wget -O $SBT_LAUNCHER $URL
fi

java $JAVA_OPTS -jar $SBT_LAUNCHER $SBT_OPTS
java $JVM_OPTS -jar $SBT_LAUNCHER $SBT_OPTS
echo

0 comments on commit b4ba7f9

Please sign in to comment.