Buck: include_defs()
Support Ukraine. Help Provide Humanitarian Aid to Ukraine.


This will be removed in the future.

NOTE: We recommend that you do not use this function. This function can make your builds difficult to maintain and debug, and it will be deprecated in a future release of Buck. We recommend that you use the load() function instead.

The include_defs() function is used to include macros and constants from another file.

The 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_library(), java_test(), etc., as well as include_defs() itself!

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.


  • path (required) #

    A path, of sorts, to a file containing macros and 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.

  • namespace (defaults to None) #

    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.


Suppose the file core/DEFS contains the following:
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')

  name = 'example',
  # ...
  no_dx = core.JARS_TO_EXCLUDE_FROM_DX,