Skip to content

Commit 926e892

Browse files
committed
Reorganize resources into new directories
Rename building module to buildlib Refactor buildlib for easier and cleaner platform extensions Update developer utilities to work with buildlib
1 parent dca44ef commit 926e892

File tree

131 files changed

+260
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+260
-239
lines changed

building/debian.py

Lines changed: 0 additions & 188 deletions
This file was deleted.

buildlib/debian.py

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# ungoogled-chromium: Google Chromium patches for removing Google integration, enhancing privacy, and adding features
2+
# Copyright (C) 2016 Eloston
3+
#
4+
# This file is part of ungoogled-chromium.
5+
#
6+
# ungoogled-chromium is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# ungoogled-chromium is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with ungoogled-chromium. If not, see <http://www.gnu.org/licenses/>.
18+
19+
'''Code for Debian and its derivatives'''
20+
21+
import pathlib
22+
import distutils.dir_util
23+
import os
24+
import subprocess
25+
import itertools
26+
import tempfile
27+
import locale
28+
import datetime
29+
import re
30+
import string
31+
32+
from . import generic
33+
34+
class DebianPlatform(generic.GenericPlatform):
35+
PLATFORM_RESOURCES = pathlib.Path("resources", "debian")
36+
DPKG_DIR = PLATFORM_RESOURCES / pathlib.Path("dpkg_dir")
37+
38+
class BuildFileStringTemplate(string.Template): # Inspired by http://stackoverflow.com/questions/12768107/string-substitutions-using-templates-in-python
39+
pattern = r"""
40+
{delim}(?:
41+
(?P<escaped>{delim}) |
42+
_(?P<named>{id}) |
43+
{{(?P<braced>{id})}} |
44+
(?P<invalid>{delim}((?!_)|(?!{{)))
45+
)
46+
""".format(delim=re.escape("$ungoog"), id=string.Template.idpattern)
47+
48+
def __init__(self, *args, **kwargs):
49+
super(DebianPlatform, self).__init__(*args, **kwargs)
50+
51+
self.sandbox_patches = self.ungoogled_dir / self.PATCHES
52+
self.sandbox_dpkg_dir = self.sandbox_root / pathlib.Path("debian")
53+
54+
self.quilt_env_vars = {
55+
"QUILT_PATCHES": str(self.UNGOOGLED_DIR / self.PATCHES),
56+
"QUILT_SERIES": str(self.PATCH_ORDER)
57+
}
58+
59+
def _get_dpkg_changelog_datetime(self, override_datetime=None):
60+
if override_datetime is None:
61+
current_datetime = datetime.date.today()
62+
else:
63+
current_datetime = override_datetime
64+
current_lc = locale.setlocale(locale.LC_TIME)
65+
try:
66+
locale.setlocale(locale.LC_TIME, "C")
67+
result = current_datetime.strftime("%a, %d %b %Y %H:%M:%S ")
68+
timezone = current_datetime.strftime("%z")
69+
if len(timezone) == 0:
70+
timezone = "+0000"
71+
return result + timezone
72+
finally:
73+
locale.setlocale(locale.LC_TIME, current_lc)
74+
75+
def generate_orig_tar_xz(self, tar_xz_path):
76+
pass
77+
78+
def generate_debian_tar_xz(self, tar_xz_path):
79+
pass
80+
81+
def setup_build_sandbox(self, *args, **kwargs):
82+
super(DebianPlatform, self).setup_build_sandbox(*args, **kwargs)
83+
84+
# Symlink flot libraries
85+
for system_path in itertools.chain(pathlib.Path("/").glob("usr/share/javascript/jquery/*min.js"), pathlib.Path("/").glob("usr/share/javascript/jquery-flot/*min.js")):
86+
symlink_path = self.sandbox_root / pathlib.Path("third_party", "flot", system_path.name)
87+
self.logger.debug("Symlinking flot library {} ...".format(system_path.name))
88+
if symlink_path.exists():
89+
symlink_path.unlink()
90+
symlink_path.symlink_to(system_path)
91+
92+
def apply_patches(self):
93+
self.logger.debug("Copying patches to {}...".format(str(self.sandbox_patches)))
94+
95+
if self.sandbox_patches.exists():
96+
raise Exception("Sandbox patches directory already exists")
97+
98+
self._generate_patches(self.sandbox_patches, self._ran_domain_substitution)
99+
100+
self.logger.info("Applying patches via quilt...")
101+
new_env = dict(os.environ)
102+
new_env.update(self.quilt_env_vars)
103+
result = subprocess.run(["quilt", "push", "-a"], env=new_env, cwd=str(self.sandbox_root))
104+
if not result.returncode == 0:
105+
raise Exception("Quilt returned non-zero exit code: {}".format(result.returncode))
106+
107+
#def generate_build_configuration(self, gn_args=pathlib.Path("gn_args.ini"), build_output=pathlib.Path("out", "Default"), debian_gn_args=(self.PLATFORM_RESOURCES / pathlib.Path("gn_args.ini")):
108+
# (self.sandbox_root / build_output).mkdir(parents=True, exist_ok=True)
109+
# common_config = configparser.ConfigParser()
110+
# common_config.read(str(gn_args))
111+
# debian_config = configparser.ConfigParser()
112+
# debian_config.read(str(debian_gn_args))
113+
# combined_dict = dict()
114+
# for section in common_config:
115+
# if not section == "DEFAULT":
116+
# combined_dict[section] = dict()
117+
# for config_key in common_config[section]:
118+
# combined_dict[section][config_key] = common_config[section][config_key]
119+
# for section in debian_config:
120+
# if not section == "DEFAULT":
121+
# if not section in combined_dict:
122+
# combined_dict[section] = dict()
123+
# for config_key in debian_config[section]:
124+
# combined_dict[section][config_key] = debian_config[section][config_key]
125+
# self._gn_write_args(combined_dict, build_output)
126+
# self._gn_generate_ninja(build_output)
127+
128+
def build(self, build_targets=["chrome", "chrome_sandbox", "chromedriver"]):
129+
super(DebianPlatform, self).build(build_targets)
130+
131+
def generate_package(self):
132+
if self.build_output is None:
133+
raise Exception("build_output member variable is not defined. Run generate_build_configuration() first or set it manually")
134+
build_file_subs = dict(
135+
changelog_version="{}-{}".format(self.version, self.revision),
136+
changelog_datetime=self._get_dpkg_changelog_datetime(),
137+
build_output=str(self.build_output)
138+
)
139+
self.logger.info("Building Debian package...")
140+
distutils.dir_util.copy_tree(str(self.DPKG_DIR), str(self.sandbox_dpkg_dir))
141+
for old_path in self.sandbox_dpkg_dir.glob("*.in"):
142+
new_path = self.sandbox_dpkg_dir / old_path.stem
143+
old_path.replace(new_path)
144+
with new_path.open("r+") as new_file:
145+
content = self.BuildFileStringTemplate(new_file.read()).substitute(**build_file_subs)
146+
new_file.seek(0)
147+
new_file.write(content)
148+
new_file.truncate()
149+
result = subprocess.run(["dpkg-buildpackage", "-b", "-uc"], cwd=str(self.sandbox_root))
150+
if not result.returncode == 0:
151+
raise Exception("dpkg-buildpackage returned non-zero exit code: {}".format(result.returncode))

0 commit comments

Comments
 (0)