source: mainline/tools/sanity.py@ 3ad309d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3ad309d was 3ad309d, checked in by Martin Decky <martin@…>, 15 years ago

add basic compilation sanity checks

  • Property mode set to 100755
File size: 5.5 KB
Line 
1#!/usr/bin/env python
2#
3# Copyright (c) 2010 Martin Decky
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# - Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# - Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15# - The name of the author may not be used to endorse or promote products
16# derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29"""
30Check whether several important prerequisites for building HelenOS
31are present in the system
32"""
33import sys
34import os
35import re
36import subprocess
37
38MAKEFILE = 'Makefile.config'
39
40def read_config(fname, config):
41 "Read HelenOS build configuration"
42
43 inf = file(fname, 'r')
44
45 for line in inf:
46 res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
47 if (res):
48 config[res.group(1)] = res.group(2)
49
50 inf.close()
51
52def print_error(msg):
53 "Print a bold error message"
54
55 sys.stderr.write("\n")
56 sys.stderr.write("######################################################################\n")
57 sys.stderr.write("HelenOS build sanity check error:\n")
58 sys.stderr.write("\n")
59 sys.stderr.write("%s\n" % "\n".join(msg))
60 sys.stderr.write("######################################################################\n")
61 sys.stderr.write("\n")
62
63 sys.exit(1)
64
65def check_app(args, name, details):
66 "Check whether an application can be executed"
67
68 try:
69 sys.stderr.write("Checking for %s ... " % args[0])
70 subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
71 except:
72 sys.stderr.write("failed\n")
73 print_error(["%s is missing." % name,
74 "",
75 "Execution of \"%s\" has failed. Please make sure that it" % " ".join(args),
76 "is installed in your system (%s)." % details])
77
78 sys.stderr.write("ok\n")
79
80def check_binutils():
81 "Check for binutils toolchain"
82
83 check_app(["as", "--version"], "GNU Assembler", "usually part of binutils")
84 check_app(["ld", "--version"], "GNU Linker", "usually part of binutils")
85 check_app(["ar", "--version"], "GNU Archiver", "usually part of binutils")
86 check_app(["objcopy", "--version"], "Objcopy utility", "usually part of binutils")
87 check_app(["objdump", "--version"], "Objdump utility", "usually part of binutils")
88
89def main():
90 config = {}
91
92 # Read configuration
93 if os.path.exists(MAKEFILE):
94 read_config(MAKEFILE, config)
95 else:
96 print_error(["Configuration file %s not found! Make sure that the" % MAKEFILE,
97 "configuration phase of HelenOS build went OK. Try running",
98 "\"make config\" again."])
99
100 if ('CROSS_PREFIX' in os.environ):
101 cross_prefix = os.environ['CROSS_PREFIX']
102 else:
103 cross_prefix = "/usr/local"
104
105 # Common utilities
106 check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
107 check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
108 check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
109 check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
110 check_app(["uname", "--version"], "System information utility", "usually part of coreutils")
111 check_app(["find", "--version"], "Find utility", "usually part of findutils")
112 check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
113 check_app(["make", "--version"], "Make utility", "preferably GNU Make")
114 check_app(["makedepend", "-f", "-"], "Makedepend utility", "usually part of imake or xutils")
115
116 try:
117 if (config['COMPILER'] == "gcc_native"):
118 check_app(["gcc", "--version"], "GNU GCC", "preferably version 4.4 or newer")
119 check_binutils()
120
121 if (config['COMPILER'] == "icc"):
122 check_app(["icc", "-V"], "Intel C++ Compiler", "support is experimental")
123 check_binutils()
124
125 if (config['COMPILER'] == "suncc"):
126 check_app(["suncc", "-V"], "Sun Studio Compiler", "support is experimental")
127 check_binutils()
128
129 if (config['COMPILER'] == "clang"):
130 check_app(["clang", "--version"], "Clang compiler", "preferably version 1.0 or newer")
131 check_binutils()
132
133 if ((config['UARCH'] == "amd64") or (config['UARCH'] == "ia32") or (config['UARCH'] == "ppc32") or (config['UARCH'] == "sparc64")):
134 check_app(["mkisofs", "--version"], "ISO 9660 creation utility", "usually part of genisoimage")
135
136 except KeyError:
137 print_error(["Build configuration of HelenOS is corrupted or the sanity checks",
138 "are out-of-sync. Try running \"make config\" again. ",
139 "If the problem persists, please contact the developers of HelenOS."])
140
141 return 0
142
143if __name__ == '__main__':
144 sys.exit(main())
Note: See TracBrowser for help on using the repository browser.