def so_dirs_path(flags, pkg): """ Assemble path for shared libraries in nonstandard directories. """ retval = separate_args(pkg.config.rpath) i = len(retval) - 1 if i < 0: return count = 0 pkg_lib = os.path.join(pkg.get_dir('libdir'), pkg.name) if os.path.isdir(pkg_lib): retval[i] += ":" + pkg_lib count += 1 if type(flags) == str: args = separate_args(flags) else: args = flags for arg in args: if arg[0:2] == '-L' and arg[0:10] != '-L/usr/lib' and arg[0:6] != '-L/lib': retval[i] += ":" + arg[2:] count += 1 if count == 0: retval = "" return retval
def so_dirs_path(flags, pkg): """ Assemble path for shared libraries in nonstandard directories. """ retval = separate_args(pkg.config.rpath) i = len(retval) - 1 if i < 0: return count = 0 pkg_lib = os.path.join(pkg.get_dir('libdir'), pkg.name) if os.path.isdir(pkg_lib): retval[i] += ":" + pkg_lib count += 1 if type(flags) == str: args = separate_args(flags) else: args = flags for arg in args: if arg[0:2] == '-L' and arg[0:10] != '-L/usr/lib' and arg[ 0:6] != '-L/lib': retval[i] += ":" + arg[2:] count += 1 if count == 0: retval = "" return retval
def get_build_flags(pkg, flag, install=False, destdir=None): cmd_line = [] # Build the command line, and split possible multiple arguments in lists. for lib in pkg.config.deplibs: if (pkg.config.libs[lib].have == "yes" and (not pkg.config.libs[lib].dynamic_load)): cmd_line += separate_args(pkg.config.libs[lib].flags[flag]) if flag == 'ldflags': if not install: if pkg.config.libs['ple'].variant == "internal": top_builddir = os.path.split(os.path.split(os.getcwd())[0])[0] ple_lib_path = os.path.join(top_builddir, "libple", "src", ".libs") cmd_line.insert(0, "-L" + ple_lib_path) cmd_line.insert(0, "-L" + os.path.join(os.getcwd(), ".libs")) else: # Do not use pkg.get_dir here as possible relocation paths must be # used after installation, not before. libdir = pkg.dirs['libdir'][1] # Strangely, on MinGW, Windows paths are not correctly handled here # So, assuming we always build on MinGW, here is a little trick! if sys.platform.startswith("win"): if pkg.get_cross_compil() != 'cygwin': #mingw32 or mingw64 libdir = os.path.normpath('C:\\MinGW\\msys\\1.0' + libdir) if destdir: libdir = dest_subdir(destdir, libdir) cmd_line.insert(0, "-L" + libdir) return cmd_line
def get_flags(self, flag): """ Determine compilation flags for a given flag type. """ if flag == 'libs': return cs_compile.get_flags(self, flag) cmd_line = self.get_pkg_path_flags(flag) # Build the command line, and split possible multiple arguments in lists. for lib in pkg.config.deplibs: if (pkg.config.libs[lib].have == "yes" \ and (not pkg.config.libs[lib].dynamic_load)): cmd_line += separate_args(pkg.config.libs[lib].flags[flag]) if flag == 'ldflags': # Do not use pkg.get_dir here as possible relocation paths # must be used after installation, not before. libdir = pkg.dirs['libdir'][1] # Strangely, on MinGW, Windows paths are not correctly # handled here. So, assuming we always build on MinGW, # here is a little trick! if sys.platform.startswith("win"): if pkg.get_cross_compile() != 'cygwin': # mingw64 libdir = os.path.normpath('C:\\MinGW\\msys\\1.0' + libdir) if self.destdir: libdir = dest_subdir(self.destdir, libdir) cmd_line.insert(0, "-L" + libdir) return cmd_line
def solver_command(self, **kw): """ Returns a tuple indicating SYRTHES's working directory, executable path, and associated command-line arguments. """ wd = enquote_arg(self.exec_dir) # Working directory exec_path = enquote_arg(self.solver_path) # Executable # Build kernel command-line arguments args = '' args += ' -d ' + enquote_arg(self.syrthes_case.data_file) args += ' -n ' + str(self.syrthes_case.n_procs) if self.syrthes_case.n_procs_ray > 0: args += ' -r ' + str(self.n_procs_ray) args += ' --name ' + enquote_arg(self.name) # Output to a logfile args += ' --log ' + enquote_arg(self.logfile) # Adjust for Valgrind if used if self.valgrind != None: args = enquote_arg(self.solver_path) + ' ' + args exec_path = '' for a in separate_args(self.valgrind): exec_path += enquote_arg(a) + ' ' return wd, exec_path, args
def get_build_flags(pkg, flag, install=False, destdir=None): cmd_line = [] # Build the command line, and split possible multiple arguments in lists. for lib in pkg.config.deplibs: if (pkg.config.libs[lib].have == "yes" and (not pkg.config.libs[lib].dynamic_load)): cmd_line += separate_args(pkg.config.libs[lib].flags[flag]) if flag == 'ldflags': if not install: if pkg.config.libs['ple'].variant == "internal": top_builddir = os.path.split(os.path.split(os.getcwd())[0])[0] ple_lib_path = os.path.join(top_builddir, "libple", "src", ".libs") cmd_line.insert(0, "-L" + ple_lib_path) cmd_line.insert(0, "-L" + os.path.join(os.getcwd(), ".libs")) else: # Do not use pkg.get_dir here as possible relocation paths must be # used after installation, not before. libdir = pkg.dirs['libdir'][1] # Strangely, on MinGW, Windows paths are not correctly handled here # So, assuming we always build on MinGW, here is a little trick! if sys.platform.startswith("win"): if pkg.get_cross_compil() != 'cygwin': #mingw32 or mingw64 libdir = os.path.normpath('C:\\MinGW\\msys\\1.0' + libdir) if destdir: libdir = dest_subdir(destdir, libdir) cmd_line.insert(0, "-L" + libdir) return cmd_line
def run_autovnv_command(_c, _log, pythondir=None): """ Run command with arguments. Redirection of the stdout or stderr of the command. """ assert type(_c) == str or type(_c) == unicode log.debug("run_autovnv_command: %s" % _c) try: _log.seek(0, os.SEEK_END) except: _log.seek(0, 2) def __text(_t): return "\n\nExecution failed --> %s: %s" \ "\n - command: %s" \ "\n - directory: %s\n\n" % \ (_t, str(retcode), _c, os.getcwd()) _l = "" cmd = separate_args(_c) env = os.environ.copy() if pythondir: pythondir = enquote_arg(pythondir) pythonpath = pythondir + ':' + env.get("PYTHONPATH", '') env.update([("PYTHONPATH", pythonpath)]) try: t1 = time.time() retcode = run_command(cmd, stdout=_log, stderr=_log, env=env) t2 = time.time() if retcode < 0: _l = __text("command was terminated by signal") elif retcode > 0: _l = __text("command return") except OSError: import traceback import sys exc_info = sys.exc_info() bt = traceback.format_exception(*exc_info) for l in bt: _log.write(l) retcode = 0 del exc_info _l = __text("unknown command") t1 = 0. t2 = 0. _log.flush() if _l: _log.write(_l) return retcode, "%.2f" % (t2 - t1)
def get_nprocs(self): """ Get the nprocs option in the run command """ args = separate_args(self.lines[self.run_cmd_line_id]) return get_command_single_value(args, ('--nprocs', '--nprocs=', '-n'))
def get_coupling(self): """ Get the coupling option in the run command """ args = separate_args(self.lines[self.run_cmd_line_id]) return get_command_single_value(args, ('--coupling', ))
def get_parameters(self): """ Get the parameters option in the run command """ args = separate_args(self.lines[self.run_cmd_line_id]) return get_command_single_value(args, ('--param', '--param=', '-p'))
def get_parameters(self): """ Get the parameters option in the run command """ args = separate_args(self.lines[self.run_cmd_line_id]) return get_command_single_value(args, ('--param', '--param=', '-p'))
def get_compute_build(self): """ Get the compute-build option in the run command """ args = separate_args(self.lines[self.run_cmd_line_id]) return get_command_single_value( args, ('--compute-build', '--compute-build='))
def get_nprocs(self): """ Get the nprocs option in the run command """ args = separate_args(self.lines[self.run_cmd_line_id]) return get_command_single_value(args, ('--nprocs', '--nprocs=', '-n'))
def get_coupling(self): """ Get the coupling option in the run command """ args = separate_args(self.lines[self.run_cmd_line_id]) return get_command_single_value(args, ('--coupling',))
def get_nthreads(self): """ Get the nthreads option in the run command """ args = separate_args(self.lines[self.run_cmd_line_id]) return get_command_single_value( args, ('--threads-per-task', '--threads-per-task=', '-nt'))
def get_nthreads(self): """ Get the nthreads option in the run command """ args = separate_args(self.lines[self.run_cmd_line_id]) return get_command_single_value(args, ('--threads-per-task', '--threads-per-task=', '-nt'))
def set_nprocs(self, parameters): """ Set the nprocs option in the run command """ line = self.lines[self.run_cmd_line_id] args = update_command_single_value(separate_args(line), ('--nprocs', '--nprocs=', '-n'), enquote_arg(parameters)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def set_coupling(self, coupling): """ Set the coupling option in the run command """ line = self.lines[self.run_cmd_line_id] args = update_command_single_value(separate_args(line), ('--coupling',), enquote_arg(coupling)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def set_nprocs(self, parameters): """ Set the nprocs option in the run command """ line = self.lines[self.run_cmd_line_id] args = update_command_single_value(separate_args(line), ('--nprocs', '--nprocs=', '-n'), enquote_arg(parameters)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def get_lib_dir(self): """ Determine directory containing library. """ cmd_line = self.get_pkg_path_flags(flag) # Build the command line, and split possible multiple arguments in lists. for lib in pkg.config.deplibs: if (pkg.config.libs[lib].have == "yes" \ and (not pkg.config.libs[lib].dynamic_load)): cmd_line += separate_args(pkg.config.libs[lib].flags[flag])
def set_coupling(self, coupling): """ Set the coupling option in the run command """ line = self.lines[self.run_cmd_line_id] args = update_command_single_value(separate_args(line), ('--coupling', ), enquote_arg(coupling)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def set_compute_build(self, parameters): """ Set the compute-build option in the run command """ line = self.lines[self.run_cmd_line_id] args = update_command_single_value( separate_args(line), ('--compute-build', '--compute-build='), enquote_arg(parameters)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def set_nthreads(self, parameters): """ Set the nthreads option in the run command """ line = self.lines[self.run_cmd_line_id] args = update_command_single_value( separate_args(line), ('--threads-per-task', '--threads-per-task=', '-nt'), enquote_arg(parameters)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def get_run_id(self): """ Get the run id, id_prefix, and id_suffix options in the run command """ args = separate_args(self.lines[self.run_cmd_line_id]) run_id = get_command_single_value(args, ('--id', '--id=')) run_id_prefix = get_command_single_value(args, ('--id-prefix', '--id-prefix=')) run_id_suffix = get_command_single_value(args, ('--id-suffix', '--id-suffix=')) return run_id, run_id_prefix, run_id_suffix
def get_run_id(self): """ Get the run id, id_prefix, and id_suffix options in the run command """ args = separate_args(self.lines[self.run_cmd_line_id]) run_id = get_command_single_value(args, ('--id', '--id=')) run_id_prefix = get_command_single_value( args, ('--id-prefix', '--id-prefix=')) run_id_suffix = get_command_single_value( args, ('--id-suffix', '--id-suffix=')) return run_id, run_id_prefix, run_id_suffix
def set_nthreads(self, parameters): """ Set the nthreads option in the run command """ line = self.lines[self.run_cmd_line_id] args = update_command_single_value(separate_args(line), ('--threads-per-task', '--threads-per-task=', '-nt'), enquote_arg(parameters)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def solver_command(self, **kw): """ Returns a tuple indicating the solver's working directory, executable path, and associated command-line arguments. """ wd = enquote_arg(self.exec_dir) # Working directory exec_path = enquote_arg(self.solver_path) # Executable # Build kernel command-line arguments args = '' if self.param != None: args += ' --param ' + enquote_arg(self.param) if self.logging_args != None: args += ' ' + self.logging_args if self.solver_args != None: args += ' ' + self.solver_args if self.package_compute.config.features['mpi'] == 'yes': if self.name != None: args += ' --mpi --app-name ' + enquote_arg(self.name) elif self.n_procs > 1: args += ' --mpi' # Add FSI coupling (using SALOME YACS) if required if hasattr(self, 'fsi_aster'): if not sys.platform.startswith('linux'): raise RunCaseError(' Coupling with Code_Aster only avalaible on Linux.') salome_module = os.path.join(self.package_compute.get_dir('libdir'), 'salome', 'libFSI_SATURNEExelib.so') if os.path.isfile(salome_module): args += ' --yacs-module=' + enquote_arg(salome_module) # Adjust for Valgrind if used if self.valgrind != None: args = enquote_arg(self.solver_path) + ' ' + args exec_path = '' for a in separate_args(self.valgrind): exec_path += enquote_arg(a) + ' ' return wd, exec_path, args
def get_flags(pkg, flag, link_build = False): cmd_line = [] # Build the command line, and split possible multiple arguments in lists. for lib in pkg.config.deplibs: if (pkg.config.libs[lib].have == "yes" and (not pkg.config.libs[lib].dynamic_load)): cmd_line += separate_args(pkg.config.libs[lib].flags[flag]) # Add CPPFLAGS and LDFLAGS information for the current package if flag == 'cppflags': cmd_line.insert(0, "-I" + pkg.get_dir("pkgincludedir")) elif flag == 'ldflags': cmd_line.insert(0, "-L" + pkg.get_dir("libdir")) # Add CPPFLAGS information when PLE is "internal" if pkg.config.libs['ple'].variant == "internal" and flag == 'cppflags': cmd_line.insert(0, "-I" + pkg.get_dir("includedir")) # Specific handling of low-level libraries, which should come last, # such as -lm and -lpthread: # If -lm appears multiple times, only add it at the end of the # libraries, so that fast versions of the library may appear first if flag == 'libs': for lib in ['-lpthread', '-lm']: n = cmd_line.count(lib) if n > 0: for i in range(n): cmd_line.remove(lib) cmd_line.append(lib) # On MinGW hosts, flags must be adapted so as to handle the relocation # of system headers (together with the compiler) # ...unless the compilation is done during the build stage if sys.platform.startswith("win") and not link_build: for i in range(len(cmd_line)): s = cmd_line[i] for p in ["-I/mingw", "-Ic:/mingw"]: s_tmp = s.replace(p, "-I" + pkg.get_dir("prefix")) for p in ["-L/mingw", "-Lc:/mingw"]: s_tmp = s.replace(p, "-L" + pkg.get_dir("prefix")) cmd_line[i] = s_tmp return cmd_line
def get_run_command(self): """ Determine the name of the main command of the runcase, and the associated line in the file; this allows mixing Code_Saturne and NEPTUNE_CFD cases in the same study. """ # Read the runcase script from the Repository. self.cmd_name = None self.run_cmd_line_id = -1 for i in range(len(self.lines) - 1, -1, -1): line = self.lines[i] # Skip comment and empty lines if len(line) == 0: continue if line[0] == '#' or line[0:4] == 'rem ': continue j = line.find('#') if j > -1: line = line[0:j] args = separate_args(line.rstrip()) if args.count('run') == 1: if args.index('run') == 1: # "<package_name> run" for name in ('code_saturne', 'neptune_cfd'): if sys.platform.startswith('win'): test_name = name if args[0].find(test_name) == 0: self.cmd_name = name self.run_cmd_line_id = i return test_name = '\\' + name if args[0].find(test_name) == 0: self.cmd_name = name self.run_cmd_line_id = i return # We should have exited before reaching this. err_str = "Error: unable to determine the name of the script for " + self.path raise ValueError(err_str)
def get_flags(pkg, flag, link_build=False): cmd_line = [] # Build the command line, and split possible multiple arguments in lists. for lib in pkg.config.deplibs: if (pkg.config.libs[lib].have == "yes" and (not pkg.config.libs[lib].dynamic_load)): cmd_line += separate_args(pkg.config.libs[lib].flags[flag]) # Add CPPFLAGS and LDFLAGS information for the current package if flag == 'cppflags': cmd_line.insert(0, "-I" + pkg.get_dir("pkgincludedir")) elif flag == 'ldflags': cmd_line.insert(0, "-L" + pkg.get_dir("libdir")) # Add CPPFLAGS information when PLE is "internal" if pkg.config.libs['ple'].variant == "internal" and flag == 'cppflags': cmd_line.insert(0, "-I" + pkg.get_dir("includedir")) # Specific handling of low-level libraries, which should come last, # such as -lm and -lpthread: # If -lm appears multiple times, only add it at the end of the # libraries, so that fast versions of the library may appear first if flag == 'libs': for lib in ['-lpthread', '-lm']: n = cmd_line.count(lib) if n > 0: for i in range(n): cmd_line.remove(lib) cmd_line.append(lib) # On MinGW hosts, flags must be adapted so as to handle the relocation # of system headers (together with the compiler) # ...unless the compilation is done during the build stage if sys.platform.startswith("win") and not link_build: for i in range(len(cmd_line)): s = cmd_line[i] for p in ["-I/mingw", "-Ic:/mingw"]: s_tmp = s.replace(p, "-I" + pkg.get_dir("prefix")) for p in ["-L/mingw", "-Lc:/mingw"]: s_tmp = s.replace(p, "-L" + pkg.get_dir("prefix")) cmd_line[i] = s_tmp return cmd_line
def debug_wrapper_args(self, debug_cmd): """ Additional arguments to use debug wrapper """ debug_args = '' python_exec = self.package.config.python if os.path.isfile(python_exec) or os.path.islink(python_exec): debug_args += python_exec + ' ' else: debug_args += 'python ' if self.package.name != 'neptune_cfd': pkg_dir = self.package.get_dir('pkgpythondir') dbg_wrapper_path = os.path.join(pkg_dir, 'cs_debug_wrapper.py') debug_args += dbg_wrapper_path + ' ' for a in separate_args(debug_cmd): debug_args += enquote_arg(a) + ' ' return debug_args
def get_run_command(self): """ Determine the name of the main command of the runcase, and the associated line in the file; this allows mixing Code_Saturne and NEPTUNE_CFD cases in the same study. """ # Read the runcase script from the Repository. self.cmd_name = None self.run_cmd_line_id = -1 for i in range(len(self.lines) - 1, -1, -1): line = self.lines[i] # Skip comment and empty lines if len(line) == 0: continue if line[0] == '#' or line[0:4] == 'rem ': continue j = line.find('#') if j > -1: line = line[0:j] args = separate_args(line.rstrip()) if args.count('run') == 1: if args.index('run') == 1: # "<package_name> run" for name in ('code_saturne', 'neptune_cfd'): if sys.platform.startswith('win'): test_name = name if args[0].find(test_name) == 0: self.cmd_name = name self.run_cmd_line_id = i return test_name = '\\' + name if args[0].find(test_name) == 0: self.cmd_name = name self.run_cmd_line_id = i return # We should have exited before reaching this. err_str = "Error: unable to determine the name of the script for " + self.path raise ValueError(err_str)
def set_run_id(self, run_id=None, run_id_prefix=None, run_id_suffix=None): """ Set the run id, id_prefix, and id_suffix options in the run command """ line = self.lines[self.run_cmd_line_id] args = separate_args(line) if run_id != None: args = update_command_single_value(args, ('--id', '--id='), enquote_arg(run_id)) if run_id_prefix != None: args = update_command_single_value(args, ('--id-prefix', '--id-prefix='), enquote_arg(run_id_prefix)) if run_id_suffix != None: args = update_command_single_value(args, ('--id-suffix', '--id-suffix='), enquote_arg(run_id_suffix)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def set_run_id(self, run_id=None, run_id_prefix=None, run_id_suffix=None): """ Set the run id, id_prefix, and id_suffix options in the run command """ line = self.lines[self.run_cmd_line_id] args = separate_args(line) if run_id != None: args = update_command_single_value(args, ('--id', '--id='), enquote_arg(run_id)) if run_id_prefix != None: args = update_command_single_value(args, ('--id-prefix', '--id-prefix='), enquote_arg(run_id_prefix)) if run_id_suffix != None: args = update_command_single_value(args, ('--id-suffix', '--id-suffix='), enquote_arg(run_id_suffix)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def compile_and_link(pkg, srcdir, destdir, opt_cflags=None, opt_cxxflags=None, opt_fcflags=None, opt_libs=None, force_link=False, keep_going=False, stdout=sys.stdout, stderr=sys.stderr): """ Compilation and link function. """ retval = 0 # Determine executable name exec_name = pkg.solver if destdir != None: exec_name = os.path.join(destdir, exec_name) # Change to temporary directory call_dir = os.getcwd() temp_dir = tempfile.mkdtemp(suffix=".cs_compile") os.chdir(temp_dir) # Find files to compile in source path dir_files = os.listdir(srcdir) c_files = fnmatch.filter(dir_files, '*.c') h_files = fnmatch.filter(dir_files, '*.h') cxx_files = fnmatch.filter(dir_files, '*.cxx') + fnmatch.filter( dir_files, '*.cpp') hxx_files = fnmatch.filter(dir_files, '*.hxx') + fnmatch.filter( dir_files, '*.hpp') f_files = fnmatch.filter(dir_files, '*.[fF]90') # Special handling for some linkers (such as Mac OS X), for which # no multiple definitions are allowable in static mode; # in this case, extract archive, then overwrite with user files. p_libs = get_flags(pkg, 'libs') if pkg.config.special_user_link == 'ar_x': if force_link or (len(c_files) + len(cxx_files) + len(f_files)) > 0: lib0 = os.path.join(pkg.get_dir('libdir'), 'lib' + p_libs[0][2:] + '.a') p_libs = p_libs[1:] cmd = ['ar', 'x', lib0] if run_command( cmd, pkg=pkg, echo=True, stdout=stdout, stderr=stderr) != 0: retval = 1 # Compile files for f in c_files: if (retval != 0 and not keep_going): break cmd = [get_compiler(pkg, 'cc')] if opt_cflags != None: cmd = cmd + separate_args(opt_cflags) if len(h_files) > 0: cmd = cmd + ["-I", srcdir] cmd.append('-DHAVE_CONFIG_H') if f == 'cs_base.c': cmd = cmd + ['-DLOCALEDIR=\\"' + pkg.get_dir('localedir') + '\\"', \ '-DPKGDATADIR=\\"' + pkg.get_dir('pkgdatadir') + '\\"'] cmd = cmd + get_flags(pkg, 'cppflags') cmd = cmd + separate_args(pkg.config.flags['cflags']) cmd = cmd + ["-c", os.path.join(srcdir, f)] if run_command(cmd, pkg=pkg, echo=True, stdout=stdout, stderr=stderr) != 0: retval = 1 for f in cxx_files: if (retval != 0 and not keep_going): break cmd = [get_compiler(pkg, 'cxx')] if opt_cxxflags != None: cmd = cmd + separate_args(opt_cxxflags) if len(hxx_files) > 0: cmd = cmd + ["-I", srcdir] cmd.append('-DHAVE_CONFIG_H') cmd = cmd + get_flags(pkg, 'cppflags') cmd = cmd + separate_args(pkg.config.flags['cxxflags']) cmd = cmd + ["-c", os.path.join(srcdir, f)] if run_command(cmd, pkg=pkg, echo=True, stdout=stdout, stderr=stderr) != 0: retval = 1 user_mod_name = 'cs_user_modules.f90' if user_mod_name in f_files: f_files.remove(user_mod_name) f_files.insert(0, user_mod_name) for f in f_files: if (retval != 0 and not keep_going): break cmd = [get_compiler(pkg, 'fc')] if f == 'cs_user_boundary_conditions.f90': cmd = cmd + ["-o", "cs_f_user_boundary_conditions.o"] if f == 'cs_user_parameters.f90': cmd = cmd + ["-o", "cs_f_user_parameters.o"] if f == 'cs_user_extra_operations.f90': cmd = cmd + ["-o", "cs_f_user_extra_operations.o"] if f == 'cs_user_initialization.f90': cmd = cmd + ["-o", "cs_f_user_initialization.o"] if f == 'cs_user_physical_properties.f90': cmd = cmd + ["-o", "cs_f_user_physical_properties.o"] if opt_fcflags != None: cmd = cmd + separate_args(opt_fcflags) cmd = cmd + ["-I", srcdir] if pkg.config.fcmodinclude != "-I": cmd = cmd + [pkg.config.fcmodinclude, srcdir] cmd = cmd + ["-I", pkg.get_dir('pkgincludedir')] if pkg.config.fcmodinclude != "-I": cmd = cmd + [pkg.config.fcmodinclude, pkg.get_dir('pkgincludedir')] cmd = cmd + separate_args(pkg.config.flags['fcflags']) cmd = cmd + ["-c", os.path.join(srcdir, f)] if run_command(cmd, pkg=pkg, echo=True, stdout=stdout, stderr=stderr) != 0: retval = 1 if retval == 0 and (force_link or (len(c_files) + len(cxx_files) + len(f_files)) > 0): cmd = [get_compiler(pkg, 'ld')] cmd = cmd + ["-o", exec_name] if (len(c_files) + len(cxx_files) + len(f_files)) > 0: dir_files = os.listdir(temp_dir) o_files = fnmatch.filter(dir_files, '*.o') cmd = cmd + o_files # If present, address sanitizer needs to come first if '-lasan' in p_libs: p_libs.remove('-lasan') cmd += ['-lasan'] if opt_libs != None: if len(opt_libs) > 0: cmd += separate_args(opt_libs) cmd = cmd + get_flags(pkg, 'ldflags') cmd = cmd + p_libs if pkg.config.rpath != "": cmd += so_dirs_path(cmd, pkg) if run_command(cmd, pkg=pkg, echo=True, stdout=stdout, stderr=stderr) != 0: retval = 1 # Cleanup for f in os.listdir(temp_dir): os.remove(os.path.join(temp_dir, f)) # Return to original directory os.chdir(call_dir) os.rmdir(temp_dir) return retval
def update(self, xmlonly=False): """ Update path for the script in the Repository. """ # 1) Load the xml file of parameters in order to update it # with the __backwardCompatibility method. from Base.XMLengine import Case from Pages.ScriptRunningModel import ScriptRunningModel from cs_exec_environment import \ separate_args, get_command_single_value, update_command_single_value, assemble_args if self.exe == "code_saturne": from Base.XMLinitialize import XMLinit elif self.exe == "neptune_cfd": from core.XMLinitialize import XMLinit n_procs = {} for fn in os.listdir(os.path.join(self.__repo, self.label, "DATA")): fp = os.path.join(self.__repo, self.label, "DATA", fn) if os.path.isfile(fp): fd = os.open(fp , os.O_RDONLY) f = os.fdopen(fd) l = f.readline() f.close() if l.startswith('''<?xml version="1.0" encoding="utf-8"?><Code_Saturne_GUI''') or \ l.startswith('''<?xml version="1.0" encoding="utf-8"?><NEPTUNE_CFD_GUI'''): try: case = Case(package = self.pkg, file_name = fp) except: print("Parameters file reading error.\n") print("This file is not in accordance with XML specifications.") sys.exit(1) case['xmlfile'] = fp case.xmlCleanAllBlank(case.xmlRootNode()) XMLinit(case).initialize() smdl = ScriptRunningModel(case) n_procs[str(fn)] = smdl.getString('n_procs') smdl.setString('n_procs', None) case.xmlSaveDocument() # 2) Create RESU directory if needed if not xmlonly: r = os.path.join(self.__repo, self.label, "RESU") if not os.path.isdir(r): os.makedirs(r) # 3) Update the GUI script from the Repository ref = os.path.join(self.__repo, self.label, "DATA", self.pkg.guiname) have_gui = 1 try: f = file(ref, mode = 'r') except IOError: print("Warning SaturneGUI does not exist: %s\n" % ref) have_gui = 0 if have_gui: lines = f.readlines() f.close() for i in range(len(lines)): if re.search(r'^prefix=', lines[i]): if xmlonly: lines[i] = "prefix=\n" else: lines[i] = "prefix=" + self.pkg.get_dir('prefix') + "\n" if re.search(r'^export PATH=', lines[i]): if xmlonly: lines[i] = 'export PATH="":$PATH\n' else: lines[i] = 'export PATH="' + self.pkg.get_dir('bindir') +'":$PATH\n' f = file(ref, mode = 'w') f.writelines(lines) f.close() # 4) Update the runcase script from the Repository ref = os.path.join(self.__repo, self.label, "SCRIPTS", "runcase") try: f = file(ref, mode = 'r') except IOError: print("Error: can not open %s\n" % ref) sys.exit(1) lines = f.readlines() f.close() for i in range(len(lines)): if lines[i].strip()[0:1] == '#': continue if xmlonly: if re.search(r'^export PATH=', lines[i]): lines[i] = 'export PATH="":$PATH\n' else: if re.search(r'^export PATH=', lines[i]): lines[i] = 'export PATH="' + self.pkg.get_dir('bindir') +'":$PATH\n' j = lines[i].find(self.pkg.name) if j > -1: j = lines[i].find('run') args = separate_args(lines[i].rstrip()) param = get_command_single_value(args, ('--param', '--param=', '-p')) try: if n_procs[param]: args = update_command_single_value(args, ('--nprocs', '--nprocs=', '-n'), n_procs[param]) lines[i] = assemble_args(args) + '\n' except Exception: pass f = file(ref, mode = 'w') f.writelines(lines) f.close()
def compile_and_link(pkg, srcdir, destdir, opt_cflags=None, opt_cxxflags=None, opt_fcflags=None, opt_libs=None, force_link=False, keep_going=False, stdout = sys.stdout, stderr = sys.stderr): """ Compilation and link function. """ retval = 0 # Determine executable name exec_name = pkg.solver if destdir != None: exec_name = os.path.join(destdir, exec_name) # Change to temporary directory call_dir = os.getcwd() temp_dir = tempfile.mkdtemp(suffix=".cs_compile") os.chdir(temp_dir) # Find files to compile in source path dir_files = os.listdir(srcdir) c_files = fnmatch.filter(dir_files, '*.c') h_files = fnmatch.filter(dir_files, '*.h') cxx_files = fnmatch.filter(dir_files, '*.cxx') + fnmatch.filter(dir_files, '*.cpp') hxx_files = fnmatch.filter(dir_files, '*.hxx') + fnmatch.filter(dir_files, '*.hpp') f_files = fnmatch.filter(dir_files, '*.[fF]90') # Special handling for some linkers (such as Mac OS X), for which # no multiple definitions are allowable in static mode; # in this case, extract archive, then overwrite with user files. p_libs = get_flags(pkg, 'libs') if pkg.config.special_user_link == 'ar_x': if force_link or (len(c_files) + len(cxx_files) + len(f_files)) > 0: lib0 = os.path.join(pkg.get_dir('libdir'), 'lib' + p_libs[0][2:] + '.a') p_libs = p_libs[1:] cmd = ['ar', 'x', lib0] if run_command(cmd, pkg=pkg, echo=True, stdout=stdout, stderr=stderr) != 0: retval = 1 # Compile files for f in c_files: if (retval != 0 and not keep_going): break cmd = [get_compiler(pkg, 'cc')] if opt_cflags != None: cmd = cmd + separate_args(opt_cflags) if len(h_files) > 0: cmd = cmd + ["-I", srcdir] cmd.append('-DHAVE_CONFIG_H') if f == 'cs_base.c': cmd = cmd + ['-DLOCALEDIR=\\"' + pkg.get_dir('localedir') + '\\"', \ '-DPKGDATADIR=\\"' + pkg.get_dir('pkgdatadir') + '\\"'] cmd = cmd + get_flags(pkg, 'cppflags') cmd = cmd + separate_args(pkg.config.flags['cflags']) cmd = cmd + ["-c", os.path.join(srcdir, f)] if run_command(cmd, pkg=pkg, echo=True, stdout=stdout, stderr=stderr) != 0: retval = 1 for f in cxx_files: if (retval != 0 and not keep_going): break cmd = [get_compiler(pkg, 'cxx')] if opt_cxxflags != None: cmd = cmd + separate_args(opt_cxxflags) if len(hxx_files) > 0: cmd = cmd + ["-I", srcdir] cmd.append('-DHAVE_CONFIG_H') cmd = cmd + get_flags(pkg, 'cppflags') cmd = cmd + separate_args(pkg.config.flags['cxxflags']) cmd = cmd + ["-c", os.path.join(srcdir, f)] if run_command(cmd, pkg=pkg, echo=True, stdout=stdout, stderr=stderr) != 0: retval = 1 user_mod_name = 'cs_user_modules.f90' if user_mod_name in f_files: f_files.remove(user_mod_name) f_files.insert(0, user_mod_name) for f in f_files: if (retval != 0 and not keep_going): break cmd = [get_compiler(pkg, 'fc')] if f == 'cs_user_parameters.f90': cmd = cmd + ["-o", "cs_f_user_parameters.o"] if f == 'cs_user_extra_operations.f90': cmd = cmd + ["-o", "cs_f_user_extra_operations.o"] if opt_fcflags != None: cmd = cmd + separate_args(opt_fcflags) cmd = cmd + ["-I", srcdir] if pkg.config.fcmodinclude != "-I": cmd = cmd + [pkg.config.fcmodinclude, srcdir] cmd = cmd + ["-I", pkg.get_dir('pkgincludedir')] if pkg.config.fcmodinclude != "-I": cmd = cmd + [pkg.config.fcmodinclude, pkg.get_dir('pkgincludedir')] cmd = cmd + separate_args(pkg.config.flags['fcflags']) cmd = cmd + ["-c", os.path.join(srcdir, f)] if run_command(cmd, pkg=pkg, echo=True, stdout=stdout, stderr=stderr) != 0: retval = 1 if retval == 0 and (force_link or (len(c_files) + len(cxx_files) + len(f_files)) > 0): cmd = [get_compiler(pkg, 'ld')] cmd = cmd + ["-o", exec_name] if (len(c_files) + len(cxx_files) + len(f_files)) > 0: dir_files = os.listdir(temp_dir) o_files = fnmatch.filter(dir_files, '*.o') cmd = cmd + o_files if opt_libs != None: if len(opt_libs) > 0: cmd += separate_args(opt_libs) cmd = cmd + get_flags(pkg, 'ldflags') cmd = cmd + p_libs if pkg.config.rpath != "": cmd += so_dirs_path(cmd, pkg) if run_command(cmd, pkg=pkg, echo=True, stdout=stdout, stderr=stderr) != 0: retval = 1 # Cleanup for f in os.listdir(temp_dir): os.remove(os.path.join(temp_dir, f)) # Return to original directory os.chdir(call_dir) os.rmdir(temp_dir) return retval
def get_run_args(self): """ Get the run command and arguments, as a list """ return separate_args(self.lines[self.run_cmd_line_id])