From 1bf1c30242b46d765eeac6723c3b9f33649e2e56 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 13 Mar 2022 20:13:20 -0400 Subject: [PATCH] Load configure task arguments before early configure operations - close #157 --- .../configure/configure_with_top_level_env.rb | 1 + doc/user_guide.md | 3 +++ lib/rscons/application.rb | 20 +++++++++++-------- spec/build_tests_spec.rb | 9 +++++++++ 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/build_tests/configure/configure_with_top_level_env.rb b/build_tests/configure/configure_with_top_level_env.rb index 3afe4bd..5582727 100644 --- a/build_tests/configure/configure_with_top_level_env.rb +++ b/build_tests/configure/configure_with_top_level_env.rb @@ -2,4 +2,5 @@ configure do check_c_compiler end env do |env| + puts "Prefix is #{Task["configure"]["prefix"]}" end diff --git a/doc/user_guide.md b/doc/user_guide.md index 5115a24..959e04c 100644 --- a/doc/user_guide.md +++ b/doc/user_guide.md @@ -446,6 +446,9 @@ end See ${#Configuring the Project} for more details on how to make use of the configuration functionality that Rscons provides. +Configure blocks must be defined in the Rsconscript file before any +environments are created. + ####> Default Task The `default` task is special in that Rscons will execute it if no other task diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index 7de5c6a..d90549b 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -73,6 +73,7 @@ module Rscons # Process exit code (0 on success). def run(rsconscript, tasks_and_params, show_tasks, all_tasks, enabled_variants) Cache.instance["failed_commands"] = [] + @tasks_and_params = tasks_and_params @enabled_variants = enabled_variants if enabled_variants == "" && !tasks_and_params.include?("configure") if cache_enabled_variants = Cache.instance["configuration_data"]["enabled_variants"] @@ -86,7 +87,7 @@ module Rscons show_script_tasks(all_tasks) return 0 end - apply_task_params(tasks_and_params) + apply_task_params(false) @task_execution_phase = true if tasks_and_params.empty? check_process_environments @@ -179,6 +180,7 @@ module Rscons # # @return [void] def check_configure + apply_task_params(true) enable_variants unless Cache.instance["configuration_data"]["configured"] if @script.autoconf @@ -378,13 +380,15 @@ module Rscons end end - def apply_task_params(tasks_and_params) - tasks_and_params.each do |task_name, task_params| - task_params.each do |param_name, param_value| - if param = Task[task_name].params[param_name] - Task[task_name].set_param_value(param_name, param_value) - else - raise RsconsError.new("Unknown parameter #{param_name.inspect} for task #{task_name}") + def apply_task_params(only_configure) + @tasks_and_params.each do |task_name, task_params| + unless only_configure && task_name != "configure" + task_params.each do |param_name, param_value| + if param = Task[task_name].params[param_name] + Task[task_name].set_param_value(param_name, param_value) + else + raise RsconsError.new("Unknown parameter #{param_name.inspect} for task #{task_name}") + end end end end diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 2f40f96..eb9095b 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1845,6 +1845,15 @@ EOF expect(result.stdout).to_not match %r{Configuring project.*Configuring project}m end + it "loads configure parameters before invoking configure" do + test_dir "configure" + + result = run_rscons(args: %w[-f configure_with_top_level_env.rb configure --prefix=/yodabob]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match "Prefix is /yodabob" + end + it "automatically runs the configure task if the project is not yet configured in the given build directory" do test_dir "configure"