3.10.7. Replicating a Build Offline

It can be useful to take a "snapshot" of upstream sources used in a build and then use that "snapshot" later to replicate the build offline. To do so, you need to first prepare and populate your downloads directory your "snapshot" of files. Once your downloads directory is ready, you can use it at any time and from any machine to replicate your build.

Follow these steps to populate your Downloads directory:

  1. Create a Clean Downloads Directory: Start with an empty downloads directory (DL_DIR). You start with an empty downloads directory by either removing the files in the existing directory or by setting DL_DIR to point to either an empty location or one that does not yet exist.

  2. Generate Tarballs of the Source Git Repositories: Edit your local.conf configuration file as follows:

         DL_DIR = "/home/your-download-dir/"
         BB_GENERATE_MIRROR_TARBALLS = "1"
                            

    During the fetch process in the next step, BitBake gathers the source files and creates tarballs in the directory pointed to by DL_DIR. See the BB_GENERATE_MIRROR_TARBALLS variable for more information.

  3. Populate Your Downloads Directory Without Building: Use BitBake to fetch your sources but inhibit the build:

         $ bitbake target --runonly=fetch
                            

    The downloads directory (i.e. ${DL_DIR}) now has a "snapshot" of the source files in the form of tarballs, which can be used for the build.

  4. Optionally Remove Any Git or other SCM Subdirectories From the Downloads Directory: If you want, you can clean up your downloads directory by removing any Git or other Source Control Management (SCM) subdirectories such as ${DL_DIR}/git2/*. The tarballs already contain these subdirectories.

Once your downloads directory has everything it needs regarding source files, you can create your "own-mirror" and build your target. Understand that you can use the files to build the target offline from any machine and at any time.

Follow these steps to build your target using the files in the downloads directory:

  1. Using Local Files Only: Inside your local.conf file, add the SOURCE_MIRROR_URL variable, inherit the own-mirrors class, and use the BB_NO_NETWORK variable to your local.conf.

         SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
         INHERIT += "own-mirrors"
         BB_NO_NETWORK = "1"
                            

    The SOURCE_MIRROR_URL and own-mirror class set up the system to use the downloads directory as your "own mirror". Using the BB_NO_NETWORK variable makes sure that BitBake's fetching process in step 3 stays local, which means files from your "own-mirror" are used.

  2. Start With a Clean Build: You can start with a clean build by removing the ${TMPDIR} directory or using a new Build Directory.

  3. Build Your Target: Use BitBake to build your target:

         $ bitbake target
                            

    The build completes using the known local "snapshot" of source files from your mirror. The resulting tarballs for your "snapshot" of source files are in the downloads directory.

    Note

    The offline build does not work if recipes attempt to find the latest version of software by setting SRCREV to ${AUTOREV}:

         SRCREV = "${AUTOREV}"
                                

    When a recipe sets SRCREV to ${AUTOREV}, the build system accesses the network in an attempt to determine the latest version of software from the SCM. Typically, recipes that use AUTOREV are custom or modified recipes. Recipes that reside in public repositories usually do not use AUTOREV.

    If you do have recipes that use AUTOREV, you can take steps to still use the recipes in an offline build. Do the following:

    1. Use a configuration generated by enabling build history.

    2. Use the buildhistory-collect-srcrevs command to collect the stored SRCREV values from the build's history. For more information on collecting these values, see the "Build History Package Information" section.

    3. Once you have the correct source revisions, you can modify those recipes to to set SRCREV to specific versions of the software.