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

Instance Method Summary collapse

Instance Method Details

#append_env(name, *args) ⇒ Object



156
157
158
# File 'lib/xot/rake/util.rb', line 156

def append_env(name, *args)
  ENV[name] = (ENV[name] || '') + " #{args.flatten.join ' '}"
end

#arObject



271
272
273
# File 'lib/xot/rake/util.rb', line 271

def ar()
  env :AR, RbConfig::CONFIG['AR']  || 'ar'
end

#arflagsObject



287
288
289
# File 'lib/xot/rake/util.rb', line 287

def arflags()
  env :ARFLAGS, RbConfig::CONFIG['ARFLAGS'] || 'crs'
end

#build_applicationObject



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/xot/rake.rb', line 248

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_libraryObject



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
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/xot/rake.rb', line 71

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\W/, 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



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
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/xot/rake.rb', line 132

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_gemObject



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
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/xot/rake.rb', line 207

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

#cd_sh(dir, cmd) ⇒ Object



98
99
100
101
102
103
# File 'lib/xot/rake/util.rb', line 98

def cd_sh(dir, cmd)
  Dir.chdir dir do
    rake_puts "(in #{Dir.pwd})"
    sh cmd
  end
end

#ci?Boolean

Returns:

  • (Boolean)


227
228
229
# File 'lib/xot/rake/util.rb', line 227

def ci?()
  github_actions?
end

#clang?Boolean

Returns:

  • (Boolean)


263
264
265
# File 'lib/xot/rake/util.rb', line 263

def clang?()
  RbConfig::CONFIG['CXX'] =~ /(^|\s)clang/i
end

#compile_erb(path, out) ⇒ Object



105
106
107
108
109
110
111
112
# File 'lib/xot/rake/util.rb', line 105

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



114
115
116
# File 'lib/xot/rake/util.rb', line 114

def compile_erb_str(str)
  ERB.new(str, trim_mode: '%').result binding
end

#cppflagsObject



275
276
277
278
# File 'lib/xot/rake/util.rb', line 275

def cppflags()
  flags = env :CPPFLAGS, RbConfig::CONFIG['CPPFLAGS']
  make_cppflags flags, defs, inc_dirs
end

#cxxObject



267
268
269
# File 'lib/xot/rake/util.rb', line 267

def cxx()
  env :CXX, RbConfig::CONFIG['CXX'] || 'g++'
end

#cxxflags(warnings = true) ⇒ Object



280
281
282
283
284
285
# File 'lib/xot/rake/util.rb', line 280

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

Returns:

  • (Boolean)


247
248
249
# File 'lib/xot/rake/util.rb', line 247

def cygwin?()
  RUBY_PLATFORM =~ /cygwin/
end

#debug?(state = nil) ⇒ Boolean

Returns:

  • (Boolean)


222
223
224
225
# File 'lib/xot/rake/util.rb', line 222

def debug?(state = nil)
  ENV['DEBUG'] = (!!state).to_s if state != nil
  env :DEBUG, false
end

#default_tasks(default = nil) ⇒ Object



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/xot/rake/util.rb', line 291

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_tasksObject



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/xot/rake.rb', line 348

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

#defsObject



43
44
45
# File 'lib/xot/rake.rb', line 43

def defs()
  env_array :DEFS, []
end

#doc_dirObject



34
35
36
# File 'lib/xot/rake/util.rb', line 34

def doc_dir()
  env :DOCDIR, 'doc'
end

#env(name, defval = nil) ⇒ Object



140
141
142
143
144
145
146
147
148
# File 'lib/xot/rake/util.rb', line 140

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



150
151
152
153
154
# File 'lib/xot/rake/util.rb', line 150

def env_array(name, defval = nil)
  val = get_env name, defval
  val = val.strip.split(/\s+/) if val.kind_of? String
  val
end

#erbs_mapObject



26
27
28
29
30
# File 'lib/xot/rake.rb', line 26

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

Returns:

  • (Boolean)


70
71
72
# File 'lib/xot/rake/util.rb', line 70

def excluded?(path)
  excludes.any? {|s| path =~ %r{#{s}}}
end

#excludesObject



66
67
68
# File 'lib/xot/rake/util.rb', line 66

def excludes()
  env_array :EXCLUDES, []
end

#ext_dirObject



38
39
40
# File 'lib/xot/rake/util.rb', line 38

def ext_dir()
  env :EXTDIR, "ext/#{target_name}"
end

#ext_lib_dirObject



42
43
44
# File 'lib/xot/rake/util.rb', line 42

def ext_lib_dir()
  env :EXTLIBDIR, "lib/#{target_name}"
end

#extensionsObject



10
11
12
# File 'lib/xot/rake/util.rb', line 10

def extensions()
  env(:EXTENSIONS, []).map {|m| m::Extension}
end

#filter_file(path, &block) ⇒ Object



94
95
96
# File 'lib/xot/rake/util.rb', line 94

def filter_file(path, &block)
  File.write path, block.call(File.read path)
end

#gcc?Boolean

Returns:

  • (Boolean)


259
260
261
# File 'lib/xot/rake/util.rb', line 259

def gcc?()
  RbConfig::CONFIG['CXX'] =~ /(^|\s)g\+\+/i
end

#get_env(name, defval = nil) ⇒ Object



135
136
137
138
# File 'lib/xot/rake/util.rb', line 135

def get_env(name, defval = nil)
  val = ENV[name.to_s] || Object.const_get(name) rescue defval
  val.dup rescue val
end

#github_actions?Boolean

Returns:

  • (Boolean)


231
232
233
# File 'lib/xot/rake/util.rb', line 231

def github_actions?()
  env :GITHUB_ACTIONS, false
end

#glob(*patterns) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/xot/rake/util.rb', line 74

def glob(*patterns)
  paths = []
  patterns.each do |pattern|
    paths.concat Dir.glob(pattern)
  end
  paths
end

#inc_dirObject



22
23
24
# File 'lib/xot/rake/util.rb', line 22

def inc_dir()
  env :INCDIR, 'include'
end

#inc_dirsObject



54
55
56
# File 'lib/xot/rake/util.rb', line 54

def inc_dirs()
  env_array(:INCDIRS, []) + extensions.reverse.map {|m| m.inc_dir}.flatten
end

#ios?Boolean

Returns:

  • (Boolean)


255
256
257
# File 'lib/xot/rake/util.rb', line 255

def ios?()
  false
end

#lib_dirObject



30
31
32
# File 'lib/xot/rake/util.rb', line 30

def lib_dir()
  env :LIBDIR, 'lib'
end

#make_cflags(flags = '') ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/xot/rake/util.rb', line 191

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



160
161
162
163
164
165
166
# File 'lib/xot/rake/util.rb', line 160

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



168
169
170
171
172
173
174
175
176
# File 'lib/xot/rake/util.rb', line 168

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



178
179
180
# File 'lib/xot/rake/util.rb', line 178

def make_cppflags_incdirs(dirs = [])
  dirs.reject {|dir| dir =~ %r|vendor/|}
end

#make_cppflags_sys_incdirs(dirs = []) ⇒ Object



182
183
184
# File 'lib/xot/rake/util.rb', line 182

def make_cppflags_sys_incdirs(dirs = [])
  dirs.select {|dir| dir =~ %r|vendor/|} + ruby_inc_dirs
end

#make_ldflags(flags = '', libdirs = [], frameworks = []) ⇒ Object



207
208
209
210
211
212
# File 'lib/xot/rake/util.rb', line 207

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



124
125
126
127
128
129
130
131
132
133
# File 'lib/xot/rake/util.rb', line 124

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

Returns:

  • (Boolean)


243
244
245
# File 'lib/xot/rake/util.rb', line 243

def ming?()
  RUBY_PLATFORM =~ /ming/
end

#mswin?Boolean

Returns:

  • (Boolean)


239
240
241
# File 'lib/xot/rake/util.rb', line 239

def mswin?()
  RUBY_PLATFORM =~ /mswin/
end

#noverbose_puts(*args) ⇒ Object



90
91
92
# File 'lib/xot/rake/util.rb', line 90

def noverbose_puts(*args)
  rake_puts(*args) unless ::Rake.verbose
end

#osx?Boolean

Returns:

  • (Boolean)


251
252
253
# File 'lib/xot/rake/util.rb', line 251

def osx?()
  RUBY_PLATFORM =~ /darwin/
end

#params(max, sep = '', &block) ⇒ Object



118
119
120
121
122
# File 'lib/xot/rake/util.rb', line 118

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



82
83
84
# File 'lib/xot/rake/util.rb', line 82

def rake_puts(*args)
  $stderr.puts(*args)
end

#ruby_inc_dirsObject



186
187
188
189
# File 'lib/xot/rake/util.rb', line 186

def ruby_inc_dirs()
  root = RbConfig::CONFIG['rubyhdrdir']
  [root, RbConfig::CONFIG['rubyarchhdrdir'] || "#{root}/#{RUBY_PLATFORM}"]
end

#src_dirObject



26
27
28
# File 'lib/xot/rake/util.rb', line 26

def src_dir()
  env :SRCDIR, 'src'
end

#src_dirsObject



58
59
60
# File 'lib/xot/rake/util.rb', line 58

def src_dirs()
  env_array :SRCDIRS, []
end

#src_ext_map(to = '.o') ⇒ Object



39
40
41
# File 'lib/xot/rake.rb', line 39

def src_ext_map(to = '.o')
  Hash[*src_exts.map {|ext| [".#{ext}", to]}.flatten]
end

#src_extsObject



62
63
64
# File 'lib/xot/rake/util.rb', line 62

def src_exts()
  env_array(:SRCEXTS, []) + %w[c cc cpp m mm]
end

#srcs_mapObject



16
17
18
19
20
21
22
23
24
# File 'lib/xot/rake.rb', line 16

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

#targetObject



14
15
16
# File 'lib/xot/rake/util.rb', line 14

def target()
  extensions.last
end

#target_nameObject



18
19
20
# File 'lib/xot/rake/util.rb', line 18

def target_name()
  env :EXTNAME, target.name.downcase
end

#test_alonesObject



47
48
49
# File 'lib/xot/rake.rb', line 47

def test_alones()
  env :TESTS_ALONE, []
end

#test_dirObject



46
47
48
# File 'lib/xot/rake/util.rb', line 46

def test_dir()
  env :TESTDIR, 'test'
end

#test_excludesObject



51
52
53
# File 'lib/xot/rake.rb', line 51

def test_excludes()
  env :TESTS_EXCLUDE, []
end

#test_ruby_extensionObject



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/xot/rake.rb', line 188

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

#use_boost_library(modules = [], branch: nil, tag: nil) ⇒ Object



338
339
340
341
342
343
344
345
346
# File 'lib/xot/rake.rb', line 338

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_bundlerObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/xot/rake.rb', line 55

def use_bundler()
  task :clobber => 'bundle:clobber'

  task :bundle => 'bundle:install'

  namespace :bundle do
    task :clobber do
      sh %( rm -rf vendor/bundle )
    end

    task :install do
      sh %( bundle install )
    end
  end
end

#use_external_library(repos, branch: nil, tag: nil, commit: nil, incdirs: nil, srcdirs: nil, excludes: [], submodules: [], post_submodules: nil, &after_clone_block) ⇒ Object



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
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/xot/rake.rb', line 276

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_dirObject



50
51
52
# File 'lib/xot/rake/util.rb', line 50

def vendor_dir()
  env :VENDORDIR, 'vendor'
end

#vendor_srcs_map(*dirs) ⇒ Object



32
33
34
35
36
37
# File 'lib/xot/rake.rb', line 32

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

Returns:

  • (Boolean)


214
215
216
217
218
219
220
# File 'lib/xot/rake/util.rb', line 214

def verbose?(state = nil)
  if state != nil
    ::Rake.verbose state
    ENV['VERBOSE'] = (!!state).to_s
  end
  ::Rake.verbose
end

#verbose_puts(*args) ⇒ Object



86
87
88
# File 'lib/xot/rake/util.rb', line 86

def verbose_puts(*args)
  rake_puts(*args) if ::Rake.verbose
end

#win32?Boolean

Returns:

  • (Boolean)


235
236
237
# File 'lib/xot/rake/util.rb', line 235

def win32?()
  RUBY_PLATFORM =~ /mswin|ming|cygwin/
end