-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
160 lines (147 loc) · 4.91 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
require "rake"
require "mkmf" # for find_executable
require "fileutils" # Cross Platform
#############
# Variables #
#############
# Common
CWD = File.expand_path(__dir__)
DOXYFILE = "Doxyfile-syme.cfg"
NIXSHELL = File.join(CWD, "shell.nix")
SYMESRC = File.join(CWD, "projects/symengine/symengine")
OUTPUB = File.join(CWD, "public")
# API
BASEAPI = File.join(CWD, "docs/")
SPHINXAPI = File.join(BASEAPI, "Sphinx")
DOXXML = File.join(BASEAPI, "Doxygen/gen_docs/xml")
OUTAPI = File.join(CWD, "public")
DOXLUA = File.join(BASEAPI, "doxyrestConf.lua")
# Coverage
OUTCOV = File.join(OUTAPI, "doc_coverage")
DOCCOV = File.join(OUTAPI, "doc-coverage.info")
# Exception
class RunnerException < StandardError
def initialize(msg = "Undefined runner, supports nix and system (with conda)", exception_type = "custom")
@exception_type = exception_type
super(msg)
end
end
class ExecException < StandardError
def initialize(msg = "Missing an application, typically doxyrest", exception_type = "custom")
@exception_type = exception_type
super(msg)
end
end
#########
# Tasks #
#########
# Genric
task :default => :darkServe
desc "Clean the generated content"
task :clean do
rm_rf "public"
rm_rf "docs/Doxygen/gen_docs"
rm_rf "docs/Sphinx/build"
rm_rf "docs/Sphinx/gen_doxyrest"
end
desc "Serve site with darkhttpd"
task :darkServe, [:port, :runner] do |task, args|
args.with_defaults(:port => "1336", :runner => "system")
if args.runner == "system"
sh "darkhttpd #{OUTAPI} --port #{args.port}"
elsif args.runner == "nix"
sh "nix-shell #{NIXSHELL} --run 'darkhttpd #{OUTAPI} --port #{args.port}'"
else
raise RunnerException.new
end
end
namespace "api" do
desc "Build full API documentation"
task :mkDocs, [:builder, :runner] do |taks, args|
args.with_defaults(:builder => "html", :runner => "system")
Rake::Task["api:mkSphinx"].invoke(args.builder, args.runner)
end
desc "Build doxygen API"
task :mkDoxy, [:runner] do |task, args|
args.with_defaults(:runner => "system")
Dir.chdir(to = File.join(CWD, "docs/Doxygen"))
if args.runner == "system"
system("doxygen", DOXYFILE)
elsif args.runner == "nix"
sh "nix-shell #{NIXSHELL} --run 'doxygen #{DOXYFILE}'"
else
raise RunnerException.new
end
end
desc "Build doxyrest API"
task :mkDoxyRest, [:builder, :runner] => "api:mkDoxy" do |task, args|
args.with_defaults(:builder => "html", :runner => "system")
puts "Disabled for now"
# Dir.chdir(to = CWD)
# if args.runner == "system"
# if find_executable "doxyrest"
# sh "doxyrest -c #{DOXLUA}"
# elsif find_executable "nix"
# begin
# puts "System has no doxyrest, trying nix"
# sh "nix-shell #{NIXSHELL} --run 'doxyrest -c #{DOXLUA}'"
# rescue
# puts "Falling back to conda"
# sh "conda run doxyrest -c #{DOXLUA}"
# end
# else
# raise ExecException.new
# end
# elsif args.runner == "nix"
# begin
# puts "System has no doxyrest, trying nix"
# sh "nix-shell #{NIXSHELL} --run 'doxyrest -c #{DOXLUA}'"
# rescue
# puts "Falling back to conda"
# sh "conda run doxyrest -c #{DOXLUA}"
# end
# else
# raise RunnerException.new
# end
end
desc "Build Sphinx API docs"
task :mkSphinx, [:builder, :runner] => ["api:mkDoxyRest"] do |task, args|
args.with_defaults(:builder => "html", :runner => "system")
if args.runner == "system"
sh "conda run sphinx-build #{SPHINXAPI} #{OUTAPI} -b #{args.builder}"
elsif args.runner == "nix"
begin
sh "nix-shell #{NIXSHELL} --run 'sphinx-build #{SPHINXAPI} #{OUTAPI} -b #{args.builder}'"
rescue
puts "Handling the case where nix errors out by rescuing with conda"
sh "conda run sphinx-build #{SPHINXAPI} #{OUTAPI} -b #{args.builder}"
end
else
raise RunnerException.new
end
puts "... Also preventing trigger happy gh-pages rubbish"
sh "touch #{OUTPUB}/.nojekyll"
end
desc "Build API Coverage"
task :mkDocCover, [:runner] => ["api:mkDoxy"] do |task, args|
args.with_defaults(:runner => "system")
if args.runner == "system"
sh "conda run python3 -m coverxygen --xml-dir #{DOXXML} --src-dir #{SYMESRC} --output #{DOCCOV}"
elsif args.runner == "nix"
sh "nix-shell #{NIXSHELL} --run 'python3 -m coverxygen --xml-dir #{DOXXML} --src-dir #{SYMESRC} --output #{DOCCOV}'"
else
raise RunnerException.new
end
end
desc "Build HTML Coverage Report"
task :mkDocCovHTML, [:runner] => ["api:mkDocCover"] do |t, args|
args.with_defaults(:runner => "system")
if args.runner == "system"
sh "genhtml --no-function-coverage --no-branch-coverage #{DOCCOV} -o #{OUTCOV}"
elsif args.runner == "nix"
sh "nix-shell #{NIXSHELL} --run 'genhtml --no-function-coverage --no-branch-coverage #{DOCCOV} -o #{OUTCOV}'"
else
raise RunnerException.new
end
end
end