Skip to content

Commit

Permalink
Merge branch 'master' into rubygh-1551
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Aug 17, 2019
2 parents ea0fb85 + 11a9f7a commit 9dc394e
Show file tree
Hide file tree
Showing 184 changed files with 1,361 additions and 976 deletions.
1 change: 1 addition & 0 deletions .github/workflows/macos.yml
Expand Up @@ -12,6 +12,7 @@ jobs:
strategy:
matrix:
test_task: [ "check", "test-bundler", "test-bundled-gems" ]
fail-fast: false
steps:
- name: Disable Firewall
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ubuntu.yml
Expand Up @@ -12,6 +12,7 @@ jobs:
strategy:
matrix:
test_task: [ "test-bundler", "test-bundled-gems" ]
fail-fast: false
steps:
- name: Install libraries
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Expand Up @@ -18,6 +18,7 @@ jobs:
vs: 2019
- os: windows-2019
vs: 2017
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Install libraries with vcpkg
Expand Down
6 changes: 3 additions & 3 deletions defs/gmake.mk
Expand Up @@ -196,13 +196,13 @@ update-github: fetch-github
curl -s $(if $(GITHUB_TOKEN),-H "Authorization: bearer $(GITHUB_TOKEN)") $(PULL_REQUEST_API) | \
$(BASERUBY) -rjson -e 'JSON.parse(STDIN.read)["head"].tap { |h| print "#{h["repo"]["full_name"]} #{h["ref"]}" }' \
))
$(eval FORK_REPO := $(shell echo $(PULL_REQUEST_FORK_BRANCH) | cut -d' ' -f1))
$(eval PR_BRANCH := $(shell echo $(PULL_REQUEST_FORK_BRANCH) | cut -d' ' -f2))
$(eval FORK_REPO := $(word 1,$(PULL_REQUEST_FORK_BRANCH)))
$(eval PR_BRANCH := $(word 2,$(PULL_REQUEST_FORK_BRANCH)))

$(eval GITHUB_UPDATE_WORKTREE := $(shell mktemp -d "$(srcdir)/gh-$(PR)-XXXXXX"))
git -C "$(srcdir)" worktree add $(notdir $(GITHUB_UPDATE_WORKTREE)) "gh-$(PR)"
git -C "$(GITHUB_UPDATE_WORKTREE)" merge master --no-edit
@$(BASERUBY) -e 'print "Are you sure to push this to PR=$(PR)? [Y/n]: "; exit(gets.chomp == "n" ? 1 : 0)'
@$(BASERUBY) -e 'print "Are you sure to push this to PR=$(PR)? [Y/n]: "; exit(gets.chomp != "n")'
git -C "$(srcdir)" remote add fork-$(PR) git@github.com:$(FORK_REPO).git
git -C "$(GITHUB_UPDATE_WORKTREE)" push fork-$(PR) gh-$(PR):$(PR_BRANCH)
git -C "$(srcdir)" remote rm fork-$(PR)
Expand Down
2 changes: 1 addition & 1 deletion enum.c
Expand Up @@ -4017,7 +4017,7 @@ int_range_sum(VALUE beg, VALUE end, int excl, VALUE init)
* { 1 => 10, 2 => 20 }.sum {|k, v| k * v } #=> 50
* (1..10).sum #=> 55
* (1..10).sum {|v| v * 2 } #=> 110
* [Object.new].each.sum #=> TypeError
* ('a'..'z').sum #=> TypeError
*
* This method can be used for non-numeric objects by
* explicit <i>init</i> argument.
Expand Down
59 changes: 30 additions & 29 deletions ext/socket/raddrinfo.c
Expand Up @@ -597,16 +597,21 @@ rsock_ipaddr(struct sockaddr *sockaddr, socklen_t sockaddrlen, int norevlookup)
}

#ifdef HAVE_SYS_UN_H
VALUE
rsock_unixpath_str(struct sockaddr_un *sockaddr, socklen_t len)
static long
unixsocket_len(const struct sockaddr_un *su, socklen_t socklen)
{
char *s, *e;
s = sockaddr->sun_path;
e = (char *)sockaddr + len;
const char *s = su->sun_path, *e = (const char*)su + socklen;
while (s < e && *(e-1) == '\0')
e--;
if (s <= e)
return rb_str_new(s, e-s);
return e - s;
}

VALUE
rsock_unixpath_str(struct sockaddr_un *sockaddr, socklen_t len)
{
long n = unixsocket_len(sockaddr, len);
if (n >= 0)
return rb_str_new(sockaddr->sun_path, n);
else
return rb_str_new2("");
}
Expand Down Expand Up @@ -985,6 +990,12 @@ init_unix_addrinfo(rb_addrinfo_t *rai, VALUE path, int socktype)
init_addrinfo(rai, (struct sockaddr *)&un, len,
PF_UNIX, socktype, 0, Qnil, Qnil);
}

static long
rai_unixsocket_len(const rb_addrinfo_t *rai)
{
return unixsocket_len(&rai->addr.un, rai->sockaddr_len);
}
#endif

/*
Expand Down Expand Up @@ -1232,16 +1243,15 @@ rsock_inspect_sockaddr(struct sockaddr *sockaddr_arg, socklen_t socklen, VALUE r
{
struct sockaddr_un *addr = &sockaddr->un;
char *p, *s, *e;
long len = unixsocket_len(addr, socklen);
s = addr->sun_path;
e = (char*)addr + socklen;
while (s < e && *(e-1) == '\0')
e--;
if (e < s)
if (len < 0)
rb_str_cat2(ret, "too-short-AF_UNIX-sockaddr");
else if (s == e)
else if (len == 0)
rb_str_cat2(ret, "empty-path-AF_UNIX-sockaddr");
else {
int printable_only = 1;
e = s + len;
p = s;
while (p < e) {
printable_only = printable_only && ISPRINT(*p) && !ISSPACE(*p);
Expand Down Expand Up @@ -1567,13 +1577,7 @@ addrinfo_mdump(VALUE self)
#ifdef HAVE_SYS_UN_H
case AF_UNIX:
{
struct sockaddr_un *su = &rai->addr.un;
char *s, *e;
s = su->sun_path;
e = (char*)su + rai->sockaddr_len;
while (s < e && *(e-1) == '\0')
e--;
sockaddr = rb_str_new(s, e-s);
sockaddr = rb_str_new(rai->addr.un.sun_path, rai_unixsocket_len(rai));
break;
}
#endif
Expand Down Expand Up @@ -2307,25 +2311,22 @@ addrinfo_unix_path(VALUE self)
rb_addrinfo_t *rai = get_addrinfo(self);
int family = ai_get_afamily(rai);
struct sockaddr_un *addr;
char *s, *e;
long n;

if (family != AF_UNIX)
rb_raise(rb_eSocket, "need AF_UNIX address");

addr = &rai->addr.un;

s = addr->sun_path;
e = (char*)addr + rai->sockaddr_len;
if (e < s)
n = rai_unixsocket_len(rai);
if (n < 0)
rb_raise(rb_eSocket, "too short AF_UNIX address: %"PRIuSIZE" bytes given for minimum %"PRIuSIZE" bytes.",
(size_t)rai->sockaddr_len, (size_t)(s - (char *)addr));
if (addr->sun_path + sizeof(addr->sun_path) < e)
(size_t)rai->sockaddr_len, offsetof(struct sockaddr_un, sun_path));
if ((long)sizeof(addr->sun_path) < n)
rb_raise(rb_eSocket,
"too long AF_UNIX path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
(size_t)(e - addr->sun_path), sizeof(addr->sun_path));
while (s < e && *(e-1) == '\0')
e--;
return rb_str_new(s, e-s);
(size_t)n, sizeof(addr->sun_path));
return rb_str_new(addr->sun_path, n);
}
#endif

Expand Down
5 changes: 1 addition & 4 deletions lib/bundler/bundler.gemspec
Expand Up @@ -34,11 +34,8 @@ Gem::Specification.new do |s|
s.required_ruby_version = ">= 2.3.0"
s.required_rubygems_version = ">= 2.5.2"

# s.files = Dir.glob("{lib,exe}/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
# s.files = Dir.glob("{lib,man,exe}/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }

# we don't check in man pages, but we need to ship them because
# we use them to generate the long-form help for each command.
# s.files += Dir.glob("man/**/*")
# Include the CHANGELOG.md, LICENSE.md, README.md manually
# s.files += %w[CHANGELOG.md LICENSE.md README.md]
# include the gemspec itself because warbler breaks w/o it
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli.rb
Expand Up @@ -538,6 +538,7 @@ def viz
:lazy_default => [ENV["BUNDLER_EDITOR"], ENV["VISUAL"], ENV["EDITOR"]].find {|e| !e.nil? && !e.empty? },
:desc => "Open generated gemspec in the specified editor (defaults to $EDITOR or $BUNDLER_EDITOR)"
method_option :ext, :type => :boolean, :default => false, :desc => "Generate the boilerplate for C extension code"
method_option :git, :type => :boolean, :default => true, :desc => "Initialize a git repo inside your library."
method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config set gem.mit true`."
method_option :test, :type => :string, :lazy_default => "rspec", :aliases => "-t", :banner => "rspec",
:desc => "Generate a test directory for your library, either rspec or minitest. Set a default with `bundle config set gem.test rspec`."
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/gem.rb
Expand Up @@ -148,7 +148,7 @@ def run
end
end

if Bundler.git_present?
if Bundler.git_present? && options[:git]
Bundler.ui.info "Initializing git repo in #{target}"
Dir.chdir(target) do
`git init`
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/plugin/api/source.rb
Expand Up @@ -196,7 +196,7 @@ def cache(spec, custom_path = nil)
# This shall check if two source object represent the same source.
#
# The comparison shall take place only on the attribute that can be
# inferred from the options passed from Gemfile and not on attibutes
# inferred from the options passed from Gemfile and not on attributes
# that are used to pin down the gem to specific version (e.g. Git
# sources should compare on branch and tag but not on commit hash)
#
Expand Down
12 changes: 1 addition & 11 deletions lib/bundler/ruby_version.rb
Expand Up @@ -103,18 +103,8 @@ def versions_string(versions)

def self.system
ruby_engine = RUBY_ENGINE.dup
# :sob: mocking RUBY_VERSION breaks stuff on 1.8.7
ruby_version = ENV.fetch("BUNDLER_SPEC_RUBY_VERSION") { RUBY_VERSION }.dup
ruby_engine_version = case ruby_engine
when "ruby"
ruby_version
when "rbx"
Rubinius::VERSION.dup
when "jruby"
JRUBY_VERSION.dup
else
RUBY_ENGINE_VERSION.dup
end
ruby_engine_version = RUBY_ENGINE_VERSION.dup
patchlevel = RUBY_PATCHLEVEL.to_s

@ruby_version ||= RubyVersion.new(ruby_version, patchlevel, ruby_engine, ruby_engine_version)
Expand Down
20 changes: 18 additions & 2 deletions lib/bundler/shared_helpers.rb
Expand Up @@ -133,8 +133,9 @@ def major_deprecation(major_version, message)

return unless bundler_major_version >= major_version && prints_major_deprecations?
@major_deprecation_ui ||= Bundler::UI::Shell.new("no-color" => true)
ui = Bundler.ui.is_a?(@major_deprecation_ui.class) ? Bundler.ui : @major_deprecation_ui
ui.warn("[DEPRECATED] #{message}")
with_major_deprecation_ui do |ui|
ui.warn("[DEPRECATED] #{message}")
end
end

def print_major_deprecations!
Expand Down Expand Up @@ -211,6 +212,21 @@ def write_to_gemfile(gemfile_path, contents)

private

def with_major_deprecation_ui(&block)
ui = Bundler.ui

if ui.is_a?(@major_deprecation_ui.class)
yield ui
else
begin
Bundler.ui = @major_deprecation_ui
yield Bundler.ui
ensure
Bundler.ui = ui
end
end
end

def validate_bundle_path
path_separator = Bundler.rubygems.path_separator
return unless Bundler.bundle_path.to_s.split(path_separator).size > 1
Expand Down
11 changes: 8 additions & 3 deletions lib/bundler/source/path.rb
Expand Up @@ -20,11 +20,16 @@ def initialize(options)
@allow_cached = false
@allow_remote = false

@root_path = options["root_path"] || Bundler.root
@root_path = options["root_path"] || root

if options["path"]
@path = Pathname.new(options["path"])
@path = expand(@path) unless @path.relative?
expanded_path = expand(@path)
@path = if @path.relative?
expanded_path.relative_path_from(root_path.expand_path)
else
expanded_path
end
end

@name = options["name"]
Expand Down Expand Up @@ -136,7 +141,7 @@ def expand(somepath)

def lockfile_path
return relative_path(original_path) if original_path.absolute?
expand(original_path).relative_path_from(Bundler.root)
expand(original_path).relative_path_from(root)
end

def app_cache_path(custom_path = nil)
Expand Down
44 changes: 43 additions & 1 deletion lib/irb.rb
Expand Up @@ -10,6 +10,7 @@
#
#
require "e2mmap"
require "ripper"

require "irb/init"
require "irb/context"
Expand Down Expand Up @@ -410,6 +411,35 @@ def IRB.irb_abort(irb, exception = Abort)
end

class Irb
ASSIGNMENT_NODE_TYPES = [
# Local, instance, global, class, constant, instance, and index assignment:
# "foo = bar",
# "@foo = bar",
# "$foo = bar",
# "@@foo = bar",
# "::Foo = bar",
# "a::Foo = bar",
# "Foo = bar"
# "foo.bar = 1"
# "foo[1] = bar"
:assign,

# Operation assignment:
# "foo += bar"
# "foo -= bar"
# "foo ||= bar"
# "foo &&= bar"
:opassign,

# Multiple assignment:
# "foo, bar = 1, 2
:massign,
]
# Note: instance and index assignment expressions could also be written like:
# "foo.bar=(1)" and "foo.[]=(1, bar)", when expressed that way, the former
# be parsed as :assign and echo will be suppressed, but the latter is
# parsed as a :method_add_arg and the output won't be suppressed

# Creates a new irb session
def initialize(workspace = nil, input_method = nil, output_method = nil)
@context = Context.new(self, workspace, input_method, output_method)
Expand Down Expand Up @@ -498,7 +528,7 @@ def eval_input
begin
line.untaint
@context.evaluate(line, line_no, exception: exc)
output_value if @context.echo?
output_value if @context.echo? && (@context.echo_on_assignment? || !assignment_expression?(line))
rescue Interrupt => exc
rescue SystemExit, SignalException
raise
Expand Down Expand Up @@ -717,6 +747,18 @@ def inspect
format("#<%s: %s>", self.class, ary.join(", "))
end

def assignment_expression?(line)
# Try to parse the line and check if the last of possibly multiple
# expressions is an assignment type.

# If the expression is invalid, Ripper.sexp should return nil which will
# result in false being returned. Any valid expression should return an
# s-expression where the second selement of the top level array is an
# array of parsed expressions. The first element of each expression is the
# expression's type.
ASSIGNMENT_NODE_TYPES.include?(Ripper.sexp(line)&.dig(1,-1,0))
end

ATTR_TTY = "\e[%sm"
def ATTR_TTY.[](*a) self % a.join(";"); end
ATTR_PLAIN = ""
Expand Down
15 changes: 15 additions & 0 deletions lib/irb/context.rb
Expand Up @@ -121,6 +121,11 @@ def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
if @echo.nil?
@echo = true
end

@echo_on_assignment = IRB.conf[:ECHO_ON_ASSIGNMENT]
if @echo_on_assignment.nil?
@echo_on_assignment = false
end
end

# The top-level workspace, see WorkSpace#main
Expand Down Expand Up @@ -236,6 +241,15 @@ def main
# puts "omg"
# # omg
attr_accessor :echo
# Whether to echo for assignment expressions
#
# Uses IRB.conf[:ECHO_ON_ASSIGNMENT] if available, or defaults to +false+.
#
# a = "omg"
# IRB.CurrentContext.echo_on_assignment = true
# a = "omg"
# #=> omg
attr_accessor :echo_on_assignment
# Whether verbose messages are displayed or not.
#
# A copy of the default <code>IRB.conf[:VERBOSE]</code>
Expand All @@ -261,6 +275,7 @@ def main
alias ignore_sigint? ignore_sigint
alias ignore_eof? ignore_eof
alias echo? echo
alias echo_on_assignment? echo_on_assignment

# Returns whether messages are displayed or not.
def verbose?
Expand Down

0 comments on commit 9dc394e

Please sign in to comment.