Only configure if necessary - close #131

This commit is contained in:
Josh Holtrop 2022-02-12 23:18:00 -05:00
parent 5c28e557bd
commit 44f61da571
9 changed files with 44 additions and 7 deletions

View File

@ -0,0 +1,3 @@
default do
puts "default"
end

View File

@ -1,5 +1,8 @@
project_name "install_test"
configure do
end
env do |env|
env["CPPPATH"] += glob("src/**")

View File

@ -49,7 +49,11 @@ module Rscons
# @return [Application]
# The Application singleton.
def application
@application ||= Application.new
unless @application
@application = Application.new
@application._initialize
end
@application
end
# Return whether the given target is a phony target.

View File

@ -21,13 +21,18 @@ module Rscons
# Build script.
attr_reader :script
# @return [Boolean]
# Whether to configure silently.
attr_accessor :silent_configure
# @return [Boolean]
# Whether to run verbosely.
attr_accessor :verbose
# Create Application instance.
def initialize
def _initialize
@script = Script.new
@silent_configure = true
@build_dir = ENV["RSCONS_BUILD_DIR"] || "build"
ENV.delete("RSCONS_BUILD_DIR")
@n_threads = Util.determine_n_threads

View File

@ -16,14 +16,18 @@ module Rscons
cache = Cache.instance
cache["failed_commands"] = []
cache["configuration_data"] = {}
unless Rscons.application.silent_configure
if project_name = script.project_name
Ansi.write($stdout, "Configuring ", :cyan, project_name, :reset, "...\n")
else
$stdout.puts "Configuring project..."
end
end
vars = {}
Task["configure"].params.each do |name, param|
unless Rscons.application.silent_configure
Ansi.write($stdout, "Setting #{name}... ", :green, param.value, :reset, "\n")
end
vars[name] = param.value
end
store_merge(vars)

View File

@ -389,6 +389,7 @@ module Rscons
#
# @return [void]
def load(path)
Rscons.application.silent_configure = true
script_contents = File.read(path, mode: "rb")
TopLevelDsl.new(self).instance_eval(script_contents, path, 1)
end

View File

@ -155,6 +155,7 @@ module Rscons
Task[dependency].check_execute
end
if @name == "configure"
Rscons.application.silent_configure = false
Rscons.application.configure
else
@actions.each do |action|

View File

@ -192,7 +192,15 @@ module Rscons
end
# Create or modify a task.
#
# @api private
#
# @return [Task]
# Created task.
def task(name, options = {}, &block)
if name == "configure"
Rscons.application.silent_configure = false
end
if task = Task.tasks[name]
task.modify(options, &block)
else

View File

@ -1789,6 +1789,14 @@ EOF
end
context "configure operation" do
it "does not print configuring messages when no configure block and configure task not called" do
test_dir "configure"
result = run_rscons(args: %w[-f no_configure_output.rb])
expect(result.stderr).to eq ""
expect(result.status).to eq 0
expect(result.stdout.chomp).to eq "default"
end
it "raises a method not found error for configure methods called outside a configure block" do
test_dir "configure"
result = run_rscons(args: %w[-f scope.rb])