-
Notifications
You must be signed in to change notification settings - Fork 5
/
rebuild-simulator
executable file
·77 lines (62 loc) · 2.71 KB
/
rebuild-simulator
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
#!/usr/bin/python
import argparse
from collections import defaultdict
import colorlog
import pyalpm
import sys
logger = colorlog.getLogger()
logger.setLevel(colorlog.DEBUG)
handler = colorlog.StreamHandler()
handler.setFormatter(colorlog.ColoredFormatter())
logger.addHandler(handler)
package_db = defaultdict(dict)
handle = pyalpm.Handle(".", "/var/lib/pacman")
for db in ["core", "extra", "community", "multilib"]:
db_handle = handle.register_syncdb(db, 0)
for package in db_handle.search(""):
for field in ("depends", "makedepends", "checkdepends"):
package_db[package.name][field] = getattr(package, field)
parser = argparse.ArgumentParser(description='Rebuild simulator, simulates a rebuild and yell out when broken')
parser.add_argument('-M', '--makedepends-are-checkdepends', action="store_true", help="Treat makedepends as checkdepends (ignore brokenness in nocheck builds)")
parser.add_argument('-1', '--immediate-fail', action="store_true", help="Exit on first failure")
parser.add_argument('package', nargs='+', help='Packages to rebuild')
args = parser.parse_args()
rebuild_list = {pkg for pkg in args.package if not pkg.endswith(":nocheck")}
package_broken = {package: False for package in rebuild_list}
def check_broken(pkgs):
for d in pkgs:
if d in rebuild_list:
if package_broken[d]:
logger.critical(f"Package {d} is broken, cannot rebuild {package}!")
if args.immediate_fail:
sys.exit(1)
def make_broken(pkg, rebuilt_package):
if not package_broken[pkg]:
package_broken[pkg] = True
logger.warning(f"Package {pkg} is broken after rebuilding {rebuilt_package}")
for p in package_db:
if p in rebuilt_package and p in package_db[p]["depends"] and not package_broken[p]:
make_broken(p, rebuilt_package)
logger.info("Starting rebuild")
for package in args.package:
logger.info(f"Rebuilding {package}")
if package.endswith(":nocheck"):
package = package[:-8]
else:
check_broken(package_db[package]["checkdepends"])
if args.makedepends_are_checkdepends:
check_broken(package_db[package]["makedepends"])
check_broken(package_db[package]["depends"])
if not args.makedepends_are_checkdepends:
check_broken(package_db[package]["makedepends"])
package_broken[package] = False
for p in package_db:
if p in rebuild_list:
if package in package_db[p]["depends"]:
make_broken(p, package)
for package in package_broken:
if package_broken[package]:
logger.critical(f"Package {package} is still broken after rebuild finished!")
break
else:
logger.info("Rebuild finished successfully.")