File: doc.rake

package info (click to toggle)
mruby 3.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,584 kB
  • sloc: ansic: 51,933; ruby: 29,510; yacc: 7,077; cpp: 517; makefile: 51; sh: 42
file content (118 lines) | stat: -rw-r--r-- 3,593 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
MRuby.autoload :Documentation, 'mruby/doc'

desc 'generate document'
task :doc => %w[doc:api doc:capi]

namespace :doc do
  desc 'generate yard docs'
  task :api do
    begin
      sh "mrbdoc"
    rescue
      puts "ERROR: To generate YARD documentation, you should install the yard-coderay and yard-mruby gems."
      puts "  $ gem install yard-coderay yard-mruby"
      puts "https://yardoc.org/"
      puts "https://rubygems.org/gems/yard-mruby"
      puts "https://rubygems.org/gems/yard-coderay"
    end
  end

  desc 'generate doxygen docs'
  task :capi do
    begin
      sh "doxygen Doxyfile"
    rescue
      puts "ERROR: To generate C API documentation, you should install Doxygen and Graphviz."
      puts "On Debian-based systems:"
      puts "  $ sudo apt-get install doxygen graphviz"
      puts "On RHEL-based systems:"
      puts "  $ sudo dnf install doxygen graphviz"
      puts "On macOS-based systems:"
      puts "  $ brew install doxygen graphviz"
      puts "https://www.doxygen.nl/"
      puts "https://graphviz.org/"
    end
  end

  desc 'clean all built docs'
  task :clean => %w[clean:api clean:capi]

  namespace :clean do
    desc 'clean yard docs'
    task :api do
      rm_rf %w(doc/api .yardoc)
    end

    desc 'clean doxygen docs'
    task :capi do
      rm_rf 'doc/capi'
    end
  end

  namespace :view do
    desc 'open yard docs'
    task :api do
      if RUBY_PLATFORM.include?('darwin')
        sh 'open doc/api/index.html'
      else
        sh 'xdg-open doc/api/index.html'
      end
    end

    desc 'open doxygen docs'
    task :capi do
      if RUBY_PLATFORM.include?('darwin')
        sh 'open doc/capi/html/index.html'
      else
        sh 'xdg-open doc/capi/html/index.html'
      end
    end
  end

  desc 'update doc/internal/opcode.md'
  task 'update-opcode.md' do
    unless system(*%W(git --git-dir #{MRUBY_ROOT}/.git --work-tree #{MRUBY_ROOT} diff --quiet @ -- doc/internal/opcode.md))
      abort <<~'ERRMESG'
        The file "doc/internal/opcode.md" has been modified but not committed.
        To avoid loss of your edits, the automatic update process has been aborted.
      ERRMESG
    end

    MRuby::Documentation.update_opcode_md
  end

  task 'update-index' do
    rev_order = %w(doc/internal/ doc/guides/ doc/)
    cmd = %W(git --git-dir #{MRUBY_ROOT}/.git --work-tree #{MRUBY_ROOT} ls-files -- doc/*.md)
    doc = IO.popen(cmd, "r") { |io| io.read.split("\n") }
    doc.sort_by! { |e| [-rev_order.index { |o| e.start_with?(o) }, e] }
    readme_path = File.join(MRUBY_ROOT, "README.md")
    readme = File.read(readme_path)
    matched = false
    mark_begin = "<!-- BEGIN OF MRUBY DOCUMENT INDEX -->\n"
    mark_end = "<!-- END OF MRUBY DOCUMENT INDEX -->\n"
    readme1 = readme.sub(/^#{mark_begin}\n\K.*(?=^\n#{mark_end})/m) {
      matched = true
      doc.each_with_object("") { |d, a|
        summary = File.open(File.join(MRUBY_ROOT, d)) { |f|
          f.each_line.first.slice(/^<!--\s*summary:\s*(.*?)\s*-->/, 1)
        }
        if summary
          summary = "Internal Implementation / #{summary}" if d.start_with?("doc/internal/")
          a << "- [#{summary}](#{d})\n"
        end
      }
    }
    raise "missing marker for document index in README.md" unless matched
    File.write(readme_path, readme1, mode: "wb") unless readme == readme1
  end
end

# deprecated
task "api_doc" => "doc:api"
task "capi_doc" => "doc:capi"
task "clean_doc" => "doc:clean"
task "clean_api_doc" => "doc:clean:api"
task "clean_capi_doc" => "doc:clean:capi"
task "view_api" => "doc:view:api"
task "view_capi" => "doc:view:capi"