mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
e0d2f4e0ae
If the current directory is different from `MRUBY_ROOT` and it has` conf.build_dir` and `conf.enable_cxx_exception` set, it was generating a pathname outside of` build_dir`.
As a result, in some cases files unrelated to mruby could be linked.
```console
% pwd
/tmp/mruby/1/2/3/4/5/6
% mruby_dir=/tmp/mruby/a/b/c/d/mruby
% cat my_config.rb
MRuby::Build.new("host", "build/to/custom/directory") do
toolchain
enable_cxx_exception
end
% rake MRUBY_CONFIG=my_config.rb -f $mruby_dir/Rakefile > logs
% grep CXX logs
CXX a/b/c/d/mruby/src/error-cxx.cxx -> a/b/c/d/mruby/src/error-cxx.o
CXX a/b/c/d/mruby/src/gc-cxx.cxx -> a/b/c/d/mruby/src/gc-cxx.o
CXX a/b/c/d/mruby/src/vm-cxx.cxx -> a/b/c/d/mruby/src/vm-cxx.o
CXX a/b/c/d/mruby/mrbgems/mruby-compiler/core/codegen-cxx.cxx -> a/b/c/d/mruby/mrbgems/mruby-compiler/core/codegen-cxx.o
CXX a/b/c/d/mruby/mrbgems/mruby-compiler/core/y.tab-cxx.cxx -> a/b/c/d/mruby/mrbgems/mruby-compiler/core/y.tab-cxx.o
CXX ../a/b/c/d/mruby/src/error-cxx.cxx -> ../a/b/c/d/mruby/src/error-cxx.o
CXX ../a/b/c/d/mruby/src/gc-cxx.cxx -> ../a/b/c/d/mruby/src/gc-cxx.o
CXX ../a/b/c/d/mruby/src/vm-cxx.cxx -> ../a/b/c/d/mruby/src/vm-cxx.o
```
41 lines
925 B
Ruby
41 lines
925 B
Ruby
autoload :Pathname, 'pathname'
|
|
|
|
class Object
|
|
class << self
|
|
def attr_block(*syms)
|
|
syms.flatten.each do |sym|
|
|
class_eval "def #{sym}(&block);block.call(@#{sym}) if block_given?;@#{sym};end"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
class String
|
|
def relative_path_from(dir)
|
|
Pathname.new(File.expand_path(self)).relative_path_from(Pathname.new(File.expand_path(dir))).to_s
|
|
end
|
|
|
|
def relative_path
|
|
relative_path_from(Dir.pwd)
|
|
end
|
|
|
|
def remove_leading_parents
|
|
Pathname.new(".#{Pathname.new("/#{self}").cleanpath}").cleanpath.to_s
|
|
end
|
|
end
|
|
|
|
def install_D(src, dst)
|
|
_pp "INSTALL", src.relative_path, dst.relative_path
|
|
rm_f dst
|
|
mkdir_p File.dirname(dst)
|
|
cp src, dst
|
|
end
|
|
|
|
def _pp(cmd, src, tgt=nil, indent: nil)
|
|
return if Rake.application.options.silent
|
|
|
|
width = 5
|
|
template = indent ? "%#{width * indent}s %s %s" : "%-#{width}s %s %s"
|
|
puts template % [cmd, src, tgt ? "-> #{tgt}" : nil]
|
|
end
|