Browse Source

WIP Python-based building system
* Implement source downloading, integrity checking, and unpacking
* Implement domain patching
* Add version.ini
Reformat README.md for easier reading
* Separate building information into BUILDING.md

Eloston 8 years ago
parent
commit
d199e5efec
8 changed files with 285 additions and 88 deletions
  1. 10 0
      .gitignore
  2. 65 0
      BUILDING.md
  3. 15 71
      README.md
  4. 28 0
      building/debian.py
  5. 147 0
      building/generic.py
  6. 2 2
      building/templates/debian/changelog
  7. 15 15
      domain_regex_list
  8. 3 0
      version.ini

+ 10 - 0
.gitignore

@@ -0,0 +1,10 @@
+# Python files
+__pycache__/
+*.py[cod]
+
+# Ignore build sandbox
+/build_sandbox/
+
+# Ignore downloaded Chromium source archives
+/chromium-*.*.*.*.tar.xz
+/chromium-*.*.*.*.tar.xz.hashes

+ 65 - 0
BUILDING.md

@@ -0,0 +1,65 @@
+# Building ungoogled-chromium
+
+**Notice for master branch users**: The information in this document may not apply to the latest tag version. Please consult the documentation from the tag instead.
+
+ungoogled-chromium provides scripts to automate the downloading, patching, and building of Chromium with these patches. Here's an overview of the building scripts and files:
+* `build-sandbox` - This directory is the build sandbox; the container for all files used and generated during building. It is created when the building environment is setup.
+* `build_templates` - This holds the system-dependent files that are used for compiling and generating a binary package. They are copied into the build sandbox by the build setup scripts.
+  * `debian` - This contains files to generate a dpkg debian directory. Debian-specific patches are located here.
+  * `ubuntu` - This contains files to generate a dpkg debian directory for Ubuntu
+* `download_source.sh` - This script downloads the source tarball from `commondatastorage.googleapis.com` and unpacks it into the build sandbox.
+  * It accepts arguments; pass in `-h` for more information.
+* `generate_domain_substitution_list.sh` - This script generates a list of files containing domain names to be replaced
+  * It should be run at the root of the build sandbox.
+  * This script is not needed during the normal build process
+* `domain_substitution_list` - This file is generated by `generate_domain_substitution_list.sh` for a specific version of Chromium
+  * It assumes that the cleaning list has been applied
+* `domain_regex_list` - The list of regular expressions used to substitute domain names
+* `evaluate_domain_substitution_list.py` - This script evaluates the domain substitution list in the current working directory
+* `generate_cleaning_list.sh` - This script generates a file list of mostly all binary files to be stripped from the source tree.
+  * It should be run at the root of the build sandbox.
+  * This script is not needed during the normal build process
+* `cleaning_list` - This file is generated by `generate_cleaning_list.sh` for a specific version of Chromium
+* `evaluate_cleaning_list.py` - This script evaluates the cleaning list in the current working directory
+* `generate_debian_scripts.sh` - This script creates a dpkg debian directory in the build sandbox for Debian
+* `generate_ubuntu_scripts.sh` - This script creates a dpkg debian directory in the build sandbox for Ubuntu
+* `build_debian.sh` - This is the main build script for Debian and derivative distributions. It handles the downloading, patching, and building of .deb packages.
+  * This script will invoke the other scripts to do certain tasks.
+  * It accepts arguments; pass in `-h` for more information.
+
+## Debian and derivatives
+
+Distributions supported: Debian Jessie 64-bit and Stretch 64-bit, and Ubuntu Xenial 64-bit
+This may work on other Debian-based distributions and 32-bit systems
+
+**Note for Debian Jessie users**: ungoogled-chromium is configured to build against the system's [FFmpeg](https://www.ffmpeg.org/) (available in Stretch and onwards); [Libav](http://libav.org) (used in Jessie) will not work. However, FFmpeg is available in `jessie-backports`. To install it, add `jessie-backports` to the apt sources, and then install `libavutil-dev`, `libavcodec-dev`, and `libavformat-dev` from it. Note that this will replace Libav.
+
+Run these steps on the system you want to build packages for.
+
+    git clone https://github.com/Eloston/ungoogled-chromium.git
+    cd ungoogled-chromium
+    git checkout $(git describe --tags `git rev-list --tags --max-count=1`) # Checkout newest tag
+    # Run dpkg-checkbuilddeps to find packages needed for building
+    ./build_debian.sh -A
+
+Debian packages will appear under `ungoogled-chromium/`
+
+Pass the `-h` flag into `build_debian.sh` or `download_source.sh` for more options.
+
+## Arch Linux
+
+For Arch Linux, consider using [Inox patchset](https://github.com/gcarq/inox-patchset); one of the projects which ungoogled-chromium draws its patches from. It offers pre-built binaries and is also available in AUR.
+
+## Windows
+
+TODO
+
+## Other systems, platforms, and configurations
+
+Consult the build instructions on the [Chromium homepage](http://www.chromium.org/Home) to build Chromium for your system.
+
+The patches in the `patches` directory should work for any build of Chromium. They assume a clean and unmodified Chromium source tree.
+
+These patches are also tested with the GYP flags defined in [`build_templates/debian/rules`](build_templates/debian/rules). Note that enabling some flags, such as `safe_browsing`, may cause the build to fail.
+
+Note about `domain_substitution_list`: Replacing the domains will break URLs in the source tree pointing to Google servers. If your building steps requires additional downloads (such as the the PNaCl toolkit), scripts in the source tree may fail to work.

+ 15 - 71
README.md

@@ -1,5 +1,5 @@
 # ungoogled-chromium
-**Patches for Google Chromium to remove integration with Google services and add additional features**
+**Google Chromium patches for removing Google integration, enhancing privacy, and adding features**
 
 ### Features
 
@@ -19,13 +19,22 @@ In addition to features provided by [Iridium Browser](https://iridiumbrowser.de/
 * (Iridium Browser feature change) Prevent URLs with the `trk:` scheme from connecting to the Internet
 * (Iridium and Inox feature change) Prevent pinging of IPv6 address when detecting the availability of IPv6
 
-## Patches
+## Getting ungoogled-chromium
 
-All features come in the form of patches. Patches are stored in the `patches` directory, with the exception of platform-specific patches (which are in the `build_templates` directory).
+Users are encouraged to use [one of the available tag](https://github.com/Eloston/ungoogled-chromium/tags) versions. Binaries are available on [the releases page](https://github.com/Eloston/ungoogled-chromium/releases) for the corresponding tag.
 
-The latest set of patches are available on [the tags page](https://github.com/Eloston/ungoogled-chromium/tags). See the Building section below for information on using these patches.
+Tags are formatted in the following manner: `{chromium_version}-{release_revision}` where
 
-Here's an overview of the files in the `patches` directory:
+* `chromium_version` is the version of Chromium used in `x.x.x.x` format, and
+* `release_revision` is an integer indicating the version of ungoogled-chromium for the corresponding Chromium version.
+
+The `master` branch is for development, so it is not guarenteed to be in a working state.
+
+## How ungoogled-chromium is designed
+
+All features are implemented through patches. Patches are contained within the `patches` directory, with the exception of platform-specific patches in the `building/templates` directory
+
+A summary of the files in the `patches` directory:
 * `ungoogled-chromium/`
   * This directory contains new patches for ungoogled-chromium. They implement the features described above.
 * `iridium-browser`
@@ -42,74 +51,9 @@ Here's an overview of the files in the `patches` directory:
 * `patch_order`
   * Determines which patches are used and what order they should be applied
 
-## Releases
-
-Builds with these patches are available on [the releases page](https://github.com/Eloston/ungoogled-chromium/releases).
-
 ## Building
 
-**NOTE**: The master branch is not always in a working state. [Tag versions](https://github.com/Eloston/ungoogled-chromium/tags) are guaranteed to work.
-
-ungoogled-chromium provides scripts to automate the downloading, patching, and building of Chromium with these patches. Here's an overview of the building scripts and files:
-* `build-sandbox` - This directory is the build sandbox; the container for all files used and generated during building. It is created when the building environment is setup.
-* `build_templates` - This holds the system-dependent files that are used for compiling and generating a binary package. They are copied into the build sandbox by the build setup scripts.
-  * `debian` - This contains files to generate a dpkg debian directory. Debian-specific patches are located here.
-  * `ubuntu` - This contains files to generate a dpkg debian directory for Ubuntu
-* `download_source.sh` - This script downloads the source tarball from `commondatastorage.googleapis.com` and unpacks it into the build sandbox.
-  * It accepts arguments; pass in `-h` for more information.
-* `generate_domain_substitution_list.sh` - This script generates a list of files containing domain names to be replaced
-  * It should be run at the root of the build sandbox.
-  * This script is not needed during the normal build process
-* `domain_substitution_list` - This file is generated by `generate_domain_substitution_list.sh` for a specific version of Chromium
-  * It assumes that the cleaning list has been applied
-* `domain_regex_list` - The list of regular expressions used to substitute domain names
-* `evaluate_domain_substitution_list.py` - This script evaluates the domain substitution list in the current working directory
-* `generate_cleaning_list.sh` - This script generates a file list of mostly all binary files to be stripped from the source tree.
-  * It should be run at the root of the build sandbox.
-  * This script is not needed during the normal build process
-* `cleaning_list` - This file is generated by `generate_cleaning_list.sh` for a specific version of Chromium
-* `evaluate_cleaning_list.py` - This script evaluates the cleaning list in the current working directory
-* `generate_debian_scripts.sh` - This script creates a dpkg debian directory in the build sandbox for Debian
-* `generate_ubuntu_scripts.sh` - This script creates a dpkg debian directory in the build sandbox for Ubuntu
-* `build_debian.sh` - This is the main build script for Debian and derivative distributions. It handles the downloading, patching, and building of .deb packages.
-  * This script will invoke the other scripts to do certain tasks.
-  * It accepts arguments; pass in `-h` for more information.
-
-### Debian and derivatives
-Distributions supported: Debian Jessie 64-bit and Stretch 64-bit, and Ubuntu Xenial 64-bit
-This may work on other Debian-based distributions and 32-bit systems
-
-**Note for Debian Jessie users**: ungoogled-chromium is configured to build against the system's [FFmpeg](https://www.ffmpeg.org/) (available in Stretch and onwards); [Libav](http://libav.org) (used in Jessie) will not work. However, FFmpeg is available in `jessie-backports`. To install it, add `jessie-backports` to the apt sources, and then install `libavutil-dev`, `libavcodec-dev`, and `libavformat-dev` from it. Note that this will replace Libav.
-
-Run these steps on the system you want to build packages for.
-
-    git clone https://github.com/Eloston/ungoogled-chromium.git
-    cd ungoogled-chromium
-    git checkout $(git describe --tags `git rev-list --tags --max-count=1`) # Checkout newest tag
-    # Run dpkg-checkbuilddeps to find packages needed for building
-    ./build_debian.sh -A
-
-Debian packages will appear under `ungoogled-chromium/`
-
-Pass the `-h` flag into `build_debian.sh` or `download_source.sh` for more options.
-
-### Arch Linux
-
-For Arch Linux, consider using [Inox patchset](https://github.com/gcarq/inox-patchset); one of the projects which ungoogled-chromium draws its patches from. It offers pre-built binaries and is also available in AUR.
-
-### Windows
-
-TODO
-
-### Other systems, platforms, and configurations
-
-Consult the build instructions on the [Chromium homepage](http://www.chromium.org/Home) to build Chromium for your system.
-
-The patches in the `patches` directory should work for any build of Chromium. They assume a clean and unmodified Chromium source tree.
-
-These patches are also tested with the GYP flags defined in [`build_templates/debian/rules`](build_templates/debian/rules). Note that enabling some flags, such as `safe_browsing`, may cause the build to fail.
-
-Note about `domain_substitution_list`: Replacing the domains will break URLs in the source tree pointing to Google servers. If your building steps requires additional downloads (such as the the PNaCl toolkit), scripts in the source tree may fail to work.
+[See BUILDING.md](BUILDING.md)
 
 ## Contributing
 

+ 28 - 0
building/debian.py

@@ -0,0 +1,28 @@
+'''
+    ungoogled-chromium: Google Chromium patches for removing Google integration, enhancing privacy, and adding features
+    Copyright (C) 2016  Eloston
+
+    This file is part of ungoogled-chromium.
+
+    ungoogled-chromium is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    ungoogled-chromium is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with ungoogled-chromium.  If not, see <http://www.gnu.org/licenses/>.
+'''
+
+from . import generic
+
+class DebianPlatform(generic.GenericPlatform):
+    def generate_orig_tar_xz(self, tar_xz_path):
+        pass
+
+    def generate_debian_tar_xz(self, tar_xz_path):
+        pass

+ 147 - 0
building/generic.py

@@ -0,0 +1,147 @@
+'''
+    ungoogled-chromium: Google Chromium patches for removing Google integration, enhancing privacy, and adding features
+    Copyright (C) 2016  Eloston
+
+    This file is part of ungoogled-chromium.
+
+    ungoogled-chromium is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    ungoogled-chromium is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with ungoogled-chromium.  If not, see <http://www.gnu.org/licenses/>.
+'''
+
+# Generic platform building class
+
+import tarfile
+import urllib.request
+import hashlib
+import pathlib
+import shutil
+import re
+import subprocess
+
+class GenericPlatform:
+    def __init__(self, logger, version, revision, sandbox_root, python2_binary, gn_binary, ninja_binary, sourcearchive, sourcearchive_hashes):
+        self.logger = logger
+        self.version = version
+        self.revision = revision
+        self.sandbox_root = sandbox_root
+        self.python2_binary = python2_binary
+        self.gn_binary = gn_binary
+        self.ninja_binary = ninja_binary
+        self.sourcearchive = sourcearchive
+        self.sourcearchive_hashes = sourcearchive_hashes
+
+    def check_source_archive(self):
+        '''
+        Run hash checks over archive_path using hashes_path
+        '''
+        with self.sourcearchive_hashes.open("r") as hashes_file:
+            for hash_line in hashes_file.read().split("\n"):
+                hash_line = hash_line.split("  ")
+                if hash_line[0] in hashlib.algorithms_available:
+                    self.logger.info("Running '{}' hash check...".format(hash_line[0]))
+                    hasher = hashlib.new(hash_line[0])
+                    with self.sourcearchive.open("rb") as f:
+                        hasher.update(f.read())
+                        if hasher.hexdigest() == hash_line[1]:
+                            self.logger.debug("'{}' hash matches".format(hash_line[0]))
+                        else:
+                            self.logger.error("Archive does not have matching '{algorithm}' hash '{hashhex}'".format(algorithm=hash_line[0], hashhex=hash_line[1]))
+                            return None
+                else:
+                    self.logger.warning("Hash algorithm '{}' not available. Skipping...".format(hash_line[0]))
+
+    def download_source_archive(self, destination_dir):
+        '''
+        Downloads the original Chromium source code in archive format along with its hashes file
+        Sets the `sourcearchive` and `sourcearchive_hashes` attributes to the newely downloaded files
+        '''
+        download_url = "https://commondatastorage.googleapis.com/chromium-browser-official/chromium-{version}.tar.xz".format(version=self.version)
+        hashes_url = download_url + ".hashes"
+        archive_path = destination_dir / pathlib.Path("chromium-{version}.tar.xz".format(version=self.version))
+        hashes_path = destination_dir / pathlib.Path("chromium-{version}.tar.xz.hashes".format(version=self.version))
+
+        self.logger.info("Downloading {} ...".format(download_url))
+
+        with urllib.request.urlopen(download_url) as response:
+            with archive_path.open("wb") as f:
+                shutil.copyfileobj(response, f)
+
+        self.logger.info("Downloading archive hashes...")
+
+        with urllib.request.urlopen(hashes_url) as response:
+            with hashes_path.open("wb") as f:
+                shutil.copyfileobj(response, f)
+
+        self.logger.info("Finished downloading source archive")
+
+        self.sourcearchive = archive_path
+        self.sourcearchive_hashes = hashes_path
+
+    def extract_source_archive(self, cleaning_list):
+        '''
+        Extract the archive located on archive_path to the sandbox root
+        Also modifies cleaning_list to contain paths not removed
+        '''
+        class NoAppendList(list): # Hack to workaround memory issues with large tar files
+            def append(self, obj):
+                pass
+
+        with tarfile.open(str(self.sourcearchive)) as tar_file_obj:
+            tar_file_obj.members = NoAppendList()
+            for tarinfo in tar_file_obj:
+                relative_path = pathlib.PurePosixPath(tarinfo.name).relative_to("chromium-{}".format(self.version))
+                if str(relative_path) in cleaning_list:
+                    cleaning_list.remove(str(relative_path))
+                else:
+                    destination = self.sandbox_root / relative_path
+                    tar_file_obj.extract(tarinfo, path=str(destination))
+
+    def domain_substitute(self, regex_strings, file_list):
+        '''
+        Run domain substitution with regex_strings over files file_list
+        '''
+        regex_list = list()
+        for expression in regex_strings:
+            expression = expression.split("#")
+            regex_list.append((re.compile(expression[0]), expression[1]))
+        for path in file_list:
+            with open(path, mode="r+") as f:
+                content = f.read()
+                file_subs = 0
+                for regex_pair in regex_list:
+                    compiled_regex, replacement_regex = regex_pair
+                    content, number_of_subs = compiled_regex.subn(replacement_regex, content)
+                    file_subs += number_of_subs
+                if file_subs > 0:
+                    f.seek(0)
+                    f.write(content)
+                else:
+                    self.logger.warning("File {} has no matches".format(path))
+
+    def build_gn(self):
+        '''
+        Build the GN tool to out/gn-tool in the build sandbox and set the attribute `gn_binary`
+        '''
+        
+
+    def setup_building_utilities(self):
+        '''
+        For now, this function builds GN
+        '''
+        pass
+
+    def configure(self): # Run GN configuration
+        pass
+
+    def build(self): # Run build command
+        pass

+ 2 - 2
building/templates/debian/changelog

@@ -1,5 +1,5 @@
-chromium-browser (51.0.2704.81-1) stretch; urgency=low
+chromium-browser (51.0.2704.84-1) stretch; urgency=low
 
   * New upstream version
 
- -- Eloston <eloston@null>  Fri, 03 Jun 2016 00:00:00 +0000
+ -- Eloston <eloston@null>  Mon, 06 Jun 2016 00:00:00 +0000

+ 15 - 15
domain_regex_list

@@ -1,16 +1,16 @@
 fonts\.googleapis\.com#about:blank
-google([A-Za-z\-]*)\.com#9oo91e\1\.qjz9zk
-gstatic([A-Za-z\-]*)\.com#95tat1c\1\.qjz9zk
-chrome([A-Za-z\-]*)\.com#ch40me\1\.qjz9zk
-chromium([A-Za-z\-]*)\.org#ch40m1um\1\.qjz9zk
-mozilla([A-Za-z\-]*)\.org#m0z111a\1\.qjz9zk
-facebook([A-Za-z\-]*)\.com#f8c3b00k\1\.qjz9zk
-appspot([A-Za-z\-]*)\.com#8pp2p8t\1\.qjz9zk
-youtube([A-Za-z\-]*)\.com#y0u1ub3\1\.qjz9zk
-ytimg([A-Za-z\-]*)\.com#yt1mg\1\.qjz9zk
-gmail([A-Za-z\-]*)\.com#9ma1l\1\.qjz9zk
-doubleclick([A-Za-z\-]*)\.net#60u613cl1c4\1\.qjz9zk
-googlezip\.net#9oo91e21p\.qjz9zk
-beacons([1-9]?)\.gvt([1-9]?)\.com#b3ac0n2\1\.9vt\2\.qjz9zk
-ggpht\.com#99pht\.qjz9zk
-microsoft\.com#m1cr050ft\.qjz9zk
+google([A-Za-z\-]*)\.com#9oo91e\1.qjz9zk
+gstatic([A-Za-z\-]*)\.com#95tat1c\1.qjz9zk
+chrome([A-Za-z\-]*)\.com#ch40me\1.qjz9zk
+chromium([A-Za-z\-]*)\.org#ch40m1um\1.qjz9zk
+mozilla([A-Za-z\-]*)\.org#m0z111a\1.qjz9zk
+facebook([A-Za-z\-]*)\.com#f8c3b00k\1.qjz9zk
+appspot([A-Za-z\-]*)\.com#8pp2p8t\1.qjz9zk
+youtube([A-Za-z\-]*)\.com#y0u1ub3\1.qjz9zk
+ytimg([A-Za-z\-]*)\.com#yt1mg\1.qjz9zk
+gmail([A-Za-z\-]*)\.com#9ma1l\1.qjz9zk
+doubleclick([A-Za-z\-]*)\.net#60u613cl1c4\1.qjz9zk
+googlezip\.net#9oo91e21p.qjz9zk
+beacons([1-9]?)\.gvt([1-9]?)\.com#b3ac0n2\1.9vt\2.qjz9zk
+ggpht\.com#99pht.qjz9zk
+microsoft\.com#m1cr050ft.qjz9zk

+ 3 - 0
version.ini

@@ -0,0 +1,3 @@
+[main]
+chromium_version = 51.0.2704.106
+release_revision = 1