<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: rsclarke</title>
    <description>The latest articles on DEV Community by rsclarke (@rsclarke).</description>
    <link>https://dev.to/rsclarke</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F80865%2Ffa58c419-d892-4813-81c2-f9605795470f.jpg</url>
      <title>DEV Community: rsclarke</title>
      <link>https://dev.to/rsclarke</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rsclarke"/>
    <language>en</language>
    <item>
      <title>Using Mock for chroot Chromium Builds</title>
      <dc:creator>rsclarke</dc:creator>
      <pubDate>Tue, 03 Jul 2018 00:34:50 +0000</pubDate>
      <link>https://dev.to/rsclarke/using-mock-for-chroot-chromium-builds-2ok9</link>
      <guid>https://dev.to/rsclarke/using-mock-for-chroot-chromium-builds-2ok9</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md" rel="noopener noreferrer"&gt;setup guide&lt;/a&gt; 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.&lt;/p&gt;

&lt;p&gt;This article utilises &lt;a href="https://github.com/rpm-software-management/mock/wiki" rel="noopener noreferrer"&gt;Mock&lt;/a&gt; to create a chroot environment on &lt;a href="https://getfedora.org/" rel="noopener noreferrer"&gt;Fedora&lt;/a&gt; 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.&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;chrsh&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;The files for this are available in the &lt;a href="https://github.com/rsclarke/chrsh" rel="noopener noreferrer"&gt;chrsh&lt;/a&gt; repo if you'd like to jump right in.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/rsclarke" rel="noopener noreferrer"&gt;
        rsclarke
      &lt;/a&gt; / &lt;a href="https://github.com/rsclarke/chrsh" rel="noopener noreferrer"&gt;
        chrsh
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Mock configuration for Chromium to build, test and run in a chroot environment.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;chrsh&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;Mock configuration for Chromium to build, test and run in a chroot environment.&lt;/p&gt;
&lt;p&gt;This repo provides a &lt;a href="https://github.com/rpm-software-management/mock" rel="noopener noreferrer"&gt;Mock&lt;/a&gt; configuration file and bash function to isolate the Chromium build environment and ease the interaction with.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Setup&lt;/h2&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Mock&lt;/h3&gt;
&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;sudo dnf install mock
sudo usermod -a -G mock [User name]
newgrp -
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;chrsh&lt;/h3&gt;

&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;git clone https://github.com/rsclarke/chrsh.git
cd chrsh
sudo cp chromium.cfg /etc/mock
cat .bashrc &amp;gt;&amp;gt; ~/.bashrc
source ~/.bashrc
mkdir ~/chromium
mock -r chromium init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Building Chromium&lt;/h2&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Install &lt;code&gt;depot_tools&lt;/code&gt; and Fetch Chromium Source&lt;/h3&gt;

&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;chrsh git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
chrsh "echo export PATH=\$PATH:\${HOME}/depot_tools &amp;gt;&amp;gt; ~/.bashrc"
chrsh cd chromium \&amp;amp;\&amp;amp; fetch --nohooks --no-history chromium
chrsh cd chromium/src \&amp;amp;\&amp;amp; gclient runhooks
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Update &lt;code&gt;/etc/mock/chromium.cfg&lt;/code&gt;
&lt;/h3&gt;

&lt;/div&gt;
&lt;p&gt;After the inital setup above, most of the time you will be executing commands within the &lt;code&gt;chromium/src&lt;/code&gt; directory.  Therefore it is recommended to uncomment the line indicated in &lt;code&gt;/etc/mock/chromium.cfg&lt;/code&gt;&lt;/p&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;
&lt;pre class="notranslate"&gt;&lt;code&gt;# Additional arguments to supply to systemd-nspawn
config_opts['nspawn_args'] = [
        "--setenv=DISPLAY={}".format(os.getenv("DISPLAY"))
        "--chdir={}".format(_home),
# Uncomment the&lt;/code&gt;&lt;/pre&gt;…&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/rsclarke/chrsh" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;The remainder of this article will walk through the setup of Mock, chrsh and have the Chromium source code checked out and built!&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Mock
&lt;/h3&gt;

&lt;p&gt;As per the mock &lt;a href="https://github.com/rpm-software-management/mock/wiki#download" rel="noopener noreferrer"&gt;wiki&lt;/a&gt;, setup is fairly straightforward.  Though you may wish to take note of the security implication raised when adding the user to the &lt;code&gt;mock&lt;/code&gt; group.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo dnf install mock
sudo usermod -a -G mock [User name]
newgrp -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  chrsh
&lt;/h3&gt;

&lt;p&gt;Grab the files, &lt;code&gt;chromium.cfg&lt;/code&gt; and &lt;code&gt;.bashrc&lt;/code&gt;, or clone the repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/rsclarke/chrsh.git
cd chrsh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy &lt;code&gt;chromium.cfg&lt;/code&gt; to &lt;code&gt;/etc/mock&lt;/code&gt; and add the contents of &lt;code&gt;.bashrc&lt;/code&gt; to yours.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo cp chromium.cfg /etc/mock/
cat .bashrc &amp;gt;&amp;gt; ~/.bashrc
source ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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 &lt;code&gt;~/chromium&lt;/code&gt; and will bind mount this to the home directory of your user inside the chroot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir ~/chromium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, you can create the chroot environment, which will install all necessary build tools and dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mock -r chromium init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Checking out and Building Chromium
&lt;/h2&gt;

&lt;p&gt;The remainder is an adaptation of the &lt;a href="https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md" rel="noopener noreferrer"&gt;guide&lt;/a&gt; but using &lt;code&gt;chrsh&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install &lt;code&gt;depot_tools&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chrsh git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
chrsh "echo export PATH=\$PATH:\${HOME}/depot_tools &amp;gt;&amp;gt; ~/.bashrc"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get the code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chrsh cd chromium \&amp;amp;\&amp;amp; fetch --nohooks --no-history chromium
chrsh cd chromium/src \&amp;amp;\&amp;amp; gclient runhooks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h5&gt;
  
  
  Side Note:
&lt;/h5&gt;

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

&lt;p&gt;Additionally, you can execute &lt;code&gt;chrsh&lt;/code&gt; standalone to provide a bash shell, instead of executing each command in the guide prefixed.&lt;/p&gt;




&lt;h3&gt;
  
  
  Building Chromium
&lt;/h3&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Test Targets
&lt;/h3&gt;

&lt;p&gt;Unit tests can be compiled and executed within the chroot also.  The following example builds and runs the &lt;code&gt;pdf_uinttests&lt;/code&gt;.  The argument &lt;code&gt;--gtest_filter&lt;/code&gt; can be used to select test cases.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chrsh ninja -C out/Default pdf_unittests
chrsh out/Default/pdf_unittests --gtest_filter="RangeSetTest.*"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Updating Chromium Source Checkout
&lt;/h3&gt;

&lt;p&gt;In theory, the &lt;code&gt;git rebase-update&lt;/code&gt; can be executed outside the chroot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chrsh git rebase-update
chrsh gclient sync
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Next Steps and Ideas
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h3&gt;
  
  
  Further Development
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://chromium.googlesource.com/chromium/src/+/master/docs/linux_development.md" rel="noopener noreferrer"&gt;Chromium Linux Development&lt;/a&gt; page provides more information on where to start for open issues and contributing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a Compilation Database
&lt;/h3&gt;

&lt;p&gt;Many IDEs make use of a compilation database to provide rich editing of the project you are working on.  The &lt;code&gt;generate_compdb.py&lt;/code&gt; script in the repository can help create this for you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chrsh ./tools/clang/scripts/generate_compdb.py -p out/Default &amp;gt; compile_commands.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>mock</category>
      <category>chroot</category>
      <category>chromium</category>
    </item>
  </channel>
</rss>
