Skip to content

Commit ac8ca0d

Browse files
authored
fix: paths for CTP, isa_explorer, and deploy (#855)
Should fix the deployment
1 parent b3ea202 commit ac8ca0d

File tree

9 files changed

+117
-77
lines changed

9 files changed

+117
-77
lines changed

backends/ext_pdf_doc/tasks.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ end
7272

7373
rule %r{#{$resolver.gen_path}/ext_pdf_doc/.*/adoc/.*_extension\.adoc} => proc { |tname|
7474
config_name = Pathname.new(tname).relative_path_from("#{$resolver.gen_path}/ext_pdf_doc").to_s.split("/")[0]
75-
arch_yaml_paths = Dir.glob("#{$root}/arch/**/*.yaml")
75+
arch_yaml_paths = Dir.glob("#{$resolver.resolved_spec_path(config_name)}/**/*.yaml")
7676
cfg_path = $resolver.gen_path / "ext_pdf_doc" / "#{config_name}.yaml"
7777
cfg = Udb::AbstractConfig.create(cfg_path)
7878
arch_yaml_paths += Dir.glob("#{cfg.arch_overlay_abs}/**/*.yaml") unless cfg.arch_overlay.nil?

backends/isa_explorer/isa_explorer.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
2+
# typed: true
13
# frozen_string_literal: true
2-
#
4+
35
# Generate
46

7+
require "sorbet-runtime"
58
require "write_xlsx"
9+
610
require "udb/architecture"
711

812
# @param presence [String] Can be nil
@@ -85,9 +89,8 @@ def arch2ext_table(arch)
8589

8690
# @param arch [Architecture] The entire RISC-V architecture
8791
# @return [Hash<String,Array<String>] Instruction table data
92+
sig { params(arch: Udb::Architecture).returns(T::Hash[String, T::Array[String]]) }
8893
def arch2inst_table(arch)
89-
raise ArgumentError, "arch is a #{arch.class} class but needs to be Architecture" unless arch.is_a?(Architecture)
90-
9194
sorted_profile_releases = get_sorted_profile_releases(arch)
9295

9396
inst_table = {
@@ -134,9 +137,8 @@ def arch2inst_table(arch)
134137

135138
# @param arch [Architecture] The entire RISC-V architecture
136139
# @return [Hash<String,Array<String>] CSR table data
140+
sig { params(arch: Udb::Architecture).returns(T::Hash[String, T::Array[String]]) }
137141
def arch2csr_table(arch)
138-
raise ArgumentError, "arch is a #{arch.class} class but needs to be Architecture" unless arch.is_a?(Architecture)
139-
140142
sorted_profile_releases = get_sorted_profile_releases(arch)
141143

142144
csr_table = {
@@ -230,9 +232,8 @@ def gen_xlsx_table(table, workbook, worksheet)
230232
#
231233
# @param arch [Architecture] The entire RISC-V architecture
232234
# @param output_pname [String] Full absolute pathname to output file
235+
sig { params(arch: Udb::Architecture, output_pname: String).void }
233236
def gen_xlsx(arch, output_pname)
234-
raise ArgumentError, "arch is a #{arch.class} class but needs to be Architecture" unless arch.is_a?(Architecture)
235-
raise ArgumentError, "output_pname is a #{output_pname.class} class but needs to be String" unless output_pname.is_a?(String)
236237

237238
# Create a new Excel workbook
238239
$logger.info "Creating Excel workboook #{output_pname}"

backends/isa_explorer/tasks.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ file "#{GEN_XLSX}" => [
8181
__FILE__,
8282
src_pnames
8383
].flatten do |t|
84-
arch = create_arch
84+
arch = $resolver.cfg_arch_for("_")
8585

8686
# Ensure directory holding target file is present.
8787
FileUtils.mkdir_p File.dirname(t.name)

backends/portfolio/templates/normative_rules.adoc.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% unless db_obj.cert_normative_rules.empty? -%>
2-
<% nice_name = db_obj.is_a?(CsrField) ? "#{db_obj.parent.name}.#{db_obj.name}" : db_obj.name -%>
2+
<% nice_name = db_obj.is_a?(Udb::CsrField) ? "#{db_obj.parent.name}.#{db_obj.name}" : db_obj.name -%>
33
<% if defined?(use_description_list) && use_description_list -%>
44
Normative Rules for `<%= nice_name %>`: ::
55
<% else -%>

backends/portfolio/templates/test_procedures.adoc.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% unless db_obj.cert_test_procedures.empty? -%>
2-
<% nice_name = db_obj.is_a?(CsrField) ? "#{db_obj.parent.name}.#{db_obj.name}" : db_obj.name -%>
2+
<% nice_name = db_obj.is_a?(Udb::CsrField) ? "#{db_obj.parent.name}.#{db_obj.name}" : db_obj.name -%>
33
<% if defined?(use_description_list) && use_description_list -%>
44
Test Procedures for `<%= nice_name %>`: ::
55
<% else -%>

backends/proc_ctp/tasks.rake

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
require "pathname"
66

77
PROC_CTP_DOC_DIR = Pathname.new "#{$root}/backends/proc_ctp"
8-
PROC_CTP_GEN_DIR = $root / "gen" / "proc_ctp"
8+
PROC_CTP_GEN_DIR = $resolver.gen_path / "proc_ctp"
99

10-
Dir.glob("#{$root}/arch/proc_cert_model/*.yaml") do |f|
10+
Dir.glob("#{$resolver.std_path}/proc_cert_model/*.yaml") do |f|
1111
model_name = File.basename(f, ".yaml")
1212
model_obj = YAML.load_file(f, permitted_classes: [Date])
1313
class_name = File.basename(model_obj['class']['$ref'].split("#")[0], ".yaml")
1414
raise "Ill-formed processor certificate model file #{f}: missing 'class' field" if model_obj['class'].nil?
1515

1616
file "#{PROC_CTP_GEN_DIR}/adoc/#{model_name}-CTP.adoc" => [
1717
__FILE__,
18-
"#{$root}/arch/proc_cert_class/#{class_name}.yaml",
19-
"#{$root}/arch/proc_cert_model/#{model_name}.yaml",
20-
"#{$root}/lib/arch_obj_models/certificate.rb",
21-
"#{$root}/lib/arch_obj_models/portfolio.rb",
22-
"#{$root}/lib/portfolio_design.rb",
18+
"#{$resolver.std_path}/proc_cert_class/#{class_name}.yaml",
19+
"#{$resolver.std_path}/proc_cert_model/#{model_name}.yaml",
20+
"#{Udb.gem_path}/lib/udb/obj/certificate.rb",
21+
"#{Udb.gem_path}/lib/udb/obj/portfolio.rb",
22+
"#{Udb.gem_path}/lib/udb/portfolio_design.rb",
2323
"#{$root}/backends/portfolio/templates/ext_appendix.adoc.erb",
2424
"#{$root}/backends/portfolio/templates/inst_appendix.adoc.erb",
2525
"#{$root}/backends/portfolio/templates/csr_appendix.adoc.erb",
@@ -65,8 +65,8 @@ namespace :gen do
6565
exit 1
6666
end
6767

68-
unless File.exist?("#{$root}/arch/proc_cert_model/#{model_name}.yaml")
69-
warn "No certification model named '#{model_name}' found in arch/proc_cert_model"
68+
unless File.exist?("#{$resolver.std_path}/proc_cert_model/#{model_name}.yaml")
69+
warn "No certification model named '#{model_name}' found in #{$resolver.std_path}/proc_cert_model"
7070
exit 1
7171
end
7272

@@ -77,16 +77,16 @@ namespace :gen do
7777
Generate Processor CTP (Certification Test Plan) as an HTML file.
7878
7979
Required options:
80-
model_name - The name of the certification model under arch/proc_cert_model
80+
model_name - The name of the certification model under spec/std/isa/proc_cert_model
8181
DESC
8282
task :proc_ctp_html, [:model_name] do |_t, args|
8383
if args[:model_name].nil?
8484
warn "Missing required option: 'model_name'"
8585
exit 1
8686
end
8787

88-
unless File.exist?("#{$root}/arch/proc_cert_model/#{args[:model_name]}.yaml")
89-
warn "No certification model named '#{args[:model_name]}' found in arch/proc_cert_model"
88+
unless File.exist?("#{$resolver.std_path}/proc_cert_model/#{args[:model_name]}.yaml")
89+
warn "No certification model named '#{args[:model_name]}' found in #{$resolver.std_path}/proc_cert_model"
9090
exit 1
9191
end
9292

tools/ruby-gems/udb/lib/udb/req_expression.rb

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
module Udb
1111

12-
class ExtensionVersion; end
12+
# sorbet needs a forward declration
13+
class ExtensionVersion; end
1314

1415
# return type for satisfied_by functions
1516
class SatisfiedResult < T::Enum
@@ -71,6 +72,7 @@ def initialize(composition_hash, cfg_arch)
7172

7273
@hsh = composition_hash
7374
@arch = cfg_arch
75+
@satisfied_by_cfg_arch = T.let({}, T::Hash[String, SatisfiedResult])
7476
end
7577

7678
sig { override.returns(T.any(String, T::Hash[String, T.untyped])) }
@@ -625,24 +627,25 @@ def could_be_true?(cfg_arch)
625627

626628
sig { override.params(cfg_arch: ConfiguredArchitecture).returns(SatisfiedResult) }
627629
def satisfied_by_cfg_arch?(cfg_arch)
628-
if cfg_arch.fully_configured?
629-
if satisfied_by? { |ext_req| cfg_arch.transitive_implemented_extension_versions.any? { |ev| ext_req.satisfied_by?(ev) } }
630-
SatisfiedResult::Yes
630+
@satisfied_by_cfg_arch[cfg_arch.name] ||=
631+
if cfg_arch.fully_configured?
632+
if satisfied_by? { |ext_req| cfg_arch.transitive_implemented_extension_versions.any? { |ev| ext_req.satisfied_by?(ev) } }
633+
SatisfiedResult::Yes
634+
else
635+
SatisfiedResult::No
636+
end
637+
elsif cfg_arch.partially_configured?
638+
if satisfied_by? { |cond_ext_req| cfg_arch.mandatory_extension_reqs.any? { |cfg_ext_req| cond_ext_req.satisfied_by?(cfg_ext_req) } }
639+
SatisfiedResult::Yes
640+
elsif satisfied_by? { |cond_ext_req| cfg_arch.possible_extension_versions.any? { |cfg_ext_ver| cond_ext_req.satisfied_by?(cfg_ext_ver) } }
641+
SatisfiedResult::Maybe
642+
else
643+
SatisfiedResult::No
644+
end
631645
else
632-
SatisfiedResult::No
633-
end
634-
elsif cfg_arch.partially_configured?
635-
if satisfied_by? { |cond_ext_req| cfg_arch.mandatory_extension_reqs.any? { |cfg_ext_req| cond_ext_req.satisfied_by?(cfg_ext_req) } }
646+
# unconfig. everything flies
636647
SatisfiedResult::Yes
637-
elsif satisfied_by? { |cond_ext_req| cfg_arch.possible_extension_versions.any? { |cfg_ext_ver| cond_ext_req.satisfied_by?(cfg_ext_ver) } }
638-
SatisfiedResult::Maybe
639-
else
640-
SatisfiedResult::No
641648
end
642-
else
643-
# unconfig. everything flies
644-
SatisfiedResult::Yes
645-
end
646649
end
647650

648651
# returns true if the list of extension requirements *can* satisfy the condition.

tools/ruby-gems/udb/lib/udb/resolver.rb

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ def self.default_cfgs_path
6666
class Resolver
6767
extend T::Sig
6868

69+
# return type of #cfg_info
70+
class ConfigInfo < T::Struct
71+
const :name, String
72+
const :path, Pathname
73+
const :unresolved_yaml, T::Hash[String, T.untyped]
74+
prop :resolved_yaml, T.nilable(T::Hash[String, T.untyped])
75+
end
76+
6977
# path to find database schema files
7078
sig { returns(Pathname) }
7179
attr_reader :schemas_path
@@ -86,6 +94,18 @@ class Resolver
8694
sig { returns(Pathname) }
8795
attr_reader :custom_path
8896

97+
# path to merged spec (merged with custom overley, but prior to resolution)
98+
sig { params(cfg_path_or_name: T.any(String, Pathname)).returns(Pathname) }
99+
def merged_spec_path(cfg_path_or_name)
100+
@gen_path / "spec" / cfg_info(cfg_path_or_name).name
101+
end
102+
103+
# path to merged and resolved spec
104+
sig { params(cfg_path_or_name: T.any(String, Pathname)).returns(Pathname) }
105+
def resolved_spec_path(cfg_path_or_name)
106+
@gen_path / "resolved_spec" / cfg_info(cfg_path_or_name).name
107+
end
108+
89109
# path to a python binary
90110
sig { returns(Pathname) }
91111
attr_reader :python_path
@@ -126,6 +146,9 @@ def initialize(
126146
@custom_path = custom_path_override || (@repo_root / "spec" / "custom" / "isa")
127147
@python_path = python_path_override || (@repo_root / ".home" / ".venv" / "bin" / "python3")
128148

149+
# cache of config names
150+
@cfg_info = T.let({}, T::Hash[T.any(String, Pathname), ConfigInfo])
151+
129152
FileUtils.mkdir_p @gen_path
130153
end
131154

@@ -151,23 +174,24 @@ def run(cmd)
151174
# returns the config data
152175
sig { params(config_path: Pathname).returns(T::Hash[String, T.untyped]) }
153176
def resolve_config(config_path)
154-
config_yaml = T.nilable(T::Hash[String, T.untyped])
155-
config_name = config_path.basename(".yaml")
177+
config_info = cfg_info(config_path)
178+
return T.must(config_info.resolved_yaml) unless config_info.resolved_yaml.nil?
156179

180+
resolved_config_yaml = T.let({}, T.nilable(T::Hash[String, T.untyped]))
157181
# write the config with arch_overlay expanded
158-
if any_newer?(gen_path / "cfgs" / "#{config_name}.yaml", [config_path])
159-
config_yaml = YAML.load_file(config_path)
160-
182+
if any_newer?(gen_path / "cfgs" / "#{config_info.name}.yaml", [config_path])
161183
# is there anything to do here? validate?
162184

185+
resolved_config_yaml = config_info.unresolved_yaml.dup
186+
resolved_config_yaml["$source"] = config_path.realpath.to_s
187+
163188
FileUtils.mkdir_p gen_path / "cfgs"
164-
File.write(gen_path / "cfgs" / "#{config_name}.yaml", YAML.dump(config_yaml))
189+
File.write(gen_path / "cfgs" / "#{config_info.name}.yaml", YAML.dump(resolved_config_yaml))
165190
else
166-
config_yaml = YAML.load_file(gen_path / "cfgs" / "#{config_name}.yaml")
191+
resolved_config_yaml = YAML.load_file(gen_path / "cfgs" / "#{config_info.name}.yaml")
167192
end
168193

169-
config_yaml["$source"] = config_path.realpath
170-
config_yaml
194+
config_info.resolved_yaml = resolved_config_yaml
171195
end
172196

173197
sig { params(config_yaml: T::Hash[String, T.untyped]).void }
@@ -189,16 +213,16 @@ def merge_arch(config_yaml)
189213
end
190214
raise "custom directory '#{overlay_path}' does not exist" if !overlay_path.nil? && !overlay_path.directory?
191215

192-
if any_newer?(gen_path / "spec" / config_name / ".stamp", deps)
216+
if any_newer?(merged_spec_path(config_name) / ".stamp", deps)
193217
run [
194218
python_path.to_s,
195219
"#{Udb.gem_path}/python/yaml_resolver.py",
196220
"merge",
197221
std_path.to_s,
198222
overlay_path.nil? ? "/does/not/exist" : overlay_path.to_s,
199-
"#{gen_path}/spec/#{config_name}"
223+
merged_spec_path(config_name).to_s
200224
]
201-
FileUtils.touch(gen_path / "spec" / config_name / ".stamp")
225+
FileUtils.touch(merged_spec_path(config_name) / ".stamp")
202226
end
203227
end
204228

@@ -207,46 +231,58 @@ def resolve_arch(config_yaml)
207231
merge_arch(config_yaml)
208232
config_name = config_yaml["name"]
209233

210-
deps = Dir[gen_path / "arch" / config_yaml["name"] / "**" / "*.yaml"].map { |p| Pathname.new(p) }
211-
if any_newer?(gen_path / "resolved_spec" / config_yaml["name"] / ".stamp", deps)
234+
deps = Dir[merged_spec_path(config_name) / "**" / "*.yaml"].map { |p| Pathname.new(p) }
235+
if any_newer?(resolved_spec_path(config_name) / ".stamp", deps)
212236
run [
213237
python_path.to_s,
214238
"#{Udb.gem_path}/python/yaml_resolver.py",
215239
"resolve",
216-
"#{gen_path}/spec/#{config_name}",
217-
"#{gen_path}/resolved_spec/#{config_name}"
240+
merged_spec_path(config_name).to_s,
241+
resolved_spec_path(config_name).to_s
218242
]
219-
FileUtils.touch(gen_path / "resolved_spec" / config_yaml["name"] / ".stamp")
243+
FileUtils.touch(resolved_spec_path(config_name) / ".stamp")
220244
end
221245
end
222246

223-
# resolve the specification for a config, and return a ConfiguredArchitecture
224-
sig { params(config_path_or_name: T.any(Pathname, String)).returns(Udb::ConfiguredArchitecture) }
225-
def cfg_arch_for(config_path_or_name)
247+
sig { params(config_path_or_name: T.any(Pathname, String)).returns(ConfigInfo) }
248+
def cfg_info(config_path_or_name)
249+
return @cfg_info.fetch(config_path_or_name) if config_path_or_name.is_a?(String) && @cfg_info.key?(config_path_or_name)
250+
return @cfg_info.fetch(config_path_or_name.realpath) if config_path_or_name.is_a?(Pathname) && @cfg_info.key?(config_path_or_name.realpath)
251+
226252
config_path =
227253
case config_path_or_name
228254
when Pathname
229255
raise "Path does not exist: #{config_path_or_name}" unless config_path_or_name.file?
230256

231-
config_path_or_name
257+
config_path_or_name.realpath
232258
when String
233-
@repo_root / "cfgs" / "#{config_path_or_name}.yaml"
259+
(@repo_root / "cfgs" / "#{config_path_or_name}.yaml").realpath
234260
else
235261
T.absurd(config_path_or_name)
236262
end
237263

238-
@cfg_archs ||= {}
239-
return @cfg_archs[config_path] if @cfg_archs.key?(config_path)
264+
config_yaml = YAML.safe_load_file(config_path)
265+
info = ConfigInfo.new(name: config_yaml["name"], path: config_path, unresolved_yaml: config_yaml)
266+
@cfg_info[config_path] = info
267+
@cfg_info[info.name] = info
268+
end
269+
private :cfg_info
240270

241-
config_yaml = resolve_config(config_path)
242-
config_name = config_yaml["name"]
271+
# resolve the specification for a config, and return a ConfiguredArchitecture
272+
sig { params(config_path_or_name: T.any(Pathname, String)).returns(Udb::ConfiguredArchitecture) }
273+
def cfg_arch_for(config_path_or_name)
274+
config_info = cfg_info(config_path_or_name)
275+
276+
@cfg_archs ||= {}
277+
return @cfg_archs[config_info.path] if @cfg_archs.key?(config_info.path)
243278

244-
resolve_arch(config_yaml)
279+
resolve_config(config_info.path)
280+
resolve_arch(config_info.unresolved_yaml)
245281

246-
@cfg_archs[config_path] = Udb::ConfiguredArchitecture.new(
247-
config_name,
248-
Udb::AbstractConfig.create(gen_path / "cfgs" / "#{config_name}.yaml"),
249-
gen_path / "resolved_spec" / config_name
282+
@cfg_archs[config_info.path] = Udb::ConfiguredArchitecture.new(
283+
config_info.name,
284+
Udb::AbstractConfig.create(gen_path / "cfgs" / "#{config_info.name}.yaml"),
285+
resolved_spec_path(config_info.name)
250286
)
251287
end
252288
end

0 commit comments

Comments
 (0)