1*4882a593Smuzhiyun.. SPDX-License-Identifier: CC-BY-SA-2.0-UK 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun******************************************* 4*4882a593SmuzhiyunUnderstanding the Yocto Project Autobuilder 5*4882a593Smuzhiyun******************************************* 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunExecution Flow within the Autobuilder 8*4882a593Smuzhiyun===================================== 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunThe "a-full" and "a-quick" targets are the usual entry points into the 11*4882a593SmuzhiyunAutobuilder and it makes sense to follow the process through the system 12*4882a593Smuzhiyunstarting there. This is best visualized from the Autobuilder Console 13*4882a593Smuzhiyunview (:yocto_ab:`/typhoon/#/console`). 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunEach item along the top of that view represents some "target build" and 16*4882a593Smuzhiyunthese targets are all run in parallel. The 'full' build will trigger the 17*4882a593Smuzhiyunmajority of them, the "quick" build will trigger some subset of them. 18*4882a593SmuzhiyunThe Autobuilder effectively runs whichever configuration is defined for 19*4882a593Smuzhiyuneach of those targets on a separate buildbot worker. To understand the 20*4882a593Smuzhiyunconfiguration, you need to look at the entry on ``config.json`` file 21*4882a593Smuzhiyunwithin the ``yocto-autobuilder-helper`` repository. The targets are 22*4882a593Smuzhiyundefined in the ‘overrides' section, a quick example could be qemux86-64 23*4882a593Smuzhiyunwhich looks like:: 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun "qemux86-64" : { 26*4882a593Smuzhiyun "MACHINE" : "qemux86-64", 27*4882a593Smuzhiyun "TEMPLATE" : "arch-qemu", 28*4882a593Smuzhiyun "step1" : { 29*4882a593Smuzhiyun "extravars" : [ 30*4882a593Smuzhiyun "IMAGE_FSTYPES:append = ' wic wic.bmap'" 31*4882a593Smuzhiyun ] 32*4882a593Smuzhiyun } 33*4882a593Smuzhiyun }, 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunAnd to expand that, you need the "arch-qemu" entry from 36*4882a593Smuzhiyunthe "templates" section, which looks like:: 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun "arch-qemu" : { 39*4882a593Smuzhiyun "BUILDINFO" : true, 40*4882a593Smuzhiyun "BUILDHISTORY" : true, 41*4882a593Smuzhiyun "step1" : { 42*4882a593Smuzhiyun "BBTARGETS" : "core-image-sato core-image-sato-dev core-image-sato-sdk core-image-minimal core-image-minimal-dev core-image-sato:do_populate_sdk", 43*4882a593Smuzhiyun "SANITYTARGETS" : "core-image-minimal:do_testimage core-image-sato:do_testimage core-image-sato-sdk:do_testimage core-image-sato:do_testsdk" 44*4882a593Smuzhiyun }, 45*4882a593Smuzhiyun "step2" : { 46*4882a593Smuzhiyun "SDKMACHINE" : "x86_64", 47*4882a593Smuzhiyun "BBTARGETS" : "core-image-sato:do_populate_sdk core-image-minimal:do_populate_sdk_ext core-image-sato:do_populate_sdk_ext", 48*4882a593Smuzhiyun "SANITYTARGETS" : "core-image-sato:do_testsdk core-image-minimal:do_testsdkext core-image-sato:do_testsdkext" 49*4882a593Smuzhiyun }, 50*4882a593Smuzhiyun "step3" : { 51*4882a593Smuzhiyun "BUILDHISTORY" : false, 52*4882a593Smuzhiyun "EXTRACMDS" : ["${SCRIPTSDIR}/checkvnc; DISPLAY=:1 oe-selftest ${HELPERSTMACHTARGS} -j 15"], 53*4882a593Smuzhiyun "ADDLAYER" : ["${BUILDDIR}/../meta-selftest"] 54*4882a593Smuzhiyun } 55*4882a593Smuzhiyun }, 56*4882a593Smuzhiyun 57*4882a593SmuzhiyunCombining these two entries you can see that "qemux86-64" is a three step build where the 58*4882a593Smuzhiyun``bitbake BBTARGETS`` would be run, then ``bitbake SANITYTARGETS`` for each step; all for 59*4882a593Smuzhiyun``MACHINE="qemx86-64"`` but with differing SDKMACHINE settings. In step 60*4882a593Smuzhiyun1 an extra variable is added to the ``auto.conf`` file to enable wic 61*4882a593Smuzhiyunimage generation. 62*4882a593Smuzhiyun 63*4882a593SmuzhiyunWhile not every detail of this is covered here, you can see how the 64*4882a593Smuzhiyuntemplate mechanism allows quite complex configurations to be built up 65*4882a593Smuzhiyunyet allows duplication and repetition to be kept to a minimum. 66*4882a593Smuzhiyun 67*4882a593SmuzhiyunThe different build targets are designed to allow for parallelization, 68*4882a593Smuzhiyunso different machines are usually built in parallel, operations using 69*4882a593Smuzhiyunthe same machine and metadata are built sequentially, with the aim of 70*4882a593Smuzhiyuntrying to optimize build efficiency as much as possible. 71*4882a593Smuzhiyun 72*4882a593SmuzhiyunThe ``config.json`` file is processed by the scripts in the Helper 73*4882a593Smuzhiyunrepository in the ``scripts`` directory. The following section details 74*4882a593Smuzhiyunhow this works. 75*4882a593Smuzhiyun 76*4882a593SmuzhiyunAutobuilder Target Execution Overview 77*4882a593Smuzhiyun===================================== 78*4882a593Smuzhiyun 79*4882a593SmuzhiyunFor each given target in a build, the Autobuilder executes several 80*4882a593Smuzhiyunsteps. These are configured in ``yocto-autobuilder2/builders.py`` and 81*4882a593Smuzhiyunroughly consist of: 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun#. *Run clobberdir*. 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun This cleans out any previous build. Old builds are left around to 86*4882a593Smuzhiyun allow easier debugging of failed builds. For additional information, 87*4882a593Smuzhiyun see :ref:`test-manual/understand-autobuilder:clobberdir`. 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun#. *Obtain yocto-autobuilder-helper* 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun This step clones the ``yocto-autobuilder-helper`` git repository. 92*4882a593Smuzhiyun This is necessary to prevent the requirement to maintain all the 93*4882a593Smuzhiyun release or project-specific code within Buildbot. The branch chosen 94*4882a593Smuzhiyun matches the release being built so we can support older releases and 95*4882a593Smuzhiyun still make changes in newer ones. 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun#. *Write layerinfo.json* 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun This transfers data in the Buildbot UI when the build was configured 100*4882a593Smuzhiyun to the Helper. 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun#. *Call scripts/shared-repo-unpack* 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun This is a call into the Helper scripts to set up a checkout of all 105*4882a593Smuzhiyun the pieces this build might need. It might clone the BitBake 106*4882a593Smuzhiyun repository and the OpenEmbedded-Core repository. It may clone the 107*4882a593Smuzhiyun Poky repository, as well as additional layers. It will use the data 108*4882a593Smuzhiyun from the ``layerinfo.json`` file to help understand the 109*4882a593Smuzhiyun configuration. It will also use a local cache of repositories to 110*4882a593Smuzhiyun speed up the clone checkouts. For additional information, see 111*4882a593Smuzhiyun :ref:`test-manual/understand-autobuilder:Autobuilder Clone Cache`. 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun This step has two possible modes of operation. If the build is part 114*4882a593Smuzhiyun of a parent build, it's possible that all the repositories needed may 115*4882a593Smuzhiyun already be available, ready in a pre-prepared directory. An "a-quick" 116*4882a593Smuzhiyun or "a-full" build would prepare this before starting the other 117*4882a593Smuzhiyun sub-target builds. This is done for two reasons: 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun - the upstream may change during a build, for example, from a forced 120*4882a593Smuzhiyun push and this ensures we have matching content for the whole build 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun - if 15 Workers all tried to pull the same data from the same repos, 123*4882a593Smuzhiyun we can hit resource limits on upstream servers as they can think 124*4882a593Smuzhiyun they are under some kind of network attack 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun This pre-prepared directory is shared among the Workers over NFS. If 127*4882a593Smuzhiyun the build is an individual build and there is no "shared" directory 128*4882a593Smuzhiyun available, it would clone from the cache and the upstreams as 129*4882a593Smuzhiyun necessary. This is considered the fallback mode. 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun#. *Call scripts/run-config* 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun This is another call into the Helper scripts where it's expected that 134*4882a593Smuzhiyun the main functionality of this target will be executed. 135*4882a593Smuzhiyun 136*4882a593SmuzhiyunAutobuilder Technology 137*4882a593Smuzhiyun====================== 138*4882a593Smuzhiyun 139*4882a593SmuzhiyunThe Autobuilder has Yocto Project-specific functionality to allow builds 140*4882a593Smuzhiyunto operate with increased efficiency and speed. 141*4882a593Smuzhiyun 142*4882a593Smuzhiyunclobberdir 143*4882a593Smuzhiyun---------- 144*4882a593Smuzhiyun 145*4882a593SmuzhiyunWhen deleting files, the Autobuilder uses ``clobberdir``, which is a 146*4882a593Smuzhiyunspecial script that moves files to a special location, rather than 147*4882a593Smuzhiyundeleting them. Files in this location are deleted by an ``rm`` command, 148*4882a593Smuzhiyunwhich is run under ``ionice -c 3``. For example, the deletion only 149*4882a593Smuzhiyunhappens when there is idle IO capacity on the Worker. The Autobuilder 150*4882a593SmuzhiyunWorker Janitor runs this deletion. See :ref:`test-manual/understand-autobuilder:Autobuilder Worker Janitor`. 151*4882a593Smuzhiyun 152*4882a593SmuzhiyunAutobuilder Clone Cache 153*4882a593Smuzhiyun----------------------- 154*4882a593Smuzhiyun 155*4882a593SmuzhiyunCloning repositories from scratch each time they are required was slow 156*4882a593Smuzhiyunon the Autobuilder. We therefore have a stash of commonly used 157*4882a593Smuzhiyunrepositories pre-cloned on the Workers. Data is fetched from these 158*4882a593Smuzhiyunduring clones first, then "topped up" with later revisions from any 159*4882a593Smuzhiyunupstream when necessary. The cache is maintained by the Autobuilder 160*4882a593SmuzhiyunWorker Janitor. See :ref:`test-manual/understand-autobuilder:Autobuilder Worker Janitor`. 161*4882a593Smuzhiyun 162*4882a593SmuzhiyunAutobuilder Worker Janitor 163*4882a593Smuzhiyun-------------------------- 164*4882a593Smuzhiyun 165*4882a593SmuzhiyunThis is a process running on each Worker that performs two basic 166*4882a593Smuzhiyunoperations, including background file deletion at IO idle (see :ref:`test-manual/understand-autobuilder:Autobuilder Target Execution Overview`: Run clobberdir) and 167*4882a593Smuzhiyunmaintenance of a cache of cloned repositories to improve the speed 168*4882a593Smuzhiyunthe system can checkout repositories. 169*4882a593Smuzhiyun 170*4882a593SmuzhiyunShared DL_DIR 171*4882a593Smuzhiyun------------- 172*4882a593Smuzhiyun 173*4882a593SmuzhiyunThe Workers are all connected over NFS which allows DL_DIR to be shared 174*4882a593Smuzhiyunbetween them. This reduces network accesses from the system and allows 175*4882a593Smuzhiyunthe build to be sped up. Usage of the directory within the build system 176*4882a593Smuzhiyunis designed to be able to be shared over NFS. 177*4882a593Smuzhiyun 178*4882a593SmuzhiyunShared SSTATE_DIR 179*4882a593Smuzhiyun----------------- 180*4882a593Smuzhiyun 181*4882a593SmuzhiyunThe Workers are all connected over NFS which allows the ``sstate`` 182*4882a593Smuzhiyundirectory to be shared between them. This means once a Worker has built 183*4882a593Smuzhiyunan artifact, all the others can benefit from it. Usage of the directory 184*4882a593Smuzhiyunwithin the directory is designed for sharing over NFS. 185*4882a593Smuzhiyun 186*4882a593SmuzhiyunResulttool 187*4882a593Smuzhiyun---------- 188*4882a593Smuzhiyun 189*4882a593SmuzhiyunAll of the different tests run as part of the build generate output into 190*4882a593Smuzhiyun``testresults.json`` files. This allows us to determine which tests ran 191*4882a593Smuzhiyunin a given build and their status. Additional information, such as 192*4882a593Smuzhiyunfailure logs or the time taken to run the tests, may also be included. 193*4882a593Smuzhiyun 194*4882a593SmuzhiyunResulttool is part of OpenEmbedded-Core and is used to manipulate these 195*4882a593Smuzhiyunjson results files. It has the ability to merge files together, display 196*4882a593Smuzhiyunreports of the test results and compare different result files. 197*4882a593Smuzhiyun 198*4882a593SmuzhiyunFor details, see :yocto_wiki:`/Resulttool`. 199*4882a593Smuzhiyun 200*4882a593Smuzhiyunrun-config Target Execution 201*4882a593Smuzhiyun=========================== 202*4882a593Smuzhiyun 203*4882a593SmuzhiyunThe ``scripts/run-config`` execution is where most of the work within 204*4882a593Smuzhiyunthe Autobuilder happens. It runs through a number of steps; the first 205*4882a593Smuzhiyunare general setup steps that are run once and include: 206*4882a593Smuzhiyun 207*4882a593Smuzhiyun#. Set up any ``buildtools-tarball`` if configured. 208*4882a593Smuzhiyun 209*4882a593Smuzhiyun#. Call "buildhistory-init" if buildhistory is configured. 210*4882a593Smuzhiyun 211*4882a593SmuzhiyunFor each step that is configured in ``config.json``, it will perform the 212*4882a593Smuzhiyunfollowing: 213*4882a593Smuzhiyun 214*4882a593Smuzhiyun#. Add any layers that are specified using the 215*4882a593Smuzhiyun ``bitbake-layers add-layer`` command (logging as stepXa) 216*4882a593Smuzhiyun 217*4882a593Smuzhiyun#. Call the ``scripts/setup-config`` script to generate the necessary 218*4882a593Smuzhiyun ``auto.conf`` configuration file for the build 219*4882a593Smuzhiyun 220*4882a593Smuzhiyun#. Run the ``bitbake BBTARGETS`` command (logging as stepXb) 221*4882a593Smuzhiyun 222*4882a593Smuzhiyun#. Run the ``bitbake SANITYTARGETS`` command (logging as stepXc) 223*4882a593Smuzhiyun 224*4882a593Smuzhiyun#. Run the ``EXTRACMDS`` command, which are run within the BitBake build 225*4882a593Smuzhiyun environment (logging as stepXd) 226*4882a593Smuzhiyun 227*4882a593Smuzhiyun#. Run the ``EXTRAPLAINCMDS`` command(s), which are run outside the 228*4882a593Smuzhiyun BitBake build environment (logging as stepXd) 229*4882a593Smuzhiyun 230*4882a593Smuzhiyun#. Remove any layers added in step 231*4882a593Smuzhiyun 1 using the ``bitbake-layers remove-layer`` command (logging as stepXa) 232*4882a593Smuzhiyun 233*4882a593SmuzhiyunOnce the execution steps above complete, ``run-config`` executes a set 234*4882a593Smuzhiyunof post-build steps, including: 235*4882a593Smuzhiyun 236*4882a593Smuzhiyun#. Call ``scripts/publish-artifacts`` to collect any output which is to 237*4882a593Smuzhiyun be saved from the build. 238*4882a593Smuzhiyun 239*4882a593Smuzhiyun#. Call ``scripts/collect-results`` to collect any test results to be 240*4882a593Smuzhiyun saved from the build. 241*4882a593Smuzhiyun 242*4882a593Smuzhiyun#. Call ``scripts/upload-error-reports`` to send any error reports 243*4882a593Smuzhiyun generated to the remote server. 244*4882a593Smuzhiyun 245*4882a593Smuzhiyun#. Cleanup the build directory using 246*4882a593Smuzhiyun :ref:`test-manual/understand-autobuilder:clobberdir` if the build was successful, 247*4882a593Smuzhiyun else rename it to "build-renamed" for potential future debugging. 248*4882a593Smuzhiyun 249*4882a593SmuzhiyunDeploying Yocto Autobuilder 250*4882a593Smuzhiyun=========================== 251*4882a593Smuzhiyun 252*4882a593SmuzhiyunThe most up to date information about how to setup and deploy your own 253*4882a593SmuzhiyunAutobuilder can be found in README.md in the ``yocto-autobuilder2`` 254*4882a593Smuzhiyunrepository. 255*4882a593Smuzhiyun 256*4882a593SmuzhiyunWe hope that people can use the ``yocto-autobuilder2`` code directly but 257*4882a593Smuzhiyunit is inevitable that users will end up needing to heavily customise the 258*4882a593Smuzhiyun``yocto-autobuilder-helper`` repository, particularly the 259*4882a593Smuzhiyun``config.json`` file as they will want to define their own test matrix. 260*4882a593Smuzhiyun 261*4882a593SmuzhiyunThe Autobuilder supports wo customization options: 262*4882a593Smuzhiyun 263*4882a593Smuzhiyun- variable substitution 264*4882a593Smuzhiyun 265*4882a593Smuzhiyun- overlaying configuration files 266*4882a593Smuzhiyun 267*4882a593SmuzhiyunThe standard ``config.json`` minimally attempts to allow substitution of 268*4882a593Smuzhiyunthe paths. The Helper script repository includes a 269*4882a593Smuzhiyun``local-example.json`` file to show how you could override these from a 270*4882a593Smuzhiyunseparate configuration file. Pass the following into the environment of 271*4882a593Smuzhiyunthe Autobuilder:: 272*4882a593Smuzhiyun 273*4882a593Smuzhiyun $ ABHELPER_JSON="config.json local-example.json" 274*4882a593Smuzhiyun 275*4882a593SmuzhiyunAs another example, you could also pass the following into the 276*4882a593Smuzhiyunenvironment:: 277*4882a593Smuzhiyun 278*4882a593Smuzhiyun $ ABHELPER_JSON="config.json /some/location/local.json" 279*4882a593Smuzhiyun 280*4882a593SmuzhiyunOne issue users often run into is validation of the ``config.json`` files. A 281*4882a593Smuzhiyuntip for minimizing issues from invalid json files is to use a Git 282*4882a593Smuzhiyun``pre-commit-hook.sh`` script to verify the JSON file before committing 283*4882a593Smuzhiyunit. Create a symbolic link as follows:: 284*4882a593Smuzhiyun 285*4882a593Smuzhiyun $ ln -s ../../scripts/pre-commit-hook.sh .git/hooks/pre-commit 286