DEV Community

rsclarke
rsclarke

Posted on

Using Mock for chroot Chromium Builds

Introduction

The setup guide to checking out and building Chromium on Linux provides some guidance for distributions other than Ubuntu. However, the provided scripts for isolating the build environment and installing dependencies are dependant on a Ubuntu or Debian distribution.

This article utilises Mock to create a chroot environment on Fedora in which build dependencies and tools will be installed. Building, running and testing Chromium can take place inside the chroot environment to avoid package conflict.

Effectively the chroot environment and all dependencies are defined by a single Mock configuration file. Also provided is a simple bash function to execute commands inside the chroot environment and can be often prefixed to the commands listed in the said setup guide. Alternatively, you can type chrsh which will drop you into a bash shell inside the chroot and follow the original guide. Though you won't have to install the additional build dependencies as these are taken care of using Mock.

The files for this are available in the chrsh repo if you'd like to jump right in.

GitHub logo rsclarke / chrsh

Mock configuration for Chromium to build, test and run in a chroot environment.

chrsh

Mock configuration for Chromium to build, test and run in a chroot environment.

This repo provides a Mock configuration file and bash function to isolate the Chromium build environment and ease the interaction with.

Setup

Mock

sudo dnf install mock
sudo usermod -a -G mock [User name]
newgrp -

chrsh

git clone https://github.com/rsclarke/chrsh.git
cd chrsh
sudo cp chromium.cfg /etc/mock
cat .bashrc >> ~/.bashrc
source ~/.bashrc
mkdir ~/chromium
mock -r chromium init

Building Chromium

Install depot_tools and Fetch Chromium Source

chrsh git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
chrsh "echo export PATH=\$PATH:\${HOME}/depot_tools >> ~/.bashrc"
chrsh cd chromium \&\& fetch --nohooks --no-history chromium
chrsh cd chromium/src \&\& gclient runhooks

Update /etc/mock/chromium.cfg

After the inital setup above, most of the time you will be executing commands within the chromium/src directory. Therefore it is recommended to uncomment the line indicated in /etc/mock/chromium.cfg

# Additional arguments to supply to systemd-nspawn
config_opts['nspawn_args'] = [
        "--setenv=DISPLAY={}".format(os.getenv("DISPLAY"))
        "--chdir={}".format(_home),
# Uncomment the

The remainder of this article will walk through the setup of Mock, chrsh and have the Chromium source code checked out and built!

Setup

Mock

As per the mock wiki, setup is fairly straightforward. Though you may wish to take note of the security implication raised when adding the user to the mock group.

sudo dnf install mock
sudo usermod -a -G mock [User name]
newgrp -
Enter fullscreen mode Exit fullscreen mode

chrsh

Grab the files, chromium.cfg and .bashrc, or clone the repository.

git clone https://github.com/rsclarke/chrsh.git
cd chrsh
Enter fullscreen mode Exit fullscreen mode

Copy chromium.cfg to /etc/mock and add the contents of .bashrc to yours.

sudo cp chromium.cfg /etc/mock/
cat .bashrc >> ~/.bashrc
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

The configuration file out of the box makes the assumption that the Chromium source code will be accessible outside of the chroot environment. Otherwise, all development tools and utilities you wish to use would also have to be installed in the chroot environment. chrsh follows the guide and will place the Chromium source code in ~/chromium and will bind mount this to the home directory of your user inside the chroot.

mkdir ~/chromium
Enter fullscreen mode Exit fullscreen mode

Finally, you can create the chroot environment, which will install all necessary build tools and dependencies.

mock -r chromium init
Enter fullscreen mode Exit fullscreen mode

Checking out and Building Chromium

The remainder is an adaptation of the guide but using chrsh.

Install depot_tools

chrsh git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
chrsh "echo export PATH=\$PATH:\${HOME}/depot_tools >> ~/.bashrc"
Enter fullscreen mode Exit fullscreen mode

Get the code

chrsh cd chromium \&\& fetch --nohooks --no-history chromium
chrsh cd chromium/src \&\& gclient runhooks
Enter fullscreen mode Exit fullscreen mode

Side Note:

From this point on, commands in the guide expect to be executed from the chromium/src directory. Naturally running chrsh cd chromium/src \&\& <cmd> isn't exactly elegant. Therefore you can start the shell in this directory by uncommenting the relevant --chdir argument in /etc/mock/chromium.cfg. This guide assumes you will do this.

Additionally, you can execute chrsh standalone to provide a bash shell, instead of executing each command in the guide prefixed.


Building Chromium

As the chromium directory is mounted inside the chroot at the same location (inside your home directory), it is best to also cd ~/chromium/src. At least you might get tab completion on filenames!

cd ~/chromium/src

# Generate build targets
chrsh gn gen out/Default

# Compile Chromium
chrsh ninja -C out/Default chrome

# Run Chromium
chrsh out/Default/chrome

Enter fullscreen mode Exit fullscreen mode

Test Targets

Unit tests can be compiled and executed within the chroot also. The following example builds and runs the pdf_uinttests. The argument --gtest_filter can be used to select test cases.

chrsh ninja -C out/Default pdf_unittests
chrsh out/Default/pdf_unittests --gtest_filter="RangeSetTest.*"
Enter fullscreen mode Exit fullscreen mode

Updating Chromium Source Checkout

In theory, the git rebase-update can be executed outside the chroot.

chrsh git rebase-update
chrsh gclient sync
Enter fullscreen mode Exit fullscreen mode

Next Steps and Ideas

Hopefully the Mock configuration file is of use to you whilst developing Chromium and chrsh eases the interaction with this. Feel free to comment, the following are a few ideas you might wish to consider further setting up your environment or working on Chromium.

Further Development

The Chromium Linux Development page provides more information on where to start for open issues and contributing.

Create a Compilation Database

Many IDEs make use of a compilation database to provide rich editing of the project you are working on. The generate_compdb.py script in the repository can help create this for you.

chrsh ./tools/clang/scripts/generate_compdb.py -p out/Default > compile_commands.json
Enter fullscreen mode Exit fullscreen mode

Top comments (0)