1 | from __future__ import print_function |
---|
2 | |
---|
3 | import os |
---|
4 | import sys |
---|
5 | import tools |
---|
6 | |
---|
7 | try : |
---|
8 | testpath = os.path.dirname(os.path.abspath(os.path.join(os.getcwd(), sys.argv[0]))) |
---|
9 | sys.path.append(testpath) |
---|
10 | import config |
---|
11 | |
---|
12 | SRCDIR = os.path.abspath(config.SRCDIR) |
---|
13 | BUILDDIR = os.path.abspath(config.BUILDDIR) |
---|
14 | os.chdir(testpath) |
---|
15 | |
---|
16 | except: |
---|
17 | print('ERROR: missing config.py, re-run configure script.', file=sys.stderr) |
---|
18 | sys.exit(1) |
---|
19 | |
---|
20 | class Architecture: |
---|
21 | KnownArchitectures = { |
---|
22 | 'x64' : 'x64', |
---|
23 | 'x86-64' : 'x64', |
---|
24 | 'x86_64' : 'x64', |
---|
25 | 'x86' : 'x86', |
---|
26 | 'i386' : 'x86', |
---|
27 | 'i486' : 'x86', |
---|
28 | 'i686' : 'x86', |
---|
29 | 'Intel 80386' : 'x86', |
---|
30 | 'arm' : 'arm', |
---|
31 | 'ARM' : 'arm', |
---|
32 | } |
---|
33 | |
---|
34 | CrossCompileFlags = { |
---|
35 | 'x64' : 'ARCH_FLAGS=-m64', |
---|
36 | 'x86' : 'ARCH_FLAGS=-m32', |
---|
37 | } |
---|
38 | |
---|
39 | def __init__(self, arch): |
---|
40 | try: |
---|
41 | canonical_host = Architecture.makeCanonical( config.HOSTARCH ) |
---|
42 | except KeyError: |
---|
43 | print("Unkown host architecture %s" % config.HOSTARCH, file=sys.stderr) |
---|
44 | sys.exit(1) |
---|
45 | |
---|
46 | if arch: |
---|
47 | try: |
---|
48 | arch = Architecture.makeCanonical( arch ) |
---|
49 | except KeyError: |
---|
50 | print("Unkown architecture %s" % arch, file=sys.stderr) |
---|
51 | sys.exit(1) |
---|
52 | |
---|
53 | if arch and arch != canonical_host: |
---|
54 | self.target = arch |
---|
55 | self.cross_compile = True |
---|
56 | else: |
---|
57 | self.target = canonical_host |
---|
58 | self.cross_compile = False |
---|
59 | |
---|
60 | |
---|
61 | try : |
---|
62 | self.flags = Architecture.CrossCompileFlags[self.target] |
---|
63 | except KeyError: |
---|
64 | print("Cross compilation not available for architecture %s" % self.target, file=sys.stderr) |
---|
65 | sys.exit(1) |
---|
66 | |
---|
67 | self.string = self.target |
---|
68 | |
---|
69 | def update(self): |
---|
70 | if not self.cross_compile: |
---|
71 | self.target = machine_default() |
---|
72 | self.string = self.target |
---|
73 | print("updated to %s" % self.target) |
---|
74 | |
---|
75 | def match(self, arch): |
---|
76 | return True if not arch else self.target == arch |
---|
77 | |
---|
78 | @classmethod |
---|
79 | def makeCanonical(_, arch): |
---|
80 | return Architecture.KnownArchitectures[arch] |
---|
81 | |
---|
82 | |
---|
83 | class Debug: |
---|
84 | def __init__(self, value): |
---|
85 | self.string = "debug" if value else "no debug" |
---|
86 | self.flags = """DEBUG_FLAGS="%s" """ % ("-debug -O0" if value else "-nodebug -O2") |
---|
87 | |
---|
88 | class Install: |
---|
89 | def __init__(self, value): |
---|
90 | self.string = "installed" if value else "in-tree" |
---|
91 | self.flags = """INSTALL_FLAGS="%s" """ % ("" if value else "-in-tree") |
---|
92 | |
---|
93 | class Timeouts: |
---|
94 | def __init__(self, ts, tg): |
---|
95 | self.single = Timeouts.check(ts) |
---|
96 | self.total = Timeouts.check(tg) |
---|
97 | |
---|
98 | @classmethod |
---|
99 | def check(_, value): |
---|
100 | if value < 1: |
---|
101 | print("Timeouts must be at least 1 second", file=sys.stderr) |
---|
102 | sys.exit(1) |
---|
103 | |
---|
104 | return value |
---|
105 | |
---|
106 | def init( options ): |
---|
107 | global arch |
---|
108 | global dry_run |
---|
109 | global generating |
---|
110 | global make |
---|
111 | global debug |
---|
112 | global install |
---|
113 | global timeout |
---|
114 | |
---|
115 | dry_run = options.dry_run |
---|
116 | generating = options.regenerate_expected |
---|
117 | make = 'make' |
---|
118 | debug = Debug(options.debug) |
---|
119 | install = Install(options.install) |
---|
120 | arch = Architecture(options.arch) |
---|
121 | timeout = Timeouts(options.timeout, options.global_timeout) |
---|
122 | |
---|
123 | |
---|
124 | def updateMakeCmd(force, jobs): |
---|
125 | global make |
---|
126 | |
---|
127 | make = "make" if not force else ("make -j%i" % jobs) |
---|
128 | |
---|
129 | def validate(): |
---|
130 | errf = os.path.join(BUILDDIR, ".validate.err") |
---|
131 | make_ret, _ = tools.make( ".validate", error_file = errf, redirects = "2> /dev/null 1> /dev/null", ) |
---|
132 | if make_ret != 0: |
---|
133 | with open (errf, "r") as myfile: |
---|
134 | error=myfile.read() |
---|
135 | print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr) |
---|
136 | print(" verify returned : \n%s" % error, file=sys.stderr) |
---|
137 | tools.rm(errf) |
---|
138 | sys.exit(1) |
---|
139 | |
---|
140 | tools.rm(errf) |
---|