Class: Origen::RemoteManager

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

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

Constructor Details

#initializeRemoteManager

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

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.



88
89
90
91
92
93
94
95
# File 'lib/origen/remote_manager.rb', line 88

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

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



99
100
101
102
103
104
105
106
107
# File 'lib/origen/remote_manager.rb', line 99

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

Returns:

  • (Boolean)


49
50
51
# File 'lib/origen/remote_manager.rb', line 49

def imports_required?
  Origen.import_manager.required?
end

#named_remotesObject

Returns a hash containing all remotes



76
77
78
# File 'lib/origen/remote_manager.rb', line 76

def named_remotes
  remotes
end

#namesObject

Returns an array of symbols that represent the names of all remotes



71
72
73
# File 'lib/origen/remote_manager.rb', line 71

def names
  named_remotes.keys
end

#origen_root(name) ⇒ Object

Returns the path to origen root for the given import name



81
82
83
# File 'lib/origen/remote_manager.rb', line 81

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
# File 'lib/origen/remote_manager.rb', line 18

def require!
  unless required?
    # Make sure the imports have already been required and added
    # to the load path of the current thread
    unless imports_required?
      fail 'Error: Imports must be required before remotes!'
    end

    while updates_required?
      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]}"
        else
          Origen.log.info "  #{name} - #{remote[:version]}"
        end
      end
      update!
    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

Returns:

  • (Boolean)


43
44
45
# File 'lib/origen/remote_manager.rb', line 43

def required?
  @required
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.

Returns:

  • (Boolean)


113
114
115
116
117
118
119
# File 'lib/origen/remote_manager.rb', line 113

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/origen/remote_manager.rb', line 53

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