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