diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-11-26 19:08:56 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-11-26 21:49:42 +0900 |
commit | 7db719c51652f0de6cae079c6ce0723dd00a9939 (patch) | |
tree | 49068885d9f173347c20afc65b3f58f01cccee4c | |
parent | 8b208293963cafa1469947a9957b59ce68895af1 (diff) | |
download | ruby-7db719c51652f0de6cae079c6ce0723dd00a9939.tar.gz |
Write rbinc files to the source directory
Update the target file itself of the dependency on this script.
Fall back to the current working directory if unwritable.
-rw-r--r-- | tool/mk_builtin_loader.rb | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/tool/mk_builtin_loader.rb b/tool/mk_builtin_loader.rb index efb2d7d0fb..87eb042145 100644 --- a/tool/mk_builtin_loader.rb +++ b/tool/mk_builtin_loader.rb @@ -57,12 +57,18 @@ end def mk_builtin_header file base = File.basename(file, '.rb') - ofile = "#{base}.rbinc" + ofile = "#{file}inc" # bs = { func_name => argc } collect_builtin(base, RubyVM::InstructionSequence.compile_file(file, false).to_a, bs = {}, inlines = []) - open(ofile, 'w'){|f| + begin + f = open(ofile, 'w') + rescue Errno::EACCESS + # Fall back to the current directory + f = open(File.basename(ofile), 'w') + end + begin f.puts "// -*- c -*-" f.puts "// DO NOT MODIFY THIS FILE DIRECTLY." f.puts "// auto-generated file" @@ -120,7 +126,9 @@ def mk_builtin_header file f.puts " rb_load_with_builtin_functions(#{base.dump}, #{table});" f.puts "}" - } + ensure + f.close + end end ARGV.each{|file| |