@@ -470,41 +470,50 @@ def compile(self, debug=False, profile=False):
470470 self .__create_propensity_file (stoich_matrix , dep_graph , file_name = self .prop_file_name )
471471
472472 # Build the solver
473+ for make_exe_location in ["make" , "mingw32-make" ]:
474+ make_exe = shutil .which ("make" )
475+ if make_exe is not None :
476+ break
477+ if make_exe is None :
478+ raise SimulationError ("Make executable could not be found" )
473479 makefile = self .spatialpy_rootdir + '/build/Makefile'
474480 makefile_ann = self .spatialpy_rootdir + '/external/ANN/src/Makefile.spatialpy'
475- cmd_list = ['cd' , self .core_dir , '&&' ,
476- 'make' , '-f' , makefile_ann ,
477- 'ROOTINC="' + self .spatialpy_rootinc + '"' ,
478- '&&' ,
479- 'make' , 'CORE' , '-f' , makefile ,
480- 'ROOT="' + self .spatialpy_rootparam + '"' ,
481- 'ROOTINC="' + self .spatialpy_rootinc + '"' ,
482- 'BUILD=' + self .core_dir , '&&'
483- 'cd' , self .build_dir , '&&' , 'make' , '-I' , self .core_dir , '-f' , makefile ,
484- 'ROOT="' + self .spatialpy_rootparam + '"' ,
485- 'ROOTINC="' + self .spatialpy_rootinc + '"' ,
486- 'COREDIR="' + self .core_dir + '"' ,
487- 'MODEL=' + self .prop_file_name , 'BUILD=' + self .build_dir ]
481+
482+ cmd_ann = [
483+ make_exe , '-d' , '-C' , self .core_dir , '-f' , makefile_ann ,
484+ f'ROOTINC={ self .spatialpy_rootinc } ' ,
485+ ]
486+ cmd_core = [
487+ make_exe , '-d' , '-C' , self .core_dir , 'CORE' , '-f' , makefile ,
488+ f'ROOT={ self .spatialpy_rootparam } ' ,
489+ f'ROOTINC={ self .spatialpy_rootinc } ' ,
490+ f'BUILD={ self .core_dir } ' ,
491+ ]
492+ cmd_build = [
493+ make_exe , '-d' , '-C' , self .build_dir , '-I' , self .core_dir , '-f' , makefile ,
494+ 'ROOT=' + self .spatialpy_rootparam ,
495+ 'ROOTINC=' + self .spatialpy_rootinc ,
496+ 'COREDIR=' + self .core_dir ,
497+ 'MODEL=' + self .prop_file_name , 'BUILD=' + self .build_dir
498+ ]
488499 if profile :
489- cmd_list .append ('GPROFFLAG=-pg' )
500+ cmd_build .append ('GPROFFLAG=-pg' )
490501 if profile or debug :
491- cmd_list .append ('GDB_FLAG=-g' )
492- cmd = " " .join (cmd_list )
502+ cmd_build .append ('GDB_FLAG=-g' )
493503 if self .debug_level > 1 :
504+ cmd = " && " .join ([* cmd_ann , * cmd_core , * cmd_build ])
494505 print (f"cmd: { cmd } \n " )
495506 try :
496- with subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .STDOUT , shell = True ) as handle :
497- stdout , _ = handle .communicate ()
498- return_code = handle .wait ()
499- if return_code != 0 :
500- try :
501- print (stdout .decode ("utf-8" ))
502- except Exception :
503- pass
504- raise SimulationError (f"Compilation of solver failed, return_code={ return_code } " )
505-
507+ for cmd_target in [cmd_ann , cmd_core , cmd_build ]:
508+ result = subprocess .check_output (cmd_target , stderr = subprocess .STDOUT )
506509 if self .debug_level > 1 :
507- print (stdout .decode ("utf-8" ))
510+ print (result .stdout .decode ("utf-8" ))
511+ except subprocess .CalledProcessError as err :
512+ try :
513+ print (err .stdout .decode ("utf-8" ))
514+ except Exception :
515+ pass
516+ raise SimulationError (f"Compilation of solver failed, return_code={ result .return_code } " )
508517 except OSError as err :
509518 print (f"Error, execution of compilation raised an exception: { err } " )
510519 print (f"cmd = { cmd } " )
@@ -559,7 +568,7 @@ def run(self, number_of_trajectories=1, seed=None, timeout=None,
559568 result = Result (self .model , outfile )
560569 if self .debug_level >= 1 :
561570 print (f"Running simulation. Result dir: { outfile } " )
562- solver_cmd = f'cd { outfile } ; { os .path .join (self .build_dir , self .executable_name )} '
571+ solver_cmd = os .path .join (self .build_dir , self .executable_name )
563572
564573 if number_of_threads is not None :
565574 solver_cmd += " -t " + str (number_of_threads )
@@ -573,7 +582,7 @@ def run(self, number_of_trajectories=1, seed=None, timeout=None,
573582 start = time .monotonic ()
574583 return_code = None
575584 try :
576- with subprocess .Popen (solver_cmd , shell = True ,
585+ with subprocess .Popen (solver_cmd , cwd = outfile , shell = True ,
577586 stdout = subprocess .PIPE , stderr = subprocess .STDOUT ,
578587 start_new_session = True ) as process :
579588 try :
0 commit comments