ffi-clang 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +4 -0
  3. data/.travis.yml +20 -9
  4. data/Gemfile +10 -1
  5. data/README.md +1 -1
  6. data/Rakefile +9 -9
  7. data/examples/docs.cpp +25 -0
  8. data/examples/docs.rb +31 -0
  9. data/ffi-clang.gemspec +1 -1
  10. data/lib/ffi/clang.rb +16 -13
  11. data/lib/ffi/clang/clang_version.rb +29 -0
  12. data/lib/ffi/clang/code_completion.rb +1 -1
  13. data/lib/ffi/clang/comment.rb +8 -4
  14. data/lib/ffi/clang/compilation_database.rb +1 -1
  15. data/lib/ffi/clang/cursor.rb +42 -15
  16. data/lib/ffi/clang/diagnostic.rb +6 -2
  17. data/lib/ffi/clang/file.rb +6 -9
  18. data/lib/ffi/clang/index.rb +4 -4
  19. data/lib/ffi/clang/lib.rb +1 -1
  20. data/lib/ffi/clang/lib/{utils.rb → clang_version.rb} +1 -1
  21. data/lib/ffi/clang/lib/code_completion.rb +2 -3
  22. data/lib/ffi/clang/lib/comment.rb +0 -2
  23. data/lib/ffi/clang/lib/compilation_database.rb +6 -9
  24. data/lib/ffi/clang/lib/cursor.rb +10 -18
  25. data/lib/ffi/clang/lib/diagnostic.rb +4 -4
  26. data/lib/ffi/clang/lib/file.rb +4 -6
  27. data/lib/ffi/clang/lib/inclusions.rb +2 -2
  28. data/lib/ffi/clang/lib/index.rb +0 -2
  29. data/lib/ffi/clang/lib/source_location.rb +6 -8
  30. data/lib/ffi/clang/lib/source_range.rb +1 -1
  31. data/lib/ffi/clang/lib/string.rb +0 -2
  32. data/lib/ffi/clang/lib/translation_unit.rb +2 -2
  33. data/lib/ffi/clang/lib/type.rb +8 -17
  34. data/lib/ffi/clang/source_location.rb +2 -2
  35. data/lib/ffi/clang/source_range.rb +16 -3
  36. data/lib/ffi/clang/token.rb +4 -4
  37. data/lib/ffi/clang/translation_unit.rb +5 -5
  38. data/lib/ffi/clang/type.rb +0 -14
  39. data/lib/ffi/clang/version.rb +2 -2
  40. data/spec/{clang → ffi/clang}/code_completion_spec.rb +6 -6
  41. data/spec/{clang → ffi/clang}/comment_spec.rb +22 -39
  42. data/spec/{clang → ffi/clang}/compilation_database_spec.rb +8 -10
  43. data/spec/{clang → ffi/clang}/cursor_spec.rb +89 -97
  44. data/spec/{clang → ffi/clang}/diagnostic_spec.rb +9 -10
  45. data/spec/{clang → ffi/clang}/file_spec.rb +3 -5
  46. data/spec/{fixtures → ffi/clang/fixtures}/a.c +0 -0
  47. data/spec/{fixtures → ffi/clang/fixtures}/canonical.c +0 -0
  48. data/spec/ffi/clang/fixtures/class.cpp +8 -0
  49. data/spec/{fixtures → ffi/clang/fixtures}/compile_commands.json +0 -0
  50. data/spec/{fixtures → ffi/clang/fixtures}/completion.cxx +0 -0
  51. data/spec/{fixtures → ffi/clang/fixtures}/docs.c +0 -0
  52. data/spec/{fixtures → ffi/clang/fixtures}/docs.cc +0 -0
  53. data/spec/{fixtures → ffi/clang/fixtures}/docs.h +0 -0
  54. data/spec/{fixtures → ffi/clang/fixtures}/list.c +0 -0
  55. data/spec/{fixtures → ffi/clang/fixtures}/location1.c +0 -0
  56. data/spec/ffi/clang/fixtures/simple.ast +0 -0
  57. data/spec/{fixtures → ffi/clang/fixtures}/simple.c +0 -0
  58. data/spec/{fixtures → ffi/clang/fixtures}/test.cxx +0 -0
  59. data/spec/{clang → ffi/clang}/index_spec.rb +17 -14
  60. data/spec/{clang → ffi/clang}/source_location_spec.rb +12 -14
  61. data/spec/{clang → ffi/clang}/source_range_spec.rb +12 -14
  62. data/spec/{clang → ffi/clang}/token_spec.rb +6 -8
  63. data/spec/{clang → ffi/clang}/translation_unit_spec.rb +28 -30
  64. data/spec/{clang → ffi/clang}/type_spec.rb +17 -33
  65. data/spec/ffi/clang/version_spec.rb +28 -0
  66. data/spec/spec_helper.rb +11 -37
  67. metadata +61 -55
  68. data/lib/ffi/clang/utils.rb +0 -89
  69. data/spec/clang/utils_spec.rb +0 -60
@@ -20,21 +20,19 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- require 'spec_helper'
24
-
25
23
  describe Type do
26
24
  let(:cursor) { Index.new.parse_translation_unit(fixture_path("a.c")).cursor }
27
25
  let(:cursor_cxx) { Index.new.parse_translation_unit(fixture_path("test.cxx")).cursor }
28
26
  let(:cursor_list) { Index.new.parse_translation_unit(fixture_path("list.c")).cursor }
29
27
  let(:type) { find_first(cursor, :cursor_function).type }
30
28
 
31
- it "can tell us about the main function", from_3_3: true do
32
- type.variadic?.should equal(false)
29
+ it "can tell us about the main function" do
30
+ expect(type.variadic?).to equal(false)
33
31
 
34
- type.num_arg_types.should equal(2)
35
- type.arg_type(0).spelling.should eq("int")
36
- type.arg_type(1).spelling.should eq("const char *")
37
- type.result_type.spelling.should eq("int")
32
+ expect(type.num_arg_types).to equal(2)
33
+ expect(type.arg_type(0).spelling).to eq("int")
34
+ expect(type.arg_type(1).spelling).to eq("const char *")
35
+ expect(type.result_type.spelling).to eq("int")
38
36
  end
39
37
 
40
38
  describe '#kind_spelling' do
@@ -42,7 +40,7 @@ describe Type do
42
40
  child.kind == :cursor_typedef_decl and child.spelling == 'const_int_ptr'}.type }
43
41
 
44
42
  it 'returns type kind name with string' do
45
- kind_spelling_type.kind_spelling.should eq 'Typedef'
43
+ expect(kind_spelling_type.kind_spelling).to eq 'Typedef'
46
44
  end
47
45
  end
48
46
 
@@ -51,12 +49,7 @@ describe Type do
51
49
  child.kind == :cursor_typedef_decl and child.spelling == 'const_int_ptr'
52
50
  }.type.canonical }
53
51
 
54
- it 'extracts typedef', upto_3_2: true do
55
- expect(canonical_type).to be_kind_of(Type)
56
- expect(canonical_type.kind).to be(:type_pointer)
57
- end
58
-
59
- it 'extracts typedef', from_3_3: true do
52
+ it 'extracts typedef' do
60
53
  expect(canonical_type).to be_kind_of(Type)
61
54
  expect(canonical_type.kind).to be(:type_pointer)
62
55
  expect(canonical_type.spelling).to eq('const int *')
@@ -68,12 +61,7 @@ describe Type do
68
61
  child.kind == :cursor_typedef_decl and child.spelling == 'const_int_ptr'
69
62
  }.type.canonical.pointee }
70
63
 
71
- it 'gets pointee type of pointer, C++ reference', upto_3_2: true do
72
- expect(pointee_type).to be_kind_of(Type)
73
- expect(pointee_type.kind).to be(:type_int)
74
- end
75
-
76
- it 'gets pointee type of pointer, C++ reference', from_3_3: true do
64
+ it 'gets pointee type of pointer, C++ reference' do
77
65
  expect(pointee_type).to be_kind_of(Type)
78
66
  expect(pointee_type.kind).to be(:type_int)
79
67
  expect(pointee_type.spelling).to eq('const int')
@@ -90,11 +78,11 @@ describe Type do
90
78
  }.type.canonical.pointee }
91
79
 
92
80
  it 'checks type is const qualified' do
93
- pointee_type.const_qualified?.should equal true
81
+ expect(pointee_type.const_qualified?).to equal true
94
82
  end
95
83
 
96
84
  it 'cannot check whether pointee type is const qualified' do
97
- pointer_type.const_qualified?.should equal false
85
+ expect(pointer_type.const_qualified?).to equal false
98
86
  end
99
87
  end
100
88
 
@@ -160,7 +148,7 @@ describe Type do
160
148
  end
161
149
  end
162
150
 
163
- describe '#alignof', from_3_3: true do
151
+ describe '#alignof' do
164
152
  let(:array_type) { find_matching(cursor_cxx) { |child, parent|
165
153
  child.kind == :cursor_variable and child.spelling == 'int_array'
166
154
  }.type }
@@ -171,7 +159,7 @@ describe Type do
171
159
  end
172
160
  end
173
161
 
174
- describe '#sizeof', from_3_3: true do
162
+ describe '#sizeof' do
175
163
  let(:array_type) { find_matching(cursor_cxx) { |child, parent|
176
164
  child.kind == :cursor_variable and child.spelling == 'int_array'
177
165
  }.type }
@@ -182,7 +170,7 @@ describe Type do
182
170
  end
183
171
  end
184
172
 
185
- describe '#offsetof', from_3_3: true do
173
+ describe '#offsetof' do
186
174
  let(:struct) { find_matching(cursor_list) { |child, parent|
187
175
  child.kind == :cursor_struct and child.spelling == 'List'
188
176
  }.type }
@@ -193,7 +181,7 @@ describe Type do
193
181
  end
194
182
  end
195
183
 
196
- describe '#ref_qualifier', from_3_4: true do
184
+ describe '#ref_qualifier' do
197
185
  let(:lvalue) { find_matching(cursor_cxx) { |child, parent|
198
186
  child.kind == :cursor_cxx_method and child.spelling == 'func_lvalue_ref'
199
187
  }.type }
@@ -227,7 +215,7 @@ describe Type do
227
215
  end
228
216
  end
229
217
 
230
- describe '#class_type', from_3_4: true do
218
+ describe '#class_type' do
231
219
  let(:member_pointer) { find_matching(cursor_cxx) { |child, parent|
232
220
  child.kind == :cursor_variable and child.spelling == 'member_pointer'
233
221
  }.type }
@@ -265,13 +253,9 @@ describe Type do
265
253
  child.kind == :cursor_function and child.spelling == 'f_variadic'
266
254
  }.type }
267
255
 
268
- it 'returns the calling convention associated with the function type', from_3_4: true do
256
+ it 'returns the calling convention associated with the function type' do
269
257
  expect(function.calling_conv).to be(:calling_conv_c)
270
258
  end
271
-
272
- it 'returns the calling convention associated with the function type', upto_3_3: true do
273
- expect(function.calling_conv).to be(:calling_conv_default)
274
- end
275
259
  end
276
260
 
277
261
  describe '#==' do
@@ -0,0 +1,28 @@
1
+ # Copyright, 2014 by Masahiro Sano.
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'ffi/clang/version'
22
+
23
+ describe FFI::Clang.clang_version_string do
24
+ it "returns a version string for showing to user" do
25
+ expect(subject).to be_kind_of(String)
26
+ expect(subject).to match(/Apple LLVM version \d+\.\d+\.\d+|clang version \d+\.\d+/)
27
+ end
28
+ end
@@ -1,63 +1,37 @@
1
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
- require 'ffi/clang'
3
1
 
4
- include FFI::Clang
2
+ require_relative '../lib/ffi/clang'
5
3
 
6
- TMP_DIR = File.expand_path("../tmp/", __FILE__)
4
+ require 'pry'
7
5
 
8
- if ENV['LLVM_CONFIG']
9
- llvm_bindir = `#{ENV['LLVM_CONFIG']} --bindir`.chomp
10
- CLANG_COMPILER = File.expand_path('clang', llvm_bindir)
11
- CLANGPP_COMPILER = File.expand_path('clang++', llvm_bindir)
12
- else
13
- CLANG_COMPILER = 'clang'
14
- CLANGPP_COMPILER = 'clang++'
15
- end
6
+ include FFI::Clang
7
+
8
+ TMP_DIR = File.expand_path("tmp", __dir__)
16
9
 
17
10
  module ClangSpecHelper
18
11
  def fixture_path(path)
19
- File.join File.expand_path("../fixtures", __FILE__), path
12
+ File.join File.expand_path("ffi/clang/fixtures", __dir__), path
20
13
  end
21
14
 
22
15
  def find_all(cursor, kind)
23
- ret = []
24
-
25
- cursor.visit_children do |cursor, parent|
26
- if (cursor.kind == kind)
27
- ret << cursor
28
- end
29
- :recurse
30
- end
31
-
32
- ret
16
+ cursor.find_all(kind)
33
17
  end
34
18
 
35
19
  def find_first(cursor, kind)
36
- find_all(cursor, kind).first
20
+ cursor.find_first(kind)
37
21
  end
38
22
 
39
23
  def find_all_matching(cursor, &term)
40
- ret = []
41
-
42
- cursor.visit_children do |child, parent|
43
- if term.call child, parent
44
- ret << child
45
- end
46
-
47
- :recurse
48
- end
49
-
50
- ret
24
+ cursor.filter(&term)
51
25
  end
52
26
 
53
27
  def find_matching(cursor, &term)
54
- find_all_matching(cursor, &term).first
28
+ cursor.filter(&term).first
55
29
  end
56
30
  end
57
31
 
58
32
  RSpec.configure do |c|
59
33
  c.include ClangSpecHelper
60
- supported_versions = ['3.2', '3.3', '3.4', '3.5']
34
+ supported_versions = ['3.4', '3.5', '3.6', '3.7', '3.8', '3.9', '4.0']
61
35
  current_version = ENV['LLVM_VERSION'] || supported_versions.last
62
36
  supported_versions.reverse_each { |version|
63
37
  break if version == current_version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-clang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-04 00:00:00.000000000 Z
12
+ date: 2017-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 3.0.0
48
+ version: 3.4.0
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 3.0.0
55
+ version: 3.4.0
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -81,10 +81,13 @@ files:
81
81
  - Gemfile
82
82
  - README.md
83
83
  - Rakefile
84
+ - examples/docs.cpp
85
+ - examples/docs.rb
84
86
  - ext/rakefile.rb
85
87
  - ext/teapot.rb
86
88
  - ffi-clang.gemspec
87
89
  - lib/ffi/clang.rb
90
+ - lib/ffi/clang/clang_version.rb
88
91
  - lib/ffi/clang/code_completion.rb
89
92
  - lib/ffi/clang/comment.rb
90
93
  - lib/ffi/clang/compilation_database.rb
@@ -93,6 +96,7 @@ files:
93
96
  - lib/ffi/clang/file.rb
94
97
  - lib/ffi/clang/index.rb
95
98
  - lib/ffi/clang/lib.rb
99
+ - lib/ffi/clang/lib/clang_version.rb
96
100
  - lib/ffi/clang/lib/code_completion.rb
97
101
  - lib/ffi/clang/lib/comment.rb
98
102
  - lib/ffi/clang/lib/compilation_database.rb
@@ -107,39 +111,39 @@ files:
107
111
  - lib/ffi/clang/lib/token.rb
108
112
  - lib/ffi/clang/lib/translation_unit.rb
109
113
  - lib/ffi/clang/lib/type.rb
110
- - lib/ffi/clang/lib/utils.rb
111
114
  - lib/ffi/clang/source_location.rb
112
115
  - lib/ffi/clang/source_range.rb
113
116
  - lib/ffi/clang/token.rb
114
117
  - lib/ffi/clang/translation_unit.rb
115
118
  - lib/ffi/clang/type.rb
116
119
  - lib/ffi/clang/unsaved_file.rb
117
- - lib/ffi/clang/utils.rb
118
120
  - lib/ffi/clang/version.rb
119
- - spec/clang/code_completion_spec.rb
120
- - spec/clang/comment_spec.rb
121
- - spec/clang/compilation_database_spec.rb
122
- - spec/clang/cursor_spec.rb
123
- - spec/clang/diagnostic_spec.rb
124
- - spec/clang/file_spec.rb
125
- - spec/clang/index_spec.rb
126
- - spec/clang/source_location_spec.rb
127
- - spec/clang/source_range_spec.rb
128
- - spec/clang/token_spec.rb
129
- - spec/clang/translation_unit_spec.rb
130
- - spec/clang/type_spec.rb
131
- - spec/clang/utils_spec.rb
132
- - spec/fixtures/a.c
133
- - spec/fixtures/canonical.c
134
- - spec/fixtures/compile_commands.json
135
- - spec/fixtures/completion.cxx
136
- - spec/fixtures/docs.c
137
- - spec/fixtures/docs.cc
138
- - spec/fixtures/docs.h
139
- - spec/fixtures/list.c
140
- - spec/fixtures/location1.c
141
- - spec/fixtures/simple.c
142
- - spec/fixtures/test.cxx
121
+ - spec/ffi/clang/code_completion_spec.rb
122
+ - spec/ffi/clang/comment_spec.rb
123
+ - spec/ffi/clang/compilation_database_spec.rb
124
+ - spec/ffi/clang/cursor_spec.rb
125
+ - spec/ffi/clang/diagnostic_spec.rb
126
+ - spec/ffi/clang/file_spec.rb
127
+ - spec/ffi/clang/fixtures/a.c
128
+ - spec/ffi/clang/fixtures/canonical.c
129
+ - spec/ffi/clang/fixtures/class.cpp
130
+ - spec/ffi/clang/fixtures/compile_commands.json
131
+ - spec/ffi/clang/fixtures/completion.cxx
132
+ - spec/ffi/clang/fixtures/docs.c
133
+ - spec/ffi/clang/fixtures/docs.cc
134
+ - spec/ffi/clang/fixtures/docs.h
135
+ - spec/ffi/clang/fixtures/list.c
136
+ - spec/ffi/clang/fixtures/location1.c
137
+ - spec/ffi/clang/fixtures/simple.ast
138
+ - spec/ffi/clang/fixtures/simple.c
139
+ - spec/ffi/clang/fixtures/test.cxx
140
+ - spec/ffi/clang/index_spec.rb
141
+ - spec/ffi/clang/source_location_spec.rb
142
+ - spec/ffi/clang/source_range_spec.rb
143
+ - spec/ffi/clang/token_spec.rb
144
+ - spec/ffi/clang/translation_unit_spec.rb
145
+ - spec/ffi/clang/type_spec.rb
146
+ - spec/ffi/clang/version_spec.rb
143
147
  - spec/spec_helper.rb
144
148
  homepage: ''
145
149
  licenses:
@@ -161,33 +165,35 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
165
  version: '0'
162
166
  requirements: []
163
167
  rubyforge_project:
164
- rubygems_version: 2.5.1
168
+ rubygems_version: 2.6.10
165
169
  signing_key:
166
170
  specification_version: 4
167
171
  summary: Ruby FFI bindings for libclang C interface.
168
172
  test_files:
169
- - spec/clang/code_completion_spec.rb
170
- - spec/clang/comment_spec.rb
171
- - spec/clang/compilation_database_spec.rb
172
- - spec/clang/cursor_spec.rb
173
- - spec/clang/diagnostic_spec.rb
174
- - spec/clang/file_spec.rb
175
- - spec/clang/index_spec.rb
176
- - spec/clang/source_location_spec.rb
177
- - spec/clang/source_range_spec.rb
178
- - spec/clang/token_spec.rb
179
- - spec/clang/translation_unit_spec.rb
180
- - spec/clang/type_spec.rb
181
- - spec/clang/utils_spec.rb
182
- - spec/fixtures/a.c
183
- - spec/fixtures/canonical.c
184
- - spec/fixtures/compile_commands.json
185
- - spec/fixtures/completion.cxx
186
- - spec/fixtures/docs.c
187
- - spec/fixtures/docs.cc
188
- - spec/fixtures/docs.h
189
- - spec/fixtures/list.c
190
- - spec/fixtures/location1.c
191
- - spec/fixtures/simple.c
192
- - spec/fixtures/test.cxx
173
+ - spec/ffi/clang/code_completion_spec.rb
174
+ - spec/ffi/clang/comment_spec.rb
175
+ - spec/ffi/clang/compilation_database_spec.rb
176
+ - spec/ffi/clang/cursor_spec.rb
177
+ - spec/ffi/clang/diagnostic_spec.rb
178
+ - spec/ffi/clang/file_spec.rb
179
+ - spec/ffi/clang/fixtures/a.c
180
+ - spec/ffi/clang/fixtures/canonical.c
181
+ - spec/ffi/clang/fixtures/class.cpp
182
+ - spec/ffi/clang/fixtures/compile_commands.json
183
+ - spec/ffi/clang/fixtures/completion.cxx
184
+ - spec/ffi/clang/fixtures/docs.c
185
+ - spec/ffi/clang/fixtures/docs.cc
186
+ - spec/ffi/clang/fixtures/docs.h
187
+ - spec/ffi/clang/fixtures/list.c
188
+ - spec/ffi/clang/fixtures/location1.c
189
+ - spec/ffi/clang/fixtures/simple.ast
190
+ - spec/ffi/clang/fixtures/simple.c
191
+ - spec/ffi/clang/fixtures/test.cxx
192
+ - spec/ffi/clang/index_spec.rb
193
+ - spec/ffi/clang/source_location_spec.rb
194
+ - spec/ffi/clang/source_range_spec.rb
195
+ - spec/ffi/clang/token_spec.rb
196
+ - spec/ffi/clang/translation_unit_spec.rb
197
+ - spec/ffi/clang/type_spec.rb
198
+ - spec/ffi/clang/version_spec.rb
193
199
  - spec/spec_helper.rb
@@ -1,89 +0,0 @@
1
- # Copyright, 2014 by Masahiro Sano.
2
- # Copyright, 2014 by Samuel Williams.
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
-
22
- require 'ffi/clang/lib/utils'
23
- require 'ffi/clang/lib/string'
24
-
25
- module FFI
26
- module Clang
27
- module Utils
28
- @@clang_version = nil
29
-
30
- def self.clang_version_string
31
- Lib.extract_string Lib.get_clang_version
32
- end
33
-
34
- def self.clang_version
35
- unless @@clang_version
36
- # Version string vary wildy:
37
- # Ubuntu: "Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM 3.0)"
38
- # Mac OS X: "Apple LLVM version 7.0.0 (clang-700.0.72)"
39
- # Linux: "clang version 3.3"
40
- if parts = clang_version_string.match(/^Apple LLVM version (\d+)\.(\d+).\d \(clang-.*\)$/)
41
- @@clang_version = [3, 7] # Fake it.
42
-
43
- puts "Using libclang: #{Lib::ffi_libraries[0].name}"
44
- puts "Clang version detected: #{@@clang_version.inspect}"
45
- elsif parts = clang_version_string.match(/(?:clang version|based on LLVM) (\d+)\.(\d+)(svn)?/)
46
- major = parts[1].to_i
47
- minor = parts[2].to_i
48
- rc = parts[3]
49
-
50
- # Mac OS X currently reports support for 3.3svn, but this support is broken in some ways, so we revert it back to 3.2 which it supports completely.
51
- if rc == 'svn'
52
- minor -= 1
53
- end
54
-
55
- @@clang_version = [major, minor]
56
-
57
- puts "Using libclang: #{Lib::ffi_libraries[0].name}"
58
- puts "Clang version detected: #{@@clang_version.inspect}"
59
- else
60
- abort "Invalid/unsupported clang version string."
61
- end
62
- end
63
-
64
- return @@clang_version
65
- end
66
-
67
- def self.clang_version_symbol
68
- "clang_#{clang_version.join('_')}".to_sym
69
- end
70
-
71
- def self.clang_major_version
72
- clang_version[0]
73
- end
74
-
75
- def self.clang_minor_version
76
- clang_version[1]
77
- end
78
-
79
- # Returns true if the current clang version is >= min version and optionally <= max_version
80
- def self.satisfy_version?(min_version, max_version = nil)
81
- min_version = Gem::Version.create(min_version)
82
- max_version = Gem::Version.create(max_version) if max_version
83
- current_version = Gem::Version.create(self.clang_version.join('.'))
84
-
85
- return (current_version >= min_version) && (!max_version || current_version <= max_version)
86
- end
87
- end
88
- end
89
- end