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
Source
# File lib/origen/application/environment.rb, line 27 def all_environments envs = [] find('').sort.each do |file| envs << File.basename(file) end envs end
Returns Array
of all environments available
Source
# File lib/origen/application/environment.rb, line 81 def default=(name) if name self.temporary = name else @file = nil end save end
As temporary=
except that the given environment will be set to the workspace default
Source
# 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
Load the default file from the workspace default if it exists and return it, otherwise returns nil
Source
# 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
Prints out the current environment details to the command line
Source
# File lib/origen/application/environment.rb, line 41 def exists?(name) envs = find(name) envs.size > 0 end
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.
Source
# 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
Returns an array of matching environment file paths
Source
# File lib/origen/application/environment.rb, line 176 def forget File.delete(SAVE_FILE) if File.exist?(SAVE_FILE) @default_file = nil end
Remove the workspace default environment
Source
# File lib/origen/application/environment.rb, line 22 def name file.basename('.rb').to_s if file end
Returns the name (the filename) of the current environment
Source
# 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
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.
Source
# File lib/origen/application/environment.rb, line 183 def temporary? @file == @default_file end
Returns true if running with a temporary environment, i.e. if the current environment is not the same as the default environment
Source
# File lib/origen/application/environment.rb, line 49 def unique?(name) envs = find(name) envs.size == 1 end
Similar to the exists? method, this will return true only if the given name resolves to a single valid environment.