Build Rule

A build rule is a procedure for producing an output file from a set of input files.

Buck comes with a number of built-in build rules, as there are many common procedures when building Android code. For example, compiling Java code against the Android SDK is one of the most common operations, so the build rule android_library exists to facilitate that. Similarly, the primary objective of most Android developers is to create an APK, so the build rule android_binary can be used to do that.

Build rules are defined using built-in Python functions in a build file. (Both the Python function to define the rule and the corresponding Java object that is ultimately created to carry out the procedure are referred to as "the build rule," even though they are technically different things.) Every build rule takes at least the following three arguments:

  • name The name of the build rule, which must be unique within a build file.
  • deps The build rule's dependencies, expressed as a list of build targets.
  • visibility The set of build rules that are allowed to claim this rule as a dependency, expressed as a list of build target patterns.

In Buck, every build rule can produce zero or one output files. These output files can be used by other rules that declare the rule responsible for the output file as a dependency. For example, the output of an android_library is a JAR file, so an android_binary that declares the android_library as a dependency can include the .class files from the android_library's JAR file in its resulting APK. Or when one android_library depends on another, the JAR of dependent rule will be included on the classpath when the rule that depends on it compiles its Java code. Check the documentation for each build rule to see how it uses its deps. Note that no matter how a rule uses its deps, every rule in a rule's deps is guaranteed to be built before the rule attempts to build itself.

Build rules and their dependencies define a directed graph. Buck requires that this graph be acyclic. This helps Buck build efficiently, as it makes it easier to build independent subgraphs in parallel.

Although Buck tries to provide a rich set of built-in build rules for Android developers, it will not be able to address all possible needs. As an "escape hatch," Buck also provides a vanilla build rule called a genrule, which can be used to build an arbitrary file using a Bash script.

Finally, note that build files are evaluated as Python files. This means that you can define your own functions within build files that generate build rules. This should not be something that you need to do often, but taking advantage of this may help you add something to Buck's build process without editing its source code. For more details on this topic, see the article on macros.

::...
免责声明:
当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
内容版权归原作者所有;
本人对内容的有效性/合法性不承担任何强制性责任.
若有不妥, 欢迎评注提醒:

或是邮件反馈可也:
askdama[AT]googlegroups.com


订阅 substack 体验古早写作:


点击注册~> 获得 100$ 体验券: DigitalOcean Referral Badge

关注公众号, 持续获得相关各种嗯哼:
zoomquiet


自怼圈/年度番新

DU22.4
关于 ~ DebugUself with DAMA ;-)
粤ICP备18025058号-1
公安备案号: 44049002000656 ...::