Class: Ritsu::Target
- Inherits:
-
Object
show all
- Includes:
- SrcFiles::AddCppFile, SrcFiles::AddCuFile, SrcFiles::AddFragFile, SrcFiles::AddHeaderFile, SrcFiles::AddQtHeaderFile, SrcFiles::AddQtUnit, SrcFiles::AddUiFile, SrcFiles::AddUnit, SrcFiles::AddVertFile, Utility::InstanceDependencies, Utility::InstanceSet, Utility::Strings
- Defined in:
- lib/ritsu/target.rb,
lib/ritsu/src_files/unit.rb,
lib/ritsu/ext/cuda/target.rb,
lib/ritsu/src_files/cpp_file.rb,
lib/ritsu/src_files/header_file.rb,
lib/ritsu/ext/qt/src_files/ui_file.rb,
lib/ritsu/ext/cuda/src_files/cu_file.rb,
lib/ritsu/ext/glsl/src_files/frag_file.rb,
lib/ritsu/ext/glsl/src_files/vert_file.rb,
lib/ritsu/ext/qt/src_files/header_file.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#add_qt_unit, #add_qt_units
#add_qt_header_file, #add_qt_header_files
#add_cpp_file, #add_cpp_files
#add_vert_file, #add_vert_files
#add_frag_file, #add_frag_files
#add_cu_file, #add_cu_files
#add_ui_file, #add_ui_files
#add_header_file, #add_header_files
#add_unit, #add_units
convert_whitespaces_to_spaces, first, is_c_name?, is_underscore_case?, leading_spaces, leading_whitespaces
included
included, #initialize_instance
Constructor Details
#initialize(name, options = {}) ⇒ Target
Returns a new instance of Target.
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/ritsu/target.rb', line 27
def initialize(name, options={})
options = {:project => Ritsu::Project.instance}.merge(options)
if !is_c_name?(name)
raise ArgumentError.new(
"target name must be a valid C name")
end
@name = name
@dependency_libraries = Set.new
@project = options[:project]
@src_files = Set.new
@custom_commands = []
@topological_order = 0
@install = false
Target.instances << self
@project.targets << self
end
|
Instance Attribute Details
#custom_commands ⇒ Object
Returns the value of attribute custom_commands.
24
25
26
|
# File 'lib/ritsu/target.rb', line 24
def custom_commands
@custom_commands
end
|
#dependency_libraries ⇒ Object
Returns the value of attribute dependency_libraries.
21
22
23
|
# File 'lib/ritsu/target.rb', line 21
def dependency_libraries
@dependency_libraries
end
|
#name ⇒ Object
Returns the value of attribute name.
20
21
22
|
# File 'lib/ritsu/target.rb', line 20
def name
@name
end
|
#project ⇒ Object
Returns the value of attribute project.
22
23
24
|
# File 'lib/ritsu/target.rb', line 22
def project
@project
end
|
#src_files ⇒ Object
Returns the value of attribute src_files.
23
24
25
|
# File 'lib/ritsu/target.rb', line 23
def src_files
@src_files
end
|
#topological_order ⇒ Object
Returns the value of attribute topological_order.
25
26
27
|
# File 'lib/ritsu/target.rb', line 25
def topological_order
@topological_order
end
|
Class Method Details
.find_by_name(name) ⇒ Object
97
98
99
100
101
102
103
104
|
# File 'lib/ritsu/target.rb', line 97
def self.find_by_name(name)
instances.each do |instance|
if instance.name == name
return instance
end
end
return nil
end
|
.validate_instance(instance) ⇒ Object
47
48
49
50
51
|
# File 'lib/ritsu/target.rb', line 47
def self.validate_instance(instance)
if instances.select { |x| x.name == instance.name }.length > 1
raise "target with name '#{instance.name}' already exists"
end
end
|
Instance Method Details
#abs_dir ⇒ Object
65
66
67
|
# File 'lib/ritsu/target.rb', line 65
def abs_dir
File.expand_path(project.project_dir + "src/#{src_dir}")
end
|
#add_dependency_target(target_or_target_name) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/ritsu/target.rb', line 121
def add_dependency_target(target_or_target_name)
if target_or_target_name.kind_of?(String)
dependency = Target.find_by_name(target_or_target_name)
if dependency.nil?
raise ArgumentError.new("no target with name '#{name}'")
end
else
dependency = target_or_target_name
end
dependency_targets << dependency
end
|
#add_dependency_targets(*target_or_target_names) ⇒ Object
133
134
135
136
137
|
# File 'lib/ritsu/target.rb', line 133
def add_dependency_targets(*target_or_target_names)
target_or_target_names.each do |target|
add_dependency_target(target)
end
end
|
#add_external_libraries(*names) ⇒ Object
115
116
117
118
119
|
# File 'lib/ritsu/target.rb', line 115
def add_external_libraries(*names)
names.each do |name|
add_external_library(name)
end
end
|
#add_external_library(name) ⇒ Object
106
107
108
109
110
111
112
113
|
# File 'lib/ritsu/target.rb', line 106
def add_external_library(name)
external_library = Ritsu::ExternalLibrary.find_by_name(name.to_s)
if !external_library.nil?
dependency_libraries << external_library
else
raise ArgumentError.new("no external library with name '#{name}'")
end
end
|
#compute_src_path(path, options = {}) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/ritsu/target.rb', line 69
def compute_src_path(path, options={})
options = {:relative_to => :target}.merge(options)
case options[:relative_to]
when :target
self.src_dir + "/" + path
when :src
path
when :absolute
src_dir = Pathname.new(project.src_dir)
input_path = Pathname.new(path)
input_path.relative_path_from(src_dir).to_s
else
raise ArgumentError.new("option :relative_to must be one of :target, :src, and :absolute")
end
end
|
#cuda_target? ⇒ Boolean
13
14
15
|
# File 'lib/ritsu/ext/cuda/target.rb', line 13
def cuda_target?
@cuda_target
end
|
#dependency_targets_sorted_by_topological_order ⇒ Object
139
140
141
142
143
144
|
# File 'lib/ritsu/target.rb', line 139
def dependency_targets_sorted_by_topological_order
Target.compute_topological_orders
result = dependency_targets.to_a
result.sort! {|x,y| x.topological_order - y.topological_order}
result
end
|
#include_file(filename, options = {}) ⇒ Object
86
87
88
89
|
# File 'lib/ritsu/target.rb', line 86
def include_file(filename, options={})
file_content = Ritsu::Utility::Files.read(filename)
instance_eval(file_content)
end
|
#initialize_target_before_cuda ⇒ Target
Returns a new instance of Target.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/ritsu/ext/cuda/target.rb', line 5
def initialize(name, options={})
options = {:project => Ritsu::Project.instance}.merge(options)
if !is_c_name?(name)
raise ArgumentError.new(
"target name must be a valid C name")
end
@name = name
@dependency_libraries = Set.new
@project = options[:project]
@src_files = Set.new
@custom_commands = []
@topological_order = 0
@install = false
Target.instances << self
@project.targets << self
end
|
#install? ⇒ Boolean
53
54
55
|
# File 'lib/ritsu/target.rb', line 53
def install?
@install
end
|
#setup_install ⇒ Object
57
58
59
|
# File 'lib/ritsu/target.rb', line 57
def setup_install
@install = true
end
|
#src_dir ⇒ Object
61
62
63
|
# File 'lib/ritsu/target.rb', line 61
def src_dir
self.name
end
|
#update ⇒ Object
91
92
93
94
95
|
# File 'lib/ritsu/target.rb', line 91
def update
src_files.each do |src_file|
src_file.update
end
end
|