Class: Bake::CacheAccess
- Inherits:
-
Object
- Object
- Bake::CacheAccess
- Defined in:
- lib/bake/cache.rb
Instance Attribute Summary collapse
-
#cacheFilename ⇒ Object
readonly
Returns the value of attribute cacheFilename.
Instance Method Summary collapse
-
#initialize ⇒ CacheAccess
constructor
A new instance of CacheAccess.
- #load_cache ⇒ Object
- #write_cache(project_files, referencedConfigs) ⇒ Object
Constructor Details
#initialize ⇒ CacheAccess
Returns a new instance of CacheAccess.
23 24 25 26 27 28 29 30 31 |
# File 'lib/bake/cache.rb', line 23 def initialize() if Bake..build_config == "" @cacheFilename = Bake..main_dir+"/.bake/Default.Project.meta.cache" else @cacheFilename = Bake..main_dir+"/.bake/Project.meta." + sanitize_filename(Bake..build_config) + ".cache" end FileUtils.mkdir_p(File.dirname(@cacheFilename)) end |
Instance Attribute Details
#cacheFilename ⇒ Object (readonly)
Returns the value of attribute cacheFilename.
21 22 23 |
# File 'lib/bake/cache.rb', line 21 def cacheFilename @cacheFilename end |
Instance Method Details
#load_cache ⇒ Object
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 |
# File 'lib/bake/cache.rb', line 33 def load_cache cache = nil begin allFiles = Dir.glob(File.dirname(@cacheFilename)+"/*.cache") if allFiles.include?(@cacheFilename) cacheTime = File.mtime(@cacheFilename) contents = File.open(@cacheFilename, "rb") {|io| io.read } cache = Marshal.load(contents) if cache.version != Version.number Bake.formatter.printInfo("Info: cache version ("+cache.version+") does not match to bake version ("+Version.number+"), reloading meta information") cache = nil end if cache != nil if cache.cache_file != @cacheFilename Bake.formatter.printInfo("Info: cache filename changed, reloading meta information") cache = nil end end if cache != nil cache.files.each do |c| if (not File.exists?(c)) Bake..nocache = true Bake.formatter.printInfo("Info: cached meta file #{c} renamed or deleted, reloading meta information") cache = nil break end end end if cache != nil cache.referencedConfigs.each do |pname,configs| configs.each do |config| if not File.exists?(config.file_name) Bake..nocache = true Bake.formatter.printInfo("Info: cached meta file #{config.file_name} renamed or deleted, reloading meta information") cache = nil end end end end if cache != nil cache.files.each do |c| if File.mtime(c) > cacheTime + 1 Bake.formatter.printInfo("Info: #{c} has been changed, reloading meta information") cache = nil break end end end if cache != nil if cache.workspace_roots.length == Bake..roots.length cache.workspace_roots.each do |r| if not Bake..roots.include?r cache = nil break end end else cache = nil end Bake.formatter.printInfo("Info: specified roots differ from cached roots, reloading meta information") if cache.nil? end if cache != nil if (not Bake..include_filter.eql?(cache.include_filter)) or (not Bake..exclude_filter.eql?(cache.exclude_filter)) cache = nil Bake.formatter.printInfo("Info: specified filters differ from cached filters, reloading meta information") end end if cache != nil if (not Bake..no_autodir.eql?(cache.no_autodir)) cache = nil Bake.formatter.printInfo("Info: no_autodir option differs in cache, reloading meta information") end end else Bake.formatter.printInfo("Info: cache not found, reloading meta information") end rescue Exception Bake.formatter.printWarning("Warning: cache file corrupt, reloading meta information (cache might be written by an older bake version)") cache = nil end if cache != nil Bake.formatter.printInfo("Info: cache is up-to-date, loading cached meta information") if Bake..verbose >= 3 Bake..build_config = cache.build_config if Bake..build_config == "" return cache.referencedConfigs end return nil end |
#write_cache(project_files, referencedConfigs) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/bake/cache.rb', line 132 def write_cache(project_files, referencedConfigs) cache = Cache.new cache.referencedConfigs = referencedConfigs cache.files = project_files cache.cache_file = @cacheFilename cache.version = Version.number cache.include_filter = Bake..include_filter cache.no_autodir = Bake..no_autodir cache.exclude_filter = Bake..exclude_filter cache.workspace_roots = Bake..roots cache.build_config = Bake..build_config bbdump = Marshal.dump(cache) begin File.delete(@cacheFilename) rescue end File.open(@cacheFilename, 'wb') {|file| file.write(bbdump) } Bake..nocache = false end |