class Origen::Application::WorkspaceManager

Public Instance Methods

build(path, options = {}) click to toggle source

Builds a new workspace at the given path

# File lib/origen/application/workspace_manager.rb, line 110
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 options.merge(remote: options[:rc_url], local: path.to_s)
  rc.build
end
container_directory() click to toggle source

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

# 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) click to toggle source
# File lib/origen/application/workspace_manager.rb, line 146
def current_version_of(workspace)
  f = "#{workspace}/.current_version"
  if File.exist?(f)
    File.readlines(f).first.strip
  end
end
imports_directory() click to toggle source

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

# 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) click to toggle source

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

# File lib/origen/application/workspace_manager.rb, line 101
def origen_root(workspace)
  Pathname.new("#{workspace}/#{path_to_origen_root}").cleanpath
end
path_to_origen_root() click to toggle source

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.

# 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_dir() click to toggle source
# File lib/origen/application/workspace_manager.rb, line 105
def reference_dir
  "#{Origen.root}/.ref" # Should probably be set by a config parameter
end
reference_workspace() click to toggle source

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

# 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_proposal() click to toggle source

Provides a proposal for where the reference workspace should live

# File lib/origen/application/workspace_manager.rb, line 34
def reference_workspace_proposal
  "#{container_directory}/#{Origen.app.name}_reference"
end
reference_workspace_set?() click to toggle source

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

# File lib/origen/application/workspace_manager.rb, line 73
def reference_workspace_set?
  f = reference_dir
  File.exist?(f) && File.symlink?(f) &&
    File.exist?(File.readlink(f))
end
remotes_directory() click to toggle source

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

# File lib/origen/application/workspace_manager.rb, line 62
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_root() click to toggle source

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)

# 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) click to toggle source
# File lib/origen/application/workspace_manager.rb, line 79
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 = {}) click to toggle source

Switches the given workspace path to the given version tag

# File lib/origen/application/workspace_manager.rb, line 125
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