Class: Rscons::Script::GlobalDsl

Inherits:
Object
  • Object
show all
Defined in:
lib/rscons/script.rb

Overview

Global DSL methods.

Direct Known Subclasses

ConfigureDsl, Dsl

Instance Method Summary collapse

Instance Method Details

#path_append(path) ⇒ void

This method returns an undefined value.

Append a path component to the PATH variable.

Parameters:

  • path (String)

    Path to append.



33
34
35
# File 'lib/rscons/script.rb', line 33

def path_append(path)
  path_set(path_components + [File.expand_path(path)])
end

#path_componentsArray<String>

Return path components from the PATH variable.

Returns:

  • (Array<String>)

    Path components from the PATH variable.



13
14
15
# File 'lib/rscons/script.rb', line 13

def path_components
  ENV["PATH"].split(File::PATH_SEPARATOR)
end

#path_prepend(path) ⇒ void

This method returns an undefined value.

Prepend a path component to the PATH variable.

Parameters:

  • path (String)

    Path to prepend.



23
24
25
# File 'lib/rscons/script.rb', line 23

def path_prepend(path)
  path_set([File.expand_path(path)] + path_components)
end

#path_set(new_path) ⇒ void

This method returns an undefined value.

Set the PATH variable.

Parameters:

  • new_path (String, Array<String>)

    New PATH variable value as an array or string.



43
44
45
46
47
48
# File 'lib/rscons/script.rb', line 43

def path_set(new_path)
  if new_path.is_a?(Array)
    new_path = new_path.join(File::PATH_SEPARATOR)
  end
  ENV["PATH"] = new_path
end

#rscons(path, *args) ⇒ Object

Invoke rscons in a subprocess for a subsidiary Rsconscript file.

Parameters:

  • path (String)

    Path to subsidiary Rsconscript to execute, or path to subsidiary directory to run rscons in.

  • args (Array<String>)

    Arguments to pass to rscons subprocess.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rscons/script.rb', line 57

def rscons(path, *args)
  rscons_path = File.expand_path($0)
  path = File.expand_path(path)
  if File.directory?(path)
    command = [*args]
    dir = path
  else
    command = ["-f", path, *args]
    dir = File.dirname(path)
  end
  if File.exist?("#{dir}/rscons")
    rscons_path = "#{dir}/rscons"
  end
  command = [rscons_path] + command
  print_dir = dir != "." && dir != File.expand_path(Dir.pwd)
  if ENV["specs"] and not ENV["dist_specs"] # specs
    command = ["ruby", $LOAD_PATH.map {|p| ["-I", p]}, command].flatten # specs
  end # specs
  puts "rscons: Entering directory '#{dir}'" if print_dir
  result = system(*command, chdir: dir)
  puts "rscons: Leaving directory '#{dir}'" if print_dir
  unless result
    raise RsconsError.new("Failed command: " + command.join(" "))
  end
end