Class: RQR::ToplevelInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/rqr.rb

Direct Known Subclasses

ToplevelInstallerMulti

Constant Summary collapse

Version =
'3.4.1'
'Copyright (c) 2000-2005 Minero Aoki'
TASKS =
[
  [ 'all',      'do config, setup, then install' ],
  [ 'config',   'saves your configurations' ],
  [ 'show',     'shows current configuration' ],
  [ 'setup',    'compiles ruby extentions and others' ],
  [ 'install',  'installs files' ],
  [ 'test',     'run all tests in test/' ],
  [ 'clean',    "does `make clean' for each extention" ],
  [ 'distclean',"does `make distclean' for each extention" ]
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ardir_root, config) ⇒ ToplevelInstaller

Returns a new instance of ToplevelInstaller.



793
794
795
796
797
798
# File 'lib/rqr.rb', line 793

def initialize(ardir_root, config)
  @ardir = File.expand_path(ardir_root)
  @config = config
  # cache
  @valid_task_re = nil
end

Class Method Details

.invokeObject



769
770
771
772
773
774
775
776
# File 'lib/rqr.rb', line 769

def ToplevelInstaller.invoke
  config = ConfigTable.new(load_rbconfig())
  config.load_standard_entries
  config.load_multipackage_entries if multipackage?
  config.fixup
  klass = (multipackage?() ? ToplevelInstallerMulti : ToplevelInstaller)
  klass.new(File.dirname($0), config).invoke
end

.load_rbconfigObject



782
783
784
785
786
787
788
789
790
791
# File 'lib/rqr.rb', line 782

def ToplevelInstaller.load_rbconfig
  if arg = ARGV.detect {|arg| /\A--rbconfig=/ =~ arg }
    ARGV.delete(arg)
    load File.expand_path(arg.split(/=/, 2)[1])
    $".push 'rbconfig.rb'
  else
    require 'rbconfig'
  end
  ::Config::CONFIG
end

.multipackage?Boolean

Returns:

  • (Boolean)


778
779
780
# File 'lib/rqr.rb', line 778

def ToplevelInstaller.multipackage?
  File.dir?(File.dirname($0) + '/packages')
end

Instance Method Details

#config(key) ⇒ Object



800
801
802
# File 'lib/rqr.rb', line 800

def config(key)
  @config[key]
end

#exec_cleanObject



1015
1016
1017
# File 'lib/rqr.rb', line 1015

def exec_clean
  @installer.exec_clean
end

#exec_configObject

Task Handlers



992
993
994
995
# File 'lib/rqr.rb', line 992

def exec_config
  @installer.exec_config
  @config.save   # must be final
end

#exec_distcleanObject



1019
1020
1021
# File 'lib/rqr.rb', line 1019

def exec_distclean
  @installer.exec_distclean
end

#exec_installObject



1001
1002
1003
# File 'lib/rqr.rb', line 1001

def exec_install
  @installer.exec_install
end

#exec_setupObject



997
998
999
# File 'lib/rqr.rb', line 997

def exec_setup
  @installer.exec_setup
end

#exec_showObject



1009
1010
1011
1012
1013
# File 'lib/rqr.rb', line 1009

def exec_show
  @config.each do |i|
    printf "%-20s %s\n", i.name, i.value if i.value?
  end
end

#exec_testObject



1005
1006
1007
# File 'lib/rqr.rb', line 1005

def exec_test
  @installer.exec_test
end

#init_installersObject



836
837
838
# File 'lib/rqr.rb', line 836

def init_installers
  @installer = Installer.new(@config, @ardir, File.expand_path('.'))
end

#inspectObject



804
805
806
# File 'lib/rqr.rb', line 804

def inspect
  "#<#{self.class} #{__id__()}>"
end

#invokeObject



808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
# File 'lib/rqr.rb', line 808

def invoke
  run_metaconfigs
  case task = parsearg_global()
  when nil, 'all'
    parsearg_config
    init_installers
    exec_config
    exec_setup
    exec_install
  else
    case task
    when 'config', 'test'
      ;
    when 'clean', 'distclean'
      @config.load_savefile if File.exist?(@config.savefile)
    else
      @config.load_savefile
    end
    __send__ "parsearg_#{task}"
    init_installers
    __send__ "exec_#{task}"
  end
end

#objdir_rootObject



848
849
850
# File 'lib/rqr.rb', line 848

def objdir_root
  '.'
end

#parsearg_configObject



907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
# File 'lib/rqr.rb', line 907

def parsearg_config
  evalopt = []
  set = []
  @config.config_opt = []
  while i = ARGV.shift
    if /\A--?\z/ =~ i
      @config.config_opt = ARGV.dup
      break
    end
    name, value = *@config.parse_opt(i)
    if @config.value_config?(name)
      @config[name] = value
    else
      evalopt.push [name, value]
    end
    set.push name
  end
  evalopt.each do |name, value|
    @config.lookup(name).evaluate value, @config
  end
  # Check if configuration is valid
  set.each do |n|
    @config[n] if @config.value_config?(n)
  end
end

#parsearg_globalObject

Option Parsing



860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
# File 'lib/rqr.rb', line 860

def parsearg_global
  while arg = ARGV.shift
    case arg
    when /\A\w+\z/
      setup_rb_error "invalid task: #{arg}" unless valid_task?(arg)
      return arg
    when '-q', '--quiet'
      @config.verbose = false
    when '--verbose'
      @config.verbose = true
    when '--help'
      print_usage $stdout
      exit 0
    when '--version'
      puts "#{File.basename($0)} version #{Version}"
      exit 0
    when '--copyright'
      puts Copyright
      exit 0
    else
      setup_rb_error "unknown global option '#{arg}'"
    end
  end
  nil
end

#parsearg_installObject



933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
# File 'lib/rqr.rb', line 933

def parsearg_install
  @config.no_harm = false
  @config.install_prefix = ''
  while a = ARGV.shift
    case a
    when '--no-harm'
      @config.no_harm = true
    when /\A--prefix=/
      path = a.split(/=/, 2)[1]
      path = File.expand_path(path) unless path[0,1] == '/'
      @config.install_prefix = path
    else
      setup_rb_error "install: unknown option #{a}"
    end
  end
end

#parsearg_no_optionsObject Also known as: parsearg_show, parsearg_setup, parsearg_test, parsearg_clean, parsearg_distclean



894
895
896
897
898
899
# File 'lib/rqr.rb', line 894

def parsearg_no_options
  unless ARGV.empty?
    task = caller(0).first.slice(%r<`parsearg_(\w+)'>, 1)
    setup_rb_error "#{task}: unknown options: #{ARGV.join(' ')}"
  end
end


950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
# File 'lib/rqr.rb', line 950

def print_usage(out)
  out.puts 'Typical Installation Procedure:'
  out.puts "  $ ruby #{File.basename $0} config"
  out.puts "  $ ruby #{File.basename $0} setup"
  out.puts "  # ruby #{File.basename $0} install (may require root privilege)"
  out.puts
  out.puts 'Detailed Usage:'
  out.puts "  ruby #{File.basename $0} <global option>"
  out.puts "  ruby #{File.basename $0} [<global options>] <task> [<task options>]"

  fmt = "  %-24s %s\n"
  out.puts
  out.puts 'Global options:'
  out.printf fmt, '-q,--quiet',   'suppress message outputs'
  out.printf fmt, '   --verbose', 'output messages verbosely'
  out.printf fmt, '   --help',    'print this message'
  out.printf fmt, '   --version', 'print version and quit'
  out.printf fmt, '   --copyright',  'print copyright and quit'
  out.puts
  out.puts 'Tasks:'
  TASKS.each do |name, desc|
    out.printf fmt, name, desc
  end

  fmt = "  %-24s %s [%s]\n"
  out.puts
  out.puts 'Options for CONFIG or ALL:'
  @config.each do |item|
    out.printf fmt, item.help_opt, item.description, item.help_default
  end
  out.printf fmt, '--rbconfig=path', 'rbconfig.rb to load',"running ruby's"
  out.puts
  out.puts 'Options for INSTALL:'
  out.printf fmt, '--no-harm', 'only display what to do if given', 'off'
  out.printf fmt, '--prefix=path',  'install path prefix', ''
  out.puts
end

#relpathObject



852
853
854
# File 'lib/rqr.rb', line 852

def relpath
  '.'
end

#run_metaconfigsObject



832
833
834
# File 'lib/rqr.rb', line 832

def run_metaconfigs
  @config.load_script "#{@ardir}/metaconfig"
end

#srcdir_rootObject

Hook Script API bases



844
845
846
# File 'lib/rqr.rb', line 844

def srcdir_root
  @ardir
end

#valid_task?(t) ⇒ Boolean

Returns:

  • (Boolean)


886
887
888
# File 'lib/rqr.rb', line 886

def valid_task?(t)
  valid_task_re() =~ t
end

#valid_task_reObject



890
891
892
# File 'lib/rqr.rb', line 890

def valid_task_re
  @valid_task_re ||= /\A(?:#{TASKS.map {|task,desc| task }.join('|')})\z/
end