Class: Tebako::NativeGemCache
- Inherits:
-
Object
- Object
- Tebako::NativeGemCache
- Defined in:
- lib/tebako/native_gem_cache.rb
Overview
Stores one installed native extension at a time for reuse across lockfiles.
Defined Under Namespace
Classes: LockedSpec
Constant Summary collapse
- SCHEMA_VERSION =
1- BUILD_ENVIRONMENT =
%w[CC CXX CFLAGS CXXFLAGS CPPFLAGS LDFLAGS ARCHFLAGS].freeze
Instance Method Summary collapse
-
#initialize(cache_dir:, gem_home:, lockfile:, ruby_version:) ⇒ NativeGemCache
constructor
A new instance of NativeGemCache.
- #restore ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(cache_dir:, gem_home:, lockfile:, ruby_version:) ⇒ NativeGemCache
Returns a new instance of NativeGemCache.
26 27 28 29 30 31 |
# File 'lib/tebako/native_gem_cache.rb', line 26 def initialize(cache_dir:, gem_home:, lockfile:, ruby_version:) @cache_dir = cache_dir @gem_home = gem_home @lockfile = lockfile @ruby_version = ruby_version end |
Instance Method Details
#restore ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tebako/native_gem_cache.rb', line 33 def restore return 0 unless @cache_dir specs = locked_specs return 0 if specs.empty? FileUtils.mkdir_p(@cache_dir) restored = specs.count { |spec| restore_spec(spec) } Tebako::BuildReporter.record( stage: "native_gems", status: restored.positive? ? "reused" : "missed", reason: "#{restored} cached native gem artifact#{"s" unless restored == 1} restored" ) restored end |
#save ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tebako/native_gem_cache.rb', line 49 def save return 0 unless @cache_dir specs_by_name = locked_specs.group_by { |spec| [spec.name, spec.version.to_s] } return 0 if specs_by_name.empty? saved = installed_native_specs.count do |installed| requested = specs_by_name[[installed.name, installed.version.to_s]]&.first requested && save_spec(installed, requested) end Tebako::BuildReporter.record( stage: "native_gems", status: "saved", reason: "#{saved} native gem artifact#{"s" unless saved == 1} available for reuse" ) saved end |