22from flask import Flask , request , jsonify
33import subprocess
44import os
5- import logging # Import the logging module
6- import json
5+ import logging
76
87# --- Flask Setup ---
98app = Flask (__name__ )
@@ -29,14 +28,23 @@ def compile_simulation():
2928 os .remove (SIMULATION_EXECUTABLE )
3029
3130 logger .info ("Compiling simulation..." )
31+
32+ # Check if main.cpp exists
33+ if not os .path .exists ("./src/main.cpp" ):
34+ COMPILE_ERROR = {"error" : "main.cpp not found" , "details" : "Ensure main.cpp is in the correct directory." }
35+ logger .error (f"Compilation failed: { COMPILE_ERROR ['error' ]} - Details: { COMPILE_ERROR ['details' ]} " )
36+ return False
3237 compile_result = subprocess .run (["g++" , "-O3" , "-o" , SIMULATION_EXECUTABLE , "./src/main.cpp" ], capture_output = True , text = True )
3338
39+ # Check if compilation was successful
3440 if compile_result .returncode != 0 :
3541 COMPILE_ERROR = {"error" : "Compilation failed" , "details" : compile_result .stderr }
3642 logger .error (f"Compilation failed: { COMPILE_ERROR ['error' ]} - Details: { COMPILE_ERROR ['details' ]} " ) # Use logger.error for errors
3743 return False
3844
45+ COMPILE_ERROR = None
3946 logger .info ("Simulation compiled successfully." )
47+
4048 return True
4149
4250# --- Run Simulation Endpoint ---
@@ -48,12 +56,10 @@ def run_simulation():
4856 return jsonify (COMPILE_ERROR ), 500
4957
5058 if not os .path .exists (SIMULATION_EXECUTABLE ):
51- return jsonify ({"error" : "Simulation executable not found. Contact developer." }), 400
59+ return jsonify ({"error" : "Simulation executable not found. Contact developer." }), 500
5260
5361 try :
5462 data = request .get_json ()
55- # if not data:
56- # return jsonify({"error": "Missing JSON parameters in request body."}), 400
5763
5864 # Parameters, use default values if not provided
5965 algorithm = data .get ("algorithm" , "FirstFit" )
0 commit comments