-
Notifications
You must be signed in to change notification settings - Fork 8
/
acbs-build
executable file
·129 lines (117 loc) · 5.17 KB
/
acbs-build
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python3
'''
ACBS - AOSC CI Build System
A small alternative system to port abbs to CI environment to prevent
from irregular bash failures
'''
import os
import sys
import shutil
import argparse
import acbs
from acbs.const import TMP_DIR
from acbs.main import BuildCore
from acbs.query import acbs_query
from acbs.resume import do_resume_checkpoint
def main() -> None:
parser = argparse.ArgumentParser(description=help_msg(acbs.__version__
), formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('-v', '--version',
help='Show the version and exit', action="version", version=f'ACBS version {acbs.__version__}')
parser.add_argument(
'-d', '--debug', help='Increase verbosity to ease debugging process', action="store_true")
parser.add_argument(
'-e', '--reorder', help='Reorder the input build list so that it follows the dependency order', action="store_true")
parser.add_argument(
'-p', '--print-tasks', help='Save the resolved build order to the group folder and exit (dry-run)', action="store_true", dest='save_list')
parser.add_argument('-t', '--tree', nargs=1, dest='acbs_tree',
help='Specify which abbs-tree to use')
parser.add_argument('-q', '--query', nargs=1, dest='acbs_query',
help='Do a simple ACBS query')
parser.add_argument('-w', '--write', dest='acbs_write',
help='Write spec changes back (Need to be specified with -g)',
action="store_true")
parser.add_argument('packages', nargs='*', help='Packages to be built')
parser.add_argument('-c', '--clear', help='Clear build directory',
action='store_true', dest='clear_dir')
parser.add_argument('-k', '--skip-deps', help='Skip dependency resolution',
action='store_true', dest='no_deps')
parser.add_argument('-g', '--get',
help='Only download source packages without building', action="store_true")
parser.add_argument('-r', '--resume', nargs=1, dest='state_file',
help='Resume a previous build attempt')
parser.add_argument('-l', '--cache-dir', nargs=1, dest='acbs_dump_dir',
help='Override cache directory')
parser.add_argument('-o', '--log-dir', nargs=1, dest='acbs_log_dir',
help='Override log directory')
parser.add_argument('-b', '--tree-dir', nargs=1, dest='acbs_tree_dir',
help='Override abbs tree directory')
parser.add_argument('-z', '--temp-dir', nargs=1, dest='acbs_temp_dir',
help='Override temp directory')
parser.add_argument('--force-use-apt', help="Only use apt to install dependency", action="store_true", dest="force_use_apt")
parser.add_argument('--generate-package-metadata', help="Generate package metadata", action="store_true", dest="generate_pkg_metadata")
args = parser.parse_args()
if args.acbs_temp_dir:
tmp_loc = args.acbs_temp_dir[0]
else:
tmp_loc = TMP_DIR
if args.clear_dir:
clear_tmp(tmp_dir=tmp_loc)
del args.clear_dir
if args.acbs_query:
result = acbs_query(args.acbs_query[0])
if not result:
sys.exit(1)
print(result)
sys.exit(0)
if args.state_file:
do_resume_checkpoint(args.state_file[0], args)
sys.exit(0)
if args.packages:
# the rest of the arguments are passed to the build process
acbs_instance = BuildCore(args)
acbs_instance.build()
# HACK: Workaround a bug in ArgumentParser
if len(sys.argv) < 2:
parser.print_help()
sys.exit(0)
def clear_tmp(tmp_dir: str) -> None:
from time import sleep
def show_progress():
try:
print(hide_cursor, end='')
while not complete_status:
for bar in ['-', '\\', '|', '/']:
print('\r[%s/%s] Clearing cache...%s' %
(sub_dirs_deleted, sub_dirs_count, bar), end='')
sys.stdout.flush()
sleep(0.1)
print('\r[OK] Clearing cache... %s\n' %
(show_cursor), end='')
except Exception as ex:
print(show_cursor, end='')
raise ex
import threading
hide_cursor = '\033[?25l'
show_cursor = '\033[?25h'
sub_dirs = os.listdir(tmp_dir)
sub_dirs_count = len(sub_dirs)
if not sub_dirs_count:
print('Build directory clean, no need to clear...')
print(show_cursor, end='')
return
sub_dirs_deleted = 0
complete_status = False
indicator = threading.Thread(target=show_progress)
indicator.start()
for dirs in sub_dirs:
shutil.rmtree(os.path.join(tmp_dir, dirs))
sub_dirs_deleted += 1
complete_status = True
indicator.join()
return
def help_msg(acbs_version: str) -> str:
help_msg = f'''ACBS - AOSC CI Build System\nVersion: {acbs_version}\nA small alternative system to port abbs to CI environment to prevent from irregular bash failures'''
return help_msg
if __name__ == '__main__':
main()