Module: FastCov::Compiler
- Defined in:
- lib/fast_cov/compiler.rb
Constant Summary collapse
- EXT_DIR =
File.("../../ext/fast_cov", __dir__)
- LIB_DIR =
lib/
File.("..", __dir__)
- FAST_COV_DIR =
lib/fast_cov/
File.(".", __dir__)
Class Method Summary collapse
- .clean_ext_dir! ⇒ Object
- .compile! ⇒ Object
- .digest_path ⇒ Object
- .extension_exists? ⇒ Boolean
- .read_digest ⇒ Object
- .source_digest ⇒ Object
- .stale? ⇒ Boolean
- .write_digest ⇒ Object
Class Method Details
.clean_ext_dir! ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/fast_cov/compiler.rb', line 25 def self.clean_ext_dir! # Clean stale build artifacts to prevent issues when switching Ruby versions FileUtils.rm_f(Dir.glob(File.join(EXT_DIR, "*.o"))) FileUtils.rm_f(Dir.glob(File.join(EXT_DIR, "*.bundle"))) FileUtils.rm_f(Dir.glob(File.join(EXT_DIR, "*.so"))) FileUtils.rm_f(File.join(EXT_DIR, "Makefile")) FileUtils.rm_f(File.join(EXT_DIR, "mkmf.log")) FileUtils.rm_rf(Dir.glob(File.join(EXT_DIR, "*.dSYM"))) end |
.compile! ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fast_cov/compiler.rb', line 13 def self.compile! clean_ext_dir! Dir.chdir(EXT_DIR) do system(RbConfig.ruby, "extconf.rb") || raise("FastCov: extconf.rb failed") system("make") || raise("FastCov: make failed") system("make install sitearchdir=#{LIB_DIR} sitelibdir=#{LIB_DIR}") || raise("FastCov: make install failed") end write_digest end |
.digest_path ⇒ Object
54 55 56 57 |
# File 'lib/fast_cov/compiler.rb', line 54 def self.digest_path # Keep version-specific so we recompile when switching Ruby versions File.join(FAST_COV_DIR, ".source_digest.#{RUBY_VERSION}") end |
.extension_exists? ⇒ Boolean
44 45 46 |
# File 'lib/fast_cov/compiler.rb', line 44 def self.extension_exists? Dir.glob(File.join(FAST_COV_DIR, "fast_cov.#{RUBY_VERSION}.{bundle,so}")).any? end |
.read_digest ⇒ Object
63 64 65 66 67 |
# File 'lib/fast_cov/compiler.rb', line 63 def self.read_digest File.read(digest_path).strip rescue Errno::ENOENT nil end |
.source_digest ⇒ Object
48 49 50 51 52 |
# File 'lib/fast_cov/compiler.rb', line 48 def self.source_digest files = Dir.glob(File.join(EXT_DIR, "*.{c,h,rb}")).sort combined = files.map { |f| Digest::MD5.file(f).hexdigest }.join Digest::MD5.hexdigest(combined) end |
.stale? ⇒ Boolean
35 36 37 38 39 40 41 42 |
# File 'lib/fast_cov/compiler.rb', line 35 def self.stale? return true unless extension_exists? stored = read_digest return true unless stored stored != source_digest end |
.write_digest ⇒ Object
59 60 61 |
# File 'lib/fast_cov/compiler.rb', line 59 def self.write_digest File.write(digest_path, source_digest) end |