class XcodeArchiveCache::ArtifactCache::LocalStorage

Attributes

archiver[R]

@return [XcodeArchiveCache::ArtifactCache::Archiver]

cache_dir_path[R]

@return [String]

Public Class Methods

new(cache_dir_path) click to toggle source

@param [String] cache_dir_path

# File lib/artifact_cache/local_storage.rb, line 7
def initialize(cache_dir_path)
  @cache_dir_path = cache_dir_path
  @archiver = Archiver.new
end

Public Instance Methods

cached_artifact_path(node) click to toggle source

@param [XcodeArchiveCache::BuildGraph::Node] node

@return [String] cached artifact path, nil if no artifact found in cache dir

# File lib/artifact_cache/local_storage.rb, line 16
def cached_artifact_path(node)
  path = path_inside_cache_dir(node)
  File.exist?(path) ? path : nil
end
store(node, path) click to toggle source

@param [XcodeArchiveCache::BuildGraph::Node] node @param [String] path

# File lib/artifact_cache/local_storage.rb, line 24
def store(node, path)
  archive_path = path_inside_cache_dir(node)
  archive_directory = File.expand_path("..", archive_path)
  unless File.exist?(archive_directory)
    FileUtils.mkdir_p(archive_directory)
  end

  archiver.archive(path, archive_path)
  save_state(node, archive_path)
end

Private Instance Methods

path_inside_cache_dir(node) click to toggle source

@param [XcodeArchiveCache::BuildGraph::Node] node

@return [String]

# File lib/artifact_cache/local_storage.rb, line 49
def path_inside_cache_dir(node)
  File.join(cache_dir_path, node.name, node.sha)
end
save_state(node, archive_path) click to toggle source

@param [XcodeArchiveCache::BuildGraph::Node] node @param [String] archive_path

Simply writes build settings and dependency SHAs to a file Useful for debugging and investigation purposes

# File lib/artifact_cache/local_storage.rb, line 59
def save_state(node, archive_path)
  state_file_path = archive_path + ".state"

  if File.exist?(state_file_path)
    warn "Replacing state file #{state_file_path}"
    FileUtils.rm_f(state_file_path)
  end

  dependency_shas = node.dependencies
                        .map {|dependency| dependency.name + ": " + dependency.sha}
                        .join("\n")
  state = node.build_settings.filtered_to_string + "\n\nDependencies:\n" + dependency_shas + "\n"

  File.write(state_file_path, state)
end