@@ -89,6 +89,7 @@ public static void main(String[] args) {
89
89
private static long startupWallClockTime = -1 ;
90
90
private static long startupNanoTime = -1 ;
91
91
92
+ private boolean verboseLauncher = false ;
92
93
private ArrayList <String > programArgs = null ;
93
94
private ArrayList <String > origArgs = null ;
94
95
private String commandString = null ;
@@ -116,6 +117,10 @@ public static void main(String[] args) {
116
117
private String checkHashPycsMode = "default" ;
117
118
private String execName ;
118
119
120
+ public GraalPythonMain () {
121
+ verboseLauncher = Boolean .parseBoolean (System .getenv ("VERBOSE_GRAALVM_LAUNCHERS" ));
122
+ }
123
+
119
124
protected static void setStartupTime () {
120
125
if (GraalPythonMain .startupNanoTime == -1 ) {
121
126
GraalPythonMain .startupNanoTime = System .nanoTime ();
@@ -480,10 +485,12 @@ protected String getLauncherExecName() {
480
485
return execName ;
481
486
}
482
487
execName = getProgramName ();
488
+ log ("initial executable name: " , execName );
483
489
if (execName == null ) {
484
490
return null ;
485
491
}
486
492
execName = calculateProgramFullPath (execName );
493
+ log ("resolved executable name: " , execName );
487
494
return execName ;
488
495
}
489
496
@@ -505,7 +512,7 @@ protected String getLauncherExecName() {
505
512
* @param program The program name as passed in the process' argument vector (position 0).
506
513
* @return The absolute path to the program or {@code null}.
507
514
*/
508
- private static String calculateProgramFullPath (String program ) {
515
+ private String calculateProgramFullPath (String program ) {
509
516
Path programPath = Paths .get (program );
510
517
511
518
// If this is an absolute path, we are already fine.
@@ -522,9 +529,11 @@ private static String calculateProgramFullPath(String program) {
522
529
// Resolve the program name with respect to the PATH variable.
523
530
String path = getEnv ("PATH" );
524
531
if (path != null ) {
532
+ log ("resolving the executable name in $PATH = " , path );
525
533
int last = 0 ;
526
534
for (int i = path .indexOf (File .pathSeparatorChar ); i != -1 ; i = path .indexOf (File .pathSeparatorChar , last )) {
527
535
Path resolvedProgramName = Paths .get (path .substring (last , i )).resolve (programPath );
536
+ log ("checking if exists and is executable: " , resolvedProgramName );
528
537
if (Files .isExecutable (resolvedProgramName )) {
529
538
return resolvedProgramName .toString ();
530
539
}
@@ -533,6 +542,8 @@ private static String calculateProgramFullPath(String program) {
533
542
// 'i' points to ':'
534
543
last = i + 1 ;
535
544
}
545
+ } else {
546
+ log ("executable name looks like it is from $PATH, but $PATH is not available." );
536
547
}
537
548
return null ;
538
549
}
@@ -598,6 +609,7 @@ private String getExecutable() {
598
609
if (launcherExecName != null ) {
599
610
return launcherExecName ;
600
611
}
612
+ log ("cannot determine the executable path. Using java command invocation for executable." );
601
613
String [] executableList = getExecutableList ();
602
614
for (int i = 0 ; i < executableList .length ; i ++) {
603
615
if (executableList [i ].matches ("\\ s" )) {
@@ -831,22 +843,27 @@ private void findAndApplyVenvCfg(Builder contextBuilder, String executable) {
831
843
try {
832
844
binDir = Paths .get (executable ).getParent ();
833
845
} catch (InvalidPathException e ) {
846
+ log ("cannot determine the parent directory of the executable" );
834
847
return ;
835
848
}
836
849
if (binDir == null ) {
850
+ log ("parent directory of the executable does not exist" );
837
851
return ;
838
852
}
839
853
Path venvCfg = binDir .resolve (J_PYENVCFG );
854
+ log ("checking: " , venvCfg );
840
855
if (!Files .exists (venvCfg )) {
841
856
Path binParent = binDir .getParent ();
842
857
if (binParent == null ) {
843
858
return ;
844
859
}
845
860
venvCfg = binParent .resolve (J_PYENVCFG );
861
+ log ("checking: " , venvCfg );
846
862
if (!Files .exists (venvCfg )) {
847
863
return ;
848
864
}
849
865
}
866
+ log ("found: " , venvCfg );
850
867
try (BufferedReader reader = Files .newBufferedReader (venvCfg )) {
851
868
String line ;
852
869
while ((line = reader .readLine ()) != null ) {
@@ -1439,4 +1456,14 @@ private static void addArgument(String pid, String uuid, ArrayList<String> envAr
1439
1456
private static boolean doEcho (@ SuppressWarnings ("unused" ) Context context ) {
1440
1457
return true ;
1441
1458
}
1459
+
1460
+ private void log (String message ) {
1461
+ log (message , "" );
1462
+ }
1463
+
1464
+ private void log (String message1 , Object message2 ) {
1465
+ if (verboseLauncher ) {
1466
+ System .err .println ("GraalPy launcher: " + message1 + message2 );
1467
+ }
1468
+ }
1442
1469
}
0 commit comments