From b0f163f4059b43f05351555d37da735848ba60d1 Mon Sep 17 00:00:00 2001 From: James Ball Date: Sun, 17 Nov 2024 07:23:13 -0800 Subject: [PATCH] Fixed typo in mip (spurious character after name:) and fixed $copy path from mie to mip description to accomodate new schema change. --- arch/csr/mie.yaml | 2 +- arch/csr/mip.yaml | 2 +- lib/test/test_yaml_loader.rb | 68 ------------------------------------ lib/yaml_loader.rb | 20 +++++------ 4 files changed, 12 insertions(+), 80 deletions(-) diff --git a/arch/csr/mie.yaml b/arch/csr/mie.yaml index b4a6e8a98..f053fa484 100644 --- a/arch/csr/mie.yaml +++ b/arch/csr/mie.yaml @@ -8,7 +8,7 @@ address: 0x304 priv_mode: M length: MXLEN definedBy: Sm -description: "$copy: mip.yaml#/mip/description" +description: "$copy: mip.yaml#/description" fields: SSIE: location: 1 diff --git a/arch/csr/mip.yaml b/arch/csr/mip.yaml index 15b2367f7..9ff6f7c4d 100644 --- a/arch/csr/mip.yaml +++ b/arch/csr/mip.yaml @@ -2,7 +2,7 @@ $schema: "csr_schema.json#" kind: csr -name: mip> +name: mip long_name: Machine Interrupt Pending address: 0x344 priv_mode: M diff --git a/lib/test/test_yaml_loader.rb b/lib/test/test_yaml_loader.rb index ee3be540b..98f23a271 100644 --- a/lib/test/test_yaml_loader.rb +++ b/lib/test/test_yaml_loader.rb @@ -208,74 +208,6 @@ def test_that_double_inherits_doesnt_delete_keys assert_equal({ "key1" => "value1", "key2" => "value2", "key3" => "value3_new", "key4" => "value4", "key5" => "value5", "key6" => "value6_new" }, doc["child"]) end -# Removed by @dhower-qc in https://github.com/riscv-software-src/riscv-unified-db/commit/7d10d70f122de6263ce7907dee8daeddc0a0af40 -# Waiting for response in https://github.com/riscv-software-src/riscv-unified-db/pull/271 -# -# def test_refs_in_the_same_document -# yaml = <<~YAML -# $defs: -# target1: A string -# target2: -# a: hash -# -# obj1: -# $ref: "#/$defs/target2" -# -# obj2: -# $ref: "#/$defs/target2" -# target2: Should disappear -# -# obj3: -# target2: Should disappear -# $ref: "#/$defs/target2" -# YAML -# -# f = Tempfile.new("yml") -# f.write(yaml) -# f.flush -# -# doc = YamlLoader.load(f.path) -# assert_equal({ "a" => "hash" }, doc["obj1"]) -# assert_equal({ "a" => "hash" }, doc["obj2"]) -# assert_equal({ "a" => "hash" }, doc["obj3"]) -# end -# -# def test_refs_in_the_different_document -# yaml1 = <<~YAML -# $defs: -# target1: A string -# target2: -# a: hash -# YAML -# -# f1 = Tempfile.new("yml") -# f1.write(yaml1) -# f1.flush -# f1_path = Pathname.new(f1.path) -# -# yaml2 = <<~YAML -# obj1: -# $ref: "#{f1_path.basename}#/$defs/target2" -# -# obj2: -# $ref: "#{f1_path.basename}#/$defs/target2" -# target2: Should disappear -# -# obj3: -# target2: Should disappear -# $ref: "#{f1_path.basename}#/$defs/target2" -# YAML -# -# f2 = Tempfile.new("yml") -# f2.write(yaml2) -# f2.flush -# -# doc = YamlLoader.load(f2.path) -# assert_equal({ "a" => "hash" }, doc["obj1"]) -# assert_equal({ "a" => "hash" }, doc["obj2"]) -# assert_equal({ "a" => "hash" }, doc["obj3"]) -# end - def test_inherits_in_the_same_document yaml = <<~YAML $defs: diff --git a/lib/yaml_loader.rb b/lib/yaml_loader.rb index 6a20ab155..56079d88d 100644 --- a/lib/yaml_loader.rb +++ b/lib/yaml_loader.rb @@ -142,7 +142,7 @@ def self.expand(filename, obj, yaml_opts = {}) obj[key] = if value.is_a?(String) && value.start_with?("$copy:") copy_target = value.delete_prefix("$copy:").lstrip - self.get_ref_target_obj(filename, copy_target, yaml_opts) + self.get_copy_target_obj(filename, copy_target, yaml_opts) else expand(filename, value, yaml_opts) end @@ -162,21 +162,21 @@ def self.expand(filename, obj, yaml_opts = {}) end # @param filename [String,Pathname] path to the YAML file - # @param ref_target [String] + # @param copy_target [String] # @param yaml_opts [Hash] options to pass to YAML.load_file # @return [Object] - def self.get_ref_target_obj(filename, ref_target, yaml_opts) - relative_path = ref_target.split("#")[0] + def self.get_copy_target_obj(filename, copy_target, yaml_opts) + relative_path = copy_target.split("#")[0] if relative_path.empty? # this is a reference in the same document obj_doc = YAML.load_file(filename, **yaml_opts) - obj_path = ref_target.split("#")[1].split("/")[1..] + obj_path = copy_target.split("#")[1].split("/")[1..] target_obj = obj_doc.dig(*obj_path) - raise DereferenceError, "$ref: #{obj_path} cannot be found in file #{filename}" if target_obj.nil? + raise DereferenceError, "$copy: #{obj_path} referenced to same file cannot be found in file #{filename}" if target_obj.nil? ref = expand(filename, target_obj, yaml_opts) if ref.nil? - raise DereferenceError, "JSON Path #{obj_path} does not exist in file #{filename}" + raise DereferenceError, "$copy: JSON Path #{obj_path} referenced to same file does not exist in file #{filename}" end ref @@ -184,13 +184,13 @@ def self.get_ref_target_obj(filename, ref_target, yaml_opts) target_filename = File.realpath(File.join(filename.dirname, relative_path)) obj_doc = YamlLoader.load(target_filename, yaml_opts) - obj_path = ref_target.split("#")[1].split("/")[1..] + obj_path = copy_target.split("#")[1].split("/")[1..] target_obj = obj_doc.dig(*obj_path) - raise "$ref: #{obj_path} cannot be found in file #{target_filename}" if target_obj.nil? + raise DereferenceError, "$copy: #{obj_path} referenced from file #{filename} cannot be found in file #{target_filename}" if target_obj.nil? ref = expand(target_filename, target_obj, yaml_opts) if ref.nil? - raise DereferenceError, "JSON Path #{obj_path} does not exist in file #{target_filename}" + raise DereferenceError, "$copy: JSON Path #{obj_path} referenced from file #{filename} does not exist in file #{target_filename}" end ref