Add tasks - close #139

This commit is contained in:
josh committed 2022-01-30 13:45:06 -05:00
1 parent f5ab51c477
commit bd9cf55b85
149 files changed
+1578 -1063

No files matched your search

+53 -127
View File
@@ -17,141 +17,57 @@ module Rscons
# The number of threads to use when scheduling subprocesses.
attr_accessor :n_threads
# @return [Script]
# Build script.
attr_reader :script
# @return [Boolean]
# Whether to run verbosely.
attr_accessor :verbose
# @return [VarSet]
# Access any variables set on the rscons command-line.
attr_reader :vars
# Create Application instance.
def initialize
@script = Script.new
@build_dir = ENV["RSCONS_BUILD_DIR"] || "build"
ENV.delete("RSCONS_BUILD_DIR")
@n_threads = Util.determine_n_threads
@vars = VarSet.new
@operations = Set.new
@build_step = 0
end
# Check whether a requested operation is active.
# Run the application.
#
# @param op [String]
# Operation name.
# Execute user-specified tasks.
#
# @return [Boolean]
# Whether the requested operation is active.
def operation(op)
@operations.include?(op)
end
# Run the specified operation.
# @api private
#
# @param operation [String]
# The operation to perform (e.g. "clean", "configure", "build", etc...)
# @param script [Script]
# The script.
# @param operation_options [Hash]
# Option values from the CLI for the operation.
# @param options [Hash]
# Optional parameters.
# @option sub_op [Boolean]
# Whether this operation is not the top-level operation.
# @param tasks [Array<String>]
# List of task(s) to execute.
#
# @return [Integer]
# Process exit code (0 on success).
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)})"
def run(tasks)
Cache.instance["failed_commands"] = []
tasks.each do |task|
Task[task].check_execute
end
rv
0
end
# Get the next build step number.
# Show the last failures.
#
# This is used internally by the {Environment} class.
#
# @api private
def get_next_build_step
@build_step += 1
end
# Get the total number of build steps.
#
# @return [Integer]
# The total number of build steps.
def get_total_build_steps
Environment.environments.reduce(@build_step) do |result, env|
result + env.build_steps_remaining
end
end
private
# Build the project.
#
# @param options [Hash]
# Options.
#
# @return [Integer]
# Exit code.
def build(options)
begin
Cache.instance["failed_commands"] = []
@script.build
Environment.environments.each do |env|
env.process
end
0
rescue RsconsError => e
Ansi.write($stderr, :red, e.message, :reset, "\n")
1
# @return [void]
def show_failure
failed_commands = Cache.instance["failed_commands"]
failed_commands.each_with_index do |command, i|
Ansi.write($stdout, :red, "Failed command (#{i + 1}/#{failed_commands.size}):", :reset, "\n")
$stdout.puts Util.command_to_s(command)
end
end
# Remove all generated files.
#
# @return [Integer]
# Exit code.
# @api private
#
# @return [void]
def clean
cache = Cache.instance
# remove all built files
@@ -168,49 +84,60 @@ module Rscons
end
end
cache.write
0
end
# Remove the build directory and clear the cache.
#
# @return [Integer]
# Exit code.
# @api private
#
# @return [void]
def distclean
cache = Cache.instance
clean
FileUtils.rm_rf(@build_dir)
cache.clear
0
end
# Check if the project needs to be configured.
#
# @api private
#
# @return [void]
def check_configure
unless Cache.instance["configuration_data"]["configured"]
if @script.autoconf
configure
end
end
end
# Configure the project.
#
# @api private
#
# @param options [Hash]
# Options.
#
# @return [Integer]
# Exit code.
def configure(options)
rv = 0
options = options.merge(project_name: @script.project_name)
co = ConfigureOp.new(options)
# @return [void]
def configure
co = ConfigureOp.new(@script)
begin
@script.configure(co)
rescue RsconsError => e
if e.message and e.message != ""
$stderr.puts e.message
end
Ansi.write($stderr, :red, "Configuration failed", :reset, "\n")
rv = 1
co.close(false)
raise e
end
co.close(rv == 0)
rv
co.close(true)
end
# Remove installed files.
#
# @api private
#
# @return [Integer]
# Exit code.
#
# @return [void]
def uninstall
cache = Cache.instance
cache.targets(true).each do |target|
@@ -229,7 +156,6 @@ module Rscons
end
end
cache.write
0
end
end