@@ -66,10 +66,16 @@ class Driver {
6666
6767 protected def command : CompilerCommand = ScalacCommand
6868
69- def setup (args : Array [String ], rootCtx : Context ): (Option [List [AbstractFile ]], Context ) = {
69+ /** Setup context with initialized settings from CLI arguments, then check if there are any settings that
70+ * would change the default behaviour of the compiler.
71+ *
72+ * @return If there is no setting like `-help` preventing us from continuing compilation,
73+ * this method returns a list of files to compile and an updated Context.
74+ * If compilation should be interrupted, this method returns None.
75+ */
76+ def setup (args : Array [String ], rootCtx : Context ): Option [(List [AbstractFile ], Context )] = {
7077 val ictx = rootCtx.fresh
71- val settings = config.ScalaSettings ()
72- val summary = command.distill(args, settings, settings.defaultState)
78+ val summary = command.distill(args, ictx.settings)(ictx.settingsState)(using ictx)
7379 ictx.setSettings(summary.sstate)
7480 MacroClassLoader .init(ictx)
7581 Positioned .init(using ictx)
@@ -78,9 +84,9 @@ class Driver {
7884 if ! ctx.settings.YdropComments .value || ctx.mode.is(Mode .ReadComments ) then
7985 ictx.setProperty(ContextDoc , new ContextDocstrings )
8086 val fileNamesOrNone = command.checkUsage(summary, sourcesRequired)(using ctx.settings)(using ctx.settingsState)
81- fileNamesOrNone.fold(( None , ictx)) { fileNames =>
87+ fileNamesOrNone.map { fileNames =>
8288 val files = fileNames.map(ctx.getFile)
83- (Some ( files) , fromTastySetup(files))
89+ (files, fromTastySetup(files))
8490 }
8591 }
8692 }
@@ -187,10 +193,11 @@ class Driver {
187193 * if compilation succeeded.
188194 */
189195 def process (args : Array [String ], rootCtx : Context ): Reporter = {
190- val (files, compileCtx) = setup(args, rootCtx)
191- files.fold(compileCtx.reporter) {
192- doCompile(newCompiler(using compileCtx), _)(using compileCtx)
193- }
196+ setup(args, rootCtx) match
197+ case Some ((files, compileCtx)) =>
198+ doCompile(newCompiler(using compileCtx), files)(using compileCtx)
199+ case None =>
200+ rootCtx.reporter
194201 }
195202
196203 def main (args : Array [String ]): Unit = {
0 commit comments