From 918c6294350fa1291c2ec0b54a83c6ebe80339f0 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 1 Jan 2019 16:15:22 -0500 Subject: [PATCH] add verbose CLI option to set Environment default echo mode - close #70 --- lib/rscons/application.rb | 4 ++++ lib/rscons/cli.rb | 5 +++++ lib/rscons/environment.rb | 9 ++++++++- spec/build_tests_spec.rb | 23 +++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index f1d9ccd..bab76c2 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -11,6 +11,10 @@ module Rscons # The number of threads to use when scheduling subprocesses. attr_accessor :n_threads + # @return [Boolean] + # Whether to run verbosely. + attr_accessor :verbose + # @return [VarSet] # Access any variables set on the rscons command-line. attr_reader :vars diff --git a/lib/rscons/cli.rb b/lib/rscons/cli.rb index 7c0e5d9..2c03382 100644 --- a/lib/rscons/cli.rb +++ b/lib/rscons/cli.rb @@ -8,6 +8,7 @@ Global options: --version Show rscons version and exit -h, --help Show rscons help and exit -r COLOR, --color=COLOR Set color mode (off, auto, force) + -v, --verbose Run verbosely Operations: configure Configure the project @@ -78,6 +79,10 @@ module Rscons end end + opts.on("-v", "--verbose") do + Rscons.application.verbose = true + end + opts.on("--version") do puts "Rscons version #{Rscons::VERSION}" exit 0 diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 476f4ce..3deaf19 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -81,7 +81,14 @@ module Rscons add_builder(builder_class.new) end end - @echo = options[:echo] || :short + @echo = + if options[:echo] + options[:echo] + elsif Rscons.application.verbose + :command + else + :short + end @build_root = "#{Cache.instance.configuration_data["build_dir"]}/e.#{@id}" if block_given? diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 5afb0f6..8540001 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1957,4 +1957,27 @@ EOF end end + context "verbose option" do + it "does not echo commands when verbose options not given" do + test_dir('simple') + result = run_rscons + expect(result.stderr).to eq "" + expect(result.stdout).to match /CC .*simple\.o/ + end + + it "echoes commands by default with -v" do + test_dir('simple') + result = run_rscons(rscons_args: %w[-v]) + expect(result.stderr).to eq "" + expect(result.stdout).to match /gcc.*-o.*simple/ + end + + it "echoes commands by default with --verbose" do + test_dir('simple') + result = run_rscons(rscons_args: %w[--verbose]) + expect(result.stderr).to eq "" + expect(result.stdout).to match /gcc.*-o.*simple/ + end + end + end