@@ -9,7 +9,7 @@ import core.Contexts._
99import core .{MacroClassLoader , Mode , TypeError }
1010import core .StdNames .nme
1111import dotty .tools .dotc .ast .Positioned
12- import dotty .tools .io .{ File , AbstractFile }
12+ import dotty .tools .io .AbstractFile
1313import reporting ._
1414import core .Decorators ._
1515import config .Feature
@@ -32,28 +32,11 @@ class Driver {
3232
3333 protected def emptyReporter : Reporter = new StoreReporter (null )
3434
35- protected def doCompile (compiler : Compiler , fileNames : List [String ])(using ctx : Context ): Reporter =
36- if fileNames.nonEmpty then
37- try
38- val run = compiler.newRun
39- run.compile(fileNames)
40- finish(compiler, run)
41- catch
42- case ex : FatalError =>
43- report.error(ex.getMessage) // signals that we should fail compilation.
44- case ex : TypeError =>
45- println(s " ${ex.toMessage} while compiling ${fileNames.mkString(" , " )}" )
46- throw ex
47- case ex : Throwable =>
48- println(s " $ex while compiling ${fileNames.mkString(" , " )}" )
49- throw ex
50- ctx.reporter
51-
52- protected def doCompileFiles (compiler : Compiler , files : List [AbstractFile ])(using Context ): Reporter =
35+ protected def doCompile (compiler : Compiler , files : List [AbstractFile ])(using Context ): Reporter =
5336 if files.nonEmpty then
5437 try
5538 val run = compiler.newRun
56- run.compileFiles (files)
39+ run.compile (files)
5740 finish(compiler, run)
5841 catch
5942 case ex : FatalError =>
@@ -81,7 +64,7 @@ class Driver {
8164
8265 protected def sourcesRequired : Boolean = true
8366
84- def setup (args : Array [String ], rootCtx : Context ): (List [String ], Context ) = {
67+ def setup (args : Array [String ], rootCtx : Context ): (List [AbstractFile ], Context ) = {
8568 val ictx = rootCtx.fresh
8669 val summary = CompilerCommand .distill(args)(using ictx)
8770 ictx.setSettings(summary.sstate)
@@ -92,43 +75,37 @@ class Driver {
9275 if ! ctx.settings.YdropComments .value || ctx.mode.is(Mode .ReadComments ) then
9376 ictx.setProperty(ContextDoc , new ContextDocstrings )
9477 val fileNames = CompilerCommand .checkUsage(summary, sourcesRequired)
95- fromTastySetup(fileNames, ctx)
78+ val files = fileNames.map(ctx.getFile)
79+ (files, fromTastySetup(files))
9680 }
9781 }
9882
99- /** Setup extra classpath and figure out class names for tasty file inputs */
100- protected def fromTastySetup (fileNames0 : List [String ], ctx0 : Context ): (List [String ], Context ) =
101- given Context = ctx0
102- if (ctx0.settings.fromTasty.value) {
103- val fromTastyIgnoreList = ctx0.settings.YfromTastyIgnoreList .value.toSet
104- // Resolve classpath and class names of tasty files
105- val (classPaths, classNames) = fileNames0.flatMap { name =>
106- val path = Paths .get(name)
107- if ! Files .exists(path) then
108- report.error(s " File does not exist: $name" )
109- Nil
110- else if name.endsWith(" .jar" ) then
111- new dotty.tools.io.Jar (File (name)).toList.collect {
112- case e if e.getName.endsWith(" .tasty" ) && ! fromTastyIgnoreList(e.getName) =>
113- (name, e.getName.stripSuffix(" .tasty" ).replace(" /" , " ." ))
114- }
115- else if name.endsWith(" .tasty" ) then
116- TastyFileUtil .getClassName(path) match
117- 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
11899 case _ =>
119- report.error(s " Could not load classname from: $name" )
120- Nil
121- else
122- report.error(s " File extension is not `tasty` or `jar`: $name" )
123- Nil
124- }.unzip
125- val ctx1 = ctx0.fresh
126- val classPaths1 = classPaths.distinct.filter(_ != " " )
127- 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)
128107 ctx1.setSetting(ctx1.settings.classpath, fullClassPath)
129- (classNames, ctx1)
130- }
131- else (fileNames0, ctx0)
108+ else ctx
132109
133110 /** Entry point to the compiler that can be conveniently used with Java reflection.
134111 *
@@ -205,8 +182,8 @@ class Driver {
205182 * if compilation succeeded.
206183 */
207184 def process (args : Array [String ], rootCtx : Context ): Reporter = {
208- val (fileNames , compileCtx) = setup(args, rootCtx)
209- doCompile(newCompiler(using compileCtx), fileNames )(using compileCtx)
185+ val (files , compileCtx) = setup(args, rootCtx)
186+ doCompile(newCompiler(using compileCtx), files )(using compileCtx)
210187 }
211188
212189 def main (args : Array [String ]): Unit = {
0 commit comments