def get_ethtool_macro(): # see: https://github.com/giampaolo/psutil/issues/659 from distutils.unixccompiler import UnixCCompiler from distutils.errors import CompileError with tempfile.NamedTemporaryFile( suffix='.c', delete=False, mode="wt") as f: f.write("#include <linux/ethtool.h>") @atexit.register def on_exit(): try: os.remove(f.name) except OSError: pass compiler = UnixCCompiler() try: with silenced_output('stderr'): with silenced_output('stdout'): compiler.compile([f.name]) except CompileError: return ("PSUTIL_ETHTOOL_MISSING_TYPES", 1) else: return None
def get_ethtool_macro(): # see: https://github.com/giampaolo/psutil/issues/659 from distutils.unixccompiler import UnixCCompiler from distutils.errors import CompileError with tempfile.NamedTemporaryFile(suffix='.c', delete=False, mode="wt") as f: f.write("#include <linux/ethtool.h>") output_dir = tempfile.mkdtemp() try: compiler = UnixCCompiler() # https://github.com/giampaolo/psutil/pull/1568 if os.getenv('CC'): compiler.set_executable('compiler_so', os.getenv('CC')) with silenced_output('stderr'): with silenced_output('stdout'): compiler.compile([f.name], output_dir=output_dir) except CompileError: return ("PSUTIL_ETHTOOL_MISSING_TYPES", 1) else: return None finally: os.remove(f.name) shutil.rmtree(output_dir)
def build_apron_util(): apron_util_src = os.path.join("pyapron", "apron_util.c") apron_util_obj = os.path.join(ROOT_DIR, os.path.join("pyapron", "apron_util.o")) cc = UnixCCompiler() cc.add_include_dir(APRON_DIR) cc.add_include_dir(os.path.join(ROOT_DIR, "include")) cc.add_library_dir(APRON_LIB_DIR) cc.set_libraries(["apron_debug"]) cc.compile([apron_util_src], extra_preargs=["-fPIC"]) cc.link_shared_lib([apron_util_obj], "apronutil", output_dir=APRON_LIB_DIR)
def compile_exe(): user = os.path.expanduser("~/.pyinitrd") if not os.path.exists(user): os.mkdir(user) src = os.path.join(user, "gen_init_cpio.c") if not os.path.exists(src): orig = "/usr/src/linux/usr/gen_init_cpio.c" if not os.path.exists(orig): Exception("Requires Linux kernel sources in %r" % orig) shutil.copyfile(orig, src) compiler = UnixCCompiler() obj = os.path.join(user, "gen_init_cpio.o") if not os.path.exists(obj): compiler.compile(["gen_init_cpio.c"], user) exe = os.path.join(user, "gen_init_cpio") if not os.path.exists(exe): print("compiling") compiler.link_executable([obj], exe, user) return exe