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.



82
83
84
85
86
87
88
89
# File 'lib/origen/remote_manager.rb', line 82

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



93
94
95
96
97
98
99
100
101
# File 'lib/origen/remote_manager.rb', line 93

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)


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

def imports_required?
  true # Guaranteed by the boot process
end

#named_remotesObject

Returns a hash containing all remotes



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

def named_remotes
  remotes
end

#namesObject

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



65
66
67
# File 'lib/origen/remote_manager.rb', line 65

def names
  named_remotes.keys
end

#origen_root(name) ⇒ Object

Returns the path to origen root for the given import name



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

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

def require!
  unless required?
    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)


37
38
39
# File 'lib/origen/remote_manager.rb', line 37

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)


107
108
109
110
111
112
113
# File 'lib/origen/remote_manager.rb', line 107

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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/origen/remote_manager.rb', line 47

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