Class: Bake::CacheAccess

Inherits:
Object
  • Object
show all
Defined in:
lib/bake/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCacheAccess

Returns a new instance of CacheAccess.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bake/cache.rb', line 26

def initialize()
  qacStr = Bake.options.qac ? "Qac" : ""
  if Bake.options.build_config == ""
    @cacheFilename = Bake.options.main_dir+"/.bake/Default" + qacStr + ".Project.meta.cache"
  else
    @cacheFilename = Bake.options.main_dir+"/.bake/Project.meta." + sanitize_filename(Bake.options.build_config) + qacStr + ".cache"
  end
  if !Bake.options.dry
    Utils.gitIgnore(File.dirname(@cacheFilename), :silent) 
  end
end

Instance Attribute Details

#cacheFilenameObject (readonly)

Returns the value of attribute cacheFilename.



24
25
26
# File 'lib/bake/cache.rb', line 24

def cacheFilename
  @cacheFilename
end

Instance Method Details

#load_cacheObject



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
# File 'lib/bake/cache.rb', line 38

def load_cache
  cache = nil
  begin

    fileExists = File.exist?(@cacheFilename)
    puts "Cache: Checking if cache file #{@cacheFilename} exists: #{fileExists}" if Bake.options.debug
    if fileExists
      cacheTime = File.mtime(@cacheFilename)
      contents = File.open(@cacheFilename, "rb") {|io| io.read }
      cache = Marshal.load(contents)

      puts "Cache: Checking cache version: #{cache.version} vs. #{Version.number}" if Bake.options.debug
      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
        puts "Cache: Checking if cache was moved: #{@cacheFilename} vs. #{cache.cache_file}" if Bake.options.debug
        if cache.cache_file != @cacheFilename
          Bake.formatter.printInfo("Info: cache filename changed, reloading meta information")
          cache = nil
        end
      end

      if cache != nil
        puts "Cache: Checking if referenced configs are up to date..." if Bake.options.debug
        cache.referencedConfigs.each do |pname,configs|
          configs.each do |config|
            fileExists = File.exist?(config.file_name)
            puts "Cache: Checking if #{config.file_name} exists: #{fileExists}" if Bake.options.debug
            if not fileExists
              Bake.options.nocache = true
              Bake.formatter.printInfo("Info: cached meta file #{config.file_name} renamed or deleted, reloading meta information")
              cache = nil
              break
            end
            configTime = File.mtime(config.file_name)
            puts "Cache: Checking if #{config.file_name} was modified: #{configTime} vs #{cacheTime}" if Bake.options.debug
            if configTime > cacheTime + 1
              Bake.formatter.printInfo("Info: #{config.file_name} has been changed, reloading meta information")
              cache = nil
              break
            end
          end
          break if cache == nil
        end
      end

      if (cache != nil)
        puts "Cache: Checking adapt options: #{cache.adaptStrings.inspect} vs. #{Bake.options.adapt.inspect}" if Bake.options.debug
        if (cache.adaptStrings.length != Bake.options.adapt.length) ||
          (cache.adaptStrings.any? { |a| !Bake.options.adapt.include?(a) }) ||
            (Bake.options.adapt.any? { |a| !cache.adaptStrings.include?(a) })
          Bake.formatter.printInfo("Info: adapts flags have been changed, reloading meta information")
          cache = nil
        end
      end

      if (cache != nil)
        cache.adapt_filenames.each do |fHash|
          f = fHash[:file]
          fileExists = File.exist?(f)
          puts "Cache: Checking if #{f} exists: #{fileExists}" if Bake.options.debug
          if !fileExists
            Bake.formatter.printInfo("Info: #{f} does not exist anymore, reloading meta information")
            cache = nil
            break
          end
          adaptTime = File.mtime(f)
          puts "Cache: Checking if #{f} was modified: #{adaptTime} vs #{cacheTime}" if Bake.options.debug
          if adaptTime > cacheTime + 1
            Bake.formatter.printInfo("Info: #{f} has been changed, reloading meta information")
            cache = nil
            break
          end
        end
      end

      if cache != nil
        puts "Cache: Checking root options: #{cache.workspace_roots.inspect} vs. #{Bake.options.roots.inspect}" if Bake.options.debug
        if (!Root.equal(cache.workspace_roots, Bake.options.roots))
          Bake.formatter.printInfo("Info: specified roots differ from cached roots, reloading meta information") if cache.nil?
          cache = nil
        end
      end

      if cache != nil
        puts "Cache: Checking include_filter options: #{cache.include_filter.inspect} vs. #{Bake.options.include_filter.inspect}" if Bake.options.debug
        if (cache.include_filter.length != Bake.options.include_filter.length) ||
          (cache.include_filter.any? { |a| !Bake.options.include_filter.include?(a) }) ||
          (Bake.options.include_filter.any? { |a| !cache.include_filter.include?(a) })
          cache = nil
          Bake.formatter.printInfo("Info: specified include filters differ from cached filters, reloading meta information")
        end
      end

      if cache != nil
        puts "Cache: Checking exclude_filter options: #{cache.exclude_filter.inspect} vs. #{Bake.options.exclude_filter.inspect}" if Bake.options.debug
        if (cache.exclude_filter.length != Bake.options.exclude_filter.length) ||
          (cache.exclude_filter.any? { |a| !Bake.options.exclude_filter.include?(a) }) ||
          (Bake.options.exclude_filter.any? { |a| !cache.exclude_filter.include?(a) })
          cache = nil
          Bake.formatter.printInfo("Info: specified include filters differ from cached filters, reloading meta information")
        end
      end

      if cache != nil
        puts "Cache: Checking autodir option: #{cache.no_autodir} vs. #{Bake.options.no_autodir}" if Bake.options.debug
        if (not Bake.options.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 => e
    Bake.formatter.printWarning("Warning: cache file corrupt, reloading meta information (cache might be written by an older bake version)")
    if Bake.options.debug
      puts e.message
      puts e.backtrace
    end
    cache = nil
  end

  if cache != nil
    Bake.formatter.printInfo("Info: cache is up-to-date, loading cached meta information") if Bake.options.verbose >= 3
    Bake.options.build_config = cache.build_config
    return cache.referencedConfigs
  end

  return nil
end

#write_cache(referencedConfigs, adaptConfigs) ⇒ Object



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
# File 'lib/bake/cache.rb', line 174

def write_cache(referencedConfigs, adaptConfigs)
  return if Bake.options.dry

  cache = Cache.new
  cache.referencedConfigs = referencedConfigs
  cache.adaptStrings = Bake.options.adapt
  cache.adaptConfigs = adaptConfigs
  cache.cache_file = @cacheFilename
  cache.version = Version.number
  cache.include_filter = Bake.options.include_filter
  cache.no_autodir = Bake.options.no_autodir
  cache.exclude_filter = Bake.options.exclude_filter
  cache.workspace_roots = Bake.options.roots
  cache.build_config = Bake.options.build_config
  cache.adapt_filenames = AdaptConfig.filenames
  bbdump = Marshal.dump(cache)
  begin
    File.open(@cacheFilename, 'wb') {|file| file.write(bbdump) }
  rescue Exception=>e
    if Bake.options.verbose >= 3
      Bake.formatter.printWarning("Warning: Could not write cache file #{@cacheFilename}")
      if Bake.options.debug
        puts e.message
        puts e.backtrace
      end
    end
  end
  Bake.options.nocache = false
end