@@ -20,12 +20,13 @@ def naturalSort(s):
2020 return [int (text ) if text .isdigit () else text .lower ()
2121 for text in re .split ('([0-9]+)' , s )]
2222
23- def run (command ):
23+ def run (command , directory ):
2424 logger .log ("Running command: " + command )
2525 result = subprocess .run (command ,
2626 stdout = subprocess .PIPE ,
2727 stderr = subprocess .STDOUT ,
28- shell = True )
28+ shell = True ,
29+ cwd = directory )
2930 logger .log (result .stdout .decode ('utf-8' ))
3031 if result .returncode != 0 :
3132 logger .log (f"Error running the command: { command } " )
@@ -183,10 +184,16 @@ def main():
183184
184185 solution_file_name = os .path .join (src_dir , "solution.cpp" )
185186 solution_function_file_name = os .path .join (src_dir , "solutionfunction.h" )
186- ret = functionextractor .get_function (solution_file_name ,
187- solution_function_file_name )
188- logger .log (f"Extracted function name: { ret } " )
189- logger .log (f"Writing the function name to { solution_function_file_name } " )
187+ if not os .path .isfile (solution_function_file_name ):
188+ ret = functionextractor .get_function (solution_file_name ,
189+ solution_function_file_name )
190+ logger .log (f"Extracted function name: { ret } " )
191+ logger .log (f"Writing the function name to { solution_function_file_name } " )
192+
193+ if not ret :
194+ print (logger .red (f"Could not extract the function name from "
195+ f"{ solution_file_name } ." ))
196+ sys .exit (1 )
190197
191198 validation_schema_file = os .path .abspath (
192199 os .path .join (openleetcode_dir , VALIDATION_SCHEMA_FILE_NAME ))
@@ -204,20 +211,19 @@ def main():
204211 sys .exit (1 )
205212 resultsvalidator .set_schema (schema )
206213
207- if not ret :
208- print (logger .red (f"Could not extract the function name from "
209- f"{ solution_file_name } ." ))
210- sys .exit (1 )
211-
212- if run (f"cmake -B { build_dir } -S { src_dir } " ) != 0 :
213- print (logger .red (f"CMake failed!" ))
214- sys .exit (1 )
214+ if not os .path .isfile (os .path .join (build_dir , "CMakeCache.txt" )):
215+ print ("CMakeCache.txt does not exist. Running CMake to configure the " )
216+ if run (f"cmake -B { build_dir } " , src_dir ) != 0 :
217+ print (logger .red (f"CMake failed!" ))
218+ sys .exit (1 )
219+ else :
220+ print ("CMakeCache.txt exists. Skipping CMake configuration." )
215221
216- if run (f"cmake --build { build_dir } --config Release" ) != 0 :
222+ if run (f"cmake --build . --config Release -j" , build_dir ) != 0 :
217223 print (logger .red ("Build failed!" ))
218224 sys .exit (1 )
219225
220- if run (f"cmake --install { build_dir } " ) != 0 :
226+ if run (f"cmake --install ." , build_dir ) != 0 :
221227 print (logger .red ("Cmake install failed!" ))
222228 sys .exit (1 )
223229
@@ -253,7 +259,6 @@ def main():
253259
254260 output_file_dir = os .path .abspath (os .path .join (TESTCAST_OUTPUT_DIR ))
255261
256- # Run the tests
257262 ret , error_message = testrunner .runTests (exe_file ,
258263 testcases_dir ,
259264 output_file_dir ,
0 commit comments