forked from cose-wg/cose-rfc8152bis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
28 lines (24 loc) · 760 Bytes
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require "rexml/document"
require "rexml/xpath"
include REXML
XMLFILE = "draft-ietf-cose-rfc8152bis-struct.xml"
CDDLFILE = "cose-extracted.cddl"
task :verify => [CDDLFILE, XMLFILE] do |t|
doc = Document.new(File.read(XMLFILE))
XPath.each(doc, "//sourcecode[@type='CBORdiag']/text()") do |snip|
IO.popen("diag2cbor.rb.bat | cddl #{CDDLFILE} v -", 'r+') do |io|
io.write snip.to_s.gsub("nil", "null").gsub(/\n\s*/, "")
io.close_write
p io.read
end
end
end
task :gen => CDDLFILE do |t|
sh "cddl #{t.source} g"
end
file CDDLFILE => [XMLFILE] do |t|
doc = Document.new(File.read(t.source))
File.open(t.name, "w") do |f|
f.puts XPath.match(doc, "//sourcecode[@type='CDDL']/text()").to_a.join.gsub(">", ">")
end
end