Class: Cxx::RubyDsl
- Inherits:
-
Object
- Object
- Cxx::RubyDsl
- Defined in:
- lib/cxx.rb
Instance Attribute Summary collapse
-
#all_tasks ⇒ Object
Returns the value of attribute all_tasks.
-
#base_dir ⇒ Object
Returns the value of attribute base_dir.
-
#build_dir ⇒ Object
Returns the value of attribute build_dir.
Instance Method Summary collapse
- #check_for_project_configs ⇒ Object
- #create_console_colorization ⇒ Object
- #create_dont_bail_on_first_task ⇒ Object
- #create_filter_task(basename) ⇒ Object
- #create_filter_task_with_namespace(basename) ⇒ Object
- #create_generic_tasks ⇒ Object
- #create_multitask ⇒ Object
- #create_tag_tasks ⇒ Object
- #define_project_info_task ⇒ Object
- #describe_clean_task ⇒ Object
- #eval_file(b, project_file) ⇒ Object
-
#initialize(projects, build_dir, toolchain_name, base_dir = '.', &option_block) ⇒ RubyDsl
constructor
A new instance of RubyDsl.
- #initialize_logging(build_dir) ⇒ Object
- #instantiate_tasks(toolchain, build_dir) ⇒ Object
- #load_nontoolchain_plugins ⇒ Object
- #prepare_block(block, toolchain, build_dir) ⇒ Object
- #register_projects ⇒ Object
Constructor Details
#initialize(projects, build_dir, toolchain_name, base_dir = '.', &option_block) ⇒ RubyDsl
Returns a new instance of RubyDsl.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cxx.rb', line 18 def initialize(projects, build_dir, toolchain_name, base_dir='.', &option_block) @build_dir = build_dir toolchain = Cxxproject::Toolchain::Provider[toolchain_name] option_block.call(toolchain) if option_block raise "no provider with name \"#{toolchain_name}\" found" unless toolchain @base_dir = base_dir cd(@base_dir, :verbose => false) do @projects = projects.to_a end Rake::application.deriveIncludes = true initialize_logging(build_dir) @all_tasks = instantiate_tasks(toolchain, build_dir) create_generic_tasks create_tag_tasks create_console_colorization create_multitask create_dont_bail_on_first_task describe_clean_task load_nontoolchain_plugins end |
Instance Attribute Details
#all_tasks ⇒ Object
Returns the value of attribute all_tasks.
16 17 18 |
# File 'lib/cxx.rb', line 16 def all_tasks @all_tasks end |
#base_dir ⇒ Object
Returns the value of attribute base_dir.
16 17 18 |
# File 'lib/cxx.rb', line 16 def base_dir @base_dir end |
#build_dir ⇒ Object
Returns the value of attribute build_dir.
16 17 18 |
# File 'lib/cxx.rb', line 16 def build_dir @build_dir end |
Instance Method Details
#check_for_project_configs ⇒ Object
168 169 170 171 172 173 174 |
# File 'lib/cxx.rb', line 168 def check_for_project_configs cd(@base_dir, :verbose => false) do @projects.each do |p| abort "project config #{p} cannot be found in #{Dir.pwd}!" unless File.exists?(p) end end end |
#create_console_colorization ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cxx.rb', line 88 def create_console_colorization # default is on Cxxproject::ColorizingFormatter.enabled = true desc 'Toggle colorization of console output (use true|t|yes|y|1|on for true ... everything else is false)' task :toggle_colorize, :on_off do |t, args| arg = args[:on_off] || 'false' on_off = arg.match(/(true|t|yes|y|1|on)$/) != nil Cxxproject::ColorizingFormatter.enabled = on_off end end |
#create_dont_bail_on_first_task ⇒ Object
71 72 73 74 75 76 |
# File 'lib/cxx.rb', line 71 def create_dont_bail_on_first_task desc 'dont bail on first error' task :dont_bail_on_first_error do Rake::Task.bail_on_first_error = false end end |
#create_filter_task(basename) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cxx.rb', line 129 def create_filter_task(basename) task :filter, :filter do |t, args| filter = ".*" if args[:filter] filter = "#{args[:filter]}" end filter = Regexp.new("#{basename}#{filter}") Rake::Task.tasks.each do |to_check| name = to_check.name if ("#{basename}:filter" != name) match = filter.match(name) if match to_check.invoke end end end end end |
#create_filter_task_with_namespace(basename) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/cxx.rb', line 117 def create_filter_task_with_namespace(basename) if basename desc "invoke #{basename} with filter" namespace basename do create_filter_task("#{basename}:") end else desc 'invoke with filter' create_filter_task('') end end |
#create_generic_tasks ⇒ Object
99 100 101 102 103 |
# File 'lib/cxx.rb', line 99 def create_generic_tasks tasks = [:lib, :exe, :run] tasks << nil tasks.each { |i| create_filter_task_with_namespace(i) } end |
#create_multitask ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/cxx.rb', line 78 def create_multitask desc 'set parallelization of multitask' task :multitask, :threads do |t, args| arg = args.threads if arg Rake::application.max_parallel_tasks = arg.to_i end end end |
#create_tag_tasks ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/cxx.rb', line 105 def create_tag_tasks desc 'invoke tagged building blocks' task :tag, :tag do |t, args| if args[:tag] current_tag = args[:tag] Rake::Task::tasks.select {|t|t..include?(current_tag)}.each do |task| task.invoke end end end end |
#define_project_info_task ⇒ Object
214 215 216 217 218 219 220 221 |
# File 'lib/cxx.rb', line 214 def define_project_info_task desc "shows your defined projects" task :project_info do Cxxproject::ALL_BUILDING_BLOCKS.each_value do |bb| pp bb end end end |
#describe_clean_task ⇒ Object
67 68 69 |
# File 'lib/cxx.rb', line 67 def describe_clean_task Rake::Task[:clean].add_description('clean') end |
#eval_file(b, project_file) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/cxx.rb', line 196 def eval_file(b, project_file) loadContext = EvalContext.new project_text = File.read(File.basename(project_file)) begin loadContext.eval_project(project_text, project_file, Dir.pwd) rescue Exception => e puts "problems with #{File.join(b, project_file)} in dir: #{Dir.pwd}" puts project_text raise e end loadContext.all_blocks.each do |block| block. set_project_dir(Dir.pwd). set_config_files([Dir.pwd + "/" + project_file]) end end |
#initialize_logging(build_dir) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cxx.rb', line 53 def initialize_logging(build_dir) @log = Logger.new(STDOUT) @log.formatter = proc { |severity, datetime, progname, msg| "#{severity}: #{msg}\n" } # Logger loglevels: fatal, error, warn, info, debug # Rake --verbose -> info # Rake --trace -> debug @log.level = Logger::ERROR @log.level = Logger::INFO if RakeFileUtils.verbose == true @log.level = Logger::DEBUG if Rake::application..trace @log.debug "initializing for build_dir: \"#{build_dir}\", base_dir: \"#{@base_dir}\"" end |
#instantiate_tasks(toolchain, build_dir) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/cxx.rb', line 148 def instantiate_tasks(toolchain, build_dir) check_for_project_configs if @log.debug? @log.debug "project_configs:" @projects.each { |c| @log.debug " * #{c}" } end register_projects() Cxxproject::ALL_BUILDING_BLOCKS.values.each do |block| prepare_block(block, toolchain, build_dir) end Cxxproject::ALL_BUILDING_BLOCKS.values.inject([]) do |memo,block| @log.debug "creating tasks for block: #{block.name}/taskname: #{block.get_task_name} (#{block})" if block.name != block.get_task_name task block.name => block.get_task_name # create task with simple name of buildinblock end memo << block.convert_to_rake() end end |
#load_nontoolchain_plugins ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/cxx.rb', line 43 def load_nontoolchain_plugins registry = Frazzle::Registry.new('cxxproject', '_', '-') plugins = registry.get_all_plugins.select do |name| name.index('toolchain') == nil end plugins.each do |plugin| registry.load_plugin(plugin, Cxxproject::PluginContext.create_three_args_context(self, Cxxproject::ALL_BUILDING_BLOCKS, @log)) end end |
#prepare_block(block, toolchain, build_dir) ⇒ Object
176 177 178 179 180 |
# File 'lib/cxx.rb', line 176 def prepare_block(block, toolchain, build_dir) block.set_tcs(toolchain) unless block.has_tcs? block.set_output_dir(Dir.pwd + "/" + build_dir) block.complete_init() end |
#register_projects ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/cxx.rb', line 182 def register_projects() cd(@base_dir,:verbose => false) do |b| @projects.each_with_index do |project_file, i| @log.debug "register project #{project_file}" dirname = File.dirname(project_file) @log.debug "dirname for project was: #{dirname}" cd(dirname,:verbose => false) do | base_dir | @log.debug "register project #{project_file} from within directory: #{Dir.pwd}" eval_file(b, File.basename(project_file)) end end end end |