class RBT::Make
Constants
- DEFAULT_RUN_ALREADY
#¶ ↑
DEFAULT_RUN_ALREADY
¶ ↑#¶ ↑
Public Class Methods
#¶ ↑
initialize¶ ↑
By default run_already will be false, as we wish to let the user more easily decide at which point to .run() on this class.
Do note that this class can also be invoked via the following way:
Make.new { :run }
#¶ ↑
# File lib/rbt/make/make.rb, line 44 def initialize( optional_commandline_arguments = ARGV, run_already = DEFAULT_RUN_ALREADY ) register_sigint reset @run_already = run_already set_commandline_arguments( optional_commandline_arguments ) # ======================================================================= # # === Handle blocks next # ======================================================================= # if block_given? yielded = yield handle_this_block(yielded) end run if @run_already end
Public Instance Methods
#¶ ↑
append_make_options
¶ ↑
#¶ ↑
# File lib/rbt/make/make.rb, line 208 def append_make_options(i) # ======================================================================= # # Handle String input such as 'foo,bar' or 'foo;bar' next: # ======================================================================= # if i.is_a? String if i.include?(',') i = i.split(',') elsif i.include?(';') i = i.split(';') end end @internal_hash[:make_options] << i @internal_hash[:make_options].flatten! end
#¶ ↑
append_these_options
?¶ ↑
#¶ ↑
# File lib/rbt/make/make.rb, line 240 def append_these_options? @internal_hash[:make_options] end
#¶ ↑
colourize_parser?¶ ↑
#¶ ↑
# File lib/rbt/make/make.rb, line 179 def colourize_parser? @colourize_parser end
#¶ ↑
do_run_the_commands
¶ ↑
This is the main powerhorse method of this class, aka the most important one.
#¶ ↑
# File lib/rbt/make/make.rb, line 419 def do_run_the_commands( i = @array_run_these_commands ) if @run_make i.each {|entry| unless @internal_hash[:make_options].empty? # ===================================================================== # # Append the make-options to "make" next: # ===================================================================== # entry = entry.dup if entry.frozen? entry << ' '+joined_make_options? end entry = entry.dup if entry.frozen? entry.squeeze!(' ') entry << SILENT_REDIRECTION if silent_redirection? now_running(entry) run_this_command_via_io_popen(entry) } end # ======================================================================= # # Next, run "make install" or the equivalent if the user decided # that this should be run. # ======================================================================= # if run_make_install? if use_porg? entry = "porg -lp #{@program_name_and_program_version} \"#{make_command?} install\"" now_running(entry) run_this_command_via_io_popen(entry) else cmd_to_run = "#{make_command?} install" esystem cmd_to_run end end end
#¶ ↑
do_use_ninja
¶ ↑
#¶ ↑
# File lib/rbt/make/make.rb, line 409 def do_use_ninja set_use_this_command :ninja end
#¶ ↑
esystem¶ ↑
The following is an adaptation to esystem() defined on the toplevel namespace. Internally we use IO.popen, but this is only equivalent to system(), so the leading e (for puts) is omitted. Thus we must display it here, before then calling popen.
#¶ ↑
# File lib/rbt/make/make.rb, line 596 def esystem(i) # e mediumturquoise(i) # <- This colour has to be manually synced for now. now_running(i) # <- We will use this - seems to be better. Unless we have more system() tasks here. run_this_command_via_io_popen(i) end
#¶ ↑
handle_symbols
¶ ↑
This method will specifically handle Symbols passed as a block to .new().
#¶ ↑
# File lib/rbt/make/make.rb, line 365 def handle_symbols(i = nil) return unless i case i when :run, :do_run @run_already = true when :and_run_make_install_as_well, :yup @run_make_install = true end end
#¶ ↑
handle_this_hash
¶ ↑
#¶ ↑
# File lib/rbt/make/make.rb, line 293 def handle_this_hash(yielded) if yielded.is_a? Hash # ===================================================================== # # === :pad_the_output # ===================================================================== # if yielded.has_key? :pad_the_output set_pad_the_output(yielded[:pad_the_output]) end # ===================================================================== # # === append_these_options # ===================================================================== # if yielded.has_key? :append_these_options _ = yielded[:append_these_options] _ = _.join(' ').strip if _.is_a? Array append_these_options(_.to_s) # ===================================================================== # # === use_stow # ===================================================================== # elsif yielded.has_key?(:append) append_these_options(yielded[:append].to_s) end # ===================================================================== # # === run_make # ===================================================================== # if yielded.has_key? :run_make @run_make = yielded.delete(:run_make) end # ===================================================================== # # === :use_this_make_command # ===================================================================== # if yielded.has_key? :use_this_make_command use_this_command = yielded.delete(:use_this_make_command) set_use_this_make_command( use_this_command ) end # ===================================================================== # # === :use_porg # ===================================================================== # if yielded.has_key? :use_porg use_porg = yielded.delete(:use_porg) set_use_porg( use_porg ) end # ===================================================================== # # === :program_name_and_program_version # ===================================================================== # if yielded.has_key? :program_name_and_program_version set_program_name_and_program_version( yielded.delete(:program_name_and_program_version) ) end # ===================================================================== # # === :run_make_install # ===================================================================== # if yielded.has_key? :run_make_install set_run_make_install( yielded.delete(:run_make_install) ) end elsif yielded.is_a? Symbol handle_symbols(yielded) end end
#¶ ↑
joined_make_options?¶ ↑
This method will return a String variant of the content found in @make_options.
We have to apply only .rstrip here because there may be valid padding on the left hand side, such as ‘ install’, which may become ‘make install’ subsequently.
#¶ ↑
# File lib/rbt/make/make.rb, line 201 def joined_make_options? @internal_hash[:make_options].join(' ').rstrip end
#¶ ↑
reset¶ ↑
#¶ ↑
RBT::CompileBase#reset
# File lib/rbt/make/make.rb, line 67 def reset super() infer_the_namespace # ======================================================================= # # === @run_make # ======================================================================= # @run_make = true # Whether to really invoke "make" or not. # ======================================================================= # # === @run_make_install # ======================================================================= # @run_make_install = false reset_internal_dataset end
#¶ ↑
reset_internal_dataset
¶ ↑
#¶ ↑
# File lib/rbt/make/make.rb, line 84 def reset_internal_dataset # ======================================================================= # # === @internal_hash # ======================================================================= # # @internal_hash = {} # ======================================================================= # # === @array_history_of_commands_run # # The next Array will keep track as to which commands were run. # ======================================================================= # @array_history_of_commands_run = [] # ======================================================================= # # === :make_options # ======================================================================= # @internal_hash[:make_options] = [] # ======================================================================= # # === :use_this_make_command # ======================================================================= # @internal_hash[:use_this_make_command] = 'make' # ======================================================================= # # === :pad_the_output # ======================================================================= # @internal_hash[:pad_the_output] = false # ======================================================================= # # The following Array can be modified by the user. # ======================================================================= # @array_run_these_commands = [] # ======================================================================= # # We will delegate towards class RBT::ColourizeParser, in order # to colourize the output. This could, in principle, be disabled, # but I like colours, so the default is to make use of it. # ======================================================================= # @colourize_parser = RBT::ColourizeParser.new # ======================================================================= # # === :use_porg # # The next variable determines whether we will make use of porg # during the "make install" step. This is optional, so it will # be disabled by default. # ======================================================================= # @internal_hash[:use_porg] = false # ======================================================================= # # The next variable can be used specifically for when we will make use # of porg. When set then it should be a String such as "htop-2.2.1". # ======================================================================= # @program_name_and_program_version = nil end
#¶ ↑
run_this_command_via_io_popen
¶ ↑
#¶ ↑
# File lib/rbt/make/make.rb, line 471 def run_this_command_via_io_popen(entry) cparser = cparser? case entry # ======================================================================= # # The next line will handle instructions such as: # # "make -j4 -j4 install" # # ======================================================================= # when /^make/ unless is_make_available? opne tomato('Note that no binary called ')+sfancy('make')+ tomato(' is available on this computer system.') opne tomato('This means that compilation will typically not work.') opne tomato('Thus, we end here at this point - you will need '\ 'a version of ')+sfancy('make')+tomato('.') exit_program end end #if pad_the_output? # e # e entry # Output here. # e #end # ======================================================================= # # We delegate towards IO.popen next. Not that there may be errors such # as "invalid byte sequence in UTF-8 (ArgumentError)" so we have to # be careful. # ======================================================================= # io_object = IO.popen(entry, :err => [:child, :out]).each { |line| line.squeeze!(' ') if line.include? ' ' cparser.grab_this_line(line) # ===================================================================== # # Delegate towards module RBT::Errors::MapLineToASpecificError to # register any possible error. # ===================================================================== # RBT::Errors::MapLineToASpecificError.parse_this_line(line) line = cparser.line? # ===================================================================== # # Store the line in our history: # ===================================================================== # @array_history_of_commands_run << line e line # Output here. } io_object.close # Close it up again. end
#¶ ↑
set_commandline_arguments
¶ ↑
#¶ ↑
# File lib/rbt/make/make.rb, line 539 def set_commandline_arguments( i = nil ) if i.is_a? Hash # ===================================================================== # # First pass into a special method: # ===================================================================== # handle_hash_or_symbol(i) # ===================================================================== # # === :use_this_make_command # ===================================================================== # if i.has_key? :use_this_make_command set_use_this_make_command( i.delete(:use_this_make_command) ) end # ===================================================================== # # === :run_make_install # ===================================================================== # if i.has_key? :run_make_install if (i.delete(:run_make_install) == true) # Query for truthness. try_to_append_this_option_to_make( ' install' ) end end end @internal_hash[:commandline_arguments] = [i].flatten.compact end
#¶ ↑
set_use_this_make_command
¶ ↑
We need this setter-method so that we can toggle between, e. g. “make” or “ninja” or any other similar build system.
#¶ ↑
# File lib/rbt/make/make.rb, line 384 def set_use_this_make_command( i = :default ) case i when :make_install # ===================================================================== # # This one is a bit different - we will only run "make install" # here, not both "make" and "make install" combined. # ===================================================================== # i = 'make' # Handle "make install" instruction here. append_this_option_to_make('install') # === :ninja when :ninja i = 'ninja' when :rake i = 'rake' when :default, nil, :make i = 'make' # <- We need to use a sane default value, aka "make". end @internal_hash[:use_this_make_command] = i end
#¶ ↑
try_to_append_this
¶ ↑
#¶ ↑
# File lib/rbt/make/make.rb, line 229 def try_to_append_this( i = ' install' ) unless use_which_command?.end_with? i append_these_make_options(i) end end
#¶ ↑
use_which_make_command?¶ ↑
#¶ ↑
# File lib/rbt/make/make.rb, line 186 def use_which_make_command? @internal_hash[:use_this_make_command] end