11# frozen_string_literal: true
2+ #
3+ # Contains Rake rules to generate adoc, PDF, and HTML for a CRD.
24
35require "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-
127CERT_DOC_DIR = Pathname . new "#{ $root} /backends/crd"
138
149Dir . 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
12366end
12467
12568namespace :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
160109end
0 commit comments