diff options
author | Paul Phillips <paulp@improving.org> | 2011-08-06 13:08:36 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-08-06 13:08:36 +0000 |
commit | 6d45fddd4c6537fb343e901d58491b81475e3786 (patch) | |
tree | bf6fd74702f2c47c4a31f9917d43d955506be9b3 | |
parent | 8709b52eef9a0c0b2600664e38e01af3423e93f6 (diff) | |
download | scala-6d45fddd4c6537fb343e901d58491b81475e3786.tar.gz scala-6d45fddd4c6537fb343e901d58491b81475e3786.tar.bz2 scala-6d45fddd4c6537fb343e901d58491b81475e3786.zip |
Attacked classpaths to get "." off of it when i...
Attacked classpaths to get "." off of it when it's not actually
specified. The commit makes me nervous, but there's no invisible way to
fix something like this.
** Attention, this commit changes classpath handling **
We desperately need some way of testing that the classpath has certain
qualities and does not have others; partest is not that way. Closes
SI-4857, no review.
-rw-r--r-- | src/compiler/scala/tools/ant/templates/tool-unix.tmpl | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/GenericRunnerCommand.scala | 5 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/MainGenericRunner.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/settings/ScalaSettings.scala | 14 | ||||
-rw-r--r-- | src/compiler/scala/tools/util/PathResolver.scala | 26 | ||||
-rw-r--r-- | test/pending/neg/dot-classpath.flags | 1 | ||||
-rw-r--r-- | test/pending/neg/dot-classpath/S_1.scala | 3 | ||||
-rw-r--r-- | test/pending/neg/dot-classpath/S_2.scala | 3 |
8 files changed, 44 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl index a3dc58263b..354a8c3644 100644 --- a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl +++ b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl @@ -154,7 +154,7 @@ fi $JAVA_OPTS \ "${java_args[@@]}" \ ${CPSELECT}${TOOL_CLASSPATH} \ - -Dscala.usejavacp=true \ + -Dscala.usejavacp=false \ -Dscala.home="$SCALA_HOME" \ -Denv.emacs="$EMACS" \ $CYGWIN_JLINE_TERMINAL \ diff --git a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala index 27596dc899..836d22192c 100644 --- a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala +++ b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala @@ -35,7 +35,10 @@ extends CompilerCommand(args, settings) { else { val f = io.File(target) if (!f.hasExtension("class", "jar", "zip") && f.canRead) AsScript - else sys.error("Cannot figure out how to run target: " + target) + else { + Console.err.println("No such file or class on classpath: " + target) + Error + } } } /** String with either the jar file, class name, or script file name. */ diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala index f2d4bacb35..d11c91a092 100644 --- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala +++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala @@ -25,7 +25,7 @@ class MainGenericRunner { false } def errorFn(str: String): Boolean = { - Console println str + Console.err println str false } @@ -62,6 +62,8 @@ class MainGenericRunner { new io.Jar(thingToRun).mainClass getOrElse sys.error("Cannot find main class for jar: " + thingToRun), command.arguments ) + case Error => + Right(false) case _ => // We start the repl when no arguments are given. Right(new ILoop process settings) diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index 2e7cb9595a..e0366f1e3d 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -17,11 +17,19 @@ trait ScalaSettings extends AbsScalaSettings with Warnings { self: MutableSettings => - import Defaults.scalaUserClassPath - /** Set of settings */ protected lazy val allSettings = mutable.HashSet[Setting]() + /** Against my better judgment, giving in to martin here and allowing + * CLASSPATH to be used automatically. So for the user-specified part + * of the classpath: + * + * - If -classpath or -cp is given, it is that + * - Otherwise, if CLASSPATH is set, it is that + * - If neither of those, then "." is used. + */ + protected def defaultClasspath = Option(sys.props("CLASSPATH")) getOrElse "." + /** Disable a setting */ def disable(s: Setting) = allSettings -= s @@ -35,7 +43,7 @@ trait ScalaSettings extends AbsScalaSettings */ // argfiles is only for the help message val argfiles = BooleanSetting ("@<file>", "A text file containing compiler arguments (options and source files)") - val classpath = PathSetting ("-classpath", "Specify where to find user class files.", scalaUserClassPath) . + val classpath = PathSetting ("-classpath", "Specify where to find user class files.", defaultClasspath) . withAbbreviation ("-cp") val d = OutputSetting (outputDirs, ".") val optimise = BooleanSetting ("-optimise", "Generates faster bytecode by applying optimisations to the program") . diff --git a/src/compiler/scala/tools/util/PathResolver.scala b/src/compiler/scala/tools/util/PathResolver.scala index 347e900886..3ea5aa1703 100644 --- a/src/compiler/scala/tools/util/PathResolver.scala +++ b/src/compiler/scala/tools/util/PathResolver.scala @@ -74,13 +74,7 @@ object PathResolver { * to the path resolution specification. */ object Defaults { - /* Against my better judgment, giving in to martin here and allowing - * CLASSPATH as the default if no -cp is given. Only if there is no - * command line option or environment variable is "." used. - */ - def scalaUserClassPath = firstNonEmpty(Environment.classPathEnv, ".") - def scalaSourcePath = Environment.sourcePathEnv - + def scalaSourcePath = Environment.sourcePathEnv def javaBootClassPath = Environment.javaBootClassPath def javaUserClassPath = Environment.javaUserClassPath def javaExtDirs = Environment.javaExtDirs @@ -195,9 +189,25 @@ class PathResolver(settings: Settings, context: JavaContext) { def javaUserClassPath = if (useJavaClassPath) Defaults.javaUserClassPath else "" def scalaBootClassPath = cmdLineOrElse("bootclasspath", Defaults.scalaBootClassPath) def scalaExtDirs = cmdLineOrElse("extdirs", Defaults.scalaExtDirs) - def userClassPath = cmdLineOrElse("classpath", Defaults.scalaUserClassPath) def sourcePath = cmdLineOrElse("sourcepath", Defaults.scalaSourcePath) + /** Against my better judgment, giving in to martin here and allowing + * CLASSPATH to be used automatically. So for the user-specified part + * of the classpath: + * + * - If -classpath or -cp is given, it is that + * - Otherwise, if CLASSPATH is set, it is that + * - If neither of those, then "." is used. + */ + def userClassPath = ( + if (!settings.classpath.isDefault) + settings.classpath.value + else sys.props("CLASSPATH") match { + case null => "." + case cp => cp + } + ) + import context._ // Assemble the elements! diff --git a/test/pending/neg/dot-classpath.flags b/test/pending/neg/dot-classpath.flags new file mode 100644 index 0000000000..5af7a81156 --- /dev/null +++ b/test/pending/neg/dot-classpath.flags @@ -0,0 +1 @@ +-Ylog-classpath
\ No newline at end of file diff --git a/test/pending/neg/dot-classpath/S_1.scala b/test/pending/neg/dot-classpath/S_1.scala new file mode 100644 index 0000000000..f8bd12404c --- /dev/null +++ b/test/pending/neg/dot-classpath/S_1.scala @@ -0,0 +1,3 @@ +package foo { + class Bippy +} diff --git a/test/pending/neg/dot-classpath/S_2.scala b/test/pending/neg/dot-classpath/S_2.scala new file mode 100644 index 0000000000..e44c1a5bb8 --- /dev/null +++ b/test/pending/neg/dot-classpath/S_2.scala @@ -0,0 +1,3 @@ +class A { + def f = new foo.Bippy +}
\ No newline at end of file |