Skip to content

Commit 6169e4d

Browse files
committed
Link the schema from the documentation
1 parent fa008e9 commit 6169e4d

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
reachability-metadata-schema-v1.2.0.json
1+
../../../../substratevm/schemas/reachability-metadata-schema-v1.2.0.json

substratevm/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ This changelog summarizes major changes to GraalVM Native Image.
88
* (GR-69280) Allow use of the `graal.` prefix for options without issuing a warning.
99
* (GR-2092) Add jitdump support for recording run-time compilation metadata for perf (see PerfProfiling.md). Can be enabled with `-g -H:+RuntimeDebugInfo -H:RuntimeDebugInfoFormat=jitdump`.
1010
* (GR-69572) Deprecates the `native-image-inspect` tool. To extract embedded SBOMs, use `native-image-configure extract-sbom --image-path=<path_to_binary>`.
11+
* (GR-68984) Ship the `reachability-metadata-schema.json` together with GraalVM at `<graalvm-home>/lib/svm/schemas/reachability-metadata-schema.json`.
12+
* (GR-68984) Improve the schema to capture detailed constraints about each element in the `reachability-metadata-schema.json`.
1113

1214
## GraalVM 25
1315
* (GR-52276) (GR-61959) Add support for Arena.ofShared().

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,6 +2494,48 @@ def compute_graal_compiler_flags_map(self):
24942494

24952495
return graal_compiler_flags_map
24962496

2497+
def get_jsonschema_validator(schema_path):
2498+
"""Create and return a jsonschema Validator for the schema at the given file path. Abort on missing jsonschema or invalid schema."""
2499+
import json
2500+
try:
2501+
with open(schema_path, "r", encoding="utf-8") as f:
2502+
schema = json.load(f)
2503+
except json.JSONDecodeError as e:
2504+
mx.abort(f'Failed to parse JSON in schema file "{schema_path}" at line {e.lineno}, column {e.colno}: {e.msg}')
2505+
except OSError as e:
2506+
mx.abort(f'I/O error when opening schema file "{schema_path}": {e}')
2507+
2508+
try:
2509+
import jsonschema # type: ignore
2510+
except ImportError as e:
2511+
mx.abort(
2512+
'Python module "jsonschema" is required to validate reachability metadata but was not found. '
2513+
'Install it with: "python3 -m pip install --user jsonschema" (or "pip3 install jsonschema"). '
2514+
f'Original error: {e}')
2515+
try:
2516+
if hasattr(jsonschema, 'Draft202012Validator'):
2517+
return jsonschema.Draft202012Validator(schema) # type: ignore[attr-defined]
2518+
else:
2519+
return jsonschema.Draft7Validator(schema) # type: ignore
2520+
except (jsonschema.exceptions.SchemaError, TypeError) as e:
2521+
mx.abort(f'Invalid reachability metadata schema: {e}')
2522+
2523+
def validate_json_file_against_schema(validator, file_path):
2524+
"""Validates a JSON file against the provided Validator. Returns a list of error strings; empty if valid."""
2525+
import json
2526+
try:
2527+
with open(file_path, 'r', encoding='utf-8') as f:
2528+
data = json.load(f)
2529+
except json.JSONDecodeError as e:
2530+
mx.abort(f'Invalid JSON syntax at line {e.lineno}, column {e.colno}: {e.msg}')
2531+
except OSError as e:
2532+
mx.abort(f'I/O error: {e}')
2533+
2534+
errors = []
2535+
for err in validator.iter_errors(data):
2536+
path = '/'.join([str(p) for p in err.path]) if err.path else '#'
2537+
errors.append(f'{path}: {err.message}')
2538+
return errors
24972539

24982540
class SubstrateCompilerFlagsBuildTask(mx.ArchivableBuildTask):
24992541
def __init__(self, subject, args):

substratevm/mx.substratevm/suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2475,7 +2475,7 @@
24752475
"clibraries/" : ["extracted-dependency:substratevm:SVM_HOSTED_NATIVE"],
24762476
"builder/clibraries/" : ["extracted-dependency:substratevm:SVM_HOSTED_NATIVE"],
24772477
"builder/lib/" : ["dependency:com.oracle.svm.native.reporterchelper"],
2478-
"schemas/reachability-metadata-schema.json" : ["file:docs/schemas/reachability-metadata-schema-v1.2.0.json"],
2478+
"schemas/reachability-metadata-schema.json" : ["file:schemas/reachability-metadata-schema-v1.2.0.json"],
24792479
# Note: `ld64.lld` is a symlink to `lld`, but it is dereferenced here.
24802480
"bin/" : ["extracted-dependency:LLVM_LLD_STANDALONE/bin/ld64.lld"],
24812481
},
File renamed without changes.

0 commit comments

Comments
 (0)