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
|
end
|
||||||
|
|
||||||
task "install", depends: "build" do
|
task "install", depends: "build" do
|
||||||
env.InstallDirectory("${prefix}/bin")
|
env.InstallDirectory("${configure:prefix}/bin")
|
||||||
env.Install("${prefix}/bin", "^/program.exe")
|
env.Install("${configure:prefix}/bin", "^/program.exe")
|
||||||
env.InstallDirectory("${prefix}/share")
|
env.InstallDirectory("${configure:prefix}/share")
|
||||||
env.Install("${prefix}/share/proj/install.rb", "install.rb")
|
env.Install("${configure:prefix}/share/proj/install.rb", "install.rb")
|
||||||
env.Install("${prefix}/mult", ["install.rb", "copy.rb"])
|
env.Install("${configure:prefix}/mult", ["install.rb", "copy.rb"])
|
||||||
env.Install("${prefix}/src", "src")
|
env.Install("${configure:prefix}/src", "src")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ build steps, but also provides an extensible framework for performing
|
|||||||
custom build operations as well.
|
custom build operations as well.
|
||||||
|
|
||||||
Rscons takes inspiration from:
|
Rscons takes inspiration from:
|
||||||
|
|
||||||
* [SCons](https://scons.org/)
|
* [SCons](https://scons.org/)
|
||||||
* [waf](https://waf.io/)
|
* [waf](https://waf.io/)
|
||||||
* [rake](https://github.com/ruby/rake)
|
* [rake](https://github.com/ruby/rake)
|
||||||
@ -293,6 +294,22 @@ task "two" do
|
|||||||
end
|
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
|
###> Tasks with Special Meaning
|
||||||
|
|
||||||
Rscons recognizes special meaning for a few tasks:
|
Rscons recognizes special meaning for a few tasks:
|
||||||
|
@ -31,7 +31,6 @@ module Rscons
|
|||||||
|
|
||||||
# Create Application instance.
|
# Create Application instance.
|
||||||
def _initialize
|
def _initialize
|
||||||
@script = Script.new
|
|
||||||
@silent_configure = true
|
@silent_configure = true
|
||||||
@build_dir = ENV["RSCONS_BUILD_DIR"] || "build"
|
@build_dir = ENV["RSCONS_BUILD_DIR"] || "build"
|
||||||
ENV.delete("RSCONS_BUILD_DIR")
|
ENV.delete("RSCONS_BUILD_DIR")
|
||||||
@ -55,6 +54,7 @@ module Rscons
|
|||||||
# Process exit code (0 on success).
|
# Process exit code (0 on success).
|
||||||
def run(rsconscript, tasks_and_params, show_tasks)
|
def run(rsconscript, tasks_and_params, show_tasks)
|
||||||
Cache.instance["failed_commands"] = []
|
Cache.instance["failed_commands"] = []
|
||||||
|
@script = Script.new
|
||||||
@script.load(rsconscript)
|
@script.load(rsconscript)
|
||||||
if show_tasks
|
if show_tasks
|
||||||
show_script_tasks
|
show_script_tasks
|
||||||
|
@ -12,6 +12,7 @@ module Rscons
|
|||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@varset = VarSet.new(Rscons::DEFAULT_CONSTRUCTION_VARIABLES)
|
@varset = VarSet.new(Rscons::DEFAULT_CONSTRUCTION_VARIABLES)
|
||||||
load_configuration_data!(options)
|
load_configuration_data!(options)
|
||||||
|
load_task_param_variables!
|
||||||
end
|
end
|
||||||
|
|
||||||
# Access the value of a construction variable.
|
# Access the value of a construction variable.
|
||||||
@ -271,5 +272,14 @@ module Rscons
|
|||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
@ -44,6 +44,7 @@ module Rscons
|
|||||||
@log_fh = nil
|
@log_fh = nil
|
||||||
cache = Cache.instance
|
cache = Cache.instance
|
||||||
cache["configuration_data"]["configured"] = success
|
cache["configuration_data"]["configured"] = success
|
||||||
|
cache["configuration_data"]["params"] = Task["configure"].param_values
|
||||||
cache.write
|
cache.write
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ module Rscons
|
|||||||
unless param
|
unless param
|
||||||
raise RsconsError.new("Could not find parameter '#{param_name}'")
|
raise RsconsError.new("Could not find parameter '#{param_name}'")
|
||||||
end
|
end
|
||||||
param.value
|
@param_values[param_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Execute a task's actions.
|
# Execute a task's actions.
|
||||||
|
@ -206,6 +206,11 @@ module Rscons
|
|||||||
else
|
else
|
||||||
task = Task.new(name, options, &block)
|
task = Task.new(name, options, &block)
|
||||||
end
|
end
|
||||||
|
if name == "configure"
|
||||||
|
if configuration_params = Cache.instance["configuration_data"]["params"]
|
||||||
|
task.param_values.merge!(configuration_params)
|
||||||
|
end
|
||||||
|
end
|
||||||
task
|
task
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1820,6 +1820,16 @@ EOF
|
|||||||
expect(Dir.exist?("bb/_configure")).to be_truthy
|
expect(Dir.exist?("bb/_configure")).to be_truthy
|
||||||
end
|
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
|
context "check_c_compiler" do
|
||||||
{"check_c_compiler.rb" => "when no arguments are given",
|
{"check_c_compiler.rb" => "when no arguments are given",
|
||||||
"check_c_compiler_find_first.rb" => "when arguments are given"}.each_pair do |rsconscript, desc|
|
"check_c_compiler_find_first.rb" => "when arguments are given"}.each_pair do |rsconscript, desc|
|
||||||
@ -2995,4 +3005,38 @@ EOF
|
|||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user