forked from alisw/alibuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliBuild
executable file
·141 lines (125 loc) · 4.31 KB
/
aliBuild
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
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
import atexit
import logging
import traceback
from os.path import exists, expanduser
from alibuild_helpers import __version__
from alibuild_helpers.analytics import decideAnalytics, askForAnalytics, report_screenview, report_exception, report_event
from alibuild_helpers.analytics import enable_analytics, disable_analytics
from alibuild_helpers.args import doParseArgs
from alibuild_helpers.init import doInit
from alibuild_helpers.clean import doClean
from alibuild_helpers.doctor import doDoctor
from alibuild_helpers.deps import doDeps
from alibuild_helpers.log import info, warning, debug, logger, error
from alibuild_helpers.utilities import detectArch
from alibuild_helpers.build import doBuild
def doMain(args, parser):
# We need to unset BASH_ENV because in certain environments (e.g.
# NERSC) this is used to source a (non -e safe) bashrc, effectively
# breaking aliBuild.
# We set all the locale related environment to C to make sure
# do not get fooled when parsing localized messages.
# We set ALIBUILD_ARCHITECTURE so that it's picked up by the external
# command which does the reporting.
if not "architecture" in args:
args.architecture = detectArch()
ENVIRONMENT_OVERRIDES = {
"LANG": "C",
"LANGUAGE": "C",
"LC_ALL": "C",
"LC_COLLATE": "C",
"LC_CTYPE": "C",
"LC_MESSAGES": "C",
"LC_MONETARY": "C",
"LC_NUMERIC": "C",
"LC_TIME": "C",
"LC_ALL": "C",
"GREP_OPTIONS": "",
"BASH_ENV": "",
"ALIBUILD_ARCHITECTURE": args.architecture
}
os.environ.update(ENVIRONMENT_OVERRIDES)
report_screenview(args.action)
# Move to the specified working directory before doing anything else
if "chdir" in args:
try:
os.chdir(os.path.expanduser(args.chdir))
debug("Current working directory is %s" % os.getcwd())
except Exception as e:
error("Cannot change to directory \"%s\"." % args.chdir)
error(e.message)
exit(1)
if args.action == "version":
print("aliBuild version: {version} ({arch})".format(
version=__version__, arch=args.architecture or "unknown"))
sys.exit(0)
if args.action == "doctor":
doDoctor(args, parser)
logger.setLevel(logging.DEBUG if args.debug else logging.INFO)
if args.action == "deps":
sys.exit(0 if doDeps(args, parser) else 1)
if args.action == "clean":
doClean(workDir=args.workDir, architecture=args.architecture, aggressiveCleanup=args.aggressiveCleanup, dryRun=args.dryRun)
exit(0)
# Setup build environment.
if args.action == "init":
doInit(args)
exit(0)
if args.action == "build":
sys.exit(doBuild(args, parser))
if __name__ == "__main__":
args, parser = doParseArgs()
# This is valid for everything
logger.setLevel(logging.DEBUG if args.debug else logging.INFO)
os.environ["ALIBUILD_ANALYTICS_ID"] = "UA-77346950-1"
os.environ["ALIBUILD_VERSION"] = __version__
if args.action == "analytics":
if args.state == "off":
disable_analytics()
else:
enable_analytics()
exit(0)
elif args.action == "architecture":
arch = detectArch()
print(arch if arch else "<unknown>")
exit(0)
if not decideAnalytics(exists(expanduser("~/.config/alibuild/disable-analytics")),
exists(expanduser("~/.config/alibuild/analytics-uuid")),
sys.stdin.isatty(),
askForAnalytics):
os.environ["ALIBUILD_NO_ANALYTICS"] = "1"
else:
os.environ["ALIBUILD_ANALYTICS_USER_UUID"] = open(expanduser("~/.config/alibuild/analytics-uuid")).read().strip()
try:
profiler = "--profile" in sys.argv
if profiler:
print("profiler started")
import cProfile, pstats
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
pr = cProfile.Profile()
pr.enable()
def profiler():
pr.disable()
print("profiler stopped")
s = StringIO()
sortby = 'time'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats()
print(s.getvalue())
atexit.register(profiler)
doMain(args, parser)
except KeyboardInterrupt as e:
info(str(e))
report_event("user", "ctrlc")
exit(1)
except Exception as e:
traceback.print_exc()
report_exception(e)
exit(1)