README.HACKING 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. Hacking on Tor Browser Build
  2. ============================
  3. This file tries to list the main things to know when making changes to
  4. the Tor Browser build.
  5. rbm documentation
  6. -----------------
  7. If you go to directory rbm/doc, you can find the rbm documentation. You
  8. can build it with 'make html' or 'make man'.
  9. Using and defining options
  10. --------------------------
  11. Options can be used in templates with the following syntax:
  12. [% c("option_name") %]
  13. More details about the templates syntax can be found in
  14. rbm/doc/rbm_templates.7 and [http://template-toolkit.org/docs/manual/index.html].
  15. Some options have a specific meaning to rbm. You can see their descriptions
  16. in rbm/doc/rbm_config.7 and rbm/doc/rbm_input_files.7.
  17. When the option does not have a specific meaning to rbm, it is a good
  18. idea to define it under var/ to avoid potential conflicts in option names
  19. with a future version of rbm.
  20. The options can be defined in different places:
  21. - rbm.conf for options available to all components
  22. - project/$project/config for options available to one component
  23. - rbm.local.conf for user defined options
  24. In each of those places, an option can be defined:
  25. - at the root of the document
  26. - under targets/$target/, in which case the definition only applies when
  27. a specific target is defined
  28. The targets are usually used to select:
  29. - the platform: torbrowser-linux-x86_64, torbrowser-linux-i686,
  30. torbrowser-windows-i686, torbrowser-osx-x86_64
  31. - the channel: release, nightly, alpha
  32. The targets torbrowser-linux-x86_64, torbrowser-linux-i686,
  33. torbrowser-windows-i686, torbrowser-osx-x86_64 are special cases. They
  34. do not contain options directly, instead they contain a list of other
  35. targets. For instance, the torbrowser-linux-x86_64 target is pointing
  36. to the linux-x86_64 and linux targets. You should define an option under
  37. the linux target if it applies to Linux on both architectures, or under
  38. the linux-x86_64 if it only applies to the x86_64 architecture.
  39. An option that is defined at the root of rbm.conf can be overridden by
  40. an other definition under a target, or inside projects/$project/config.
  41. You can find the complete priority order in rbm/doc/rbm_config.7.
  42. Defining a project's filename
  43. -----------------------------
  44. The filename option defines the output file or directory from the build
  45. of a component. If the file or directory exists in the out/$component
  46. directory, the component will not be rebuilt when it is used as a
  47. dependency from an other component.
  48. The filename is usually something like this:
  49. filename: '[% project %]-[% c("version") %]-[% c("var/osname") %]-[% c("var/build_id") %].tar.gz'
  50. The var/build_id value is a hash that is based on the build inputs of
  51. the component:
  52. - the build script (after template evaluation)
  53. - the container definition
  54. - the input files (the filename when it is a dependency on an other
  55. project, the filename and hash of its content otherwise)
  56. This means that each time the build script, the container or one of the
  57. dependencies is modified, the output filename will change and a rebuild
  58. of the component will be required.
  59. The version and var/osname values could be removed from the filename,
  60. but they are useful to get an idea of what a file contains.
  61. Adding some Linux/Windows/OSX specific changes to a build script
  62. ----------------------------------------------------------------
  63. You can use the following template syntax in the build scripts:
  64. [% IF c("var/linux") -%]
  65. # do something for linux
  66. [% ELSIF c("var/windows") -%]
  67. # do something for windows
  68. [% ELSIF c("var/osx") -%]
  69. # do something for osx
  70. [% END -%]
  71. You can also use var/linux-x86_64 and var/linux-i686 for things that
  72. only apply to x86_64 and i686 linux builds. You can use the var/release,
  73. var/alpha and var/nightly options to do things depending on the channel.
  74. As an alternative you can define an option with a different value
  75. depending on the target:
  76. targets:
  77. linux:
  78. var:
  79. do_something: 'do something for linux'
  80. windows-i686:
  81. var:
  82. do_something: 'do something for windows'
  83. osx-x86_64:
  84. var:
  85. do_something: 'do something for osx'
  86. And in the build script, use:
  87. [% c("var/do_something") %]
  88. Evaluating a component's build script
  89. -------------------------------------
  90. If you want to look at the build script used to build a component for a
  91. specific platform/channel, you can use the following command:
  92. $ ./rbm/rbm showconf $component build --target $channel --target $platform
  93. $component should be replaced by the name of the component.
  94. $channel should be one of the following:
  95. - release
  96. - alpha
  97. - nightly
  98. $platform should be one of the following:
  99. - torbrowser-linux-x86_64
  100. - torbrowser-linux-i686
  101. - torbrowser-windows-i686
  102. - torbrowser-osx-x86_64
  103. For example, to see tor's build script for linux x86_64 on the alpha
  104. channel, you can use:
  105. $ ./rbm/rbm showconf tor build --target alpha --target \
  106. torbrowser-linux-x86_64
  107. If the component you are looking at has many dependencies, the display
  108. can take some time as various build_id values need to be computed. If
  109. you don't care about the accuracy of input and output file names, you
  110. can add '--target no_build_id' to the command line. For instance, if you
  111. want to look at the build script for the tor-browser component (which
  112. has a lot of dependencies), you can use:
  113. $ ./rbm/rbm showconf tor build --target alpha --target \
  114. torbrowser-linux-x86_64 --target no_build_id
  115. The same type of commands can be used to look at any option values,
  116. replacing build with the name of the option you want to look at. For
  117. instance, if you want to know the output filename of tor on linux-x86_64
  118. on the alpha channel, you can use:
  119. $ ./rbm/rbm showconf tor filename --target alpha --target \
  120. torbrowser-linux-x86_64
  121. Building a single component
  122. ---------------------------
  123. When you are working on some changes to a component, before creating a
  124. full bundle with those changes, you might want to try a build of the
  125. component you modified only.
  126. This can be done with the following command:
  127. $ ./rbm/rbm build $component --target $channel --target $platform
  128. See the previous section "Evaluating a component's build script" for a
  129. list of possible values for $channel and $platform.
  130. For instance, if you want to build tor for linux-x86_64 on the alpha
  131. channel, you can run:
  132. $ ./rbm/rbm build tor --target alpha --target torbrowser-linux-x86_64
  133. To find the resulting file from the build, you can use 'ls -ltr out/tor/'
  134. to find the file with the last modification time.
  135. Patching Firefox (or an other component)
  136. ----------------------------------------
  137. If you want to test a Firefox patch, the easiest way to do it is to
  138. copy the patch file to the projects/firefox/ directory, then edit
  139. projects/firefox/config to add the new patch to the list of input_files:
  140. - filename: patch-for-XXXX.patch
  141. Then edit projects/firefox/build to add a line somewhere (probably just
  142. before running the configure script) to apply the patch:
  143. patch -p1 < $rootdir/patch-for-XXXX.patch
  144. You can now run 'make testbuild' (or an other build target) to start a
  145. build with the patch.
  146. As an alternative, if you have your patch in a git repository, you can
  147. edit projects/firefox/config to change the git_url option to point to
  148. your git repository, and change the git_hash option to point to the
  149. commit you want to build. If the new git_hash option is not pointing to
  150. a signed tag, you will also need to comment the 'tag_gpg_id: 1' line.
  151. The git_hash option can point to a tag, a commit, a branch or anything
  152. that is understood by git.
  153. If you specify a branch in the git_hash option, you don't need to prefix
  154. it with a git remote name as all branches from the git repository
  155. selected in the git_url option are created as local branches.
  156. If you want to work on a local git repository, it is not a good idea to
  157. work on the git_clones/firefox repository directly. Instead you should
  158. create a separate git repository and update the git_url option with a
  159. file:// URL pointing to your repository.
  160. After changing the git_url option or when new commits have been added
  161. to a branch, you should run "make fetch" before starting a build to get
  162. the new commits. If you want to fetch new commits automatically when
  163. starting a new build you can add a "fetch: 1" line to
  164. projects/firefox/config.
  165. Remember that the git_hash option has different definitions for alpha
  166. and nightly builds, so you should modify the right one depending on
  167. what type of build you are doing (see also the "Types of builds" section).
  168. The Firefox mozconfig files
  169. ---------------------------
  170. In the gitian build, we are using the mozconfig files included in the
  171. tor-browser.git repository (the .mozconfig, .mozconfig-mac and
  172. .mozconfig-mingw files).
  173. In the rbm build however, we need to make some small modifications to
  174. those files, so we are instead using mozconfig files stored in the
  175. projects/firefox/ directory, ignoring the .mozconfig files from the
  176. tor-browser.git repository.
  177. This could change in the future, when we are not using Gitian anymore.
  178. Debugging a build error
  179. -----------------------
  180. If the build fails, a debugging shell will automatically be opened in
  181. the container used for the build (unless you set debug to 0 in
  182. rbm.local.conf).
  183. Before using the debugging shell, you can first look at the build logs
  184. in an other terminal (the filename of the log file is indicated in the
  185. rbm output).
  186. In the debug shell, you can type 'bash' to get a shell with completion.
  187. You can then look at the 'build' file, and copy paste some of its commands
  188. to debug the problem. If you need to edit files, vim is not installed
  189. in the build containers, but vi can be used instead.
  190. When you press ctrl+d (twice if you opened a bash shell) the debug shell
  191. is closed and the container containing the failed build is removed.
  192. The path to the container should be printed on the screen in case you
  193. want to backup its rootfs to be able to look at it later.
  194. Testing an rbm patch
  195. --------------------
  196. When you are working on a patch to rbm, you might want to try a Tor
  197. Browser build using your patched version of rbm. You could patch the
  198. rbm in the rbm/ directory, however your patch can be reverted if you
  199. use any of the makefile rules that does a 'git submodule update'.
  200. To avoid this you can clone the rbm git repository to a separate
  201. directory, where you will apply your patch. To do a build using your
  202. patched rbm, take the command from the makefile, but replace $(rbm)
  203. with the path to your patched rbm.
  204. For example, if you want to try a Linux x86_64 alpha build, you can run:
  205. $ /path_to_rbm/rbm build release --target alpha --target \
  206. torbrowser-linux-x86_64
  207. Types of builds: nightly, alpha, release and testbuild
  208. ------------------------------------------------------
  209. The testbuild makefile target allows you to do a build quickly in the
  210. testbuild directory, skipping the generation of all the locales and the
  211. mar files. This is useful during development.
  212. By default the testbuild is based on the alpha build. All the options
  213. can have a different definition for the alpha, release and nightly builds.
  214. Usually the git_hash option has a different definition for the nightly
  215. builds in order to point to the master branch.
  216. If you want your testbuild target to create builds based on nightly
  217. rather than alpha, you can edit your rbm.local.conf file and uncomment
  218. the targets/torbrowser-testbuild definition.