Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/kbroch/rubocop pre commit #409

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@ repos:
rev: v3.19.1
hooks:
- id: pyupgrade

- repo: https://github.com/rubocop/rubocop
rev: v1.70.0
hooks:
- id: rubocop
additional_dependencies:
- rubocop-minitest
21 changes: 11 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace :test do
Architecture.new("#{$root}/resolved_arch").validate(show_progress: true)
puts "All files validate against their schema"
end
task idl: ["gen:resolved_arch", "#{$root}/.stamps/resolve-rv32.stamp", "#{$root}/.stamps/resolve-rv64.stamp"] do
task idl: ["gen:resolved_arch", "#{$root}/.stamps/resolve-rv32.stamp", "#{$root}/.stamps/resolve-rv64.stamp"] do
print "Parsing IDL code for RV32..."
cfg_arch32 = cfg_arch_for("rv32")
puts "done"
Expand All @@ -141,55 +141,56 @@ def insert_warning(str, from)
# insert a warning on the second line
lines = str.lines
first_line = lines.shift
lines.unshift(first_line, "\n# WARNING: This file is auto-generated from #{Pathname.new(from).relative_path_from($root)}").join("")
lines.unshift(first_line,
"\n# WARNING: This file is auto-generated from #{Pathname.new(from).relative_path_from($root)}").join("")
end
private :insert_warning

(3..31).each do |hpm_num|
file "#{$root}/arch/csr/Zihpm/mhpmcounter#{hpm_num}.yaml" => [
"#{$root}/arch/csr/Zihpm/mhpmcounterN.layout",
__FILE__
] do |t|
] do |t|
erb = ERB.new(File.read($root / "arch/csr/Zihpm/mhpmcounterN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/mhpmcounterN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/mhpmcounter#{hpm_num}h.yaml" => [
"#{$root}/arch/csr/Zihpm/mhpmcounterNh.layout",
__FILE__
] do |t|
] do |t|
erb = ERB.new(File.read($root / "arch/csr/Zihpm/mhpmcounterNh.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/mhpmcounterNh.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/mhpmevent#{hpm_num}.yaml" => [
"#{$root}/arch/csr/Zihpm/mhpmeventN.layout",
__FILE__
] do |t|
] do |t|
erb = ERB.new(File.read($root / "arch/csr/Zihpm/mhpmeventN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/mhpmeventN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/mhpmevent#{hpm_num}h.yaml" => [
"#{$root}/arch/csr/Zihpm/mhpmeventNh.layout",
__FILE__
] do |t|
] do |t|
erb = ERB.new(File.read($root / "arch/csr/Zihpm/mhpmeventNh.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/mhpmeventNh.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/hpmcounter#{hpm_num}.yaml" => [
"#{$root}/arch/csr/Zihpm/hpmcounterN.layout",
__FILE__
] do |t|
] do |t|
erb = ERB.new(File.read($root / "arch/csr/Zihpm/hpmcounterN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/hpmcounterN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/hpmcounter#{hpm_num}h.yaml" => [
"#{$root}/arch/csr/Zihpm/hpmcounterNh.layout",
__FILE__
] do |t|
] do |t|
erb = ERB.new(File.read($root / "arch/csr/Zihpm/hpmcounterNh.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/hpmcounterNh.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
Expand All @@ -200,7 +201,7 @@ end
file "#{$root}/arch/csr/I/pmpaddr#{pmpaddr_num}.yaml" => [
"#{$root}/arch/csr/I/pmpaddrN.layout",
__FILE__
] do |t|
] do |t|
erb = ERB.new(File.read($root / "arch/csr/I/pmpaddrN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/I/pmpaddrN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
Expand All @@ -211,7 +212,7 @@ end
file "#{$root}/arch/csr/I/pmpcfg#{pmpcfg_num}.yaml" => [
"#{$root}/arch/csr/I/pmpcfgN.layout",
__FILE__
] do |t|
] do |t|
erb = ERB.new(File.read($root / "arch/csr/I/pmpcfgN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/I/pmpcfgN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
Expand Down
8 changes: 3 additions & 5 deletions backends/certificate_doc/tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ CERT_DOC_DIR = Pathname.new "#{$root}/backends/certificate_doc"
Dir.glob("#{$root}/arch/certificate_model/*.yaml") do |f|
cert_model_name = File.basename(f, ".yaml")
cert_model_obj = YAML.load_file(f, permitted_classes: [Date])
cert_class_name = File.basename(cert_model_obj['class']['$ref'].split("#")[0], ".yaml")
raise "Ill-formed certificate model file #{f}: missing 'class' field" if cert_model_obj['class'].nil?
cert_class_name = File.basename(cert_model_obj["class"]["$ref"].split("#")[0], ".yaml")
raise "Ill-formed certificate model file #{f}: missing 'class' field" if cert_model_obj["class"].nil?

base = cert_model_obj["base"]
raise "Missing certificate model base" if base.nil?
Expand Down Expand Up @@ -46,12 +46,11 @@ Dir.glob("#{$root}/arch/certificate_model/*.yaml") do |f|
cert_model = cfg_arch.cert_model(cert_model_name)

# Set globals for ERB template.
portfolio = cert_model
cert_class = cert_model.cert_class
portfolio = cert_model
portfolio_class = cert_class

version = File.basename(t.name, '.adoc').split('-')[1..].join('-')
version = File.basename(t.name, ".adoc").split("-")[1..].join("-")

erb = ERB.new(File.read("#{CERT_DOC_DIR}/templates/certificate.adoc.erb"), trim_mode: "-")
erb.filename = "#{CERT_DOC_DIR}/templates/certificate.adoc.erb"
Expand Down Expand Up @@ -108,7 +107,6 @@ Dir.glob("#{$root}/arch/certificate_model/*.yaml") do |f|
adoc_file
].join(" ")
end

end

namespace :gen do
Expand Down
2 changes: 1 addition & 1 deletion backends/cfg_html_doc/adoc_gen.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require "ruby-prof"

# fill out templates for every csr, inst, ext, and func
["csr", "inst", "ext", "func"].each do |type|
rule %r{#{$root}/\.stamps/adoc-gen-#{type}s-.*\.stamp} => proc { |tname|
rule %r{#{$root}/\.stamps/adoc-gen-#{type}s-.*\.stamp} => proc { |_tname|
[
"#{CFG_HTML_DOC_DIR}/templates/#{type}.adoc.erb",
"#{$root}/lib/cfg_arch.rb",
Expand Down
7 changes: 4 additions & 3 deletions backends/cfg_html_doc/html_gen.rake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module AntoraUtils
when "csr"
"xref:csrs:#{name}.adoc##{name}-def[#{link_text.gsub(']', '\]')}]"
when "csr_field"
csr_name, field_name = name.split('.')
csr_name, field_name = name.split(".")
"xref:csrs:#{csr_name}.adoc##{csr_name}-#{field_name}-def[#{link_text.gsub(']', '\]')}]"
when "ext"
"xref:exts:#{name}.adoc##{name}-def[#{link_text.gsub(']', '\]')}]"
Expand Down Expand Up @@ -72,7 +72,7 @@ rule %r{#{$root}/gen/cfg_html_doc/.*/antora/modules/nav.adoc} => proc { |tname|
end

rule %r{#{$root}/gen/cfg_html_doc/.*/antora/modules/ROOT/pages/config.adoc} => proc { |tname|
config_name = Pathname.new(tname).relative_path_from("#{$root}/gen/cfg_html_doc").to_s.split("/")[0]
Pathname.new(tname).relative_path_from("#{$root}/gen/cfg_html_doc").to_s.split("/")[0]
[
"#{CFG_HTML_DOC_DIR}/templates/config.adoc.erb",
__FILE__
Expand Down Expand Up @@ -226,7 +226,8 @@ rule %r{#{$root}/\.stamps/html-gen-prose-.*\.stamp} => FileList[$root / "arch" /
config_name = Pathname.new(t.name).basename(".stamp").sub("html-gen-prose-", "")
FileUtils.rm_rf $root / "gen" / "cfg_html_doc" / config_name / "antora" / "modules" / "prose"
FileUtils.mkdir_p $root / "gen" / "cfg_html_doc" / config_name / "antora" / "modules" / "prose"
FileUtils.cp_r $root / "arch" / "prose", $root / "gen" / "cfg_html_doc" / config_name / "antora" / "modules" / "prose" / "pages"
FileUtils.cp_r $root / "arch" / "prose",
$root / "gen" / "cfg_html_doc" / config_name / "antora" / "modules" / "prose" / "pages"

Rake::Task["#{$root}/.stamps"].invoke

Expand Down
20 changes: 10 additions & 10 deletions backends/ext_pdf_doc/idl_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ def self.keywords_type

state :root do
rule ws, Text::Whitespace
rule %r{#.*}, Comment::Single
rule %r{"[^"]*"}, Str::Double
rule %r{[A-Z][a-zA-Z0-9]*}, Name::Constant
rule %r{(?:(?:[0-9]+)|(?:XLEN))?'s?[bodh]?[0-9_a-fA-F]+}, Num
rule %r/0x[0-9a-f]+[lu]*/i, Num::Hex
rule %r/0[0-7]+[lu]*/i, Num::Oct
rule %r{\d+}, Num::Integer
rule %r{(?:true|false|\$encoding|\$pc|\$signed|\$bits)}, Name::Builtin
rule %r{[.,;:\[\]\(\)\}\{]}, Punctuation
rule %r([~!%^&*+=\|?:<>/-]), Operator
rule(/#.*/, Comment::Single)
rule(/"[^"]*"/, Str::Double)
rule(/[A-Z][a-zA-Z0-9]*/, Name::Constant)
rule(/(?:(?:[0-9]+)|(?:XLEN))?'s?[bodh]?[0-9_a-fA-F]+/, Num)
rule(/0x[0-9a-f]+[lu]*/i, Num::Hex)
rule(/0[0-7]+[lu]*/i, Num::Oct)
rule(/\d+/, Num::Integer)
rule(/(?:true|false|\$encoding|\$pc|\$signed|\$bits)/, Name::Builtin)
rule(/[.,;:\[\]()}{]/, Punctuation)
rule %r{[~!%^&*+=|?:<>/-]}, Operator
rule id do |m|
name = m[0]

Expand Down
6 changes: 3 additions & 3 deletions backends/ext_pdf_doc/tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module AsciidocUtils
when "csr"
"xref:#csr-#{name}-def[#{link_text.gsub(']', '\]')}]"
when "csr_field"
csr_name, field_name = name.split('.')
name.split(".")
# "xref:csrs:#{csr_name}.adoc##{csr_name}-#{field_name}-def[#{link_text.gsub(']', '\]')}]"
link_text
when "ext"
Expand All @@ -47,7 +47,7 @@ module AsciidocUtils
end
end

file "#{$root}/ext/docs-resources/themes/riscv-pdf.yml" => "#{$root}/.gitmodules" do |t|
file "#{$root}/ext/docs-resources/themes/riscv-pdf.yml" => "#{$root}/.gitmodules" do |_t|
system "git submodule update --init ext/docs-resources"
end

Expand Down Expand Up @@ -111,7 +111,7 @@ rule %r{#{$root}/gen/ext_pdf_doc/.*/html/.*_extension\.html} => proc { |tname|
end

rule %r{#{$root}/gen/ext_pdf_doc/.*/adoc/.*_extension\.adoc} => proc { |tname|
config_name = Pathname.new(tname).relative_path_from("#{$root}/gen/ext_pdf_doc").to_s.split("/")[0]
Pathname.new(tname).relative_path_from("#{$root}/gen/ext_pdf_doc").to_s.split("/")[0]
ext_name = Pathname.new(tname).basename(".adoc").to_s.split("_")[0..-2].join("_")
arch_yaml_paths =
if File.exist?("#{$root}/arch/ext/#{ext_name}.yaml")
Expand Down
1 change: 0 additions & 1 deletion backends/indexer/tasks.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

require "pathname"

namespace :gen do
Expand Down
28 changes: 16 additions & 12 deletions backends/manual/tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ end
# Rule to create a chapter page in antora hierarchy
rule %r{#{MANUAL_GEN_DIR}/.*/.*/antora/modules/chapters/pages/.*\.adoc} do |t|
parts = t.name.sub("#{MANUAL_GEN_DIR}/", "").split("/")
manual_name = parts[0]
version_name = parts[1]
parts[0]
parts[1]
manual = cfg_arch_for("_").manual(parts[0])
manual_version = manual.version(parts[1])
chapter_name = File.basename(t.name, ".adoc")
Expand Down Expand Up @@ -128,9 +128,7 @@ rule %r{#{MANUAL_GEN_DIR}/.*/.*/antora/nav.adoc} => proc { |tname|
raise "Can't find any manual version for '#{parts[0]}' '#{parts[1]}'" if manual_version.nil?

nav_template_path = $root / "backends" / "manual" / "templates" / "#{parts[0]}_nav.adoc.erb"
unless nav_template_path.exist?
raise "There is no navigation file for manual '#{parts[0]}' at '#{nav_template_path}'"
end
raise "There is no navigation file for manual '#{parts[0]}' at '#{nav_template_path}'" unless nav_template_path.exist?

raise "no cfg_arch" if manual_version.cfg_arch.nil?

Expand Down Expand Up @@ -298,8 +296,10 @@ end
rule %r{#{MANUAL_GEN_DIR}/.*/top/.*/antora/landing/modules/ROOT/pages/index.adoc} => proc { |tname|
parts = tname.sub("#{MANUAL_GEN_DIR}/", "").split("/")
manual_name = parts[0]
versions, _ = versions_from_env(ENV["MANUAL_NAME"])
version_files = Dir.glob($root / "arch" / "manual_version" / "**" / "*.yaml").select { |f| versions.include?(File.basename(f, ".yaml"))}
versions, = versions_from_env(ENV["MANUAL_NAME"])
version_files = Dir.glob($root / "arch" / "manual_version" / "**" / "*.yaml").select do |f|
versions.include?(File.basename(f, ".yaml"))
end
FileList[
__FILE__,
($root / "arch" / "manual" / "#{manual_name}.yaml").to_s,
Expand All @@ -325,8 +325,10 @@ end
rule %r{#{MANUAL_GEN_DIR}/.*/top/.*/antora/playbook/playbook.yml} => proc { |tname|
parts = tname.sub("#{MANUAL_GEN_DIR}/", "").split("/")
manual_name = parts[0]
versions, _ = versions_from_env(ENV["MANUAL_NAME"])
version_files = Dir.glob($root / "arch" / "manual_version" / "**" / "*.yaml").select { |f| versions.include?(File.basename(f, ".yaml"))}
versions, = versions_from_env(ENV["MANUAL_NAME"])
version_files = Dir.glob($root / "arch" / "manual_version" / "**" / "*.yaml").select do |f|
versions.include?(File.basename(f, ".yaml"))
end
FileList[
__FILE__,
($root / "arch" / "manual" / "#{manual_name}.yaml").to_s,
Expand Down Expand Up @@ -355,7 +357,7 @@ file $root / "ext" / "riscv-isa-manual" / "README.md" do
end

rule %r{#{MANUAL_GEN_DIR}/[^/]+/[^/]+/riscv-isa-manual/README.md} => ["#{$root}/ext/riscv-isa-manual/README.md"] do |t|
parts = t.name.sub("#{MANUAL_GEN_DIR}/","").split("/")
parts = t.name.sub("#{MANUAL_GEN_DIR}/", "").split("/")
manual_version_name = parts[1]

version_paths = Dir.glob("#{$root}/arch/manual_version/**/#{manual_version_name}.yaml")
Expand Down Expand Up @@ -396,7 +398,10 @@ namespace :gen do
DESC
desc html_manual_desc
task :html_manual do
raise ArgumentError, "Missing required environment variable MANUAL_NAME\n\n#{html_manual_desc}" if ENV["MANUAL_NAME"].nil?
if ENV["MANUAL_NAME"].nil?
raise ArgumentError,
"Missing required environment variable MANUAL_NAME\n\n#{html_manual_desc}"
end
raise ArgumentError, "Missing required environment variable VERSIONS\n\n#{html_manual_desc}" if ENV["VERSIONS"].nil?

versions, output_hash = versions_from_env(ENV["MANUAL_NAME"])
Expand All @@ -405,7 +410,6 @@ namespace :gen do
manual = cfg_arch.manual(ENV["MANUAL_NAME"])
raise "No manual named '#{ENV['MANUAL_NAME']}" if manual.nil?


# check out the correct version of riscv-isa-manual, if needed
versions.each do |version|
version_obj = cfg_arch.manual_version(version)
Expand Down
7 changes: 3 additions & 4 deletions cfgs/qc_iu/arch_overlay/csr/Xqci/gen_mcliciX.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

require 'erb'
require "erb"

pend_template = <<~YAML
# yaml-language-server: $schema=../../../../../schemas/csr_schema.json
Expand Down Expand Up @@ -47,12 +46,12 @@

root = File.dirname(__FILE__)

erb = ERB.new(pend_template, trim_mode: '-')
erb = ERB.new(pend_template, trim_mode: "-")
8.times do |num|
File.write("#{root}/qc_mclicip#{num}.yaml", erb.result(binding))
end

erb = ERB.new(en_template, trim_mode: '-')
erb = ERB.new(en_template, trim_mode: "-")
8.times do |num|
File.write("#{root}/qc_mclicie#{num}.yaml", erb.result(binding))
end
12 changes: 6 additions & 6 deletions lib/arch_obj_models/certificate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def initialize(obj_yaml, yaml_path, arch: nil)

# TODO: XXX: Add back in arch.name.
# See https://github.com/riscv-software-src/riscv-unified-db/pull/371
#puts "UPDATE: Creating CertModel object for #{name} using cfg #{cfg_arch.name}"
# puts "UPDATE: Creating CertModel object for #{name} using cfg #{cfg_arch.name}"
puts "UPDATE: Creating CertModel object for #{name}"
end

Expand All @@ -47,15 +47,15 @@ def tsc_profile

profile = cfg_arch.profile(@data["tsc_profile"])

raise "No profile '#{@data["tsc_profile"]}'" if profile.nil?
raise "No profile '#{@data['tsc_profile']}'" if profile.nil?

profile
end

# @return [CertClass] The certification class that this model belongs to.
def cert_class
cert_class = @cfg_arch.ref(@data["class"]['$ref'])
raise "No certificate class named '#{@data["class"]}'" if cert_class.nil?
cert_class = @cfg_arch.ref(@data["class"]["$ref"])
raise "No certificate class named '#{@data['class']}'" if cert_class.nil?

cert_class
end
Expand All @@ -81,7 +81,7 @@ def when_pretty
@data["when"].keys.map do |key|
case key
when "xlen"
"XLEN == #{@data["when"]["xlen"]}"
"XLEN == #{@data['when']['xlen']}"
when "param"
@data["when"]["param"].map do |param_name, param_value|
"Parameter #{param_name} == #{param_value}"
Expand Down Expand Up @@ -115,7 +115,7 @@ def when_pretty
@data["when"].keys.map do |key|
case key
when "xlen"
"XLEN == #{@data["when"]["xlen"]}"
"XLEN == #{@data['when']['xlen']}"
when "param"
@data["when"]["param"].map do |param_name, param_value|
"Parameter #{param_name} == #{param_value}"
Expand Down
Loading
Loading