From 2b04d2a96100fad5fc88b78b6b4094ae6ae25a37 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 5 Apr 2017 00:10:30 +0200 Subject: Fix #2186: Synchronize classpath handling with Scala 2.12 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit is a very crude port of the classpath handling as it exists in the 2.12.x branch of scalac (hash: 232d95a198c94da0c6c8393624e83e9b9ac84e81), this replaces the existing Classpath code that was adapted from scalac years ago. This code was written by Grzegorz Kossakowski, MichaƂ Pociecha, Lukas Rytz, Jason Zaugg and other scalac contributors, many thanks to them! For more information on this implementation, see the description of the PR that originally added it to scalac: https://github.com/scala/scala/pull/4060 Changes made to the copied code to get it to compile with dotty: - Rename scala.tools.nsc.util.ClassPath to dotty.tools.io.ClassPath - Rename scala.tools.nsc.classpath.* to dotty.tools.dotc.classpath.* - Replace "private[nsc]" by "private[dotty]" - Changed `isClass` methods in FileUtils to skip Scala 2.11 implementation classes (needed until we stop being retro-compatible with Scala 2.11) I also copied PlainFile.scala from scalac to get access to `PlainNioFile`. --- .../src/dotty/tools/dotc/config/PathResolver.scala | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'compiler/src/dotty/tools/dotc/config/PathResolver.scala') diff --git a/compiler/src/dotty/tools/dotc/config/PathResolver.scala b/compiler/src/dotty/tools/dotc/config/PathResolver.scala index 159989e6f..f0709f4d3 100644 --- a/compiler/src/dotty/tools/dotc/config/PathResolver.scala +++ b/compiler/src/dotty/tools/dotc/config/PathResolver.scala @@ -4,8 +4,9 @@ package config import java.net.{ URL, MalformedURLException } import WrappedProperties.AccessControl -import io.{ ClassPath, JavaClassPath, File, Directory, Path, AbstractFile } -import ClassPath.{ JavaContext, DefaultJavaContext, join, split } +import io.{ ClassPath, File, Directory, Path, AbstractFile } +import classpath.{AggregateClassPath, ClassPathFactory } +import ClassPath.{ JavaContext, join, split } import PartialFunction.condOpt import scala.language.postfixOps import core.Contexts._ @@ -128,7 +129,7 @@ object PathResolver { ) } - def fromPathString(path: String)(implicit ctx: Context): JavaClassPath = { + def fromPathString(path: String)(implicit ctx: Context): ClassPath = { val settings = ctx.settings.classpath.update(path) new PathResolver()(ctx.fresh.setSettings(settings)).result } @@ -150,7 +151,11 @@ object PathResolver { val pr = new PathResolver()(ctx.fresh.setSettings(sstate)) println(" COMMAND: 'scala %s'".format(args.mkString(" "))) println("RESIDUAL: 'scala %s'\n".format(rest.mkString(" "))) - pr.result.show + + pr.result match { + case cp: AggregateClassPath => + println(s"ClassPath has ${cp.aggregates.size} entries and results in:\n${cp.asClassPathStrings}") + } } } } @@ -159,7 +164,7 @@ import PathResolver.{ Defaults, Environment, firstNonEmpty, ppcp } class PathResolver(implicit ctx: Context) { import ctx.base.settings - val context = ClassPath.DefaultJavaContext + private val classPathFactory = new ClassPathFactory private def cmdLineOrElse(name: String, alt: String) = { (commandLineFor(name) match { @@ -214,7 +219,7 @@ class PathResolver(implicit ctx: Context) { else sys.env.getOrElse("CLASSPATH", ".") } - import context._ + import classPathFactory._ // Assemble the elements! // priority class path takes precedence @@ -254,8 +259,8 @@ class PathResolver(implicit ctx: Context) { def containers = Calculated.containers - lazy val result: JavaClassPath = { - val cp = new JavaClassPath(containers.toIndexedSeq, context) + lazy val result: ClassPath = { + val cp = AggregateClassPath(containers.toIndexedSeq) if (settings.Ylogcp.value) { Console.println("Classpath built from " + settings.toConciseString(ctx.sstate)) -- cgit v1.2.3