@@ -101,7 +101,7 @@ fun main(args: Array<String>) {
101101 val nonGlobalDirectives = executeGlobalDirectives(globalDirectiveFunctions,
102102 configDirectives, userArgs)
103103
104- val runtimes = configureRuntimes(config, configDir, hints, vars)
104+ val runtimes = configureRuntimes(config, configDir, configDirectives, launchDirectives, hints, vars)
105105
106106 debugBanner(" BUILDING ARGUMENT LISTS" )
107107
@@ -377,6 +377,8 @@ private fun applyModeHints(
377377private fun configureRuntimes (
378378 config : JaunchConfig ,
379379 configDir : File ,
380+ configDirectives : List <String >,
381+ launchDirectives : List <String >,
380382 hints : MutableSet <String >,
381383 vars : Vars
382384): List <RuntimeConfig > {
@@ -385,10 +387,34 @@ private fun configureRuntimes(
385387 if (config.jvmEnabled == true ) runtimes + = JvmRuntimeConfig (config.jvmRecognizedArgs)
386388 if (config.pythonEnabled == true ) runtimes + = PythonRuntimeConfig (config.pythonRecognizedArgs)
387389
388- // Discover the runtime installations.
390+ // Discover the runtime installations - but only for runtimes that are actually needed.
391+ for (r in runtimes) {
392+ // Check if this runtime will be used for any launch or config directives.
393+ if (
394+ r.directive in launchDirectives ||
395+ configDirectives.any { r.supportedDirectives.containsKey(it) }
396+ ) {
397+ debugBanner(" CONFIGURING RUNTIME: ${r.directive} " )
398+ r.configure(configDir, config, hints, vars)
399+ }
400+ else {
401+ debugBanner(" SKIPPING DORMANT RUNTIME: ${r.directive} " )
402+ }
403+ }
404+
405+ // Now configure any runtimes that are DEPENDENCIES of the now-configured ones.
389406 for (r in runtimes) {
390- debugBanner(" CONFIGURING RUNTIME: ${r.directive} " )
391- r.configure(configDir, config, hints, vars)
407+ if (r.configured) continue
408+ val needed = runtimes.any { active ->
409+ active.configured && active.dependsOn(r, config)
410+ }
411+ if (needed) {
412+ debugBanner(" CONFIGURING RUNTIME DEPENDENCY: ${r.directive} " )
413+ r.configure(configDir, config, hints, vars)
414+ }
415+ else {
416+ debugBanner(" SKIPPING UNNEEDED RUNTIME: ${r.directive} " )
417+ }
392418 }
393419
394420 return runtimes
0 commit comments