easy-swig 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +15 -0
  2. data/MIT_LICENSE +19 -0
  3. data/README.md +86 -0
  4. data/lib/apinodes/api_attribute.rb +6 -0
  5. data/lib/apinodes/api_class.rb +207 -0
  6. data/lib/apinodes/api_enum.rb +10 -0
  7. data/lib/apinodes/api_function.rb +13 -0
  8. data/lib/apinodes/api_group.rb +13 -0
  9. data/lib/apinodes/api_method.rb +12 -0
  10. data/lib/apinodes/api_namespace.rb +104 -0
  11. data/lib/apinodes/api_node.rb +109 -0
  12. data/lib/apinodes/api_variable.rb +12 -0
  13. data/lib/apinodes/inc_file.rb +118 -0
  14. data/lib/config.rb +56 -0
  15. data/lib/csharp/csharp_features.rb +100 -0
  16. data/lib/csharp/generators/csharp_class_generator.rb +14 -0
  17. data/lib/csharp/generators/csharp_generator.rb +17 -0
  18. data/lib/csharp/generators/csharp_namespace_generator.rb +33 -0
  19. data/lib/easy-swig-cli.rb +143 -0
  20. data/lib/easy-swig.rb +71 -0
  21. data/lib/features.rb +39 -0
  22. data/lib/generators/class_generator.rb +209 -0
  23. data/lib/generators/generator.rb +124 -0
  24. data/lib/generators/generator_util.rb +135 -0
  25. data/lib/generators/hfile_generator.rb +56 -0
  26. data/lib/generators/namespace_generator.rb +58 -0
  27. data/lib/generators/properties.rb +13 -0
  28. data/lib/readers/csv_parser.rb +127 -0
  29. data/lib/tasks/doxygen_task.rb +28 -0
  30. data/lib/tasks/generate_task.rb +85 -0
  31. data/lib/tasks/hfiles_manager.rb +86 -0
  32. data/lib/tasks/swig_task.rb +69 -0
  33. data/lib/util/logger.rb +36 -0
  34. data/lib/util/print.rb +72 -0
  35. data/lib/util/query.rb +136 -0
  36. data/lib/util/utilities.rb +101 -0
  37. data/spec/accessors/accessors_spec.rb +45 -0
  38. data/spec/anonymousEnums/anonymous_enums_spec.rb +49 -0
  39. data/spec/friends/friends_spec.rb +45 -0
  40. data/spec/innerclasses/innerclasses_spec.rb +48 -0
  41. data/spec/namespacePrefixes/namespace_prefixes_spec.rb +39 -0
  42. data/spec/squish/squish_spec.rb +40 -0
  43. data/spec/subdirectories/subdirectories_spec.rb +41 -0
  44. data/spec/templates/templates_spec.rb +34 -0
  45. metadata +107 -0
@@ -0,0 +1,101 @@
1
+ class String
2
+ def escape_heredoc
3
+ this = dup
4
+ lines = this.split(/\r\n|\r|\n/).select { |line| line.size > 0 }
5
+ levels = lines.map do |line|
6
+ match = line.match(/^( +)[^ ]+/)
7
+ match ? match[1].size : 0
8
+ end
9
+ level = levels.min
10
+ this.gsub!(/^#{' ' * level}/, '') if level > 0
11
+ this
12
+ end
13
+ end
14
+
15
+ module EasySwig
16
+ module Util
17
+
18
+ def lib_dir
19
+ File.expand_path(File.dirname(__FILE__)+'/..')
20
+ end
21
+
22
+ def home_dir
23
+ File.expand_path(lib_dir+"/..")
24
+ end
25
+
26
+ def output_dir
27
+ @output_dir
28
+ end
29
+
30
+ def escape_all(typename)
31
+ return del_prefix_class(escape_template(escape_const_ref_ptr(typename)))
32
+ end
33
+
34
+ def escape_const_ref_ptr(typename)
35
+ typename.gsub(/^ *const /,'').gsub(/ +(const)* *[&*]* *(const)* *$/,'').strip
36
+ end
37
+
38
+ def del_prefix_class(n) # Previuously escaped for const
39
+ n.gsub(%r{^[^<]*[:]}, "")
40
+ end
41
+
42
+ def is_primitive?(typename)
43
+ ['void', 'bool', 'char', 'unsigned char',
44
+ 'short', 'unsigned short', 'int', 'unsigned int',
45
+ 'long', 'unsigned long', 'long long', 'unsigned long long int',
46
+ 'unsigned long long', 'float', 'double', 'long double',
47
+ 'size_t', 'uint32', 'uint8', 'uint16'].include?(typename)
48
+ end
49
+
50
+ def is_std?(typename) # TODO depends on language. What happens with templates?
51
+ ['vector', 'string', 'pair', 'list',
52
+ 'map', 'deque', 'multimap', 'set'].include?(typename)
53
+ end
54
+
55
+ def escape_template(typename)
56
+ typename.gsub(/<.+$/,'').strip
57
+ end
58
+
59
+ def logs_dir
60
+ @output_dir+"/logs"
61
+ end
62
+
63
+ def gen_dir
64
+ File.expand_path(output_dir+"/gen")
65
+ end
66
+
67
+ def swig_dir
68
+ File.expand_path(output_dir+"/swig")
69
+ end
70
+
71
+ def read_file file_name
72
+ file = File.open(file_name, "r")
73
+ data = file.read
74
+ file.close
75
+ return data
76
+ end
77
+
78
+ def write_file file_name, data
79
+ FileUtils::mkdir_p File.dirname(file_name)
80
+ file = File.open(file_name, "w")
81
+ count = file.write(data)
82
+ file.close
83
+ return count
84
+ end
85
+
86
+ def rename_files (dir, find, ext='*', &block)
87
+ if ext
88
+ Dir.glob(%Q{#{dir}/*.#{ext}}) { |file|
89
+ # do work on files ending in .ext in the desired directory
90
+ name = File.basename(file, "."+ext)
91
+ newname = name.gsub(find) { |match|
92
+ puts match
93
+ a = block.call(match, $1)
94
+ a
95
+ }
96
+ File.rename(file, file.gsub(name, newname))
97
+ }
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,45 @@
1
+ #!/usr/bin rspec
2
+ require 'rspec'
3
+ require_relative '../../lib/easy-swig'
4
+ require_relative '../functional_tests_support'
5
+
6
+ def name
7
+ 'accessors'
8
+ end
9
+
10
+ describe "Accessors" do
11
+
12
+ before(:all) do
13
+ @spec_dir = File.dirname(__FILE__)
14
+ @config = EasySwig::Config.new(@spec_dir)
15
+ @config.stl_support = nil
16
+ @swig_dir = ::File.expand_path('./easy-swig/swig', @spec_dir)
17
+
18
+ EasySwig::doxygen(@config)
19
+ # Uncomment to regenerate files when needed
20
+ #compile_lib(@spec_dir + '/include', @spec_dir + '/lib', name.capitalize + 'Spec' )
21
+ EasySwig::generate(@config)
22
+ EasySwig::swig(@config)
23
+ end
24
+
25
+ it "should run swig succesfully" do
26
+ ::File.exists?(@swig_dir).should be_true
27
+ ::File.exists?(@swig_dir+"/#{name}_wrap.cxx").should be_true
28
+ end
29
+
30
+ it "should compile C# code" do
31
+ verify_compilation_csharp(@swig_dir, name) # .dll
32
+ end
33
+
34
+ it "should compile C++ wrapper" do
35
+ verify_compilation_cpp(@swig_dir, name) # .o
36
+ end
37
+
38
+ it "should link C++ wrapper against shared library" do
39
+ verify_linking_cpp(@swig_dir, name, name.capitalize + 'Spec') # lib#{name}.so
40
+ end
41
+
42
+ it "should run functional tests" do
43
+ verify_functional_test(@swig_dir, name.capitalize + 'Test') # .cs
44
+ end
45
+ end
@@ -0,0 +1,49 @@
1
+ #!/usr/bin rspec
2
+ require 'rspec'
3
+ require_relative '../../lib/easy-swig'
4
+ require_relative '../functional_tests_support'
5
+
6
+ def name
7
+ 'anonymousEnums'
8
+ end
9
+
10
+ describe "AnonymousEnums" do
11
+
12
+ before(:all) do
13
+ @spec_dir = File.dirname(__FILE__)
14
+ @config = EasySwig::Config.new(@spec_dir)
15
+ @config.stl_support = nil
16
+ @swig_dir = ::File.expand_path('./easy-swig/swig', @spec_dir)
17
+
18
+ EasySwig::doxygen(@config)
19
+ # Uncomment to regenerate files when needed
20
+ #compile_lib(@spec_dir + '/include', @spec_dir + '/lib', name.capitalize + 'Spec' )
21
+ EasySwig::generate(@config)
22
+ EasySwig::swig(@config)
23
+ end
24
+
25
+ it "should run swig" do
26
+ ::File.exists?(@swig_dir).should be_true
27
+ ::File.exists?(@swig_dir+'/anonymousEnums_wrap.cxx').should be_true
28
+ ::File.exists?(@swig_dir+'/anonymousEnums/AnonymousEnums.cs').should be_true
29
+ ::File.exists?(@swig_dir+'/anonymousEnums/AnonymousEnums_Enum.cs').should be_true
30
+ ::File.exists?(@swig_dir+'/anonymousEnums/file_AnonymousEnums_Enum.cs').should be_true
31
+ ::File.exists?(@swig_dir+'/anonymousEnums/ns_TestNamespace_Enum.cs').should be_true
32
+ end
33
+
34
+ it "should compile C# code" do
35
+ verify_compilation_csharp(@swig_dir, name) # .dll
36
+ end
37
+
38
+ it "should compile C++ wrapper" do
39
+ verify_compilation_cpp(@swig_dir, name) # .o
40
+ end
41
+
42
+ it "should link C++ wrapper against shared library" do
43
+ verify_linking_cpp(@swig_dir, name, name.capitalize + 'Spec') # lib#{name}.so
44
+ end
45
+
46
+ it "should run functional tests" do
47
+ verify_functional_test(@swig_dir, name.capitalize + 'Test') # .cs
48
+ end
49
+ end
@@ -0,0 +1,45 @@
1
+ #!/usr/bin rspec
2
+ require 'rspec'
3
+ require_relative '../../lib/easy-swig'
4
+ require_relative '../functional_tests_support'
5
+
6
+ def name
7
+ 'friends'
8
+ end
9
+
10
+ describe "Friends" do
11
+
12
+ before(:all) do
13
+ @spec_dir = File.dirname(__FILE__)
14
+ @config = EasySwig::Config.new(@spec_dir)
15
+ @config.stl_support = nil
16
+ @swig_dir = ::File.expand_path('./easy-swig/swig', @spec_dir)
17
+
18
+ EasySwig::doxygen(@config)
19
+ # Uncomment to regenerate files when needed
20
+ #compile_lib(@spec_dir + '/include', @spec_dir + '/lib', name.capitalize + 'Spec' )
21
+ EasySwig::generate(@config)
22
+ EasySwig::swig(@config)
23
+ end
24
+
25
+ it "should run swig succesfully" do
26
+ ::File.exists?(@swig_dir).should be_true
27
+ ::File.exists?(@swig_dir+"/#{name}_wrap.cxx").should be_true
28
+ end
29
+
30
+ it "should compile C# code" do
31
+ verify_compilation_csharp(@swig_dir, name) # .dll
32
+ end
33
+
34
+ it "should compile C++ wrapper" do
35
+ verify_compilation_cpp(@swig_dir, name) # .o
36
+ end
37
+
38
+ it "should link C++ wrapper against shared library" do
39
+ verify_linking_cpp(@swig_dir, name, name.capitalize + 'Spec') # lib#{name}.so
40
+ end
41
+
42
+ it "should run functional tests" do
43
+ verify_functional_test(@swig_dir, name.capitalize + 'Test') # .cs
44
+ end
45
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin rspec
2
+ require 'rspec'
3
+ require_relative '../../lib/easy-swig'
4
+ require_relative '../functional_tests_support'
5
+
6
+ def name
7
+ 'innerclasses'
8
+ end
9
+
10
+ describe "Innerclasses" do
11
+
12
+ before(:all) do
13
+ @spec_dir = File.dirname(__FILE__)
14
+ @config = EasySwig::Config.new(@spec_dir)
15
+ @config.stl_support = nil
16
+ @swig_dir = ::File.expand_path('./easy-swig/swig', @spec_dir)
17
+
18
+ EasySwig::doxygen(@config)
19
+ # Uncomment to regenerate files when needed
20
+ #compile_lib(@spec_dir + '/include', @spec_dir + '/lib', name.capitalize + 'Spec' )
21
+ EasySwig::generate(@config)
22
+ EasySwig::swig(@config)
23
+ end
24
+
25
+ it "should run swig succesfully" do
26
+ ::File.exists?(@swig_dir).should be_true
27
+ ::File.exists?(@swig_dir+"/#{name}_wrap.cxx").should be_true
28
+ ::File.exists?(@swig_dir+"/#{name}/Inner3.cs").should be_false
29
+ ::File.exists?(@swig_dir+"/#{name}/Inner4.cs").should be_false
30
+ ::File.exists?(@swig_dir+"/#{name}/Inner5.cs").should be_false
31
+ end
32
+
33
+ it "should compile C# code" do
34
+ verify_compilation_csharp(@swig_dir, name) # .dll
35
+ end
36
+
37
+ it "should compile C++ wrapper" do
38
+ verify_compilation_cpp(@swig_dir, name) # .o
39
+ end
40
+
41
+ it "should link C++ wrapper against shared library" do
42
+ verify_linking_cpp(@swig_dir, name, name.capitalize + 'Spec') # lib#{name}.so
43
+ end
44
+
45
+ it "should run functional tests" do
46
+ verify_functional_test(@swig_dir, name.capitalize + 'Test') # .cs
47
+ end
48
+ end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin rspec
2
+ require 'rspec'
3
+ require_relative '../../lib/easy-swig'
4
+ require_relative '../functional_tests_support'
5
+
6
+
7
+ def name
8
+ 'namespacePrefixes'
9
+ end
10
+
11
+ describe "NamespacePrefixes" do
12
+
13
+ before(:all) do
14
+ @spec_dir = File.dirname(__FILE__)
15
+ @config = EasySwig::Config.new(@spec_dir)
16
+ @config.stl_support = nil
17
+ @swig_dir = ::File.expand_path('./easy-swig/swig', @spec_dir)
18
+
19
+ EasySwig::doxygen(@config)
20
+ EasySwig::generate(@config)
21
+ EasySwig::swig(@config)
22
+ end
23
+
24
+ it "should run swig succesfully" do
25
+ ::File.exists?(@swig_dir).should be_true
26
+ ::File.exists?(@swig_dir+"/#{name}_wrap.cxx").should be_true
27
+ ::File.exists?("#{@swig_dir}/#{name}/VectorInt.cs").should be_true
28
+ ::File.exists?("#{@swig_dir}/#{name}/VectorKlass1.cs").should be_true
29
+ ::File.exists?("#{@swig_dir}/#{name}/VectorKlass2.cs").should be_true
30
+ end
31
+
32
+ it "should compile C# code" do
33
+ verify_compilation_csharp(@swig_dir, name) # .dll
34
+ end
35
+
36
+ it "should compile C++ wrapper" do
37
+ verify_compilation_cpp(@swig_dir, name) # .o
38
+ end
39
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin rspec
2
+ require 'rspec'
3
+ require_relative '../../lib/easy-swig'
4
+ require_relative '../functional_tests_support'
5
+
6
+ def name
7
+ 'squish'
8
+ end
9
+
10
+ describe "Squish" do
11
+
12
+ before(:all) do
13
+ @spec_dir = File.dirname(__FILE__)
14
+ @config = EasySwig::Config.new(@spec_dir)
15
+ @config.stl_support = nil
16
+ @swig_dir = ::File.expand_path('./easy-swig/swig', @spec_dir)
17
+
18
+ EasySwig::doxygen(@config)
19
+ EasySwig::generate(@config)
20
+ EasySwig::swig(@config)
21
+ end
22
+
23
+ it "should run swig succesfully" do
24
+ ::File.exists?(@swig_dir).should be_true
25
+ ::File.exists?(@swig_dir+"/#{name}_wrap.cxx").should be_true
26
+ end
27
+
28
+ it "should compile C# code" do
29
+ verify_compilation_csharp(@swig_dir, name) # .dll
30
+ end
31
+
32
+ it "should compile C++ wrapper" do
33
+ verify_compilation_cpp(@swig_dir, name) # .o
34
+ end
35
+
36
+ it "should link C++ wrapper against shared library" do
37
+ verify_linking_cpp(@swig_dir, name, name.capitalize + 'Spec') # lib#{name}.so
38
+ end
39
+ end
40
+
@@ -0,0 +1,41 @@
1
+ #!/usr/bin rspec
2
+ require 'rspec'
3
+ require_relative '../../lib/easy-swig'
4
+ require_relative '../functional_tests_support'
5
+
6
+ def name
7
+ 'subdirectories'
8
+ end
9
+
10
+ describe "Subdirectories" do
11
+
12
+ before(:all) do
13
+ @spec_dir = File.dirname(__FILE__)
14
+ @config = EasySwig::Config.new(@spec_dir)
15
+ @config.stl_support = nil
16
+ @swig_dir = ::File.expand_path('./easy-swig/swig', @spec_dir)
17
+
18
+ EasySwig::doxygen(@config)
19
+ # Uncomment to regenerate files when needed
20
+ #compile_lib(@spec_dir + '/include', @spec_dir + '/lib', name.capitalize + 'Spec' )
21
+ EasySwig::generate(@config)
22
+ EasySwig::swig(@config)
23
+ end
24
+
25
+ it "should run swig succesfully" do
26
+ ::File.exists?(@swig_dir).should be_true
27
+ ::File.exists?(@swig_dir+"/#{name}_wrap.cxx").should be_true
28
+ end
29
+
30
+ it "should compile C# code" do
31
+ verify_compilation_csharp(@swig_dir, name) # .dll
32
+ end
33
+
34
+ it "should compile C++ wrapper" do
35
+ verify_compilation_cpp(@swig_dir, name) # .o
36
+ end
37
+
38
+ it "should link C++ wrapper against shared library" do
39
+ verify_linking_cpp(@swig_dir, name, name.capitalize + 'Spec') # lib#{name}.so
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin rspec
2
+ require 'rspec'
3
+ require_relative '../../lib/easy-swig'
4
+ require_relative '../functional_tests_support'
5
+
6
+ def name
7
+ 'templates'
8
+ end
9
+
10
+ describe "Templates" do
11
+
12
+ before(:all) do
13
+ @spec_dir = File.dirname(__FILE__)
14
+ @config = EasySwig::Config.new(@spec_dir)
15
+ @config.stl_support = nil
16
+ @swig_dir = ::File.expand_path('./easy-swig/swig', @spec_dir)
17
+ EasySwig::doxygen(@config)
18
+ EasySwig::generate(@config)
19
+ EasySwig::swig(@config)
20
+ end
21
+
22
+ it "should run swig succesfully" do
23
+ ::File.exists?(@swig_dir).should be_true
24
+ ::File.exists?(@swig_dir+"/#{name}_wrap.cxx").should be_true
25
+ end
26
+
27
+ it "should compile C# code" do
28
+ verify_compilation_csharp(@swig_dir, name) # .dll
29
+ end
30
+
31
+ it "should compile C++ wrapper" do
32
+ verify_compilation_cpp(@swig_dir, name) # .o
33
+ end
34
+ end