Store configure task parameters in configuration cache data - close #151
This commit is contained in:
parent
7e5c6e6b12
commit
5b6353395d
6
build_tests/configure/check_c_compiler_non_default.rb
Normal file
6
build_tests/configure/check_c_compiler_non_default.rb
Normal file
@ -0,0 +1,6 @@
|
||||
configure do
|
||||
check_c_compiler "clang"
|
||||
end
|
||||
env do |env|
|
||||
env.Program("simple.exe", "simple.c")
|
||||
end
|
11
build_tests/tasks/configure_params.rb
Normal file
11
build_tests/tasks/configure_params.rb
Normal file
@ -0,0 +1,11 @@
|
||||
configure params: [
|
||||
param("with-xyz", "xyz", true, "Set xyz"),
|
||||
param("flag", nil, false, "Set flag"),
|
||||
] do
|
||||
check_c_compiler
|
||||
end
|
||||
|
||||
default do
|
||||
puts "xyz: #{Task["configure"]["with-xyz"]}"
|
||||
puts "flag: #{Task["configure"]["flag"].inspect}"
|
||||
end
|
@ -11,12 +11,12 @@ env do |env|
|
||||
end
|
||||
|
||||
task "install", depends: "build" do
|
||||
env.InstallDirectory("${prefix}/bin")
|
||||
env.Install("${prefix}/bin", "^/program.exe")
|
||||
env.InstallDirectory("${prefix}/share")
|
||||
env.Install("${prefix}/share/proj/install.rb", "install.rb")
|
||||
env.Install("${prefix}/mult", ["install.rb", "copy.rb"])
|
||||
env.Install("${prefix}/src", "src")
|
||||
env.InstallDirectory("${configure:prefix}/bin")
|
||||
env.Install("${configure:prefix}/bin", "^/program.exe")
|
||||
env.InstallDirectory("${configure:prefix}/share")
|
||||
env.Install("${configure:prefix}/share/proj/install.rb", "install.rb")
|
||||
env.Install("${configure:prefix}/mult", ["install.rb", "copy.rb"])
|
||||
env.Install("${configure:prefix}/src", "src")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -24,6 +24,7 @@ build steps, but also provides an extensible framework for performing
|
||||
custom build operations as well.
|
||||
|
||||
Rscons takes inspiration from:
|
||||
|
||||
* [SCons](https://scons.org/)
|
||||
* [waf](https://waf.io/)
|
||||
* [rake](https://github.com/ruby/rake)
|
||||
@ -293,6 +294,22 @@ task "two" do
|
||||
end
|
||||
```
|
||||
|
||||
Task parameters can also be referenced via construction variables.
|
||||
Each task parameter is stored in a construction variable.
|
||||
The name for the construction variable is created by joining the task name
|
||||
and the parameter name with a ":" character.
|
||||
For example:
|
||||
|
||||
```ruby
|
||||
task "build", params: [
|
||||
param("heap-size", "1024", true, "Set heap size"),
|
||||
] do
|
||||
env["CPPDEFINES"] << "HEAP_SIZE=${build:heap-size}"
|
||||
env.Program("^/myprog", glob("src/**/*.c"))
|
||||
env.Install("${configure:prefix}/bin/myprog", "^/myprog")
|
||||
end
|
||||
```
|
||||
|
||||
###> Tasks with Special Meaning
|
||||
|
||||
Rscons recognizes special meaning for a few tasks:
|
||||
|
@ -31,7 +31,6 @@ module Rscons
|
||||
|
||||
# Create Application instance.
|
||||
def _initialize
|
||||
@script = Script.new
|
||||
@silent_configure = true
|
||||
@build_dir = ENV["RSCONS_BUILD_DIR"] || "build"
|
||||
ENV.delete("RSCONS_BUILD_DIR")
|
||||
@ -55,6 +54,7 @@ module Rscons
|
||||
# Process exit code (0 on success).
|
||||
def run(rsconscript, tasks_and_params, show_tasks)
|
||||
Cache.instance["failed_commands"] = []
|
||||
@script = Script.new
|
||||
@script.load(rsconscript)
|
||||
if show_tasks
|
||||
show_script_tasks
|
||||
|
@ -12,6 +12,7 @@ module Rscons
|
||||
def initialize(options = {})
|
||||
@varset = VarSet.new(Rscons::DEFAULT_CONSTRUCTION_VARIABLES)
|
||||
load_configuration_data!(options)
|
||||
load_task_param_variables!
|
||||
end
|
||||
|
||||
# Access the value of a construction variable.
|
||||
@ -271,5 +272,14 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
# Load task parameters as construction variables.
|
||||
def load_task_param_variables!
|
||||
Task[].each do |task_name, task|
|
||||
task.param_values.each do |param_name, param_value|
|
||||
self["#{task.name}:#{param_name}"] = param_value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -44,6 +44,7 @@ module Rscons
|
||||
@log_fh = nil
|
||||
cache = Cache.instance
|
||||
cache["configuration_data"]["configured"] = success
|
||||
cache["configuration_data"]["params"] = Task["configure"].param_values
|
||||
cache.write
|
||||
end
|
||||
|
||||
|
@ -144,7 +144,7 @@ module Rscons
|
||||
unless param
|
||||
raise RsconsError.new("Could not find parameter '#{param_name}'")
|
||||
end
|
||||
param.value
|
||||
@param_values[param_name]
|
||||
end
|
||||
|
||||
# Execute a task's actions.
|
||||
|
@ -206,6 +206,11 @@ module Rscons
|
||||
else
|
||||
task = Task.new(name, options, &block)
|
||||
end
|
||||
if name == "configure"
|
||||
if configuration_params = Cache.instance["configuration_data"]["params"]
|
||||
task.param_values.merge!(configuration_params)
|
||||
end
|
||||
end
|
||||
task
|
||||
end
|
||||
|
||||
|
@ -1820,6 +1820,16 @@ EOF
|
||||
expect(Dir.exist?("bb/_configure")).to be_truthy
|
||||
end
|
||||
|
||||
it "applies the configured settings to top-level created environments" do
|
||||
test_dir "configure"
|
||||
|
||||
result = run_rscons(args: %w[-f check_c_compiler_non_default.rb -v])
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to match /Checking for C compiler\.\.\./
|
||||
expect(result.stdout).to match /clang.*simple\.exe/
|
||||
end
|
||||
|
||||
context "check_c_compiler" do
|
||||
{"check_c_compiler.rb" => "when no arguments are given",
|
||||
"check_c_compiler_find_first.rb" => "when arguments are given"}.each_pair do |rsconscript, desc|
|
||||
@ -2995,4 +3005,38 @@ EOF
|
||||
end
|
||||
end
|
||||
|
||||
context "configure task parameters" do
|
||||
it "allows access to configure task parameters from another task" do
|
||||
test_dir "tasks"
|
||||
|
||||
result = run_rscons(args: %w[-f configure_params.rb])
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to match /xyz: xyz/
|
||||
expect(result.stdout).to match /flag: nil/
|
||||
|
||||
result = run_rscons(args: %w[-f configure_params.rb configure --with-xyz=foo --flag default])
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to match /xyz: foo/
|
||||
expect(result.stdout).to match /flag: true/
|
||||
end
|
||||
|
||||
it "stores configure task parameters in the cache for subsequent invocations" do
|
||||
test_dir "tasks"
|
||||
|
||||
result = run_rscons(args: %w[-f configure_params.rb configure --with-xyz=foo --flag default])
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to match /xyz: foo/
|
||||
expect(result.stdout).to match /flag: true/
|
||||
|
||||
result = run_rscons(args: %w[-f configure_params.rb])
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to match /xyz: foo/
|
||||
expect(result.stdout).to match /flag: true/
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user