mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/extmk.rb, lib/fileutils.rb, lib/mkmf.rb, lib/optparse.rb,
lib/shellwords.rb: get rid of shadowing outer local variable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c009be97e8
commit
88d6c083ea
6 changed files with 45 additions and 43 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Oct 9 23:40:58 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/extmk.rb, lib/fileutils.rb, lib/mkmf.rb, lib/optparse.rb,
|
||||
lib/shellwords.rb: get rid of shadowing outer local variable.
|
||||
|
||||
Mon Oct 9 22:56:12 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* lib/rexml/encoding.rb (REXML::Encoding::check_encoding): spaces
|
||||
|
|
16
ext/extmk.rb
16
ext/extmk.rb
|
@ -220,7 +220,6 @@ end
|
|||
def parse_args()
|
||||
$mflags = []
|
||||
|
||||
opts = nil
|
||||
$optparser ||= OptionParser.new do |opts|
|
||||
opts.on('-n') {$dryrun = true}
|
||||
opts.on('--[no-]extension [EXTS]', Array) do |v|
|
||||
|
@ -259,7 +258,7 @@ def parse_args()
|
|||
rescue OptionParser::InvalidOption => e
|
||||
retry if /^--/ =~ e.args[0]
|
||||
$optparser.warn(e)
|
||||
abort opts.to_s
|
||||
abort $optparser.to_s
|
||||
end
|
||||
|
||||
$destdir ||= ''
|
||||
|
@ -331,7 +330,8 @@ MTIMES = [__FILE__, 'rbconfig.rb', srcdir+'/lib/mkmf.rb'].collect {|f| File.mtim
|
|||
# get static-link modules
|
||||
$static_ext = {}
|
||||
if $extstatic
|
||||
$extstatic.each do |target|
|
||||
$extstatic.each do |t|
|
||||
target = t
|
||||
target = target.downcase if /mswin32|bccwin32/ =~ RUBY_PLATFORM
|
||||
$static_ext[target] = $static_ext.size
|
||||
end
|
||||
|
@ -368,12 +368,12 @@ if $extension
|
|||
exts |= $extension.select {|d| File.directory?("#{ext_prefix}/#{d}")}
|
||||
else
|
||||
withes, withouts = %w[--with --without].collect {|w|
|
||||
if not (w = %w[-extensions -ext].collect {|opt|arg_config(w+opt)}).any?
|
||||
if not (w = %w[-extensions -ext].collect {|o|arg_config(w+o)}).any?
|
||||
proc {false}
|
||||
elsif (w = w.grep(String)).empty?
|
||||
proc {true}
|
||||
else
|
||||
w.collect {|opt| opt.split(/,/)}.flatten.method(:any?)
|
||||
w.collect {|o| o.split(/,/)}.flatten.method(:any?)
|
||||
end
|
||||
}
|
||||
cond = proc {|ext|
|
||||
|
@ -461,7 +461,7 @@ unless $extlist.empty?
|
|||
void Init_ext _((void))\n{\n char *src;#$extinit}
|
||||
}
|
||||
if !modified?(extinit.c, MTIMES) || IO.read(extinit.c) != src
|
||||
open(extinit.c, "w") {|f| f.print src}
|
||||
open(extinit.c, "w") {|fe| fe.print src}
|
||||
end
|
||||
|
||||
$extobjs = "ext/#{extinit.o} " + $extobjs
|
||||
|
@ -485,8 +485,8 @@ else
|
|||
FileUtils.rm_f(extinit.to_a)
|
||||
end
|
||||
rubies = []
|
||||
%w[RUBY RUBYW STATIC_RUBY].each {|r|
|
||||
n = r
|
||||
%w[RUBY RUBYW STATIC_RUBY].each {|n|
|
||||
r = n
|
||||
if r = arg_config("--"+r.downcase) || config_string(r+"_INSTALL_NAME")
|
||||
rubies << Config.expand(r+=EXEEXT)
|
||||
$mflags << "#{n}=#{r}"
|
||||
|
|
|
@ -212,11 +212,11 @@ module FileUtils
|
|||
stack.push path
|
||||
path = File.dirname(path)
|
||||
end
|
||||
stack.reverse_each do |path|
|
||||
stack.reverse_each do |dir|
|
||||
begin
|
||||
fu_mkdir path, options[:mode]
|
||||
fu_mkdir dir, options[:mode]
|
||||
rescue SystemCallError => err
|
||||
raise unless File.directory?(path)
|
||||
raise unless File.directory?(dir)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
29
lib/mkmf.rb
29
lib/mkmf.rb
|
@ -108,7 +108,7 @@ end
|
|||
|
||||
def map_dir(dir, map = nil)
|
||||
map ||= INSTALL_DIRS
|
||||
map.inject(dir) {|dir, (orig, new)| dir.gsub(orig, new)}
|
||||
map.inject(dir) {|d, (orig, new)| d.gsub(orig, new)}
|
||||
end
|
||||
|
||||
topdir = File.dirname(libdir = File.dirname(__FILE__))
|
||||
|
@ -501,7 +501,8 @@ def install_files(mfile, ifiles, map = nil, srcprefix = nil)
|
|||
len = srcdir.size
|
||||
end
|
||||
f = nil
|
||||
Dir.glob(files) do |f|
|
||||
Dir.glob(files) do |fx|
|
||||
f = fx
|
||||
f[0..len] = "" if len
|
||||
d = File.dirname(f)
|
||||
d.sub!(prefix, "") if prefix
|
||||
|
@ -967,11 +968,11 @@ def dir_config(target, idefault=nil, ldefault=nil)
|
|||
|
||||
idirs = idir ? Array === idir ? idir : idir.split(File::PATH_SEPARATOR) : []
|
||||
if defaults
|
||||
idirs.concat(defaults.collect {|dir| dir + "/include"})
|
||||
idirs.concat(defaults.collect {|d| d + "/include"})
|
||||
idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR)
|
||||
end
|
||||
unless idirs.empty?
|
||||
idirs.collect! {|dir| "-I" + dir}
|
||||
idirs.collect! {|d| "-I" + d}
|
||||
idirs -= Shellwords.shellwords($CPPFLAGS)
|
||||
unless idirs.empty?
|
||||
$CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ")
|
||||
|
@ -980,7 +981,7 @@ def dir_config(target, idefault=nil, ldefault=nil)
|
|||
|
||||
ldirs = ldir ? Array === ldir ? ldir : ldir.split(File::PATH_SEPARATOR) : []
|
||||
if defaults
|
||||
ldirs.concat(defaults.collect {|dir| dir + "/lib"})
|
||||
ldirs.concat(defaults.collect {|d| d + "/lib"})
|
||||
ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR)
|
||||
end
|
||||
$LIBPATH = ldirs | $LIBPATH
|
||||
|
@ -1177,7 +1178,7 @@ def create_makefile(target, srcprefix = nil)
|
|||
$objs.push(obj) unless $objs.index(obj)
|
||||
end
|
||||
elsif !(srcs = $srcs)
|
||||
srcs = $objs.collect {|obj| obj.sub(/\.o\z/, '.c')}
|
||||
srcs = $objs.collect {|o| o.sub(/\.o\z/, '.c')}
|
||||
end
|
||||
$srcs = srcs
|
||||
for i in $objs
|
||||
|
@ -1282,7 +1283,7 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
|
|||
dirs << dir
|
||||
mfile.print "pre-install-rb#{sfx}: #{dir}\n"
|
||||
end
|
||||
files.each do |f|
|
||||
for f in files
|
||||
dest = "#{dir}/#{File.basename(f)}"
|
||||
mfile.print("install-rb#{sfx}: #{dest}\n")
|
||||
mfile.print("#{dest}: #{f}\n\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) ")
|
||||
|
@ -1303,7 +1304,7 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
|
|||
end
|
||||
end
|
||||
dirs.unshift(sodir) if target and !dirs.include?(sodir)
|
||||
dirs.each {|dir| mfile.print "#{dir}:\n\t$(MAKEDIRS) $@\n"}
|
||||
dirs.each {|d| mfile.print "#{d}:\n\t$(MAKEDIRS) $@\n"}
|
||||
|
||||
mfile.print <<-SITEINSTALL
|
||||
|
||||
|
@ -1379,7 +1380,7 @@ site-install-rb: install-rb
|
|||
implicit = [[m[1], m[2]], [m.post_match]]
|
||||
next
|
||||
elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line
|
||||
line.gsub!(%r"(?<=\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)") {|*m| RULE_SUBST % m}
|
||||
line.gsub!(%r"(?<=\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)", &RULE_SUBST.method(:%))
|
||||
end
|
||||
depout << line
|
||||
end
|
||||
|
@ -1408,7 +1409,7 @@ site-install-rb: install-rb
|
|||
else
|
||||
headers = %w[ruby.h defines.h]
|
||||
if RULE_SUBST
|
||||
headers.each {|h| h.sub!(/.*/) {|*m| RULE_SUBST % m}}
|
||||
headers.each {|h| h.sub!(/.*/, &RULE_SUBST.method(:%))}
|
||||
end
|
||||
headers << $config_h if $config_h
|
||||
headers << "$(RUBY_EXTCONF_H)" if $extconf_h
|
||||
|
@ -1508,13 +1509,13 @@ EXPORT_PREFIX = config_string('EXPORT_PREFIX') {|s| s.strip}
|
|||
|
||||
hdr = []
|
||||
config_string('COMMON_MACROS') do |s|
|
||||
Shellwords.shellwords(s).each do |s|
|
||||
/(.*?)(?:=(.*))/ =~ s
|
||||
Shellwords.shellwords(s).each do |w|
|
||||
/(.*?)(?:=(.*))/ =~ w
|
||||
hdr << "#define #$1 #$2"
|
||||
end
|
||||
end
|
||||
config_string('COMMON_HEADERS') do |s|
|
||||
Shellwords.shellwords(s).each {|s| hdr << "#include <#{s}>"}
|
||||
Shellwords.shellwords(s).each {|w| hdr << "#include <#{w}>"}
|
||||
end
|
||||
COMMON_HEADERS = hdr.join("\n")
|
||||
COMMON_LIBS = config_string('COMMON_LIBS', &split) || []
|
||||
|
@ -1537,7 +1538,7 @@ LIBPATHFLAG = config_string('LIBPATHFLAG') || ' -L"%s"'
|
|||
RPATHFLAG = config_string('RPATHFLAG') || ''
|
||||
LIBARG = config_string('LIBARG') || '-l%s'
|
||||
|
||||
sep = config_string('BUILD_FILE_SEPARATOR') {|sep| ":/=#{sep}" if sep != "/"} || ""
|
||||
sep = config_string('BUILD_FILE_SEPARATOR') {|s| ":/=#{s}" if sep != "/"} || ""
|
||||
CLEANINGS = "
|
||||
clean:
|
||||
@-$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep})
|
||||
|
|
|
@ -221,7 +221,7 @@ class OptionParser
|
|||
def complete(key, icase = false, pat = nil)
|
||||
pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'),
|
||||
icase)
|
||||
canon, sw, k, v, cn = nil
|
||||
canon, sw, cn = nil
|
||||
candidates = []
|
||||
each do |k, *v|
|
||||
(if Regexp === k
|
||||
|
@ -349,7 +349,7 @@ class OptionParser
|
|||
if conv
|
||||
val = conv.call(*val)
|
||||
else
|
||||
val = proc {|val| val}.call(*val)
|
||||
val = proc {|v| v}.call(*val)
|
||||
end
|
||||
return arg, block, val
|
||||
end
|
||||
|
@ -368,7 +368,7 @@ class OptionParser
|
|||
# +indent+:: Prefix string indents all summarized lines.
|
||||
#
|
||||
def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "")
|
||||
sopts, lopts, s = [], [], nil
|
||||
sopts, lopts = [], [], nil
|
||||
@short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
|
||||
@long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
|
||||
return if sopts.empty? and lopts.empty? # completely hidden
|
||||
|
@ -384,9 +384,9 @@ class OptionParser
|
|||
end
|
||||
|
||||
left[0] << arg if arg
|
||||
mlen = left.collect {|s| s.length}.max.to_i
|
||||
mlen = left.collect {|ss| ss.length}.max.to_i
|
||||
while mlen > width and l = left.shift
|
||||
mlen = left.collect {|s| s.length}.max.to_i if l.length == mlen
|
||||
mlen = left.collect {|ss| ss.length}.max.to_i if l.length == mlen
|
||||
yield(indent + l)
|
||||
end
|
||||
|
||||
|
@ -453,7 +453,7 @@ class OptionParser
|
|||
raise MissingArgument if argv.empty?
|
||||
arg = argv.shift
|
||||
end
|
||||
conv_arg(*parse_arg(arg) {|*exc| raise(*exc)})
|
||||
conv_arg(*parse_arg(arg, &method(:raise)))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -557,7 +557,6 @@ class OptionParser
|
|||
# +nlopts+:: Negated long style options list.
|
||||
#
|
||||
def update(sw, sopts, lopts, nsw = nil, nlopts = nil)
|
||||
o = nil
|
||||
sopts.each {|o| @short[o] = sw} if sopts
|
||||
lopts.each {|o| @long[o] = sw} if lopts
|
||||
nlopts.each {|o| @long[o] = nsw} if nsw and nlopts
|
||||
|
@ -1063,7 +1062,6 @@ class OptionParser
|
|||
default_style = Switch::NoArgument
|
||||
default_pattern = nil
|
||||
klass = nil
|
||||
o = nil
|
||||
n, q, a = nil
|
||||
|
||||
opts.each do |o|
|
||||
|
@ -1097,7 +1095,7 @@ class OptionParser
|
|||
else
|
||||
raise ArgumentError, "argument pattern given twice"
|
||||
end
|
||||
o.each {|(o, *v)| pattern[o] = v.fetch(0) {o}}
|
||||
o.each {|pat, *v| pattern[pat] = v.fetch(0) {pat}}
|
||||
when Module
|
||||
raise ArgumentError, "unsupported argument type: #{o}"
|
||||
when *ArgumentStyle.keys
|
||||
|
@ -1246,8 +1244,8 @@ class OptionParser
|
|||
|
||||
# :nodoc:
|
||||
def parse_in_order(argv = default_argv, setter = nil, &nonopt)
|
||||
opt, arg, sw, val, rest = nil
|
||||
nonopt ||= proc {|arg| throw :terminate, arg}
|
||||
opt, arg, val, rest = nil
|
||||
nonopt ||= proc {|a| throw :terminate, a}
|
||||
argv.unshift(arg) if arg = catch(:terminate) {
|
||||
while arg = argv.shift
|
||||
case arg
|
||||
|
@ -1301,7 +1299,8 @@ class OptionParser
|
|||
# non-option argument
|
||||
else
|
||||
catch(:prune) do
|
||||
visit(:each_option) do |sw|
|
||||
visit(:each_option) do |sw0|
|
||||
sw = sw0
|
||||
sw.block.call(arg) if Switch === sw and sw.match_nonswitch?(arg)
|
||||
end
|
||||
nonopt.call(arg)
|
||||
|
@ -1332,8 +1331,7 @@ class OptionParser
|
|||
#
|
||||
def permute!(argv = default_argv)
|
||||
nonopts = []
|
||||
arg = nil
|
||||
order!(argv) {|arg| nonopts << arg}
|
||||
order!(argv, &nonopts.method(:<<))
|
||||
argv[0, 0] = nonopts
|
||||
argv
|
||||
end
|
||||
|
@ -1410,7 +1408,6 @@ class OptionParser
|
|||
# +block+.
|
||||
#
|
||||
def visit(id, *args, &block)
|
||||
el = nil
|
||||
@stack.reverse_each do |el|
|
||||
el.send(id, *args, &block)
|
||||
end
|
||||
|
@ -1443,7 +1440,7 @@ class OptionParser
|
|||
search(typ, opt) {|sw| return [sw, opt]} # exact match or...
|
||||
end
|
||||
raise AmbiguousOption, catch(:ambiguous) {
|
||||
visit(:complete, typ, opt, icase, *pat) {|opt, *sw| return sw}
|
||||
visit(:complete, typ, opt, icase, *pat) {|o, *sw| return sw}
|
||||
raise InvalidOption, opt
|
||||
}
|
||||
end
|
||||
|
@ -1562,7 +1559,7 @@ class OptionParser
|
|||
#
|
||||
accept(Array) do |s,|
|
||||
if s
|
||||
s = s.split(',').collect {|s| s unless s.empty?}
|
||||
s = s.split(',').collect {|ss| ss unless ss.empty?}
|
||||
end
|
||||
s
|
||||
end
|
||||
|
|
|
@ -28,7 +28,6 @@ module Shellwords
|
|||
def shellwords(line)
|
||||
words = []
|
||||
field = ''
|
||||
word = sq = dq = esc = garbage = sep = nil
|
||||
line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do
|
||||
|word, sq, dq, esc, garbage, sep|
|
||||
raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage
|
||||
|
|
Loading…
Reference in a new issue