Class: Rscons::Command

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

Overview

Class to keep track of system commands that builders need to execute. Rscons will manage scheduling these commands to be run in separate threads.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, builder, options = {}) ⇒ Command

Create a ThreadedCommand object.

Parameters:

  • command (Array<String>)

    The command to execute.

  • builder (Builder)

    The Builder executing this command.

  • options (Hash) (defaults to: {})

    Optional parameters.

Options Hash (options):

  • :system_env (Hash)

    Environment Hash to pass to Kernel#system.

  • :system_options (Hash)

    Options Hash to pass to Kernel#system.



44
45
46
47
48
49
# File 'lib/rscons/command.rb', line 44

def initialize(command, builder, options = {})
  @command = command
  @builder = builder
  @system_env = options[:system_env]
  @system_options = options[:system_options]
end

Instance Attribute Details

#builderBuilder (readonly)

Returns Builder executing this command.

Returns:



8
9
10
# File 'lib/rscons/command.rb', line 8

def builder
  @builder
end

#commandArray<String> (readonly)

Returns The command to execute.

Returns:

  • (Array<String>)

    The command to execute.



12
13
14
# File 'lib/rscons/command.rb', line 12

def command
  @command
end

#statusnil, ...

Returns true if the command gives zero exit status. false if the command gives non-zero exit status. nil if command execution fails.

Returns:

  • (nil, true, false)

    true if the command gives zero exit status. false if the command gives non-zero exit status. nil if command execution fails.



18
19
20
# File 'lib/rscons/command.rb', line 18

def status
  @status
end

#system_envHash (readonly)

Returns Environment Hash to pass to Kernel#system.

Returns:

  • (Hash)

    Environment Hash to pass to Kernel#system.



22
23
24
# File 'lib/rscons/command.rb', line 22

def system_env
  @system_env
end

#system_optionsHash (readonly)

Returns Options Hash to pass to Kernel#system.

Returns:

  • (Hash)

    Options Hash to pass to Kernel#system.



26
27
28
# File 'lib/rscons/command.rb', line 26

def system_options
  @system_options
end

#threadThread (readonly)

Returns The thread waiting on this command to terminate.

Returns:

  • (Thread)

    The thread waiting on this command to terminate.



30
31
32
# File 'lib/rscons/command.rb', line 30

def thread
  @thread
end

Instance Method Details

#runThread

Start a thread to run the command.

Returns:

  • (Thread)

    The Thread created to run the command.



55
56
57
58
59
60
61
62
63
# File 'lib/rscons/command.rb', line 55

def run
  env_args = @system_env ? [@system_env] : []
  options_args = @system_options ? [@system_options] : []
  system_args = [*env_args, *Rscons.command_executer, *@command, *options_args]

  @thread = Thread.new do
    system(*system_args)
  end
end