def build_regex_win32(using_cmake=False): # pragma: windows r"""Build the regex_win32 library.""" _regex_win32_dir = os.path.dirname(_regex_win32_lib) _regex_win32_cpp = os.path.join(_regex_win32_dir, 'regex_win32.cpp') _regex_win32_obj = os.path.join(_regex_win32_dir, 'regex_win32.obj') # Compile object cmd = [ 'cl', '/c', '/Zi', '/EHsc', '/I', '%s' % _regex_win32_dir, _regex_win32_cpp ] # '/out:%s' % _regex_win32_obj, comp_process = tools.popen_nobuffer(cmd, cwd=_regex_win32_dir) output, err = comp_process.communicate() exit_code = comp_process.returncode if exit_code != 0: # pragma: debug print(' '.join(cmd)) tools.print_encoded(output, end="") raise RuntimeError("Could not create regex_win32.obj") assert (os.path.isfile(_regex_win32_obj)) # Create library cmd = ['lib', '/out:%s' % _regex_win32_lib, _regex_win32_obj] comp_process = tools.popen_nobuffer(cmd, cwd=_regex_win32_dir) output, err = comp_process.communicate() exit_code = comp_process.returncode if exit_code != 0: # pragma: debug print(' '.join(cmd)) tools.print_encoded(output, end="") raise RuntimeError("Could not build regex_win32.lib") assert (os.path.isfile(_regex_win32_lib))
def build_regex_win32(): # pragma: windows r"""Build the regex_win32 library using cmake.""" # Configure project cmd = ['cmake', '-H.', '-Bbuild'] comp_process = tools.popen_nobuffer(cmd, cwd=_regex_win32_dir) output, err = comp_process.communicate() exit_code = comp_process.returncode if exit_code != 0: # pragma: debug print(' '.join(cmd)) tools.print_encoded(output, end="") raise RuntimeError("Could not config regex_win32") # Build project cmd = ['cmake', '--build', 'build', '--clean-first'] comp_process = tools.popen_nobuffer(cmd, cwd=_regex_win32_dir) output, err = comp_process.communicate() exit_code = comp_process.returncode if exit_code != 0: # pragma: debug print(' '.join(cmd)) tools.print_encoded(output, end="") raise RuntimeError("Could not build regex_win32") assert(os.path.isfile(_regex_win32_lib))
# If the receive was not succesful, send the end-of-file message to # close the output file. print("End of file input (Python)") out_file.send_eof() # Read rows from ASCII table until end of file is reached. # As each row is received, it is then sent to the output ASCII table print('ascii_io(P): Receiving/sending ASCII table.') ret = True while ret: # Receive a single row (ret, line) = in_table.recv_row() if ret: # If the receive was succesful, send the values to output. # Formatting is taken care of on the output driver side. print_encoded("Table: %s, %d, %3.1f, %s" % line) # print("Table: %s, %d, %3.1f, %s" % line) ret = out_table.send_row(*line) if not ret: print("ascii_io(P): ERROR SENDING ROW") error_code = -1 break else: # If the receive was not succesful, send the end-of-file message to # close the output file. print("End of table input (Python)") out_table.send_eof() # Read entire array from ASCII table into numpy array ret = True while ret:
def do_compile(src, out=None, cc=None, ccflags=None, ldflags=None, working_dir=None): r"""Compile a C/C++ program with necessary interface libraries. Args: src (list): List of source files. out (str, optional): Path where compile executable should be saved. Defaults to name of source file without extension on linux/osx and with .exe extension on windows. cc (str, optional): Compiler command. Defaults to gcc/g++ on linux/osx and cl on windows. ccflags (list, optional): Compiler flags. Defaults to []. ldflags (list, optional): Linker flags. Defaults to []. working_dir (str, optional): Working directory that input file paths are relative to. Defaults to current working directory. Returns: str: Full path to the compiled executable. """ if working_dir is None: # pragma: no cover working_dir = os.getcwd() if ccflags is None: # pragma: no cover ccflags = [] if ldflags is None: # pragma: no cover ldflags = [] _compile_flags, _linker_flags = get_flags() ldflags0 = _linker_flags if platform._is_win: # pragma: windows ccflags0 = ['/W4', '/Zi', "/EHsc"] else: ccflags0 = ['-g', '-Wall'] ccflags0 += _compile_flags # Change format for path (windows compat of examples) if platform._is_win: # pragma: windows for i in range(len(src)): src[i] = os.path.join(*(src[i].split('/'))) # Get primary file cfile = src[0] src_base, src_ext = os.path.splitext(cfile) # Select compiler if cc is None: if platform._is_win: # pragma: windows cc = 'cl' else: if src_ext in ['.c']: cc = 'gcc' else: cc = 'g++' # Create/fix executable if out is None: if platform._is_win: # pragma: windows osuffix = '_%s.exe' % src_ext[1:] else: osuffix = '_%s.out' % src_ext[1:] out = src_base + osuffix if not os.path.isabs(out): out = os.path.normpath(os.path.join(working_dir, out)) # Get flag specifying standard library if '++' in cc and (not platform._is_win): std_flag = None for a in ccflags: if a.startswith('-std='): std_flag = a break if std_flag is None: ccflags.append('-std=c++11') # Construct compile arguments compile_args = [cc] if not platform._is_win: compile_args += ["-o", out] compile_args += src + ccflags0 + ccflags if platform._is_win: # pragma: windows compile_args += ['/link', '/out:%s' % out] compile_args += ldflags0 + ldflags if os.path.isfile(out): os.remove(out) # Compile comp_process = tools.popen_nobuffer(compile_args) output, err = comp_process.communicate() exit_code = comp_process.returncode if exit_code != 0: # pragma: debug print(' '.join(compile_args)) tools.print_encoded(output, end="") raise RuntimeError("Compilation failed with code %d." % exit_code) assert (os.path.isfile(out)) return out