-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
625 lines (528 loc) · 21 KB
/
Rakefile
File metadata and controls
625 lines (528 loc) · 21 KB
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
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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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
234
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
262
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
324
325
326
327
328
329
330
331
332
333
334
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
# frozen_string_literal: true
require 'bundler/setup'
require 'rbconfig'
require 'rake/testtask'
# -- Compile -----------------------------------------------------------------
ext_dir = File.expand_path('ext/gemba', __dir__)
lib_dir = File.expand_path('lib', __dir__)
so_name = "gemba_ext.#{RbConfig::CONFIG['DLEXT']}"
desc "Compile C extension"
task :compile do
Dir.chdir(ext_dir) do
sh RbConfig.ruby, 'extconf.rb' unless File.exist?('Makefile')
sh 'make'
end
cp File.join(ext_dir, so_name), lib_dir
end
desc "Remove build artifacts"
task :clobber do
Dir.chdir(ext_dir) do
sh 'make clean' if File.exist?('Makefile')
end
rm_f Dir.glob("#{ext_dir}/{Makefile,*.o,*.so,*.bundle,*.def,mkmf.log}")
rm_f File.join(lib_dir, so_name)
rm_rf File.expand_path('vendor/build', __dir__)
end
# -- Test --------------------------------------------------------------------
Rake::TestTask.new(:test) do |t|
t.libs << 'test' << 'lib'
t.test_files = FileList['test/**/test_*.rb'] - FileList['test/test_helper.rb']
t.ruby_opts << '-r test_helper'
t.verbose = true
end
task test: :compile
# Isolate tests from the user's real config/saves/recordings.
task 'test:isolate_config' do
require 'tmpdir'
ENV['GEMBA_CONFIG_DIR'] ||= Dir.mktmpdir('gemba-test')
end
Rake::Task['test'].enhance(['test:isolate_config'])
# -- Submodules ---------------------------------------------------------------
task :submodules do
rcheevos_sentinel = File.expand_path('vendor/rcheevos/src/rcheevos/runtime.c', __dir__)
unless File.exist?(rcheevos_sentinel)
puts "Initialising git submodules..."
sh "git submodule update --init"
end
end
# -- Dependencies (macOS / platforms without libmgba-dev) --------------------
desc "Download and build libmgba from source"
task :deps do
if RUBY_PLATFORM =~ /mingw|mswin/
abort "rake deps is not needed on Windows — install via MSYS2:\n" \
" pacman -S mingw-w64-ucrt-x86_64-mgba"
end
# cmake needs C and C++ compilers; check everything up front.
needed = %w[cmake git make]
needed += RUBY_PLATFORM =~ /mingw|mswin/ ? %w[gcc g++] : %w[cc c++]
missing = needed.reject { |cmd| ENV['PATH'].split(File::PATH_SEPARATOR).any? { |d| File.executable?(File.join(d, cmd)) || File.executable?(File.join(d, "#{cmd}.exe")) } }
unless missing.empty?
find_bin = ->(name) { ENV['PATH'].split(File::PATH_SEPARATOR).any? { |d| File.executable?(File.join(d, name)) } }
hint = if RUBY_PLATFORM =~ /darwin/
" xcode-select --install && brew install cmake"
elsif find_bin['dnf']
" sudo dnf install cmake gcc gcc-c++ make git"
elsif find_bin['apt']
" sudo apt install cmake build-essential git"
elsif find_bin['pacman']
" sudo pacman -S cmake gcc make git"
elsif find_bin['apk']
" apk add cmake gcc g++ make git"
else
" Install: #{missing.join(', ')}"
end
abort "Missing required tools: #{missing.join(', ')}\n#{hint}"
end
require 'fileutils'
require 'etc'
# Install to a system-visible prefix so `gem install gemba` finds libmgba
# without needing MGBA_DIR. Mirrors what `brew install` would do.
default_prefix = RUBY_PLATFORM =~ /darwin/ ? '/opt/homebrew' : '/usr/local'
install_dir = ENV.fetch('MGBA_PREFIX', default_prefix)
vendor_dir = File.expand_path('vendor')
mgba_src = File.join(vendor_dir, 'mgba')
build_dir = File.join(vendor_dir, 'build')
unless File.directory?(mgba_src)
FileUtils.mkdir_p(vendor_dir)
sh "git clone --depth 1 --branch 0.10.5 https://github.com/mgba-emu/mgba.git #{mgba_src}"
end
FileUtils.mkdir_p(build_dir)
# -DMARKDOWN= disables mgba's README-to-HTML build; it finds kramdown
# on PATH from Ruby gems, but Bundler blocks it. We only need the static lib.
cmake_flags = %W[
-DMARKDOWN=
-DBUILD_SHARED=OFF
-DBUILD_STATIC=ON
-DBUILD_QT=OFF
-DBUILD_SDL=OFF
-DBUILD_GL=OFF
-DBUILD_GLES2=OFF
-DBUILD_GLES3=OFF
-DBUILD_LIBRETRO=OFF
-DSKIP_FRONTEND=ON
-DUSE_SQLITE3=OFF
-DUSE_ELF=OFF
-DUSE_LZMA=OFF
-DUSE_EDITLINE=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_INSTALL_PREFIX=#{install_dir}
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
].join(' ')
sh "cmake -S #{mgba_src} -B #{build_dir} #{cmake_flags}"
sh "cmake --build #{build_dir} -j #{Etc.nprocessors}"
install_cmd = "cmake --install #{build_dir}"
# System prefixes like /usr/local need root on Linux; Homebrew doesn't.
if !File.writable?(install_dir) && !RUBY_PLATFORM.match?(/mingw|mswin/)
install_cmd = "sudo #{install_cmd}"
end
sh install_cmd
puts "libmgba built and installed to #{install_dir}"
puts " headers: #{install_dir}/include/mgba/"
puts " libs: #{install_dir}/lib/"
end
# SDL2 libraries to build from source, in dependency order.
# SDL2 core must be built first; satellites find it via CMAKE_PREFIX_PATH.
SDL2_LIBS = [
{ name: 'SDL2', repo: 'libsdl-org/SDL', tag: 'release-2.32.10' },
{ name: 'SDL2_ttf', repo: 'libsdl-org/SDL_ttf', tag: 'release-2.24.0' },
{ name: 'SDL2_image', repo: 'libsdl-org/SDL_image', tag: 'release-2.8.8' },
{ name: 'SDL2_mixer', repo: 'libsdl-org/SDL_mixer', tag: 'release-2.8.1' },
].freeze
desc "Download and build SDL2 + satellite libs from source"
task 'deps:sdl2' do
if RUBY_PLATFORM =~ /mingw|mswin/
abort "rake deps:sdl2 is not needed on Windows — install via MSYS2:\n" \
" pacman -S mingw-w64-ucrt-x86_64-SDL2 mingw-w64-ucrt-x86_64-SDL2_ttf " \
"mingw-w64-ucrt-x86_64-SDL2_image mingw-w64-ucrt-x86_64-SDL2_mixer"
end
needed = %w[cmake git make pkg-config]
needed += RUBY_PLATFORM =~ /mingw|mswin/ ? %w[gcc g++] : %w[cc c++]
missing = needed.reject { |cmd| ENV['PATH'].split(File::PATH_SEPARATOR).any? { |d| File.executable?(File.join(d, cmd)) || File.executable?(File.join(d, "#{cmd}.exe")) } }
unless missing.empty?
find_bin = ->(name) { ENV['PATH'].split(File::PATH_SEPARATOR).any? { |d| File.executable?(File.join(d, name)) } }
hint = if RUBY_PLATFORM =~ /darwin/
" xcode-select --install && brew install cmake pkg-config"
elsif find_bin['dnf']
" sudo dnf install cmake gcc gcc-c++ make git pkg-config"
elsif find_bin['apt']
" sudo apt install cmake build-essential git pkg-config"
else
" Install: #{missing.join(', ')}"
end
abort "Missing required tools: #{missing.join(', ')}\n#{hint}"
end
require 'fileutils'
require 'etc'
default_prefix = RUBY_PLATFORM =~ /darwin/ ? '/opt/homebrew' : '/usr/local'
install_dir = ENV.fetch('SDL2_PREFIX', default_prefix)
vendor_dir = File.expand_path('vendor/sdl2', __dir__)
build_base = File.expand_path('vendor/sdl2_build', __dir__)
FileUtils.mkdir_p(vendor_dir)
use_sudo = !File.writable?(install_dir) && !RUBY_PLATFORM.match?(/mingw|mswin/)
SDL2_LIBS.each do |lib|
name = lib[:name]
src_dir = File.join(vendor_dir, name)
bld_dir = File.join(build_base, name)
puts "\n=== Building #{name} (#{lib[:tag]}) ==="
unless File.directory?(src_dir)
sh "git clone --depth 1 --branch #{lib[:tag]} https://github.com/#{lib[:repo]}.git #{src_dir}"
end
FileUtils.mkdir_p(bld_dir)
cmake_flags = %W[
-DCMAKE_INSTALL_PREFIX=#{install_dir}
-DCMAKE_PREFIX_PATH=#{install_dir}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
-DBUILD_SHARED_LIBS=ON
]
# Disable tests, examples, and docs for all libs
cmake_flags += %w[
-DSDL2_DISABLE_INSTALL=OFF
-DSDL_TEST=OFF
-DSDL_TESTS=OFF
-DSDL2TTF_SAMPLES=OFF
-DSDL2IMAGE_SAMPLES=OFF
-DSDL2MIXER_SAMPLES=OFF
]
# SDL2_mixer: disable optional tracker-music support (requires libxmp)
if name == 'SDL2_mixer'
cmake_flags << '-DSDL2MIXER_MOD=OFF'
cmake_flags << '-DSDL2MIXER_MIDI_FLUIDSYNTH=OFF'
cmake_flags << '-DSDL2MIXER_WAVPACK=OFF'
end
sh "cmake -S #{src_dir} -B #{bld_dir} #{cmake_flags.join(' ')}"
sh "cmake --build #{bld_dir} -j #{Etc.nprocessors}"
install_cmd = "cmake --install #{bld_dir}"
install_cmd = "sudo #{install_cmd}" if use_sudo
sh install_cmd
puts "#{name} installed to #{install_dir}"
end
puts "\n=== SDL2 build complete ==="
puts " prefix: #{install_dir}"
puts " verify: pkg-config --libs sdl2"
end
# -- Documentation -----------------------------------------------------------
namespace :docs do
desc "Install docs dependencies (docs_site/Gemfile)"
task :setup do
Dir.chdir('docs_site') do
Bundler.with_unbundled_env { sh 'bundle install' }
end
end
task :yard_clean do
FileUtils.rm_rf('doc')
FileUtils.rm_rf('docs_site/_api')
FileUtils.rm_rf('docs_site/_site')
FileUtils.rm_rf('docs_site/.jekyll-cache')
FileUtils.rm_f('docs_site/assets/js/search-data.json')
FileUtils.rm_f('docs_site/internals.md')
end
# Copy INTERNALS.md from repo root into docs_site/ with Jekyll front matter.
# Source of truth stays at the repo root (visible on GitHub).
task :copy_internals do
content = File.read('INTERNALS.md')
front_matter = "---\nlayout: default\ntitle: Internals\nnav_order: 80\n---\n\n"
File.write('docs_site/internals.md', front_matter + content)
end
desc "Generate YARD JSON (uses docs_site/Gemfile)"
task yard_json: :yard_clean do
Bundler.with_unbundled_env do
sh 'BUNDLE_GEMFILE=docs_site/Gemfile bundle exec yard doc'
end
end
desc "Generate per-method coverage JSON from SimpleCov data"
task :method_coverage do
if Dir.exist?('coverage/results')
require_relative 'lib/gemba/method_coverage_service'
Gemba::MethodCoverageService.new(coverage_dir: 'coverage').call
else
puts "No coverage data found (run tests with COVERAGE=1 first)"
end
end
desc "Generate API docs (YARD JSON -> HTML)"
task yard: [:yard_json, :method_coverage] do
Bundler.with_unbundled_env do
sh 'BUNDLE_GEMFILE=docs_site/Gemfile bundle exec ruby docs_site/build_api_docs.rb'
end
end
# Pulled from teek — no recordings yet, but keeping in case we add demos later.
desc "Bless recordings from recordings/ into docs_site/assets/recordings/"
task :bless_recordings do
require 'fileutils'
src = 'recordings'
dest = 'docs_site/assets/recordings'
FileUtils.mkdir_p(dest)
videos = Dir.glob("#{src}/*.{mp4,webm}")
if videos.empty?
puts "No recordings in #{src}/ to bless."
next
end
videos.each do |path|
FileUtils.cp(path, dest)
puts " #{File.basename(path)} -> #{dest}/"
end
puts "Blessed #{videos.size} recording(s)."
end
desc "Generate recordings gallery page"
task :recordings do
sh 'ruby docs_site/build_recordings.rb'
end
desc "Generate full docs site (YARD + Jekyll)"
task generate: [:yard, :copy_internals] do
Dir.chdir('docs_site') do
Bundler.with_unbundled_env { sh 'bundle exec jekyll build' }
end
puts "Docs generated in docs_site/_site/"
end
desc "Serve docs locally (watches lib/ and ext/ for changes, regenerates API docs)"
task serve: [:yard, :copy_internals] do
require 'listen'
# Use absolute paths so Dir.chdir('docs_site') for Jekyll doesn't confuse Listen.
root = __dir__
gemfile = File.join(root, 'docs_site', 'Gemfile')
rebuild_docs = proc do |modified, added, _removed|
changed = (modified + added).select { |f| f.end_with?('.rb', '.c', '.h', '.erb', '.md') }
next if changed.empty?
puts "\n--- Changed: #{changed.map { |f| f.sub("#{root}/", '') }.join(', ')}"
puts "--- Regenerating API docs..."
Bundler.with_unbundled_env do
system("BUNDLE_GEMFILE=#{gemfile} bundle exec yard doc --quiet", chdir: root) &&
system("BUNDLE_GEMFILE=#{gemfile} bundle exec ruby docs_site/build_api_docs.rb", chdir: root)
end
# Re-copy INTERNALS.md in case it changed
Rake::Task['docs:copy_internals'].execute
puts "--- Done. Jekyll will pick up changes automatically."
end
listener = Listen.to(
File.join(root, 'lib'),
File.join(root, 'ext'),
File.join(root, 'docs_site', 'templates'),
only: /\.(rb|c|h|erb)$/,
&rebuild_docs
)
root_listener = Listen.to(root, only: /\.md$/) do |mod, add, _rem|
# Only care about top-level markdown files (INTERNALS.md, README.md, etc.)
changed = (mod + add).select { |f| File.dirname(f) == root }
rebuild_docs.call(changed, [], []) unless changed.empty?
end
listener.start
root_listener.start
puts "Watching lib/, ext/, docs_site/templates/, *.md for changes"
Dir.chdir(File.join(root, 'docs_site')) do
Bundler.with_unbundled_env { sh 'bundle exec jekyll serve --watch --livereload' }
end
end
end
# Aliases for convenience
task doc: 'docs:yard'
task yard: 'docs:yard'
# -- Docker ------------------------------------------------------------------
# -- Build -------------------------------------------------------------------
desc "Build gem (aborts if working tree is dirty)"
task :build do
unless `git status --porcelain`.strip.empty?
abort "Working tree is dirty. Commit or stash changes before building the gem."
end
sh "gem build gemba.gemspec"
end
desc "Remove libmgba files installed by `rake deps`"
task 'deps:uninstall' do
manifest = File.expand_path('vendor/build/install_manifest.txt', __dir__)
unless File.exist?(manifest)
abort "No install manifest found at #{manifest} — nothing to uninstall."
end
files = File.readlines(manifest, chomp: true)
files.each do |f|
if File.exist?(f)
rm f
puts " removed #{f}"
end
end
# Clean up empty directories left behind
dirs = files.map { |f| File.dirname(f) }.uniq.sort_by { |d| -d.length }
dirs.each { |d| Dir.rmdir(d) if File.directory?(d) && Dir.empty?(d) rescue nil }
puts "Uninstalled #{files.size} file(s) from manifest."
end
desc "Smoke test: build, install, require, load ROM, run 1 frame"
task 'release:smoke' => [:submodules, :build] do
require_relative 'lib/gemba/version'
version = Gemba::VERSION
gem_file = "gemba-#{version}.gem"
test_rom = File.expand_path('test/fixtures/test.gba', __dir__)
abort "Test ROM not found: #{test_rom}" unless File.exist?(test_rom)
abort "Gem not found: #{gem_file}" unless File.exist?(gem_file)
# Clean slate: remove everything and start fresh
sh "gem uninstall gemba --all --executables --force 2>/dev/null || true"
manifest = File.expand_path('vendor/build/install_manifest.txt', __dir__)
Rake::Task['deps:uninstall'].invoke if File.exist?(manifest)
Rake::Task['clobber'].invoke
# Fresh install from scratch
Rake::Task['deps'].invoke
sh "gem install #{gem_file} --no-document"
# Run from a temp dir with a clean env so Ruby loads the installed gem,
# not the local lib/ (Bundler's load path would shadow the gem otherwise).
require 'tmpdir'
smoke_script = File.expand_path('scripts/smoke_test.rb', __dir__)
Dir.mktmpdir('gemba-smoke') do |tmpdir|
Bundler.with_unbundled_env do
sh RbConfig.ruby, smoke_script, version, test_rom, chdir: tmpdir
end
end
end
# -- Docker ------------------------------------------------------------------
namespace :docker do
DOCKERFILE = 'Dockerfile.ci-test'
DOCKER_LABEL = 'project=gemba'
BUILD_DEPS_DIR = '_build_deps'
# Copy local teek/teek-sdl2 source into _build_deps/ for Docker builds.
# Opt-in via LOCAL_DEPS=1 (auto-detect sibling repos) or explicit
# TEEK_PATH / TEEK_SDL2_PATH env vars.
#
# Returns extra --build-arg flags for docker build.
def prepare_build_deps
require 'fileutils'
FileUtils.rm_rf(BUILD_DEPS_DIR)
FileUtils.mkdir_p(BUILD_DEPS_DIR)
build_args = []
use_local = ENV['LOCAL_DEPS'] || ENV['TEEK_PATH'] || ENV['TEEK_SDL2_PATH']
return build_args unless use_local
teek_path = ENV['TEEK_PATH'] || File.expand_path('../teek', Dir.pwd)
teek_sdl2_path = ENV['TEEK_SDL2_PATH'] || File.join(teek_path, 'teek-sdl2')
if File.exist?(File.join(teek_path, 'teek.gemspec'))
puts " Using local teek: #{teek_path}"
sync_dep(teek_path, File.join(BUILD_DEPS_DIR, 'teek'))
build_args += ['--build-arg', 'TEEK_PATH=/deps/teek']
end
if File.exist?(File.join(teek_sdl2_path, 'teek-sdl2.gemspec'))
puts " Using local teek-sdl2: #{teek_sdl2_path}"
sync_dep(teek_sdl2_path, File.join(BUILD_DEPS_DIR, 'teek-sdl2'))
build_args += ['--build-arg', 'TEEK_SDL2_PATH=/deps/teek-sdl2']
end
build_args
end
# Copy only what bundler needs to compile a gem: lib/, ext/, gemspec.
def sync_dep(src, dest)
require 'fileutils'
FileUtils.mkdir_p(dest)
%w[lib ext].each do |subdir|
src_sub = File.join(src, subdir)
FileUtils.cp_r(src_sub, dest) if File.directory?(src_sub)
end
Dir.glob(File.join(src, '*.gemspec')).each { |f| FileUtils.cp(f, dest) }
end
def cleanup_build_deps
FileUtils.rm_rf(BUILD_DEPS_DIR)
end
def docker_image_name(tcl_version, ruby_version = nil)
ruby_version ||= ruby_version_from_env
base = tcl_version == '8.6' ? 'gemba-ci-8' : 'gemba-ci-9'
ruby_version == '4.0' ? base : "#{base}-ruby#{ruby_version}"
end
def warn_if_containers_running(image_name)
running = `docker ps --filter ancestor=#{image_name} --format '{{.ID}} {{.Status}}'`.strip
return if running.empty?
count = running.lines.size
warn "\n #{count} container(s) already running on #{image_name}:"
running.lines.each { |l| warn " #{l.strip}" }
warn " Consider: docker kill $(docker ps -q --filter ancestor=#{image_name})\n"
end
def tcl_version_from_env
version = ENV.fetch('TCL_VERSION', '9.0')
unless ['8.6', '9.0'].include?(version)
abort "Invalid TCL_VERSION='#{version}'. Must be '8.6' or '9.0'."
end
version
end
def ruby_version_from_env
ENV.fetch('RUBY_VERSION', '4.0')
end
desc "Build Docker image (TCL_VERSION=9.0|8.6, RUBY_VERSION=4.0|..., LOCAL_DEPS=1)"
task :build do
tcl_version = tcl_version_from_env
ruby_version = ruby_version_from_env
image_name = docker_image_name(tcl_version, ruby_version)
dep_args = prepare_build_deps
verbose = ENV['VERBOSE'] || ENV['V']
quiet = !verbose
if quiet
puts "Building Docker image for Ruby #{ruby_version}, Tcl #{tcl_version}... (VERBOSE=1 for details)"
else
puts "Building Docker image for Ruby #{ruby_version}, Tcl #{tcl_version}..."
end
cmd = "docker build -f #{DOCKERFILE}"
cmd += " -q" if quiet
cmd += " --label #{DOCKER_LABEL}"
cmd += " --build-arg RUBY_VERSION=#{ruby_version}"
cmd += " --build-arg TCL_VERSION=#{tcl_version}"
dep_args.each_slice(2) { |flag, val| cmd += " #{flag} #{val}" }
cmd += " -t #{image_name} ."
begin
sh cmd, verbose: !quiet
ensure
cleanup_build_deps
end
end
desc "Run tests in Docker (TCL_VERSION=9.0|8.6)"
task test: :build do
tcl_version = tcl_version_from_env
ruby_version = ruby_version_from_env
image_name = docker_image_name(tcl_version, ruby_version)
require 'fileutils'
FileUtils.mkdir_p('coverage')
warn_if_containers_running(image_name)
puts "Running tests in Docker (Ruby #{ruby_version}, Tcl #{tcl_version})..."
screenshots_dir = File.join(Dir.pwd, 'test', 'screenshots')
FileUtils.mkdir_p(screenshots_dir)
cmd = "docker run --rm --init"
cmd += " -v #{Dir.pwd}/coverage:/app/coverage"
cmd += " -v #{screenshots_dir}:/app/test/screenshots"
cmd += " -e TCL_VERSION=#{tcl_version}"
cmd += " -e TEST='#{ENV['TEST']}'" if ENV['TEST']
cmd += " -e TESTOPTS='#{ENV['TESTOPTS']}'" if ENV['TESTOPTS']
cmd += " -e SEED='#{ENV['SEED']}'" if ENV['SEED']
cmd += " -e CI='#{ENV['CI']}'" if ENV['CI']
if ENV['COVERAGE'] == '1'
cmd += " -e COVERAGE=1"
cmd += " -e COVERAGE_NAME=#{ENV['COVERAGE_NAME'] || 'gemba'}"
end
cmd += " #{image_name}"
cmd += " xvfb-run -a bundle exec rake test"
sh cmd
end
desc "Run interactive shell in Docker"
task shell: :build do
tcl_version = tcl_version_from_env
ruby_version = ruby_version_from_env
image_name = docker_image_name(tcl_version, ruby_version)
cmd = "docker run --rm --init -it"
cmd += " -v #{Dir.pwd}/coverage:/app/coverage"
cmd += " -e TCL_VERSION=#{tcl_version}"
cmd += " #{image_name} bash"
sh cmd
end
desc "Force rebuild Docker image (no cache)"
task :rebuild do
tcl_version = tcl_version_from_env
ruby_version = ruby_version_from_env
image_name = docker_image_name(tcl_version, ruby_version)
dep_args = prepare_build_deps
puts "Rebuilding Docker image (no cache)..."
cmd = "docker build -f #{DOCKERFILE} --no-cache"
cmd += " --label #{DOCKER_LABEL}"
cmd += " --build-arg RUBY_VERSION=#{ruby_version}"
cmd += " --build-arg TCL_VERSION=#{tcl_version}"
dep_args.each_slice(2) { |flag, val| cmd += " #{flag} #{val}" }
cmd += " -t #{image_name} ."
begin
sh cmd
ensure
cleanup_build_deps
end
end
desc "Remove dangling Docker images"
task :prune do
sh "docker image prune -f --filter label=#{DOCKER_LABEL}"
end
Rake::Task['docker:test'].enhance { Rake::Task['docker:prune'].invoke }
end
task default: 'docker:test'