diff --git a/build_tests/configure/no_configure_output.rb b/build_tests/configure/no_configure_output.rb new file mode 100644 index 0000000..0639a5e --- /dev/null +++ b/build_tests/configure/no_configure_output.rb @@ -0,0 +1,3 @@ +default do + puts "default" +end diff --git a/build_tests/typical/install.rb b/build_tests/typical/install.rb index 525525e..5f2d6f3 100644 --- a/build_tests/typical/install.rb +++ b/build_tests/typical/install.rb @@ -1,5 +1,8 @@ project_name "install_test" +configure do +end + env do |env| env["CPPPATH"] += glob("src/**") diff --git a/lib/rscons.rb b/lib/rscons.rb index 28ea715..e896239 100644 --- a/lib/rscons.rb +++ b/lib/rscons.rb @@ -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. diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index 473d214..905b7a0 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -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 diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index d4cdea1..d1d40e5 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -16,14 +16,18 @@ module Rscons cache = Cache.instance cache["failed_commands"] = [] cache["configuration_data"] = {} - if project_name = script.project_name - Ansi.write($stdout, "Configuring ", :cyan, project_name, :reset, "...\n") - else - $stdout.puts "Configuring project..." + 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| - Ansi.write($stdout, "Setting #{name}... ", :green, param.value, :reset, "\n") + unless Rscons.application.silent_configure + Ansi.write($stdout, "Setting #{name}... ", :green, param.value, :reset, "\n") + end vars[name] = param.value end store_merge(vars) diff --git a/lib/rscons/script.rb b/lib/rscons/script.rb index 876e26e..433e86c 100644 --- a/lib/rscons/script.rb +++ b/lib/rscons/script.rb @@ -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 diff --git a/lib/rscons/task.rb b/lib/rscons/task.rb index c1ebe1e..a119340 100644 --- a/lib/rscons/task.rb +++ b/lib/rscons/task.rb @@ -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| diff --git a/lib/rscons/util.rb b/lib/rscons/util.rb index e394b78..f60f8d8 100644 --- a/lib/rscons/util.rb +++ b/lib/rscons/util.rb @@ -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 diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 96ba08e..babd3c7 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -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])