Adding file naming and indexing
[AGL/documentation.git] / docs / 01_Getting_Started / 02_Building_AGL_Image / 05_Customizing_Your_Build.md
1 ---
2 title: Customizing Your Build
3 ---
4
5 Because the build process is based on BitBake and the Yocto Project,
6 build customizations are driven through configuration files used during
7 the build.
8
9 Lots of configuration files exist that define a build.
10 However, the primary one that acts as a global configuration mechanism is the
11 `local.conf` file, which is found in the Build Directory in a folder named "conf".
12
13 Before you start your build process, you should open up the `local.conf` file
14 and look through it to be sure the general configurations are correct.
15 The file is well commented so you should be able to understand what the
16 various variables accomplish.
17
18 To view and customize the `local.conf` file, use any text editor:
19
20 ```sh
21 $ vim $AGL_TOP/<release-branch-name>/<build-dir>/conf/local.conf
22 ```
23
24 As mentioned in the "[Initializing Your Build Environment](./04_Initializing_Your_Build_Environment.md)" section,
25 the `local.conf` file gets augmented with AGL configuration fragments based on
26 how you execute the `aglsetup.sh` script.
27 You can see those fragments at the end the configuration file.
28
29 Even though your build should work fine after running the `aglsetup.sh` script,
30 you might consider editing your `local.conf` file to use one or more of the
31 following configurations.
32
33 ## Capturing Build History
34
35 You can enable build history to help maintain the quality of your build output.
36 You can use it to highlight unexpected and possibly unwanted changes in the build output.
37 Basically, with build history enabled, you get a record of information about the contents
38 of each package and image.
39 That information is committed to a local Git repository where you can examine it.
40
41 To enable build history, make sure the following two lines are in your
42 `local.conf` file:
43
44 ```sh
45 INHERIT += "buildhistory"
46 BUILDHISTORY_COMMIT = "1"
47 ```
48
49 See the
50 "[Maintaining Build Output Quality](https://www.yoctoproject.org/docs/3.1.4/ref-manual/ref-manual.html#maintaining-build-output-quality)"
51 section in the Yocto Project Reference Manual for a complete discussion on
52 build history.
53
54 ## Deleting Temporary Workspace
55
56 During a build, the build system uses a lot of disk space to store temporary files.
57 You can ease the burden on your system and speed up the build by configuring the build
58 to remove temporary workspace.
59
60 You need to inherit the `rm_work` class by using this statement in the `local.conf` file:
61
62 ```sh
63 INHERIT += "rm_work"
64 ```
65
66 You can read about the class in the
67 "[rm_work.bbclass](https://www.yoctoproject.org/docs/3.1.4/ref-manual/ref-manual.html#ref-classes-rm-work)"
68 section of the Yocto Project Reference Manual for more information.
69
70 ##  Pointing at Shared State Cache Locations
71
72 The build system creates everything from scratch unless BitBake can determine that parts do not need to be rebuilt. Fundamentally, building from scratch is attractive as it means all parts are built fresh and there is no possibility of stale data causing problems.
73 When developers hit problems, they typically default back to building from scratch so they know the state
74 of things from the start.
75
76 The build process uses Shared State Cache (sstate) to speed up subsequent builds.
77 This cache retains artifacts that can be re-used once it is determined that they
78 would not be different as compared to a re-built module.
79
80 For the AGL build, you can specify the location for sstate files by including the
81 following in the `local.conf` file:
82
83 ```sh
84 SSTATE_DIR = "${AGL_TOP}/sstate-cache"
85 ```
86
87 Also, in the `local.conf` file, you can specify additional directories in which the build
88 system can look for shared state information.
89 Use the following form in your file to list out the directories you want the build
90 process to look at for sstate information:
91
92 ```sh
93 SSTATE_MIRRORS ?= "\
94     file://.* http://someserver.tld/share/sstate/PATH;downloadfilename=PATH \n \
95     file://.* file:///some/local/dir/sstate/PATH"
96 ```
97
98 If you want to know more about the Yocto Project sstate mechanism, see the
99 "[Shared State Cache](https://www.yoctoproject.org/docs/3.1.4/ref-manual/ref-manual.html#shared-state-cache)"
100 section in the Yocto Project Reference Manual.
101
102 ## Preserving the Download Directory
103
104 During the initial build, the system downloads many different source code tarballs
105 from various upstream projects.
106 Downloading these files can take a while, particularly if your network
107 connection is slow.
108 The process downloads files into a
109 "[download directory](https://www.yoctoproject.org/docs/3.1.4/ref-manual/ref-manual.html#var-DL_DIR)".
110 The `DL_DIR` variable defines the download directory.
111 For subsequent builds, you can preserve this directory to speed up the download
112 part of a build.
113
114 The default download directory is in a folder named "downloads".
115 For the AGL build you can set the download directory by adding the following to your
116 `local.conf` file:
117
118 ```sh
119 DL_DIR = "${AGL_TOP}/downloads"
120 ```
121
122 ## Using a Shared State (sstate) Mirror
123
124 The underlying Yocto Project build system uses Shared State Mirrors to cache
125 artifacts from previous builds.
126 You can significantly speed up builds and guard against fetcher failures by
127 using mirrors.
128 To use mirrors, add this line to your `local.conf` file in the Build directory:
129
130 ```sh
131 SSTATE_MIRRORS_append = " file://.* https://download.automotivelinux.org/sstate-mirror/master/${DEFAULTTUNE}/PATH \n "
132 ```
133
134 You can learn more about shared state and how it is used in the
135 "[Shared State Cache](https://yoctoproject.org/docs/3.1.4/ref-manual/ref-manual.html#shared-state-cache)"
136 section of the Yocto Project Reference Manual.
137
138 ## Common Settings using Symbolic Link with site.conf
139
140 ```sh
141 $ echo "# reuse download directories" >> $AGL_TOP/site.conf
142 $ echo "DL_DIR = \"$HOME/downloads/\"" >> $AGL_TOP/site.conf
143 $ echo "SSTATE_DIR = \"$AGL_TOP/sstate-cache/\"" >> $AGL_TOP/site.conf
144 $ cd $AGL_TOP/master/qemux86-64/
145 $ ln -sf $AGL_TOP/site.conf conf/
146
147 In General;
148 $ cd $AGL_TOP/<release-branch-name>/<build-dir>/
149 $ ln -sf $AGL_TOP/site.conf conf/
150 ```