109209eecSAndrew Geissler.. SPDX-License-Identifier: CC-BY-SA-2.0-UK 209209eecSAndrew Geissler 309209eecSAndrew Geissler******************************************* 409209eecSAndrew GeisslerUnderstanding the Yocto Project Autobuilder 509209eecSAndrew Geissler******************************************* 609209eecSAndrew Geissler 709209eecSAndrew GeisslerExecution Flow within the Autobuilder 809209eecSAndrew Geissler===================================== 909209eecSAndrew Geissler 1009209eecSAndrew GeisslerThe "a-full" and "a-quick" targets are the usual entry points into the 1109209eecSAndrew GeisslerAutobuilder and it makes sense to follow the process through the system 12*169d7bccSPatrick Williamsstarting there. This is best visualized from the :yocto_ab:`Autobuilder 13*169d7bccSPatrick WilliamsConsole view </typhoon/#/console>`. 1409209eecSAndrew Geissler 1509209eecSAndrew GeisslerEach item along the top of that view represents some "target build" and 1609209eecSAndrew Geisslerthese targets are all run in parallel. The 'full' build will trigger the 1709209eecSAndrew Geisslermajority of them, the "quick" build will trigger some subset of them. 1809209eecSAndrew GeisslerThe Autobuilder effectively runs whichever configuration is defined for 193b8a17c1SAndrew Geisslereach of those targets on a separate buildbot worker. To understand the 2009209eecSAndrew Geisslerconfiguration, you need to look at the entry on ``config.json`` file 21*169d7bccSPatrick Williamswithin the :yocto_git:`yocto-autobuilder-helper </yocto-autobuilder-helper>` 22*169d7bccSPatrick Williamsrepository. The targets are defined in the ``overrides`` section, a quick 23*169d7bccSPatrick Williamsexample could be ``qemux86-64`` which looks like:: 2409209eecSAndrew Geissler 2509209eecSAndrew Geissler "qemux86-64" : { 2609209eecSAndrew Geissler "MACHINE" : "qemux86-64", 2709209eecSAndrew Geissler "TEMPLATE" : "arch-qemu", 2809209eecSAndrew Geissler "step1" : { 2909209eecSAndrew Geissler "extravars" : [ 300ca19ccfSPatrick Williams "IMAGE_FSTYPES:append = ' wic wic.bmap'" 3109209eecSAndrew Geissler ] 3209209eecSAndrew Geissler } 3309209eecSAndrew Geissler }, 3409209eecSAndrew Geissler 35*169d7bccSPatrick WilliamsAnd to expand that, you need the ``arch-qemu`` entry from 36*169d7bccSPatrick Williamsthe ``templates`` section, which looks like:: 3709209eecSAndrew Geissler 3809209eecSAndrew Geissler "arch-qemu" : { 3909209eecSAndrew Geissler "BUILDINFO" : true, 4009209eecSAndrew Geissler "BUILDHISTORY" : true, 4109209eecSAndrew Geissler "step1" : { 4209209eecSAndrew Geissler "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", 4309209eecSAndrew Geissler "SANITYTARGETS" : "core-image-minimal:do_testimage core-image-sato:do_testimage core-image-sato-sdk:do_testimage core-image-sato:do_testsdk" 4409209eecSAndrew Geissler }, 4509209eecSAndrew Geissler "step2" : { 4609209eecSAndrew Geissler "SDKMACHINE" : "x86_64", 4709209eecSAndrew Geissler "BBTARGETS" : "core-image-sato:do_populate_sdk core-image-minimal:do_populate_sdk_ext core-image-sato:do_populate_sdk_ext", 4809209eecSAndrew Geissler "SANITYTARGETS" : "core-image-sato:do_testsdk core-image-minimal:do_testsdkext core-image-sato:do_testsdkext" 4909209eecSAndrew Geissler }, 5009209eecSAndrew Geissler "step3" : { 5109209eecSAndrew Geissler "BUILDHISTORY" : false, 5209209eecSAndrew Geissler "EXTRACMDS" : ["${SCRIPTSDIR}/checkvnc; DISPLAY=:1 oe-selftest ${HELPERSTMACHTARGS} -j 15"], 5309209eecSAndrew Geissler "ADDLAYER" : ["${BUILDDIR}/../meta-selftest"] 5409209eecSAndrew Geissler } 5509209eecSAndrew Geissler }, 5609209eecSAndrew Geissler 57*169d7bccSPatrick WilliamsCombining these two entries you can see that ``qemux86-64`` is a three step 58*169d7bccSPatrick Williamsbuild where ``bitbake BBTARGETS`` would be run, then ``bitbake SANITYTARGETS`` 59*169d7bccSPatrick Williamsfor each step; all for ``MACHINE="qemux86-64"`` but with differing 60*169d7bccSPatrick Williams:term:`SDKMACHINE` settings. In step 1, an extra variable is added to the 61*169d7bccSPatrick Williams``auto.conf`` file to enable wic image generation. 6209209eecSAndrew Geissler 6309209eecSAndrew GeisslerWhile not every detail of this is covered here, you can see how the 6409209eecSAndrew Geisslertemplate mechanism allows quite complex configurations to be built up 6509209eecSAndrew Geissleryet allows duplication and repetition to be kept to a minimum. 6609209eecSAndrew Geissler 673b8a17c1SAndrew GeisslerThe different build targets are designed to allow for parallelization, 6809209eecSAndrew Geisslerso different machines are usually built in parallel, operations using 6909209eecSAndrew Geisslerthe same machine and metadata are built sequentially, with the aim of 703b8a17c1SAndrew Geisslertrying to optimize build efficiency as much as possible. 7109209eecSAndrew Geissler 7209209eecSAndrew GeisslerThe ``config.json`` file is processed by the scripts in the Helper 7309209eecSAndrew Geisslerrepository in the ``scripts`` directory. The following section details 7409209eecSAndrew Geisslerhow this works. 7509209eecSAndrew Geissler 7609209eecSAndrew GeisslerAutobuilder Target Execution Overview 7709209eecSAndrew Geissler===================================== 7809209eecSAndrew Geissler 7909209eecSAndrew GeisslerFor each given target in a build, the Autobuilder executes several 8009209eecSAndrew Geisslersteps. These are configured in ``yocto-autobuilder2/builders.py`` and 8109209eecSAndrew Geisslerroughly consist of: 8209209eecSAndrew Geissler 8309209eecSAndrew Geissler#. *Run clobberdir*. 8409209eecSAndrew Geissler 8509209eecSAndrew Geissler This cleans out any previous build. Old builds are left around to 8609209eecSAndrew Geissler allow easier debugging of failed builds. For additional information, 8709209eecSAndrew Geissler see :ref:`test-manual/understand-autobuilder:clobberdir`. 8809209eecSAndrew Geissler 8909209eecSAndrew Geissler#. *Obtain yocto-autobuilder-helper* 9009209eecSAndrew Geissler 91*169d7bccSPatrick Williams This step clones the :yocto_git:`yocto-autobuilder-helper </yocto-autobuilder-helper>` 92*169d7bccSPatrick Williams git repository. This is necessary to avoid the requirement to maintain all 93*169d7bccSPatrick Williams the release or project-specific code within Buildbot. The branch chosen 9409209eecSAndrew Geissler matches the release being built so we can support older releases and 9509209eecSAndrew Geissler still make changes in newer ones. 9609209eecSAndrew Geissler 9709209eecSAndrew Geissler#. *Write layerinfo.json* 9809209eecSAndrew Geissler 9909209eecSAndrew Geissler This transfers data in the Buildbot UI when the build was configured 10009209eecSAndrew Geissler to the Helper. 10109209eecSAndrew Geissler 10209209eecSAndrew Geissler#. *Call scripts/shared-repo-unpack* 10309209eecSAndrew Geissler 10409209eecSAndrew Geissler This is a call into the Helper scripts to set up a checkout of all 10509209eecSAndrew Geissler the pieces this build might need. It might clone the BitBake 10609209eecSAndrew Geissler repository and the OpenEmbedded-Core repository. It may clone the 10709209eecSAndrew Geissler Poky repository, as well as additional layers. It will use the data 10809209eecSAndrew Geissler from the ``layerinfo.json`` file to help understand the 10909209eecSAndrew Geissler configuration. It will also use a local cache of repositories to 11009209eecSAndrew Geissler speed up the clone checkouts. For additional information, see 11109209eecSAndrew Geissler :ref:`test-manual/understand-autobuilder:Autobuilder Clone Cache`. 11209209eecSAndrew Geissler 11309209eecSAndrew Geissler This step has two possible modes of operation. If the build is part 1143b8a17c1SAndrew Geissler of a parent build, it's possible that all the repositories needed may 11509209eecSAndrew Geissler already be available, ready in a pre-prepared directory. An "a-quick" 11609209eecSAndrew Geissler or "a-full" build would prepare this before starting the other 11709209eecSAndrew Geissler sub-target builds. This is done for two reasons: 11809209eecSAndrew Geissler 11909209eecSAndrew Geissler - the upstream may change during a build, for example, from a forced 12009209eecSAndrew Geissler push and this ensures we have matching content for the whole build 12109209eecSAndrew Geissler 12209209eecSAndrew Geissler - if 15 Workers all tried to pull the same data from the same repos, 12309209eecSAndrew Geissler we can hit resource limits on upstream servers as they can think 12409209eecSAndrew Geissler they are under some kind of network attack 12509209eecSAndrew Geissler 12609209eecSAndrew Geissler This pre-prepared directory is shared among the Workers over NFS. If 12709209eecSAndrew Geissler the build is an individual build and there is no "shared" directory 12809209eecSAndrew Geissler available, it would clone from the cache and the upstreams as 12909209eecSAndrew Geissler necessary. This is considered the fallback mode. 13009209eecSAndrew Geissler 13109209eecSAndrew Geissler#. *Call scripts/run-config* 13209209eecSAndrew Geissler 1333b8a17c1SAndrew Geissler This is another call into the Helper scripts where it's expected that 13409209eecSAndrew Geissler the main functionality of this target will be executed. 13509209eecSAndrew Geissler 13609209eecSAndrew GeisslerAutobuilder Technology 13709209eecSAndrew Geissler====================== 13809209eecSAndrew Geissler 13909209eecSAndrew GeisslerThe Autobuilder has Yocto Project-specific functionality to allow builds 14009209eecSAndrew Geisslerto operate with increased efficiency and speed. 14109209eecSAndrew Geissler 14209209eecSAndrew Geisslerclobberdir 14309209eecSAndrew Geissler---------- 14409209eecSAndrew Geissler 14509209eecSAndrew GeisslerWhen deleting files, the Autobuilder uses ``clobberdir``, which is a 14609209eecSAndrew Geisslerspecial script that moves files to a special location, rather than 14709209eecSAndrew Geisslerdeleting them. Files in this location are deleted by an ``rm`` command, 14809209eecSAndrew Geisslerwhich is run under ``ionice -c 3``. For example, the deletion only 14909209eecSAndrew Geisslerhappens when there is idle IO capacity on the Worker. The Autobuilder 15009209eecSAndrew GeisslerWorker Janitor runs this deletion. See :ref:`test-manual/understand-autobuilder:Autobuilder Worker Janitor`. 15109209eecSAndrew Geissler 15209209eecSAndrew GeisslerAutobuilder Clone Cache 15309209eecSAndrew Geissler----------------------- 15409209eecSAndrew Geissler 15509209eecSAndrew GeisslerCloning repositories from scratch each time they are required was slow 15609209eecSAndrew Geissleron the Autobuilder. We therefore have a stash of commonly used 15709209eecSAndrew Geisslerrepositories pre-cloned on the Workers. Data is fetched from these 15809209eecSAndrew Geisslerduring clones first, then "topped up" with later revisions from any 15909209eecSAndrew Geisslerupstream when necessary. The cache is maintained by the Autobuilder 16009209eecSAndrew GeisslerWorker Janitor. See :ref:`test-manual/understand-autobuilder:Autobuilder Worker Janitor`. 16109209eecSAndrew Geissler 16209209eecSAndrew GeisslerAutobuilder Worker Janitor 16309209eecSAndrew Geissler-------------------------- 16409209eecSAndrew Geissler 16509209eecSAndrew GeisslerThis is a process running on each Worker that performs two basic 166*169d7bccSPatrick Williamsoperations, including background file deletion at IO idle (see 167*169d7bccSPatrick Williams"Run clobberdir" in :ref:`test-manual/understand-autobuilder:Autobuilder Target Execution Overview`) 168*169d7bccSPatrick Williamsand maintenance of a cache of cloned repositories to improve the speed 16909209eecSAndrew Geisslerthe system can checkout repositories. 17009209eecSAndrew Geissler 17109209eecSAndrew GeisslerShared DL_DIR 17209209eecSAndrew Geissler------------- 17309209eecSAndrew Geissler 174517393d9SAndrew GeisslerThe Workers are all connected over NFS which allows :term:`DL_DIR` to be shared 17509209eecSAndrew Geisslerbetween them. This reduces network accesses from the system and allows 176*169d7bccSPatrick Williamsthe build to be sped up. The usage of the directory within the build system 17709209eecSAndrew Geissleris designed to be able to be shared over NFS. 17809209eecSAndrew Geissler 17909209eecSAndrew GeisslerShared SSTATE_DIR 18009209eecSAndrew Geissler----------------- 18109209eecSAndrew Geissler 18209209eecSAndrew GeisslerThe Workers are all connected over NFS which allows the ``sstate`` 18309209eecSAndrew Geisslerdirectory to be shared between them. This means once a Worker has built 184*169d7bccSPatrick Williamsan artifact, all the others can benefit from it. The usage of the directory 185*169d7bccSPatrick Williamswithin the build system is designed for sharing over NFS. 18609209eecSAndrew Geissler 18709209eecSAndrew GeisslerResulttool 18809209eecSAndrew Geissler---------- 18909209eecSAndrew Geissler 19009209eecSAndrew GeisslerAll of the different tests run as part of the build generate output into 19109209eecSAndrew Geissler``testresults.json`` files. This allows us to determine which tests ran 19209209eecSAndrew Geisslerin a given build and their status. Additional information, such as 19309209eecSAndrew Geisslerfailure logs or the time taken to run the tests, may also be included. 19409209eecSAndrew Geissler 19509209eecSAndrew GeisslerResulttool is part of OpenEmbedded-Core and is used to manipulate these 196*169d7bccSPatrick WilliamsJSON results files. It has the ability to merge files together, display 19709209eecSAndrew Geisslerreports of the test results and compare different result files. 19809209eecSAndrew Geissler 19909209eecSAndrew GeisslerFor details, see :yocto_wiki:`/Resulttool`. 20009209eecSAndrew Geissler 20109209eecSAndrew Geisslerrun-config Target Execution 20209209eecSAndrew Geissler=========================== 20309209eecSAndrew Geissler 20409209eecSAndrew GeisslerThe ``scripts/run-config`` execution is where most of the work within 20509209eecSAndrew Geisslerthe Autobuilder happens. It runs through a number of steps; the first 20609209eecSAndrew Geisslerare general setup steps that are run once and include: 20709209eecSAndrew Geissler 208517393d9SAndrew Geissler#. Set up any :term:`buildtools` tarball if configured. 20909209eecSAndrew Geissler 210*169d7bccSPatrick Williams#. Call ``buildhistory-init`` if :ref:`ref-classes-buildhistory` is configured. 21109209eecSAndrew Geissler 21209209eecSAndrew GeisslerFor each step that is configured in ``config.json``, it will perform the 21309209eecSAndrew Geisslerfollowing: 21409209eecSAndrew Geissler 21509209eecSAndrew Geissler#. Add any layers that are specified using the 21609209eecSAndrew Geissler ``bitbake-layers add-layer`` command (logging as stepXa) 21709209eecSAndrew Geissler 21809209eecSAndrew Geissler#. Call the ``scripts/setup-config`` script to generate the necessary 21909209eecSAndrew Geissler ``auto.conf`` configuration file for the build 22009209eecSAndrew Geissler 22109209eecSAndrew Geissler#. Run the ``bitbake BBTARGETS`` command (logging as stepXb) 22209209eecSAndrew Geissler 22309209eecSAndrew Geissler#. Run the ``bitbake SANITYTARGETS`` command (logging as stepXc) 22409209eecSAndrew Geissler 22509209eecSAndrew Geissler#. Run the ``EXTRACMDS`` command, which are run within the BitBake build 22609209eecSAndrew Geissler environment (logging as stepXd) 22709209eecSAndrew Geissler 22809209eecSAndrew Geissler#. Run the ``EXTRAPLAINCMDS`` command(s), which are run outside the 22909209eecSAndrew Geissler BitBake build environment (logging as stepXd) 23009209eecSAndrew Geissler 23109209eecSAndrew Geissler#. Remove any layers added in step 23209209eecSAndrew Geissler 1 using the ``bitbake-layers remove-layer`` command (logging as stepXa) 23309209eecSAndrew Geissler 23409209eecSAndrew GeisslerOnce the execution steps above complete, ``run-config`` executes a set 23509209eecSAndrew Geisslerof post-build steps, including: 23609209eecSAndrew Geissler 23709209eecSAndrew Geissler#. Call ``scripts/publish-artifacts`` to collect any output which is to 23809209eecSAndrew Geissler be saved from the build. 23909209eecSAndrew Geissler 24009209eecSAndrew Geissler#. Call ``scripts/collect-results`` to collect any test results to be 24109209eecSAndrew Geissler saved from the build. 24209209eecSAndrew Geissler 24309209eecSAndrew Geissler#. Call ``scripts/upload-error-reports`` to send any error reports 24409209eecSAndrew Geissler generated to the remote server. 24509209eecSAndrew Geissler 2462390b1b6SPatrick Williams#. Cleanup the :term:`Build Directory` using 24709209eecSAndrew Geissler :ref:`test-manual/understand-autobuilder:clobberdir` if the build was successful, 24809209eecSAndrew Geissler else rename it to "build-renamed" for potential future debugging. 24909209eecSAndrew Geissler 25009209eecSAndrew GeisslerDeploying Yocto Autobuilder 25109209eecSAndrew Geissler=========================== 25209209eecSAndrew Geissler 25309209eecSAndrew GeisslerThe most up to date information about how to setup and deploy your own 254*169d7bccSPatrick WilliamsAutobuilder can be found in :yocto_git:`README.md </yocto-autobuilder2/tree/README.md>` 255*169d7bccSPatrick Williamsin the :yocto_git:`yocto-autobuilder2 </yocto-autobuilder2>` repository. 25609209eecSAndrew Geissler 257*169d7bccSPatrick WilliamsWe hope that people can use the :yocto_git:`yocto-autobuilder2 </yocto-autobuilder2>` 258*169d7bccSPatrick Williamscode directly but it is inevitable that users will end up needing to heavily 259*169d7bccSPatrick Williamscustomize the :yocto_git:`yocto-autobuilder-helper </yocto-autobuilder-helper>` 260*169d7bccSPatrick Williamsrepository, particularly the ``config.json`` file as they will want to define 261*169d7bccSPatrick Williamstheir own test matrix. 26209209eecSAndrew Geissler 263*169d7bccSPatrick WilliamsThe Autobuilder supports two customization options: 26409209eecSAndrew Geissler 26509209eecSAndrew Geissler- variable substitution 26609209eecSAndrew Geissler 26709209eecSAndrew Geissler- overlaying configuration files 26809209eecSAndrew Geissler 26909209eecSAndrew GeisslerThe standard ``config.json`` minimally attempts to allow substitution of 27009209eecSAndrew Geisslerthe paths. The Helper script repository includes a 27109209eecSAndrew Geissler``local-example.json`` file to show how you could override these from a 27209209eecSAndrew Geisslerseparate configuration file. Pass the following into the environment of 27309209eecSAndrew Geisslerthe Autobuilder:: 27409209eecSAndrew Geissler 27509209eecSAndrew Geissler $ ABHELPER_JSON="config.json local-example.json" 27609209eecSAndrew Geissler 27709209eecSAndrew GeisslerAs another example, you could also pass the following into the 27809209eecSAndrew Geisslerenvironment:: 27909209eecSAndrew Geissler 28009209eecSAndrew Geissler $ ABHELPER_JSON="config.json /some/location/local.json" 28109209eecSAndrew Geissler 28209209eecSAndrew GeisslerOne issue users often run into is validation of the ``config.json`` files. A 283*169d7bccSPatrick Williamstip for minimizing issues from invalid JSON files is to use a Git 28409209eecSAndrew Geissler``pre-commit-hook.sh`` script to verify the JSON file before committing 28509209eecSAndrew Geisslerit. Create a symbolic link as follows:: 28609209eecSAndrew Geissler 28709209eecSAndrew Geissler $ ln -s ../../scripts/pre-commit-hook.sh .git/hooks/pre-commit 288