Class: Origen::Application::WorkspaceManager

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

Instance Method Summary collapse

Instance Method Details

#build(path, options = {}) ⇒ Object

Builds a new workspace at the given path



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/origen/application/workspace_manager.rb', line 108

def build(path, options = {})
  options = {
    rc_url:        Origen.app.config.rc_url || Origen.app.config.vault,
    allow_rebuild: false
  }.merge(options)
  if File.exist?(path.to_s) && !options[:allow_rebuild]
    fail "Sorry but #{path} already exists!"
  end
  FileUtils.rm_rf(path.to_s) if File.exist?(path.to_s)
  rc = RevisionControl.new remote: options[:rc_url], local: path.to_s
  rc.build
end

#container_directoryObject

Returns the directory that contains the current application's revision control root (basically just Origen.app.rc.root.parent)



6
7
8
9
10
11
12
13
# File 'lib/origen/application/workspace_manager.rb', line 6

def container_directory
  if Origen.running_on_windows?
    dir = revision_control_root.parent
    Pathname.new(dir.to_s.sub(/\/$/, ''))
  else
    revision_control_root.parent
  end
end

#current_version_of(workspace) ⇒ Object



143
144
145
146
147
148
# File 'lib/origen/application/workspace_manager.rb', line 143

def current_version_of(workspace)
  f = "#{workspace}/.current_version"
  if File.exist?(f)
    File.readlines(f).first.strip
  end
end

#imports_directoryObject

Returns the path to the directory that will be used to contain all imported application workspaces



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

def imports_directory
  return @imports_directory if @imports_directory
  old = "#{container_directory}/#{revision_control_root.basename}_imports_DO_NOT_HAND_MODIFY"
  @imports_directory = "#{container_directory}/.#{revision_control_root.basename}_imports_DO_NOT_HAND_MODIFY"
  FileUtils.rm_rf(old) if File.exist?(old)
  @imports_directory
end

#origen_root(workspace) ⇒ Object

Returns the full path to Origen.root within the given workspace



99
100
101
# File 'lib/origen/application/workspace_manager.rb', line 99

def origen_root(workspace)
  Pathname.new("#{workspace}/#{path_to_origen_root}").cleanpath
end

#path_to_origen_rootObject

Origen.root may not necessarily be the same as the revision control root. This method will return the relative path from the revision control root to Origen.root.



27
28
29
30
31
# File 'lib/origen/application/workspace_manager.rb', line 27

def path_to_origen_root
  path = Origen.root.to_s.sub(revision_control_root.to_s, '').sub(/^(\/|\\)/, '')
  path = '.' if path.empty?
  path
end

#reference_dirObject



103
104
105
# File 'lib/origen/application/workspace_manager.rb', line 103

def reference_dir
  "#{Origen.root}/.ref" # Should probably be set by a config parameter
end

#reference_workspaceObject

Returns the path to the actual reference workspace if it is set, otherwise returns nil



40
41
42
43
44
45
46
47
# File 'lib/origen/application/workspace_manager.rb', line 40

def reference_workspace
  if reference_workspace_set?
    dir = File.readlink(reference_dir)
    dir.gsub!('.ref', '')
    dir.gsub!(/#{Regexp.escape(path_to_origen_root)}\/?$/, '')
    Pathname.new(dir).cleanpath
  end
end

#reference_workspace_proposalObject

Provides a proposal for where the reference workspace should live



34
35
36
# File 'lib/origen/application/workspace_manager.rb', line 34

def reference_workspace_proposal
  "#{container_directory}/#{Origen.app.name}_reference"
end

#reference_workspace_set?Boolean

Returns true if the local reference directory is already pointing to an external workspace.

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/origen/application/workspace_manager.rb', line 71

def reference_workspace_set?
  f = reference_dir
  File.exist?(f) && File.symlink?(f) &&
    File.exist?(File.readlink(f))
end

#remotes_directoryObject

Returns the path to the directory that will be used to contain all remotes workspaces



61
62
63
64
65
66
67
# File 'lib/origen/application/workspace_manager.rb', line 61

def remotes_directory
  return @remotes_directory if @remotes_directory
  old = "#{container_directory}/#{revision_control_root.basename}_remotes_DO_NOT_HAND_MODIFY"
  @remotes_directory = "#{container_directory}/.#{revision_control_root.basename}_remotes_DO_NOT_HAND_MODIFY"
  FileUtils.rm_rf(old) if File.exist?(old)
  @remotes_directory
end

#revision_control_rootObject

Returns the path to the root directory of the revision control system that is managing the application.

This may not necessarily be Origen.root if the application is embedded within a larger project workspace (for example in tool_data/origen)



20
21
22
# File 'lib/origen/application/workspace_manager.rb', line 20

def revision_control_root
  Origen.app.rc ? Origen.app.rc.root : Origen.root
end

#set_reference_workspace(workspace) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/origen/application/workspace_manager.rb', line 77

def set_reference_workspace(workspace)
  f = reference_dir
  if File.exist?(f)
    if File.symlink?(f)
      FileUtils.rm_f(f)
    else
      FileUtils.rm_rf(f)
    end
  end
  remote_ref = "#{origen_root(workspace)}/.ref"
  unless File.exist?(remote_ref)
    FileUtils.mkdir_p(remote_ref)
    `touch #{remote_ref}/dont_delete`  # Make sure the pop does not blow this away
  end
  if Origen.running_on_windows?
    system("call mklink /h #{reference_dir} #{remote_ref}")
  else
    File.symlink(remote_ref, reference_dir)
  end
end

#switch_version(workspace, tag, options = {}) ⇒ Object

Switches the given workspace path to the given version tag



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/origen/application/workspace_manager.rb', line 122

def switch_version(workspace, tag, options = {})
  options = {
    origen_root_only: false, # When true pop the Origen.root dir only instead
    # of the whole application workspace - these may or may
    # not be the same thing depending on the application.
  }.merge(options)
  version_file = "#{workspace}/.current_version"
  FileUtils.rm_f(version_file) if File.exist?(version_file)
  if options[:origen_root_only]
    dir = "#{workspace}/#{path_to_origen_root}"
  else
    dir = workspace
  end
  rc_url = Origen.app.config.rc_url || Origen.app.config.vault
  rc = RevisionControl.new remote: rc_url, local: dir.to_s
  rc.checkout version: tag, force: true
  File.open(version_file, 'w') do |f|
    f.puts tag
  end
end