mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #5928 from dearblue/task/install
Improved `rake install`
This commit is contained in:
+52
-3
@@ -1,12 +1,16 @@
|
||||
require "mruby/core_ext"
|
||||
require "mruby/build/load_gems"
|
||||
require "mruby/build/command"
|
||||
autoload :Find, "find"
|
||||
|
||||
module MRuby
|
||||
autoload :Gem, "mruby/gem"
|
||||
autoload :Lockfile, "mruby/lockfile"
|
||||
autoload :Presym, "mruby/presym"
|
||||
|
||||
INSTALL_PREFIX = ENV['PREFIX'] || ENV['INSTALL_PREFIX'] || '/usr/local'
|
||||
INSTALL_DESTDIR = ENV['DESTDIR'] || ''
|
||||
|
||||
class << self
|
||||
def targets
|
||||
@targets ||= {}
|
||||
@@ -97,6 +101,7 @@ module MRuby
|
||||
@file_separator = '/'
|
||||
@build_dir = "#{build_dir}/#{@name}"
|
||||
@gem_clone_dir = "#{build_dir}/repos/#{@name}"
|
||||
@install_prefix = nil
|
||||
@defines = []
|
||||
@cc = Command::Compiler.new(self, %w(.c), label: "CC")
|
||||
@cxx = Command::Compiler.new(self, %w(.cc .cxx .cpp), label: "CXX")
|
||||
@@ -370,14 +375,35 @@ EOS
|
||||
end
|
||||
end
|
||||
|
||||
def define_installer(src)
|
||||
dst = "#{self.class.install_dir}/#{File.basename(src)}"
|
||||
def define_installer_outline(src, dst)
|
||||
file dst => src do
|
||||
install_D src, dst
|
||||
_pp "GEN", src.relative_path, dst.relative_path
|
||||
mkdir_p(File.dirname(dst))
|
||||
yield dst
|
||||
end
|
||||
dst
|
||||
end
|
||||
|
||||
if ENV['OS'] == 'Windows_NT'
|
||||
def define_installer(src)
|
||||
dst = "#{self.class.install_dir}/#{File.basename(src)}".pathmap("%X.bat")
|
||||
define_installer_outline(src, dst) do
|
||||
File.write dst, <<~BATCHFILE
|
||||
@echo off
|
||||
call "#{src}" %*
|
||||
BATCHFILE
|
||||
end
|
||||
end
|
||||
else
|
||||
def define_installer(src)
|
||||
dst = "#{self.class.install_dir}/#{File.basename(src)}"
|
||||
define_installer_outline(src, dst) do
|
||||
File.unlink(dst) if File.exist?(dst)
|
||||
File.symlink(src, dst)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def define_installer_if_needed(bin)
|
||||
exe = exefile("#{build_dir}/bin/#{bin}")
|
||||
host? ? define_installer(exe) : exe
|
||||
@@ -485,6 +511,29 @@ 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
|
||||
|
||||
def install_prefix
|
||||
@install_prefix || (self.name == "host" ? MRuby::INSTALL_PREFIX :
|
||||
File.join(MRuby::INSTALL_PREFIX, "mruby/#{self.name}"))
|
||||
end
|
||||
|
||||
def install_prefix=(dir)
|
||||
@install_prefix = dir&.to_s
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
attr_writer :presym
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -284,6 +284,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
|
||||
|
||||
Reference in New Issue
Block a user