@@ -9,7 +9,7 @@ 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 , AbstractFile }
12
+ import dotty .tools .io .AbstractFile
13
13
import reporting ._
14
14
import core .Decorators ._
15
15
import config .Feature
@@ -32,28 +32,11 @@ class Driver {
32
32
33
33
protected def emptyReporter : Reporter = new StoreReporter (null )
34
34
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 =
53
36
if files.nonEmpty then
54
37
try
55
38
val run = compiler.newRun
56
- run.compileFiles (files)
39
+ run.compile (files)
57
40
finish(compiler, run)
58
41
catch
59
42
case ex : FatalError =>
@@ -81,7 +64,7 @@ class Driver {
81
64
82
65
protected def sourcesRequired : Boolean = true
83
66
84
- def setup (args : Array [String ], rootCtx : Context ): (List [String ], Context ) = {
67
+ def setup (args : Array [String ], rootCtx : Context ): (List [AbstractFile ], Context ) = {
85
68
val ictx = rootCtx.fresh
86
69
val summary = CompilerCommand .distill(args)(using ictx)
87
70
ictx.setSettings(summary.sstate)
@@ -92,43 +75,37 @@ class Driver {
92
75
if ! ctx.settings.YdropComments .value || ctx.mode.is(Mode .ReadComments ) then
93
76
ictx.setProperty(ContextDoc , new ContextDocstrings )
94
77
val fileNames = CompilerCommand .checkUsage(summary, sourcesRequired)
95
- fromTastySetup(fileNames, ctx)
78
+ val files = fileNames.map(ctx.getFile)
79
+ (files, fromTastySetup(files))
96
80
}
97
81
}
98
82
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
118
99
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)
128
107
ctx1.setSetting(ctx1.settings.classpath, fullClassPath)
129
- (classNames, ctx1)
130
- }
131
- else (fileNames0, ctx0)
108
+ else ctx
132
109
133
110
/** Entry point to the compiler that can be conveniently used with Java reflection.
134
111
*
@@ -205,8 +182,8 @@ class Driver {
205
182
* if compilation succeeded.
206
183
*/
207
184
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)
210
187
}
211
188
212
189
def main (args : Array [String ]): Unit = {
0 commit comments