« Prev 4.2.6 Checking for a Package Configuration | Table of Contents | Next » 4.2.8 Global Configuration Check Options |
The Rsconscript
author can add custom configuration checks to be performed
during the rscons configure
operation.
Here is an example from build_tests/configure/custom_config_check.rb
showing
a custom configuration check:
configure do custom_check("Checking 'grep' version") do |op| stdout, stderr, status = op.log_and_test_command(%w[grep --version]) should_fail = true if status != 0 fail_message = "error executing grep" elsif stdout =~ /^grep \(GNU grep\) 1\./ fail_message = "too old!" status = 1 elsif stdout =~ /^grep \(GNU grep\) 2\./ fail_message = "we'll work with it but you should upgrade" status = 1 should_fail = false op.store_merge("CPPDEFINES" => "GREP_WORKAROUND") else op.store_append("CPPDEFINES" => "GREP_FULL") end op.complete(status, success_message: "good!", fail_message: fail_message, fail: should_fail) end custom_check("Checking sed -E flag") do |op| stdout, stderr, status = op.log_and_test_command(%w[sed -E -e s/ab+/rep/], stdin: "abbbc") op.complete(stdout =~ /repc/ ? 0 : 1, success_message: "good", fail_message: "fail") end end env do |env| puts env["CPPDEFINES"] end
A custom configuration check is created by calling the custom_check
method
and passing a block.
The contents of the block should perform the custom configuration checking
logic.
This logic can include executing a test command or other arbitrary operations.
An argument op
is passed to the block.
This object is an instance of the ConfigureOp
class
class and provides several methods that can be used to aid with the custom
configuration check.
The log_and_test_command
method can be used to execute a test command and retrieve its results.
The command and its output are also logged to the config.log file.
The store_merge
,
store_append
,
and store_parse
methods can be used to store construction variables to be used in Environments
created later.
Finally, the complete
method can be used to complete the configuration check and indicate a success
or failure.
While performing a custom configuration check, it can sometimes be useful to
be able to construct an Environment to use the set of default construction
variables as defined so far in the configuration block, for example to expand
construction variables to build a test command.
The normal Environment
class cannot be used within the configure
block,
however the BasicEnvironment
class
can be used for such a purpose.
For example, to expand the current ${CCCMD}
value:
configure do custom_check("Checking something to do with CCCMD") do command = BasicEnvironment.new.expand_varref("${CCCMD}") # ... end end
« Prev 4.2.6 Checking for a Package Configuration | Table of Contents | Next » 4.2.8 Global Configuration Check Options |