@@ -9,10 +9,11 @@ import core.Contexts._
99import core .{MacroClassLoader , Mode , TypeError }
1010import core .StdNames .nme
1111import dotty .tools .dotc .ast .Positioned
12- import dotty .tools .io .File
12+ import dotty .tools .io .AbstractFile
1313import reporting ._
1414import core .Decorators ._
1515import config .Feature
16+ import util .SourceFile
1617
1718import scala .util .control .NonFatal
1819import fromtasty .{TASTYCompiler , TastyFileUtil }
@@ -31,41 +32,39 @@ class Driver {
3132
3233 protected def emptyReporter : Reporter = new StoreReporter (null )
3334
34- protected def doCompile (compiler : Compiler , fileNames : List [String ])(using Context ): Reporter =
35- if (fileNames .nonEmpty)
35+ protected def doCompile (compiler : Compiler , files : List [AbstractFile ])(using Context ): Reporter =
36+ if files .nonEmpty then
3637 try
3738 val run = compiler.newRun
38- run.compile(fileNames)
39-
40- def finish (run : Run )(using Context ): Unit =
41- run.printSummary()
42- if ! ctx.reporter.errorsReported && run.suspendedUnits.nonEmpty then
43- val suspendedUnits = run.suspendedUnits.toList
44- if (ctx.settings.XprintSuspension .value)
45- report.echo(i " compiling suspended $suspendedUnits%, % " )
46- val run1 = compiler.newRun
47- for unit <- suspendedUnits do unit.suspended = false
48- run1.compileUnits(suspendedUnits)
49- finish(run1)(using MacroClassLoader .init(ctx.fresh))
50-
51- finish(run)
39+ run.compile(files)
40+ finish(compiler, run)
5241 catch
53- case ex : FatalError =>
42+ case ex : FatalError =>
5443 report.error(ex.getMessage) // signals that we should fail compilation.
5544 case ex : TypeError =>
56- println(s " ${ex.toMessage} while compiling ${fileNames .mkString(" , " )}" )
45+ println(s " ${ex.toMessage} while compiling ${files.map(_.path) .mkString(" , " )}" )
5746 throw ex
5847 case ex : Throwable =>
59- println(s " $ex while compiling ${fileNames .mkString(" , " )}" )
48+ println(s " $ex while compiling ${files.map(_.path) .mkString(" , " )}" )
6049 throw ex
6150 ctx.reporter
62- end doCompile
51+
52+ protected def finish (compiler : Compiler , run : Run )(using Context ): Unit =
53+ run.printSummary()
54+ if ! ctx.reporter.errorsReported && run.suspendedUnits.nonEmpty then
55+ val suspendedUnits = run.suspendedUnits.toList
56+ if (ctx.settings.XprintSuspension .value)
57+ report.echo(i " compiling suspended $suspendedUnits%, % " )
58+ val run1 = compiler.newRun
59+ for unit <- suspendedUnits do unit.suspended = false
60+ run1.compileUnits(suspendedUnits)
61+ finish(compiler, run1)(using MacroClassLoader .init(ctx.fresh))
6362
6463 protected def initCtx : Context = (new ContextBase ).initialCtx
6564
6665 protected def sourcesRequired : Boolean = true
6766
68- def setup (args : Array [String ], rootCtx : Context ): (List [String ], Context ) = {
67+ def setup (args : Array [String ], rootCtx : Context ): (List [AbstractFile ], Context ) = {
6968 val ictx = rootCtx.fresh
7069 val summary = CompilerCommand .distill(args)(using ictx)
7170 ictx.setSettings(summary.sstate)
@@ -76,43 +75,37 @@ class Driver {
7675 if ! ctx.settings.YdropComments .value || ctx.mode.is(Mode .ReadComments ) then
7776 ictx.setProperty(ContextDoc , new ContextDocstrings )
7877 val fileNames = CompilerCommand .checkUsage(summary, sourcesRequired)
79- fromTastySetup(fileNames, ctx)
78+ val files = fileNames.map(ctx.getFile)
79+ (files, fromTastySetup(files))
8080 }
8181 }
8282
83- /** Setup extra classpath and figure out class names for tasty file inputs */
84- protected def fromTastySetup (fileNames0 : List [String ], ctx0 : Context ): (List [String ], Context ) =
85- given Context = ctx0
86- if (ctx0.settings.fromTasty.value) {
87- val fromTastyIgnoreList = ctx0.settings.YfromTastyIgnoreList .value.toSet
88- // Resolve classpath and class names of tasty files
89- val (classPaths, classNames) = fileNames0.flatMap { name =>
90- val path = Paths .get(name)
91- if ! Files .exists(path) then
92- report.error(s " File does not exist: $name" )
93- Nil
94- else if name.endsWith(" .jar" ) then
95- new dotty.tools.io.Jar (File (name)).toList.collect {
96- case e if e.getName.endsWith(" .tasty" ) && ! fromTastyIgnoreList(e.getName) =>
97- (name, e.getName.stripSuffix(" .tasty" ).replace(" /" , " ." ))
98- }
99- else if name.endsWith(" .tasty" ) then
100- TastyFileUtil .getClassName(path) match
101- case Some (res) => res :: Nil
83+ /** Setup extra classpath of tasty and jar files */
84+ protected def fromTastySetup (files : List [AbstractFile ])(using Context ): Context =
85+ if ctx.settings.fromTasty.value then
86+ val newEntries : List [String ] = files
87+ .flatMap { file =>
88+ if ! file.exists then
89+ report.error(s " File does not exist: ${file.path}" )
90+ None
91+ else file.extension match
92+ case " jar" => Some (file.path)
93+ case " tasty" =>
94+ TastyFileUtil .getClassPath(file) match
95+ case Some (classpath) => Some (classpath)
96+ case _ =>
97+ report.error(s " Could not load classname from: ${file.path}" )
98+ None
10299 case _ =>
103- report.error(s " Could not load classname from: $name" )
104- Nil
105- else
106- report.error(s " File extension is not `tasty` or `jar`: $name" )
107- Nil
108- }.unzip
109- val ctx1 = ctx0.fresh
110- val classPaths1 = classPaths.distinct.filter(_ != " " )
111- val fullClassPath = (classPaths1 :+ ctx1.settings.classpath.value(using ctx1)).mkString(java.io.File .pathSeparator)
100+ report.error(s " File extension is not `tasty` or `jar`: ${file.path}" )
101+ None
102+ }
103+ .distinct
104+ val ctx1 = ctx.fresh
105+ val fullClassPath =
106+ (newEntries :+ ctx.settings.classpath.value).mkString(java.io.File .pathSeparator)
112107 ctx1.setSetting(ctx1.settings.classpath, fullClassPath)
113- (classNames, ctx1)
114- }
115- else (fileNames0, ctx0)
108+ else ctx
116109
117110 /** Entry point to the compiler that can be conveniently used with Java reflection.
118111 *
@@ -189,8 +182,8 @@ class Driver {
189182 * if compilation succeeded.
190183 */
191184 def process (args : Array [String ], rootCtx : Context ): Reporter = {
192- val (fileNames , compileCtx) = setup(args, rootCtx)
193- doCompile(newCompiler(using compileCtx), fileNames )(using compileCtx)
185+ val (files , compileCtx) = setup(args, rootCtx)
186+ doCompile(newCompiler(using compileCtx), files )(using compileCtx)
194187 }
195188
196189 def main (args : Array [String ]): Unit = {
0 commit comments