Skip to content

Commit

Permalink
Merge tag 'upstream/1.12.7'
Browse files Browse the repository at this point in the history
upstream 1.12.7
  • Loading branch information
sorah committed Oct 4, 2021
2 parents 29d5969 + 282ab8f commit 9451f82
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: k0kubun
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
## v1.12.7

- Add mruby-enum-ext

## v1.12.6

- Fix a build issue for Solaris

## v1.12.5

- Upgrade mruby-yaml
- No impact for behaviors. You can build this mitamae without curl to fetch libyaml.

## v1.12.4

- Upgrade specinfra [from v2.82.23 to v2.82.25](https://github.com/mizzy/specinfra/compare/v2.82.23...v2.82.25)
- Fix `undefined method 'basename' (NoMethodError)` in `package` resources

## v1.12.3

- Add `--no-color` option to disable colors

## v1.12.2

- Upgrade mruby from v2.1.2 to v3.0.0

## v1.12.1

- Allow defining top-level modules without `::` in recipes

## v1.12.0

- Upgrade mruby from v2.0.1 to v2.1.2
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,14 @@ See [CHANGELOG.md](./CHANGELOG.md).

## Contributing

Please refer to [CONTRIBUTING.md](./CONTRIBUTING.md).
When you develop your local changes, you can write an integration test under [`spec/`](./spec) and run it like:

```
bundle install
bundle exec rake test:integration
```

This requires Docker on your local environment.

## License

Expand Down
36 changes: 35 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
require 'fileutils'
require 'shellwords'

MRUBY_VERSION = '2.1.2'
MRUBY_VERSION = '3.0.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
10 changes: 5 additions & 5 deletions build_config.rb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ builds:
https://github.com/ksss/mruby-file-stat.git:
url: https://github.com/ksss/mruby-file-stat.git
branch: master
commit: 66cf135ff9642d96a6127a79b307f6314e606deb
commit: b81bc71a6f2ddd424fd5e544d2cccd289d4d7545
version: 0.0.0
https://github.com/k0kubun/mruby-hashie.git:
url: https://github.com/k0kubun/mruby-hashie.git
Expand All @@ -42,7 +42,7 @@ builds:
https://github.com/k0kubun/mruby-open3.git:
url: https://github.com/k0kubun/mruby-open3.git
branch: master
commit: b2dba93fdbd60dcff8aa20b6c56014ac89d267ad
commit: d6ab1bcd13446661c2e134ad8343caba9d15e59a
version: 0.0.0
https://github.com/fastly/mruby-optparse.git:
url: https://github.com/fastly/mruby-optparse.git
Expand All @@ -57,17 +57,17 @@ builds:
https://github.com/k0kubun/mruby-specinfra.git:
url: https://github.com/k0kubun/mruby-specinfra.git
branch: master
commit: f29062376e4cdca4c21401e1ed8a8551206be9e6
commit: 6581261797b38bc7698f27c22733f74fcc102b30
version: 0.0.0
https://github.com/k0kubun/mruby-tempfile.git:
url: https://github.com/k0kubun/mruby-tempfile.git
branch: master
commit: 26273b9f884bb4c9e58ba83010ccd5b4258fb82e
commit: 77736581bf971717aa2259144cf17bbb88b8d6b6
version: 0.0.0
https://github.com/mrbgems/mruby-yaml.git:
url: https://github.com/mrbgems/mruby-yaml.git
branch: master
commit: 0606652a6e99d902cd3101cf2d757a7c0c37a7fd
commit: 9f4408d4d46ffc8668ea07cc9c6249f33114d3a9
version: 0.1.0
https://github.com/k0kubun/mruby-erb.git:
url: https://github.com/k0kubun/mruby-erb.git
Expand Down
1 change: 1 addition & 0 deletions mrbgem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ MRuby::Gem::Specification.new('mitamae') do |spec|
spec.summary = 'mitamae'
spec.bins = ['mitamae']

spec.add_dependency 'mruby-enum-ext', core: 'mruby-enum-ext'
spec.add_dependency 'mruby-enumerator', core: 'mruby-enumerator'
spec.add_dependency 'mruby-eval', core: 'mruby-eval'
spec.add_dependency 'mruby-exit', core: 'mruby-exit'
Expand Down
1 change: 1 addition & 0 deletions mrblib/mitamae/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def print_help
[--shell=SHELL] # Default: /bin/sh
-l, [--log-level=LOG_LEVEL] # Default: info
[--plugins=PATH] # Default: ./plugins
[--color, --no-color] # Default: true
Run mitamae locally
HELP
Expand Down
5 changes: 4 additions & 1 deletion mrblib/mitamae/cli/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Local
shell: '/bin/sh',
log_level: 'info',
plugins: './plugins',
color: true,
}

def initialize(args)
Expand All @@ -21,7 +22,7 @@ def run
exit 1
end

MItamae.logger = Logger.new(@options[:log_level])
MItamae.logger = Logger.new(@options[:log_level], colored: @options[:color])
MItamae.logger.info 'Starting mitamae...'

Plugin.plugins_path = File.expand_path(@options[:plugins])
Expand Down Expand Up @@ -49,6 +50,8 @@ def parse_options(args)
opt.on('--shell=VAL') { |v| @options[:shell] = v }
opt.on('--log-level=VAL') { |v| @options[:log_level] = v }
opt.on('--plugins=VAL') { |v| @options[:plugins] = v }
opt.on('--color') { |v| @options[:color] = true }
opt.on('--no-color') { |v| @options[:color] = false }
opt.parse!(args.dup)
end
end
Expand Down
4 changes: 3 additions & 1 deletion mrblib/mitamae/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Logger

attr_reader :level

def initialize(severity)
def initialize(severity, colored: true)
case severity.to_s.downcase
when 'debug'
@level = DEBUG
Expand All @@ -40,6 +40,7 @@ def initialize(severity)
end
@indent_level = 0
@color = :clear
@colored = colored
end

def debug?
Expand Down Expand Up @@ -127,6 +128,7 @@ def add(severity, message)
end

def colorize(severity, str)
return str unless @colored
color =
case severity
when :error
Expand Down
20 changes: 12 additions & 8 deletions mrblib/mitamae/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,24 @@ def root
def eval_file(path, variables)
src = File.read(path)
context = RecipeContext.new(self, variables)
InstanceEval.new(src, path, 1, receiver: context).call
InstanceEval.new(src, path, 1, context: context).call
end

# For #instance_eval with TOPLEVEL_BINDING
class InstanceEval
def initialize(*args, receiver:)
@args = args
@receiver = receiver
def initialize(src, path, lineno, context:)
# Using instance_eval + eval to allow top-level class/module definition without `::`.
# To pass args without introducing any local/instance variables, this code is also eval-ed.
@code = <<-RUBY
@context.instance_eval do
eval(#{src.dump}, nil, #{path.dump}, #{lineno})
end
RUBY
@context = context
end

# This method has no local variables to avoid spilling them to recipes.
def call
# When we call #instance_eval, we should not have local variables.
# Otherwise a recipe may see the local variables by default.
@receiver.instance_eval(*@args)
eval(@code)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion mrblib/mitamae/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MItamae
VERSION = '1.12.0'
VERSION = '1.12.7'
end
7 changes: 7 additions & 0 deletions spec/integration/color_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe 'no-color' do
it 'is appliable' do
expect { apply_recipe('color', options: %w[--no-color], redirect: { out: "/tmp/color-result-file" }) }.to_not raise_error
end
end
20 changes: 20 additions & 0 deletions spec/integration/namespace_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'spec_helper'

describe 'namespace' do
before(:all) do
apply_recipe('namespace')
end

describe file('/tmp/toplevel_module') do
it { should exist }
it { should be_file }
its(:content) { should eq 'helper' }
end

describe file('/tmp/instance_variables') do
it { should exist }
it { should be_file }
# @recipe is for backward compatibility. @variables should not be defined.
its(:content) { should eq '[:@recipe, :@variables]' }
end
end
1 change: 1 addition & 0 deletions spec/recipes/color.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
execute("echo -n Hello")
6 changes: 6 additions & 0 deletions spec/recipes/namespace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include_recipe 'toplevel_module'
file '/tmp/toplevel_module' do
content ToplevelModule.helper
end

include_recipe 'variables'
6 changes: 6 additions & 0 deletions spec/recipes/toplevel_module.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Testing you don't need to write `module ::ToplevelModule`
module ToplevelModule
def self.helper
'helper'
end
end
15 changes: 15 additions & 0 deletions spec/recipes/variables.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node.reverse_merge!(
variables: {
# #binding is not supported in mruby
# lvars: binding.local_variables,
ivars: instance_variables.sort,
}
)

# file '/tmp/local_variables' do
# content node[:variables][:lvars].to_s
# end

file '/tmp/instance_variables' do
content node[:variables][:ivars].to_s
end

0 comments on commit 9451f82

Please sign in to comment.