bitclust-core 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog +7 -0
  3. data/Gemfile +1 -0
  4. data/bitclust.gemspec +1 -0
  5. data/data/bitclust/template.offline/class +1 -1
  6. data/lib/bitclust/crossrubyutils.rb +2 -2
  7. data/lib/bitclust/methodentry.rb +1 -2
  8. data/lib/bitclust/progress_bar.rb +7 -0
  9. data/lib/bitclust/rdcompiler.rb +1 -1
  10. data/lib/bitclust/runner.rb +46 -32
  11. data/lib/bitclust/searcher.rb +14 -13
  12. data/lib/bitclust/silent_progress_bar.rb +17 -0
  13. data/lib/bitclust/subcommand.rb +27 -0
  14. data/lib/bitclust/subcommands/ancestors_command.rb +145 -0
  15. data/lib/bitclust/subcommands/chm_command.rb +268 -0
  16. data/lib/bitclust/subcommands/classes_command.rb +73 -0
  17. data/lib/bitclust/subcommands/extract_command.rb +55 -0
  18. data/lib/bitclust/subcommands/htmlfile_command.rb +105 -0
  19. data/lib/bitclust/subcommands/init_command.rb +29 -30
  20. data/lib/bitclust/subcommands/list_command.rb +39 -41
  21. data/lib/bitclust/subcommands/lookup_command.rb +71 -73
  22. data/lib/bitclust/subcommands/methods_command.rb +159 -0
  23. data/lib/bitclust/subcommands/preproc_command.rb +35 -0
  24. data/lib/bitclust/subcommands/property_command.rb +47 -48
  25. data/lib/bitclust/subcommands/query_command.rb +12 -18
  26. data/lib/bitclust/subcommands/server_command.rb +180 -182
  27. data/lib/bitclust/subcommands/setup_command.rb +85 -89
  28. data/lib/bitclust/subcommands/statichtml_command.rb +276 -0
  29. data/lib/bitclust/subcommands/update_command.rb +39 -41
  30. data/lib/bitclust/version.rb +1 -1
  31. data/test/test_bitclust.rb +1 -1
  32. data/test/test_rdcompiler.rb +1 -1
  33. data/test/test_runner.rb +7 -14
  34. metadata +120 -114
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 16a76bb3555a76e8172df8e518012cf5c441bf15
4
+ data.tar.gz: 98b008bd6df5d144bbb98bfe1cae8757bfe1dffb
5
+ SHA512:
6
+ metadata.gz: 712c1e7a269282a99cf27af4176d40b9e0337d5533d27aaea190648c0df49232d6114374fa74e3b693f0b8dd000dba5b7360cec8c6885fcb1079cbb139235b8e
7
+ data.tar.gz: f8e50965325085b78e6b2dc4230d61c597d0d646699984e96adeedccdf322d7cab6cf00bf5dc3bf7f3eb2c45017b9397d9d9bbd3d71056513781f7727b12414c
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ 2013-04-12 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
2
+
3
+ * lib/bitclust/subcommands/setup_command.rb (BitClust::SetupCommand#checkout):
4
+ use result of system directly instead of calling "svn help" with
5
+ redirects. because it may cause permission problem on cygwin.
6
+ see https://twitter.com/higaki/status/322542075927212034
7
+
1
8
  2013-04-06 Sho Hashimoto <sho-h@netlab.jp>
2
9
 
3
10
  * lib/bitclust/nameutils.rb
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem "rake"
4
+ gem "progressbar"
4
5
 
5
6
  # Specify your gem's dependencies in bitclust.gemspec
6
7
  gemspec :name => "bitclust"
data/bitclust.gemspec CHANGED
@@ -30,4 +30,5 @@ EOD
30
30
  s.add_development_dependency "test-unit-notify"
31
31
  s.add_development_dependency "test-unit-rr"
32
32
  s.add_runtime_dependency "rack"
33
+ s.add_runtime_dependency "progressbar"
33
34
  end
@@ -55,7 +55,7 @@
55
55
  entries.each do |m|
56
56
  m.names.each do |mname|
57
57
  %>
58
- <a href="#<%= m.index_id(mname, false) %>"><%= "#{prefix}#{mname}" %></a>
58
+ <a href="#<%= m.index_id %>"><%= "#{prefix}#{mname}" %></a>
59
59
  <%
60
60
  end
61
61
  end
@@ -40,7 +40,7 @@ module BitClust
40
40
  ver.split[1].tr('.', '')
41
41
  end
42
42
 
43
- def get_ruby(version)
43
+ def get_ruby(version)
44
44
  forall_ruby(ENV['PATH']) do |ruby, |
45
45
  v = `#{ruby} -e 'print RUBY_VERSION'`
46
46
  patch = `#{ruby} -e 'print RUBY_PATCHLEVEL if defined? RUBY_PATCHLEVEL'`
@@ -50,7 +50,7 @@ module BitClust
50
50
  end
51
51
  return nil
52
52
  end
53
-
53
+
54
54
  def build_crossruby_table
55
55
  ENV.delete 'RUBYOPT'
56
56
  ENV.delete 'RUBYLIB'
@@ -122,8 +122,7 @@ module BitClust
122
122
  "#{t == '#' ? '' : t}#{m}"
123
123
  end
124
124
 
125
- def index_id(name, remove_prefix = true)
126
- name = name.sub(/^\$/, '') if remove_prefix
125
+ def index_id
127
126
  "#{methodid2typechar(@id)}_#{encodename_fs(name).gsub(/=/, '--')}".upcase
128
127
  end
129
128
 
@@ -0,0 +1,7 @@
1
+
2
+ begin
3
+ require 'progressbar'
4
+ rescue LoadError
5
+ require 'bitclust/silent_progress_bar'
6
+ ProgressBar = BitClust::SilentProgressBar
7
+ end
@@ -333,7 +333,7 @@ module BitClust
333
333
  # FIXME: check parameters, types, etc.
334
334
  sig = MethodSignature.parse(sig_line)
335
335
  string %Q(<dt class="method-heading")
336
- string %Q( id="#{@method.index_id(sig.name)}") if first
336
+ string %Q( id="#{@method.index_id}") if first
337
337
  string '><code>'
338
338
  string @method.klass.name + @method.typemark if @opt
339
339
  string escape_html(sig.friendly_string)
@@ -41,18 +41,30 @@ module BitClust
41
41
  @parser.banner = <<-EndBanner
42
42
  Usage: #{File.basename($0, '.*')} [global options] <subcommand> [options] [args]
43
43
 
44
- Subcommands:
44
+ Subcommands(for users):
45
45
  init Initialize database.
46
+ update Update database.
47
+ setup Initialize and update database with default options.
46
48
  list List libraries/classes/methods in database.
47
49
  lookup Lookup a library/class/method from database.
48
50
  search Search classes/methods from database.
51
+
52
+ Subcommands(for developers):
53
+ ancestors Compare class/module's ancestors between Ruby and DB.
54
+ htmlfile Generate a static HTML file for test.
49
55
  query Dispatch arbitrary query.
50
- update Update database.
51
56
  property Handle database properties.
52
- setup Initialize and update database with default options.
57
+ preproc Preprocess source file.
58
+ extract Extract method entries from source file.
59
+ classes Display defined classes for all ruby.
60
+ methods Display defined methods for all ruby.
61
+
62
+ Subcommands(for packagers):
63
+ statichtml Generate static HTML files.
64
+ chm Generate static HTML files for CHM.
53
65
 
54
66
  Global Options:
55
- EndBanner
67
+ EndBanner
56
68
  @parser.on('-d', '--database=PATH', 'Database prefix.') {|path|
57
69
  @prefix = path
58
70
  }
@@ -71,15 +83,23 @@ Global Options:
71
83
  exit 0
72
84
  }
73
85
  @subcommands = {
74
- 'init' => BitClust::Subcommands::InitCommand.new,
75
- 'list' => BitClust::Subcommands::ListCommand.new,
76
- 'lookup' => BitClust::Subcommands::LookupCommand.new,
77
- 'search' => BitClust::Searcher.new,
78
- 'query' => BitClust::Subcommands::QueryCommand.new,
79
- 'update' => BitClust::Subcommands::UpdateCommand.new,
80
- 'property' => BitClust::Subcommands::PropertyCommand.new,
81
- 'setup' => BitClust::Subcommands::SetupCommand.new,
82
- 'server' => BitClust::Subcommands::ServerCommand.new,
86
+ 'init' => BitClust::Subcommands::InitCommand.new,
87
+ 'list' => BitClust::Subcommands::ListCommand.new,
88
+ 'lookup' => BitClust::Subcommands::LookupCommand.new,
89
+ 'search' => BitClust::Searcher.new,
90
+ 'query' => BitClust::Subcommands::QueryCommand.new,
91
+ 'update' => BitClust::Subcommands::UpdateCommand.new,
92
+ 'property' => BitClust::Subcommands::PropertyCommand.new,
93
+ 'setup' => BitClust::Subcommands::SetupCommand.new,
94
+ 'server' => BitClust::Subcommands::ServerCommand.new,
95
+ 'statichtml' => BitClust::Subcommands::StatichtmlCommand.new,
96
+ 'htmlfile' => BitClust::Subcommands::HtmlfileCommand.new,
97
+ 'chm' => BitClust::Subcommands::ChmCommand.new,
98
+ 'ancestors' => BitClust::Subcommands::AncestorsCommand.new,
99
+ 'preproc' => BitClust::Subcommands::PreprocCommand.new,
100
+ 'extract' => BitClust::Subcommands::ExtractCommand.new,
101
+ 'classes' => BitClust::Subcommands::ClassesCommand.new,
102
+ 'methods' => BitClust::Subcommands::MethodsCommand.new,
83
103
  }
84
104
  end
85
105
 
@@ -105,26 +125,20 @@ Global Options:
105
125
  $stderr.puts cmd.help
106
126
  exit 1
107
127
  end
108
- case name
109
- when "setup", "server"
110
- db = nil
111
- else
112
- config = load_config()
113
- if config
114
- @version ||= config[:default_version]
115
- @prefix ||= "#{config[:database_prefix]}-#{@version}"
116
- end
117
- unless @prefix
118
- $stderr.puts "no database given. Use --database option"
119
- exit 1
120
- end
121
- if @capi
122
- db = BitClust::FunctionDatabase.new(@prefix)
123
- else
124
- db = BitClust::MethodDatabase.new(@prefix)
125
- end
128
+ config = load_config()
129
+ if config
130
+ @version ||= config[:default_version]
131
+ @prefix ||= "#{config[:database_prefix]}-#{@version}"
126
132
  end
127
- cmd.exec(db, argv)
133
+ unless @prefix
134
+ $stderr.puts "no database given. Use --database option"
135
+ exit 1
136
+ end
137
+ options = {
138
+ :prefix => @prefix,
139
+ :capi => @capi
140
+ }
141
+ cmd.exec(argv, options)
128
142
  rescue BitClust::WriterError => err
129
143
  raise if $DEBUG
130
144
  error err.message
@@ -34,34 +34,34 @@ module BitClust
34
34
  @target_type = nil
35
35
  @listen_url = nil
36
36
  @foreground = false
37
- @parser = OptionParser.new {|opt|
38
- opt.banner = "Usage: #{@name} <pattern>"
37
+ @parser = OptionParser.new {|parser|
38
+ parser.banner = "Usage: #{@name} <pattern>"
39
39
  unless cmd == 'bitclust'
40
- opt.on('-d', '--database=URL', "Database location (default: #{dblocation_name()})") {|loc|
40
+ parser.on('-d', '--database=URL', "Database location (default: #{dblocation_name()})") {|loc|
41
41
  url = (/:/ =~ loc) ? loc : "file://#{File.expand_path(loc)}"
42
42
  @dblocation = URI.parse(url)
43
43
  }
44
- opt.on('--server=URL', 'Spawns BitClust database server and listen URL. Requires --database option with local path.') {|url|
44
+ parser.on('--server=URL', 'Spawns BitClust database server and listen URL. Requires --database option with local path.') {|url|
45
45
  require 'bitclust/server' # require here for speed
46
46
  @listen_url = url
47
47
  }
48
- opt.on('--foreground', 'Do not become daemon (for debug)') {
48
+ parser.on('--foreground', 'Do not become daemon (for debug)') {
49
49
  @foreground = true
50
50
  }
51
51
  end
52
- opt.on('-a', '--all', 'Prints descriptions for all matched entries.') {
52
+ parser.on('-a', '--all', 'Prints descriptions for all matched entries.') {
53
53
  @describe_all = true
54
54
  }
55
- opt.on('-l', '--line', 'Prints one entry in one line.') {
55
+ parser.on('-l', '--line', 'Prints one entry in one line.') {
56
56
  @linep = true
57
57
  }
58
- opt.on('-e', '--encoding=ENCODING', 'Select encoding.') {|enc|
58
+ parser.on('-e', '--encoding=ENCODING', 'Select encoding.') {|enc|
59
59
  @encoding = enc
60
60
  }
61
- opt.on('--class', 'Search class or module.') {
61
+ parser.on('--class', 'Search class or module.') {
62
62
  @target_type = :class
63
63
  }
64
- opt.on('--version', 'Prints version and quit.') {
64
+ parser.on('--version', 'Prints version and quit.') {
65
65
  if cmd == 'bitclust'
66
66
  puts "BitClust -- Next generation reference manual interface"
67
67
  exit 1
@@ -70,8 +70,8 @@ module BitClust
70
70
  exit 1
71
71
  end
72
72
  }
73
- opt.on('--help', 'Prints this message and quit.') {
74
- puts opt.help
73
+ parser.on('--help', 'Prints this message and quit.') {
74
+ puts parser.help
75
75
  exit 0
76
76
  }
77
77
  }
@@ -88,7 +88,8 @@ module BitClust
88
88
  end
89
89
  end
90
90
 
91
- def exec(db, argv)
91
+ def exec(argv, options = {})
92
+ db = nil
92
93
  if @listen_url
93
94
  spawn_server db
94
95
  else
@@ -0,0 +1,17 @@
1
+
2
+ module BitClust
3
+ class SilentProgressBar
4
+
5
+ attr_reader :title
6
+
7
+ def initialize(title, total, out = $stderr)
8
+ @title, @total, @out = title, total, out
9
+ end
10
+
11
+ def inc(step = 1)
12
+ end
13
+
14
+ def finish
15
+ end
16
+ end
17
+ end
@@ -10,6 +10,14 @@ require 'yaml'
10
10
  module BitClust
11
11
 
12
12
  class Subcommand
13
+ def initialize
14
+ @parser = OptionParser.new
15
+ @parser.on_tail("-h", "--help", "Print this message and quit."){
16
+ $stderr.puts help
17
+ exit 0
18
+ }
19
+ end
20
+
13
21
  def parse(argv)
14
22
  @parser.parse! argv
15
23
  end
@@ -18,11 +26,30 @@ module BitClust
18
26
  @parser.help
19
27
  end
20
28
 
29
+ def exec(argv, options)
30
+ prefix = options[:prefix]
31
+ if options[:capi]
32
+ @db = BitClust::FunctionDatabase.new(prefix)
33
+ else
34
+ @db = BitClust::MethodDatabase.new(prefix)
35
+ end
36
+ end
37
+
21
38
  # TODO refactor
22
39
  def error(message)
23
40
  $stderr.puts "#{File.basename($0, '.*')}: error: #{message}"
24
41
  exit 1
25
42
  end
43
+
44
+ def option_error(message)
45
+ $stderr.puts message
46
+ $stderr.puts help
47
+ exit 1
48
+ end
49
+
50
+ def srcdir_root
51
+ Pathname.new(__FILE__).realpath.dirname.parent.parent
52
+ end
26
53
  end
27
54
  end
28
55
 
@@ -0,0 +1,145 @@
1
+ require 'bitclust'
2
+ require 'bitclust/crossrubyutils'
3
+
4
+ require 'pathname'
5
+ require 'optparse'
6
+ require 'set'
7
+
8
+ module BitClust
9
+ module Subcommands
10
+ class AncestorsCommand < Subcommand
11
+ include CrossRubyUtils
12
+
13
+ def initialize
14
+ super
15
+ @prefix = nil
16
+ @requires = []
17
+ @version = RUBY_VERSION
18
+ @all = false
19
+ @verbose = false
20
+ @parser.banner = <<-BANNER
21
+ Usage: #{File.basename($0, '.*')} ancestors [-r<lib>] [--ruby=<VER>] --db=PATH <classname>
22
+ #{File.basename($0, '.*')} ancestors [-r<lib>] [--ruby=<VER>] --db=PATH --all
23
+ NG Sample:
24
+ $ #{File.basename($0, '.*')} ancestors -rfoo --ruby=1.9.1 --db=./db Foo
25
+ NG : Foo
26
+ + FooModule (The Ruby have this class/module in ancestors of the class)
27
+ - BarModule (The Database have this class/module in ancestors of the class)
28
+ Options:
29
+ BANNER
30
+ @parser.on('-d', '--database=PATH', 'Database prefix.') {|path|
31
+ @prefix = path
32
+ }
33
+ @parser.on('-r LIB', 'Requires library LIB') {|lib|
34
+ @requires.push lib
35
+ }
36
+ @parser.on('--ruby=[VER]', "The version of Ruby interpreter"){|ver|
37
+ @version = ver
38
+ }
39
+ @parser.on('-v', '--verbose', 'Show differences'){
40
+ @verbose = true
41
+ }
42
+ @parser.on('--all', 'Check anccestors for all classes'){
43
+ @all = true
44
+ }
45
+ end
46
+
47
+ def exec(argv, options)
48
+ classname = argv[0]
49
+ db = MethodDatabase.new(@prefix)
50
+ ruby = get_ruby(@version)
51
+ if classname && !@all
52
+ check_ancestors(db, ruby, @requires, classname)
53
+ else
54
+ $stderr.puts 'check all...'
55
+ check_all_ancestors(db, ruby, @requires)
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def ancestors(ruby, requires, classname)
62
+ req = requires.map{|lib|
63
+ unless '_builtin' == lib
64
+ "-r#{lib}"
65
+ else
66
+ ''
67
+ end
68
+ }.join(" ")
69
+ script = <<-SRC
70
+ c = #{classname}
71
+ puts c.ancestors.join("\n")
72
+ SRC
73
+ puts "#{ruby} #{req} -e '#{script}'"
74
+ `#{ruby} #{req} -e '#{script}'`.split
75
+ end
76
+
77
+ def check_ancestors(db, ruby, requires, classname)
78
+ a = ancestors(ruby, requires, classname)
79
+ p a
80
+ begin
81
+ b = db.fetch_class(classname).ancestors.map(&:name)
82
+ rescue ClassNotFound => ex
83
+ $stderr.puts ex.backtrace
84
+ $stderr.puts "class not found in database : #{classname}"
85
+ b = []
86
+ end
87
+ unless a.to_set == b.to_set
88
+ puts "NG : #{classname}"
89
+ puts (a-b).map{|c| "+ #{c}" }.join("\n")
90
+ puts (b-a).map{|c| "- #{c}" }.join("\n")
91
+ else
92
+ puts "OK : #{classname}" if @verbose
93
+ end
94
+ end
95
+
96
+ def check_all_ancestors(db, ruby, requires)
97
+ classnames = []
98
+ requires.each do |lib|
99
+ classnames.push(*defined_classes(ruby, lib, []))
100
+ end
101
+ classnames.each do |classname|
102
+ check_ancestors(db, ruby, requires, classname)
103
+ end
104
+ end
105
+
106
+ def defined_classes(ruby, lib, rejects)
107
+ script = <<-SCRIPT
108
+ def class_extent
109
+ result = []
110
+ ObjectSpace.each_object(Module) do |c|
111
+ result.push c
112
+ end
113
+ result
114
+ end
115
+
116
+ %w(#{rejects.join(" ")}).each do |lib|
117
+ begin
118
+ require lib
119
+ rescue LoadError
120
+ end
121
+ end
122
+ if "#{lib}" == "_builtin"
123
+ class_extent().each do |c|
124
+ puts c
125
+ end
126
+ else
127
+ before = class_extent()
128
+ begin
129
+ require "#{lib}"
130
+ rescue LoadError
131
+ $stderr.puts "\#{RUBY_VERSION} (\#{RUBY_RELEASE_DATE}): library not exist: #{lib}"
132
+ exit
133
+ end
134
+ after = class_extent()
135
+ (after - before).each do |c|
136
+ puts c
137
+ end
138
+ end
139
+ SCRIPT
140
+ output = `#{ruby} -e '#{script}'`
141
+ output.split
142
+ end
143
+ end
144
+ end
145
+ end