tool/vpath.rb
* tool/generic_erb.rb, tool/id2token.rb: add --path-separator option for mingw where make and built ruby live in different world. * tool/vpath.rb: extract from tool/instruction.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2f80fddadc
commit
d22ac50ad4
@ -1,3 +1,10 @@
|
|||||||
|
Thu Nov 29 17:12:26 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* tool/generic_erb.rb, tool/id2token.rb: add --path-separator option
|
||||||
|
for mingw where make and built ruby live in different world.
|
||||||
|
|
||||||
|
* tool/vpath.rb: extract from tool/instruction.rb.
|
||||||
|
|
||||||
Thu Nov 29 17:11:06 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Nov 29 17:11:06 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* test/io/wait/test_io_wait.rb (TestIOWait#fill_pipe):
|
* test/io/wait/test_io_wait.rb (TestIOWait#fill_pipe):
|
||||||
|
@ -565,7 +565,7 @@ PHONY:
|
|||||||
|
|
||||||
{$(srcdir)}.y.c:
|
{$(srcdir)}.y.c:
|
||||||
$(ECHO) generating $@
|
$(ECHO) generating $@
|
||||||
$(Q)$(BASERUBY) $(srcdir)/tool/id2token.rb --vpath=$(VPATH) id.h $(SRC_FILE) > parse.tmp.y
|
$(Q)$(BASERUBY) $(srcdir)/tool/id2token.rb --path-separator=$(PATH_SEPARATOR) --vpath=$(VPATH) id.h $(SRC_FILE) > parse.tmp.y
|
||||||
$(Q)$(YACC) -d $(YFLAGS) -o y.tab.c parse.tmp.y
|
$(Q)$(YACC) -d $(YFLAGS) -o y.tab.c parse.tmp.y
|
||||||
$(Q)$(RM) parse.tmp.y
|
$(Q)$(RM) parse.tmp.y
|
||||||
$(Q)sed -f $(srcdir)/tool/ytab.sed -e "/^#/s!parse\.tmp\.[iy]!parse.y!" -e "/^#/s!y\.tab\.c!$@!" y.tab.c > $@.new
|
$(Q)sed -f $(srcdir)/tool/ytab.sed -e "/^#/s!parse\.tmp\.[iy]!parse.y!" -e "/^#/s!y\.tab\.c!$@!" y.tab.c > $@.new
|
||||||
|
@ -1,19 +1,11 @@
|
|||||||
|
# -*- coding: us-ascii -*-
|
||||||
require 'erb'
|
require 'erb'
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
$:.unshift(File.dirname(__FILE__))
|
||||||
|
require 'vpath'
|
||||||
|
|
||||||
vpath = ["."]
|
vpath = VPath.new
|
||||||
def vpath.open(file, *rest)
|
|
||||||
find do |dir|
|
|
||||||
begin
|
|
||||||
path = File.join(dir, file)
|
|
||||||
return File.open(path, *rest) {|f| yield(f)}
|
|
||||||
rescue Errno::ENOENT
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end or raise(Errno::ENOENT, file)
|
|
||||||
end
|
|
||||||
|
|
||||||
timestamp = nil
|
timestamp = nil
|
||||||
output = nil
|
output = nil
|
||||||
ifchange = nil
|
ifchange = nil
|
||||||
@ -22,7 +14,7 @@ opt = OptionParser.new do |o|
|
|||||||
o.on('-t', '--timestamp[=PATH]') {|v| timestamp = v || true}
|
o.on('-t', '--timestamp[=PATH]') {|v| timestamp = v || true}
|
||||||
o.on('-o', '--output=PATH') {|v| output = v}
|
o.on('-o', '--output=PATH') {|v| output = v}
|
||||||
o.on('-c', '--[no-]if-change') {|v| ifchange = v}
|
o.on('-c', '--[no-]if-change') {|v| ifchange = v}
|
||||||
o.on('-v', '--vpath=DIR') {|dirs| vpath.concat dirs.split(File::PATH_SEPARATOR)}
|
vpath.def_options(o)
|
||||||
o.order!(ARGV)
|
o.order!(ARGV)
|
||||||
end
|
end
|
||||||
template = ARGV.shift or abort opt.to_s
|
template = ARGV.shift or abort opt.to_s
|
||||||
|
@ -1,27 +1,22 @@
|
|||||||
#! /usr/bin/ruby -p
|
#! /usr/bin/ruby -p
|
||||||
|
# -*- coding: us-ascii -*-
|
||||||
BEGIN {
|
BEGIN {
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
vpath = ["."]
|
$:.unshift(File.dirname(__FILE__))
|
||||||
|
require 'vpath'
|
||||||
|
vpath = VPath.new
|
||||||
header = nil
|
header = nil
|
||||||
|
|
||||||
opt = OptionParser.new do |o|
|
opt = OptionParser.new do |o|
|
||||||
o.on('-v', '--vpath=DIR') {|dirs| vpath.concat dirs.split(File::PATH_SEPARATOR)}
|
vpath.def_options(o)
|
||||||
header = o.order!(ARGV).shift
|
header = o.order!(ARGV).shift
|
||||||
end or abort opt.opt_s
|
end or abort opt.opt_s
|
||||||
|
|
||||||
TOKENS = {}
|
TOKENS = {}
|
||||||
vpath.find do |dir|
|
h = vpath.read(header) rescue abort("#{header} not found in #{vpath.inspect}")
|
||||||
begin
|
h.scan(/^#define\s+RUBY_TOKEN_(\w+)\s+(\d+)/) do |token, id|
|
||||||
h = File.read(File.join(dir, header))
|
TOKENS[token] = id
|
||||||
rescue Errno::ENOENT
|
end
|
||||||
nil
|
|
||||||
else
|
|
||||||
h.scan(/^#define\s+RUBY_TOKEN_(\w+)\s+(\d+)/) do |token, id|
|
|
||||||
TOKENS[token] = id
|
|
||||||
end
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end or abort "#{header} not found in #{vpath.inspect}"
|
|
||||||
|
|
||||||
TOKENS_RE = /\bRUBY_TOKEN\((#{TOKENS.keys.join('|')})\)\s*(?=\s)/
|
TOKENS_RE = /\bRUBY_TOKEN\((#{TOKENS.keys.join('|')})\)\s*(?=\s)/
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
#!./miniruby
|
#!./miniruby
|
||||||
|
# -*- coding: us-ascii -*-
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'erb'
|
require 'erb'
|
||||||
|
$:.unshift(File.dirname(__FILE__))
|
||||||
|
require 'vpath'
|
||||||
|
|
||||||
class RubyVM
|
class RubyVM
|
||||||
class Instruction
|
class Instruction
|
||||||
@ -1256,66 +1259,6 @@ class RubyVM
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module VPATH
|
|
||||||
def search(meth, base, *rest)
|
|
||||||
begin
|
|
||||||
meth.call(base, *rest)
|
|
||||||
rescue Errno::ENOENT => error
|
|
||||||
each do |dir|
|
|
||||||
return meth.call(File.join(dir, base), *rest) rescue nil
|
|
||||||
end
|
|
||||||
raise error
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def process(*args, &block)
|
|
||||||
search(File.method(__callee__), *args, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
alias stat process
|
|
||||||
alias lstat process
|
|
||||||
|
|
||||||
def open(*args)
|
|
||||||
f = search(File.method(:open), *args)
|
|
||||||
if block_given?
|
|
||||||
begin
|
|
||||||
yield f
|
|
||||||
ensure
|
|
||||||
f.close unless f.closed?
|
|
||||||
end
|
|
||||||
else
|
|
||||||
f
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def read(*args)
|
|
||||||
open(*args) {|f| f.read}
|
|
||||||
end
|
|
||||||
|
|
||||||
def foreach(file, *args, &block)
|
|
||||||
open(file) {|f| f.each(*args, &block)}
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.def_options(opt)
|
|
||||||
vpath = []
|
|
||||||
path_sep = ':'
|
|
||||||
|
|
||||||
opt.on("-I", "--srcdir=DIR", "add a directory to search path") {|dir|
|
|
||||||
vpath |= [dir]
|
|
||||||
}
|
|
||||||
opt.on("-L", "--vpath=PATH LIST", "add directories to search path") {|dirs|
|
|
||||||
vpath |= dirs.split(path_sep)
|
|
||||||
}
|
|
||||||
opt.on("--path-separator=SEP", /\A\W\z/, "separator for vpath") {|sep|
|
|
||||||
path_sep = sep
|
|
||||||
}
|
|
||||||
|
|
||||||
proc {
|
|
||||||
vpath.extend(self) unless vpath.empty?
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class SourceCodeGenerator
|
class SourceCodeGenerator
|
||||||
Files = { # codes
|
Files = { # codes
|
||||||
'vm.inc' => VmBodyGenerator,
|
'vm.inc' => VmBodyGenerator,
|
||||||
@ -1382,16 +1325,17 @@ class RubyVM
|
|||||||
opts[:verbose] = v
|
opts[:verbose] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
vpath = VPATH.def_options(opt)
|
vpath = VPath.new
|
||||||
|
vpath.def_options(opt)
|
||||||
|
|
||||||
proc {
|
proc {
|
||||||
opts[:VPATH] = vpath.call
|
opts[:VPATH] = vpath
|
||||||
build opts
|
build opts
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.build opts, vpath = ['./']
|
def self.build opts, vpath = ['./']
|
||||||
opts[:VPATH] = vpath.extend(VPATH) unless opts[:VPATH]
|
opts[:VPATH] ||= VPath.new(*vpath)
|
||||||
self.new InstructionsLoader.new(opts)
|
self.new InstructionsLoader.new(opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
79
tool/vpath.rb
Normal file
79
tool/vpath.rb
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
# -*- coding: us-ascii -*-
|
||||||
|
|
||||||
|
class VPath
|
||||||
|
attr_accessor :separator
|
||||||
|
|
||||||
|
def initialize(*list)
|
||||||
|
@list = list
|
||||||
|
@additional = []
|
||||||
|
@separator = File::PATH_SEPARATOR
|
||||||
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
list.inspect
|
||||||
|
end
|
||||||
|
|
||||||
|
def search(meth, base, *rest)
|
||||||
|
begin
|
||||||
|
meth.call(base, *rest)
|
||||||
|
rescue Errno::ENOENT => error
|
||||||
|
list.each do |dir|
|
||||||
|
return meth.call(File.join(dir, base), *rest) rescue nil
|
||||||
|
end
|
||||||
|
raise error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def process(*args, &block)
|
||||||
|
search(File.method(__callee__), *args, &block)
|
||||||
|
end
|
||||||
|
|
||||||
|
alias stat process
|
||||||
|
alias lstat process
|
||||||
|
|
||||||
|
def open(*args)
|
||||||
|
f = search(File.method(:open), *args)
|
||||||
|
if block_given?
|
||||||
|
begin
|
||||||
|
yield f
|
||||||
|
ensure
|
||||||
|
f.close unless f.closed?
|
||||||
|
end
|
||||||
|
else
|
||||||
|
f
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def read(*args)
|
||||||
|
open(*args) {|f| f.read}
|
||||||
|
end
|
||||||
|
|
||||||
|
def foreach(file, *args, &block)
|
||||||
|
open(file) {|f| f.each(*args, &block)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_options(opt)
|
||||||
|
opt.on("-I", "--srcdir=DIR", "add a directory to search path") {|dir|
|
||||||
|
@additional << dir
|
||||||
|
}
|
||||||
|
opt.on("-L", "--vpath=PATH LIST", "add directories to search path") {|dirs|
|
||||||
|
@additional << [dirs]
|
||||||
|
}
|
||||||
|
opt.on("--path-separator=SEP", /\A\W\z/, "separator for vpath") {|sep|
|
||||||
|
@separator = sep
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def list
|
||||||
|
@additional.reject! do |dirs|
|
||||||
|
case dirs
|
||||||
|
when String
|
||||||
|
@list << dirs
|
||||||
|
when Array
|
||||||
|
@list.concat(dirs[0].split(@separator))
|
||||||
|
end
|
||||||
|
true
|
||||||
|
end
|
||||||
|
@list
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user