1
1
"""----------------------------------------------------------------------------
2
2
-- L K Q L J I T --
3
3
-- --
4
- -- Copyright (C) 2023, AdaCore --
4
+ -- Copyright (C) 2023-2025 , AdaCore --
5
5
-- --
6
6
-- This library is free software; you can redistribute it and/or modify it --
7
7
-- under terms of the GNU General Public License as published by the Free --
41
41
"""
42
42
43
43
import os
44
- import os .path as P
45
44
import subprocess
46
45
import sys
47
46
47
+ from pathlib import Path
48
+
48
49
sys .path .append (".." )
50
+ # noinspection PyUnresolvedReferences
49
51
from utils import GraalManager , parse_args , is_windows
50
52
53
+
51
54
def look_for_files_in_env (files : list [str ], env_var_name : str ) -> dict [str , str ] | None :
52
55
"""
53
56
Look for required `files` in directories listed in the value of the
@@ -56,19 +59,20 @@ def look_for_files_in_env(files: list[str], env_var_name: str) -> dict[str, str]
56
59
cannot be retrieved this function returns `None` and displays error message
57
60
about file not being found.
58
61
"""
59
- res = {f : None for f in files }
60
- for dir in os .environ .get (env_var_name , "" ).split (os .pathsep ):
62
+ res : dict [ str , str | None ] = {f : None for f in files }
63
+ for directory in os .environ .get (env_var_name , "" ).split (os .pathsep ):
61
64
for file in files :
62
- if os . path . isfile ( os . path . join ( dir , file )):
63
- res [file ] = dir
65
+ if Path ( directory , file ). is_file ( ):
66
+ res [file ] = directory
64
67
break
65
68
one_not_found = False
66
- for file , dir in res .items ():
67
- if dir is None :
69
+ for file , directory in res .items ():
70
+ if directory is None :
68
71
one_not_found = True
69
- print (f" Cannot find \ "{ file } \ " in { env_var_name } " )
72
+ print (f' Cannot find "{ file } " in { env_var_name } ' )
70
73
return None if one_not_found else res
71
74
75
+
72
76
if __name__ == "__main__" :
73
77
# Create utils
74
78
graal = GraalManager ()
@@ -93,31 +97,49 @@ def look_for_files_in_env(files: list[str], env_var_name: str) -> dict[str, str]
93
97
94
98
# We also need to provide rpath-links to the compiler to allow it to
95
99
# find libraries during linking phase.
96
- ld_library_path = os .environ .get (' LD_LIBRARY_PATH' )
100
+ ld_library_path = os .environ .get (" LD_LIBRARY_PATH" )
97
101
rpaths = (
98
102
[f"-Wl,-rpath-link={ p } " for p in ld_library_path .split (os .pathsep )]
99
- if ld_library_path else
100
- []
103
+ if ld_library_path
104
+ else []
101
105
)
102
106
103
- os_specific_options .extend ([
104
- # The G1 garbage collector is only supported on Linux for now
105
- "--gc=G1" ,
106
-
107
- # Then we add additional options for the C compiler
108
- * [f"--native-compiler-options=-I{ dir } " for dir in headers_paths .values ()],
109
- * [f"--native-compiler-options=-L{ dir } " for dir in libs_paths .values ()],
110
- * [f"--native-compiler-options={ rp } " for rp in rpaths ],
111
- ])
107
+ os_specific_options .extend (
108
+ [
109
+ # The G1 garbage collector is only supported on Linux for now
110
+ "--gc=G1" ,
111
+ # Then we add additional options for the C compiler
112
+ * [
113
+ f"--native-compiler-options=-I{ header_dir } "
114
+ for header_dir in headers_paths .values ()
115
+ ],
116
+ * [
117
+ f"--native-compiler-options=-L{ lib_dir } "
118
+ for lib_dir in libs_paths .values ()
119
+ ],
120
+ * [f"--native-compiler-options={ rp } " for rp in rpaths ],
121
+ ]
122
+ )
112
123
113
124
# Run the Native-Image compiler if required by the build process
114
125
if "lkql_cli" in args .native_components :
126
+ # Get the buildspace tmp dir to set the polyglot cache path. When
127
+ # built in docker images (where only the buildspace is writable), the
128
+ # build crashes because it tries to create $HOME/.cache. This behavior
129
+ # may be overridden by the polyglot.engine.userResourceCache value.
130
+ # There is nothing in args (build_mode, classpath native_components) to
131
+ # give a clue about buildspace location, guess it from this file's path.
132
+ buildspace : Path = Path (__file__ ).parents [3 ]
133
+ tmp_path : Path = Path (buildspace , "tmp" )
134
+
115
135
# Create the base Native-Image command
116
136
cmd = [
117
137
graal .native_image ,
118
- "-cp" , args .classpath ,
138
+ "-cp" ,
139
+ args .classpath ,
119
140
"--no-fallback" ,
120
141
"--initialize-at-build-time" ,
142
+ f"-Dpolyglot.engine.userResourceCache={ tmp_path .as_posix ()} " ,
121
143
* os_specific_options ,
122
144
]
123
145
@@ -145,7 +167,7 @@ def look_for_files_in_env(files: list[str], env_var_name: str) -> dict[str, str]
145
167
# Finally specify the main class name and the output file
146
168
final_cmd = cmd + [
147
169
"com.adacore.lkql_jit.cli.LKQLMain" ,
148
- P . join ( "target" , "lkql" ),
170
+ str ( Path ( "target" , "lkql" ) ),
149
171
]
150
172
151
173
# Debug print and run
0 commit comments