Develop and Download Open Source Software

Browse CVS Repository

Diff of /exerb/exerb/setup.rb

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.4 by yuya, Wed Oct 12 02:39:14 2005 UTC revision 1.5 by yuya, Thu Dec 15 02:59:12 2005 UTC
# Line 55  class ConfigTable Line 55  class ConfigTable
55      @config_opt = nil      @config_opt = nil
56      @verbose = true      @verbose = true
57      @no_harm = false      @no_harm = false
     @libsrc_pattern = '*.rb'  
58    end    end
59    
60    attr_accessor :install_prefix    attr_accessor :install_prefix
# Line 73  class ConfigTable Line 72  class ConfigTable
72      @no_harm      @no_harm
73    end    end
74    
   attr_accessor :libsrc_pattern  
   
75    def [](key)    def [](key)
76      lookup(key).resolve(self)      lookup(key).resolve(self)
77    end    end
# Line 150  class ConfigTable Line 147  class ConfigTable
147    def standard_entries(rbconfig)    def standard_entries(rbconfig)
148      c = rbconfig      c = rbconfig
149    
150      rubypath = c['bindir'] + '/' + c['ruby_install_name']      rubypath = File.join(c['bindir'], c['ruby_install_name'] + c['EXEEXT'])
151    
152      major = c['MAJOR'].to_i      major = c['MAJOR'].to_i
153      minor = c['MINOR'].to_i      minor = c['MINOR'].to_i
# Line 373  class ConfigTable Line 370  class ConfigTable
370    
371      def check(val)      def check(val)
372        return 'yes' unless val        return 'yes' unless val
373        unless /\A(y(es)?|n(o)?|t(rue)?|f(alse))\z/i =~ val        case val
374          when /\Ay(es)?\z/i, /\At(rue)?\z/i then 'yes'
375          when /\An(o)?\z/i, /\Af(alse)\z/i  then 'no'
376          else
377          setup_rb_error "config: --#{@name} accepts only yes/no for argument"          setup_rb_error "config: --#{@name} accepts only yes/no for argument"
378        end        end
       (/\Ay(es)?|\At(rue)/i =~ value) ? 'yes' : 'no'  
379      end      end
380    end    end
381    
# Line 472  class ConfigTable Line 471  class ConfigTable
471    end    end
472    
473    class MetaConfigEnvironment    class MetaConfigEnvironment
474      def intiailize(config, installer)      def initialize(config, installer)
475        @config = config        @config = config
476        @installer = installer        @installer = installer
477      end      end
# Line 751  end Line 750  end
750    
751  class ToplevelInstaller  class ToplevelInstaller
752    
753    Version   = '3.4.0'    Version   = '3.4.1'
754    Copyright = 'Copyright (c) 2000-2005 Minero Aoki'    Copyright = 'Copyright (c) 2000-2005 Minero Aoki'
755    
756    TASKS = [    TASKS = [
# Line 892  class ToplevelInstaller Line 891  class ToplevelInstaller
891    
892    def parsearg_no_options    def parsearg_no_options
893      unless ARGV.empty?      unless ARGV.empty?
894          task = caller(0).first.slice(%r<`parsearg_(\w+)'>, 1)
895        setup_rb_error "#{task}: unknown options: #{ARGV.join(' ')}"        setup_rb_error "#{task}: unknown options: #{ARGV.join(' ')}"
896      end      end
897    end    end
# Line 1173  class Installer Line 1173  class Installer
1173      "#<#{self.class} #{File.basename(@srcdir)}>"      "#<#{self.class} #{File.basename(@srcdir)}>"
1174    end    end
1175    
1176      def noop(rel)
1177      end
1178    
1179    #    #
1180    # Hook Script API base methods    # Hook Script API base methods
1181    #    #
# Line 1220  class Installer Line 1223  class Installer
1223      exec_task_traverse 'config'      exec_task_traverse 'config'
1224    end    end
1225    
1226    def config_dir_bin(rel)    alias config_dir_bin noop
1227    end    alias config_dir_lib noop
   
   def config_dir_lib(rel)  
   end  
   
   def config_dir_man(rel)  
   end  
1228    
1229    def config_dir_ext(rel)    def config_dir_ext(rel)
1230      extconf if extdir?(curr_srcdir())      extconf if extdir?(curr_srcdir())
1231    end    end
1232    
1233      alias config_dir_data noop
1234      alias config_dir_conf noop
1235      alias config_dir_man noop
1236    
1237    def extconf    def extconf
1238      ruby "#{curr_srcdir()}/extconf.rb", *@config.config_opt      ruby "#{curr_srcdir()}/extconf.rb", *@config.config_opt
1239    end    end
1240    
   def config_dir_data(rel)  
   end  
   
   def config_dir_conf(rel)  
   end  
   
1241    #    #
1242    # TASK setup    # TASK setup
1243    #    #
# Line 1253  class Installer Line 1248  class Installer
1248    
1249    def setup_dir_bin(rel)    def setup_dir_bin(rel)
1250      files_of(curr_srcdir()).each do |fname|      files_of(curr_srcdir()).each do |fname|
1251        adjust_shebang "#{curr_srcdir()}/#{fname}"        update_shebang_line "#{curr_srcdir()}/#{fname}"
1252      end      end
1253    end    end
1254    
1255    def adjust_shebang(path)    alias setup_dir_lib noop
1256    
1257      def setup_dir_ext(rel)
1258        make if extdir?(curr_srcdir())
1259      end
1260    
1261      alias setup_dir_data noop
1262      alias setup_dir_conf noop
1263      alias setup_dir_man noop
1264    
1265      def update_shebang_line(path)
1266      return if no_harm?      return if no_harm?
1267        return if config('shebang') == 'never'
1268        old = Shebang.load(path)
1269        if old
1270          $stderr.puts "warning: #{path}: Shebang line includes too many args.  It is not portable and your program may not work." if old.args.size > 1
1271          new = new_shebang(old)
1272          return if new.to_s == old.to_s
1273        else
1274          return unless config('shebang') == 'all'
1275          new = Shebang.new(config('rubypath'))
1276        end
1277        $stderr.puts "updating shebang: #{File.basename(path)}" if verbose?
1278        open_atomic_writer(path) {|output|
1279          File.open(path, 'rb') {|f|
1280            f.gets if old   # discard
1281            output.puts new.to_s
1282            output.print f.read
1283          }
1284        }
1285      end
1286    
1287      def new_shebang(old)
1288        if /\Aruby/ =~ File.basename(old.cmd)
1289          Shebang.new(config('rubypath'), old.args)
1290        elsif File.basename(old.cmd) == 'env' and old.args.first == 'ruby'
1291          Shebang.new(config('rubypath'), old.args[1..-1])
1292        else
1293          return old unless config('shebang') == 'all'
1294          Shebang.new(config('rubypath'))
1295        end
1296      end
1297    
1298      def open_atomic_writer(path, &block)
1299      tmpfile = File.basename(path) + '.tmp'      tmpfile = File.basename(path) + '.tmp'
1300      begin      begin
1301        File.open(path, 'rb') {|r|        File.open(tmpfile, 'wb', &block)
1302          first = r.gets        File.rename tmpfile, File.basename(path)
         return unless File.basename(first.sub(/\A\#!/, '').split[0].to_s) == 'ruby'  
         $stderr.puts "adjusting shebang: #{File.basename(path)}" if verbose?  
         File.open(tmpfile, 'wb') {|w|  
           w.print first.sub(/\A\#!\s*\S+/, '#! ' + config('rubypath'))  
           w.write r.read  
         }  
       }  
       move_file tmpfile, File.basename(path)  
1303      ensure      ensure
1304        File.unlink tmpfile if File.exist?(tmpfile)        File.unlink tmpfile if File.exist?(tmpfile)
1305      end      end
1306    end    end
1307    
1308    def setup_dir_lib(rel)    class Shebang
1309    end      def Shebang.load(path)
1310          line = nil
1311          File.open(path) {|f|
1312            line = f.gets
1313          }
1314          return nil unless /\A#!/ =~ line
1315          parse(line)
1316        end
1317    
1318    def setup_dir_man(rel)      def Shebang.parse(line)
1319    end        cmd, *args = *line.strip.sub(/\A\#!/, '').split(' ')
1320          new(cmd, args)
1321        end
1322    
1323    def setup_dir_ext(rel)      def initialize(cmd, args = [])
1324      make if extdir?(curr_srcdir())        @cmd = cmd
1325    end        @args = args
1326        end
1327    
1328    def setup_dir_data(rel)      attr_reader :cmd
1329    end      attr_reader :args
1330    
1331    def setup_dir_conf(rel)      def to_s
1332          "#! #{@cmd}" + (@args.empty? ? '' : " #{@args.join(' ')}")
1333        end
1334    end    end
1335    
1336    #    #
# Line 1306  class Installer Line 1347  class Installer
1347    end    end
1348    
1349    def install_dir_lib(rel)    def install_dir_lib(rel)
1350      install_files rubyscripts(), "#{config('rbdir')}/#{rel}", 0644      install_files libfiles(), "#{config('rbdir')}/#{rel}", 0644
1351    end    end
1352    
1353    def install_dir_ext(rel)    def install_dir_ext(rel)
# Line 1337  class Installer Line 1378  class Installer
1378      end      end
1379    end    end
1380    
1381    def rubyscripts    def libfiles
1382      glob_select(@config.libsrc_pattern, targetfiles())      glob_reject(%w(*.y *.output), targetfiles())
1383    end    end
1384    
1385    def rubyextentions(dir)    def rubyextentions(dir)
# Line 1416  class Installer Line 1457  class Installer
1457        return        return
1458      end      end
1459      $stderr.puts 'Running tests...' if verbose?      $stderr.puts 'Running tests...' if verbose?
1460      require 'test/unit'      begin
1461          require 'test/unit'
1462        rescue LoadError
1463          setup_rb_error 'test/unit cannot loaded.  You need Ruby 1.8 or later to invoke this task.'
1464        end
1465      runner = Test::Unit::AutoRunner.new(true)      runner = Test::Unit::AutoRunner.new(true)
1466      runner.to_run << TESTDIR      runner.to_run << TESTDIR
1467      runner.run      runner.run
# Line 1432  class Installer Line 1477  class Installer
1477      rm_f 'InstalledFiles'      rm_f 'InstalledFiles'
1478    end    end
1479    
1480    def clean_dir_bin(rel)    alias clean_dir_bin noop
1481    end    alias clean_dir_lib noop
1482      alias clean_dir_data noop
1483    def clean_dir_lib(rel)    alias clean_dir_conf noop
1484    end    alias clean_dir_man noop
1485    
1486    def clean_dir_ext(rel)    def clean_dir_ext(rel)
1487      return unless extdir?(curr_srcdir())      return unless extdir?(curr_srcdir())
1488      make 'clean' if File.file?('Makefile')      make 'clean' if File.file?('Makefile')
1489    end    end
1490    
   def clean_dir_data(rel)  
   end  
   
   def clean_dir_conf(rel)  
   end  
   
1491    #    #
1492    # TASK distclean    # TASK distclean
1493    #    #
# Line 1459  class Installer Line 1498  class Installer
1498      rm_f 'InstalledFiles'      rm_f 'InstalledFiles'
1499    end    end
1500    
1501    def distclean_dir_bin(rel)    alias distclean_dir_bin noop
1502    end    alias distclean_dir_lib noop
   
   def distclean_dir_lib(rel)  
   end  
1503    
1504    def distclean_dir_ext(rel)    def distclean_dir_ext(rel)
1505      return unless extdir?(curr_srcdir())      return unless extdir?(curr_srcdir())
1506      make 'distclean' if File.file?('Makefile')      make 'distclean' if File.file?('Makefile')
1507    end    end
1508    
1509    def distclean_dir_data(rel)    alias distclean_dir_data noop
1510    end    alias distclean_dir_conf noop
1511      alias distclean_dir_man noop
   def distclean_dir_conf(rel)  
   end  
1512    
1513    #    #
1514    # lib    # Traversing
1515    #    #
1516    
1517    def exec_task_traverse(task)    def exec_task_traverse(task)
1518      run_hook "pre-#{task}"      run_hook "pre-#{task}"
1519      FILETYPES.each do |type|      FILETYPES.each do |type|
1520        if config('without-ext') == 'yes' and type == 'ext'        if type == 'ext' and config('without-ext') == 'yes'
1521          $stderr.puts 'skipping ext/* by user option' if verbose?          $stderr.puts 'skipping ext/* by user option' if verbose?
1522          next          next
1523        end        end

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26