Make the doc Rakefile a little more helpful when it's missing javadoc
[arvados.git] / doc / Rakefile
1 #!/usr/bin/env rake
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: CC-BY-SA-3.0
5
6 require "rubygems"
7 require "colorize"
8
9 #task :generate => [ :realclean, 'sdk/python/arvados/index.html', 'sdk/R/arvados/index.html', 'sdk/java-v2/javadoc/index.html' ] do
10 task :generate => [ :realclean, 'sdk/python/arvados/index.html', 'sdk/java-v2/javadoc/index.html' ] do
11   vars = ['baseurl', 'arvados_cluster_uuid', 'arvados_api_host', 'arvados_workbench_host']
12   vars.each do |v|
13     if ENV[v]
14       website.config.h[v] = ENV[v]
15     end
16   end
17 end
18
19 file "sdk/python/arvados/index.html" do |t|
20   `which epydoc`
21   if $? == 0
22     STDERR.puts `epydoc --html --parse-only -o sdk/python/arvados ../sdk/python/arvados/ 2>&1`
23     raise if $? != 0
24   else
25     puts "Warning: epydoc not found, Python documentation will not be generated".colorize(:light_red)
26   end
27 end
28
29 file "sdk/R/arvados/index.html" do |t|
30   `which R`
31   if $? == 0
32     tgt = Dir.pwd
33     Dir.mkdir("sdk/R")
34     Dir.mkdir("sdk/R/arvados")
35     docfiles = []
36     Dir.chdir("../sdk/R/") do
37       STDERR.puts `Rscript createDoc.R README.Rmd #{tgt}/sdk/R/README.md 2>&1`
38       Dir.entries("man").each do |rd|
39         if rd[-3..-1] == ".Rd"
40           htmlfile = "#{rd[0..-4]}.html"
41           `R CMD Rdconv -t html man/#{rd} > #{tgt}/sdk/R/arvados/#{htmlfile}`
42           docfiles << htmlfile
43         end
44       end
45     end
46     raise if $? != 0
47
48     File.open("sdk/R/README.md", "r") do |rd|
49     File.open("sdk/R/index.html.md", "w") do |fn|
50       fn.write(<<-EOF
51 ---
52 layout: default
53 navsection: sdk
54 navmenu: R
55 title: "R SDK Overview"
56 ...
57
58 #{rd.read.gsub(/^```$/, "~~~").gsub(/^```(\w)$/, "~~~\\1")}
59 EOF
60               )
61       end
62     end
63
64     File.open("sdk/R/arvados/index.html.textile.liquid", "w") do |fn|
65       fn.write(<<-EOF
66 ---
67 layout: default
68 navsection: sdk
69 navmenu: R
70 title: "R Reference"
71 ...
72 {% comment %}
73 Copyright (C) The Arvados Authors. All rights reserved.
74
75 SPDX-License-Identifier: CC-BY-SA-3.0
76 {% endcomment %}
77
78 EOF
79               )
80
81       docfiles.sort.each do |d|
82         fn.write("* \"#{d[0..-6]}\":#{d}\n")
83       end
84
85     end
86   else
87     puts "Warning: R not found, R documentation will not be generated".colorize(:light_red)
88   end
89 end
90
91 file "sdk/java-v2/javadoc/index.html" do |t|
92   `which java`
93   if $? == 0
94     `which gradle`
95     if $? != 0
96       puts "Warning: gradle not found, java sdk documentation will not be generated".colorize(:light_red)
97     else
98       tgt = Dir.pwd
99       docfiles = []
100       Dir.chdir("../sdk/java-v2") do
101         STDERR.puts `gradle javadoc 2>&1`
102         raise if $? != 0
103       end
104       cp_r("../sdk/java-v2/build/docs/javadoc", "sdk/java-v2")
105       raise if $? != 0
106     end
107   else
108     puts "Warning: java not found, java sdk documentation will not be generated".colorize(:light_red)
109   end
110 end
111
112 task :linkchecker => [ :generate ] do
113   Dir.chdir(".site") do
114     `which linkchecker`
115     if $? == 0
116       system "linkchecker index.html --ignore-url='!file://'" or exit $?.exitstatus
117     else
118       puts "Warning: linkchecker not found, skipping run".colorize(:light_red)
119     end
120   end
121 end
122
123 task :clean do
124   rm_rf "sdk/python/arvados"
125   rm_rf "sdk/R"
126   rm_rf "sdk/java-v2/javadoc"
127 end
128
129 require "zenweb/tasks"
130 load "zenweb-textile.rb"
131 load "zenweb-liquid.rb"
132
133 task :extra_wirings do
134   $website.pages["sdk/python/python.html.textile.liquid"].depends_on("sdk/python/arvados/index.html")
135 end