-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
83 lines (74 loc) · 2.95 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
require "rake/extensiontask"
Rake::ExtensionTask.new("boost_distributions") do |ext|
ext.lib_dir = "lib/boost_distributions"
end
namespace :git do
task :version do
@git_version ||= proc{
res = Gem::Version::new(`git --version`.match(/\d+\.\d+\.\d+/)[0])
res.instance_eval{
cmp_orig = self.method(:<=>)
define_singleton_method(:<=>){|arg|
cmp_orig.call(arg.kind_of?(String) ? Gem::Version::new(arg) : arg)
}
}
res
}.call
end
namespace :submodules do
desc "Initialize git submodules"
task :init => ["git:version"] do
sh "git submodule init"
# for sparse-checkout; @see https://stackoverflow.com/a/59521050/15992898
`git config --file .gitmodules --name-only --get-regexp path`.lines.each{|str|
# list submodule; @see https://stackoverflow.com/a/23490756/15992898
next unless str =~ /submodule\.(.+)\.path/
repo_dir = $1
sh "git clone -n #{`git config submodule.#{repo_dir}.url`.chomp} #{repo_dir}"
}
{
'ext/ninja-scan-light' => [
# From git 2.37.0, cone mode, which denies part of pattern like .ignore, is its default.
# @see https://git-scm.com/docs/git-sparse-checkout/2.37.0#_internalscone_mode_handling
(@git_version < "2.37.0") ? "sparse-checkout init" : nil, # same as "git -C #{repo} config core.sparseCheckout true"
# same as #{repo}/.git/info/sparse-checkout
"sparse-checkout set #{'--no-cone' if @git_version >= "2.37.0"}" \
+ (<<-__SPARSE_PATTERNS__).lines.collect{|str| str.chomp.gsub(/^ */, ' ')}.join,
tool/swig/BoostDistributions.i
tool/swig/makefile
tool/swig/extconf.rb
__SPARSE_PATTERNS__
].compact
}.each{|repo, commands|
commands.each{|str| sh "git -C #{repo} #{str}"}
}
sh "git submodule absorbgitdirs" # Move #{repo}/.git to .git/modules/#{repo}/.git
sh "git submodule update"
# if already checked out, then git -C #{repo} read-tree -mu HEAD
end
end
end
desc "Generate SWIG wrapper codes"
task :swig, [:swig_options] do |task, args|
swig_dir = File::join(File::dirname(__FILE__), 'ext', 'ninja-scan-light', 'tool', 'swig')
out_base_dir = File::join(File::dirname(__FILE__), 'ext', 'boost_distributions')
Dir::chdir(swig_dir){
Dir::glob("*.i"){|src|
mod_name = File::basename(src, '.*')
out_dir = File::join(out_base_dir, mod_name)
sh "mkdir -p #{out_dir}"
wrapper = File::join(out_dir, "#{mod_name}_wrap.cxx")
sh [:make, :clean, wrapper,
"BUILD_DIR=#{out_dir}",
"SWIGFLAGS='-c++ -ruby #{" -D__MINGW__" if ENV["MSYSTEM"]} #{args[:swig_options]}'"].join(' ')
}
}
end
file "ext/ninja-scan-light/tool" do |t|
Rake::Task["git:submodules:init"].invoke
end
task :default => [:compile, :spec]