For more stable build processs, blade's DSL is designed to be a restricted Python language that prohibits some builtin functions and keywords, include but not limited to:
exec
,execfile
andeval
To improve the consistency of BUILD files.import
Use the built-inblade
module insteadprint
Use the functions inblade.console
module instead
Some builtin functions are restricted.
open
only read mode is allowed
To use some common additional functions, such as os.path.join
, you need to use similar sub-modules in the blade
module.
If you want to add more appropriate modules, please make an Issue.
Even if you use Python 2 to run Blade, you'd better to use the backported Python 3 syntax as much as possible.
To allow unrestricted python in existing BUILD
files, set the global_config.unrestricted_dsl_dirs = [...]
,
to disable DSL restriction globally, set the global_config.restricted_dsl = False
.
The global Blade API module, accessed through blade.
, includes:
current_source_dir()
function: The directory where the current BUILD file is located (relative to the root directory of the workspace)current_target_dir()
function: The output directory where the current BUILD file is located corresponds to (relative to the root directory of the workspace)config
submodule: Read blade configuration informationconsole
submodule: Output diagnostic informationre
submodule: The python regex librarypath
submodule: a Restricted subset ofos.path
Access configuration information, including:
get_section()
function: Get the content of a configuration section, such ascc_config
, which can be read through theget
methodget_item()
function: Get a specific configuration item, such asblade.config.get_item('cc_config','cppflags')
Output diagnostic information, including:
debug()
function: Output debugging message, which is not displayed by default, only output to the screen after using the--verbose
optioninfo()
function: Output informational messagenotice()
function: Output some notiable messagewarning()
function: Output warning messageerror()
function: Output error message, which will cause the build to fail
A subset of the os.path
module, including abspath()
, basename()
, dirname()
, exists()
, join()
, normpath()
, relpath ()
, sep
, splitext()
.
Some auxiliary functions, including:
var_to_list()
function: If type of the argument isstr
, turn it intolist
contains a single element
Get some information about the current workspace, including:
root_dir()
function: Returns the directory of the current root workspacebuild_dir()
function: Returns the name of the build subdirectory under the workspace, such asbuild64_release