Skip to content

Commit dca44ef

Browse files
committed
Improve and add more variable substitutions for debian packaging
Change fastbuild flag from 1 to 2 Ignore Debian changes file
1 parent 04e8c6b commit dca44ef

15 files changed

+62
-45
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ __pycache__/
1111

1212
# Ignore packages
1313
/*.deb
14+
/chromium-browser_*.changes

building/debian.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import tempfile
2727
import locale
2828
import datetime
29+
import re
30+
import string
2931

3032
from . import generic
3133

@@ -154,22 +156,33 @@ def get_changelog_date(override_datetime=None):
154156
return result + timezone
155157
finally:
156158
locale.setlocale(locale.LC_TIME, current_lc)
157-
template_parsing_defs = {
158-
("changelog.in", "changelog"): {
159-
"VERSION": "{}-{}".format(self.version, self.revision),
160-
"DATETIME": get_changelog_date()
161-
}
162-
}
159+
160+
class CustomTemplate(string.Template): # Inspired by http://stackoverflow.com/questions/12768107/string-substitutions-using-templates-in-python
161+
pattern = r"""
162+
{delim}(?:
163+
(?P<escaped>{delim}) |
164+
_(?P<named>{id}) |
165+
{{(?P<braced>{id})}} |
166+
(?P<invalid>{delim}((?!_)|(?!{{)))
167+
)
168+
""".format(delim=re.escape("$ungoog"), id=string.Template.idpattern)
169+
170+
template_parsing_defs = dict(
171+
changelog_version="{}-{}".format(self.version, self.revision),
172+
changelog_datetime=get_changelog_date(),
173+
build_output=str(self.build_output)
174+
)
163175
self.logger.info("Building Debian package...")
164176
destination_dpkg_dir = self.sandbox_root / pathlib.Path("debian")
165177
distutils.dir_util.copy_tree(str(self.PLATFORM_RESOURCES / pathlib.Path("dpkg_dir")), str(destination_dpkg_dir))
166-
for template_expr in template_parsing_defs:
167-
old_name, new_name = template_expr
168-
with (destination_dpkg_dir / pathlib.Path(old_name)).open() as old_file:
169-
content = old_file.read().format(**template_parsing_defs[template_expr])
170-
with (destination_dpkg_dir / pathlib.Path(new_name)).open("w") as new_file:
171-
new_file.write(content)
172-
(destination_dpkg_dir / pathlib.Path(old_name)).unlink()
178+
for old_path in destination_dpkg_dir.glob("*.in"):
179+
new_path = destination_dpkg_dir / old_path.stem
180+
old_path.replace(new_path)
181+
with new_path.open("r+") as new_file:
182+
content = CustomTemplate(new_file.read()).substitute(**template_parsing_defs)
183+
new_file.seek(0)
184+
new_file.write(content)
185+
new_file.truncate()
173186
result = subprocess.run(["dpkg-buildpackage", "-b", "-uc"], cwd=str(self.sandbox_root))
174187
if not result.returncode == 0:
175188
raise Exception("dpkg-buildpackage returned non-zero exit code: {}".format(result.returncode))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
chromium-browser ({VERSION}) stretch; urgency=low
1+
chromium-browser ($ungoog{changelog_version}) stretch; urgency=low
22

33
* New version
44

5-
-- Eloston <eloston@null> {DATETIME}
5+
-- Eloston <eloston@null> $ungoog{changelog_datetime}

building/resources/debian/dpkg_dir/chrome-sandbox.install

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ungoog{build_output}/chrome-sandbox usr/lib/chromium

building/resources/debian/dpkg_dir/chromedriver.install

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ungoog{build_output}/chromedriver usr/lib/chromium

building/resources/debian/dpkg_dir/chromium-l10n.install

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ungoog{build_output}/locales usr/lib/chromium

building/resources/debian/dpkg_dir/chromium.install

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

0 commit comments

Comments
 (0)