-
Notifications
You must be signed in to change notification settings - Fork 118
/
package.py
93 lines (77 loc) · 3.03 KB
/
package.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2018 The ungoogled-chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
ungoogled-chromium packaging script for Microsoft Windows
"""
import sys
if sys.version_info.major < 3:
raise RuntimeError('Python 3 is required for this script.')
import argparse
import os
import platform
from pathlib import Path
import shutil
sys.path.insert(0, str(Path(__file__).resolve().parent / 'ungoogled-chromium' / 'utils'))
import filescfg
from _common import ENCODING, get_chromium_version
sys.path.pop(0)
def _get_release_revision():
revision_path = Path(__file__).resolve().parent / 'ungoogled-chromium' / 'revision.txt'
return revision_path.read_text(encoding=ENCODING).strip()
def _get_packaging_revision():
revision_path = Path(__file__).resolve().parent / 'revision.txt'
return revision_path.read_text(encoding=ENCODING).strip()
_cached_target_cpu = None
def _get_target_cpu(build_outputs):
global _cached_target_cpu
if not _cached_target_cpu:
with open(build_outputs / 'args.gn', 'r') as f:
args_gn_text = f.read()
for cpu in ('x64', 'x86'):
if f'target_cpu="{cpu}"' in args_gn_text:
_cached_target_cpu = cpu
break
assert _cached_target_cpu
return _cached_target_cpu
def main():
"""Entrypoint"""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'--cpu-arch',
metavar='ARCH',
default=platform.architecture()[0],
choices=('64bit', '32bit'),
help=('Filter build outputs by a target CPU. '
'This is the same as the "arch" key in FILES.cfg. '
'Default (from platform.architecture()): %(default)s'))
args = parser.parse_args()
build_outputs = Path('build/src/out/Default')
shutil.copyfile('build/src/out/Default/mini_installer.exe',
'build/ungoogled-chromium_{}-{}.{}_installer_{}.exe'.format(
get_chromium_version(), _get_release_revision(),
_get_packaging_revision(), _get_target_cpu(build_outputs)))
timestamp = None
try:
with open('build/src/build/util/LASTCHANGE.committime', 'r') as ct:
timestamp = int(ct.read())
except FileNotFoundError:
pass
output = Path('build/ungoogled-chromium_{}-{}.{}_windows_{}.zip'.format(
get_chromium_version(), _get_release_revision(),
_get_packaging_revision(), _get_target_cpu(build_outputs)))
excluded_files = set([
Path('mini_installer.exe'),
Path('mini_installer_exe_version.rc'),
Path('setup.exe'),
Path('chrome.packed.7z'),
])
files_generator = filescfg.filescfg_generator(
Path('build/src/chrome/tools/build/win/FILES.cfg'),
build_outputs, args.cpu_arch, excluded_files)
filescfg.create_archive(
files_generator, tuple(), build_outputs, output, timestamp)
if __name__ == '__main__':
main()