1*cc02d7e2SAndroid Build Coastguard Worker# Regenerating project files 2*cc02d7e2SAndroid Build Coastguard Worker 3*cc02d7e2SAndroid Build Coastguard WorkerPrerequisites 4*cc02d7e2SAndroid Build Coastguard Worker- `python` 5*cc02d7e2SAndroid Build Coastguard Worker- `pip install mako` (the template processor) 6*cc02d7e2SAndroid Build Coastguard Worker- `pip install pyyaml` (to read the yaml files) 7*cc02d7e2SAndroid Build Coastguard Worker- `go` (required by boringssl dependency) 8*cc02d7e2SAndroid Build Coastguard Worker 9*cc02d7e2SAndroid Build Coastguard Worker``` 10*cc02d7e2SAndroid Build Coastguard Worker# Regenerate the projects files (and other generated files) using templates 11*cc02d7e2SAndroid Build Coastguard Workertools/buildgen/generate_projects.sh 12*cc02d7e2SAndroid Build Coastguard Worker``` 13*cc02d7e2SAndroid Build Coastguard Worker 14*cc02d7e2SAndroid Build Coastguard Worker# Quick justification 15*cc02d7e2SAndroid Build Coastguard Worker 16*cc02d7e2SAndroid Build Coastguard WorkerWe've approached the problem of the build system from a lot of different 17*cc02d7e2SAndroid Build Coastguard Workerangles. The main issue was that there isn't a single build system that 18*cc02d7e2SAndroid Build Coastguard Workerwas going to single handedly cover all of our usage cases. 19*cc02d7e2SAndroid Build Coastguard Worker 20*cc02d7e2SAndroid Build Coastguard WorkerSo instead we decided to work the following way: 21*cc02d7e2SAndroid Build Coastguard Worker 22*cc02d7e2SAndroid Build Coastguard Worker* A `build.yaml` file at the root is the source of truth for listing all the 23*cc02d7e2SAndroid Build Coastguard Workertargets and files needed to build grpc and its tests, as well as a basic system 24*cc02d7e2SAndroid Build Coastguard Workerfor dependency description. 25*cc02d7e2SAndroid Build Coastguard Worker 26*cc02d7e2SAndroid Build Coastguard Worker* Most of the build systems supported by gRPC (e.g. Makefile, cmake, XCode) have a template defined in this directory. The templates use the information from the `build.yaml` file to generate the project files specific to a given build system. 27*cc02d7e2SAndroid Build Coastguard Worker 28*cc02d7e2SAndroid Build Coastguard WorkerThis way we can maintain as many project system as we see fit, without having 29*cc02d7e2SAndroid Build Coastguard Workerto manually maintain them when we add or remove new code to the repository. 30*cc02d7e2SAndroid Build Coastguard WorkerOnly the structure of the project file is relevant to the template. The actual 31*cc02d7e2SAndroid Build Coastguard Workerlist of source code and targets isn't. 32*cc02d7e2SAndroid Build Coastguard Worker 33*cc02d7e2SAndroid Build Coastguard Worker# Structure of `build.yaml` 34*cc02d7e2SAndroid Build Coastguard Worker 35*cc02d7e2SAndroid Build Coastguard WorkerThe `build.yaml` file has the following structure: 36*cc02d7e2SAndroid Build Coastguard Worker 37*cc02d7e2SAndroid Build Coastguard Worker``` 38*cc02d7e2SAndroid Build Coastguard Workersettings: # global settings, such as version number 39*cc02d7e2SAndroid Build Coastguard Worker ... 40*cc02d7e2SAndroid Build Coastguard Workerfilegroups: # groups of files that are automatically expanded 41*cc02d7e2SAndroid Build Coastguard Worker ... 42*cc02d7e2SAndroid Build Coastguard Workerlibs: # list of libraries to build 43*cc02d7e2SAndroid Build Coastguard Worker ... 44*cc02d7e2SAndroid Build Coastguard Workertargets: # list of targets to build 45*cc02d7e2SAndroid Build Coastguard Worker ... 46*cc02d7e2SAndroid Build Coastguard Worker``` 47*cc02d7e2SAndroid Build Coastguard Worker 48*cc02d7e2SAndroid Build Coastguard WorkerThe `filegroups` are helpful to re-use a subset of files in multiple targets. 49*cc02d7e2SAndroid Build Coastguard WorkerOne `filegroups` entry has the following structure: 50*cc02d7e2SAndroid Build Coastguard Worker 51*cc02d7e2SAndroid Build Coastguard Worker``` 52*cc02d7e2SAndroid Build Coastguard Worker- name: "arbitrary string", # the name of the filegroup 53*cc02d7e2SAndroid Build Coastguard Worker public_headers: # list of public headers defined in that filegroup 54*cc02d7e2SAndroid Build Coastguard Worker - ... 55*cc02d7e2SAndroid Build Coastguard Worker headers: # list of headers defined in that filegroup 56*cc02d7e2SAndroid Build Coastguard Worker - ... 57*cc02d7e2SAndroid Build Coastguard Worker src: # list of source files defined in that filegroup 58*cc02d7e2SAndroid Build Coastguard Worker - ... 59*cc02d7e2SAndroid Build Coastguard Worker``` 60*cc02d7e2SAndroid Build Coastguard Worker 61*cc02d7e2SAndroid Build Coastguard WorkerThe `libs` collection contains the list of all the libraries we describe. Some may be 62*cc02d7e2SAndroid Build Coastguard Workerhelper libraries for the tests. Some may be installable libraries. Some may be 63*cc02d7e2SAndroid Build Coastguard Workerhelper libraries for installable binaries. 64*cc02d7e2SAndroid Build Coastguard Worker 65*cc02d7e2SAndroid Build Coastguard WorkerThe `targets` array contains the list of all the binary targets we describe. Some may 66*cc02d7e2SAndroid Build Coastguard Workerbe installable binaries. 67*cc02d7e2SAndroid Build Coastguard Worker 68*cc02d7e2SAndroid Build Coastguard WorkerOne `libs` or `targets` entry has the following structure (see below for 69*cc02d7e2SAndroid Build Coastguard Workerdetails): 70*cc02d7e2SAndroid Build Coastguard Worker 71*cc02d7e2SAndroid Build Coastguard Worker``` 72*cc02d7e2SAndroid Build Coastguard Workername: "arbitrary string", # the name of the library 73*cc02d7e2SAndroid Build Coastguard Workerbuild: "build type", # in which situation we want that library to be 74*cc02d7e2SAndroid Build Coastguard Worker # built and potentially installed (see below). 75*cc02d7e2SAndroid Build Coastguard Workerlanguage: "...", # the language tag; "c" or "c++" 76*cc02d7e2SAndroid Build Coastguard Workerpublic_headers: # list of public headers to install 77*cc02d7e2SAndroid Build Coastguard Workerheaders: # list of headers used by that target 78*cc02d7e2SAndroid Build Coastguard Workersrc: # list of files to compile 79*cc02d7e2SAndroid Build Coastguard Workerbaselib: boolean, # this is a low level library that has system 80*cc02d7e2SAndroid Build Coastguard Worker # dependencies 81*cc02d7e2SAndroid Build Coastguard Workerfilegroups: # list of filegroups to merge to that project 82*cc02d7e2SAndroid Build Coastguard Worker # note that this will be expanded automatically 83*cc02d7e2SAndroid Build Coastguard Workerdeps: # list of libraries this target depends on 84*cc02d7e2SAndroid Build Coastguard Workerdll: "..." # see below. 85*cc02d7e2SAndroid Build Coastguard Worker``` 86*cc02d7e2SAndroid Build Coastguard Worker 87*cc02d7e2SAndroid Build Coastguard Worker## The `"build"` tag 88*cc02d7e2SAndroid Build Coastguard Worker 89*cc02d7e2SAndroid Build Coastguard WorkerCurrently, the "`build`" tag have these meanings: 90*cc02d7e2SAndroid Build Coastguard Worker 91*cc02d7e2SAndroid Build Coastguard Worker* `"all"`: library to build on `"make all"`, and install on the system. 92*cc02d7e2SAndroid Build Coastguard Worker* `"plugin"`: library to build on `"make all"`, and install, but the corresponding CMake option defaults to off. The option needs to be declared manually at present to allow depending on third-party dependencies. 93*cc02d7e2SAndroid Build Coastguard Worker* `"protoc"`: a protoc plugin to build on `"make all"` and install on the system. 94*cc02d7e2SAndroid Build Coastguard Worker* `"plugin_test"`: A test that should only be built if the associated plugin is enabled. The plugin is mentioned in the `"plugin_option"` tag. 95*cc02d7e2SAndroid Build Coastguard Worker* `"private"`: a library to only build for tests. 96*cc02d7e2SAndroid Build Coastguard Worker* `"test"`: a test binary to run on `"make test"`. 97*cc02d7e2SAndroid Build Coastguard Worker* `"tool"`: a binary to be built upon `"make tools"`. 98*cc02d7e2SAndroid Build Coastguard Worker 99*cc02d7e2SAndroid Build Coastguard WorkerAll of the targets should always be present in the generated project file, if 100*cc02d7e2SAndroid Build Coastguard Workerpossible and applicable. But the build tag is what should group the targets 101*cc02d7e2SAndroid Build Coastguard Workertogether in a single build command. 102*cc02d7e2SAndroid Build Coastguard Worker 103*cc02d7e2SAndroid Build Coastguard Worker## The `"baselib"` boolean 104*cc02d7e2SAndroid Build Coastguard Worker 105*cc02d7e2SAndroid Build Coastguard WorkerThis means this is a library that will provide most of the features for gRPC. 106*cc02d7e2SAndroid Build Coastguard WorkerIn particular, if we're locally building OpenSSL, protobuf or zlib, then we 107*cc02d7e2SAndroid Build Coastguard Workershould merge OpenSSL, protobuf or zlib inside that library. That effect depends 108*cc02d7e2SAndroid Build Coastguard Workeron the `"language"` tag. OpenSSL and zlib are for `"c"` libraries, while 109*cc02d7e2SAndroid Build Coastguard Workerprotobuf is for `"c++"` ones. 110*cc02d7e2SAndroid Build Coastguard Worker 111*cc02d7e2SAndroid Build Coastguard Worker# The template system 112*cc02d7e2SAndroid Build Coastguard Worker 113*cc02d7e2SAndroid Build Coastguard WorkerWe're currently using the [mako templates](http://www.makotemplates.org/) 114*cc02d7e2SAndroid Build Coastguard Workerrenderer. That choice enables us to simply render text files without dragging 115*cc02d7e2SAndroid Build Coastguard Workerwith us a lot of other features. Feel free to explore the current templates 116*cc02d7e2SAndroid Build Coastguard Workerin that directory. 117*cc02d7e2SAndroid Build Coastguard Worker 118*cc02d7e2SAndroid Build Coastguard Worker## The renderer engine 119*cc02d7e2SAndroid Build Coastguard Worker 120*cc02d7e2SAndroid Build Coastguard WorkerAs mentioned, the renderer is using [mako templates](http://www.makotemplates.org/), 121*cc02d7e2SAndroid Build Coastguard Workerbut some glue is needed to process all of that. See the [buildgen folder](../tools/buildgen) 122*cc02d7e2SAndroid Build Coastguard Workerfor more details. We're mainly loading the build.json file, and massaging it, 123*cc02d7e2SAndroid Build Coastguard Workerin order to get the list of properties we need, into a Python dictionary, that 124*cc02d7e2SAndroid Build Coastguard Workeris then passed to the template while rending it. 125*cc02d7e2SAndroid Build Coastguard Worker 126*cc02d7e2SAndroid Build Coastguard Worker## The plugins 127*cc02d7e2SAndroid Build Coastguard Worker 128*cc02d7e2SAndroid Build Coastguard WorkerThe file build.json itself isn't passed straight to the template files. It is 129*cc02d7e2SAndroid Build Coastguard Workerfirst processed and modified by a few plugins. For example, the version 130*cc02d7e2SAndroid Build Coastguard Workerexpander is [a plugin](../tools/buildgen/plugins/expand_version.py). 131*cc02d7e2SAndroid Build Coastguard Worker 132*cc02d7e2SAndroid Build Coastguard WorkerThe structure of a plugin is simple. The plugin must defined the function 133*cc02d7e2SAndroid Build Coastguard Worker`mako_plugin` that takes a Python dictionary. That dictionary represents the 134*cc02d7e2SAndroid Build Coastguard Workercurrent state of the build.json contents. The plugin can alter it to whatever 135*cc02d7e2SAndroid Build Coastguard Workerfeature it needs to add. 136