ritsu 0.2.0 → 0.3.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.
- data/Thorfile +3 -3
- data/VERSION +1 -1
- data/bin/define_cpp_string +54 -0
- data/lib/ritsu/ext/glsl/src_files/glfp_file.rb +79 -0
- data/lib/ritsu/ext/glsl/src_files/glvp_file.rb +76 -0
- data/lib/ritsu/ext/glsl.rb +2 -0
- data/lib/ritsu/src_file.rb +4 -0
- data/lib/ritsu/src_files/project_cmake_lists.rb +1 -1
- data/lib/ritsu/src_files/unit.rb +1 -1
- data/test/ritsu/src_files/project_cmake_lists_test.rb +2 -2
- metadata +12 -7
data/Thorfile
CHANGED
@@ -58,10 +58,10 @@ class Default < Thor
|
|
58
58
|
s.version = File.read(File.dirname(__FILE__) + '/VERSION').strip
|
59
59
|
s.rubyforge_project = "ritsu"
|
60
60
|
s.platform = Gem::Platform::RUBY
|
61
|
-
s.summary = "A code generation system that facilitates building C/C++ software with the help of CMake
|
61
|
+
s.summary = "A code generation system that facilitates building C/C++ software with the help of CMake"
|
62
62
|
s.email = "dragonmeteor@gmail.com"
|
63
63
|
s.homepage = "http://github.com/dragonmeteor/ritsu"
|
64
|
-
s.description = "
|
64
|
+
s.description = "Ritsu is a tool to help generate CMakeLists.txt and other source code files in a C++ software project."
|
65
65
|
s.authors = ['dragonmeteor']
|
66
66
|
|
67
67
|
s.has_rdoc = true
|
@@ -75,7 +75,7 @@ class Default < Thor
|
|
75
75
|
|
76
76
|
s.require_path = 'lib'
|
77
77
|
s.bindir = "bin"
|
78
|
-
s.executables = %w( ritsu )
|
78
|
+
s.executables = %w( ritsu define_cpp_string )
|
79
79
|
s.files = s.extra_rdoc_files + Dir.glob("{bin,lib}/**/*")
|
80
80
|
s.test_files.include 'test/**/*'
|
81
81
|
s.test_files.exclude 'test/**/output/**'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Convert a text file's content into a C++ const string.
|
3
|
+
|
4
|
+
# Turn the given string to
|
5
|
+
# a C string literal that
|
6
|
+
# parses to the original string.
|
7
|
+
def string_literal(s)
|
8
|
+
result = "\"\\\n"
|
9
|
+
s.each_byte do |b|
|
10
|
+
c = b.chr
|
11
|
+
if c == "\n"
|
12
|
+
result += "\\n\\\n"
|
13
|
+
elsif c == "\r"
|
14
|
+
next
|
15
|
+
elsif c == "\\"
|
16
|
+
result += "\\\\"
|
17
|
+
elsif c == "\""
|
18
|
+
result += "\\\""
|
19
|
+
else
|
20
|
+
result += c
|
21
|
+
end
|
22
|
+
end
|
23
|
+
result += "\""
|
24
|
+
result
|
25
|
+
end
|
26
|
+
|
27
|
+
# Declare a constant string
|
28
|
+
# variable whose value
|
29
|
+
# is the given string.
|
30
|
+
def const_string(name, s)
|
31
|
+
result = "const char * #{name} = " + string_literal(s) + ";"
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'optparse'
|
35
|
+
|
36
|
+
parser = OptionParser.new do |parser|
|
37
|
+
parser.banner = "Usage: define_cpp_string variable_name"
|
38
|
+
|
39
|
+
parser.on_tail("-h", "--help", "Show this message") do
|
40
|
+
puts parser
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
parser.parse(ARGV)
|
46
|
+
var_name = ARGV.shift
|
47
|
+
if not var_name
|
48
|
+
puts parser
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
|
52
|
+
s = STDIN.read
|
53
|
+
|
54
|
+
puts const_string(var_name, s)
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_support/core_ext/string/inflections'
|
3
|
+
require File.dirname(__FILE__) + '/../../../src_file'
|
4
|
+
require File.dirname(__FILE__) + '/../../../project'
|
5
|
+
require File.dirname(__FILE__) + '/../../../utility/instance_set'
|
6
|
+
require File.dirname(__FILE__) + '/../../../src_files/cpp_file'
|
7
|
+
|
8
|
+
module Ritsu
|
9
|
+
module SrcFiles
|
10
|
+
module GlfpFileMixin
|
11
|
+
def glsl_file?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def glvp_file?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
def glfp_file?
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
def header_file?
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def cpp_file?
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def cpp_file_base_name
|
32
|
+
base_name.gsub(/[.\/]+/,'_') + ".cpp"
|
33
|
+
end
|
34
|
+
|
35
|
+
def code_var_name
|
36
|
+
src_path.gsub(/[.\/]+/,'_') + "_code"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class GlfpFile < Ritsu::SrcFile
|
41
|
+
include GlfpFileMixin
|
42
|
+
|
43
|
+
def initialize(src_path, owner)
|
44
|
+
super(src_path, owner)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
module AddGlfpFile
|
49
|
+
def add_glfp_file(path, options={})
|
50
|
+
src_path = compute_src_path(path, options)
|
51
|
+
glfp_file = GlfpFile.new(src_path, self)
|
52
|
+
|
53
|
+
cpp_src_path = compute_src_path(glfp_file.cpp_file_base_name, options)
|
54
|
+
cpp_file = CppFile.new(cpp_src_path, self)
|
55
|
+
|
56
|
+
self.custom_commands << "ADD_CUSTOM_COMMAND(\n" +
|
57
|
+
" OUTPUT ${CMAKE_SOURCE_DIR}/#{cpp_src_path}\n" +
|
58
|
+
" COMMAND define_cpp_string #{glfp_file.code_var_name} < ${CMAKE_SOURCE_DIR}/#{glfp_file.src_path} > ${CMAKE_SOURCE_DIR}/#{cpp_file.src_path}\n" +
|
59
|
+
" DEPENDS ${CMAKE_SOURCE_DIR}/#{glfp_file.src_path})"
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_glfp_files(*paths)
|
63
|
+
paths.each do |path|
|
64
|
+
add_glfp_file(path)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
module Ritsu
|
72
|
+
class Target
|
73
|
+
include Ritsu::SrcFiles::AddGlfpFile
|
74
|
+
end
|
75
|
+
|
76
|
+
class Project
|
77
|
+
include Ritsu::SrcFiles::AddGlfpFile
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../src_file'
|
2
|
+
require File.dirname(__FILE__) + '/../../../project'
|
3
|
+
require File.dirname(__FILE__) + '/../../../utility/instance_set'
|
4
|
+
|
5
|
+
module Ritsu
|
6
|
+
module SrcFiles
|
7
|
+
module GlvpFileMixin
|
8
|
+
def glsl_file?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def glvp_file?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def glfp_file?
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
def header_file?
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
def cpp_file?
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def cpp_file_base_name
|
29
|
+
base_name.gsub(/[.\/]+/,'_') + ".cpp"
|
30
|
+
end
|
31
|
+
|
32
|
+
def code_var_name
|
33
|
+
src_path.gsub(/[.\/]+/,'_') + "_code"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class GlvpFile < Ritsu::SrcFile
|
38
|
+
include GlvpFileMixin
|
39
|
+
|
40
|
+
def initialize(src_path, owner)
|
41
|
+
super(src_path, owner)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module AddGlvpFile
|
46
|
+
def add_glvp_file(path, options={})
|
47
|
+
src_path = compute_src_path(path, options)
|
48
|
+
glvp_file = GlvpFile.new(src_path, self)
|
49
|
+
|
50
|
+
cpp_src_path = compute_src_path(glvp_file.cpp_file_base_name, options)
|
51
|
+
cpp_file = CppFile.new(cpp_src_path, self)
|
52
|
+
|
53
|
+
self.custom_commands << "ADD_CUSTOM_COMMAND(\n" +
|
54
|
+
" OUTPUT ${CMAKE_SOURCE_DIR}/#{cpp_src_path}\n" +
|
55
|
+
" COMMAND define_cpp_string #{glvp_file.code_var_name} < ${CMAKE_SOURCE_DIR}/#{glvp_file.src_path} > ${CMAKE_SOURCE_DIR}/#{cpp_file.src_path}\n" +
|
56
|
+
" DEPENDS ${CMAKE_SOURCE_DIR}/#{glvp_file.src_path})"
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_glvp_files(*paths)
|
60
|
+
paths.each do |path|
|
61
|
+
add_glvp_file(path)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
module Ritsu
|
69
|
+
class Target
|
70
|
+
include Ritsu::SrcFiles::AddGlvpFile
|
71
|
+
end
|
72
|
+
|
73
|
+
class Project
|
74
|
+
include Ritsu::SrcFiles::AddGlvpFile
|
75
|
+
end
|
76
|
+
end
|
data/lib/ritsu/src_file.rb
CHANGED
@@ -27,6 +27,10 @@ module Ritsu
|
|
27
27
|
@owner.src_files << self
|
28
28
|
end
|
29
29
|
|
30
|
+
def base_name
|
31
|
+
File.basename(src_path)
|
32
|
+
end
|
33
|
+
|
30
34
|
def self.validate_instance(instance)
|
31
35
|
if instances.select { |x| x.src_path == instance.src_path }.length > 0
|
32
36
|
raise ArgumentError.new "source file with path '#{instance.src_path}' already exists"
|
@@ -13,7 +13,7 @@ module Ritsu
|
|
13
13
|
@project = project
|
14
14
|
|
15
15
|
add_line "PROJECT(#{@project.name})"
|
16
|
-
add_line "CMAKE_MINIMUM_REQUIRED(VERSION 2.
|
16
|
+
add_line "CMAKE_MINIMUM_REQUIRED(VERSION 2.8)"
|
17
17
|
add_line "SET(CMAKE_MODULE_PATH \"${CMAKE_SOURCE_DIR}/cmake_modules\" ${CMAKE_MODULE_PATH})"
|
18
18
|
add_new_line
|
19
19
|
add_line "IF(WIN32)"
|
data/lib/ritsu/src_files/unit.rb
CHANGED
@@ -37,7 +37,7 @@ class ProjectCMakeListsTest < Test::Unit::TestCase
|
|
37
37
|
expected_content = <<-TEXT
|
38
38
|
##<< ProjectCmakeLists -- Header
|
39
39
|
PROJECT(mio)
|
40
|
-
CMAKE_MINIMUM_REQUIRED(VERSION 2.
|
40
|
+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
41
41
|
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
|
42
42
|
|
43
43
|
IF(WIN32)
|
@@ -107,7 +107,7 @@ CMAKE
|
|
107
107
|
expected_content = <<-TEXT
|
108
108
|
##<< ProjectCmakeLists -- Header
|
109
109
|
PROJECT(mio)
|
110
|
-
CMAKE_MINIMUM_REQUIRED(VERSION 2.
|
110
|
+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
111
111
|
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
|
112
112
|
|
113
113
|
IF(WIN32)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ritsu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- dragonmeteor
|
@@ -15,8 +15,8 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
19
|
-
default_executable:
|
18
|
+
date: 2010-07-21 00:00:00 +07:00
|
19
|
+
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: thor
|
@@ -98,10 +98,11 @@ dependencies:
|
|
98
98
|
version: 0.5.9
|
99
99
|
type: :development
|
100
100
|
version_requirements: *id005
|
101
|
-
description:
|
101
|
+
description: Ritsu is a tool to help generate CMakeLists.txt and other source code files in a C++ software project.
|
102
102
|
email: dragonmeteor@gmail.com
|
103
103
|
executables:
|
104
104
|
- ritsu
|
105
|
+
- define_cpp_string
|
105
106
|
extensions: []
|
106
107
|
|
107
108
|
extra_rdoc_files:
|
@@ -112,12 +113,16 @@ files:
|
|
112
113
|
- README.md
|
113
114
|
- Thorfile
|
114
115
|
- VERSION
|
116
|
+
- bin/define_cpp_string
|
115
117
|
- bin/ritsu
|
116
118
|
- lib/ritsu.rb
|
117
119
|
- lib/ritsu/block.rb
|
118
120
|
- lib/ritsu/ext/fake_install.rb
|
119
121
|
- lib/ritsu/ext/fake_install/project.rb
|
120
122
|
- lib/ritsu/ext/fake_install/src_files/project_cmake_lists.rb
|
123
|
+
- lib/ritsu/ext/glsl.rb
|
124
|
+
- lib/ritsu/ext/glsl/src_files/glfp_file.rb
|
125
|
+
- lib/ritsu/ext/glsl/src_files/glvp_file.rb
|
121
126
|
- lib/ritsu/ext/test_case.rb
|
122
127
|
- lib/ritsu/external_library.rb
|
123
128
|
- lib/ritsu/project.rb
|
@@ -224,7 +229,7 @@ rubyforge_project: ritsu
|
|
224
229
|
rubygems_version: 1.3.7
|
225
230
|
signing_key:
|
226
231
|
specification_version: 3
|
227
|
-
summary: A code generation system that facilitates building C/C++ software with the help of CMake
|
232
|
+
summary: A code generation system that facilitates building C/C++ software with the help of CMake
|
228
233
|
test_files:
|
229
234
|
- test/ritsu/block_test.rb
|
230
235
|
- test/ritsu/external_library_test.rb
|