diff mbox series

[2/3] selftest/bblayers: Refactor JSON schema validation

Message ID 20251023072513.280477-2-yoann.congal@smile.fr
State New
Headers show
Series [1/3] meta/files: Add a jsonschema for bitbake-setup configuration files | expand

Commit Message

Yoann Congal Oct. 23, 2025, 7:25 a.m. UTC
From: Yoann Congal <yoann.congal@smile.fr>

* Extract a function "validate_json"
* Allow to specify the schema relative to $COREBASE/meta/files/
* Specify the Base URI to allow schema to reference each other

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
---
RFC: Maybe I should split this commit?
---
 meta/lib/oeqa/selftest/cases/bblayers.py | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/bblayers.py b/meta/lib/oeqa/selftest/cases/bblayers.py
index 982287c9a5..43a158fcf2 100644
--- a/meta/lib/oeqa/selftest/cases/bblayers.py
+++ b/meta/lib/oeqa/selftest/cases/bblayers.py
@@ -136,15 +136,24 @@  class BitbakeLayers(OESelftestTestCase):
         self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe)
         return os.path.basename(recipe_file)
 
-    def validate_layersjson(self, json):
-        python = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'nativepython3')
-        jsonvalidator = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'jsonschema')
-        jsonschema = os.path.join(get_bb_var('COREBASE'), 'meta/files/layers.schema.json')
-        result = runCmd("{} {} -i {} {}".format(python, jsonvalidator, json, jsonschema))
+    def validate_json(self, json, jsonschema):
+        staging_bindir = get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native')
+        python = os.path.join(staging_bindir, 'nativepython3')
+        jsonvalidator = os.path.join(staging_bindir, 'jsonschema')
+        schemas_dir = os.path.join(get_bb_var('COREBASE'), "meta/files/")
+        if not os.path.isabs(jsonschema):
+            jsonschema = os.path.join(schemas_dir, jsonschema)
+
+        result = runCmd(
+            "{} {} -i {} --base-uri file://{}/ {}".format(
+                python, jsonvalidator, json, schemas_dir, jsonschema
+            )
+        )
 
     def test_validate_examplelayersjson(self):
         json = os.path.join(get_bb_var('COREBASE'), "meta/files/layers.example.json")
-        self.validate_layersjson(json)
+        jsonschema = "layers.schema.json"
+        self.validate_json(json, jsonschema)
 
     def test_bitbakelayers_setup(self):
         result = runCmd('bitbake-layers create-layers-setup {}'.format(self.testlayer_path))