Skip to content
Merged
36 changes: 1 addition & 35 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,14 @@
require 'fileutils'
require 'shellwords'

MRUBY_VERSION = '3.0.0'
MRUBY_VERSION = '3.4.0'

file :mruby do
if RUBY_PLATFORM.match(/solaris/)
sh "git clone --branch=#{MRUBY_VERSION} https://github.com/mruby/mruby"
patch = 'gpatch'
else
sh "curl -L --fail --retry 3 --retry-delay 1 https://github.com/mruby/mruby/archive/#{MRUBY_VERSION}.tar.gz -s -o - | tar zxf -"
FileUtils.mv("mruby-#{MRUBY_VERSION}", 'mruby')
patch = 'patch'
end

# Patch: https://github.com/mruby/mruby/pull/5318
if MRUBY_VERSION == '3.0.0'
IO.popen([patch, '-p0'], 'w') do |io|
io.write(<<-'EOS')
--- mruby/lib/mruby/build.rb 2021-03-05 00:07:35.000000000 -0800
+++ mruby/lib/mruby/build.rb 2021-03-05 12:25:15.159190950 -0800
@@ -320,12 +320,16 @@
return @mrbcfile if @mrbcfile

gem_name = "mruby-bin-mrbc"
- gem = @gems[gem_name]
- gem ||= (host = MRuby.targets["host"]) && host.gems[gem_name]
- unless gem
- fail "external mrbc or mruby-bin-mrbc gem in current('#{@name}') or 'host' build is required"
+ if (gem = @gems[gem_name])
+ @mrbcfile = exefile("#{gem.build.build_dir}/bin/mrbc")
+ elsif !host? && (host = MRuby.targets["host"])
+ if (gem = host.gems[gem_name])
+ @mrbcfile = exefile("#{gem.build.build_dir}/bin/mrbc")
+ elsif host.mrbcfile_external?
+ @mrbcfile = host.mrbcfile
+ end
end
- @mrbcfile = exefile("#{gem.build.build_dir}/bin/mrbc")
+ @mrbcfile || fail("external mrbc or mruby-bin-mrbc gem in current('#{@name}') or 'host' build is required")
end

def mrbcfile=(path)
EOS
end
end
end

Expand Down
116 changes: 0 additions & 116 deletions build_config.rb.lock

This file was deleted.

4 changes: 2 additions & 2 deletions mrbgem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ MRuby::Gem::Specification.new('mitamae') do |spec|
spec.add_dependency 'mruby-io', core: 'mruby-io'
spec.add_dependency 'mruby-kernel-ext', core: 'mruby-kernel-ext'
spec.add_dependency 'mruby-object-ext', core: 'mruby-object-ext'
spec.add_dependency 'mruby-print', core: 'mruby-print'
spec.add_dependency 'mruby-struct', core: 'mruby-struct'
spec.add_dependency 'mruby-symbol-ext', core: 'mruby-symbol-ext'

spec.add_dependency 'mruby-dir', core: 'mruby-dir'

spec.add_dependency 'mruby-at_exit', mgem: 'mruby-at_exit'
spec.add_dependency 'mruby-dir', mgem: 'mruby-dir'
spec.add_dependency 'mruby-dir-glob', mgem: 'mruby-dir-glob'
spec.add_dependency 'mruby-env', mgem: 'mruby-env'
spec.add_dependency 'mruby-file-stat', mgem: 'mruby-file-stat'
Expand Down
2 changes: 1 addition & 1 deletion mrblib/mitamae/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def log_output_line(level, output_name, line)
# https://github.com/itamae-kitchen/itamae/blob/v1.9.9/lib/itamae/backend.rb#L168-L189
def build_command(command, user: nil, cwd: nil)
if command.is_a?(Array)
command = Shellwords.shelljoin(command)
command = command.shelljoin
end

if cwd
Expand Down
132 changes: 132 additions & 0 deletions mrblib/mitamae/compat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Compatibility patches for mruby 3.4.0
#
# In mruby 3.4.0, module_function makes singleton methods private instead
# of public. This affects Shellwords and Open3 modules. Work around by
# redefining affected methods as explicit public singleton methods.

module Shellwords
def self.shellescape(str)
str = str.to_s
return "''".dup if str.empty?

str = str.dup
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1")
str.gsub!(/\n/, "'\n'")
str
end

def self.escape(str)
shellescape(str)
end

def self.shelljoin(array)
array.map { |arg| shellescape(arg) }.join(' ')
end

def self.join(array)
shelljoin(array)
end
end

class String
def shellescape
Shellwords.shellescape(self)
end
end

class Array
def shelljoin
Shellwords.shelljoin(self)
end
end

# In mruby 3.4.0, Kernel#` is private. Make it accessible via public method.
module Kernel
def `(cmd)
IO.popen(cmd) { |io| io.read }
end
end

# Redefine Open3 module methods as public class methods.
# The original module_function definitions in mruby-open3 become private
# singleton methods in mruby 3.4.0.
module Open3
def self.capture3(*cmd)
opts = {}
if cmd.last.is_a?(Hash)
opts = cmd.pop.dup
end
out_r, out_w = IO.pipe
err_r, err_w = IO.pipe
opts[:out] = out_w.to_i
opts[:err] = err_w.to_i
pid = spawn(*cmd, opts)

out_w.close
err_w.close

stdout = ''
stderr = ''

remaining_ios = [out_r, err_r]
buf = ''
until remaining_ios.empty?
readable_ios, = IO.select(remaining_ios)
readable_ios.each do |io|
begin
io.sysread(1024, buf)
if io == out_r
stdout << buf
else
stderr << buf
end
rescue EOFError
io.close unless io.closed?
remaining_ios.delete(io)
end
end
end

_, status = Process.waitpid2(pid)
[stdout, stderr, status]
end

def self.capture2(*cmd)
stdout, stderr, status = capture3(*cmd)
$stderr.print(stderr)
[stdout, status]
end

def self.capture2e(*cmd)
opts = {}
if cmd.last.is_a?(Hash)
opts = cmd.pop.dup
end
out_r, out_w = IO.pipe
opts[:out] = out_w.to_i
opts[:err] = out_w.to_i
pid = spawn(*cmd, opts)

out_w.close

stdout_and_stderr_str = ''

remaining_ios = [out_r]
buf = ''
until remaining_ios.empty?
readable_ios, = IO.select(remaining_ios)
readable_ios.each do |io|
begin
io.sysread(1024, buf)
stdout_and_stderr_str << buf
rescue EOFError
io.close unless io.closed?
remaining_ios.delete(io)
end
end
end

_, status = Process.waitpid2(pid)
[stdout_and_stderr_str, status]
end
end
9 changes: 7 additions & 2 deletions mrblib/mitamae/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ def reverse_merge!(other_hash)
@mash.replace(_reverse_merge(other_hash))
end

def merge!(other_hash)
@mash.merge!(other_hash)
end

def [](key)
if @mash.has_key?(key)
@mash[key]
skey = key.to_s
if @mash.has_key?(skey)
@mash[skey]
else
fetch_inventory_value(key)
end
Expand Down
6 changes: 3 additions & 3 deletions mrblib/mitamae/recipe_loader.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module MItamae
class RecipeLoader
def initialize(options)
@backend = options[:backend]
@node = build_node(options[:node_jsons], options[:node_yamls], @backend)
def initialize(node_jsons: [], node_yamls: [], backend:)
@backend = backend
@node = build_node(node_jsons, node_yamls, @backend)
end

# @return [Array<MItamae::Recipe>]
Expand Down
11 changes: 6 additions & 5 deletions mrblib/mitamae/resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ def resource_type

def process_attributes
self.class.defined_attributes.each_pair do |key, details|
@attributes[key] ||= @resource_name if details[:default_name]
@attributes[key] = details[:default] if details.has_key?(:default) && !@attributes.has_key?(key)
skey = key.to_s
@attributes[skey] ||= @resource_name if details[:default_name]
@attributes[skey] = details[:default] if details.has_key?(:default) && !@attributes.has_key?(skey)

if details[:required] && !@attributes.has_key?(key)
if details[:required] && !@attributes.has_key?(skey)
raise AttributeMissingError, "'#{key}' attribute is required but it is not set."
end

if @attributes[key] && details[:type]
if @attributes[skey] && details[:type]
valid_type = [details[:type]].flatten.any? do |type|
@attributes[key].is_a?(type)
@attributes[skey].is_a?(type)
end
unless valid_type
raise Resource::InvalidTypeError, "#{key} attribute should be #{details[:type]}."
Expand Down
7 changes: 4 additions & 3 deletions mrblib/mitamae/resource_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ def respond_to_missing?(method, include_private = false)

def method_missing(method, *args, &block)
if @resource.class.defined_attributes[method]
smethod = method.to_s
if args.size == 1
return @resource.attributes[method] = args.first
return @resource.attributes[smethod] = args.first
elsif args.size == 0 && block_given?
return @resource.attributes[method] = block
return @resource.attributes[smethod] = block
elsif args.size == 0
return @resource.attributes[method]
return @resource.attributes[smethod]
end
end

Expand Down
Loading
Loading