include_defs()function is used to include
macrosand constants from another file.
include_defs() function executes a file of build-file-style code in the context of the current build file. Therefore, code in the included file may reference Buck functions, such as
java_test(), etc., as well as
The motivation behind
include_defs() is to avoid copy-and-pasting code across multiple build files. Often, included files will contain data declarations (as shown in the example below) or definitions of macros for creating more complex build rules.
A path, of sorts, to a file containing
macrosand constants. It looks similar to a build target because it starts with
//(indicating the root of the project), but is not a proper build target because it identifies a file relative to the root of the project rather than a build rule.
A string representing a namespace in which the bindings from the other file will be stored. When set, an object of the given name that holds the bindings from the other file is put into the global scope of the current file. If unset, the bindings from the other file are injected directly into global scope of the current file.
If the name is already in scope, it is simply overwritten.
ExamplesSuppose the file
core/DEFScontains the following:
JARS_TO_EXCLUDE_FROM_DX = [ 'third_party/guava/guava-14.0.1.jar', 'third_party/jackson/jackson-core-2.7.8.jar', 'third_party/jackson/jackson-databind-2.7.8.jar', 'third_party/jackson/jackson-datatype-guava-2.0.4.jar', ]Then another build file could include the array using
include_defs(). This eliminates the need to copy-and-paste definitions across build files:
include_defs('//core/DEFS', 'core') android_binary( name = 'example', # ... no_dx = core.JARS_TO_EXCLUDE_FROM_DX, )