Class: Origen::Application::VersionTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/application/version_tracker.rb

Overview

Keeps track of production released versions

Constant Summary collapse

STORAGE_FILE =
"#{Origen.root}/.version_tracker"

Instance Method Summary collapse

Instance Method Details

#add_version(version) ⇒ Object

Adds a new version to the tracker


14
15
16
17
18
19
# File 'lib/origen/application/version_tracker.rb', line 14

def add_version(version)
  restore_to_latest
  versions << version
  save
  check_in
end

#check_inObject

Check in the persisted storage container


45
46
47
# File 'lib/origen/application/version_tracker.rb', line 45

def check_in
  Origen.app.rc.checkin(STORAGE_FILE, force: true, unmanaged: true, comment: 'Recorded new version in the version tracker')
end

#restore_to_latestObject

Force the storage container to the latest checked in version


50
51
52
53
54
55
56
# File 'lib/origen/application/version_tracker.rb', line 50

def restore_to_latest
  @storage = nil
  # Check out the latest version of the storage, forcing to Trunk
  system "dssc co -get -force '#{STORAGE_FILE};Trunk:Latest'"
  system "dssc setselector 'Trunk' #{STORAGE_FILE}"
  `chmod 666 #{STORAGE_FILE}`
end

#saveObject

Save the persisted storage container to disk


38
39
40
41
42
# File 'lib/origen/application/version_tracker.rb', line 38

def save
  File.open(STORAGE_FILE, 'w') do |f|
    Marshal.dump(storage, f)
  end
end

#storageObject

Returns the persisted storage container (a Hash)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/origen/application/version_tracker.rb', line 22

def storage
  return @storage if @storage
  if File.exist?(STORAGE_FILE)
    File.open(STORAGE_FILE) do |f|
      begin
        @storage = Marshal.load(f)
      rescue
        @storage = {}
      end
    end
  else
    @storage = {}
  end
end

#versionsObject

Returns an array containing all Production release tags since they started being tracked


9
10
11
# File 'lib/origen/application/version_tracker.rb', line 9

def versions
  storage[:versions] ||= []
end