Class: Origen::RemoteManager
Overview
Responsible for ensuring that all dependencies defined in config.remotes are available.
Workspaces will automatically be created and updated to the correct version as required.
An instance of this class is hooked up to:
Origen.remote_manager
Instance Method Summary collapse
-
#create_symlink(from, to) ⇒ Object
private
Handles all symlink creation since Ruby/Windows is ropey.
-
#delete_symlink(path) ⇒ Object
private
Manually handle symlink deletion to support windows.
-
#imports_required? ⇒ Boolean
Returns true if the imports have already been required and added to the load path of the current thread.
-
#initialize ⇒ RemoteManager
constructor
A new instance of RemoteManager.
-
#named_remotes ⇒ Object
Returns a hash containing all remotes.
-
#names ⇒ Object
Returns an array of symbols that represent the names of all remotes.
-
#origen_root(name) ⇒ Object
Returns the path to origen root for the given import name.
-
#require! ⇒ Object
This will fetch all remotes (if required) It does not add the libs to the load path, and require the environments since remotes are not assumed to be Ruby.
-
#required? ⇒ Boolean
Returns true if the imports have already been required and added to the load path of the current thread.
-
#resolve_remotes! ⇒ Object
Fetches any defined remotes, regardless of whether they are dirty or not.
-
#symlink?(path) ⇒ Boolean
private
Returns true if the given path is a symlink.
- #validate_production_status(force = false) ⇒ Object
Constructor Details
#initialize ⇒ RemoteManager
Returns a new instance of RemoteManager.
11 12 13 |
# File 'lib/origen/remote_manager.rb', line 11 def initialize @required = false end |
Instance Method Details
#create_symlink(from, to) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Handles all symlink creation since Ruby/Windows is ropey. On windows it will create an additional flag file to easily tell us a symlink is active later.
89 90 91 92 93 94 95 96 |
# File 'lib/origen/remote_manager.rb', line 89 def create_symlink(from, to) if Origen.running_on_windows? system("call mklink /D #{to.to_s.gsub('/', '\\')} #{from.to_s.gsub('/', '\\')}") File.new("#{to}_is_a_symlink", 'w') {} else FileUtils.symlink from, to end end |
#delete_symlink(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Manually handle symlink deletion to support windows
100 101 102 103 104 105 106 107 108 |
# File 'lib/origen/remote_manager.rb', line 100 def delete_symlink(path) if Origen.running_on_windows? # Don't use regular rm on windows symlink, will delete into the remote dir! system("call cmd /c rmdir #{path.to_s.gsub('/', '\\')}") FileUtils.rm_f("#{path}_is_a_symlink") else FileUtils.rm_f(path) end end |
#imports_required? ⇒ Boolean
Returns true if the imports have already been required and added to the load path of the current thread
50 51 52 |
# File 'lib/origen/remote_manager.rb', line 50 def imports_required? true # Guaranteed by the boot process end |
#named_remotes ⇒ Object
Returns a hash containing all remotes
77 78 79 |
# File 'lib/origen/remote_manager.rb', line 77 def named_remotes remotes end |
#names ⇒ Object
Returns an array of symbols that represent the names of all remotes
72 73 74 |
# File 'lib/origen/remote_manager.rb', line 72 def names named_remotes.keys end |
#origen_root(name) ⇒ Object
Returns the path to origen root for the given import name
82 83 84 |
# File 'lib/origen/remote_manager.rb', line 82 def origen_root(name) origen_root_for(named_remotes[name]) end |
#require! ⇒ Object
This will fetch all remotes (if required) It does not add the libs to the load path, and require the environments
since remotes are not assumed to be Ruby.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/origen/remote_manager.rb', line 18 def require! unless required? while updates_required? Origen.log.info '*******************************************************************************' Origen.log.info 'The following remotes need to be updated, this will now happen automatically:' dirty_remotes.each do |name, remote| if remote[:path] Origen.log.info " #{name} - #{remote[:path]} (included by #{remote[:importer].name})".green else Origen.log.info " #{name} - #{remote[:version]} (included by #{remote[:importer].name})".green end end Origen.log.info '' update! Origen.log.info '' Origen.log.info 'Finished updating remotes.' Origen.log.info '*******************************************************************************' end @required = true end end |
#required? ⇒ Boolean
Returns true if the imports have already been required and added to the load path of the current thread
44 45 46 |
# File 'lib/origen/remote_manager.rb', line 44 def required? @required end |
#resolve_remotes! ⇒ Object
Fetches any defined remotes, regardless of whether they are dirty or not
123 124 125 126 |
# File 'lib/origen/remote_manager.rb', line 123 def resolve_remotes! resolve_remotes process_remotes end |
#symlink?(path) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if the given path is a symlink. Since Rubies handling of symlinks is ropey we will manually maintain a flag (an empty file that means true when present) to indicate when an import is currently setup as a symlink to a path.
114 115 116 117 118 119 120 |
# File 'lib/origen/remote_manager.rb', line 114 def symlink?(path) if Origen.running_on_windows? File.exist?("#{path}_is_a_symlink") else File.symlink?(path) end end |
#validate_production_status(force = false) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/origen/remote_manager.rb', line 54 def validate_production_status(force = false) if Origen.mode.production? || force remotes.each do |_name, remote| if remote[:path] fail "The following remote is defined as a path, but that is not allowed in production: #{remote}" end version = Origen::VersionString.new(remote[:version]) unless version.valid? fail "The following remote version is not in a valid format: #{remote}" end if version.latest? fail "Latest is not allowed as a remote version in production: #{remote}" end end end end |