Use Rake DSL instead of commands of FileUtils

- Respect `--verbose(-v)` and `--dry-run(-n)` options.
- Silence warnings to keyword arguments on Ruby 2.7.
This commit is contained in:
KOBAYASHI Shuji
2019-12-27 16:49:32 +09:00
parent ef6805f599
commit 26e6e75ba6
12 changed files with 27 additions and 28 deletions
+6 -7
View File
@@ -33,10 +33,9 @@ load "#{MRUBY_ROOT}/tasks/gitlab.rake"
load "#{MRUBY_ROOT}/tasks/doc.rake" load "#{MRUBY_ROOT}/tasks/doc.rake"
def install_D(src, dst) def install_D(src, dst)
opts = { :verbose => $verbose } rm_f dst
FileUtils.rm_f dst, opts mkdir_p File.dirname(dst)
FileUtils.mkdir_p File.dirname(dst), opts cp src, dst
FileUtils.cp src, dst, opts
end end
############################## ##############################
@@ -144,16 +143,16 @@ end
desc "clean all built and in-repo installed artifacts" desc "clean all built and in-repo installed artifacts"
task :clean do task :clean do
MRuby.each_target do |t| MRuby.each_target do |t|
FileUtils.rm_rf t.build_dir, { :verbose => $verbose } rm_rf t.build_dir
end end
FileUtils.rm_f depfiles, { :verbose => $verbose } rm_f depfiles
puts "Cleaned up target build folder" puts "Cleaned up target build folder"
end end
desc "clean everything!" desc "clean everything!"
task :deep_clean => ["clean", "clean_doc"] do task :deep_clean => ["clean", "clean_doc"] do
MRuby.each_target do |t| MRuby.each_target do |t|
FileUtils.rm_rf t.gem_clone_dir, { :verbose => $verbose } rm_rf t.gem_clone_dir
end end
puts "Cleaned up mrbgems build folder" puts "Cleaned up mrbgems build folder"
end end
+1 -1
View File
@@ -173,7 +173,7 @@ module MRuby
obj = objfile(cxx_src) if obj.nil? obj = objfile(cxx_src) if obj.nil?
file cxx_src => [src, __FILE__] do |t| file cxx_src => [src, __FILE__] do |t|
FileUtils.mkdir_p File.dirname t.name mkdir_p File.dirname t.name
IO.write t.name, <<EOS IO.write t.name, <<EOS
#define __STDC_CONSTANT_MACROS #define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS
+5 -5
View File
@@ -89,7 +89,7 @@ module MRuby
end end
def run(outfile, infile, _defines=[], _include_paths=[], _flags=[]) def run(outfile, infile, _defines=[], _include_paths=[], _flags=[])
FileUtils.mkdir_p File.dirname(outfile) mkdir_p File.dirname(outfile)
_pp "CC", infile.relative_path, outfile.relative_path _pp "CC", infile.relative_path, outfile.relative_path
if MRUBY_BUILD_HOST_IS_CYGWIN if MRUBY_BUILD_HOST_IS_CYGWIN
_run compile_options, { :flags => all_flags(_defines, _include_paths, _flags), _run compile_options, { :flags => all_flags(_defines, _include_paths, _flags),
@@ -205,7 +205,7 @@ module MRuby
end end
def run(outfile, objfiles, _libraries=[], _library_paths=[], _flags=[], _flags_before_libraries=[], _flags_after_libraries=[]) def run(outfile, objfiles, _libraries=[], _library_paths=[], _flags=[], _flags_before_libraries=[], _flags_after_libraries=[])
FileUtils.mkdir_p File.dirname(outfile) mkdir_p File.dirname(outfile)
library_flags = [libraries, _libraries].flatten.map { |d| option_library % d } library_flags = [libraries, _libraries].flatten.map { |d| option_library % d }
_pp "LD", outfile.relative_path _pp "LD", outfile.relative_path
@@ -235,7 +235,7 @@ module MRuby
end end
def run(outfile, objfiles) def run(outfile, objfiles)
FileUtils.mkdir_p File.dirname(outfile) mkdir_p File.dirname(outfile)
_pp "AR", outfile.relative_path _pp "AR", outfile.relative_path
if MRUBY_BUILD_HOST_IS_CYGWIN if MRUBY_BUILD_HOST_IS_CYGWIN
_run archive_options, { :outfile => cygwin_filename(outfile), :objs => cygwin_filename(objfiles).join(' ') } _run archive_options, { :outfile => cygwin_filename(outfile), :objs => cygwin_filename(objfiles).join(' ') }
@@ -255,7 +255,7 @@ module MRuby
end end
def run(outfile, infile) def run(outfile, infile)
FileUtils.mkdir_p File.dirname(outfile) mkdir_p File.dirname(outfile)
_pp "YACC", infile.relative_path, outfile.relative_path _pp "YACC", infile.relative_path, outfile.relative_path
_run compile_options, { :outfile => filename(outfile) , :infile => filename(infile) } _run compile_options, { :outfile => filename(outfile) , :infile => filename(infile) }
end end
@@ -271,7 +271,7 @@ module MRuby
end end
def run(outfile, infile) def run(outfile, infile)
FileUtils.mkdir_p File.dirname(outfile) mkdir_p File.dirname(outfile)
_pp "GPERF", infile.relative_path, outfile.relative_path _pp "GPERF", infile.relative_path, outfile.relative_path
_run compile_options, { :outfile => filename(outfile) , :infile => filename(infile) } _run compile_options, { :outfile => filename(outfile) , :infile => filename(infile) }
end end
+2 -2
View File
@@ -57,7 +57,7 @@ module MRuby
if File.exist? mgem_list_dir if File.exist? mgem_list_dir
git.run_pull mgem_list_dir, mgem_list_url if $pull_gems git.run_pull mgem_list_dir, mgem_list_url if $pull_gems
else else
FileUtils.mkdir_p mgem_list_dir mkdir_p mgem_list_dir
git.run_clone mgem_list_dir, mgem_list_url, "--depth 1" git.run_clone mgem_list_dir, mgem_list_url, "--depth 1"
end end
@@ -99,7 +99,7 @@ module MRuby
options << "--recursive" options << "--recursive"
options << "--branch \"#{branch}\"" options << "--branch \"#{branch}\""
options << "--depth 1" unless params[:checksum_hash] options << "--depth 1" unless params[:checksum_hash]
FileUtils.mkdir_p "#{gem_clone_dir}" mkdir_p "#{gem_clone_dir}"
git.run_clone gemdir, url, options git.run_clone gemdir, url, options
# Jump to the specified commit # Jump to the specified commit
+1 -1
View File
@@ -157,7 +157,7 @@ module MRuby
def define_gem_init_builder def define_gem_init_builder
file objfile("#{build_dir}/gem_init") => [ "#{build_dir}/gem_init.c", File.join(dir, "mrbgem.rake") ] file objfile("#{build_dir}/gem_init") => [ "#{build_dir}/gem_init.c", File.join(dir, "mrbgem.rake") ]
file "#{build_dir}/gem_init.c" => [build.mrbcfile, __FILE__] + [rbfiles].flatten do |t| file "#{build_dir}/gem_init.c" => [build.mrbcfile, __FILE__] + [rbfiles].flatten do |t|
FileUtils.mkdir_p build_dir mkdir_p build_dir
generate_gem_init("#{build_dir}/gem_init.c") generate_gem_init("#{build_dir}/gem_init.c")
end end
end end
+1 -1
View File
@@ -17,7 +17,7 @@ unless MRuby::Build.current.kind_of?(MRuby::CrossBuild)
}] }]
tmplt = File.read(tmplt_path) tmplt = File.read(tmplt_path)
File.write(t.name, tmplt.gsub(/(#{Regexp.union(*config.keys)})\b/, config)) File.write(t.name, tmplt.gsub(/(#{Regexp.union(*config.keys)})\b/, config))
FileUtils.chmod(0755, t.name) chmod(0755, t.name)
end end
end end
end end
+1 -1
View File
@@ -26,7 +26,7 @@ MRuby::Gem::Specification.new 'mruby-compiler' do |spec|
# Parser # Parser
file "#{current_build_dir}/core/y.tab.c" => ["#{current_dir}/core/parse.y", lex_def] do |t| file "#{current_build_dir}/core/y.tab.c" => ["#{current_dir}/core/parse.y", lex_def] do |t|
FileUtils.mkdir_p File.dirname t.name mkdir_p File.dirname t.name
yacc.run t.name, t.prerequisites.first yacc.run t.name, t.prerequisites.first
end end
+4 -4
View File
@@ -40,7 +40,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec|
file test_rbobj => g.test_rbireps file test_rbobj => g.test_rbireps
file g.test_rbireps => [g.test_rbfiles, build.mrbcfile].flatten do |t| file g.test_rbireps => [g.test_rbfiles, build.mrbcfile].flatten do |t|
FileUtils.mkdir_p File.dirname(t.name) mkdir_p File.dirname(t.name)
open(t.name, 'w') do |f| open(t.name, 'w') do |f|
g.print_gem_test_header(f) g.print_gem_test_header(f)
test_preload = g.test_preload and [g.dir, MRUBY_ROOT].map {|dir| test_preload = g.test_preload and [g.dir, MRUBY_ROOT].map {|dir|
@@ -152,12 +152,12 @@ MRuby::Gem::Specification.new('mruby-test') do |spec|
active_gem_list = if File.exist? active_gems_path active_gem_list = if File.exist? active_gems_path
File.read active_gems_path File.read active_gems_path
else else
FileUtils.mkdir_p File.dirname(active_gems_path) mkdir_p File.dirname(active_gems_path)
nil nil
end end
current_gem_list = build.gems.map(&:name).join("\n") current_gem_list = build.gems.map(&:name).join("\n")
task active_gems_path do |_t| task active_gems_path do |_t|
FileUtils.mkdir_p File.dirname(active_gems_path) mkdir_p File.dirname(active_gems_path)
File.write active_gems_path, current_gem_list File.write active_gems_path, current_gem_list
end end
file clib => active_gems_path if active_gem_list != current_gem_list file clib => active_gems_path if active_gem_list != current_gem_list
@@ -165,7 +165,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec|
file mlib => clib file mlib => clib
file clib => [build.mrbcfile, __FILE__] do |_t| file clib => [build.mrbcfile, __FILE__] do |_t|
_pp "GEN", "*.rb", "#{clib.relative_path}" _pp "GEN", "*.rb", "#{clib.relative_path}"
FileUtils.mkdir_p File.dirname(clib) mkdir_p File.dirname(clib)
open(clib, 'w') do |f| open(clib, 'w') do |f|
f.puts %Q[/*] f.puts %Q[/*]
f.puts %Q[ * This file contains a list of all] f.puts %Q[ * This file contains a list of all]
+1 -1
View File
@@ -8,7 +8,7 @@ MRuby.each_target do
file objfile("#{current_build_dir}/mrblib") => "#{current_build_dir}/mrblib.c" file objfile("#{current_build_dir}/mrblib") => "#{current_build_dir}/mrblib.c"
file "#{current_build_dir}/mrblib.c" => [mrbcfile, __FILE__] + Dir.glob("#{current_dir}/*.rb").sort do |t| file "#{current_build_dir}/mrblib.c" => [mrbcfile, __FILE__] + Dir.glob("#{current_dir}/*.rb").sort do |t|
_, _, *rbfiles = t.prerequisites _, _, *rbfiles = t.prerequisites
FileUtils.mkdir_p File.dirname(t.name) mkdir_p File.dirname(t.name)
open(t.name, 'w') do |f| open(t.name, 'w') do |f|
_pp "GEN", "*.rb", "#{t.name.relative_path}" _pp "GEN", "*.rb", "#{t.name.relative_path}"
f.puts File.read("#{current_dir}/init_mrblib.c") f.puts File.read("#{current_dir}/init_mrblib.c")
+2 -2
View File
@@ -25,12 +25,12 @@ end
desc 'clean all built docs' desc 'clean all built docs'
task :clean_api_doc do task :clean_api_doc do
FileUtils.rm_rf 'doc/api' rm_rf 'doc/api'
end end
desc 'clean all built docs' desc 'clean all built docs'
task :clean_capi_doc do task :clean_capi_doc do
FileUtils.rm_rf 'doc/capi' rm_rf 'doc/capi'
end end
desc 'clean all built docs' desc 'clean all built docs'
+1 -1
View File
@@ -4,7 +4,7 @@ MRuby.each_target do
end end
file "#{build_dir}/lib/libmruby.flags.mak" => [__FILE__, libmruby_static] do |t| file "#{build_dir}/lib/libmruby.flags.mak" => [__FILE__, libmruby_static] do |t|
FileUtils.mkdir_p File.dirname t.name mkdir_p File.dirname t.name
open(t.name, 'w') do |f| open(t.name, 'w') do |f|
f.puts "MRUBY_CFLAGS = #{cc.all_flags}" f.puts "MRUBY_CFLAGS = #{cc.all_flags}"
+2 -2
View File
@@ -8,7 +8,7 @@ MRuby.each_target do
self.libmruby_objs << objfile("#{build_dir}/mrbgems/gem_init") self.libmruby_objs << objfile("#{build_dir}/mrbgems/gem_init")
file objfile("#{build_dir}/mrbgems/gem_init") => ["#{build_dir}/mrbgems/gem_init.c", "#{build_dir}/LEGAL"] file objfile("#{build_dir}/mrbgems/gem_init") => ["#{build_dir}/mrbgems/gem_init.c", "#{build_dir}/LEGAL"]
file "#{build_dir}/mrbgems/gem_init.c" => [MRUBY_CONFIG, __FILE__] do |t| file "#{build_dir}/mrbgems/gem_init.c" => [MRUBY_CONFIG, __FILE__] do |t|
FileUtils.mkdir_p "#{build_dir}/mrbgems" mkdir_p "#{build_dir}/mrbgems"
open(t.name, 'w') do |f| open(t.name, 'w') do |f|
gem_func_gems = gems.select { |g| g.generate_functions } gem_func_gems = gems.select { |g| g.generate_functions }
gem_func_decls = gem_func_gems.each_with_object('') do |g, s| gem_func_decls = gem_func_gems.each_with_object('') do |g, s|
@@ -53,7 +53,7 @@ MRuby.each_target do
# legal documents # legal documents
file "#{build_dir}/LEGAL" => [MRUBY_CONFIG, __FILE__] do |t| file "#{build_dir}/LEGAL" => [MRUBY_CONFIG, __FILE__] do |t|
FileUtils.mkdir_p File.dirname t.name mkdir_p File.dirname t.name
open(t.name, 'w+') do |f| open(t.name, 'w+') do |f|
f.puts <<LEGAL f.puts <<LEGAL
Copyright (c) #{Time.now.year} mruby developers Copyright (c) #{Time.now.year} mruby developers