def _build_mod_file(modfilename, output_dir=None, build_dir=None, modfile=None): build_dir = LocMgr().get_default_mod_builddir() if not build_dir else build_dir output_dir = LocMgr().get_default_mod_outdir() if not output_dir else output_dir if SettingsMgr.simulator_is_verbose(): print " - Building: ", modfilename modfilenamebase = os.path.basename(modfilename) sofilenamebase = modfilenamebase.replace(".mod", ".so") shutil.copyfile(modfilename, os.path.join(build_dir, modfilenamebase)) so_filename_output = os.path.join(output_dir, sofilenamebase) # Move to new directory to build: initial_cwd = os.getcwd() os.chdir(build_dir) so_filename_build_short = _build_modfile_local(mod_filename_short=modfilenamebase, modfile=modfile) os.chdir(initial_cwd) # CopyFile to output cell_location: so_filename_build = os.path.join(build_dir, so_filename_build_short) if so_filename_build != so_filename_output: shutil.move(so_filename_build, so_filename_output) return so_filename_output
def _build_mod_file(modfilename, output_dir=None, build_dir=None, modfile=None): build_dir = LocMgr().get_default_mod_builddir( ) if not build_dir else build_dir output_dir = LocMgr().get_default_mod_outdir( ) if not output_dir else output_dir if SettingsMgr.simulator_is_verbose(): print ' - Building: ', modfilename modfilenamebase = os.path.basename(modfilename) sofilenamebase = modfilenamebase.replace('.mod', '.so') shutil.copyfile(modfilename, os.path.join(build_dir, modfilenamebase)) so_filename_output = os.path.join(output_dir, sofilenamebase) # Move to new directory to build: initial_cwd = os.getcwd() os.chdir(build_dir) so_filename_build_short = _build_modfile_local( mod_filename_short=modfilenamebase, modfile=modfile) os.chdir(initial_cwd) # CopyFile to output cell_location: so_filename_build = os.path.join(build_dir, so_filename_build_short) if so_filename_build != so_filename_output: shutil.move(so_filename_build, so_filename_output) return so_filename_output
def _simple_exec(cmd, remaining): print "Executing: %s %s" % (cmd, remaining) output = subprocess.Popen( [cmd + " " + remaining], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE ).communicate()[0] if SettingsMgr.simulator_is_verbose(): print output return output
def _simple_exec(cmd, remaining): print 'Executing: %s %s' % (cmd, remaining) output = subprocess.Popen([cmd + ' ' + remaining], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] if SettingsMgr.simulator_is_verbose(): print output return output
def _is_logging_active_and_ready(cls): if cls._initialised_state == LogMgrState.Ready: from morphforge.core.mgrs.settingsmgr import SettingsMgr if not SettingsMgr.is_logging(): return False return True elif cls._initialised_state == LogMgrState.Configuring: return False elif cls._initialised_state == LogMgrState.Uninitialised: cls.config() return True else: raise ValueError()
def _simple_exec(cmd, remaining, err_ok=False): print 'Executing: %s %s' % (cmd, remaining) args = [cmd + ' ' + remaining] proc = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output,err = proc.communicate() if not proc.returncode == 0 and err_ok!=True: print output, err raise ValueError(('Problem Building Mod-file!' + '\n %s '% args) + output) if SettingsMgr.simulator_is_verbose(): print output, err return output
def check_modfile_units(cls, modfilename): output = _simple_exec(ModBuilderParams.modlunitpath, modfilename) op_expected = """ model 1.1.1.1 1994/10/12 17:22:51 Checking units of %s""" % modfilename if SettingsMgr.simulator_is_verbose(): print 'OP', output # Check line by line: for (line, line_expected) in zip(output.split('\n'), op_expected.split('\n')): if not line_expected.strip() == line.strip(): print 'ERROR ERROR ERROR WITH UNITS!!' print 'Seen', line print 'Expt', line_expected
def check_modfile_units(cls, modfilename): output = _simple_exec(ModBuilderParams.modlunitpath, modfilename, err_ok=True) op_expected = """ model 1.1.1.1 1994/10/12 17:22:51 Checking units of %s""" % modfilename if SettingsMgr.simulator_is_verbose(): print 'OP', output # Check line by line: for (line, line_expected) in zip(output.split('\n'), op_expected.split('\n')): if not line_expected.strip() == line.strip(): print 'ERROR ERROR ERROR WITH UNITS!!' print 'Seen', line print 'Expt', line_expected assert False
def check_modfile_units(cls, modfilename): output = _simple_exec(ModBuilderParams.modlunitpath, modfilename) op_expected = ( """ model 1.1.1.1 1994/10/12 17:22:51 Checking units of %s""" % modfilename ) if SettingsMgr.simulator_is_verbose(): print "OP", output # Check line by line: for (line, line_expected) in zip(output.split("\n"), op_expected.split("\n")): if not line_expected.strip() == line.strip(): print "ERROR ERROR ERROR WITH UNITS!!" print "Seen", line print "Expt", line_expected
def _build_modfile_local(mod_filename_short, modfile=None): print os.getcwd() mod_file_basename = mod_filename_short.replace('.mod', '') c_filename = mod_file_basename + '.c' la_filename = mod_file_basename + '.la' lo_filename = mod_file_basename + '.lo' so_filename = mod_file_basename + '.so' libs_dir = '.libs/' # Check for some existing files: #for gen_file in gen_files: # if os.path.exists(gen_file): # assert False, 'We never get here' # LocMgr.BackupDirectory(gen_file) c_filename = mod_file_basename + '.c' output = _simple_exec(ModBuilderParams.nocmodlpath, mod_filename_short) if not os.path.exists(c_filename): print 'Failed to compile modfile. Error:' print output, '\n' assert False # Add the extra registration function into our mod file: new_register_func = """\n modl_reg(){ _%s_reg(); }""" \ % mod_file_basename FileIO.append_to_file(new_register_func, c_filename) # Compile the .c file -> .so: compile_str = ModBuilderParams.get_compile_str(c_filename, lo_filename) link_str = ModBuilderParams.get_link_str(lo_filename, la_filename) if SettingsMgr.simulator_is_verbose(): print 'IN:', ModBuilderParams.libtoolpath, print compile_str print link_str compile_flags = modfile.additional_compile_flags if modfile else '' link_flags = modfile.additional_link_flags if modfile else '' op1 = _simple_exec( ModBuilderParams.libtoolpath, ModBuilderParams.get_compile_str( c_filename, lo_filename, additional_compile_flags=compile_flags)) op2 = _simple_exec( ModBuilderParams.libtoolpath, ModBuilderParams.get_link_str(lo_filename, la_filename, additional_link_flags=link_flags)) if SettingsMgr.simulator_is_verbose() or True: print 'OP1:', op1 print 'OP2:', op2 # Copy the correct .so from the libDir to the build_dir: shutil.move(os.path.join(libs_dir, mod_file_basename + '.so.0.0.0'), so_filename) # Clean up: if True: os.remove(c_filename) os.remove(mod_filename_short) for ext in ['.la', '.lo']: os.remove(mod_file_basename + ext) for ext in ['.la', '.lai', '.o', '.so', '.so.0']: os.remove(os.path.join(libs_dir, mod_file_basename + ext)) os.rmdir(libs_dir) return so_filename
def _build_modfile_local(mod_filename_short, modfile=None): print os.getcwd() mod_file_basename = mod_filename_short.replace(".mod", "") c_filename = mod_file_basename + ".c" la_filename = mod_file_basename + ".la" lo_filename = mod_file_basename + ".lo" so_filename = mod_file_basename + ".so" libs_dir = ".libs/" # Check for some existing files: # for gen_file in gen_files: # if os.path.exists(gen_file): # assert False, 'We never get here' # LocMgr.BackupDirectory(gen_file) c_filename = mod_file_basename + ".c" output = _simple_exec(ModBuilderParams.nocmodlpath, mod_filename_short) if not os.path.exists(c_filename): print "Failed to compile modfile. Error:" print output, "\n" assert False # Add the extra registration function into our mod file: new_register_func = """\n modl_reg(){ _%s_reg(); }""" % mod_file_basename FileIO.append_to_file(new_register_func, c_filename) # Compile the .c file -> .so: compile_str = ModBuilderParams.get_compile_str(c_filename, lo_filename) link_str = ModBuilderParams.get_link_str(lo_filename, la_filename) if SettingsMgr.simulator_is_verbose(): print "IN:", ModBuilderParams.libtoolpath, print compile_str print link_str compile_flags = modfile.additional_compile_flags if modfile else "" link_flags = modfile.additional_link_flags if modfile else "" op1 = _simple_exec( ModBuilderParams.libtoolpath, ModBuilderParams.get_compile_str(c_filename, lo_filename, additional_compile_flags=compile_flags), ) op2 = _simple_exec( ModBuilderParams.libtoolpath, ModBuilderParams.get_link_str(lo_filename, la_filename, additional_link_flags=link_flags), ) if SettingsMgr.simulator_is_verbose() or True: print "OP1:", op1 print "OP2:", op2 # Copy the correct .so from the libDir to the build_dir: shutil.move(os.path.join(libs_dir, mod_file_basename + ".so.0.0.0"), so_filename) # Clean up: if True: os.remove(c_filename) os.remove(mod_filename_short) for ext in [".la", ".lo"]: os.remove(mod_file_basename + ext) for ext in [".la", ".lai", ".o", ".so", ".so.0"]: os.remove(os.path.join(libs_dir, mod_file_basename + ext)) os.rmdir(libs_dir) return so_filename
def _build_modfile_local(mod_filename_short, modfile=None): print os.getcwd() mod_file_basename = mod_filename_short.replace('.mod', '') c_filename = mod_file_basename + '.c' la_filename = mod_file_basename + '.la' lo_filename = mod_file_basename + '.lo' so_filename = mod_file_basename + '.so' libs_dir = '.libs/' c_filename = mod_file_basename + '.c' output = _simple_exec(ModBuilderParams.nocmodlpath, mod_filename_short, err_ok=True) if not os.path.exists(c_filename): print 'Failed to compile modfile. Error:' print output, '\n' assert False # Add the extra registration function into our mod file: new_register_func = """\n modl_reg(){ _%s_reg(); }""" \ % mod_file_basename FileIO.append_to_file(new_register_func, c_filename) # Compile the .c file -> .so: compile_str = ModBuilderParams.get_compile_str(c_filename, lo_filename) link_str = ModBuilderParams.get_link_str(lo_filename, la_filename) compile_flags = modfile.additional_compile_flags if modfile else '' link_flags = modfile.additional_link_flags if modfile else '' if SettingsMgr.simulator_is_verbose(): print 'IN:', ModBuilderParams.libtoolpath, print compile_str print link_str op1 = _simple_exec(ModBuilderParams.libtoolpath, ModBuilderParams.get_compile_str(c_filename, lo_filename, additional_compile_flags=compile_flags)) op2 = _simple_exec(ModBuilderParams.libtoolpath, ModBuilderParams.get_link_str(lo_filename, la_filename, additional_link_flags=link_flags)) for filename in [c_filename, lo_filename, la_filename]: if not os.path.exists(filename): assert False, 'Error building mod-file!' if SettingsMgr.simulator_is_verbose() or True: print 'OP1:', op1 print 'OP2:', op2 # Copy the correct .so from the libDir to the build_dir: shutil.move( os.path.join(libs_dir, mod_file_basename + '.so.0.0.0'), so_filename) # Clean up: if True: os.remove(c_filename) os.remove(mod_filename_short) for ext in ['.la', '.lo']: os.remove(mod_file_basename + ext) for ext in ['.la', '.lai', '.o', '.so', '.so.0']: os.remove(os.path.join(libs_dir, mod_file_basename + ext)) os.rmdir(libs_dir) return so_filename