def do_on_fail_pass(start_message, cb): Print.status(start_message) try: cb() except Exception as e: pass Print.ok()
def setup(): global java_compilers global missing_compilers # Get the names and paths for know Java compilers names = ['javac'] for name in names: paths = Find.program_paths(name) if len(paths) == 0: missing_compilers.append(name) continue if name in ['javac']: comp = JavaCompiler(name=name, path=paths[0], debug='-g', no_warnings='-nowarn', verbose='-verbose', deprecation='-deprecation', runtime='java', jar='jar') java_compilers[comp._name] = comp # Make sure there is at least one Java compiler installed if len(java_compilers) == 0: Print.status("Setting up Java module") Print.fail() Print.exit("No Java compiler found. Install one and try again.")
def remove_dir(name, and_children = False): Print.status("Removing the dir '{0}'".format(name)) success = False # Make sure we are not removing the current directory if name == os.getcwd(): Print.fail() Print.exit("Can't remove the current directory '{0}'.".format(name)) try: for entry in glob_names(name): if os.path.islink(entry): os.unlink(entry) elif os.path.isdir(entry): if and_children: shutil.rmtree(entry) else: os.rmdir(entry) success = True except OSError as e: if 'No such file or directory' in e: success = True if success: Print.ok() else: Print.fail() Print.exit("Failed to remove the dir '{0}'.".format(name))
def setup(): global linkers # Get the names and paths for know linkers names = ['ld', 'link.exe'] for name in names: paths = Find.program_paths(name) if len(paths) == 0: continue if name == 'link.exe': link = Linker( name = 'link.exe', setup = '/nologo', out_file = '/out:', shared = '/dll ' ) linkers[link._name] = link elif name == 'ld': link = Linker( name = 'ld', setup = '', out_file = '-o ', shared = '-G' ) linkers[link._name] = link # Make sure there is at least one linker installed if len(linkers) == 0: Print.status("Setting up Linker module") Print.fail() Print.exit("No Linker found. Install one and try again.")
def ldconfig(): # Setup the message Print.status("Running 'ldconfig'") # Skip ldconfig on Cygwin if Config.os_type in OSType.Cygwin: Print.ok() return # Find ldconfig prog = Find.program_paths('ldconfig') if not prog: Print.fail() Print.exit("Could not find 'ldconfig'.") # Run the process runner = findlib.ProcessRunner(prog[0]) runner.run() runner.is_done runner.wait() # Success or failure if runner.is_failure: Print.fail(runner.stdall) Print.exit("Failed run 'ldconfig'.") elif runner.is_success or runner.is_warning: Print.ok()
def require_programs(prog_names): for prog_name in prog_names: Print.status("Checking for program '{0}'".format(prog_name)) if len(findlib.program_paths(prog_name)): Print.ok() else: Print.fail() Print.exit("Install the program '{0}' and try again.".format(prog_name))
def require_environmental_variable(env_name, version_cb = None): Print.status("Checking for environmental variable '{0}'".format(env_name)) if not os.environ.get(env_name): message = "The environmental variable '{0}' was not found. Set it and try again." Print.fail() Print.exit(message.format(env_name)) else: Print.ok()
def remove_binaries(name): Print.status("Removing binaries '{0}'".format(name)) extensions = ['.exe', '.o', '.obj', '.so', '.a', '.dll', '.lib', '.pyc', '.exe.mdb', '.dll.mdb', '.jar', '.class'] for entry in os.listdir(os.getcwd()): if entry.startswith(name) and os.path.isfile(entry): extension = '.' + str.join('.', entry.lower().split('.')[1:]) if extension in extensions or entry == name: os.remove(entry) Print.ok()
def require_header_file(header_name, version_str = None): Print.status("Checking for header file '{0}'".format(header_name)) # If the header is not installed, make them install it to continue if not findlib.get_header_file(header_name, version_str): ver = "(Any version)" if version_str: ver = version_str message = "Header file '{0} {1}' not installed. Install and try again." Print.fail() Print.exit(message.format(header_name, ver)) else: Print.ok()
def require_shared_library(lib_name, version_str = None): Print.status("Checking for shared library '{0}'".format(lib_name)) # If the shared library is not installed, make them install it to continue if not findlib.get_shared_library(lib_name, version_str): # Get the version requirement lambda as a printable string ver = "(Any version)" if version_str: ver = version_str message = "Shared library '{0} {1}' not installed. Install and try again." Print.fail() Print.exit(message.format(lib_name, ver)) else: Print.ok()
def get_default_compiler(): global c_compilers if Config.os_type in OSType.Windows: # Make sure Windows SDK tools are found if not 'WINDOWSSDKDIR' in os.environ and not 'WINDOWSSDKVERSIONOVERRIDE' in os.environ: Print.status("Setting up cl.exe") Print.fail() Print.exit('Windows SDK not found. Must be run from Windows SDK Command Prompt.') return c_compilers.get('cl.exe') elif Config.os_type in OSType.Unix: return c_compilers.get('clang') or c_compilers.get('gcc') else: return c_compilers.get('gcc') or c_compilers.get('clang') return None
def require_static_or_shared_library(lib_name, version_str = None): Print.status("Checking for static/shared library '{0}'".format(lib_name)) shared_file = get_shared_library(lib_name, version_str) static_file = get_shared_library(lib_name, version_str) # Make them install the lib if neither was found if not shared_file and not static_file: # Get the version requirement lambda as a printable string ver = "(Any version)" if version_str: ver = version_str message = "Shared/Static library '{0} {1}' not installed. Install and try again." Print.fail() Print.exit(message.format(lib_name, ver)) else: Print.ok()
def run_print(command): Print.status("Running C++ program") native_command = to_native(command) runner = findlib.ProcessRunner(native_command) runner.run() runner.is_done runner.wait() if runner.is_success or runner.is_warning: Print.ok() sys.stdout.write(command + '\n') sys.stdout.write(runner.stdall) elif runner.is_failure: Print.fail() sys.stdout.write(command + '\n') sys.stdout.write(runner.stdall) Print.exit('Failed to run command.')
def wait(self): # Wait for the process to complete self._runner.wait() # Display the message if Event.is_concurrent: Print.status(" '{0}'".format(self._result)) # Success or failure if self._runner.is_success: Print.ok() self._status = 'success' elif self._runner.is_warning: Print.warning(self._runner.stderr) self._status = 'success' else: Print.fail(self._runner.stdall) Print.exit("{0} failed. Try again.".format(self._task)) self._status = 'failure'
def remove_file(name, ignore_failure = False): Print.status("Removing the file '{0}'".format(name)) success = False try: for entry in glob_names(name): if os.path.islink(entry): os.unlink(entry) elif os.path.isfile(entry): os.remove(entry) success = True except Exception as e: if ignore_failure: success = True if success: Print.ok() else: Print.fail() Print.exit("Failed to remove the file '{0}'.".format(name))
def do_on_fail_exit(start_message, fail_message, cb): Print.status(start_message) # Run it if it is a function if hasattr(cb, '__call__'): try: cb() Print.ok() except Exception as e: Print.fail() Print.exit(fail_message) # Or run it as a process if a string elif type(cb) == str: runner = findlib.ProcessRunner(cb) runner.run() runner.is_done runner.wait() if runner.is_success or runner.is_warning: Print.ok() elif runner.is_failure: Print.fail() Print.exit(fail_message)
def setup(): global cs_compilers global missing_compilers # Get the names and paths for know C# compilers names = ['dmcs', 'csc'] for name in names: paths = Find.program_paths(name) if len(paths) == 0: missing_compilers.append(name) continue if name in ['dmcs']: comp = CSCompiler(name=name, path=paths[0], out_file='-out:', debug='-debug', warnings_all='-warn:4', warnings_as_errors='-warnaserror', optimize='-optimize', runtime='mono') cs_compilers[comp._name] = comp elif name in ['csc']: comp = CSCompiler(name=name, path=paths[0], out_file='-out:', debug='-debug', warnings_all='-warn:4', warnings_as_errors='-warnaserror', optimize='-optimize', runtime='') cs_compilers[comp._name] = comp # Make sure there is at least one C# compiler installed if len(cs_compilers) == 0: Print.status("Setting up C# module") Print.fail() Print.exit("No C# compiler found. Install one and try again.")
def run(self): # Show the concurrent header if Event.is_concurrent: if Event.is_first_concurrent: Event.is_first_concurrent = False sys.stdout.write("{0} {1} concurrently ...\n".format( self._task, self._plural)) sys.stdout.flush() Print.message_length = 0 # Run the setup function if not self._setup_cb(): return False # Show the serial message if not Event.is_concurrent: Print.status("{0} {1} '{2}'".format(self._task, self._singular, self._result)) # Start the process self._runner = findlib.ProcessRunner(self._command) self._status = 'running' self._runner.run() return True
def _on_status(message): Terminal.status(message)
def setup(): global d_compilers global missing_compilers # Get the names and paths for know D compilers compilers = { 'dmd': ['dmd', r'dmd[0-9]*'], 'ldc': ['ldc', r'ldc[0-9]*'], #gdc } for name, alt_names in compilers.items(): paths = Find.program_paths(*alt_names) if len(paths) == 0: missing_compilers.append(name) continue if name in ['dmd2', 'dmd']: comp = DCompiler(name=name, path=paths[0], setup='', out_file='-of', no_link='-c', lib='-lib', debug='-g', warnings_all='-w', optimize='-O', compile_time_flags='-version=', link='-Wl,-as-needed', interface='-H', interface_file='-Hf', interface_dir='-Hd', unittest='-unittest') d_compilers[comp._name] = comp elif name in ['ldc2', 'ldc']: comp = DCompiler(name=name, path=paths[0], setup='', out_file='-of', no_link='-c', lib='-lib', debug='-g', warnings_all='-w', optimize='-O2', compile_time_flags='-d-version=', link='-Wl,-as-needed', interface='-H', interface_file='-Hf=', interface_dir='-Hd=', unittest='-unittest') d_compilers[comp._name] = comp elif name in ['gdc']: # http://wiki.dlang.org/GDC/Using_GDC comp = DCompiler(name=name, path=paths[0], setup='', out_file='-o ', no_link='-c', lib='-lib', debug='-g', warnings_all='-Werror', optimize='-O2', compile_time_flags='-f-version=', link='-Wl,-as-needed', interface='-fintfc=', interface_file='-fintfc-file=', interface_dir='-fintfc-dir=', unittest='-unittest') d_compilers[comp._name] = comp # Make sure there is at least one D compiler installed if len(d_compilers) == 0: Print.status("Setting up D module") Print.fail() Print.exit("No D compiler found. Install one and try again.")
def setup(): global cxx_compilers global missing_compilers # Figure out if OS X has the dev tools installed OSX_HAS_TOOLS = False if Config.os_type in OSType.MacOS: result = findlib.run_and_get_stdout( 'pkgutil --pkg-info=com.apple.pkg.CLTools_Executables') if result: OSX_HAS_TOOLS = True # Get the names and paths for known C++ compilers compilers = { 'g++': ['g++', r'g++[0-9]*', r'g++-[0-9|\.]*'], 'clang++': ['clang++'], 'cl.exe': ['cl.exe'] } for name, alt_names in compilers.items(): paths = Find.program_paths(*alt_names) if len(paths) == 0: missing_compilers.append(name) continue standards = { Standard.std1998: '-std=c++98', Standard.std2003: '-std=c++03', Standard.std2011: '-std=c++11', Standard.std201x: '-std=c++1x', Standard.gnu1998: '-std=gnu++98', Standard.gnu2003: '-std=gnu++03', Standard.gnu2011: '-std=gnu++11', Standard.gnu201x: '-std=gnu++1x' } if name == 'g++': # On Mac OS X skip this compiler if it is clang pretending to be g++ if Config.os_type in OSType.MacOS and OSX_HAS_TOOLS: version = findlib.run_and_get_stdout('g++ --version') if version and 'clang' in version.lower(): missing_compilers.append(name) continue comp = CXXCompiler(name='g++', path=paths[0], standards=standards, setup='', out_file='-o ', no_link='-c', debug='-g', position_independent_code='-fPIC', warnings_all='-Wall', warnings_extra='-Wextra', warnings_as_errors='-Werror', optimize_zero='-O0', optimize_one='-O1', optimize_two='-O2', optimize_three='-O3', optimize_size='-Os', compile_time_flags='-D', link='-shared -Wl,-as-needed') cxx_compilers[comp._name] = comp elif name == 'clang++': comp = CXXCompiler(name='clang++', path=paths[0], standards=standards, setup='', out_file='-o ', no_link='-c', debug='-g', position_independent_code='-fPIC', warnings_all='-Wall', warnings_extra='-Wextra', warnings_as_errors='-Werror', optimize_zero='-O0', optimize_one='-O1', optimize_two='-O2', optimize_three='-O3', optimize_size='-Os', compile_time_flags='-D', link='-shared') cxx_compilers[comp._name] = comp elif name == 'cl.exe': # http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx comp = CXXCompiler(name='cl.exe', path=paths[0], standards=None, setup='/nologo /EHsc', out_file='/Fe', no_link='/c', debug='/Zi', position_independent_code='', warnings_all='/Wall', warnings_extra=None, warnings_as_errors='/WX', optimize_zero='/Od', optimize_one='/O1', optimize_two='/O2', optimize_three='/Ox', optimize_size='/Os', compile_time_flags='/D', link='/LDd') cxx_compilers[comp._name] = comp # Make sure there is at least one C++ compiler installed if len(cxx_compilers) == 0: Print.status("Setting up C++ module") Print.fail() Print.exit("No C++ compiler found. Install one and try again.")