|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT |
| 4 | +# file at the top-level directory of this distribution and at |
| 5 | +# http://rust-lang.org/COPYRIGHT. |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 9 | +# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 10 | +# option. This file may not be copied, modified, or distributed |
| 11 | +# except according to those terms. |
| 12 | + |
| 13 | +import os |
| 14 | +import sys |
| 15 | +import functools |
| 16 | +import resource |
| 17 | + |
| 18 | +STATUS = 0 |
| 19 | + |
| 20 | + |
| 21 | +def error_unless_permitted(env_var, message): |
| 22 | + global STATUS |
| 23 | + if not os.getenv(env_var): |
| 24 | + sys.stderr.write(message) |
| 25 | + STATUS = 1 |
| 26 | + |
| 27 | + |
| 28 | +def only_on(platforms): |
| 29 | + def decorator(func): |
| 30 | + @functools.wraps(func) |
| 31 | + def inner(): |
| 32 | + if any(map(lambda x: sys.platform.startswith(x), platforms)): |
| 33 | + func() |
| 34 | + return inner |
| 35 | + return decorator |
| 36 | + |
| 37 | + |
| 38 | +@only_on(('linux', 'darwin', 'freebsd', 'openbsd')) |
| 39 | +def check_rlimit_core(): |
| 40 | + soft, hard = resource.getrlimit(resource.RLIMIT_CORE) |
| 41 | + if soft > 0: |
| 42 | + error_unless_permitted('ALLOW_NONZERO_RLIMIT_CORE', """\ |
| 43 | +RLIMIT_CORE is set to a nonzero value (%d). During debuginfo, the test suite |
| 44 | +will segfault many rustc's, creating many potentially large core files. |
| 45 | +set ALLOW_NONZERO_RLIMIT_CORE to ignore this warning |
| 46 | +""" % (soft)) |
| 47 | + |
| 48 | + |
| 49 | +def main(): |
| 50 | + check_rlimit_core() |
| 51 | + |
| 52 | +if __name__ == '__main__': |
| 53 | + main() |
| 54 | + sys.exit(STATUS) |
0 commit comments