Class: ToplevelInstaller

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



852
853
854
855
856
857
# File 'lib/roebe/setup/setup.rb', line 852

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

Class Method Details

.invokeObject



828
829
830
831
832
833
834
835
# File 'lib/roebe/setup/setup.rb', line 828

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



841
842
843
844
845
846
847
848
849
850
# File 'lib/roebe/setup/setup.rb', line 841

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

.multipackage?Boolean

Returns:

  • (Boolean)


837
838
839
# File 'lib/roebe/setup/setup.rb', line 837

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

Instance Method Details

#config(key) ⇒ Object

#

config

#


862
863
864
# File 'lib/roebe/setup/setup.rb', line 862

def config(key)
  @config[key]
end

#exec_cleanObject



1078
1079
1080
# File 'lib/roebe/setup/setup.rb', line 1078

def exec_clean
  @installer.exec_clean
end

#exec_configObject

Task Handlers



1055
1056
1057
1058
# File 'lib/roebe/setup/setup.rb', line 1055

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

#exec_distcleanObject



1082
1083
1084
# File 'lib/roebe/setup/setup.rb', line 1082

def exec_distclean
  @installer.exec_distclean
end

#exec_installObject



1064
1065
1066
# File 'lib/roebe/setup/setup.rb', line 1064

def exec_install
  @installer.exec_install
end

#exec_setupObject



1060
1061
1062
# File 'lib/roebe/setup/setup.rb', line 1060

def exec_setup
  @installer.exec_setup
end

#exec_showObject



1072
1073
1074
1075
1076
# File 'lib/roebe/setup/setup.rb', line 1072

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

#exec_testObject



1068
1069
1070
# File 'lib/roebe/setup/setup.rb', line 1068

def exec_test
  @installer.exec_test
end

#init_installersObject



899
900
901
# File 'lib/roebe/setup/setup.rb', line 899

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

#inspectObject



866
867
868
# File 'lib/roebe/setup/setup.rb', line 866

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

#invokeObject



870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
# File 'lib/roebe/setup/setup.rb', line 870

def invoke
  run_metaconfigs
  case task = parsearg_global()
  when nil, 'all'
    parsearg_config
    init_installers
    exec_config
    exec_setup
    exec_install
  else
    case task
    # === config
    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



911
912
913
# File 'lib/roebe/setup/setup.rb', line 911

def objdir_root
  '.'
end

#parsearg_configObject



970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
# File 'lib/roebe/setup/setup.rb', line 970

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 |inner_name, inner_value|
    @config.lookup(inner_name).evaluate inner_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



923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
# File 'lib/roebe/setup/setup.rb', line 923

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



996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
# File 'lib/roebe/setup/setup.rb', line 996

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



957
958
959
960
961
962
# File 'lib/roebe/setup/setup.rb', line 957

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


1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
# File 'lib/roebe/setup/setup.rb', line 1013

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



915
916
917
# File 'lib/roebe/setup/setup.rb', line 915

def relpath
  '.'
end

#run_metaconfigsObject



895
896
897
# File 'lib/roebe/setup/setup.rb', line 895

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

#srcdir_rootObject

Hook Script API bases



907
908
909
# File 'lib/roebe/setup/setup.rb', line 907

def srcdir_root
  @ardir
end

#valid_task?(t) ⇒ Boolean

Returns:

  • (Boolean)


949
950
951
# File 'lib/roebe/setup/setup.rb', line 949

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

#valid_task_reObject



953
954
955
# File 'lib/roebe/setup/setup.rb', line 953

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