Copy header files to the build directory

This is so that the build directory can be regarded as a temporary installation directory to work in.

Directories set in `MRuby::Gem::Specification#export_include_paths` are used as they are if they are subdirectories placed under `gem.dir`.
Files are placed under `<build-dir>/include/mruby/gems/<gem-name>/<gem-include_paths>` to separate each GEM.

When GEM is compiled by building `libmruby.a`, the same `include_paths` will be set as before, so it is expected that no unintended references will be made.
This commit is contained in:
dearblue
2023-02-12 21:02:28 +09:00
parent c020d8507e
commit aac2fd7055
4 changed files with 73 additions and 0 deletions
+15
View File
@@ -1,6 +1,7 @@
require "mruby/core_ext"
require "mruby/build/load_gems"
require "mruby/build/command"
autoload :Find, "find"
module MRuby
autoload :Gem, "mruby/gem"
@@ -487,6 +488,20 @@ EOS
@internal
end
def each_header_files(&block)
return to_enum(__method__) unless block
basedir = File.join(MRUBY_ROOT, "include")
Find.find(basedir) do |d|
next unless File.file? d
yield d
end
@gems.each { |g| g.each_header_files(&block) }
self
end
protected
attr_writer :presym
+21
View File
@@ -22,6 +22,27 @@ class String
def remove_leading_parents
Pathname.new(".#{Pathname.new("/#{self}").cleanpath}").cleanpath.to_s
end
def replace_prefix_by(dirmap)
[self].replace_prefix_by(dirmap)[0]
end
end
class Array
# Replace the prefix of each string that is a file path that contains in its own array.
#
# dirmap is a hash whose elements are `{ "path/to/old-prefix" => "path/to/new-prefix", ... }`.
# If it does not match any element of dirmap, the file path is not replaced.
def replace_prefix_by(dirmap)
dirmap = dirmap.map { |older, newer| [File.join(older, "/"), File.join(newer, "/")] }
dirmap.sort!
dirmap.reverse!
self.flatten.map do |e|
map = dirmap.find { |older, newer| e.start_with?(older) }
e = e.sub(map[0], map[1]) if map
e
end
end
end
def install_D(src, dst)
+13
View File
@@ -292,6 +292,19 @@ module MRuby
end
end.all?
end
def each_header_files(&block)
return to_enum(__method__) unless block
self.export_include_paths.flatten.uniq.compact.each do |dir|
Find.find(dir) do |d|
next unless File.file? d
yield d
end
end
self
end
end # Specification
class Version