|
24 | 24 | # |
25 | 25 |
|
26 | 26 | import os |
| 27 | +import pathlib |
27 | 28 | import re |
| 29 | +import shutil |
28 | 30 | import tempfile |
29 | 31 | from glob import glob |
30 | 32 | from contextlib import contextmanager |
|
53 | 55 |
|
54 | 56 | import sys |
55 | 57 |
|
56 | | - |
57 | | - |
58 | 58 | suite = mx.suite('substratevm') |
59 | 59 | svmSuites = [suite] |
60 | 60 |
|
@@ -206,6 +206,7 @@ def __getattr__(self, name): |
206 | 206 | 'hellomodule', |
207 | 207 | 'condconfig', |
208 | 208 | 'truffle_unittests', |
| 209 | + 'check_libcontainer_annotations' |
209 | 210 | ]) |
210 | 211 |
|
211 | 212 | def vm_native_image_path(config=None): |
@@ -449,6 +450,10 @@ def help_stdout_check(output): |
449 | 450 |
|
450 | 451 | mx.log('mx native-image --help output check detected no errors.') |
451 | 452 |
|
| 453 | + with Task('Check ContainerLibrary annotations', tasks, tags=[GraalTags.check_libcontainer_annotations]) as t: |
| 454 | + if t: |
| 455 | + mx.command_function("check-libcontainer-annotations")([]) |
| 456 | + |
452 | 457 | with Task('module build demo', tasks, tags=[GraalTags.hellomodule]) as t: |
453 | 458 | if t: |
454 | 459 | hellomodule(args.extra_image_builder_arguments) |
@@ -2213,3 +2218,77 @@ def javac_image(args): |
2213 | 2218 | def musl_helloworld(args, config=None): |
2214 | 2219 | final_args = ['--static', '--libc=musl'] + args |
2215 | 2220 | run_helloworld_command(final_args, config, 'muslhelloworld') |
| 2221 | + |
| 2222 | + |
| 2223 | +def _get_libcontainer_files(): |
| 2224 | + paths = [] |
| 2225 | + libcontainer_project = mx.project("com.oracle.svm.native.libcontainer") |
| 2226 | + libcontainer_dir = libcontainer_project.dir |
| 2227 | + for src_dir in libcontainer_project.source_dirs(): |
| 2228 | + for path, _, files in os.walk(src_dir): |
| 2229 | + for name in files: |
| 2230 | + abs_path = pathlib.PurePath(path, name) |
| 2231 | + rel_path = abs_path.relative_to(libcontainer_dir) |
| 2232 | + src_svm = pathlib.PurePath("src", "svm") |
| 2233 | + if src_svm in rel_path.parents: |
| 2234 | + # replace "svm" with "hotspot" |
| 2235 | + stripped_path = rel_path.relative_to(src_svm) |
| 2236 | + if not stripped_path.as_posix().startswith("svm_container"): |
| 2237 | + hotspot_path = pathlib.PurePath("src", "hotspot") / stripped_path |
| 2238 | + paths.append(hotspot_path.as_posix()) |
| 2239 | + else: |
| 2240 | + paths.append(rel_path.as_posix()) |
| 2241 | + return libcontainer_dir, paths |
| 2242 | + |
| 2243 | + |
| 2244 | +@mx.command(suite, 'check-libcontainer-annotations') |
| 2245 | +def check_libcontainer_annotations(args): |
| 2246 | + """Verifies that files from libcontainer that are copied from hotspot have a @BasedOnJDKFile annotation in ContainerLibrary.""" |
| 2247 | + |
| 2248 | + # collect paths to check |
| 2249 | + |
| 2250 | + libcontainer_dir, paths = _get_libcontainer_files() |
| 2251 | + |
| 2252 | + java_project = mx.project("com.oracle.svm.core") |
| 2253 | + container_library = pathlib.Path(java_project.dir, "src/com/oracle/svm/core/container/ContainerLibrary.java") |
| 2254 | + with open(container_library, "r") as fp: |
| 2255 | + annotation_lines = [x for x in fp.readlines() if "@BasedOnJDKFile" in x] |
| 2256 | + |
| 2257 | + # check all files are in an annotation |
| 2258 | + for f in paths: |
| 2259 | + if not any((a for a in annotation_lines if f in a)): |
| 2260 | + mx.abort(f"file {f} not found in any annotation in {container_library}") |
| 2261 | + |
| 2262 | + # check all annotations refer to a file |
| 2263 | + for a in annotation_lines: |
| 2264 | + if not any((f for f in paths if f in a)): |
| 2265 | + mx.abort(f"annotation {a} does not match any files in {libcontainer_dir}") |
| 2266 | + |
| 2267 | + |
| 2268 | +reimport_libcontainer_files_cmd = "reimport-libcontainer-files" |
| 2269 | + |
| 2270 | + |
| 2271 | +@mx.command(suite, reimport_libcontainer_files_cmd) |
| 2272 | +def reimport_libcontainer_files(args): |
| 2273 | + parser = ArgumentParser(prog=f"mx {reimport_libcontainer_files_cmd}") |
| 2274 | + parser.add_argument("--jdk-repo", required=True, help="Path to the OpenJDK repo to import the files from.") |
| 2275 | + parsed_args = parser.parse_args(args) |
| 2276 | + |
| 2277 | + libcontainer_dir, paths = _get_libcontainer_files() |
| 2278 | + |
| 2279 | + libcontainer_path = pathlib.Path(libcontainer_dir) |
| 2280 | + jdk_path = pathlib.Path(parsed_args.jdk_repo) |
| 2281 | + |
| 2282 | + missing = [] |
| 2283 | + |
| 2284 | + for path in paths: |
| 2285 | + jdk_file = jdk_path / path |
| 2286 | + svm_file = libcontainer_path / path |
| 2287 | + if jdk_file.is_file(): |
| 2288 | + if mx.ask_yes_no(f"Should I update {path}"): |
| 2289 | + shutil.copyfile(jdk_file, svm_file) |
| 2290 | + else: |
| 2291 | + missing.append(jdk_file) |
| 2292 | + mx.warn(f"File not found: {jdk_file}") |
| 2293 | + if mx.ask_yes_no(f"Should I delete {path}"): |
| 2294 | + svm_file.unlink() |
0 commit comments