Module: Xot::Rake
- Included in:
- ExtConf
- Defined in:
- lib/xot/rake.rb,
lib/xot/rake/util.rb,
lib/xot/rake/alias_task.rb
Defined Under Namespace
Classes: AliasTask
Constant Summary collapse
- VERSION_NAME =
'VERSION'
Instance Method Summary collapse
- #actions? ⇒ Boolean
- #append_env(name, *args) ⇒ Object
- #ar ⇒ Object
- #arflags ⇒ Object
- #build_application ⇒ Object
- #build_native_library ⇒ Object
- #build_ruby_extension(dlname: 'native', dlext: nil, liboutput: true) ⇒ Object
- #build_ruby_gem ⇒ Object
- #bump_version(index, version = get_version, min_digits: 3) ⇒ Object
- #bump_version_file(index, dir: nil) ⇒ Object
- #cd_sh(dir, cmd) ⇒ Object
- #clang? ⇒ Boolean
- #compile_erb(path, out) ⇒ Object
- #compile_erb_str(str) ⇒ Object
- #cppflags ⇒ Object
- #cxx ⇒ Object
- #cxxflags(warnings = true) ⇒ Object
- #cygwin? ⇒ Boolean
- #debug?(state = nil) ⇒ Boolean
- #default_tasks(default = nil) ⇒ Object
- #define_placeholder_tasks ⇒ Object
- #defs ⇒ Object
- #doc_dir ⇒ Object
- #env(name, defval = nil) ⇒ Object
- #env_array(name, defval = nil) ⇒ Object
- #erbs_map ⇒ Object
- #excluded?(path) ⇒ Boolean
- #excludes ⇒ Object
- #ext_dir ⇒ Object
- #ext_lib_dir ⇒ Object
- #extensions ⇒ Object
- #filter_file(path, &block) ⇒ Object
- #gcc? ⇒ Boolean
- #get_env(name, defval = nil) ⇒ Object
- #get_version(dir = nil) ⇒ Object
- #glob(*patterns) ⇒ Object
- #inc_dir ⇒ Object
- #inc_dirs ⇒ Object
- #ios? ⇒ Boolean
- #lib_dir ⇒ Object
- #make_cflags(flags = '') ⇒ Object
- #make_cppflags(flags = '', defs = [], incdirs = []) ⇒ Object
- #make_cppflags_defs(defs = []) ⇒ Object
- #make_cppflags_incdirs(dirs = []) ⇒ Object
- #make_cppflags_sys_incdirs(dirs = []) ⇒ Object
- #make_ldflags(flags = '', libdirs = [], frameworks = []) ⇒ Object
- #make_path_map(paths, ext_map) ⇒ Object
- #ming? ⇒ Boolean
- #modified_files(dir: '.', hash: '@') ⇒ Object
- #mswin? ⇒ Boolean
- #noverbose_puts(*args) ⇒ Object
- #osx? ⇒ Boolean
- #params(max, sep = '', &block) ⇒ Object
- #rake_puts(*args) ⇒ Object
- #ruby_inc_dirs ⇒ Object
- #src_dir ⇒ Object
- #src_dirs ⇒ Object
- #src_ext_map(to = '.o') ⇒ Object
- #src_exts ⇒ Object
- #srcs_map ⇒ Object
- #target ⇒ Object
- #target_name ⇒ Object
- #test_alones ⇒ Object
- #test_dir ⇒ Object
- #test_excludes ⇒ Object
- #test_ruby_extension ⇒ Object
- #update_and_tag_version(index, dir: nil, &block) ⇒ Object
- #use_boost_library(modules = [], branch: nil, tag: nil) ⇒ Object
- #use_external_library(repos, branch: nil, tag: nil, commit: nil, incdirs: nil, srcdirs: nil, excludes: [], submodules: [], post_submodules: nil, &after_clone_block) ⇒ Object
- #vendor_dir ⇒ Object
- #vendor_srcs_map(*dirs) ⇒ Object
- #verbose?(state = nil) ⇒ Boolean
- #verbose_puts(*args) ⇒ Object
- #version_path(dir = nil) ⇒ Object
- #win32? ⇒ Boolean
Instance Method Details
#actions? ⇒ Boolean
275 276 277 |
# File 'lib/xot/rake/util.rb', line 275 def actions?() env :GITHUB_ACTIONS, false end |
#append_env(name, *args) ⇒ Object
204 205 206 |
# File 'lib/xot/rake/util.rb', line 204 def append_env(name, *args) ENV[name] = (ENV[name] || '') + " #{args.flatten.join ' '}" end |
#ar ⇒ Object
315 316 317 |
# File 'lib/xot/rake/util.rb', line 315 def ar() env :AR, RbConfig::CONFIG['AR'] || 'ar' end |
#arflags ⇒ Object
331 332 333 |
# File 'lib/xot/rake/util.rb', line 331 def arflags() env :ARFLAGS, RbConfig::CONFIG['ARFLAGS'] || 'crs' end |
#build_application ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/xot/rake.rb', line 235 def build_application() bindir = env :BINDIR, 'bin' bin = "#{bindir}/#{target_name}" appdir = "#{target.name}.app" appbindir = "#{appdir}/Contents/MacOS" out = "#{appbindir}/#{target.name}" tmps = [appdir] alias_task :app => out alias_task :clean => 'app:clean' namespace :app do task :run => :app do sh %( ruby #{bin} ) end file out => [bin, appbindir] do sh %( cp #{bin} #{appbindir} ) end directory appbindir task :clean do sh %( rm -rf #{tmps.join ' '} ) end end end |
#build_native_library ⇒ Object
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/xot/rake.rb', line 58 def build_native_library() outname = "lib#{target_name}.a" out = File.join lib_dir, outname erbs = erbs_map srcs = srcs_map depend = 'depend.mf' alias_task :erb => 'lib:erb' alias_task :lib => out alias_task :clean => 'lib:clean' namespace :lib do desc "compile sources" alias_task :compile => srcs.values desc "convert erb sources" alias_task :erb => erbs.values desc "link #{out}" file out => srcs.values do next if srcs.values.empty? objs = srcs.values + vendor_srcs_map.values noverbose_puts "linking #{out}" sh %( rm -f #{out} ) sh %( #{ar} #{arflags} #{out} #{objs.join " "} ) end desc "create #{depend}" file depend => erbs.values do sh %( #{cxx} -M #{cppflags} #{srcs.keys.join ' '} > #{depend} ) input = open(depend) {|f| f.read} open(depend, 'w') do |output| output << input.gsub(/\w+\.o/, src_dir + '/\0') end end import depend if File.exist? depend srcs.each do |src, obj| desc "compile #{src}" file obj => [:vendor, depend, src] + erbs.values do noverbose_puts "compiling #{src}" sh %( #{cxx} -c #{cppflags} #{cxxflags} -o #{obj} #{src} ) end end erbs.each do |erb, to| desc "compile #{erb}" file to => erb do rake_puts "compiling #{erb} to #{to}" compile_erb erb, to end end task :clean do tmps = srcs.values + erbs.values sh %( rm -rf #{out} #{depend} #{tmps.join ' '} ) end end end |
#build_ruby_extension(dlname: 'native', dlext: nil, liboutput: true) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/xot/rake.rb', line 119 def build_ruby_extension(dlname: 'native', dlext: nil, liboutput: true) dlname = env :DLNAME, dlname dlext = env :DLEXT, dlext || RbConfig::CONFIG['DLEXT'] || 'so' extconf = File.join ext_dir, 'extconf.rb' makefile = File.join ext_dir, 'Makefile' depend = File.join ext_dir, 'depend.mf' outname = "#{dlname}.#{dlext}" extout = File.join ext_dir, outname libout = File.join ext_lib_dir, outname srcs = FileList["#{ext_dir}/**/*.cpp"] libs = extensions.map {|x| "#{x.lib_dir}/lib#{x.name.downcase}.a"} alias_task :ext => (liboutput ? libout : extout) alias_task :clean => 'ext:clean' alias_task :clobber => 'ext:clobber' namespace :ext do desc "build #{libout}" file libout => extout do sh %( cp #{extout} #{libout} ) end desc "build #{extout}" file extout => [:lib, makefile] do opts = ::Rake.verbose ? 'V=1' : '' sh %( cd #{ext_dir} && make #{opts} ) end desc "create #{makefile}" file makefile => [extconf, depend] + libs do sh %( cd #{ext_dir} && ruby #{File.basename extconf} ) end desc "create #{depend}" file depend => srcs do inc = inc_dirs.map {|s| " -I#{s}"}.join src = srcs.map {|cpp| File.basename cpp}.join ' ' dep = File.basename depend sh %( cd #{ext_dir} && #{cxx} -M #{cppflags} #{inc} #{src} > #{dep} ) end task :clean do sh %( cd #{ext_dir} && make clean ) if File.exist? makefile sh %( rm -rf #{libout} ) end task :clobber do sh %( cd #{ext_dir} && make distclean ) if File.exist? makefile sh %( rm -rf #{makefile} #{depend} ) end end end |
#build_ruby_gem ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/xot/rake.rb', line 194 def build_ruby_gem() gemspec = "#{target_name}.gemspec" gemname = env :GEMNAME, target_name gemver = env :GEMVERSION, target.version gemfile = "#{gemname}-#{gemver}.gem" alias_task :gem => gemfile alias_task :clean => 'gem:clean' alias_task :install => 'gem:install' alias_task :uninstall => 'gem:uninstall' alias_task :upload => 'gem:upload' namespace :gem do file gemfile => [:ext, :doc, gemspec] do sh %( gem build #{gemspec} ) end desc "test gem" alias_task :test => [:install, :uninstall] desc "install gem" task :install => gemfile do sh %( gem install #{gemfile} ) end desc "uninstall gem" task :uninstall do sh %( gem uninstall -x --version #{gemver} #{gemname} ) end desc "upload gem" task :upload => gemfile do sh %( gem push #{gemfile} ) end task :clean do sh %( rm -f #{gemfile} ) end end end |
#bump_version(index, version = get_version, min_digits: 3) ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/xot/rake/util.rb', line 122 def bump_version(index, version = get_version, min_digits: 3) nums = version.split('.').map &:to_i nums << 0 until nums.size > index nums[index] += 1 nums.map!.with_index {|num, i| i > index ? 0 : num} nums.pop while nums.last == 0 && nums.size > min_digits nums.join '.' end |
#bump_version_file(index, dir: nil) ⇒ Object
131 132 133 134 135 |
# File 'lib/xot/rake/util.rb', line 131 def bump_version_file(index, dir: nil) newver = bump_version index, get_version(dir) File.write version_path(dir), newver newver end |
#cd_sh(dir, cmd) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/xot/rake/util.rb', line 103 def cd_sh(dir, cmd) Dir.chdir dir do rake_puts "(in #{Dir.pwd})" sh cmd end end |
#clang? ⇒ Boolean
307 308 309 |
# File 'lib/xot/rake/util.rb', line 307 def clang?() RbConfig::CONFIG['CXX'] =~ /(^|\s)clang/i end |
#compile_erb(path, out) ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/xot/rake/util.rb', line 153 def compile_erb(path, out) open(path) do |input| open(out, 'w') do |output| output.write compile_erb_str(input.read) end end #rescue end |
#compile_erb_str(str) ⇒ Object
162 163 164 |
# File 'lib/xot/rake/util.rb', line 162 def compile_erb_str(str) ERB.new(str, trim_mode: '%').result binding end |
#cppflags ⇒ Object
319 320 321 322 |
# File 'lib/xot/rake/util.rb', line 319 def cppflags() flags = env :CPPFLAGS, RbConfig::CONFIG['CPPFLAGS'] make_cppflags flags, defs, inc_dirs end |
#cxx ⇒ Object
311 312 313 |
# File 'lib/xot/rake/util.rb', line 311 def cxx() env :CXX, RbConfig::CONFIG['CXX'] || 'g++' end |
#cxxflags(warnings = true) ⇒ Object
324 325 326 327 328 329 |
# File 'lib/xot/rake/util.rb', line 324 def cxxflags(warnings = true) cflags = env :CFLAGS, RbConfig::CONFIG['CFLAGS'] cxxflags = env :CXXFLAGS, RbConfig::CONFIG['CXXFLAGS'] cflags = cflags.gsub(/-W[\w\-]+/, '') + ' -w' unless warnings make_cflags "#{cflags} #{cxxflags}" end |
#cygwin? ⇒ Boolean
291 292 293 |
# File 'lib/xot/rake/util.rb', line 291 def cygwin?() RUBY_PLATFORM =~ /cygwin/ end |
#debug?(state = nil) ⇒ Boolean
270 271 272 273 |
# File 'lib/xot/rake/util.rb', line 270 def debug?(state = nil) ENV['DEBUG'] = (!!state).to_s if state != nil env :DEBUG, false end |
#default_tasks(default = nil) ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/xot/rake/util.rb', line 335 def default_tasks(default = nil) verbose? env(:VERBOSE, true) if default task :default => default else task :default end task :quiet do verbose? false end task :debug do debug? true end end |
#define_placeholder_tasks ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/xot/rake.rb', line 335 def define_placeholder_tasks() desc "delete temporary files" alias_task :clean desc "delete all generated files" alias_task :clobber => :clean desc "build native library" alias_task :lib desc "build ruby extension" alias_task :ext desc "build ruby gem" alias_task :gem desc "generate documentations" alias_task :doc desc "run all tests" alias_task :test desc "setup all external libraries" alias_task :vendor desc "convert erb files" alias_task :erb end |
#defs ⇒ Object
46 47 48 |
# File 'lib/xot/rake.rb', line 46 def defs() env_array :DEFS, [] end |
#doc_dir ⇒ Object
39 40 41 |
# File 'lib/xot/rake/util.rb', line 39 def doc_dir() env :DOCDIR, 'doc' end |
#env(name, defval = nil) ⇒ Object
188 189 190 191 192 193 194 195 196 |
# File 'lib/xot/rake/util.rb', line 188 def env(name, defval = nil) case val = get_env(name, defval) when /^\d+$/ then val.to_i when 'true', true then true when 'false', false then false when nil then nil else val end end |
#env_array(name, defval = nil) ⇒ Object
198 199 200 201 202 |
# File 'lib/xot/rake/util.rb', line 198 def env_array(name, defval = nil) val = get_env name, defval val = val.strip.split(/\s+/) if val.kind_of? String val end |
#erbs_map ⇒ Object
29 30 31 32 33 |
# File 'lib/xot/rake.rb', line 29 def erbs_map() paths = glob(*[inc_dir, src_dir].map {|s| "#{s}/**/*.erb"}) paths.reject! {|path| excluded? path} make_path_map paths, {".erb" => ""} end |
#excluded?(path) ⇒ Boolean
75 76 77 |
# File 'lib/xot/rake/util.rb', line 75 def excluded?(path) excludes.any? {|s| path =~ %r{#{s}}} end |
#excludes ⇒ Object
71 72 73 |
# File 'lib/xot/rake/util.rb', line 71 def excludes() env_array :EXCLUDES, [] end |
#ext_dir ⇒ Object
43 44 45 |
# File 'lib/xot/rake/util.rb', line 43 def ext_dir() env :EXTDIR, "ext/#{target_name}" end |
#ext_lib_dir ⇒ Object
47 48 49 |
# File 'lib/xot/rake/util.rb', line 47 def ext_lib_dir() env :EXTLIBDIR, "lib/#{target_name}" end |
#extensions ⇒ Object
15 16 17 |
# File 'lib/xot/rake/util.rb', line 15 def extensions() env(:EXTENSIONS, []).map {|m| m::Extension} end |
#filter_file(path, &block) ⇒ Object
99 100 101 |
# File 'lib/xot/rake/util.rb', line 99 def filter_file(path, &block) File.write path, block.call(File.read path) end |
#gcc? ⇒ Boolean
303 304 305 |
# File 'lib/xot/rake/util.rb', line 303 def gcc?() RbConfig::CONFIG['CXX'] =~ /(^|\s)g\+\+/i end |
#get_env(name, defval = nil) ⇒ Object
183 184 185 186 |
# File 'lib/xot/rake/util.rb', line 183 def get_env(name, defval = nil) val = ENV[name.to_s] || Object.const_get(name) rescue defval val.dup rescue val end |
#get_version(dir = nil) ⇒ Object
118 119 120 |
# File 'lib/xot/rake/util.rb', line 118 def get_version(dir = nil) File.readlines(version_path dir).first.chomp end |
#glob(*patterns) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/xot/rake/util.rb', line 79 def glob(*patterns) paths = [] patterns.each do |pattern| paths.concat Dir.glob(pattern) end paths end |
#inc_dir ⇒ Object
27 28 29 |
# File 'lib/xot/rake/util.rb', line 27 def inc_dir() env :INCDIR, 'include' end |
#inc_dirs ⇒ Object
59 60 61 |
# File 'lib/xot/rake/util.rb', line 59 def inc_dirs() env_array(:INCDIRS, []) + extensions.reverse.map {|m| m.inc_dir}.flatten end |
#ios? ⇒ Boolean
299 300 301 |
# File 'lib/xot/rake/util.rb', line 299 def ios?() false end |
#lib_dir ⇒ Object
35 36 37 |
# File 'lib/xot/rake/util.rb', line 35 def lib_dir() env :LIBDIR, 'lib' end |
#make_cflags(flags = '') ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/xot/rake/util.rb', line 239 def make_cflags(flags = '') warning_opts = %w[ no-unknown-pragmas no-deprecated-register no-reserved-user-defined-literal ] s = flags.dup s << warning_opts.map {|s| " -W#{s}"}.join s << " -arch arm64" if RUBY_PLATFORM =~ /arm64-darwin/ s << ' -std=c++20' if gcc? s << ' -std=c++20 -stdlib=libc++ -mmacosx-version-min=10.7' if clang? s << ' ' + RbConfig::CONFIG['debugflags'] if debug? s.gsub!(/-O\d?\w*/, '-O0') if debug? s end |
#make_cppflags(flags = '', defs = [], incdirs = []) ⇒ Object
208 209 210 211 212 213 214 |
# File 'lib/xot/rake/util.rb', line 208 def make_cppflags(flags = '', defs = [], incdirs = []) s = flags.dup s += make_cppflags_defs(defs) .map {|s| " -D#{s}"}.join s += make_cppflags_incdirs(incdirs) .map {|s| " -I#{s}"}.join s += make_cppflags_sys_incdirs(incdirs).map {|s| " -isystem#{s}"}.join s end |
#make_cppflags_defs(defs = []) ⇒ Object
216 217 218 219 220 221 222 223 224 |
# File 'lib/xot/rake/util.rb', line 216 def make_cppflags_defs(defs = []) a = defs.dup a << $~[0].upcase if RUBY_PLATFORM =~ /mswin|ming|cygwin|darwin/i a << (debug? ? '_DEBUG' : 'NDEBUG') a << 'WIN32' if win32? a << 'OSX' if osx? a << 'IOS' if ios? a end |
#make_cppflags_incdirs(dirs = []) ⇒ Object
226 227 228 |
# File 'lib/xot/rake/util.rb', line 226 def make_cppflags_incdirs(dirs = []) dirs.reject {|dir| dir =~ %r|vendor/|} end |
#make_cppflags_sys_incdirs(dirs = []) ⇒ Object
230 231 232 |
# File 'lib/xot/rake/util.rb', line 230 def make_cppflags_sys_incdirs(dirs = []) dirs.select {|dir| dir =~ %r|vendor/|} + ruby_inc_dirs end |
#make_ldflags(flags = '', libdirs = [], frameworks = []) ⇒ Object
255 256 257 258 259 260 |
# File 'lib/xot/rake/util.rb', line 255 def make_ldflags(flags = '', libdirs = [], frameworks = []) s = flags.dup s << libdirs.map {|s| " -L#{s}"}.join s << frameworks.map {|s| " -framework #{s}"}.join s end |
#make_path_map(paths, ext_map) ⇒ Object
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/xot/rake/util.rb', line 172 def make_path_map(paths, ext_map) paths = paths.map do |path| newpath = ext_map.inject path do |value, (from, to)| value.sub(/#{from.gsub('.', '\.')}$/, to) end raise "map to same path" if path == newpath [path, newpath] end Hash[*paths.flatten] end |
#ming? ⇒ Boolean
287 288 289 |
# File 'lib/xot/rake/util.rb', line 287 def ming?() RUBY_PLATFORM =~ /ming/ end |
#modified_files(dir: '.', hash: '@') ⇒ Object
110 111 112 |
# File 'lib/xot/rake/util.rb', line 110 def modified_files(dir: '.', hash: '@') `git diff --name-only #{hash} -- #{dir}`.lines.map &:chomp end |
#mswin? ⇒ Boolean
283 284 285 |
# File 'lib/xot/rake/util.rb', line 283 def mswin?() RUBY_PLATFORM =~ /mswin/ end |
#noverbose_puts(*args) ⇒ Object
95 96 97 |
# File 'lib/xot/rake/util.rb', line 95 def noverbose_puts(*args) rake_puts(*args) unless ::Rake.verbose end |
#osx? ⇒ Boolean
295 296 297 |
# File 'lib/xot/rake/util.rb', line 295 def osx?() RUBY_PLATFORM =~ /darwin/ end |
#params(max, sep = '', &block) ⇒ Object
166 167 168 169 170 |
# File 'lib/xot/rake/util.rb', line 166 def params(max, sep = '', &block) raise 'block not given.' unless block return '' if max == 0 (1..max).map(&block).join(sep) end |
#rake_puts(*args) ⇒ Object
87 88 89 |
# File 'lib/xot/rake/util.rb', line 87 def rake_puts(*args) $stderr.puts(*args) end |
#ruby_inc_dirs ⇒ Object
234 235 236 237 |
# File 'lib/xot/rake/util.rb', line 234 def ruby_inc_dirs() root = RbConfig::CONFIG['rubyhdrdir'] [root, RbConfig::CONFIG['rubyarchhdrdir'] || "#{root}/#{RUBY_PLATFORM}"] end |
#src_dir ⇒ Object
31 32 33 |
# File 'lib/xot/rake/util.rb', line 31 def src_dir() env :SRCDIR, 'src' end |
#src_dirs ⇒ Object
63 64 65 |
# File 'lib/xot/rake/util.rb', line 63 def src_dirs() env_array :SRCDIRS, [] end |
#src_ext_map(to = '.o') ⇒ Object
42 43 44 |
# File 'lib/xot/rake.rb', line 42 def src_ext_map(to = '.o') Hash[*src_exts.map {|ext| [".#{ext}", to]}.flatten] end |
#src_exts ⇒ Object
67 68 69 |
# File 'lib/xot/rake/util.rb', line 67 def src_exts() env_array(:SRCEXTS, []) + %w[c cc cpp m mm] end |
#srcs_map ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/xot/rake.rb', line 19 def srcs_map() paths = glob("#{src_dir}/**/*.{#{src_exts.join ','}}") + erbs_map.values.grep(/\.(#{src_exts.join '|'})$/) paths.reject! {|path| excluded? path} paths.reject! {|path| path =~ %r(/win32/)} unless win32? paths.reject! {|path| path =~ %r(/osx/)} unless osx? paths.reject! {|path| path =~ %r(/ios/)} unless ios? make_path_map paths, src_ext_map end |
#target ⇒ Object
19 20 21 |
# File 'lib/xot/rake/util.rb', line 19 def target() extensions.last end |
#target_name ⇒ Object
23 24 25 |
# File 'lib/xot/rake/util.rb', line 23 def target_name() env :EXTNAME, target.name.downcase end |
#test_alones ⇒ Object
50 51 52 |
# File 'lib/xot/rake.rb', line 50 def test_alones() env :TESTS_ALONE, [] end |
#test_dir ⇒ Object
51 52 53 |
# File 'lib/xot/rake/util.rb', line 51 def test_dir() env :TESTDIR, 'test' end |
#test_excludes ⇒ Object
54 55 56 |
# File 'lib/xot/rake.rb', line 54 def test_excludes() env :TESTS_EXCLUDE, [] end |
#test_ruby_extension ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/xot/rake.rb', line 175 def test_ruby_extension() alias_task :test => [:ext, 'test:full', 'test:alones'] namespace :test do ::Rake::TestTask.new :full do |t| t.libs << lib_dir t.test_files = FileList["#{test_dir}/**/test_*.rb"] - test_alones - test_excludes t.verbose = ::Rake.verbose end task :alones do test_alones.each do |rb| next if test_excludes.include? rb sh %( ruby #{rb} ) end end end end |
#update_and_tag_version(index, dir: nil, &block) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/xot/rake/util.rb', line 137 def update_and_tag_version(index, dir: nil, &block) raise 'modified files exist' unless modified_files.empty? = ENV['message'] raise 'no message' unless newver = bump_version_file index, dir: dir raise 'version is not updated' unless modified_files == [version_path(dir)] block.call if block sh %( git add -u ) sh %( git commit -m "#{message}" ) sh %( git tag -a -m "#{message}" v#{newver} ) end |
#use_boost_library(modules = [], branch: nil, tag: nil) ⇒ Object
325 326 327 328 329 330 331 332 333 |
# File 'lib/xot/rake.rb', line 325 def use_boost_library(modules = [], branch: nil, tag: nil) default_modules = %w[tools/build libs/config] use_external_library 'https://github.com/boostorg/boost', branch: branch, tag: tag, srcdirs: 'NOSRC', submodules: default_modules | modules.map {|mod| "libs/#{mod}"}, post_submodules: './bootstrap.sh && ./b2 headers' end |
#use_external_library(repos, branch: nil, tag: nil, commit: nil, incdirs: nil, srcdirs: nil, excludes: [], submodules: [], post_submodules: nil, &after_clone_block) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/xot/rake.rb', line 263 def use_external_library( repos, branch: nil, tag: nil, commit: nil, incdirs: nil, srcdirs: nil, excludes: [], submodules: [], post_submodules: nil, &after_clone_block) name = repos[%r{/([^/]+?)(:?\.git)?$}, 1] dir = "#{vendor_dir}/#{name}" incdirs = [incdirs].flatten.map {|s| s ? "#{dir}/#{s}" : dir} srcdirs = [srcdirs].flatten.map {|s| s ? "#{dir}/#{s}" : dir} excludes = [excludes].flatten append_env 'INCDIRS', incdirs append_env 'SRCDIRS', srcdirs append_env 'EXCLUDES', excludes unless excludes.empty? alias_task :vendor => "vendor:#{name}" alias_task :clobber => "vendor:#{name}:clobber" namespace :vendor do desc "setup #{name} library" alias_task name => dir namespace name do desc "clone #{name}" file dir do opts = '-c advice.detachedHead=false --depth 1' opts += " --branch #{branch || tag}" if branch || tag opts += " --recursive" if submodules.empty? sh %( git clone #{opts} #{repos} #{dir} ) Dir.chdir dir do sh %( git fetch --depth 1 origin #{commit} ) sh %( git checkout #{commit} ) end if commit unless submodules.empty? Dir.chdir dir do submodules.each do |path| sh %( git submodule init #{path} ) end sh %( git submodule update --depth=1 ) sh post_submodules if post_submodules end end Dir.chdir(dir) {after_clone_block.call} if after_clone_block unless env :VENDOR_NOCOMPILE, false vendor_srcs_map(*srcdirs).each do |src, obj| sh %( #{cxx} -c #{cppflags} #{cxxflags false} -o #{obj} #{src} ) end end end desc "update #{name} library" task :update => ["vendor:#{name}:clobber", "vendor:#{name}"] desc "delete #{name} library" task :clobber do sh %( rm -rf #{dir} ) end end end end |
#vendor_dir ⇒ Object
55 56 57 |
# File 'lib/xot/rake/util.rb', line 55 def vendor_dir() env :VENDORDIR, 'vendor' end |
#vendor_srcs_map(*dirs) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/xot/rake.rb', line 35 def vendor_srcs_map(*dirs) dirs = src_dirs if dirs.empty? paths = dirs.map {|dir| glob "#{dir}/**/*.{#{src_exts.join ','}}"}.flatten paths.reject! {|path| excluded? path} make_path_map paths.flatten, src_ext_map end |
#verbose?(state = nil) ⇒ Boolean
262 263 264 265 266 267 268 |
# File 'lib/xot/rake/util.rb', line 262 def verbose?(state = nil) if state != nil ::Rake.verbose state ENV['VERBOSE'] = (!!state).to_s end ::Rake.verbose end |
#verbose_puts(*args) ⇒ Object
91 92 93 |
# File 'lib/xot/rake/util.rb', line 91 def verbose_puts(*args) rake_puts(*args) if ::Rake.verbose end |
#version_path(dir = nil) ⇒ Object
114 115 116 |
# File 'lib/xot/rake/util.rb', line 114 def version_path(dir = nil) dir ? "#{dir}/#{VERSION_NAME}" : VERSION_NAME end |
#win32? ⇒ Boolean
279 280 281 |
# File 'lib/xot/rake/util.rb', line 279 def win32?() RUBY_PLATFORM =~ /mswin|ming|cygwin/ end |