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
|
# Simple Rakefile for generating documentation from the CMake buildsystem using
# Rocco:
#
# https://rtomayko.github.io/rocco/
#
require 'pathname'
require 'rocco/tasks' # Not used, but serves as a good test that Rocco is installed
# Run everything from the project root directory
DOC_DIR = Pathname.new(__FILE__).realpath.dirname
DOC_OUTPUT_DIR = DOC_DIR + "html" + "docs"
ROOT_DIR = DOC_DIR.join '..'
Dir.chdir ROOT_DIR
# Gather all source code files
SOURCE_FILES = Dir['src/**/*.cpp']
# Check if prerequisites are met.
task :prerequisites do
raise "Failed to find 'rocco' script!" unless File.file?(rocco_binary)
puts "Found 'rocco' in '#{File.dirname(rocco_binary)}'!"
end
# Remove generated documentation files.
task :clean => [:prerequisites] do
html_files = Dir.chdir(DOC_OUTPUT_DIR) { Dir["**/*.html"] }
next if html_files.empty?
puts "Cleaning '#{DOC_OUTPUT_DIR}' (#{html_files.count} files):"
html_files.each do |f|
abs_f = DOC_OUTPUT_DIR + f
if abs_f.file? then
puts " * #{f}"
abs_f.delete
else
puts " ! #{f} is not a file"
end
end
end
# Generate documentation from comments
task :docs => [:prerequisites, :clean] do
ruby rocco_binary,
"--language=cmake",
"--output=#{DOC_OUTPUT_DIR}",
"--template=#{DOC_DIR + 'layout.mustache'}",
*SOURCE_FILES
puts <<-EOS
Done generating documentation, index page available at:
#{DOC_DIR + 'html' + 'index.html'}
EOS
end
# Make doc generation the default task
task :default => :docs
# Generate documentation and then view it. Launching a viewer currently assumes
# OS X. For Linux `xdg-open` would be used and `start` on Windows.
task :view => [:docs] do
exec "open #{DOC_DIR + 'html' + 'index.html'}"
end
# Asks 'Gem' for the path to 'rocco' to avoid dependency on proper search path.
def rocco_binary
_binary ||= Gem.bin_path("rocco", "rocco")
end
|