class RBT::Libtool

Constants

FILE_SEARCH_IN_THESE_DIRECTORIES
#

FILE_SEARCH_IN_THESE_DIRECTORIES

#
REGEX_TO_DISCOVER_PROGRAMS_ENTRIES_IN_DEPENDENCY_LIBS
#

REGEX_TO_DISCOVER_PROGRAMS_ENTRIES_IN_DEPENDENCY_LIBS

Rubular example at:

http://rubular.com/r/E8jSpNAMcX
#
SYSTEM_LIBRARIES
#

SYSTEM_LIBRARIES

In modern GoboLinux variants, this is pointing towards /System/Index/lib.

#
ULIB64_LIBRARIES
#

ULIB64_LIBRARIES

#
ULIB_LIBRARIES
#

ULIB_LIBRARIES

#

Public Class Methods

[](i = '') click to toggle source
#

RBT::Libtool[]

#
# File lib/rbt/libtool/misc.rb, line 152
def self.[](i = '')
  new(i)
end
append_this_directory_to_the_list_of_directories_to_search_for( i = ARGV ) click to toggle source
#

RBT::Libtool.append_this_directory_to_the_list_of_directories_to_search_for

This should be used on the commandline.

It will permanently set to use a new directory to search for.

#
# File lib/rbt/libtool/class_methods/append_this_directory_to_the_list_of_directories_to_search_for.rb, line 30
def self.append_this_directory_to_the_list_of_directories_to_search_for(
    i = ARGV
  )
  i = i.first if i.is_a? Array
  case i
  when 'PROGRAMS'
    i = program_dir?
  end unless File.exist?(i)
  i = i.dup if i.frozen?
  i << '/' unless i.end_with? '/'
  target_file = FILE_SEARCH_IN_THESE_DIRECTORIES
  array_search_in_these_directories = YAML.load_file(target_file)
  # ======================================================================= #
  # Only add new entries.
  # ======================================================================= #
  if array_search_in_these_directories.include? i
    opn; e "Can not add #{Colours.sdir(i)} as it is already a part "\
           "of the search-directories."
  # ======================================================================= #
  # Add the new entry into our main yaml file.
  # ======================================================================= #
  else
    array_search_in_these_directories << i
    opn; e 'We will append the directory `'+Colours.sdir(i)+'` to the '\
           'list of directories'
    opn; e 'that we will search for incorrect .la files.'
    File.open(target_file, 'w+') { |file|
      file.write(YAML.dump(array_search_in_these_directories))
    }
    opn; e "Done! The new file can be found at `#{Colours.sfile(target_file)}`."
    if RBT.is_on_roebe?
      this_file = "#{RUBY_SRC_DIR}roebe/lib/roebe/yaml/"\
                  "#{File.basename(target_file)}"
      File.open(this_file, 'w+') { |file|
        file.write(YAML.dump(array_search_in_these_directories))
      }
      opn; e 'Done! The new file can be found at '+Colours.sfile(this_file)
    end
  end
end
autocorrect_this_file(i) click to toggle source
#

RBT::Libtool.autocorrect_this_file

The argument for this method should be an erroneous libtool entry such as /usr/lib/glib.la.

#
# File lib/rbt/libtool/class_methods/autocorrect_this_file.rb, line 19
def self.autocorrect_this_file(i)
  RBT::Libtool.new(:do_not_run_yet).remove_this_entry(i)
end
autofix_every_la_file() click to toggle source
#

Libtool.autofix_every_la_file

Use this method to fix every .la file on your system.

Invocation example:

rubylibtool --autofix
#
# File lib/rbt/libtool/misc.rb, line 91
def self.autofix_every_la_file
  ensure_that_we_have_found_la_files
  if Libtool.faulty_la_files?.empty?
    # ===================================================================== #
    # In this case, fill up the Array first.
    # ===================================================================== #
    Libtool.fill_up_array_that_holds_faulty_la_files
  end
  Libtool.faulty_la_files?.each {|file|
    opne "Now working on the #{orange('.la')} file `#{sfile(file)}`."
    dataset = File.readlines(file)
    new_file_content = ''
    dataset.each {|line|
      if line.include?('dependency_libs') and 
         line.include? PROGRAMS_DIRECTORY.chop # .chop because we have a trailing '/'.
        splitted = line.split(' ')
        splitted.map! {|entry|
          if entry.include? PROGRAMS_DIRECTORY.chop
            entry = rds(entry)
            # ============================================================= #
            #   /usr//Programs/Libx11/1.6.3/lib/libX11.la
            # or
            #   /usr//usr//usr//Programs/Atspi2core/2.18.2/lib/libatspi.la
            # really strange
            # ============================================================= #
            regex = REGEX_TO_DISCOVER_PROGRAMS_ENTRIES_IN_DEPENDENCY_LIBS
            entry =~ regex
            match = $1.to_s.dup
            entry.sub!(/#{match}/, '/usr/')
          end
          entry
        }
        line = splitted.join(' ')+N
      end
      new_file_content << line
    }
    what = new_file_content
    into = file
    opne "Now storing into `#{sfile(into)}`."
    write_what_into(what, into)
  }
end
e(i = '') click to toggle source
#

RBT::Libtool.e

#
# File lib/rbt/libtool/class_methods/append_this_directory_to_the_list_of_directories_to_search_for.rb, line 19
def self.e(i = '')
  puts i
end
new( i = ARGV, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/libtool/initialize.rb, line 12
def initialize(
    i           = ARGV,
    run_already = true
  )
  reset
  case i
  # ======================================================================= #
  # === :do_not_run_yet
  # ======================================================================= #
  when :do_not_run_yet
    # In this case, do not run anything.
  else # This else clause here is the default clause.
    set_commandline_arguments(i)
    run if run_already
  end
end
obtain_all_la_files_from_system_libraries() click to toggle source
#

Libtool.obtain_all_la_files_from_system_libraries

Grab all .la files from /System/Index/lib/.

#
# File lib/rbt/libtool/class_methods/class_methods.rb, line 36
def self.obtain_all_la_files_from_system_libraries
  Dir["#{SYSTEM_LIBRARIES}*.la"].sort
end
obtain_all_la_files_from_usr_lib() click to toggle source
#

Libtool.obtain_all_la_files_from_usr_lib

Grab all .la files from /usr/lib/.

#
# File lib/rbt/libtool/class_methods/class_methods.rb, line 27
def self.obtain_all_la_files_from_usr_lib
  Dir["#{ULIB_LIBRARIES}*.la"].sort
end
obtain_all_la_files_from_usr_lib64() click to toggle source
#

Libtool.obtain_all_la_files_from_usr_lib64

Grab all .la files from the /usr/lib64/ directory.

This is no longer in use a lot.

#
# File lib/rbt/libtool/class_methods/class_methods.rb, line 18
def self.obtain_all_la_files_from_usr_lib64
  Dir["#{ULIB64_LIBRARIES}*.la"].sort
end
return_all_la_files_from_this_directory(this_directory) click to toggle source
#

RBT::Libtool.return_all_la_files_from_this_directory

#
# File lib/rbt/libtool/class_methods/return_all_la_files_from_this_directory.rb, line 14
def self.return_all_la_files_from_this_directory(this_directory)
  Dir["#{this_directory}*.la"].sort
end
return_every_la_file() click to toggle source
#

RBT::Libtool.return_every_la_file

If you want to return every .la file on a given computer system, then, use this method here.

This will obtain from /usr/lib/, /usr/lib64 and /System/Libraries/ by default. Otherwise, we will make use of an Array.

#
# File lib/rbt/libtool/class_methods/return_every_la_file.rb, line 22
def self.return_every_la_file
  ::RBT::Libtool.new.every_la_file
end
set_use_this_directory(i) click to toggle source
#

RBT::Libtool.set_use_this_directory

#
# File lib/rbt/libtool/class_methods/use_this_directory.rb, line 32
def self.set_use_this_directory(i)
  @use_this_directory = i.to_s
end
use_this_directory(i) click to toggle source
#

RBT::Libtool.use_this_directory

The PWD macro means Dir.pwd actually.

#
# File lib/rbt/libtool/class_methods/use_this_directory.rb, line 41
def self.use_this_directory(i)
  i = i.to_s
  case i
  when 'PWD'
    i = return_pwd
  end unless File.exist? i
  i << '/' unless i.end_with? '/'
  @use_this_directory = i
end
use_this_directory?() click to toggle source
#

RBT::Libtool.use_this_directory?

#
# File lib/rbt/libtool/class_methods/use_this_directory.rb, line 25
def self.use_this_directory?
  @use_this_directory
end

Public Instance Methods

append_this_directory_to_the_list_of_directories_to_search_for(i) { || ... } click to toggle source
#

append_this_directory_to_the_list_of_directories_to_search_for

#
# File lib/rbt/libtool/remove_this_entry.rb, line 20
def append_this_directory_to_the_list_of_directories_to_search_for(i)
  case i
  when 'PROGRAMS'
    i = program_dir?
  end unless File.exist?(i)
  i = i.dup if i.frozen?
  i << '/' unless i.end_with? '/'
  unless @search_in_these_directories.include? i
    if block_given?
      yielded = yield
      case yielded
      # =================================================================== #
      # === :be_verbose
      # =================================================================== #
      when :be_verbose
        opne "Adding the directory `#{sdir(i)}"\
             "` to the search path of this class."
      end
    end
    @search_in_these_directories << i
  end
end
clear_array_log_these_files() click to toggle source
#

clear_array_log_these_files

#
# File lib/rbt/libtool/remove_this_entry.rb, line 75
def clear_array_log_these_files
  @array_log_these_files = []
end
ensure_that_we_have_found_la_files() click to toggle source
#

ensure_that_we_have_found_la_files

#
# File lib/rbt/libtool/misc.rb, line 42
def ensure_that_we_have_found_la_files
  if @array_all_libtool_files.empty?
    obtain_all_the_la_files
  end
end
every_la_file()
input?() click to toggle source
#

input?

#
# File lib/rbt/libtool/misc.rb, line 61
def input?
  @input
end
log_these_files() click to toggle source
#

log_these_files

#
# File lib/rbt/libtool/misc.rb, line 14
def log_these_files
  @array_log_these_files
end
menu(i) click to toggle source
#

menu (menu tag)

The input to this should ideally be the whole commandline, as String.

Reason being that we can apply a regex on the whole line.

#
n_la_files?() click to toggle source
#

n_la_files?

#
# File lib/rbt/libtool/misc.rb, line 137
def n_la_files?
  @array_all_libtool_files.size
end
notify_the_user_which_directories_will_be_searched() click to toggle source
#

notify_the_user_which_directories_will_be_searched

#
# File lib/rbt/libtool/remove_this_entry.rb, line 46
def notify_the_user_which_directories_will_be_searched
  opne 'The following directories will be searched:'
  e "  #{sfancy(@search_in_these_directories.join(', '))}"
end
obtain_all_libtool_files()
obtain_all_the_la_files() click to toggle source
#

obtain_all_the_la_files

#
# File lib/rbt/libtool/remove_this_entry.rb, line 62
def obtain_all_the_la_files
  @search_in_these_directories.each {|this_dir|
    these_la_files = Dir["#{this_dir}**/**.la"]
    @array_all_libtool_files << these_la_files
    @array_all_libtool_files.flatten!
  }
  return @array_all_libtool_files
end
remove_the_last_faulty_libtool_entry_stored_in_a_file() click to toggle source
#

remove_the_last_faulty_libtool_entry_stored_in_a_file

Invocation example:

rubylibtool --remove-from-file
#
# File lib/rbt/libtool/remove_this_entry.rb, line 161
def remove_the_last_faulty_libtool_entry_stored_in_a_file
  _ = "#{rbt_log_directory?}libtool/last_faulty_libtool_file.md"
  # ======================================================================= #
  # (1) Read the entry from the .md file, if it exists
  # ======================================================================= #
  if File.exist? _
    this_is_a_faulty_libtool_entry = File.read(_).strip
    # ===================================================================== #
    # (2) pass this into remove_this_entry()
    # ===================================================================== #
    remove_this_entry(this_is_a_faulty_libtool_entry)
  else
    opnn; no_file_exists_at(_)
  end
end
remove_this_entry(i) click to toggle source
#

remove_this_entry

Use this method to remove a specific entry within all .la files.

#
# File lib/rbt/libtool/remove_this_entry.rb, line 84
def remove_this_entry(i)
  clear_array_log_these_files # Reset the Array first.
  if i.end_with?(':') and !File.exist?(i)
    i.chop!
  end
  opne 'The following entry will be removed from every '\
       'encountered .la file on this computer:'
  e
  e "  #{seagreen(i)}"
  e
  if ::RBT::Libtool.use_this_directory?
    la_files = Dir["#{RBT::Libtool.use_this_directory?}**/**.la"]
  else
    la_files = obtain_all_libtool_files
  end
  notify_the_user_which_directories_will_be_searched
  # ======================================================================= #
  # Next, reject those who do not contain the given search term "i".
  # We will also log these files.
  # ======================================================================= #
  la_files.select! {|file|
    # ===================================================================== #
    # Must first check whether it is a symlink that exists.
    # ===================================================================== #
    if File.symlink?(file) and !File.exist?(File.readlink(file))
      symlink_target = File.readlink(file)
      opne 'No file exists at '+sfile(file)+' (a symlink pointing '\
           'at '+sfile(symlink_target)+')'
    end
    if File.exist? file
      dataset = File.read(file)
      dataset.include?(i)
    else
      opne "No file could be found at `#{sfile(file)}`."
    end
  }
  if la_files.empty?
    opne "We did not find any .la file that includes "\
         "the entry `#{simp(i)}`."
  else
    la_files.each {|file|
      opne "Working on `#{sfile(file)}` next."
      dataset = File.readlines(file)
      _ = ''.dup
      dataset.each {|line|
        if line.include?('dependency_libs') and line.include?(i)
          line.gsub!(/#{Regexp.quote(i)}/,'')
          @array_log_these_files << i
        end
        _ << line
      }
      # =================================================================== #
      # Write the new content into that .la file.
      # =================================================================== #
      write_what_into(_, file)
    }
    unless @array_log_these_files.empty?
      what = N+@array_log_these_files.join(N)+('-' * 40)+N
      # ===================================================================== #
      # Store the modified files in a file:
      # ===================================================================== #
      into = "#{rbt_log_directory?}libtool_modified_these_files.md"
      opne 'Keeping a backup of which libtool files were '\
           'modified, at `'+sfile(into)+'`.'
      append_what_into(what, into)
    end
  end
end
report_how_many_la_files_were_found() click to toggle source
#

report_how_many_la_files_were_found

#
# File lib/rbt/libtool/misc.rb, line 51
def report_how_many_la_files_were_found
  opne "There are a total of #{sfancy(n_la_files?.to_s)}"\
       " .la files on this system."
  opne 'The directories '+sdir(target_directories?.join(', '))+
       ' were searched.'
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/libtool/reset.rb, line 16
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @array_all_libtool_files
  # ======================================================================= #
  @array_all_libtool_files = []
  clear_array_log_these_files
  _ = FILE_SEARCH_IN_THESE_DIRECTORIES
  if File.exist? _
    set_search_in_these_directories(YAML.load_file(_))
  else
    opne "No file called #{sfile(_)} exists. Thus, "\
         "we can not load the dataset."
  end
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/libtool/run.rb, line 12
def run
end
sanitize_commandline_arguments() click to toggle source
#

sanitize_commandline_arguments

#
# File lib/rbt/libtool/misc.rb, line 30
def sanitize_commandline_arguments
  @commandline_arguments.map! {|entry|
    if entry and entry.end_with?(':')
      entry.chop! # Trailing ':' seem pointless.
    end
    entry
  }
end
search_in_these_directories?() click to toggle source
#

search_in_these_directories?

#
# File lib/rbt/libtool/remove_this_entry.rb, line 54
def search_in_these_directories?
  @search_in_these_directories
end
search_in_which_directories?()
set_commandline_arguments(i) click to toggle source
#

set_commandline_arguments

#
# File lib/rbt/libtool/misc.rb, line 21
def set_commandline_arguments(i)
  @commandline_arguments = [i].flatten.compact
  sanitize_commandline_arguments
  menu(@commandline_arguments)
end
set_search_in_these_directories( i = FILE_SEARCH_IN_THESE_DIRECTORIES ) click to toggle source
#

set_search_in_these_directories

Note that the variable that is set here, called @search_in_these_directories, will keep track of the directories that we will search for, by default.

A directory must end with a trailing ‘/’ character, which is ensured here by this method too, if an Array is used as input.

On my home system, the .yml file that is searched is at:

bl $RSRC/libtool/lib/libtool/yaml/search_in_these_directories.yml
#
# File lib/rbt/libtool/search_in_these_directories.rb, line 23
def set_search_in_these_directories(
    i = FILE_SEARCH_IN_THESE_DIRECTORIES
  )
  if i.end_with?('.yml')
    i = YAML.load_file(i)
  end if i.is_a? String
  # ======================================================================= #
  # Modify the Array by ensuring a trailing '/' is used.
  # ======================================================================= #
  if i.is_a? Array
    i.map! {|line|
      # =================================================================== #
      # Check for ALL_CAPS constants next - these will be handled as
      # shortcut for ENV[].
      # =================================================================== #
      if (line == line.upcase) and ENV.has_key?(line.upcase)
        line = ENV[line.upcase].dup
      end 
      line << '/' unless line.end_with? '/'
      line
    }
  end
  @search_in_these_directories = i
end
show_every_la_file() click to toggle source
#

show_every_la_file

Invocation example:

roebelibtool --show-every-la-file
#
# File lib/rbt/libtool/misc.rb, line 71
def show_every_la_file
  ensure_that_we_have_found_la_files
  opne 'Every .la file on this computer will be shown next'
  e
  @array_all_libtool_files.each_with_index {|this_libtool_file, index| index += 1
    index = (index.to_s+')').ljust(6)
    e "  #{sfancy(index)}#{sfile(this_libtool_file)}"
  }; e
end
show_help() click to toggle source
#

show_help (help tag)

Give some information to the user how RBT::Libtool can be used.

Invoke this like so:

roebelibtool --help
#
# File lib/rbt/libtool/help.rb, line 21
def show_help
  e
  opnn; ecomment '  --remove-this-entry=/usr/lib/libpng16.la # remove this entry from all .la files'
  opnn; ecomment '  --stats                                  # show some statistics from your system'
  opnn; ecomment '  --show-every-la-file                     # show every .la file on your system'
  opnn; ecomment '  --all                                    # an alias to the above ^^^'
  opnn; ecomment '  --search-in-which-directories?           # report in which '\
                 'directories we will look for .la files'
  opnn; ecomment '  --stats                                  # show some statistics about your .la files'
  opnn; ecomment '  --report                                 # report how many .la files we have found'
  opnn; ecomment '  --autofix                                # autofix every faulty .la file'
  opnn; ecomment '  --purge                                  # purge a specific entry from a '\
                 '.la file; also note that we will log this action'
  opnn; ecomment '  --remove-this-entry                      # Remove a specific entry '\
                 'from all .la files'
  opnn; ecomment '  --from-this-directory=                   # use '\
                 'another directory to search in'
  opnn; ecomment '  --remove-from-stored-file                # remove '\
                 'the .la file last registered'
  ecomment       '                                                         '\
                 '# as faulty, from a local file'
  e
  opnn; ecomment '  rubylibtool --remove-this-entry=/usr/lib/libpng16.la # Remove this entry.'
  e
  e
  opne 'Note that you can also add new entries to the '\
       'array of files that'
  opne 'will be searched from the commandline, by doing this:'
  e
  opnn; ecomment '  --search-in-this-directory=   # add this directory to '\
                 'the list of directories that will be searched'
  opnn; ecomment '  --add=                        # ^^^ same as above, but shorter'
  e
end
show_statistics() click to toggle source
#

show_statistics

#
# File lib/rbt/libtool/misc.rb, line 144
def show_statistics
  ensure_that_we_have_found_la_files
  report_how_many_la_files_were_found
end
target_directories?()