diff --git a/src/bedit_gui/controllers/simulation_controller.py b/src/bedit_gui/controllers/simulation_controller.py index 8c071b1..4479ed0 100644 --- a/src/bedit_gui/controllers/simulation_controller.py +++ b/src/bedit_gui/controllers/simulation_controller.py @@ -11,11 +11,14 @@ from PySide6.QtWidgets import QApplication, QMessageBox from bedit_core.models import Component from bedit_gui.documents import Document from bedit_gui.services import simulation_files +from bedit_gui.services.application_logging import get_logger from bedit_gui.services.simulation_loader import component_choices from bedit_gui.simulation_models import CompiledModel, SimulationRoot from bedit_gui.views.main_window import MainWindow from bedit_simulation import ModelBuildResult, compile_component_sync +logger = get_logger(__name__) + Compiler = Callable[[Component, str | Path], ModelBuildResult] Launcher = Callable[[Path, CompiledModel], bool] @@ -54,15 +57,17 @@ class SimulationController(QObject): build_directory = Path(tempfile.mkdtemp(prefix="bedit-compiled-")) QApplication.setOverrideCursor(Qt.CursorShape.WaitCursor) self.window.statusBar().showMessage(f"Compiling {component_path}…") + logger.info("Compiling model: %s", component_path) try: build = self.compiler(component, build_directory) except (OSError, RuntimeError, ValueError) as exc: + logger.exception("Could not compile model %s", component_path) QMessageBox.critical(self.window, "Could not compile", str(exc)) self.window.statusBar().showMessage("Compilation failed") return None finally: QApplication.restoreOverrideCursor() - self.compiled_model = CompiledModel(build.model_name, str(build.executable.resolve()), str(build.executable.parent.resolve())) + self.compiled_model = CompiledModel(build.model_name, str(build.executable.resolve()), str(build.executable.parent.resolve()), build.output, build.errors) self.compiled_root = SimulationRoot( format_version=1, source_document=str(self.document.path.resolve()) if self.document.path is not None else None, @@ -73,6 +78,11 @@ class SimulationController(QObject): settings=settings, ) self.window.statusBar().showMessage(f"Compiled {component_path}") + logger.info("Compiled model %s: %s", build.model_name, self.compiled_model.executable) + if build.output.strip(): + logger.info("Compiler output:\n%s", build.output.strip()) + if build.errors.strip(): + logger.warning("Compiler errors:\n%s", build.errors.strip()) return self.compiled_root def open_simulation(self) -> None: diff --git a/src/bedit_gui/controllers/simulation_file_controller.py b/src/bedit_gui/controllers/simulation_file_controller.py index 341c36f..8497716 100644 --- a/src/bedit_gui/controllers/simulation_file_controller.py +++ b/src/bedit_gui/controllers/simulation_file_controller.py @@ -49,6 +49,7 @@ class SimulationFileController(QObject): except (OSError, RuntimeError, TypeError, ValueError): logger.exception("Could not open simulation %s", file_path) raise + self._log_compilation() self._update_window() logger.info("Opened simulation: %s", file_path) @@ -151,3 +152,12 @@ class SimulationFileController(QObject): self.window.statusBar().showMessage(f"{self.root.component_path} · {compiled}") self.window.ui.actionSave_Simulation_Run.setEnabled(True) self.window.ui.actionSimulation_Options.setEnabled(True) + + def _log_compilation(self) -> None: + if self.compiled_model is None: + return + logger.info("Compiled model %s: %s", self.compiled_model.model_name, self.compiled_model.executable) + if self.compiled_model.output.strip(): + logger.info("Compiler output:\n%s", self.compiled_model.output.strip()) + if self.compiled_model.errors.strip(): + logger.warning("Compiler errors:\n%s", self.compiled_model.errors.strip()) diff --git a/src/bedit_gui/services/simulation_loader.py b/src/bedit_gui/services/simulation_loader.py index 218952e..e70da66 100644 --- a/src/bedit_gui/services/simulation_loader.py +++ b/src/bedit_gui/services/simulation_loader.py @@ -92,4 +92,4 @@ def _default_settings(component_id: ComponentID) -> Simulation: def _compile(component: Component, working_directory: Path, omc_command: str) -> CompiledModel: build = compile_component_sync(component, working_directory, omc_command=omc_command) - return CompiledModel(build.model_name, str(build.executable.resolve()), str(build.executable.parent.resolve())) + return CompiledModel(build.model_name, str(build.executable.resolve()), str(build.executable.parent.resolve()), build.output, build.errors) diff --git a/src/bedit_gui/simulation_models.py b/src/bedit_gui/simulation_models.py index d40e883..637b1f9 100644 --- a/src/bedit_gui/simulation_models.py +++ b/src/bedit_gui/simulation_models.py @@ -13,13 +13,15 @@ class CompiledModel: model_name: str executable: str working_directory: str + output: str = "" + errors: str = "" @classmethod def from_data(cls, data: Mapping[str, Any]) -> CompiledModel: - return cls(model_name=str(data["model_name"]), executable=str(data["executable"]), working_directory=str(data["working_directory"])) + return cls(model_name=str(data["model_name"]), executable=str(data["executable"]), working_directory=str(data["working_directory"]), output=str(data.get("output", "")), errors=str(data.get("errors", ""))) def to_data(self) -> dict[str, Any]: - return {"model_name": self.model_name, "executable": self.executable, "working_directory": self.working_directory} + return {"model_name": self.model_name, "executable": self.executable, "working_directory": self.working_directory, "output": self.output, "errors": self.errors} @dataclass