docurium 0.4.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ef759fe2bcc48694d8393ed1812d996149cd6852
4
- data.tar.gz: 12bbee6302d4f68c66af27c231a28cf0f9e306fc
2
+ SHA256:
3
+ metadata.gz: 4ace5599ba2e3394f8edf0f6dbe0a388c163a11f3b55548c1048c386c8e18c54
4
+ data.tar.gz: e4bf9b423afd1a32079b8c5722ab64f7140da1d43072bc7d66418a9c8bfb9601
5
5
  SHA512:
6
- metadata.gz: 077054ce5ca5c84bf529597a0e5345729fb329cef5e934bfc3deba2dcecdf8dfcdb24b2bf01d19d3ff21f85670a87cc6d0bdd1a1b5c02dacaa47dff9eb6ac289
7
- data.tar.gz: 5b7e76e3f66ebaed25c234135bf3c16db099f5f892796dbf9190a3297049255126eac7123f990263524d5e9af69d8e9b1aa64614cb2bcd5b0bf69a303438d533
6
+ metadata.gz: a0d4bf587364d3436d28dbab2f4bc5785c52510dcae70bae4f05ca89181786286e5b3072be86984ad5c216f64dccbbd76e02c35db8cb5022bef53907eba041f8
7
+ data.tar.gz: 0b7c46c6776e92c9dd233c8fe7b48fd9791dad0e26c105169fc3b8c8ff79ba57e9f72c152b8e6a53c0f8fcbdea8c9d2cc9eedb63b4eae91d70d76d7bbd958e74
@@ -0,0 +1,42 @@
1
+ name: Docurium
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby: [head, 3.0, 2.7, 2.6]
16
+ llvm: ["6.0", 7, 8, 9, 10]
17
+ os: [ ubuntu-18.04 ]
18
+ include:
19
+ - os: macos-latest
20
+ ruby: 2.6
21
+ llvm: ~ # system
22
+
23
+ name: Ruby ${{ matrix.ruby }} / LLVM ${{ matrix.llvm }} on ${{ matrix.os }}
24
+ runs-on: ${{ matrix.os }}
25
+ continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
26
+
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+ - name: Install Linux packages
30
+ if: runner.os == 'Linux'
31
+ run: |
32
+ sudo apt update
33
+ sudo apt install -y python-pygments libclang-${{ matrix.llvm }}-dev llvm-${{ matrix.llvm }} clang-${{ matrix.llvm }}
34
+ - name: Set up Ruby ${{ matrix.ruby }}
35
+ uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: ${{ matrix.ruby }}
38
+ bundler-cache: true
39
+ - name: Run tests
40
+ run: |
41
+ [ -x /usr/bin/llvm-config-${{ matrix.llvm }} ] && export LLVM_CONFIG=llvm-config-${{ matrix.llvm }}
42
+ bundle exec rake
data/Gemfile CHANGED
@@ -1,11 +1,11 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- platforms :rbx do
4
- gem 'rubysl', '~> 2.0'
3
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0')
4
+ platforms :rbx do
5
+ gem 'rubysl', '~> 2.2'
6
+ end
5
7
  end
6
8
 
7
9
  gemspec
8
10
 
9
- gem 'ffi-clang', :git => 'https://github.com/ioquatix/ffi-clang.git'
10
-
11
11
  # vim:ft=ruby
data/README.md CHANGED
@@ -57,21 +57,6 @@ Docurium will write your docs directly into the specified Git branch.
57
57
 
58
58
  $ gem install docurium
59
59
 
60
- # Screenshots
61
-
62
- ## Main Page
63
-
64
- ![Main Page](https://img.skitch.com/20110614-c98pp6c9p9mn35jn4iskjim7hk.png)
65
-
66
- Each version of your app has a landing page that lists out all the functions available. Functions that are new in that version from the previous version are highlighted in green, functions that have changed signatures are in orange.
67
-
68
- ## Function Page
69
-
70
- ![Func Page](https://img.skitch.com/20110614-mdasyhip3swxtngwxrce8wqy3h.png)
71
-
72
- Each function has a page showing all the relevant info for that function including metadata extracted from Doxygen-style comments. I also list all the versions of the library that this function is included in and in which versions the signature changed.
73
-
74
-
75
60
  # Contributing
76
61
 
77
62
  If you want to fix or change something, please fork on GitHub, push your change to a branch named after your change and send me a pull request.
data/bin/cm CHANGED
@@ -13,12 +13,27 @@ version Docurium::Version
13
13
  desc 'Generate HTML documentation'
14
14
  long_desc 'Generate HTML docs from a Docurium config file'
15
15
  command :doc do |c|
16
+ c.flag :for, :desc => "The version to generate", :multiple => true
17
+ c.switch [:n, "dry-run"], :desc => "Dry-run"
18
+ c.switch [:d, "debug"], :desc => "Enable debug log"
19
+ c.flag "debug-file", :desc => "Enable debug output for header", :multiple => true
20
+ c.flag "debug-function", :desc => "Show debug output when processing function", :multiple => true
21
+ c.flag "debug-type", :desc => "Show debug output when processing type", :multiple => true
16
22
  c.action do |global_options,options,args|
17
23
  file = args.first
18
24
  Docurium::CLI.doc(file, options)
19
25
  end
20
26
  end
21
27
 
28
+ desc 'Check documentation for warnings'
29
+ long_desc 'Check a project\'s documentation for issues'
30
+ command :check do |c|
31
+ c.action do |global_options,options,args|
32
+ file = args.first
33
+ Docurium::CLI.check(file, options)
34
+ end
35
+ end
36
+
22
37
  desc 'Generate Docurium config file template'
23
38
  long_desc 'Generate Docurium config file template'
24
39
  command :gen do |c|
@@ -34,8 +49,10 @@ pre { |global,command,options,args| true }
34
49
  post { |global,command,options,args| true }
35
50
 
36
51
  on_error do |exception|
37
- puts exception
38
- puts exception.backtrace
52
+ if !exception.is_a?(SystemExit)
53
+ puts exception
54
+ puts exception.backtrace
55
+ end
39
56
  end
40
57
 
41
58
  exit run(ARGV)
data/docurium.gemspec CHANGED
@@ -13,15 +13,16 @@ Gem::Specification.new do |s|
13
13
  s.description = s.summary
14
14
  s.license = 'MIT'
15
15
 
16
- s.add_dependency "version_sorter", "~>1.1"
17
- s.add_dependency "mustache", "~> 0.99"
16
+ s.add_dependency "version_sorter", "~>2.0"
17
+ s.add_dependency "mustache", "~> 1.1"
18
18
  s.add_dependency "rocco", "~>0.8"
19
19
  s.add_dependency "gli", "~>2.5"
20
- s.add_dependency "rugged", "~>0.21"
20
+ s.add_dependency "rugged", "~>1.1"
21
21
  s.add_dependency "redcarpet", "~>3.0"
22
- s.add_dependency "ffi-clang", "~> 0.2"
23
- s.add_development_dependency "bundler", "~>1.0"
24
- s.add_development_dependency "rake", "~> 10.1"
22
+ s.add_dependency "ffi-clang", "~> 0.5"
23
+ s.add_dependency "parallel", "~> 1.20"
24
+ s.add_development_dependency "rake", "~> 13"
25
+ s.add_development_dependency "minitest", "~> 5.11"
25
26
 
26
27
  s.files = `git ls-files`.split("\n")
27
28
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/lib/docurium/cli.rb CHANGED
@@ -2,10 +2,15 @@ class Docurium
2
2
  class CLI
3
3
 
4
4
  def self.doc(idir, options)
5
- doc = Docurium.new(idir)
5
+ doc = Docurium.new(idir, options)
6
6
  doc.generate_docs
7
7
  end
8
8
 
9
+ def self.check(idir, options)
10
+ doc = Docurium.new(idir)
11
+ doc.check_warnings(options)
12
+ end
13
+
9
14
  def self.gen(file)
10
15
 
11
16
  temp = <<-TEMPLATE
@@ -0,0 +1,41 @@
1
+ $debug_stack = [false]
2
+
3
+ def debug_enabled
4
+ $debug_stack[-1]
5
+ end
6
+
7
+ def debug(str = nil)
8
+ puts str if debug_enabled
9
+ end
10
+
11
+ def debug_enable
12
+ $debug_stack.push true
13
+ end
14
+
15
+ def debug_silence
16
+ $debug_stack.push false
17
+ end
18
+
19
+ def debug_set val
20
+ $debug_stack.push val
21
+ end
22
+
23
+ def debug_pass
24
+ $debug_stack.push debug_enabled
25
+ end
26
+
27
+ def debug_restore
28
+ $debug_stack.pop
29
+ end
30
+
31
+ def with_debug(&block)
32
+ debug_enable
33
+ block.call
34
+ debug_restore
35
+ end
36
+
37
+ def without_debug(&block)
38
+ debug_silence
39
+ block.call
40
+ debug_restore
41
+ end
@@ -1,46 +1,87 @@
1
1
  require 'tempfile'
2
2
  require 'fileutils'
3
3
  require 'ffi/clang'
4
+ require 'open3'
4
5
  include FFI::Clang
5
6
 
6
7
  class Docurium
7
8
  class DocParser
8
- # Entry point for this parser
9
- # Parse `filename` out of the hash `files`
10
- def parse_file(orig_filename, files)
9
+ # The include directory where clang has its basic type definitions is not
10
+ # included in our default search path, so as a workaround we execute clang
11
+ # in verbose mode and grab its include paths from the output.
12
+ def find_clang_includes
13
+ @includes ||=
14
+ begin
15
+ clang = if ENV["LLVM_CONFIG"]
16
+ bindir = `#{ENV["LLVM_CONFIG"]} --bindir`.strip
17
+ "#{bindir}/clang"
18
+ else
19
+ "clang"
20
+ end
21
+
22
+ output, _status = Open3.capture2e("#{clang} -v -x c -", :stdin_data => "")
23
+ includes = []
24
+ output.each_line do |line|
25
+ if line =~ %r{^\s+/(.*usr|.*lib/clang.*)/include}
26
+ includes << line.strip
27
+ end
28
+ end
29
+
30
+ includes
31
+ end
32
+ end
11
33
 
34
+ def self.with_files(files, opts = {})
35
+ parser = self.new(files, opts)
36
+ yield parser
37
+ parser.cleanup!
38
+ end
39
+
40
+ def initialize(files, opts = {})
12
41
  # unfortunately Clang wants unsaved files to exist on disk, so
13
42
  # we need to create at least empty files for each unsaved file
14
43
  # we're given.
15
44
 
16
- tmpdir = Dir.mktmpdir()
17
-
18
- unsaved = files.map do |name, contents|
19
- full_path = File.join(tmpdir, name)
45
+ prefix = (opts[:prefix] ? opts[:prefix] + "-" : nil)
46
+ @tmpdir = Dir.mktmpdir(prefix)
47
+ @unsaved = files.map do |name, contents|
48
+ full_path = File.join(@tmpdir, name)
20
49
  dirname = File.dirname(full_path)
21
- FileUtils.mkdir_p(dirname) unless Dir.exists? dirname
50
+ FileUtils.mkdir_p(dirname) unless Dir.exist? dirname
22
51
  File.new(full_path, File::CREAT).close()
23
-
24
52
  UnsavedFile.new(full_path, contents)
25
53
  end
54
+ end
26
55
 
27
- # Override the path we want to filter by
28
- filename = File.join(tmpdir, orig_filename)
29
- tu = Index.new.parse_translation_unit(filename, [], unsaved, {:detailed_preprocessing_record => 1})
56
+ def cleanup!
57
+ FileUtils.remove_entry(@tmpdir)
58
+ end
30
59
 
31
- FileUtils.remove_entry(tmpdir)
60
+ # Entry point for this parser
61
+ # Parse `filename` out of the hash `files`
62
+ def parse_file(orig_filename, opts = {})
32
63
 
33
- cursor = tu.cursor
64
+ includes = find_clang_includes + [@tmpdir]
65
+
66
+ # Override the path we want to filter by
67
+ filename = File.join(@tmpdir, orig_filename)
68
+ debug_enable if opts[:debug]
69
+ debug "parsing #{filename} #{@tmpdir}"
70
+ args = includes.map { |path| "-I#{path}" }
71
+ args << '-ferror-limit=1'
72
+
73
+ tu = Index.new(true, true).parse_translation_unit(filename, args, @unsaved, {:detailed_preprocessing_record => 1})
34
74
 
35
75
  recs = []
36
76
 
37
- cursor.visit_children do |cursor, parent|
38
- #puts "visiting #{cursor.kind} - #{cursor.spelling}"
77
+ tu.cursor.visit_children do |cursor, parent|
39
78
  location = cursor.location
40
79
  next :continue if location.file == nil
41
80
  next :continue unless location.file == filename
42
81
 
43
- #puts "for file #{location.file} #{cursor.kind} #{cursor.spelling} #{cursor.comment.kind} #{location.line}"
82
+ loc = "%d:%d-%d:%d" % [cursor.extent.start.line, cursor.extent.start.column, cursor.extent.end.line, cursor.extent.end.column]
83
+ debug "#{cursor.location.file}:#{loc} - visiting #{cursor.kind}: #{cursor.spelling}, comment is #{cursor.comment.kind}"
84
+
44
85
  #cursor.visit_children do |c|
45
86
  # puts " child #{c.kind}, #{c.spelling}, #{c.comment.kind}"
46
87
  # :continue
@@ -57,25 +98,38 @@ class Docurium
57
98
  :tdef => nil,
58
99
  }
59
100
 
60
- case cursor.kind
101
+ extract = case cursor.kind
61
102
  when :cursor_function
62
- #puts "have function"
63
- rec.merge! extract_function(cursor)
103
+ debug "have function #{cursor.spelling}"
104
+ rec.update extract_function(cursor)
64
105
  when :cursor_enum_decl
65
- rec.merge! extract_enum(cursor)
106
+ debug "have enum #{cursor.spelling}"
107
+ rec.update extract_enum(cursor)
66
108
  when :cursor_struct
67
- #puts "raw struct"
68
- rec.merge! extract_struct(cursor)
109
+ debug "have struct #{cursor.spelling}"
110
+ rec.update extract_struct(cursor)
69
111
  when :cursor_typedef_decl
70
- rec.merge! extract_typedef(cursor)
112
+ debug "have typedef #{cursor.spelling} #{cursor.underlying_type.spelling}"
113
+ rec.update extract_typedef(cursor)
71
114
  else
72
115
  raise "No idea how to deal with #{cursor.kind}"
73
116
  end
74
117
 
118
+ rec.merge! extract
119
+
75
120
  recs << rec
76
121
  :continue
77
122
  end
78
123
 
124
+ if debug_enabled
125
+ puts "parse_file: parsed #{recs.size} records for #{filename}:"
126
+ recs.each do |r|
127
+ puts "\t#{r}"
128
+ end
129
+ end
130
+
131
+ debug_restore
132
+
79
133
  recs
80
134
  end
81
135
 
@@ -149,14 +203,27 @@ class Docurium
149
203
 
150
204
  def extract_subject_desc(comment)
151
205
  subject = comment.child.text
152
- desc = (comment.find_all { |cmt| cmt.kind == :comment_paragraph }).drop(1).map(&:text).join("\n\n")
206
+ debug "\t\tsubject: #{subject}"
207
+ paras = comment.find_all { |cmt| cmt.kind == :comment_paragraph }.drop(1).map { |p| p.text }
208
+ desc = paras.join("\n\n")
209
+ debug "\t\tdesc: #{desc}"
153
210
  return subject, desc
154
211
  end
155
212
 
156
213
  def extract_function(cursor)
157
214
  comment = cursor.comment
158
215
 
159
- #puts "looking at function #{cursor.spelling}, #{cursor.display_name}"
216
+ $buggy_functions = %w()
217
+ debug_set ($buggy_functions.include? cursor.spelling)
218
+ if debug_enabled
219
+ puts "\tlooking at function #{cursor.spelling}, #{cursor.display_name}"
220
+ puts "\tcomment: #{comment}, #{comment.kind}"
221
+ cursor.visit_children do |cur, parent|
222
+ puts "\t\tchild: #{cur.spelling}, #{cur.kind}"
223
+ :continue
224
+ end
225
+ end
226
+
160
227
  cmt = extract_function_comment(comment)
161
228
  args = extract_function_args(cursor, cmt)
162
229
  #args = args.reject { |arg| arg[:comment].nil? }
@@ -181,6 +248,7 @@ class Docurium
181
248
  decl = "#{ret[:type]} #{cursor.spelling}(#{argline})"
182
249
  body = "#{decl};"
183
250
 
251
+ debug_restore
184
252
  #puts cursor.display_name
185
253
  # Return the format that docurium expects
186
254
  {
@@ -199,6 +267,7 @@ class Docurium
199
267
 
200
268
  def extract_function_comment(comment)
201
269
  subject, desc = extract_subject_desc(comment)
270
+ debug "\t\textract_function_comment: #{comment}, #{comment.kind}, #{subject}, #{desc}"
202
271
 
203
272
  args = {}
204
273
  (comment.find_all { |cmt| cmt.kind == :comment_param_command }).each do |param|
@@ -274,7 +343,7 @@ class Docurium
274
343
  :continue
275
344
  end
276
345
 
277
- #puts "struct value #{values}"
346
+ debug "\tstruct value #{values}"
278
347
 
279
348
  rec = {
280
349
  :type => :struct,
@@ -1,7 +1,4 @@
1
1
  # adding some stuff I need
2
2
  class Rocco::Layout
3
3
  attr_accessor :version
4
- def version
5
- @version
6
- end
7
4
  end
@@ -1,3 +1,3 @@
1
1
  class Docurium
2
- Version = VERSION = '0.4.1'
2
+ Version = VERSION = '0.7.0'
3
3
  end