Skip to content

Commit bf1fc6e

Browse files
author
Zachary Scott
authored
Merge pull request #49 from tagomoris/fix-rakefile
Not to chdir globally
2 parents 53feb91 + 3055db5 commit bf1fc6e

File tree

2 files changed

+98
-82
lines changed

2 files changed

+98
-82
lines changed

Rakefile

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ mruby_config=File.expand_path(ENV["MRUBY_CONFIG"] || "build_config.rb")
1616
ENV['MRUBY_ROOT'] = mruby_root
1717
ENV['MRUBY_CONFIG'] = mruby_config
1818
Rake::Task[:mruby].invoke unless Dir.exist?(mruby_root)
19-
Dir.chdir(mruby_root)
2019
load "#{mruby_root}/Rakefile"
2120

2221
load File.join(File.expand_path(File.dirname(__FILE__)), "mrbgem.rake")
@@ -27,25 +26,29 @@ APP_VERSION = (app_version.nil? || app_version.empty?) ? "unknown" : app_version
2726

2827
desc "compile all the binaries"
2928
task :compile => [:all] do
30-
MRuby.each_target do |target|
31-
`#{target.cc.command} --version`
32-
abort("Command #{target.cc.command} for #{target.name} is missing.") unless $?.success?
33-
end
34-
%W(#{mruby_root}/build/x86_64-pc-linux-gnu/bin/#{APP_NAME} #{mruby_root}/build/i686-pc-linux-gnu/#{APP_NAME}").each do |bin|
35-
sh "strip --strip-unneeded #{bin}" if File.exist?(bin)
29+
Dir.chdir(mruby_root) do
30+
MRuby.each_target do |target|
31+
`#{target.cc.command} --version`
32+
abort("Command #{target.cc.command} for #{target.name} is missing.") unless $?.success?
33+
end
34+
%W(#{mruby_root}/build/x86_64-pc-linux-gnu/bin/#{APP_NAME} #{mruby_root}/build/i686-pc-linux-gnu/#{APP_NAME}).each do |bin|
35+
sh "strip --strip-unneeded #{bin}" if File.exist?(bin)
36+
end
3637
end
3738
end
3839

3940
namespace :test do
4041
desc "run mruby & unit tests"
4142
# only build mtest for host
4243
task :mtest => :compile do
43-
# in order to get mruby/test/t/synatx.rb __FILE__ to pass,
44-
# we need to make sure the tests are built relative from mruby_root
45-
MRuby.each_target do |target|
46-
# only run unit tests here
47-
target.enable_bintest = false
48-
run_test if target.test_enabled?
44+
Dir.chdir(mruby_root) do
45+
# in order to get mruby/test/t/synatx.rb __FILE__ to pass,
46+
# we need to make sure the tests are built relative from mruby_root
47+
MRuby.each_target do |target|
48+
# only run unit tests here
49+
target.enable_bintest = false
50+
run_test if target.test_enabled?
51+
end
4952
end
5053
end
5154

@@ -63,9 +66,11 @@ namespace :test do
6366

6467
desc "run integration tests"
6568
task :bintest => :compile do
66-
MRuby.each_target do |target|
67-
clean_env(%w(MRUBY_ROOT MRUBY_CONFIG)) do
68-
run_bintest if target.bintest_enabled?
69+
Dir.chdir(mruby_root) do
70+
MRuby.each_target do |target|
71+
clean_env(%w(MRUBY_ROOT MRUBY_CONFIG)) do
72+
run_bintest if target.bintest_enabled?
73+
end
6974
end
7075
end
7176
end
@@ -77,38 +82,42 @@ task :test => ['test:bintest', 'test:mtest']
7782

7883
desc "cleanup"
7984
task :clean do
80-
sh "rake deep_clean"
85+
Dir.chdir(mruby_root) do
86+
sh "rake deep_clean"
87+
end
8188
end
8289

8390
desc "generate a release tarball"
8491
task :release => :compile do
8592
require 'tmpdir'
8693

87-
# since we're in the mruby/
88-
release_dir = "releases/v#{APP_VERSION}"
89-
release_path = Dir.pwd + "/../#{release_dir}"
90-
app_name = "#{APP_NAME}-#{APP_VERSION}"
91-
FileUtils.mkdir_p(release_path)
92-
93-
Dir.mktmpdir do |tmp_dir|
94-
Dir.chdir(tmp_dir) do
95-
MRuby.each_target do |target|
96-
next if name == "host"
97-
98-
arch = name
99-
bin = "#{build_dir}/bin/#{exefile(APP_NAME)}"
100-
FileUtils.mkdir_p(name)
101-
FileUtils.cp(bin, name)
102-
103-
Dir.chdir(arch) do
104-
arch_release = "#{app_name}-#{arch}"
105-
puts "Writing #{release_dir}/#{arch_release}.tgz"
106-
`tar czf #{release_path}/#{arch_release}.tgz *`
94+
Dir.chdir(mruby_root) do
95+
# since we're in the mruby/
96+
release_dir = "releases/v#{APP_VERSION}"
97+
release_path = Dir.pwd + "/../#{release_dir}"
98+
app_name = "#{APP_NAME}-#{APP_VERSION}"
99+
FileUtils.mkdir_p(release_path)
100+
101+
Dir.mktmpdir do |tmp_dir|
102+
Dir.chdir(tmp_dir) do
103+
MRuby.each_target do |target|
104+
next if name == "host"
105+
106+
arch = name
107+
bin = "#{build_dir}/bin/#{exefile(APP_NAME)}"
108+
FileUtils.mkdir_p(name)
109+
FileUtils.cp(bin, name)
110+
111+
Dir.chdir(arch) do
112+
arch_release = "#{app_name}-#{arch}"
113+
puts "Writing #{release_dir}/#{arch_release}.tgz"
114+
`tar czf #{release_path}/#{arch_release}.tgz *`
115+
end
107116
end
108-
end
109117

110-
puts "Writing #{release_dir}/#{app_name}.tgz"
111-
`tar czf #{release_path}/#{app_name}.tgz *`
118+
puts "Writing #{release_dir}/#{app_name}.tgz"
119+
`tar czf #{release_path}/#{app_name}.tgz *`
120+
end
112121
end
113122
end
114123
end

mrblib/mruby-cli/setup.rb

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,8 @@ def rakefile
330330
ENV['MRUBY_ROOT'] = mruby_root
331331
ENV['MRUBY_CONFIG'] = mruby_config
332332
Rake::Task[:mruby].invoke unless Dir.exist?(mruby_root)
333-
Dir.chdir(mruby_root)
334333
load "\#{mruby_root}/Rakefile"
335334
336-
337335
load File.join(File.expand_path(File.dirname(__FILE__)), "mrbgem.rake")
338336
339337
current_gem = MRuby::Gem.current
@@ -342,26 +340,29 @@ def rakefile
342340
343341
desc "compile binary"
344342
task :compile => [:all] do
345-
346-
MRuby.each_target do |target|
347-
`\#{target.cc.command} --version`
348-
abort("Command \#{target.cc.command} for \#{target.name} is missing.") unless $?.success?
349-
end
350-
%W(\#{mruby_root}/build/x86_64-pc-linux-gnu/bin/\#{APP_NAME} \#{mruby_root}/build/i686-pc-linux-gnu/\#{APP_NAME}).each do |bin|
351-
sh "strip --strip-unneeded \#{bin}" if File.exist?(bin)
343+
Dir.chdir(mruby_root) do
344+
MRuby.each_target do |target|
345+
`\#{target.cc.command} --version`
346+
abort("Command \#{target.cc.command} for \#{target.name} is missing.") unless $?.success?
347+
end
348+
%W(\#{mruby_root}/build/x86_64-pc-linux-gnu/bin/\#{APP_NAME} \#{mruby_root}/build/i686-pc-linux-gnu/\#{APP_NAME}).each do |bin|
349+
sh "strip --strip-unneeded \#{bin}" if File.exist?(bin)
350+
end
352351
end
353352
end
354353
355354
namespace :test do
356355
desc "run mruby & unit tests"
357356
# only build mtest for host
358357
task :mtest => :compile do
359-
# in order to get mruby/test/t/synatx.rb __FILE__ to pass,
360-
# we need to make sure the tests are built relative from mruby_root
361-
MRuby.each_target do |target|
362-
# only run unit tests here
363-
target.enable_bintest = false
364-
run_test if target.test_enabled?
358+
Dir.chdir(mruby_root) do
359+
# in order to get mruby/test/t/synatx.rb __FILE__ to pass,
360+
# we need to make sure the tests are built relative from mruby_root
361+
MRuby.each_target do |target|
362+
# only run unit tests here
363+
target.enable_bintest = false
364+
run_test if target.test_enabled?
365+
end
365366
end
366367
end
367368
@@ -379,9 +380,11 @@ def clean_env(envs)
379380
380381
desc "run integration tests"
381382
task :bintest => :compile do
382-
MRuby.each_target do |target|
383-
clean_env(%w(MRUBY_ROOT MRUBY_CONFIG)) do
384-
run_bintest if target.bintest_enabled?
383+
Dir.chdir(mruby_root) do
384+
MRuby.each_target do |target|
385+
clean_env(%w(MRUBY_ROOT MRUBY_CONFIG)) do
386+
run_bintest if target.bintest_enabled?
387+
end
385388
end
386389
end
387390
end
@@ -393,38 +396,42 @@ def clean_env(envs)
393396
394397
desc "cleanup"
395398
task :clean do
396-
sh "rake deep_clean"
399+
Dir.chdir(mruby_root) do
400+
sh "rake deep_clean"
401+
end
397402
end
398403
399404
desc "generate a release tarball"
400405
task :release => :compile do
401406
require 'tmpdir'
402407
403-
# since we're in the mruby/
404-
release_dir = "releases/v\#{APP_VERSION}"
405-
release_path = Dir.pwd + "/../\#{release_dir}"
406-
app_name = "\#{APP_NAME}-\#{APP_VERSION}"
407-
FileUtils.mkdir_p(release_path)
408-
409-
Dir.mktmpdir do |tmp_dir|
410-
Dir.chdir(tmp_dir) do
411-
MRuby.each_target do |target|
412-
next if name == "host"
413-
414-
arch = name
415-
bin = "\#{build_dir}/bin/\#{exefile(APP_NAME)}"
416-
FileUtils.mkdir_p(name)
417-
FileUtils.cp(bin, name)
418-
419-
Dir.chdir(arch) do
420-
arch_release = "\#{app_name}-\#{arch}"
421-
puts "Writing \#{release_dir}/\#{arch_release}.tgz"
422-
`tar czf \#{release_path}/\#{arch_release}.tgz *`
408+
Dir.chdir(mruby_root) do
409+
# since we're in the mruby/
410+
release_dir = "releases/v\#{APP_VERSION}"
411+
release_path = Dir.pwd + "/../\#{release_dir}"
412+
app_name = "\#{APP_NAME}-\#{APP_VERSION}"
413+
FileUtils.mkdir_p(release_path)
414+
415+
Dir.mktmpdir do |tmp_dir|
416+
Dir.chdir(tmp_dir) do
417+
MRuby.each_target do |target|
418+
next if name == "host"
419+
420+
arch = name
421+
bin = "\#{build_dir}/bin/\#{exefile(APP_NAME)}"
422+
FileUtils.mkdir_p(name)
423+
FileUtils.cp(bin, name)
424+
425+
Dir.chdir(arch) do
426+
arch_release = "\#{app_name}-\#{arch}"
427+
puts "Writing \#{release_dir}/\#{arch_release}.tgz"
428+
`tar czf \#{release_path}/\#{arch_release}.tgz *`
429+
end
423430
end
424-
end
425431
426-
puts "Writing \#{release_dir}/\#{app_name}.tgz"
427-
`tar czf \#{release_path}/\#{app_name}.tgz *`
432+
puts "Writing \#{release_dir}/\#{app_name}.tgz"
433+
`tar czf \#{release_path}/\#{app_name}.tgz *`
434+
end
428435
end
429436
end
430437
end

0 commit comments

Comments
 (0)