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



110
111
112
113
114
115
116
117
118
119
120
121
122
# 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_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



146
147
148
149
150
151
# 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_directoryObject

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



51
52
53
54
55
56
57
58
# 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



101
102
103
# 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_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



105
106
107
# 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_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)


73
74
75
76
77
# 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_directoryObject

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



62
63
64
65
66
67
68
69
# 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_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



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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 = {}) ⇒ Object

Switches the given workspace path to the given version tag



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# 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