Class: Tebako::CacheManager
- Inherits:
-
Object
- Object
- Tebako::CacheManager
- Defined in:
- lib/tebako/cache_manager.rb
Overview
Cache management
Constant Summary collapse
- E_VERSION_FILE =
".environment.version"
Instance Method Summary collapse
- #clean_cache ⇒ Object
- #clean_output ⇒ Object
- #ensure_version_file ⇒ Object
-
#initialize(deps, src_dir, out_dir) ⇒ CacheManager
constructor
A new instance of CacheManager.
- #version_cache ⇒ Object
- #version_cache_check ⇒ Object
- #version_key ⇒ Object
- #version_mismatch(cached_version) ⇒ Object
- #version_source_mismatch(cached_source) ⇒ Object
- #version_unknown ⇒ Object
Constructor Details
#initialize(deps, src_dir, out_dir) ⇒ CacheManager
37 38 39 40 41 |
# File 'lib/tebako/cache_manager.rb', line 37 def initialize(deps, src_dir, out_dir) @deps = deps @src_dir = src_dir @out_dir = out_dir end |
Instance Method Details
#clean_cache ⇒ Object
43 44 45 46 47 |
# File 'lib/tebako/cache_manager.rb', line 43 def clean_cache puts "Cleaning tebako packaging environment" # Using File.join(deps, "") to ensure that the slashes are appropriate FileUtils.rm_rf([File.join(@deps, ""), File.join(@out_dir, "")], secure: true) end |
#clean_output ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tebako/cache_manager.rb', line 49 def clean_output puts "Cleaning CMake cache and Ruby build files" nmr = "src/_ruby_*" nms = "stash_*" FileUtils.rm_rf(Dir.glob(File.join(@deps, nmr)), secure: true) FileUtils.rm_rf(Dir.glob(File.join(@deps, nms)), secure: true) # Using File.join(output_folder, "") to ensure that the slashes are appropriate FileUtils.rm_rf(File.join(@out_dir, ""), secure: true) end |
#ensure_version_file ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/tebako/cache_manager.rb', line 61 def ensure_version_file version_file_path = File.join(@deps, E_VERSION_FILE) begin File.write(version_file_path, version_key) # puts "Set version information for tebako packaging environment to #{Tebako::VERSION}" rescue StandardError => e puts "#{Tebako::PACKAGING_ERRORS[201]} #{E_VERSION_FILE}: #{e.}" end end |
#version_cache ⇒ Object
76 77 78 79 80 |
# File 'lib/tebako/cache_manager.rb', line 76 def version_cache version_file_path = File.join(@deps, E_VERSION_FILE) file_version = File.open(version_file_path, &:readline).strip file_version.match(/(?<version>.+) at (?<source>.+)/) end |
#version_cache_check ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/tebako/cache_manager.rb', line 82 def version_cache_check match_data = version_cache return version_unknown unless match_data if match_data[:version] != Tebako::VERSION version_mismatch(match_data[:version]) elsif match_data[:source] != @src_dir version_source_mismatch(match_data[:source]) end rescue StandardError version_unknown end |
#version_key ⇒ Object
72 73 74 |
# File 'lib/tebako/cache_manager.rb', line 72 def version_key @version_key ||= "#{Tebako::VERSION} at #{@src_dir}" end |
#version_mismatch(cached_version) ⇒ Object
95 96 97 98 99 |
# File 'lib/tebako/cache_manager.rb', line 95 def version_mismatch(cached_version) puts "Tebako cache was created by a gem version #{cached_version} " \ "and cannot be used for gem version #{Tebako::VERSION}" clean_cache end |
#version_source_mismatch(cached_source) ⇒ Object
101 102 103 104 105 |
# File 'lib/tebako/cache_manager.rb', line 101 def version_source_mismatch(cached_source) puts "CMake cache was created for a different source directory '#{cached_source}' " \ "and cannot be used for '#{@src_dir}'" clean_output end |
#version_unknown ⇒ Object
107 108 109 110 |
# File 'lib/tebako/cache_manager.rb', line 107 def version_unknown puts "CMake cache version was not recognized, cleaning up" clean_cache end |