Skip to content

Don't chdir globally #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 49 additions & 40 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ mruby_config=File.expand_path(ENV["MRUBY_CONFIG"] || "build_config.rb")
ENV['MRUBY_ROOT'] = mruby_root
ENV['MRUBY_CONFIG'] = mruby_config
Rake::Task[:mruby].invoke unless Dir.exist?(mruby_root)
Dir.chdir(mruby_root)
load "#{mruby_root}/Rakefile"

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

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

namespace :test do
desc "run mruby & unit tests"
# only build mtest for host
task :mtest => :compile do
# in order to get mruby/test/t/synatx.rb __FILE__ to pass,
# we need to make sure the tests are built relative from mruby_root
MRuby.each_target do |target|
# only run unit tests here
target.enable_bintest = false
run_test if target.test_enabled?
Dir.chdir(mruby_root) do
# in order to get mruby/test/t/synatx.rb __FILE__ to pass,
# we need to make sure the tests are built relative from mruby_root
MRuby.each_target do |target|
# only run unit tests here
target.enable_bintest = false
run_test if target.test_enabled?
end
end
end

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

desc "run integration tests"
task :bintest => :compile do
MRuby.each_target do |target|
clean_env(%w(MRUBY_ROOT MRUBY_CONFIG)) do
run_bintest if target.bintest_enabled?
Dir.chdir(mruby_root) do
MRuby.each_target do |target|
clean_env(%w(MRUBY_ROOT MRUBY_CONFIG)) do
run_bintest if target.bintest_enabled?
end
end
end
end
Expand All @@ -77,38 +82,42 @@ task :test => ['test:bintest', 'test:mtest']

desc "cleanup"
task :clean do
sh "rake deep_clean"
Dir.chdir(mruby_root) do
sh "rake deep_clean"
end
end

desc "generate a release tarball"
task :release => :compile do
require 'tmpdir'

# since we're in the mruby/
release_dir = "releases/v#{APP_VERSION}"
release_path = Dir.pwd + "/../#{release_dir}"
app_name = "#{APP_NAME}-#{APP_VERSION}"
FileUtils.mkdir_p(release_path)

Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir) do
MRuby.each_target do |target|
next if name == "host"

arch = name
bin = "#{build_dir}/bin/#{exefile(APP_NAME)}"
FileUtils.mkdir_p(name)
FileUtils.cp(bin, name)

Dir.chdir(arch) do
arch_release = "#{app_name}-#{arch}"
puts "Writing #{release_dir}/#{arch_release}.tgz"
`tar czf #{release_path}/#{arch_release}.tgz *`
Dir.chdir(mruby_root) do
# since we're in the mruby/
release_dir = "releases/v#{APP_VERSION}"
release_path = Dir.pwd + "/../#{release_dir}"
app_name = "#{APP_NAME}-#{APP_VERSION}"
FileUtils.mkdir_p(release_path)

Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir) do
MRuby.each_target do |target|
next if name == "host"

arch = name
bin = "#{build_dir}/bin/#{exefile(APP_NAME)}"
FileUtils.mkdir_p(name)
FileUtils.cp(bin, name)

Dir.chdir(arch) do
arch_release = "#{app_name}-#{arch}"
puts "Writing #{release_dir}/#{arch_release}.tgz"
`tar czf #{release_path}/#{arch_release}.tgz *`
end
end
end

puts "Writing #{release_dir}/#{app_name}.tgz"
`tar czf #{release_path}/#{app_name}.tgz *`
puts "Writing #{release_dir}/#{app_name}.tgz"
`tar czf #{release_path}/#{app_name}.tgz *`
end
end
end
end
Expand Down
91 changes: 49 additions & 42 deletions mrblib/mruby-cli/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,8 @@ def rakefile
ENV['MRUBY_ROOT'] = mruby_root
ENV['MRUBY_CONFIG'] = mruby_config
Rake::Task[:mruby].invoke unless Dir.exist?(mruby_root)
Dir.chdir(mruby_root)
load "\#{mruby_root}/Rakefile"


load File.join(File.expand_path(File.dirname(__FILE__)), "mrbgem.rake")

current_gem = MRuby::Gem.current
Expand All @@ -342,26 +340,29 @@ def rakefile

desc "compile binary"
task :compile => [:all] do

MRuby.each_target do |target|
`\#{target.cc.command} --version`
abort("Command \#{target.cc.command} for \#{target.name} is missing.") unless $?.success?
end
%W(\#{mruby_root}/build/x86_64-pc-linux-gnu/bin/\#{APP_NAME} \#{mruby_root}/build/i686-pc-linux-gnu/\#{APP_NAME}).each do |bin|
sh "strip --strip-unneeded \#{bin}" if File.exist?(bin)
Dir.chdir(mruby_root) do
MRuby.each_target do |target|
`\#{target.cc.command} --version`
abort("Command \#{target.cc.command} for \#{target.name} is missing.") unless $?.success?
end
%W(\#{mruby_root}/build/x86_64-pc-linux-gnu/bin/\#{APP_NAME} \#{mruby_root}/build/i686-pc-linux-gnu/\#{APP_NAME}).each do |bin|
sh "strip --strip-unneeded \#{bin}" if File.exist?(bin)
end
end
end

namespace :test do
desc "run mruby & unit tests"
# only build mtest for host
task :mtest => :compile do
# in order to get mruby/test/t/synatx.rb __FILE__ to pass,
# we need to make sure the tests are built relative from mruby_root
MRuby.each_target do |target|
# only run unit tests here
target.enable_bintest = false
run_test if target.test_enabled?
Dir.chdir(mruby_root) do
# in order to get mruby/test/t/synatx.rb __FILE__ to pass,
# we need to make sure the tests are built relative from mruby_root
MRuby.each_target do |target|
# only run unit tests here
target.enable_bintest = false
run_test if target.test_enabled?
end
end
end

Expand All @@ -379,9 +380,11 @@ def clean_env(envs)

desc "run integration tests"
task :bintest => :compile do
MRuby.each_target do |target|
clean_env(%w(MRUBY_ROOT MRUBY_CONFIG)) do
run_bintest if target.bintest_enabled?
Dir.chdir(mruby_root) do
MRuby.each_target do |target|
clean_env(%w(MRUBY_ROOT MRUBY_CONFIG)) do
run_bintest if target.bintest_enabled?
end
end
end
end
Expand All @@ -393,38 +396,42 @@ def clean_env(envs)

desc "cleanup"
task :clean do
sh "rake deep_clean"
Dir.chdir(mruby_root) do
sh "rake deep_clean"
end
end

desc "generate a release tarball"
task :release => :compile do
require 'tmpdir'

# since we're in the mruby/
release_dir = "releases/v\#{APP_VERSION}"
release_path = Dir.pwd + "/../\#{release_dir}"
app_name = "\#{APP_NAME}-\#{APP_VERSION}"
FileUtils.mkdir_p(release_path)

Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir) do
MRuby.each_target do |target|
next if name == "host"

arch = name
bin = "\#{build_dir}/bin/\#{exefile(APP_NAME)}"
FileUtils.mkdir_p(name)
FileUtils.cp(bin, name)

Dir.chdir(arch) do
arch_release = "\#{app_name}-\#{arch}"
puts "Writing \#{release_dir}/\#{arch_release}.tgz"
`tar czf \#{release_path}/\#{arch_release}.tgz *`
Dir.chdir(mruby_root) do
# since we're in the mruby/
release_dir = "releases/v\#{APP_VERSION}"
release_path = Dir.pwd + "/../\#{release_dir}"
app_name = "\#{APP_NAME}-\#{APP_VERSION}"
FileUtils.mkdir_p(release_path)

Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir) do
MRuby.each_target do |target|
next if name == "host"

arch = name
bin = "\#{build_dir}/bin/\#{exefile(APP_NAME)}"
FileUtils.mkdir_p(name)
FileUtils.cp(bin, name)

Dir.chdir(arch) do
arch_release = "\#{app_name}-\#{arch}"
puts "Writing \#{release_dir}/\#{arch_release}.tgz"
`tar czf \#{release_path}/\#{arch_release}.tgz *`
end
end
end

puts "Writing \#{release_dir}/\#{app_name}.tgz"
`tar czf \#{release_path}/\#{app_name}.tgz *`
puts "Writing \#{release_dir}/\#{app_name}.tgz"
`tar czf \#{release_path}/\#{app_name}.tgz *`
end
end
end
end
Expand Down