Skip to content

Commit 7e83edf

Browse files
Created portfolio tasks.rake file and moved common Rake code from profile & CRD tasks.rake into it.
1 parent 7b0bd31 commit 7e83edf

File tree

7 files changed

+180
-200
lines changed

7 files changed

+180
-200
lines changed

.github/workflows/pages.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@ jobs:
7676
- name: Copy RVI20 Profile Release PDF
7777
run: cp gen/profile_doc/pdf/RVA20.pdf _site/pdfs/RVI20.pdf
7878
- name: Create MC100-32 PDF Spec
79-
run: ./do gen:proc_cert_model_pdf[MC100-32]
79+
run: ./do gen:proc_crd_pdf[MC100-32]
8080
- name: Copy MC100-32 PDF
8181
run: cp gen/crd/pdf/MC100-32.pdf _site/pdfs/MC100-32.pdf
8282
- name: Create MC100-32 HTML Spec
83-
run: ./do gen:proc_cert_model_html[MC100-32]
83+
run: ./do gen:proc_crd_html[MC100-32]
8484
- name: Copy MC100-32 HTML
8585
run: cp gen/crd/html/MC100-32.html _site/htmls/MC100-32.html
8686
- name: Create MC100-64 PDF Spec
87-
run: ./do gen:proc_cert_model_pdf[MC100-64]
87+
run: ./do gen:proc_crd_pdf[MC100-64]
8888
- name: Copy MC100-64 PDF
8989
run: cp gen/crd/pdf/MC100-64.pdf _site/pdfs/MC100-64.pdf
9090
- name: Create MC100-64 HTML Spec
91-
run: ./do gen:proc_cert_model_html[MC100-64]
91+
run: ./do gen:proc_crd_html[MC100-64]
9292
- name: Copy MC100-64 HTML
9393
un: cp gen/crd/html/MC100-64.html _site/htmls/MC100-64.html
9494
- name: Copy manual html

.github/workflows/regress.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
name: Build container
132132
run: ./bin/build_container
133133
- name: Generate extension PDF
134-
run: ./do gen:proc_cert_model_pdf[MockProcCertModel]
134+
run: ./do gen:proc_crd_pdf[MockProcCertModel]
135135
regress-gen-profile:
136136
runs-on: ubuntu-latest
137137
needs: regress-smoke

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ _site
1717
images
1818
*.bak
1919
*.log
20-
*.bak

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": "MC100-32",
77
"request": "launch",
88
"command": "bundle exec rake",
9-
"script": "gen:proc_cert_model_pdf[MC100-32]",
9+
"script": "gen:proc_crd_pdf[MC100-32]",
1010
"args": [],
1111
"askParameters": false
1212
},
@@ -15,7 +15,7 @@
1515
"name": "MC200-32",
1616
"request": "launch",
1717
"command": "bundle exec rake",
18-
"script": "gen:proc_cert_model_pdf[MC200-32]",
18+
"script": "gen:proc_crd_pdf[MC200-32]",
1919
"args": [],
2020
"askParameters": false
2121
},

backends/crd/tasks.rake

Lines changed: 42 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,38 @@
11
# frozen_string_literal: true
2+
#
3+
# Contains Rake rules to generate adoc, PDF, and HTML for a CRD.
24

35
require "pathname"
46

5-
require "asciidoctor-pdf"
6-
require "asciidoctor-diagram"
7-
8-
require_relative "#{$lib}/idl/passes/gen_adoc"
9-
10-
puts "UPDATE: Inside crd tasks.rake"
11-
127
CERT_DOC_DIR = Pathname.new "#{$root}/backends/crd"
138

149
Dir.glob("#{$root}/arch/proc_cert_model/*.yaml") do |f|
15-
proc_cert_model_name = File.basename(f, ".yaml")
16-
proc_cert_model_obj = YAML.load_file(f, permitted_classes: [Date])
17-
proc_cert_class_name = File.basename(proc_cert_model_obj['class']['$ref'].split("#")[0], ".yaml")
18-
raise "Ill-formed processor certificate model file #{f}: missing 'class' field" if proc_cert_model_obj['class'].nil?
10+
model_name = File.basename(f, ".yaml")
11+
model_obj = YAML.load_file(f, permitted_classes: [Date])
12+
class_name = File.basename(model_obj['class']['$ref'].split("#")[0], ".yaml")
13+
raise "Ill-formed processor certificate model file #{f}: missing 'class' field" if model_obj['class'].nil?
1914

20-
file "#{$root}/gen/crd/adoc/#{proc_cert_model_name}.adoc" => [
15+
file "#{$root}/gen/crd/adoc/#{model_name}.adoc" => [
2116
__FILE__,
22-
"#{$root}/arch/proc_cert_class/#{proc_cert_class_name}.yaml",
23-
"#{$root}/arch/proc_cert_model/#{proc_cert_model_name}.yaml",
17+
"#{$root}/arch/proc_cert_class/#{class_name}.yaml",
18+
"#{$root}/arch/proc_cert_model/#{model_name}.yaml",
2419
"#{$root}/lib/arch_obj_models/certificate.rb",
2520
"#{$root}/lib/arch_obj_models/portfolio.rb",
2621
"#{$root}/lib/portfolio_design.rb",
2722
"#{$root}/lib/design.rb",
2823
"#{CERT_DOC_DIR}/templates/crd.adoc.erb"
2924
] do |t|
30-
# Ensure that unconfigured resolved architecture called "_" exists.
31-
Rake::Task["#{$root}/.stamps/resolve-_.stamp"].invoke
32-
33-
# Create architecture object so we can have it create the ProcCertModel.
34-
# Use the unconfigured resolved architecture called "_".
35-
arch = Architecture.new("RISC-V Architecture", $root / "gen" / "resolved_arch" / "_")
25+
arch = pf_create_arch
3626

3727
# Create ProcCertModel for specific processor certificate model as specified in its arch YAML file.
3828
# The Architecture object also creates all other portfolio-related class instances from their arch YAML files.
3929
# None of these objects are provided with a Design object when created.
40-
puts "UPDATE: Creating ProcCertModel for #{proc_cert_model_name}"
41-
proc_cert_model = arch.proc_cert_model(proc_cert_model_name)
30+
puts "UPDATE: Creating ProcCertModel for #{model_name}"
31+
proc_cert_model = arch.proc_cert_model(model_name)
4232

43-
puts "UPDATE: Creating PortfolioDesign using processor certificate model #{proc_cert_model_name}"
4433
# Create the one PortfolioDesign object required for the ERB evaluation.
45-
portfolio_design = PortfolioDesign.new(proc_cert_model_name, arch, [proc_cert_model])
34+
puts "UPDATE: Creating PortfolioDesign using processor certificate model #{model_name}"
35+
portfolio_design = PortfolioDesign.new(model_name, arch, [proc_cert_model])
4636

4737
# Create empty binding and then specify explicitly which variables the ERB template can access.
4838
# Seems to use this method name in stack backtraces (hence its name).
@@ -57,104 +47,63 @@ Dir.glob("#{$root}/arch/proc_cert_model/*.yaml") do |f|
5747
erb_binding.local_variable_set(:proc_cert_model, proc_cert_model)
5848
erb_binding.local_variable_set(:portfolio, proc_cert_model)
5949

60-
template_path = Pathname.new("#{CERT_DOC_DIR}/templates/crd.adoc.erb")
61-
erb = ERB.new(File.read(template_path), trim_mode: "-")
62-
erb.filename = template_path.to_s
63-
64-
FileUtils.mkdir_p File.dirname(t.name)
65-
66-
# Convert ERB to final ASCIIDOC. Note that this code is broken up into separate function calls
67-
# each with a variable name to aid in running a command-line debugger on this code.
68-
puts "UPDATE: Converting ERB template to adoc for #{proc_cert_model_name}"
69-
erb_result = erb.result(erb_binding)
70-
erb_result_monospace_converted_to_links = portfolio_design.find_replace_links(erb_result)
71-
erb_result_with_links_added = portfolio_design.find_replace_links(erb_result_monospace_converted_to_links)
72-
erb_result_with_links_resolved = AsciidocUtils.resolve_links(erb_result_with_links_added)
73-
74-
File.write(t.name, erb_result_with_links_resolved)
75-
puts "UPDATE: Generated adoc source at #{t.name}"
50+
pf_create_adoc("#{CERT_DOC_DIR}/templates/crd.adoc.erb", erb_binding, t.name, portfolio_design)
7651
end
7752

78-
file "#{$root}/gen/crd/pdf/#{proc_cert_model_name}.pdf" => [
53+
file "#{$root}/gen/crd/pdf/#{model_name}.pdf" => [
7954
__FILE__,
80-
"#{$root}/gen/crd/adoc/#{proc_cert_model_name}.adoc"
55+
"#{$root}/gen/crd/adoc/#{model_name}.adoc"
8156
] do |t|
82-
adoc_file = "#{$root}/gen/crd/adoc/#{proc_cert_model_name}.adoc"
83-
FileUtils.mkdir_p File.dirname(t.name)
84-
sh [
85-
"asciidoctor-pdf",
86-
"-w",
87-
"-v",
88-
"-a toc",
89-
"-a compress",
90-
"-a pdf-theme=#{$root}/ext/docs-resources/themes/riscv-pdf.yml",
91-
"-a pdf-fontsdir=#{$root}/ext/docs-resources/fonts",
92-
"-a imagesdir=#{$root}/ext/docs-resources/images",
93-
"-r asciidoctor-diagram",
94-
"-r #{$root}/backends/ext_pdf_doc/idl_lexer",
95-
"-o #{t.name}",
96-
adoc_file
97-
].join(" ")
98-
puts "UPDATE: Generated PDF at #{t.name}"
57+
pf_adoc2pdf("#{$root}/gen/crd/adoc/#{model_name}.adoc", t.name)
9958
end
10059

101-
file "#{$root}/gen/crd/html/#{proc_cert_model_name}.html" => [
60+
file "#{$root}/gen/crd/html/#{model_name}.html" => [
10261
__FILE__,
103-
"#{$root}/gen/crd/adoc/#{proc_cert_model_name}.adoc"
62+
"#{$root}/gen/crd/adoc/#{model_name}.adoc"
10463
] do |t|
105-
adoc_file = "#{$root}/gen/crd/adoc/#{proc_cert_model_name}.adoc"
106-
FileUtils.mkdir_p File.dirname(t.name)
107-
108-
puts "UPDATE: Generating PDF at #{t.name}"
109-
sh [
110-
"asciidoctor",
111-
"-w",
112-
"-v",
113-
"-a toc",
114-
"-a imagesdir=#{$root}/ext/docs-resources/images",
115-
"-b html5",
116-
"-r asciidoctor-diagram",
117-
"-r #{$root}/backends/ext_pdf_doc/idl_lexer",
118-
"-o #{t.name}",
119-
adoc_file
120-
].join(" ")
121-
puts "UPDATE: Generated PDF at #{t.name}"
64+
pf_adoc2html("#{$root}/gen/crd/adoc/#{model_name}.adoc", t.name)
12265
end
12366
end
12467

12568
namespace :gen do
12669
desc <<~DESC
127-
Generate certificate documentation for a specific version as a PDF.
70+
Generate CRD (Certification Requirements Document) as a PDF.
12871
12972
Required options:
130-
proc_cert_model_name - The key of the certification model under arch/proc_cert_model
73+
model_name - The name of the certification model under arch/proc_cert_model
13174
DESC
132-
task :proc_cert_model_pdf, [:proc_cert_model_name] do |_t, args|
133-
proc_cert_model_name = args[:proc_cert_model_name]
134-
if proc_cert_model_name.nil?
135-
warn "Missing required option: 'proc_cert_model_name'"
75+
task :proc_crd_pdf, [:model_name] do |_t, args|
76+
model_name = args[:model_name]
77+
if model_name.nil?
78+
warn "Missing required option: 'model_name'"
13679
exit 1
13780
end
13881

139-
unless File.exist?("#{$root}/arch/proc_cert_model/#{proc_cert_model_name}.yaml")
140-
warn "No certification model named '#{proc_cert_model_name}' found in arch/proc_cert_model"
82+
unless File.exist?("#{$root}/arch/proc_cert_model/#{model_name}.yaml")
83+
warn "No certification model named '#{model_name}' found in arch/proc_cert_model"
14184
exit 1
14285
end
14386

144-
Rake::Task["#{$root}/gen/crd/pdf/#{proc_cert_model_name}.pdf"].invoke
87+
Rake::Task["#{$root}/gen/crd/pdf/#{model_name}.pdf"].invoke
14588
end
14689

147-
task :proc_cert_model_html, [:proc_cert_model_name] do |_t, args|
148-
if args[:proc_cert_model_name].nil?
149-
warn "Missing required option: 'proc_cert_model_name'"
90+
desc <<~DESC
91+
Generate CRD (Certification Requirements Document) as an HTML file.
92+
93+
Required options:
94+
model_name - The name of the certification model under arch/proc_cert_model
95+
DESC
96+
task :proc_crd_html, [:model_name] do |_t, args|
97+
if args[:model_name].nil?
98+
warn "Missing required option: 'model_name'"
15099
exit 1
151100
end
152101

153-
unless File.exist?("#{$root}/arch/proc_cert_model/#{args[:proc_cert_model_name]}.yaml")
154-
warn "No certification model named '#{args[:proc_cert_model_name]}' found in arch/proc_cert_model"
102+
unless File.exist?("#{$root}/arch/proc_cert_model/#{args[:model_name]}.yaml")
103+
warn "No certification model named '#{args[:model_name]}' found in arch/proc_cert_model"
155104
exit 1
156105
end
157106

158-
Rake::Task["#{$root}/gen/crd/html/#{args[:proc_cert_model_name]}.html"].invoke
107+
Rake::Task["#{$root}/gen/crd/html/#{args[:model_name]}.html"].invoke
159108
end
160109
end

backends/portfolios/tasks.rake

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# frozen_string_literal: true
2+
#
3+
# Contains common methods called from portfolio-based tasks.rake files.
4+
5+
require "pathname"
6+
require "asciidoctor-pdf"
7+
require "asciidoctor-diagram"
8+
require_relative "#{$lib}/idl/passes/gen_adoc"
9+
10+
# @return [Architecture]
11+
def pf_create_arch
12+
# Ensure that unconfigured resolved architecture called "_" exists.
13+
Rake::Task["#{$root}/.stamps/resolve-_.stamp"].invoke
14+
15+
# Create architecture object so we can have it create the ProcCertModel.
16+
# Use the unconfigured resolved architecture called "_".
17+
Architecture.new("RISC-V Architecture", $root / "gen" / "resolved_arch" / "_")
18+
end
19+
20+
# @param erb_template_pname [String] Path to ERB template file
21+
# @param erb_binding [Binding] Path to ERB template file
22+
# @param target_pname [String] Full name of adoc file being generated
23+
# @param portfolio_design [PortfolioDesign] Portfolio design being generated
24+
def pf_create_adoc(erb_template_pname, erb_binding, target_pname, portfolio_design)
25+
template_path = Pathname.new(erb_template_pname)
26+
erb = ERB.new(File.read(template_path), trim_mode: "-")
27+
erb.filename = template_path.to_s
28+
29+
FileUtils.mkdir_p File.dirname(target_pname)
30+
31+
# Convert ERB to final ASCIIDOC. Note that this code is broken up into separate function calls
32+
# each with a variable name to aid in running a command-line debugger on this code.
33+
puts "UPDATE: Converting ERB template to adoc for #{portfolio_design.name}"
34+
erb_result = erb.result(erb_binding)
35+
erb_result_monospace_converted_to_links = portfolio_design.find_replace_links(erb_result)
36+
erb_result_with_links_added = portfolio_design.find_replace_links(erb_result_monospace_converted_to_links)
37+
erb_result_with_links_resolved = AsciidocUtils.resolve_links(erb_result_with_links_added)
38+
39+
File.write(target_pname, erb_result_with_links_resolved)
40+
puts "UPDATE: Generated adoc in #{target_pname}"
41+
end
42+
43+
# @param adoc_file [String] Full name of source adoc file
44+
# @param target_pname [String] Full name of PDF file being generated
45+
def pf_adoc2pdf(adoc_file, target_pname)
46+
FileUtils.mkdir_p File.dirname(target_pname)
47+
48+
puts "UPDATE: Generating PDF in #{target_pname}"
49+
sh [
50+
"asciidoctor-pdf",
51+
"-w",
52+
"-v",
53+
"-a toc",
54+
"-a compress",
55+
"-a pdf-theme=#{$root}/ext/docs-resources/themes/riscv-pdf.yml",
56+
"-a pdf-fontsdir=#{$root}/ext/docs-resources/fonts",
57+
"-a imagesdir=#{$root}/ext/docs-resources/images",
58+
"-r asciidoctor-diagram",
59+
"-r #{$root}/backends/ext_pdf_doc/idl_lexer",
60+
"-o #{target_pname}",
61+
adoc_file
62+
].join(" ")
63+
puts "UPDATE: Generated PDF in #{target_pname}"
64+
end
65+
66+
# @param adoc_file [String] Full name of source adoc file
67+
# @param target_pname [String] Full name of HTML file being generated
68+
def pf_adoc2html(adoc_file, target_pname)
69+
FileUtils.mkdir_p File.dirname(target_pname)
70+
71+
puts "UPDATE: Generating HTML in #{target_pname}"
72+
sh [
73+
"asciidoctor",
74+
"-w",
75+
"-v",
76+
"-a toc",
77+
"-a imagesdir=#{$root}/ext/docs-resources/images",
78+
"-r asciidoctor-diagram",
79+
"-r #{$root}/backends/ext_pdf_doc/idl_lexer",
80+
"-o #{target_pname}",
81+
adoc_file
82+
].join(" ")
83+
puts "UPDATE: Generated HTML in #{target_pname}"
84+
end

0 commit comments

Comments
 (0)