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