class Origen::Application::Environment

Class to control the environment.

The environment is a Ruby file that is loaded prior to generating every piece of output. It is optional, and is loaded before the target, thereby allowing targets to override environment settings.

A typical use case for the environment is to setup the test platform, or to set Origen to run in debug or simulation mode. It can generally be thought of as a global target.

All environment definition files must live in Origen.root/environment.

An instance of this class is automatically instantiated and available globally as Origen.environment.

Public Instance Methods

all_environments() click to toggle source

Returns Array of all environments available

# File lib/origen/application/environment.rb, line 27
def all_environments
  envs = []
  find('').sort.each do |file|
    envs << File.basename(file)
  end
  envs
end
default=(name) click to toggle source

As temporary= except that the given environment will be set to the workspace default

# File lib/origen/application/environment.rb, line 81
def default=(name)
  if name
    self.temporary = name
  else
    @file = nil
  end
  save
end
default_file() click to toggle source

Load the default file from the workspace default if it exists and return it, otherwise returns nil

# File lib/origen/application/environment.rb, line 134
def default_file
  return @default_file if @default_file

  if File.exist?(SAVE_FILE)
    File.open(SAVE_FILE) do |f|
      @default_file = Marshal.load(f)
    end
  elsif File.exist?(DEFAULT_FILE)
    @default_file = Pathname.new(DEFAULT_FILE)
  end
  @default_file
end
describe() click to toggle source

Prints out the current environment details to the command line

# File lib/origen/application/environment.rb, line 91
def describe
  f = file!
  puts "Current environment: #{f.basename}"
  puts '*' * 70
  File.open(f).each do |line|
    puts "  #{line}"
  end
  puts '*' * 70
end
exist?(name)
Alias for: exists?
exists?(name) click to toggle source

Returns true if the environment exists, this can be used to test for the presence of an environment before calling one of the other methods to actually apply it.

It will return true if one or more environments are found matching the given name, use the unique? method to test if the given name uniquely identifies a valid environment.

# File lib/origen/application/environment.rb, line 41
def exists?(name)
  envs = find(name)
  envs.size > 0
end
Also aliased as: exist?
find(name) click to toggle source

Returns an array of matching environment file paths

# File lib/origen/application/environment.rb, line 102
def find(name)
  if name
    name = name.gsub('*', '')
    if File.exist?(name)
      [name]
    elsif File.exist?("#{Origen.root}/environment/#{name}") && name != ''
      ["#{Origen.root}/environment/#{name}"]
    else
      # The below weirdness is to make it recurse into symlinked directories
      Dir.glob("#{DIR}/**{,/*/**}/*").sort.uniq.select do |file|
        File.basename(file) =~ /#{name}/ && file !~ /.*\.rb.+$/
      end
    end
  else
    [nil]
  end
end
forget() click to toggle source

Remove the workspace default environment

# File lib/origen/application/environment.rb, line 176
def forget
  File.delete(SAVE_FILE) if File.exist?(SAVE_FILE)
  @default_file = nil
end
name() click to toggle source

Returns the name (the filename) of the current environment

# File lib/origen/application/environment.rb, line 22
def name
  file.basename('.rb').to_s if file
end
switch(name)
Alias for: temporary=
switch_to(name)
Alias for: temporary=
temporary=(name) click to toggle source

Switch to the supplied environment, name can be a fragment as long as it allows a unique environment to be identified.

Calling this method does not affect the default environment setting in the workspace.

# File lib/origen/application/environment.rb, line 58
def temporary=(name)
  envs = find(name)
  if envs.size == 0
    puts "Sorry no environments were found matching '#{name}'!"
    puts 'Here are the available options:'
    find('').sort.each do |file|
      puts File.basename(file)
    end
    exit 1
  elsif envs.size > 1
    puts 'Please try again with one of the following environments:'
    envs.sort.each do |file|
      puts File.basename(file)
    end
    exit 1
  else
    self.file = envs[0]
  end
end
Also aliased as: switch, switch_to
temporary?() click to toggle source

Returns true if running with a temporary environment, i.e. if the current environment is not the same as the default environment

# File lib/origen/application/environment.rb, line 183
def temporary?
  @file == @default_file
end
unique?(name) click to toggle source

Similar to the exists? method, this will return true only if the given name resolves to a single valid environment.

# File lib/origen/application/environment.rb, line 49
def unique?(name)
  envs = find(name)
  envs.size == 1
end