Skip to content

Commit 2c6bbc7

Browse files
committed
[build] implement document generation tasks in Rakefile
1 parent 44b8b68 commit 2c6bbc7

File tree

3 files changed

+85
-32
lines changed

3 files changed

+85
-32
lines changed

Rakefile

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- mode: ruby -*-
22

3+
require 'English'
34
$LOAD_PATH.unshift File.expand_path('.')
45

56
require 'rake'
@@ -257,25 +258,21 @@ ie_generator.generate_type_mapping(
257258
out: 'cpp/iedriver/IEReturnTypes.h'
258259
)
259260

261+
desc 'Generate Javadocs'
260262
task javadocs: %i[//java/src/org/openqa/selenium/grid:all-javadocs] do
261-
rm_rf 'build/javadoc'
262-
mkdir_p 'build/javadoc'
263+
rm_rf 'build/docs/api/java'
264+
mkdir_p 'build/docs/api/java'
263265

264-
# Temporary hack, bazel is not outputting where things are so we need to do it manually.
265-
# This will only work on Posix based OSes
266-
Rake::Task['//java/src/org/openqa/selenium/grid:all-javadocs']
267266
out = 'bazel-bin/java/src/org/openqa/selenium/grid/all-javadocs.jar'
268267

269-
cmd = %{cd build/javadoc && jar xf "../../#{out}" 2>&1}
270-
if SeleniumRake::Checks.windows?
271-
cmd = cmd.gsub(/\//, '\\').gsub(/:/, ';')
272-
end
268+
cmd = %(cd build/docs/api/java && jar xf "../../../../#{out}" 2>&1)
269+
cmd = cmd.tr('/', '\\').tr(':', ';') if SeleniumRake::Checks.windows?
273270

274271
ok = system(cmd)
275-
ok or raise "could not unpack javadocs"
272+
ok or raise 'could not unpack javadocs'
276273

277-
File.open('build/javadoc/stylesheet.css', 'a') { |file|
278-
file.write(<<~EOF
274+
File.open('build/docs/api/java/stylesheet.css', 'a') do |file|
275+
file.write(<<~STYLE
279276
/* Custom selenium-specific styling */
280277
.blink {
281278
animation: 2s cubic-bezier(0.5, 0, 0.85, 0.85) infinite blink;
@@ -287,9 +284,9 @@ task javadocs: %i[//java/src/org/openqa/selenium/grid:all-javadocs] do
287284
}
288285
}
289286
290-
EOF
291-
)
292-
}
287+
STYLE
288+
)
289+
end
293290
end
294291

295292
file 'cpp/iedriver/sizzle.h' => ['//third_party/js/sizzle:sizzle:header'] do
@@ -553,16 +550,23 @@ namespace :py do
553550
end
554551

555552
desc 'Generate Python documentation'
556-
task docs: :update do
557-
sh 'tox -c py/tox.ini -e docs', verbose: true
553+
task :docs do
554+
FileUtils.rm_r('build/docs/api/py/', force: true)
555+
FileUtils.rm_r('build/docs/doctrees/', force: true)
556+
begin
557+
sh 'tox -c py/tox.ini -e docs', verbose: true
558+
rescue StandardError
559+
puts 'Ensure that tox is installed on your system'
560+
raise
561+
end
558562
end
559563

560564
desc 'Install Python wheel locally'
561565
task :install do
562566
Bazel.execute('build', [], '//py:selenium-wheel')
563567
begin
564568
sh 'pip install bazel-bin/py/selenium-*.whl'
565-
rescue
569+
rescue StandardError
566570
puts 'Ensure that Python and pip are installed on your system'
567571
raise
568572
end
@@ -590,6 +594,13 @@ namespace :rb do
590594
Bazel.execute('run', args, '//rb:selenium-webdriver')
591595
Bazel.execute('run', args, '//rb:selenium-devtools')
592596
end
597+
598+
desc 'Generate Ruby documentation'
599+
task :docs do
600+
FileUtils.rm_r('build/docs/api/rb/', force: true)
601+
Bazel.execute('run', [], '//rb:docs')
602+
FileUtils.cp_r('bazel-bin/rb/docs.rb.sh.runfiles/selenium/docs/api/rb/.', 'build/docs/api/rb')
603+
end
593604
end
594605

595606
namespace :dotnet do
@@ -635,6 +646,29 @@ namespace :dotnet do
635646
sh "dotnet nuget push #{asset} --api-key #{ENV.fetch('NUGET_API_KEY', nil)} --source https://api.nuget.org/v3/index.json"
636647
end
637648
end
649+
650+
desc 'Generate .NET documentation'
651+
task :docs do
652+
begin
653+
sh 'dotnet tool update -g docfx'
654+
rescue StandardError
655+
puts 'Please ensure that .NET SDK is installed.'
656+
raise
657+
end
658+
659+
begin
660+
sh 'docfx dotnet/docs/docfx.json'
661+
rescue StandardError
662+
case $CHILD_STATUS.exitstatus
663+
when 127
664+
raise 'Ensure the dotnet/tools directory is added to your PATH environment variable (e.g., `~/.dotnet/tools`)'
665+
when 255
666+
puts 'Build failed, likely because of DevTools namespacing. This is ok; continuing'
667+
else
668+
raise
669+
end
670+
end
671+
end
638672
end
639673

640674
namespace :java do
@@ -666,6 +700,9 @@ namespace :java do
666700

667701
desc 'Install jars to local m2 directory'
668702
task install: :'maven-install'
703+
704+
desc 'Generate Java documentation'
705+
task docs: :javadocs
669706
end
670707

671708
namespace :rust do
@@ -681,6 +718,16 @@ namespace :rust do
681718
end
682719
end
683720

721+
namespace :all do
722+
desc 'Update all API Documentation'
723+
task :docs do
724+
Rake::Task['java:docs'].invoke
725+
Rake::Task['py:docs'].invoke
726+
Rake::Task['rb:docs'].invoke
727+
Rake::Task['dotnet:docs'].invoke
728+
end
729+
end
730+
684731
at_exit do
685732
if File.exist?('.git') && !SeleniumRake::Checks.windows?
686733
system 'sh', '.git-fixfiles'

generate_api_docs.sh

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,26 @@ BRANCH_NAME=${2:-trunk}
55

66
case ${API_DOCS_LANGUAGE} in
77
java)
8-
./go javadocs || exit
8+
./go java:docs || exit
99
;;
1010
py)
11-
tox -c py/tox.ini -e docs || exit
11+
./go py:docs || exit
1212
;;
1313
rb)
14-
bazel run //rb:docs || exit
15-
docs="bazel-bin/rb/docs.rb.sh.runfiles/selenium/docs/api/rb"
14+
./go rb:docs || exit
1615
;;
1716
dotnet)
18-
# dotnet sdk should be installed
19-
# bazel should be installed
20-
dotnet tool update -g docfx
21-
docfx dotnet/docs/docfx.json
17+
./go dotnet:docs || exit
18+
;;
19+
all)
20+
./go all:docs || exit
2221
;;
2322
*)
2423
echo "Selenium API docs generation"
2524
echo "ERROR: unknown parameter \"$API_DOCS_LANGUAGE\""
2625
echo "Usage:"
2726
echo ""
28-
echo "./generate_api_docs.sh java|rb|py"
27+
echo "./generate_api_docs.sh java|rb|py|dotnet|all"
2928
echo -e "\t Example:"
3029
echo -e "\t Generating API docs for the Ruby bindings"
3130
echo -e "\t ./generate_api_docs.sh rb"
@@ -41,19 +40,26 @@ git pull || exit
4140
case ${API_DOCS_LANGUAGE} in
4241
java)
4342
rm -rf docs/api/java
44-
mv build/javadoc docs/api/java
43+
cp -r build/docs/api/java docs/api/java
4544
;;
4645
py)
4746
rm -rf docs/api/py
48-
mv build/docs/api/py docs/api/py
47+
cp -r build/docs/api/py docs/api/py
4948
;;
5049
rb)
5150
rm -rf docs/api/rb
52-
mv $docs docs/api/rb
51+
cp -r build/docs/api/rb docs/api/rb
5352
;;
5453
dotnet)
5554
rm -rf docs/api/dotnet
56-
mv build/docs/api/dotnet docs/api/dotnet
55+
cp -r build/docs/api/dotnet docs/api/dotnet
56+
;;
57+
all)
58+
rm -rf docs/api/java
59+
rm -rf docs/api/py
60+
rm -rf docs/api/rb
61+
rm -rf docs/api/dotnet
62+
cp -r build/docs/api/* docs/api/
5763
;;
5864
*)
5965
echo "ERROR: unknown parameter \"$API_DOCS_LANGUAGE\""

py/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ deps =
77
Jinja2==3.0.3
88
Sphinx==1.8.2
99

10-
commands = sphinx-build -b html -d ../build/doctrees docs/source ../build/docs/api/py {posargs}
10+
commands = sphinx-build -b html -d ../build/docs/doctrees docs/source ../build/docs/api/py {posargs}
1111

1212

1313
[testenv:mypy]

0 commit comments

Comments
 (0)