Module: Gaudi::Utilities

Defined in:
lib/gaudi/helpers/utilities.rb,
lib/gaudi.rb

Instance Method Summary collapse

Instance Method Details

#env_setup(work_dir) ⇒ Object

Reads the configuration and sets the environment up

This is the system's entry point


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gaudi.rb', line 15

def env_setup work_dir
  #Ensure that stdout and stderr output is properly ordered
  $stdout.sync=true
  $stderr.sync=true
  #Tell rake not to truncate it's task output
  Rake.application.terminal_columns = 999
  unless $configuration
    #we're looking for the configuration
    if ENV['GAUDI_CONFIG']
      system_config=Gaudi::Configuration::SystemConfiguration.load([ENV['GAUDI_CONFIG']])
      system_config.workspace=File.expand_path(work_dir)
      if system_config.auto_rules? 
        include Gaudi::Rules::Build
        all_rules(system_config)
      end
      $configuration=system_config
    else
      raise GaudiError,"Did not specify a configuration.\n Add GAUDI_CONFIG=path/to/config to the commandline or specify the GAUDI_CONFIG environment variable"
    end
  end
end

#mass_require(filelist) ⇒ Object

Requires all files defined in the list printing out errors but without interrupting on error


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/gaudi/helpers/utilities.rb', line 6

def mass_require filelist
  filelist.each do |helper|
    begin
      require helper 
    rescue LoadError
      puts "Could not load #{helper} : #{$!.message}"
    rescue
      puts "Could not load #{helper} : #{$!.message}"
    end
  end
end

#require_tasks(system_config) ⇒ Object

Iterates over system_config.gaudi_modules and requires all tasks


18
19
20
21
22
# File 'lib/gaudi/helpers/utilities.rb', line 18

def require_tasks system_config
  system_config.gaudi_modules.each do |gm|
    mass_require(Rake::FileList["#{system_config.base}/tools/build/lib/#{gm}/tasks/*.rb"])
  end
end

#write_file(filename, content) ⇒ Object

Writes a file making sure the directory is created


24
25
26
27
# File 'lib/gaudi/helpers/utilities.rb', line 24

def write_file filename,content
  mkdir_p(File.dirname(filename),:verbose=>false)
  File.open(filename, 'wb') {|f| f.write(content) }
end