summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorGilles Dubochet <gilles.dubochet@epfl.ch>2006-03-20 15:58:47 +0000
committerGilles Dubochet <gilles.dubochet@epfl.ch>2006-03-20 15:58:47 +0000
commit0a5eb2c599eead1eeba7559ed0dcc5706079bf4d (patch)
tree73c710573e7146cb6958e90f679ed35f51aaa740 /src/compiler
parentb656cd6c838b424ed2aa0cff746e3f49b9871dd0 (diff)
downloadscala-0a5eb2c599eead1eeba7559ed0dcc5706079bf4d.tar.gz
scala-0a5eb2c599eead1eeba7559ed0dcc5706079bf4d.tar.bz2
scala-0a5eb2c599eead1eeba7559ed0dcc5706079bf4d.zip
1.
2. ScalaTool Ant task updated to be more flexible. 3. Build now generates a separate archive for DBC (also changed in source layout).
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/ant/ScalaTool.scala125
-rw-r--r--src/compiler/scala/tools/ant/templates/generic-unix.tmpl85
-rw-r--r--src/compiler/scala/tools/ant/templates/int-unix.tmpl99
-rw-r--r--src/compiler/scala/tools/ant/templates/tool-unix.tmpl74
4 files changed, 137 insertions, 246 deletions
diff --git a/src/compiler/scala/tools/ant/ScalaTool.scala b/src/compiler/scala/tools/ant/ScalaTool.scala
index de130777ec..94ab2d9918 100644
--- a/src/compiler/scala/tools/ant/ScalaTool.scala
+++ b/src/compiler/scala/tools/ant/ScalaTool.scala
@@ -60,34 +60,34 @@ package scala.tools.ant {
/** The path to the exec script file. ".bat" will be appended for the
* Windows BAT file, if generated. */
private var file: Option[File] = None
- /** The name of this tool. By default this is equal to the file name. */
- private var name: Option[String] = None
- /** The main class to run. */
+ /** The main class to run. If this is not set, a generic script will be generated */
private var mainClass: Option[String] = None
+ /** The name of this tool. Can only be set when a main class is defined,
+ * default this is equal to the file name. */
+ private var name: Option[String] = None
/** Supported platforms for the script. Either "unix" or "windows". Defaults
* to both. */
private var platforms: List[String] = Nil
/** The optional version number. If set, when "-version" is passed to the
- * script, this value will be printed. */
+ * script, this value will be printed. */
private var version: String = ""
/** The optional copyright notice, that will be printed in the script. */
private var copyright: String = "This file is copyrighted by its owner"
/** An (optional) path to all JARs that this script depend on. Paths must be
* relative to the scala home directory. If not set, all JAR archives in
* "lib/" are automatically added. */
- private var classpath: List[String] = Nil
+ private var extclasspath: List[String] = Nil
/** Comma-separated Java system properties to pass to the JRE. Properties
- * are formated as name=value. Properties scala.home and scala.tool.name
- * are always set. */
+ * are formated as name=value. Properties scala.home, scala.class.path,
+ * scala.boot.class.path and scala.ext.class.path are always set;
+ * scala.tool.name and scala.tool.version are set when this script is
+ * non-generic. */
private var properties: List[Pair[String,String]] = Nil
/** Additional flags passed to the JRE ("java [javaFlags] class"). */
private var javaFlags: String = ""
- /** Additional flags passed to the tool ("java class [toolFlags]"). */
+ /** Additional flags passed to the tool ("java class [toolFlags]"). Can only
+ * be set when a main class is defined */
private var toolFlags: String = ""
- /** The path to the generic runtime script file. ".bat" will be appended for
- * the Windows BAT file, if generated. If not set, no generic runtime
- * script will be generated. */
- private var genericFile: Option[File] = None
/******************************************************************************\
** Properties setters **
@@ -132,10 +132,10 @@ package scala.tools.ant {
def setCopyright(input: String) =
copyright = input
- /** Sets the classpath attribute. Used by Ant.
+ /** Sets the extension classpath attribute. Used by Ant.
* @param input The value of <code>classpath</code>. */
- def setClasspath(input: String) =
- classpath = classpath ::: List.fromArray(input.split(":"))
+ def setExtclasspath(input: String) =
+ extclasspath = extclasspath ::: List.fromArray(input.split(":"))
/** Sets the properties attribute. Used by Ant.
* @param input The value for <code>properties</code>. */
@@ -158,11 +158,6 @@ package scala.tools.ant {
def setToolflags(input: String) =
toolFlags = input
- /** Sets the version attribute. Used by Ant.
- * @param input The value of <code>version</code>. */
- def setGenericfile(input: File) =
- genericFile = Some(input)
-
/******************************************************************************\
** Properties getters **
\******************************************************************************/
@@ -175,13 +170,13 @@ package scala.tools.ant {
/** Gets the value of the classpath attribute in a Scala-friendly form.
* @returns The class path as a list of files. */
- private def getUnixClasspath: String =
- classpath.mkString("", ":", "")
+ private def getUnixExtClasspath: String =
+ extclasspath.mkString("", ":", "")
/** Gets the value of the classpath attribute in a Scala-friendly form.
* @returns The class path as a list of files. */
- private def getWinClasspath: String =
- classpath.map(.replace('/', '\\')).
+ private def getWinExtClasspath: String =
+ extclasspath.map(.replace('/', '\\')).
mkString("", ";", "")
/** Gets the value of the classpath attribute in a Scala-friendly form.
@@ -191,12 +186,6 @@ package scala.tools.ant {
case Pair(name,value) => "-D" + name + "=\"" + value + "\""
}).mkString("", " ", "")
- /** Gets the value of the file attribute in a Scala-friendly form.
- * @returns The file as a file. */
- private def getGenericFile: File =
- if (genericFile.isEmpty) error("Member 'file' is empty.")
- else getProject().resolveFile(genericFile.get.toString())
-
/******************************************************************************\
** Compilation and support methods **
\******************************************************************************/
@@ -263,6 +252,24 @@ package scala.tools.ant {
replaceAll("#([^#]*)#", "%_$1%")
)
+ private def pipeTemplate(template: String, patches: Map[String,String]) = {
+ val resourceRoot = "scala/tools/ant/templates/"
+ if (platforms.contains("unix")) {
+ val unixPatches = expandUnixVar(patches.
+ update("extclasspath", getUnixExtClasspath))
+ val unixTemplateResource = resourceRoot + template + "-unix.tmpl"
+ val unixTemplate = readResource(unixTemplateResource, unixPatches)
+ writeFile(getFile, unixTemplate)
+ }
+ if (platforms.contains("windows")) {
+ val winPatches = expandWinVar(patches.
+ update("extclasspath", getWinExtClasspath))
+ val winTemplateResource = resourceRoot + template + "-windows.tmpl"
+ val winTemplate = readResource(winTemplateResource, winPatches)
+ writeFile(new File(getFile.getAbsolutePath() + ".bat"), winTemplate)
+ }
+ }
+
/******************************************************************************\
** The big execute method **
@@ -272,43 +279,29 @@ package scala.tools.ant {
override def execute() = {
// Tests if all mandatory attributes are set and valid.
if (file.isEmpty) error("Attribute 'file' is not set.")
- if (name.isEmpty) name = Some(file.get.getName())
- if (mainClass.isEmpty) error("Attribute 'mainclass' is not set.")
if (platforms.isEmpty) platforms = Platforms.values
- // Gets the input streams for the script templates.
- val resourceRoot = "scala/tools/ant/templates/"
- val patches = ListMap.Empty.
- update("name", name.get).
- update("class", mainClass.get).
- update("version", version).
- update("copyright", copyright).
- update("properties", getProperties).
- update("javaflags", javaFlags).
- update("toolflags", toolFlags)
- if (platforms.contains("unix")) {
- val unixPatches = expandUnixVar(
- patches.update("classpath", getUnixClasspath))
- val unixTemplateResource = resourceRoot + "tool-unix.tmpl"
- val unixTemplate = readResource(unixTemplateResource, unixPatches)
- writeFile(getFile, unixTemplate)
- if (!genericFile.isEmpty) {
- val unixTemplateResource = resourceRoot + "generic-unix.tmpl"
- val unixTemplate = readResource(unixTemplateResource, unixPatches)
- writeFile(getGenericFile, unixTemplate)
- }
- }
- if (platforms.contains("windows")) {
- val winPatches = expandWinVar(
- patches.update("classpath", getWinClasspath))
- val winTemplateResource = resourceRoot + "tool-windows.tmpl"
- val winTemplate = readResource(winTemplateResource, winPatches)
- writeFile(new File(getFile.getAbsolutePath() + ".bat"), winTemplate)
- if (!genericFile.isEmpty) {
- val winTemplateResource = resourceRoot + "generic-windows.tmpl"
- val winTemplate = readResource(winTemplateResource, winPatches)
- writeFile(new File(getGenericFile.getAbsolutePath() + ".bat"),
- winTemplate)
- }
+ if (mainClass.isEmpty) {
+ if (toolFlags != "")
+ error("Attribute 'toolflags' cannot be set in a generic file.")
+ if (!name.isEmpty)
+ error("Attribute 'name' cannot be set in a generic file.")
+ val patches = ListMap.Empty.
+ update("version", version).
+ update("copyright", copyright).
+ update("properties", getProperties).
+ update("javaflags", javaFlags)
+ pipeTemplate("generic", patches)
+ } else {
+ val patches = ListMap.Empty.
+ update("name", name.get).
+ update("class", mainClass.get).
+ update("version", version).
+ update("copyright", copyright).
+ update("properties", getProperties).
+ update("javaflags", javaFlags).
+ update("toolflags", toolFlags)
+ if (name.isEmpty) name = Some(file.get.getName())
+ pipeTemplate("tool", patches)
}
}
diff --git a/src/compiler/scala/tools/ant/templates/generic-unix.tmpl b/src/compiler/scala/tools/ant/templates/generic-unix.tmpl
index c06273c36e..e2c899682e 100644
--- a/src/compiler/scala/tools/ant/templates/generic-unix.tmpl
+++ b/src/compiler/scala/tools/ant/templates/generic-unix.tmpl
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
##############################################################################
# Scala runtime @version@
@@ -31,50 +31,58 @@ done;
SCALA_HOME=`dirname "$SOURCE"`/..;
SCALA_HOME=`cd "$SCALA_HOME"; pwd`;
-## buraq: previous version of this script computed the MYCLASSPATH and
-## then appended it to the bootclasspath. Unfortunately, this
-## won't work for library code that uses reflection to obtain
-## a class living on the classpath. For this reason, we have
-## to merge everything in the -cp classpath. This requires
-## intercepting the user's -cp, if any, or the user's $CLASSPATH,
-## if set, appending our libs to it and passing the whole thing by -cp
+EXTENSION_CLASSPATH="@extclasspath@"
+USER_CLASSPATH="."
+USER_ARGS=""
-MYCLASSPATH=@classpath@
-if [ "$MYCLASSPATH" == "" ] ; then
+if [ "$EXTENSION_CLASSPATH" == "" ] ; then
for jar in `ls $SCALA_HOME/lib/*.jar` ; do
- MYCLASSPATH="$MYCLASSPATH:$jar"
+ EXTENSION_CLASSPATH="$EXTENSION_CLASSPATH:$jar"
done
- MYCLASSPATH=${MYCLASSPATH:1}
+ EXTENSION_CLASSPATH=${EXTENSION_CLASSPATH:1}
fi
-QQ_USERCLASSPATH="."
-QQ_USERARGS=""
-QQ_NEXT=0
+if [ "$CLASSPATH" != "" ] ; then
+ USER_CLASSPATH="$CLASSPATH"
+fi
+
+QQ_CP_ARGUMENT=0
for i in $@@ ; do
- if [ $QQ_NEXT -eq 1 ] ; then
- QQ_USERCLASSPATH=$i
- QQ_NEXT=0
+ if [ "$QQ_CP_ARGUMENT" -eq 1 ] ; then
+ USER_CLASSPATH=$i
+ QQ_CP_ARGUMENT=0
else
if [[ $i = "-cp" || $i = "-classpath" ]] ; then
- QQ_NEXT=1
+ QQ_CP_ARGUMENT=1
else
- QQ_USERARGS="$QQ_USERARGS $i"
- QQ_NEXT=0
+ USER_ARGS="$USER_ARGS $i"
+ QQ_CP_ARGUMENT=0
fi
fi
done
-## Lex suggested the user classpath comes before
-## the Scala libraries, since it gets preferred.
-
-if [ "$QQ_USERCLASSPATH" != "." ] ; then
- MYCLASSPATH="$QQ_USERCLASSPATH:$MYCLASSPATH"
+MYCLASSPATH=""
+if [ "$EXTENSION_CLASSPATH" == "" ] ; then
+ MYCLASSPATH="$USER_CLASSPATH"
else
- if [ "$CLASSPATH" != "" ] ; then
- MYCLASSPATH="$CLASSPATH:$MYCLASSPATH"
+ if [ "$USER_CLASSPATH" == "" ] ; then
+ MYCLASSPATH="$EXTENSION_CLASSPATH"
else
- MYCLASSPATH=".:$MYCLASSPATH"
+ MYCLASSPATH="$USER_CLASSPATH:$EXTENSION_CLASSPATH"
+ fi
+fi
+
+for flag in "$@@" ; do
+ if [ "$flag" == '-version' ] ; then
+ echo "Scala runtime version @version@ -- @copyright@"
+ ${JAVACMD:=java} -version
+ exit 0
fi
+done
+
+BOOT_CLASSPATH=""
+if [ -f "$SCALA_HOME/lib/scala-library.jar" ] ; then
+ BOOT_CLASSPATH="$SCALA_HOME/lib/scala-library.jar"
fi
if $cygwin; then
@@ -83,17 +91,16 @@ if $cygwin; then
else
format=windows
fi
+ SCALA_HOME=`cygpath --$format "$SCALA_HOME"`
+ USER_CLASSPATH=`cygpath --path --$format "$USER_CLASSPATH"`
+ BOOT_CLASSPATH=`cygpath --path --$format "$BOOT_CLASSPATH"`
+ EXTENSION_CLASSPATH=`cygpath --path --$format "$EXTENSION_CLASSPATH"`
MYCLASSPATH=`cygpath --path --$format "$MYCLASSPATH"`
fi
-QQ_USERARGS="-cp $MYCLASSPATH $QQ_USERARGS"
-
-for flag in "$@@" ; do
- if [ "$flag" == '-version' ] ; then
- echo "Scala runtime version @version@ -- @copyright@"
- ${JAVACMD:=java} -version
- exit 0
- fi
-done
+QQ_BOOT_ARG=""
+if [ "$BOOT_CLASSPATH" != "" ] ; then
+ QQ_BOOT_ARG="-Xbootclasspath/a:$BOOT_CLASSPATH"
+fi
-${JAVACMD:=java} @javaflags@ $QQ_USERARGS
+${JAVACMD:=java} $QQ_BOOT_ARG @javaflags@ -cp "$MYCLASSPATH" -Dscala.home="$SCALA_HOME" -Dscala.class.path="$USER_CLASSPATH" -Dscala.boot.class.path="$BOOT_CLASSPATH" -Dscala.ext.path="$EXTENSION_CLASSPATH" @properties@ $USER_ARGS
diff --git a/src/compiler/scala/tools/ant/templates/int-unix.tmpl b/src/compiler/scala/tools/ant/templates/int-unix.tmpl
deleted file mode 100644
index 7a78d65258..0000000000
--- a/src/compiler/scala/tools/ant/templates/int-unix.tmpl
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/bin/bash
-
-##############################################################################
-# @name@ @version@
-##############################################################################
-# @copyright@
-# This is free software; see the distribution for copying conditions.
-# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE.
-##############################################################################
-
-cygwin=false;
-darwin=false;
-case "`uname`" in
- CYGWIN*) cygwin=true ;;
- Darwin*) darwin=true ;;
-esac
-
-SOURCE=$0;
-SCRIPT=`basename "$SOURCE"`;
-while [ -h "$SOURCE" ]; do
- SCRIPT=`basename "$SOURCE"`;
- LOOKUP=`ls -ld "$SOURCE"`;
- TARGET=`expr "$LOOKUP" : '.*-> \(.*\)$'`;
- if expr "${TARGET:-.}/" : '/.*/$' > /dev/null; then
- SOURCE=${TARGET:-.};
- else
- SOURCE=`dirname "$SOURCE"`/${TARGET:-.};
- fi;
-done;
-SCALA_HOME=`dirname "$SOURCE"`/..;
-SCALA_HOME=`cd "$SCALA_HOME"; pwd`;
-
-## buraq: previous version of this script computed the MYCLASSPATH and
-## then appended it to the bootclasspath. Unfortunately, this
-## won't work for library code that uses reflection to obtain
-## a class living on the classpath. For this reason, we have
-## to merge everything in the -cp classpath. This requires
-## intercepting the user's -cp, if any, or the user's $CLASSPATH,
-## if set, appending our libs to it and passing the whole thing by -cp
-
-MYCLASSPATH=@classpath@
-if [ "$MYCLASSPATH" == "" ] ; then
- for jar in `ls $SCALA_HOME/lib/*.jar` ; do
- MYCLASSPATH="$MYCLASSPATH:$jar"
- done
- MYCLASSPATH=${MYCLASSPATH:1}
-fi
-
-QQ_USERCLASSPATH="."
-QQ_USERARGS=""
-QQ_OTHER=""
-QQ_NEXT=0
-for i in $@@ ; do
- if [ $QQ_NEXT -eq 1 ] ; then
- QQ_USERCLASSPATH=$i
- QQ_NEXT=0
- else
- if [[ $i = "-cp" || $i = "-classpath" ]] ; then
- QQ_NEXT=1
- else
- QQ_OTHER="$QQ_OTHER $i"
- QQ_NEXT=0
- fi
- fi
-done
-
-## Lex suggested the user classpath comes before
-## the Scala libraries, since it gets preferred.
-
-if [ "$QQ_USERCLASSPATH" != "." ] ; then
- MYCLASSPATH="$QQ_USERCLASSPATH:$MYCLASSPATH"
-else
- if [ "$CLASSPATH" != "" ] ; then
- MYCLASSPATH="$CLASSPATH:$MYCLASSPATH"
- else
- MYCLASSPATH=".:$MYCLASSPATH"
- fi
-fi
-
-if $cygwin; then
- if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then
- format=mixed
- else
- format=windows
- fi
- MYCLASSPATH=`cygpath --path --$format "$MYCLASSPATH"`
-fi
-
-QQ_USERARGS="-cp $MYCLASSPATH $QQ_USERARGS"
-
-for flag in "$@@" ; do
- if [ "$flag" == '-version' ] ; then
- echo "@name@ version @version@ -- @copyright@"
- exit 0
- fi
-done
-
-${JAVACMD:=java} @javaflags@ -Dscala.home="$SCALA_HOME" -Dscala.tool.name="@name@" -Dscala.tool.version="@version@" @properties@ $QQ_USERARGS @class@ @toolflags@ $QQ_OTHER
diff --git a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
index d192198bad..3777c9bf89 100644
--- a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
+++ b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
##############################################################################
# @name@ @version@
@@ -31,51 +31,18 @@ done;
SCALA_HOME=`dirname "$SOURCE"`/..;
SCALA_HOME=`cd "$SCALA_HOME"; pwd`;
-## buraq: previous version of this script computed the MYCLASSPATH and
-## then appended it to the bootclasspath. Unfortunately, this
-## won't work for library code that uses reflection to obtain
-## a class living on the classpath. For this reason, we have
-## to merge everything in the -cp classpath. This requires
-## intercepting the user's -cp, if any, or the user's $CLASSPATH,
-## if set, appending our libs to it and passing the whole thing by -cp
+EXTENSION_CLASSPATH="@extclasspath@"
+BOOT_CLASSPATH="@bootclasspath@"
+USER_ARGS=""
-MYCLASSPATH=@classpath@
-if [ "$MYCLASSPATH" == "" ] ; then
+if [ "$EXTENSION_CLASSPATH" == "" ] ; then
for jar in `ls $SCALA_HOME/lib/*.jar` ; do
- MYCLASSPATH="$MYCLASSPATH:$jar"
+ EXTENSION_CLASSPATH="$EXTENSION_CLASSPATH:$jar"
done
- MYCLASSPATH=${MYCLASSPATH:1}
+ EXTENSION_CLASSPATH=${EXTENSION_CLASSPATH:1}
fi
-QQ_USERCLASSPATH="."
-QQ_USERARGS=""
-QQ_NEXT=0
-for i in $@@ ; do
- if [ $QQ_NEXT -eq 1 ] ; then
- QQ_USERCLASSPATH=$i
- QQ_NEXT=0
- else
- if [[ $i = "-cp" || $i = "-classpath" ]] ; then
- QQ_NEXT=1
- else
- QQ_USERARGS="$QQ_USERARGS $i"
- QQ_NEXT=0
- fi
- fi
-done
-
-## Lex suggested the user classpath comes before
-## the Scala libraries, since it gets preferred.
-
-if [ "$QQ_USERCLASSPATH" != "." ] ; then
- MYCLASSPATH="$QQ_USERCLASSPATH:$MYCLASSPATH"
-else
- if [ "$CLASSPATH" != "" ] ; then
- MYCLASSPATH="$CLASSPATH:$MYCLASSPATH"
- else
- MYCLASSPATH=".:$MYCLASSPATH"
- fi
-fi
+MYCLASSPATH="$EXTENSION_CLASSPATH"
if $cygwin; then
if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then
@@ -94,4 +61,27 @@ for flag in "$@@" ; do
fi
done
-${JAVACMD:=java} @javaflags@ -Dscala.home="$SCALA_HOME" -Dscala.tool.name="@name@" -Dscala.tool.version="@version@" @properties@ -cp $MYCLASSPATH @class@ @toolflags@ $QQ_USERARGS
+BOOT_CLASSPATH=""
+if [ -f "$SCALA_HOME/lib/scala-library.jar" ] ; then
+ BOOT_CLASSPATH="$SCALA_HOME/lib/scala-library.jar"
+fi
+
+if $cygwin; then
+ if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then
+ format=mixed
+ else
+ format=windows
+ fi
+ SCALA_HOME=`cygpath --$format "$SCALA_HOME"`
+ USER_CLASSPATH=`cygpath --path --$format "$USER_CLASSPATH"`
+ BOOT_CLASSPATH=`cygpath --path --$format "$BOOT_CLASSPATH"`
+ EXTENSION_CLASSPATH=`cygpath --path --$format "$EXTENSION_CLASSPATH"`
+ MYCLASSPATH=`cygpath --path --$format "$MYCLASSPATH"`
+fi
+
+QQ_BOOT_ARG=""
+if [ "$BOOT_CLASSPATH" != "" ] ; then
+ QQ_BOOT_ARG="-Xbootclasspath/a:$BOOT_CLASSPATH"
+fi
+
+${JAVACMD:=java} $QQ_BOOT_ARG @javaflags@ -cp "$MYCLASSPATH" -Dscala.home="$SCALA_HOME" -Dscala.class.path="$USER_CLASSPATH" -Dscala.boot.class.path="$BOOT_CLASSPATH" -Dscala.ext.path="$EXTENSION_CLASSPATH" -Dscala.tool.name="@name@" -Dscala.tool.version="@version@" @properties@ @class@ @toolflags@ $@@