Class: ToplevelInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/xmpp4r/setup.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.



792
793
794
795
796
797
# File 'lib/vendor/xmpp4r/setup.rb', line 792

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

Class Method Details

.invokeObject



768
769
770
771
772
773
774
775
# File 'lib/vendor/xmpp4r/setup.rb', line 768

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



781
782
783
784
785
786
787
788
789
790
# File 'lib/vendor/xmpp4r/setup.rb', line 781

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)


777
778
779
# File 'lib/vendor/xmpp4r/setup.rb', line 777

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

Instance Method Details

#config(key) ⇒ Object



799
800
801
# File 'lib/vendor/xmpp4r/setup.rb', line 799

def config(key)
  @config[key]
end

#exec_cleanObject



1014
1015
1016
# File 'lib/vendor/xmpp4r/setup.rb', line 1014

def exec_clean
  @installer.exec_clean
end

#exec_configObject

Task Handlers



991
992
993
994
# File 'lib/vendor/xmpp4r/setup.rb', line 991

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

#exec_distcleanObject



1018
1019
1020
# File 'lib/vendor/xmpp4r/setup.rb', line 1018

def exec_distclean
  @installer.exec_distclean
end

#exec_installObject



1000
1001
1002
# File 'lib/vendor/xmpp4r/setup.rb', line 1000

def exec_install
  @installer.exec_install
end

#exec_setupObject



996
997
998
# File 'lib/vendor/xmpp4r/setup.rb', line 996

def exec_setup
  @installer.exec_setup
end

#exec_showObject



1008
1009
1010
1011
1012
# File 'lib/vendor/xmpp4r/setup.rb', line 1008

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

#exec_testObject



1004
1005
1006
# File 'lib/vendor/xmpp4r/setup.rb', line 1004

def exec_test
  @installer.exec_test
end

#init_installersObject



835
836
837
# File 'lib/vendor/xmpp4r/setup.rb', line 835

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

#inspectObject



803
804
805
# File 'lib/vendor/xmpp4r/setup.rb', line 803

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

#invokeObject



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

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



847
848
849
# File 'lib/vendor/xmpp4r/setup.rb', line 847

def objdir_root
  '.'
end

#parsearg_configObject



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

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



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

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



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

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



893
894
895
896
897
898
# File 'lib/vendor/xmpp4r/setup.rb', line 893

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


949
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
# File 'lib/vendor/xmpp4r/setup.rb', line 949

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



851
852
853
# File 'lib/vendor/xmpp4r/setup.rb', line 851

def relpath
  '.'
end

#run_metaconfigsObject



831
832
833
# File 'lib/vendor/xmpp4r/setup.rb', line 831

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

#srcdir_rootObject

Hook Script API bases



843
844
845
# File 'lib/vendor/xmpp4r/setup.rb', line 843

def srcdir_root
  @ardir
end

#valid_task?(t) ⇒ Boolean

Returns:

  • (Boolean)


885
886
887
# File 'lib/vendor/xmpp4r/setup.rb', line 885

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

#valid_task_reObject



889
890
891
# File 'lib/vendor/xmpp4r/setup.rb', line 889

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