-
Notifications
You must be signed in to change notification settings - Fork 3
/
nbuild.py
executable file
·71 lines (54 loc) · 1.91 KB
/
nbuild.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""NBuild: Raven-OS's automated package builder for lazy maintainers"""
import sys
import os
import re
import importlib.util
import core.args
import core.config
import stdlib.log
from multiprocessing import cpu_count
def main():
core.args.parse_args()
if core.args.get_args().purge:
from core.cache import purge_cache
stdlib.log.ilog("Purging caches... ")
purge_cache()
stdlib.log.slog("Caches purged!")
exit(0)
if core.args.get_args().manifest is None:
stdlib.log.flog("No path to a build manifest given.")
exit(1)
try:
core.config.load_config()
except Exception as e:
stdlib.log.flog(str(e))
exit(1)
# Clear environment, inflate a default one
os.environ.clear()
# Target and host architecture
# TODO FIXME Set as parameter
os.environ['TARGET'] = 'x86_64-raven-linux-gnu'
# Common flags for the gnu toolchain (cpp, cc, cxx, as, ld)
gnuflags = '-O2 -s -m64 -mtune=generic '
# Compilator flags
os.environ['CFLAGS'] = gnuflags
os.environ['CXXFLAGS'] = gnuflags
os.environ['LDFLAGS'] = gnuflags
# Misc
os.environ['TERM'] = 'xterm-256color'
os.environ['PATH'] = '/bin:/sbin/:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin'
os.environ['MAKEFLAGS'] = f'-j{cpu_count() + 1}'
# Override environment with the content of the config file
if 'env' in core.config.get_config():
os.environ.update(core.config.get_config()['env'])
manifest_path = core.args.get_args().manifest
spec = importlib.util.spec_from_file_location('build_manifest', manifest_path)
if not spec:
stdlib.log.flog(f"Failed to load Build Manifest located at path \"{manifest_path}\"")
exit(1)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
if __name__ == "__main__":
main()