Class: Rscons::Application

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

Overview

Functionality for an instance of the rscons application invocation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Create Application instance.



25
26
27
28
29
30
# File 'lib/rscons/application.rb', line 25

def initialize
  @n_threads = Util.determine_n_threads
  @vars = VarSet.new
  @operations = Set.new
  @build_step = 0
end

Instance Attribute Details

#do_ansi_colorBoolean

Returns Whether to output ANSI color escape sequences.

Returns:

  • (Boolean)

    Whether to output ANSI color escape sequences.



10
11
12
# File 'lib/rscons/application.rb', line 10

def do_ansi_color
  @do_ansi_color
end

#n_threadsInteger

Returns The number of threads to use when scheduling subprocesses.

Returns:

  • (Integer)

    The number of threads to use when scheduling subprocesses.



14
15
16
# File 'lib/rscons/application.rb', line 14

def n_threads
  @n_threads
end

#varsVarSet (readonly)

Returns Access any variables set on the rscons command-line.

Returns:

  • (VarSet)

    Access any variables set on the rscons command-line.



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

def vars
  @vars
end

#verboseBoolean

Returns Whether to run verbosely.

Returns:

  • (Boolean)

    Whether to run verbosely.



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

def verbose
  @verbose
end

Instance Method Details

#get_next_build_stepObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the next build step number.

This is used internally by the Environment class.



108
109
110
# File 'lib/rscons/application.rb', line 108

def get_next_build_step
  @build_step += 1
end

#get_total_build_stepsInteger

Get the total number of build steps.

Returns:

  • (Integer)

    The total number of build steps.



116
117
118
119
120
# File 'lib/rscons/application.rb', line 116

def get_total_build_steps
  Environment.environments.reduce(@build_step) do |result, env|
    result + env.build_steps_remaining
  end
end

#operation(op) ⇒ Boolean

Check whether a requested operation is active.

Parameters:

  • op (String)

    Operation name.

Returns:

  • (Boolean)

    Whether the requested operation is active.



39
40
41
# File 'lib/rscons/application.rb', line 39

def operation(op)
  @operations.include?(op)
end

#run(operation, script, operation_options, options = {}) ⇒ Integer

Run the specified operation.

Parameters:

  • operation (String)

    The operation to perform (e.g. “clean”, “configure”, “build”, etc…)

  • script (Script)

    The script.

  • operation_options (Hash)

    Option values from the CLI for the operation.

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

    Optional parameters.

  • sub_op (Hash)

    a customizable set of options

Returns:

  • (Integer)

    Process exit code (0 on success).



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rscons/application.rb', line 58

def run(operation, script, operation_options, options = {})
  @start_time = Time.new
  @script = script
  @operations << operation
  puts "Starting '#{operation}' at #{Time.new}" if verbose
  rv =
    case operation
    when "build"
      rv = 0
      unless Cache.instance["configuration_data"]["configured"]
        rv =
          if @script.autoconf
            run("configure", script, operation_options, sub_op: false)
          else
            $stderr.puts "Project must be configured first, and autoconf is disabled"
            1
          end
      end
      if rv == 0
        build(operation_options)
      else
        rv
      end
    when "clean"
      clean
    when "configure"
      configure(operation_options)
    when "distclean"
      distclean
    when "install"
      run("build", script, operation_options, sub_op: false)
    when "uninstall"
      uninstall
    else
      $stderr.puts "Unknown operation: #{operation}"
      1
    end
  if verbose and options[:sub_op].nil?
    time = Time.new
    elapsed = time - @start_time
    puts "'#{operation}' complete at #{time} (#{Util.format_elapsed_time(elapsed)})"
  end
  rv
end