diff --git a/build_tests/tasks/tasks.rb b/build_tests/tasks/tasks.rb new file mode 100644 index 0000000..c49ccea --- /dev/null +++ b/build_tests/tasks/tasks.rb @@ -0,0 +1,20 @@ +task "one" do + puts "one" +end + +task "two", deps: ["one", "three"] do + puts "two" +end + +task "three", desc: "Task three" do + puts "three" +end + +task "four", desc: "Task four", params: [ + param("myparam", "defaultvalue", true, "My special parameter"), + param("myp2", nil, false, "My parameter 2"), +] do |task, params| + puts "four" + puts "myparam:" + params["myparam"].inspect + puts "myp2:" + params["myp2"].inspect +end diff --git a/lib/rscons/cli.rb b/lib/rscons/cli.rb index 21b4de1..b347bb7 100644 --- a/lib/rscons/cli.rb +++ b/lib/rscons/cli.rb @@ -31,7 +31,7 @@ module Rscons while argv.size > 0 if argv[0].start_with?("-") valid_arg = false - if argv[0] =~ /^--(\S+?)(?:=(.*))$/ + if argv[0] =~ /^--(\S+?)(?:=(.*))?$/ param_name, value = $1, $2 if param = Task[task].params[param_name] param.value = value || argv[0] diff --git a/lib/rscons/script.rb b/lib/rscons/script.rb index dc828e7..055d030 100644 --- a/lib/rscons/script.rb +++ b/lib/rscons/script.rb @@ -339,8 +339,11 @@ module Rscons # Perform configure action. def configure(configure_op) cdsl = ConfigureDsl.new(self, configure_op) - Task["configure"].actions.each do |action| - cdsl.instance_eval(&action) + configure_task = Task["configure"] + configure_task.actions.each do |action| + cdsl.instance_eval do + action[configure_task, configure_task.param_values] + end end end diff --git a/lib/rscons/task.rb b/lib/rscons/task.rb index aa70f0a..6d34833 100644 --- a/lib/rscons/task.rb +++ b/lib/rscons/task.rb @@ -146,7 +146,7 @@ module Rscons Rscons.application.configure else @actions.each do |action| - action[] + action[self, param_values] end end end @@ -200,6 +200,18 @@ module Rscons end end + # Get parameter values as a Hash. + # + # @return [Hash] + # Parameter values. + def param_values + param_values = {} + @params.each do |name, param| + param_values[name] = param.value + end + param_values + end + end end diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 5b59040..6aef8fe 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -2841,4 +2841,64 @@ EOF end end + it "executes the requested tasks in the requested order" do + test_dir "tasks" + result = run_rscons(args: %w[-f tasks.rb configure]) + result = run_rscons(args: %w[-f tasks.rb one three]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to eq "one\nthree\n" + result = run_rscons(args: %w[-f tasks.rb three one]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to eq "three\none\n" + end + + it "executes the task's dependencies before the requested task" do + test_dir "tasks" + result = run_rscons(args: %w[-f tasks.rb configure]) + result = run_rscons(args: %w[-f tasks.rb two]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to eq "one\nthree\ntwo\n" + end + + it "does not execute a task more than once" do + test_dir "tasks" + result = run_rscons(args: %w[-f tasks.rb configure]) + result = run_rscons(args: %w[-f tasks.rb one two three]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to eq "one\nthree\ntwo\n" + end + + it "passes task arguments" do + test_dir "tasks" + result = run_rscons(args: %w[-f tasks.rb configure]) + result = run_rscons(args: %w[-f tasks.rb four]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to eq %[four\nmyparam:"defaultvalue"\nmyp2:nil\n] + result = run_rscons(args: %w[-f tasks.rb four --myparam=cli-value --myp2 one]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to eq %[four\nmyparam:"cli-value"\nmyp2:"--myp2"\none\n] + end + + it "displays tasks and their arguments in the help info" do + test_dir "tasks" + result = run_rscons(args: %w[-f tasks.rb -h]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + verify_lines(lines(result.stdout), [ + "Tasks:", + /\bthree\b\s+Task three/, + /\bfour\b\s+Task four/, + /--myparam=MYPARAM\s+My special parameter/, + /--myp2\s+My parameter 2/, + ]) + expect(result.stdout).to_not match /^\s*one\b/ + expect(result.stdout).to_not match /^\s*two\b/ + end + end