ritsu 0.7.0 → 0.7.1

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 (89) hide show
  1. data/README.md +95 -95
  2. data/bin/define_cpp_string +54 -54
  3. data/bin/ritsu +31 -31
  4. data/lib/ritsu.rb +16 -16
  5. data/lib/ritsu/block.rb +258 -258
  6. data/lib/ritsu/ext/cuda.rb +5 -5
  7. data/lib/ritsu/ext/cuda/external_library.rb +15 -15
  8. data/lib/ritsu/ext/cuda/project.rb +31 -31
  9. data/lib/ritsu/ext/cuda/src_files/cu_file.rb +46 -46
  10. data/lib/ritsu/ext/cuda/src_files/target_cmake_lists.rb +110 -110
  11. data/lib/ritsu/ext/cuda/target.rb +16 -16
  12. data/lib/ritsu/ext/cuda/targets/library.rb +16 -16
  13. data/lib/ritsu/ext/fake_install.rb +2 -2
  14. data/lib/ritsu/ext/fake_install/project.rb +16 -16
  15. data/lib/ritsu/ext/fake_install/src_files/project_cmake_lists.rb +45 -45
  16. data/lib/ritsu/ext/glsl.rb +1 -1
  17. data/lib/ritsu/ext/glsl/src_files/frag_file.rb +70 -70
  18. data/lib/ritsu/ext/glsl/src_files/vert_file.rb +70 -70
  19. data/lib/ritsu/ext/qt.rb +4 -4
  20. data/lib/ritsu/ext/qt/project.rb +47 -47
  21. data/lib/ritsu/ext/qt/src_files/header_file.rb +60 -60
  22. data/lib/ritsu/ext/qt/src_files/target_cmake_lists.rb +106 -106
  23. data/lib/ritsu/ext/qt/src_files/ui_file.rb +46 -46
  24. data/lib/ritsu/ext/test_case.rb +19 -19
  25. data/lib/ritsu/external_library.rb +46 -46
  26. data/lib/ritsu/project.rb +93 -93
  27. data/lib/ritsu/project_generator.rb +33 -33
  28. data/lib/ritsu/project_generators/default_generator.rb +72 -72
  29. data/lib/ritsu/project_generators/default_generator_files/Thorfile.erb +8 -8
  30. data/lib/ritsu/project_generators/default_generator_files/meta/project.rb.erb +10 -10
  31. data/lib/ritsu/src_file.rb +79 -79
  32. data/lib/ritsu/src_files.rb +12 -12
  33. data/lib/ritsu/src_files/cpp_file.rb +43 -43
  34. data/lib/ritsu/src_files/executable_cmake_lists.rb +39 -39
  35. data/lib/ritsu/src_files/header_file.rb +60 -60
  36. data/lib/ritsu/src_files/project_cmake_lists.rb +133 -133
  37. data/lib/ritsu/src_files/project_config_header_file.rb +14 -14
  38. data/lib/ritsu/src_files/project_config_header_template_file.rb +44 -44
  39. data/lib/ritsu/src_files/shared_library_cmake_lists.rb +39 -39
  40. data/lib/ritsu/src_files/static_library_cmake_lists.rb +39 -39
  41. data/lib/ritsu/src_files/target_cmake_lists.rb +189 -189
  42. data/lib/ritsu/src_files/templated_src_file.rb +47 -47
  43. data/lib/ritsu/src_files/unit.rb +32 -32
  44. data/lib/ritsu/target.rb +154 -154
  45. data/lib/ritsu/targets.rb +3 -3
  46. data/lib/ritsu/targets/executable.rb +44 -44
  47. data/lib/ritsu/targets/library.rb +29 -29
  48. data/lib/ritsu/targets/shared_library.rb +38 -38
  49. data/lib/ritsu/targets/static_library.rb +32 -32
  50. data/lib/ritsu/template.rb +68 -68
  51. data/lib/ritsu/template_policies.rb +132 -132
  52. data/lib/ritsu/test_helpers.rb +123 -123
  53. data/lib/ritsu/thors/default_thor.rb +1 -1
  54. data/lib/ritsu/utility.rb +7 -7
  55. data/lib/ritsu/utility/accessors.rb +29 -29
  56. data/lib/ritsu/utility/check_upon_add_set.rb +34 -34
  57. data/lib/ritsu/utility/file_robot.rb +128 -128
  58. data/lib/ritsu/utility/files.rb +12 -12
  59. data/lib/ritsu/utility/instance_dependencies.rb +112 -112
  60. data/lib/ritsu/utility/instance_set.rb +28 -28
  61. data/lib/ritsu/utility/platform.rb +20 -20
  62. data/lib/ritsu/utility/simple_io.rb +64 -64
  63. data/lib/ritsu/utility/single_instance.rb +33 -33
  64. data/lib/ritsu/utility/strings.rb +40 -40
  65. data/test/ritsu/block_test.rb +196 -196
  66. data/test/ritsu/ext/cuda/src_files/cuda_static_library_cmake_lists_test.rb +63 -63
  67. data/test/ritsu/external_library_test.rb +41 -41
  68. data/test/ritsu/project_generators/default_generator_test.rb +34 -34
  69. data/test/ritsu/project_test.rb +127 -127
  70. data/test/ritsu/src_file_test.rb +69 -69
  71. data/test/ritsu/src_files/cpp_file_test.rb +42 -42
  72. data/test/ritsu/src_files/executable_cmake_lists_test.rb +92 -92
  73. data/test/ritsu/src_files/header_file_test.rb +57 -57
  74. data/test/ritsu/src_files/project_cmake_lists_test.rb +159 -159
  75. data/test/ritsu/src_files/shared_library_cmake_lists_test.rb +54 -54
  76. data/test/ritsu/src_files/static_library_cmake_lists_test.rb +54 -54
  77. data/test/ritsu/src_files/target_cmake_lists_test.rb +15 -15
  78. data/test/ritsu/target_test.rb +105 -105
  79. data/test/ritsu/targets/executable_test.rb +10 -10
  80. data/test/ritsu/targets/shared_library_test.rb +10 -10
  81. data/test/ritsu/targets/static_library_test.rb +10 -10
  82. data/test/ritsu/utility/accessors_test.rb +14 -14
  83. data/test/ritsu/utility/check_upon_add_set_test.rb +31 -31
  84. data/test/ritsu/utility/file_robot_test.rb +175 -175
  85. data/test/ritsu/utility/strings_test.rb +28 -28
  86. data/test/test_helpers.rb +3 -3
  87. metadata +72 -124
  88. data/Thorfile +0 -104
  89. data/VERSION +0 -1
@@ -1,34 +1,34 @@
1
- module Ritsu
2
- module Utility
3
- module SingleInstance
4
- module ClassMethods
5
- def instance
6
- @instance ||= nil
7
- end
8
-
9
- def set_instance(instance)
10
- validate_instance(instance)
11
- @instance = instance
12
- end
13
-
14
- def validate_instance(instance)
15
- end
16
- end
17
-
18
- def self.included(base)
19
- base.extend(ClassMethods)
20
- end
21
-
22
- def initialize(*args, &block)
23
- initialize_instance(*args, &block)
24
- self.class.set_instance(self)
25
- end
26
-
27
- def initialize_instance(*args, &block)
28
- if self.class.superclass.method_defined? :initialize_instance
29
- super
30
- end
31
- end
32
- end
33
- end
1
+ module Ritsu
2
+ module Utility
3
+ module SingleInstance
4
+ module ClassMethods
5
+ def instance
6
+ @instance ||= nil
7
+ end
8
+
9
+ def set_instance(instance)
10
+ validate_instance(instance)
11
+ @instance = instance
12
+ end
13
+
14
+ def validate_instance(instance)
15
+ end
16
+ end
17
+
18
+ def self.included(base)
19
+ base.extend(ClassMethods)
20
+ end
21
+
22
+ def initialize(*args, &block)
23
+ initialize_instance(*args, &block)
24
+ self.class.set_instance(self)
25
+ end
26
+
27
+ def initialize_instance(*args, &block)
28
+ if self.class.superclass.method_defined? :initialize_instance
29
+ super
30
+ end
31
+ end
32
+ end
33
+ end
34
34
  end
@@ -1,41 +1,41 @@
1
- module Ritsu
2
- module Utility
3
- module Strings
4
- def is_underscore_case?(str)
5
- str =~ /^[a-z_][0-9a-z_]*$/
6
- end
7
- module_function :is_underscore_case?
8
-
9
- def is_c_name?(str)
10
- str =~ /^[A-Za-z_]\w*$/
11
- end
12
- module_function :is_c_name?
13
-
14
- def first(len, str)
15
- if str.length > count
16
- str[0..(len-1)]
17
- else
18
- str
19
- end
20
- end
21
- module_function :first
22
-
23
- def leading_whitespaces(str)
24
- /^\s*/.match(str)[0]
25
- end
26
- module_function :leading_whitespaces
27
-
28
- def convert_whitespaces_to_spaces(str, options={})
29
- options = {:soft_tab => 4}.merge(options)
30
- str.sub("\t", " "*options[:soft_tab]).sub(/\n\r/, "")
31
- end
32
- module_function :convert_whitespaces_to_spaces
33
-
34
- def leading_spaces(str, options={})
35
- Ritsu::Utility::Strings.convert_whitespaces_to_spaces(
36
- Ritsu::Utility::Strings.leading_whitespaces(str), options)
37
- end
38
- module_function :leading_spaces
39
- end
40
- end
1
+ module Ritsu
2
+ module Utility
3
+ module Strings
4
+ def is_underscore_case?(str)
5
+ str =~ /^[a-z_][0-9a-z_]*$/
6
+ end
7
+ module_function :is_underscore_case?
8
+
9
+ def is_c_name?(str)
10
+ str =~ /^[A-Za-z_]\w*$/
11
+ end
12
+ module_function :is_c_name?
13
+
14
+ def first(len, str)
15
+ if str.length > count
16
+ str[0..(len-1)]
17
+ else
18
+ str
19
+ end
20
+ end
21
+ module_function :first
22
+
23
+ def leading_whitespaces(str)
24
+ /^\s*/.match(str)[0]
25
+ end
26
+ module_function :leading_whitespaces
27
+
28
+ def convert_whitespaces_to_spaces(str, options={})
29
+ options = {:soft_tab => 4}.merge(options)
30
+ str.sub("\t", " "*options[:soft_tab]).sub(/\n\r/, "")
31
+ end
32
+ module_function :convert_whitespaces_to_spaces
33
+
34
+ def leading_spaces(str, options={})
35
+ Ritsu::Utility::Strings.convert_whitespaces_to_spaces(
36
+ Ritsu::Utility::Strings.leading_whitespaces(str), options)
37
+ end
38
+ module_function :leading_spaces
39
+ end
40
+ end
41
41
  end
@@ -1,197 +1,197 @@
1
- require File.dirname(__FILE__) + "/../test_helpers"
2
-
3
- class BlockTest < Test::Unit::TestCase
4
- include Ritsu::TestCaseWithFileTestData
5
- include Ritsu::Utility
6
-
7
- def data_dir; File.dirname(__FILE__) + "/" + File.basename(__FILE__, ".rb") end
8
-
9
- must "parse lines with no block content correctly" do
10
- block = Ritsu::Block.new
11
- block.parse_lines(["abc", "def", "ghi"])
12
- assert_equal ["abc", "def", "ghi"], block.contents
13
- end
14
-
15
- BLOCK_A_ARRAY = [
16
- "abc",
17
- "//<< 123",
18
- "def",
19
- "//>> 123",
20
- "ghi",
21
- "jkl",
22
- "//<<",
23
- "mno",
24
- "pqr",
25
- "//>>",
26
- "stu"
27
- ]
28
-
29
- def check_block_A(block)
30
- assert_equal 6, block.contents.length
31
- assert_equal "abc", block.contents[0]
32
- assert_equal 1, block.contents[1].contents.length
33
- assert_equal "def", block.contents[1].contents[0]
34
- assert_equal "ghi", block.contents[2]
35
- assert_equal "jkl", block.contents[3]
36
- assert_equal 2, block.contents[4].contents.length
37
- assert_equal "mno", block.contents[4].contents[0]
38
- assert_equal "pqr", block.contents[4].contents[1]
39
- assert_equal "stu", block.contents[5]
40
- end
41
-
42
- must "parse block delimiter correctly" do
43
- block = Ritsu::Block.new
44
- block.parse_lines(BLOCK_A_ARRAY)
45
- check_block_A(block)
46
- end
47
-
48
- BLOCK_B_ARRAY = [
49
- "//<<",
50
- "//<<",
51
- "//>>",
52
-
53
- "//<<",
54
- "//<<",
55
- "//>>",
56
- "//>>",
57
- "//>>",
58
-
59
- "//<<",
60
- "//>>",
61
- ]
62
-
63
- def check_block_B(block)
64
- assert_equal 2, block.contents.length
65
- assert_equal 2, block.contents[0].contents.length
66
- assert_equal 0, block.contents[0].contents[0].contents.length
67
- assert_equal 1, block.contents[0].contents[1].contents.length
68
- assert_equal 0, block.contents[0].contents[1].contents[0].contents.length
69
- assert_equal 0, block.contents[1].contents.length
70
- end
71
-
72
- must "parse nested block correctly" do
73
- block = Ritsu::Block.new
74
- block.parse_lines(BLOCK_B_ARRAY)
75
- check_block_B(block)
76
- end
77
-
78
- must "convert to string correctly" do
79
- block = Ritsu::Block.new("123",
80
- :contents => [
81
- "abc",
82
- "def",
83
- Ritsu::Block.new("456",
84
- :contents => [
85
- "ghi"
86
- ]
87
- ),
88
- "jkl"
89
- ]
90
- )
91
- expected_string =
92
- "//<< 123\n" +
93
- "abc\n" +
94
- "def\n" +
95
- "//<< 456\n" +
96
- "ghi\n" +
97
- "//>> 456\n" +
98
- "jkl\n" +
99
- "//>> 123"
100
- assert_equal expected_string, block.to_s
101
- end
102
-
103
- must "convert to string correct when the no_delimiter option is set" do
104
- block = Ritsu::Block.new("123",
105
- :contents => [
106
- "abc",
107
- "def",
108
- Ritsu::Block.new("456",
109
- :contents => [
110
- "ghi"
111
- ]
112
- ),
113
- "jkl"
114
- ]
115
- )
116
- expected_string =
117
- "abc\n" +
118
- "def\n" +
119
- "//<< 456\n" +
120
- "ghi\n" +
121
- "//>> 456\n" +
122
- "jkl"
123
- assert_equal expected_string, block.to_s(:no_delimiter=>true)
124
- end
125
-
126
- file_test "write to file" do
127
- block = Ritsu::Block.new("123",
128
- :contents => [
129
- "abc",
130
- "def",
131
- Ritsu::Block.new("456",
132
- :contents => [
133
- "ghi"
134
- ]
135
- ),
136
- "jkl"
137
- ]
138
- )
139
- expected_content =
140
- "abc\n" +
141
- "def\n" +
142
- "//<< 456\n" +
143
- "ghi\n" +
144
- "//>> 456\n" +
145
- "jkl"
146
- block.write_to_file(output_path("block.txt"))
147
- assert_output_file_content expected_content, "block.txt"
148
- end
149
-
150
- must "Block.parse must work correctly on array" do
151
- block = Ritsu::Block.parse(BLOCK_A_ARRAY)
152
- check_block_A(block)
153
- end
154
-
155
- must "Block.parse must work correctly on string" do
156
- block = Ritsu::Block.parse(BLOCK_A_ARRAY.join("\n"))
157
- check_block_A(block)
158
- end
159
-
160
- file_test "Block_dot_parse must work correct on file" do
161
- FileRobot.quietly do
162
- FileRobot.create_file(output_path("block.txt"), BLOCK_A_ARRAY.join("\n"))
163
- end
164
- block = Ritsu::Block.parse(:file => output_path("block.txt"))
165
- check_block_A(block)
166
- end
167
-
168
- BLOCK_C_ARRAY = [
169
- "123",
170
- " //<< abc",
171
- " 456",
172
- " //<< def",
173
- " 789",
174
- " //>> def",
175
- " //>> abc",
176
- ]
177
-
178
- must "parse indented blocks correctly" do
179
- block = Ritsu::Block.parse(BLOCK_C_ARRAY)
180
- assert_equal " ", block.contents[1].local_indentation
181
- assert_equal "456", block.contents[1].contents[0]
182
- assert_equal " ", block.contents[1].contents[1].local_indentation
183
- assert_equal " 789", block.contents[1].contents[1].contents[0]
184
-
185
- expected_string = <<-STRING
186
- 123
187
- //<< abc
188
- 456
189
- //<< def
190
- 789
191
- //>> def
192
- //>> abc
193
- STRING
194
- expected_string.strip!
195
- assert_equal expected_string, block.to_s(:no_delimiter=>true)
196
- end
1
+ require File.dirname(__FILE__) + "/../test_helpers"
2
+
3
+ class BlockTest < Test::Unit::TestCase
4
+ include Ritsu::TestCaseWithFileTestData
5
+ include Ritsu::Utility
6
+
7
+ def data_dir; File.dirname(__FILE__) + "/" + File.basename(__FILE__, ".rb") end
8
+
9
+ must "parse lines with no block content correctly" do
10
+ block = Ritsu::Block.new
11
+ block.parse_lines(["abc", "def", "ghi"])
12
+ assert_equal ["abc", "def", "ghi"], block.contents
13
+ end
14
+
15
+ BLOCK_A_ARRAY = [
16
+ "abc",
17
+ "//<< 123",
18
+ "def",
19
+ "//>> 123",
20
+ "ghi",
21
+ "jkl",
22
+ "//<<",
23
+ "mno",
24
+ "pqr",
25
+ "//>>",
26
+ "stu"
27
+ ]
28
+
29
+ def check_block_A(block)
30
+ assert_equal 6, block.contents.length
31
+ assert_equal "abc", block.contents[0]
32
+ assert_equal 1, block.contents[1].contents.length
33
+ assert_equal "def", block.contents[1].contents[0]
34
+ assert_equal "ghi", block.contents[2]
35
+ assert_equal "jkl", block.contents[3]
36
+ assert_equal 2, block.contents[4].contents.length
37
+ assert_equal "mno", block.contents[4].contents[0]
38
+ assert_equal "pqr", block.contents[4].contents[1]
39
+ assert_equal "stu", block.contents[5]
40
+ end
41
+
42
+ must "parse block delimiter correctly" do
43
+ block = Ritsu::Block.new
44
+ block.parse_lines(BLOCK_A_ARRAY)
45
+ check_block_A(block)
46
+ end
47
+
48
+ BLOCK_B_ARRAY = [
49
+ "//<<",
50
+ "//<<",
51
+ "//>>",
52
+
53
+ "//<<",
54
+ "//<<",
55
+ "//>>",
56
+ "//>>",
57
+ "//>>",
58
+
59
+ "//<<",
60
+ "//>>",
61
+ ]
62
+
63
+ def check_block_B(block)
64
+ assert_equal 2, block.contents.length
65
+ assert_equal 2, block.contents[0].contents.length
66
+ assert_equal 0, block.contents[0].contents[0].contents.length
67
+ assert_equal 1, block.contents[0].contents[1].contents.length
68
+ assert_equal 0, block.contents[0].contents[1].contents[0].contents.length
69
+ assert_equal 0, block.contents[1].contents.length
70
+ end
71
+
72
+ must "parse nested block correctly" do
73
+ block = Ritsu::Block.new
74
+ block.parse_lines(BLOCK_B_ARRAY)
75
+ check_block_B(block)
76
+ end
77
+
78
+ must "convert to string correctly" do
79
+ block = Ritsu::Block.new("123",
80
+ :contents => [
81
+ "abc",
82
+ "def",
83
+ Ritsu::Block.new("456",
84
+ :contents => [
85
+ "ghi"
86
+ ]
87
+ ),
88
+ "jkl"
89
+ ]
90
+ )
91
+ expected_string =
92
+ "//<< 123\n" +
93
+ "abc\n" +
94
+ "def\n" +
95
+ "//<< 456\n" +
96
+ "ghi\n" +
97
+ "//>> 456\n" +
98
+ "jkl\n" +
99
+ "//>> 123"
100
+ assert_equal expected_string, block.to_s
101
+ end
102
+
103
+ must "convert to string correct when the no_delimiter option is set" do
104
+ block = Ritsu::Block.new("123",
105
+ :contents => [
106
+ "abc",
107
+ "def",
108
+ Ritsu::Block.new("456",
109
+ :contents => [
110
+ "ghi"
111
+ ]
112
+ ),
113
+ "jkl"
114
+ ]
115
+ )
116
+ expected_string =
117
+ "abc\n" +
118
+ "def\n" +
119
+ "//<< 456\n" +
120
+ "ghi\n" +
121
+ "//>> 456\n" +
122
+ "jkl"
123
+ assert_equal expected_string, block.to_s(:no_delimiter=>true)
124
+ end
125
+
126
+ file_test "write to file" do
127
+ block = Ritsu::Block.new("123",
128
+ :contents => [
129
+ "abc",
130
+ "def",
131
+ Ritsu::Block.new("456",
132
+ :contents => [
133
+ "ghi"
134
+ ]
135
+ ),
136
+ "jkl"
137
+ ]
138
+ )
139
+ expected_content =
140
+ "abc\n" +
141
+ "def\n" +
142
+ "//<< 456\n" +
143
+ "ghi\n" +
144
+ "//>> 456\n" +
145
+ "jkl"
146
+ block.write_to_file(output_path("block.txt"))
147
+ assert_output_file_content expected_content, "block.txt"
148
+ end
149
+
150
+ must "Block.parse must work correctly on array" do
151
+ block = Ritsu::Block.parse(BLOCK_A_ARRAY)
152
+ check_block_A(block)
153
+ end
154
+
155
+ must "Block.parse must work correctly on string" do
156
+ block = Ritsu::Block.parse(BLOCK_A_ARRAY.join("\n"))
157
+ check_block_A(block)
158
+ end
159
+
160
+ file_test "Block_dot_parse must work correct on file" do
161
+ FileRobot.quietly do
162
+ FileRobot.create_file(output_path("block.txt"), BLOCK_A_ARRAY.join("\n"))
163
+ end
164
+ block = Ritsu::Block.parse(:file => output_path("block.txt"))
165
+ check_block_A(block)
166
+ end
167
+
168
+ BLOCK_C_ARRAY = [
169
+ "123",
170
+ " //<< abc",
171
+ " 456",
172
+ " //<< def",
173
+ " 789",
174
+ " //>> def",
175
+ " //>> abc",
176
+ ]
177
+
178
+ must "parse indented blocks correctly" do
179
+ block = Ritsu::Block.parse(BLOCK_C_ARRAY)
180
+ assert_equal " ", block.contents[1].local_indentation
181
+ assert_equal "456", block.contents[1].contents[0]
182
+ assert_equal " ", block.contents[1].contents[1].local_indentation
183
+ assert_equal " 789", block.contents[1].contents[1].contents[0]
184
+
185
+ expected_string = <<-STRING
186
+ 123
187
+ //<< abc
188
+ 456
189
+ //<< def
190
+ 789
191
+ //>> def
192
+ //>> abc
193
+ STRING
194
+ expected_string.strip!
195
+ assert_equal expected_string, block.to_s(:no_delimiter=>true)
196
+ end
197
197
  end