@@ -9,10 +9,11 @@ import core.Contexts._
9
9
import core .{MacroClassLoader , Mode , TypeError }
10
10
import core .StdNames .nme
11
11
import dotty .tools .dotc .ast .Positioned
12
- import dotty .tools .io .File
12
+ import dotty .tools .io .AbstractFile
13
13
import reporting ._
14
14
import core .Decorators ._
15
15
import config .Feature
16
+ import util .SourceFile
16
17
17
18
import scala .util .control .NonFatal
18
19
import fromtasty .{TASTYCompiler , TastyFileUtil }
@@ -31,41 +32,39 @@ class Driver {
31
32
32
33
protected def emptyReporter : Reporter = new StoreReporter (null )
33
34
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
36
37
try
37
38
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)
52
41
catch
53
- case ex : FatalError =>
42
+ case ex : FatalError =>
54
43
report.error(ex.getMessage) // signals that we should fail compilation.
55
44
case ex : TypeError =>
56
- println(s " ${ex.toMessage} while compiling ${fileNames .mkString(" , " )}" )
45
+ println(s " ${ex.toMessage} while compiling ${files.map(_.path) .mkString(" , " )}" )
57
46
throw ex
58
47
case ex : Throwable =>
59
- println(s " $ex while compiling ${fileNames .mkString(" , " )}" )
48
+ println(s " $ex while compiling ${files.map(_.path) .mkString(" , " )}" )
60
49
throw ex
61
50
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))
63
62
64
63
protected def initCtx : Context = (new ContextBase ).initialCtx
65
64
66
65
protected def sourcesRequired : Boolean = true
67
66
68
- def setup (args : Array [String ], rootCtx : Context ): (List [String ], Context ) = {
67
+ def setup (args : Array [String ], rootCtx : Context ): (List [AbstractFile ], Context ) = {
69
68
val ictx = rootCtx.fresh
70
69
val summary = CompilerCommand .distill(args)(using ictx)
71
70
ictx.setSettings(summary.sstate)
@@ -76,43 +75,37 @@ class Driver {
76
75
if ! ctx.settings.YdropComments .value || ctx.mode.is(Mode .ReadComments ) then
77
76
ictx.setProperty(ContextDoc , new ContextDocstrings )
78
77
val fileNames = CompilerCommand .checkUsage(summary, sourcesRequired)
79
- fromTastySetup(fileNames, ctx)
78
+ val files = fileNames.map(ctx.getFile)
79
+ (files, fromTastySetup(files))
80
80
}
81
81
}
82
82
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
102
99
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)
112
107
ctx1.setSetting(ctx1.settings.classpath, fullClassPath)
113
- (classNames, ctx1)
114
- }
115
- else (fileNames0, ctx0)
108
+ else ctx
116
109
117
110
/** Entry point to the compiler that can be conveniently used with Java reflection.
118
111
*
@@ -189,8 +182,8 @@ class Driver {
189
182
* if compilation succeeded.
190
183
*/
191
184
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)
194
187
}
195
188
196
189
def main (args : Array [String ]): Unit = {
0 commit comments