def gnatpp(file): """ Run gnatpp on a specific file. Nothing is done if the file is not an Ada file. """ if file.language().lower() != 'ada': GPS.Logger("GNATPP").log("Not an Ada file: %s" % file.path) return sv = GPS.Project.scenario_variables() x_args = ['-X%s=%s' % (k, v) for k, v in sv.items()] if sv else [] gnat_driver = gs_utils.get_gnat_driver_cmd() # If the GNAT driver is not found (e.g: when <target_prefix>-gnat # is not found), fallback on the native GNAT driver if not locate_exec_on_path(gnat_driver): gnat_driver = "gnat" cmd = [gnat_driver, 'pretty', '-rnb', '-P%s' % GPS.Project.root().file().path] + x_args + [file.path] p = ProcessWrapper(cmd, spawn_console='') status, output = yield p.wait_until_terminate() if status != 0: GPS.Locations.parse(output, category='gnat pretty') else: GPS.EditorBuffer.get(file, force=True, open=True)
def ensure_switches(self, cmd="", args="make -h"): prev_cmd = self.gnatCmd if cmd == "": self.gnatCmd = gs_utils.get_gnat_driver_cmd() else: self.gnatCmd = cmd if self.gnatCmd == "": self.gnatCmd = "gnat" if GPS.is_server_local("Build_Server"): if not os.path.isfile(self.gnatCmd): cmd = os_utils.locate_exec_on_path(self.gnatCmd) if cmd == "": GPS.Console("Messages").write( "Error: '%s' is not in the path.\n" % self.gnatCmd) GPS.Console("Messages").write( "Error: Could not initialize the ada_support module.\n" ) return self.gnatCmd = cmd # gnat check command changed: we reinitialize the rules list if prev_cmd != self.gnatCmd: self.__get_switches_from_help(self.gnatCmd, args) return True else: return False
def updateGnatCmd(self): self.gnatCmd = gs_utils.get_gnat_driver_cmd() if self.gnatCmd == "": self.gnatCmd = "gnat" if self.gnatCmd == "": GPS.Console("Messages").write( "Error: 'gnat' is not in the path.\n") GPS.Console("Messages").write( "Error: Could not initialize the gnatcheck module.\n")
def generate_body(as_separate, for_subprogram): """ Run gnatstub on the current Ada spec to generate a matching body file. as_separate: whether we want to generate as a separate for_subprogram: whether we want to generate for the current subprogram """ global can_update_body """ Doesn't work for now # Check gnatstub for --update-body support command = [gs_utils.get_gnat_driver_cmd(), 'stub', '--help'] if os_utils.locate_exec_on_path (command[0]): process = GPS.Process(command) output = process.get_result() can_update_body = output.find('--update-body') >= 0 """ GPS.MDI.save_all() context = GPS.current_context() file = context.file() sv = GPS.Project.scenario_variables() x_args = ['-X%s=%s' % (k, v) for k, v in sv.items()] if sv else [] command = [gs_utils.get_gnat_driver_cmd(), 'stub'] confirmation_msg = "" loc = None if for_subprogram: loc = context.location() command.append('--update-body=' + str(loc.line())) confirmation_msg = \ "Are you sure you want to update the body of %s?" % ( context.entity_name()) else: confirmation_msg = \ "Are you sure you want to generate the body of %s?" % ( file.base_name()) if as_separate: command.append('--subunits') proj = context.project() if proj: command.append('-P%s' % proj.file().path) command += x_args + [file.path, file.directory()] if GPS.MDI.yes_no_dialog(confirmation_msg): GPS.Process(command, task_manager=True, show_command=True, on_exit=OnExit(file, loc).on_exit)