def updateGnatCmd(self): target = GPS.get_target() # Use the correct GNAT driver to spawn GNATcheck. On old versions, # GNATcheck used to be prefixed by the target (i.e: # arm-eabi-gnatcheck). # This is not the case with newer versions, where there is only # one 'gnatcheck' executable: the target and runtime should be # specified via the '--target' and the '--RTS' option. if target == "": self.gnatCmd = "gnat" elif locate_exec_on_path('{}-gnatcheck'.format(target)): self.gnatCmd = '{}-gnat'.format(target) else: runtime = GPS.get_runtime() self.gnatCmd = "gnat" self.gnatArgs = ["--target=%s" % target] if runtime != "": self.gnatArgs.append("--RTS=%s" % runtime) if not locate_exec_on_path(self.gnatCmd): 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 map_file_is_supported(context): """ The filter used to know if the ld linker supports the '-map' switch. """ target = GPS.get_target() build_mode = GPS.get_build_mode() v = LD._cache.get((target, build_mode), None) if v is not None: return v if not target or target == 'native' or build_mode != 'default': return False ld_exe = target + '-ld' # Ensure that we don't even try to spawn ld if it's not in the PATH # to avoid displaying error messages in the Messages view. if not locate_exec_on_path(ld_exe): v = False else: try: process = GPS.Process([ld_exe, '--help']) output = process.get_result() v = '-map' in output except: v = False LD._cache[(target, build_mode)] = v return v
def __ensure_switches(self): prev_cmd = self.gnatCmd self.gnatCmd = gps_utils.get_gnat_driver_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() return True else: return False
def preferences_changed(self): """Called when the preferences are changed""" cmd = self.pref_cmd.get() if self.ispell_command != cmd: if self.ispell: GPS.Logger('ISPELL').log('command changed, restart process') self.kill() self.ispell_command = '' if os_utils.locate_exec_on_path(cmd.split()[0]): GPS.Logger('ISPELL').log('initialize ispell module: %s' % cmd) self.ispell_command = cmd if self.ispell_command and self.pref_type.get() == 'static': GPS.Logger("ISPELL").log('Activate static contextual menu') if self.dynamic: self.dynamic.hide() Static_Contextual(ispell=self) elif self.ispell_command and self.pref_type.get() == 'dynamic': GPS.Logger("ISPELL").log("Activate dynamic contextual menu") GPS.Contextual('spell check word').hide() # disable static menu if not self.dynamic: self.dynamic = Dynamic_Contextual(ispell=self) else: self.dynamic.show() else: if self.dynamic: self.dynamic.hide()
def __ensure_switches(self): prev_cmd = self.gnatCmd self.gnatCmd = GPS.Project.root().get_attribute_as_string("gnat", "ide") 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() return True else: return False
def discover_working_dir(file): global VOBS if not os_utils.locate_exec_on_path("cleartool"): return "" # Only query the VOBs once to not slowdown GPS if VOBS is None: # Map of tag path to VOB dir VOBS = [] p = subprocess.Popen(['cleartool', 'lsvob'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) output, error = p.communicate() status = p.wait() if status or not output: return "" else: for line in output.splitlines(): # The format is {tag} {vob dir} {public | private} tag = line.split()[0] vob_dir = line.split()[1] VOBS.append(os.path.dirname(vob_dir) + tag) cur_dir = os.path.dirname(file.path) for path in VOBS: if path in cur_dir: return path return ""
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 get_coverage_runtime_gpr_name(): """ Return the absolute path to the gnatcov instrumentation runtime project to use for the current target/runtime. """ runtime_attr = GPS.get_runtime() # Locate the directory that contains the gnatcov instrumentation # runtime projects. gnatcov_path = os_utils.locate_exec_on_path("gnatcov") gnatcov_dir = os.path.dirname(gnatcov_path) rts_dir = os.path.join(gnatcov_dir, os.pardir, "share", "gnatcoverage", "gnatcov_rts") default = os.path.join(rts_dir, "gnatcov_rts.gpr") full = os.path.join(rts_dir, "gnatcov_rts_full.gpr") # Pick the restricted profile for BB runtimes ("default"), the "full" # one otherwise (unless the full one does not exist, after the # gnatcov_rts merge): if ("ravenscar" in runtime_attr or "zfp" in runtime_attr or "light" in runtime_attr or "embedded" in runtime_attr or not os.path.exists(full)): return default else: return full
def on_project_changed(hook): # Change default build mode to "codepeer" # when GNAT is absent and build mode not set for the project if not os_utils.locate_exec_on_path("gprconfig"): root_project = GPS.Project.root() try: root_project.get_property("Build-Mode") except GPS.Exception: GPS.set_build_mode("codepeer")
def setup(self): if os_utils.locate_exec_on_path('gnatprove'): make_interactive( self.get_view, category="Views", description=("Open (or reuse if it already exists)" + " the 'GNATprove Runs' view"), menu="SPARK/Show Previous Runs", name="open gnatprove runs")
def on_project_changed(hook): # Change default build mode to "codepeer" # when GNAT is absent and build mode not set for the project gnatCmd = gps_utils.get_gnat_driver_cmd() if not os_utils.locate_exec_on_path(gnatCmd): root_project = GPS.Project.root() try: mode = root_project.get_property("Build-Mode") except GPS.Exception: GPS.set_build_mode("codepeer")
def setup(self): # This plugin makes sense only if GNATcoverage is available: # return immediately if not. if not os_utils.locate_exec_on_path("gnatfuzz"): return # These fields are set when the project is a harness project self.user_project = None # The original user project self.output_dir = None # The gnatfuzz output dir # Create the build targets GPS.parse_xml(list_to_xml(self.BUILD_TARGETS)) ref_menu = "Analyze" # Create the actions make_interactive( self.gnatfuzz_analyze_project, category="GNATfuzz", name="gnatfuzz analyze project workflow", menu="/GNATfuzz/Analyze project", before=ref_menu, ) make_interactive( self.gnatfuzz_analyze_file, category="GNATfuzz", name="gnatfuzz analyze file workflow", menu="/GNATfuzz/Analyze file", before=ref_menu, ) make_interactive( self.gnatfuzz_generate, category="GNATfuzz", name="gnatfuzz generate workflow", ) make_interactive( self.gnatfuzz_fuzz_start_stop, filter=self.is_harness_project, category="GNATfuzz", name="gnatfuzz fuzz workflow", menu="/GNATfuzz/Start\\/Stop Fuzzing Session", before=ref_menu, ) make_interactive( self.switch_to_user_project, filter=self.is_harness_project, category="GNATfuzz", name="gnatfuzz switch to user project", menu="/GNATfuzz/Switch to User Project", before=ref_menu, ) # Call the project changed hook to refresh the harness flags self.project_view_changed()
def map_file_is_supported(context): """ The filter used to know if the ld linker supports the '-map' switch. """ target = GPS.get_target() build_mode = GPS.get_build_mode() v = LD._cache.get((target, build_mode), None) if v is not None: return v if target not in LD._supported_targets: return False # Check if the project uses a GCC-based toolchain for all the # registered languages project = GPS.Project.root() languages = project.get_attribute_as_list("languages") has_gcc_toolchain = True for lang in languages: comp_driver = project.get_attribute_as_string(attribute="driver", package="compiler", index=lang) comp_command = project.get_attribute_as_string( attribute="ide", package="compiler_command", index=lang) if ("gcc" not in comp_driver or (comp_command != '' and "gcc" not in comp_command)): has_gcc_toolchain = False break if not has_gcc_toolchain: return False ld_exe = target + '-ld' # Ensure that we don't even try to spawn ld if it's not in the PATH # to avoid displaying error messages in the Messages view. if not locate_exec_on_path(ld_exe): v = False else: try: process = GPS.Process([ld_exe, '--help']) output = process.get_result() v = '-map' in output except Exception: v = False LD._cache[(target, build_mode)] = v return v
def get_coverage_runtime_project_arg(): """ Return the path of the coverage runtime bundled with the gnatcov installation. This runtime is needed to use gnatcov with instrumentation. """ gnatcov_path = os_utils.locate_exec_on_path('gnatcov') gnatcov_dir = os.path.dirname(gnatcov_path) runtime_dir = os.path.join(gnatcov_dir, os.pardir, "share", "gnatcoverage", "gnatcov_rts") return "-P" + os.path.join(runtime_dir, "gnatcov_rts_full.gpr")
def discover_working_dir(file): if os_utils.locate_exec_on_path('git'): p = GPS.Process( ["git", "--no-pager", "rev-parse", "--show-toplevel"], block_exit=False) output = p.get_result() status = p.wait() if not status and os.path.exists(output): output = os.path.realpath(output) return output else: return core.find_admin_directory(file, '.git', allow_file=True)
def use_rts_and_target_options(): """ Return True if GNATtest should be launched with the --target and --RTS options. This is only available with 22+ GNATtest versions: older GNATtest versions should be prefixed by the project's target instead (e.g: arm-eabi-gnattest) """ if locate_exec_on_path('gnattest'): major, _ = version('gnattest') return int(major) >= 22 return False
def on_gps_started (hook_name): """ Called once, when GPS is starting. """ global gnatcov_menu_separator if os_utils.locate_exec_on_path ("gnatcov") != "": GPS.Hook("compilation_finished").add(on_compilation_finished) menu = "/Tools/GNATcov/" ref = "Coverage" gnatcov_menu = GPS.Menu.create(menu + '-', ref=ref, add_before=False) GPS.parse_xml(xml.replace("@MENU@", 'menu="%s"' % menu))
def discover_working_dir(file): if os_utils.locate_exec_on_path("cleartool"): # Get the working view tag for the project file directory p = GPS.Process(['cleartool', 'pwd', '-wdv', '-short'], block_exit=False) output = p.get_result() status = p.wait() has_output = output and "** NONE **" not in output if not status and has_output: # The output format is: "{tag}@@" tag = output.split('@@')[0] # Use the tag to retrieve the Clearcase view path p = GPS.Process(['cleartool', 'lsview', '-long', tag], block_exit=False) output = p.get_result() status = p.wait() if not status and output: global_path = "" server_path = "" # The output format is: "[{name}: {value}\n]*" # And we are interested only on the value containing # path to .vws files for line in output.splitlines(): if "Global path:" in line: global_dir = os.path.dirname( line.split(": ")[1].rstrip()) global_path = os.path.join(global_dir, tag) if "View server access path:" in line: server_dir = os.path.dirname( line.split(": ")[1].rstrip()) server_path = os.path.join(server_dir, tag) has_server = server_path and os.path.exists(server_path) has_global = global_path and os.path.exists(global_path) if has_server and has_global: # Only one VCS engine can be created for a project # and at this point we can have 2 valid paths. # => Choose the one "nearer" to the project file. cur_dir = os.path.dirname(file.path) if server_path in cur_dir: return server_path else: return global_path elif has_server: return server_path elif has_global: return global_path
def display(): # Two possible ways here: older versions of GNAT still have the # gnatpsta utility, whereas for more recent versions we need to # compile a file with -gnatS. Try gnatpsta first: path = None if os_utils.locate_exec_on_path("gnatpsta") != "": sub = subprocess.Popen( ['gnatpsta'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) sub.wait() else: dir = tempfile.mkdtemp() path = dir + "/p.ads" f = open(path, "w") f.write("package p is end p;") f.close() cmdline = ['gprbuild', '-c', '-gnatc', '-gnatS', '-q'] target = GPS.Project.root().get_attribute_as_string("target") if target: cmdline.append('--target=%s' % target) runtime = GPS.Project.root().get_attribute_as_string( "runtime", index="Ada") if runtime: cmdline.append('--RTS=%s' % runtime) cmdline.append('p.ads') sub = subprocess.Popen( cmdline, cwd=dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) sub.wait() shutil.rmtree(dir) # We do not create the file on the disk, because: # - we cannot create a temporay file and delete it immediately, since # GPS will then display the dialog that the file has changed on disk. # - we cannot create the file in the project's object_dir, since the # latter might not exist, or worse could also be a source_dir which # would confuse the compiler. buffer = EditorBuffer.get_new() buffer.delete() # delete any text inserted via templates buffer.insert(buffer.at(1, 1), sub.stdout.read()) buffer.set_lang('ada') buffer.current_view().set_read_only(True) MDI.get_by_child(buffer.current_view()).rename('package Standard')
def _populate_menu(self): """ Populate the Help menu with the GNAT examples """ # For now, we look for the location of "gnat" from the PATH. # TODO: get the path from toolchains, if any (this requires # exposing the toolchains API to Python, or providing another # high-level service). # Create the native examples menu, if any if "gnat" not in self.menus_created_for_compiler: self.menus_created_for_compiler.append("gnat") gnat = os_utils.locate_exec_on_path("gnat") examples_root = os.path.join(os.path.dirname(gnat), "..", "share", "examples", "gnat") self._process_examples_dir("Native", examples_root)
def get_no_subprojects_arg(): """ Return --no-subprojects argument when supported, empty string otherwise (older gnatpp versions). """ target = GPS.get_target() if os_utils.locate_exec_on_path(target + "-gnatmetric"): exe = target + "-gnatmetric" else: exe = "gnatmetric" help_output = GPS.Process(exe + " --help").get_result() if "--no-subprojects" in help_output: return "--no-subprojects" else: return ""
def _populate_menu(self): """ Populate the Help menu with the GNAT examples """ # For now, we look for the location of "gnat" from the PATH. # TODO: get the path from toolchains, if any (this requires # exposing the toolchains API to Python, or providing another # high-level service). # Create the native examples menu, if any if "gnat" not in self.menus_created_for_compiler: self.menus_created_for_compiler.append("gnat") gnat = os_utils.locate_exec_on_path("gnat") examples_root = os.path.join( os.path.dirname(gnat), "..", "share", "examples", "gnat" ) self._process_examples_dir("Native", examples_root)
def _populate_menu(self): """ Populate the Help menu for the AdaCore tools """ help_actions = [] for exec_name in _DOC_ENTRIES.keys(): executable = exec_name if exec_name == 'gnatls' and GPS.get_target(): executable = '{}-gnatls'.format(GPS.get_target()) ex = os_utils.locate_exec_on_path(executable) if ex: for descr, tup in _DOC_ENTRIES[exec_name].iteritems(): html_files, menu_base = tup menu_path = menu_base + '/' + descr action_descr = 'display documentation {}'.format(descr) # Do not create a menu if the action already exists if GPS.Action(action_descr).exists(): continue # As a convenience, html_files can either be a string or a # list of strings. Deal with this here. if type(html_files) != list: html_files = [html_files] for file in html_files: path = os.path.realpath( os.path.join(os.path.dirname(ex), '..', 'share', 'doc', file) ) if os.path.isfile(path): action = HTMLAction(action_descr, path, '/Help/{}'.format(menu_path)) help_actions.append(action) break help_actions.sort(key=lambda x: x.menu_path) for a in help_actions: a.menu(a.menu_path, ref='About', add_before=False)
def gps_started(self): """ Initializations done after the gps_started hook """ # This action requires pydoc if os_utils.locate_exec_on_path('pydoc'): gs_utils.make_interactive(callback=self.show_python_library, name='display python library help') gs_utils.make_interactive(callback=self.reload_file, name='reload python file', filter='Python file', contextual='Python/Import & Reload') gs_utils.make_interactive(callback=self.indent_on_new_line, name="Python Auto Indentation", filter='Python edition') self.pydoc_proc = None GPS.Hook("project_view_changed").add(self._project_recomputed) GPS.Hook("before_exit_action_hook").add(self._before_exit)
def display(): # Two possible ways here: older versions of GNAT still have the # gnatpsta utility, whereas for more recent versions we need to # compile a file with -gnatS. Try gnatpsta first: path = None if os_utils.locate_exec_on_path("gnatpsta") != "": GPS.Process(['gnatpsta'], on_exit=on_exit) else: # We do not create the file on the disk, because: - we cannot create a # temporary file and delete it immediately, since GPS will then display # the dialog that the file has changed on disk. - we cannot create the # file in the project's object_dir, since the latter might not exist, # or worse could also be a source_dir which would confuse the compiler. global tmp_dir tmp_dir = tempfile.mkdtemp() path = tmp_dir + "/p.ads" f = open(path, "w") f.write("package p is end p;") f.close() cmdline = ['gprbuild', '-c', '-gnatc', '-gnatS', '-q'] target = GPS.Project.root().get_attribute_as_string("target") if target: cmdline.append('--target=%s' % target) runtime = GPS.Project.root().get_attribute_as_string("runtime", index="Ada") if runtime: cmdline.append('--RTS=%s' % runtime) cmdline.append('p.ads') GPS.Process(cmdline, directory=tmp_dir, on_exit=on_exit)
def run(self): # find gnatpp - first, if we're working on the gnatpp project, # use it! GPS.Console().clear() gnatpp = os.path.join( GPS.Project.root().exec_dir(), "gnatpp" + ("" if "linux" in sys.platform else ".exe"), ) if not os.path.exists(gnatpp): gnatpp = os_utils.locate_exec_on_path("gnatpp") # Create the contents of the temp dir for f in (self.ada_file, self.template_file): base = os.path.basename(f) tmpfile = os.path.join(self.tmp_dir, base) b = GPS.EditorBuffer.get(GPS.File(f)) with open(tmpfile, "w") as tmp: tmp.write(b.get_chars()) # Run gnatpp tmp_templates = os.path.join(self.tmp_dir, os.path.basename(self.template_file)) tmp_ada_file = os.path.join(self.tmp_dir, os.path.basename(self.ada_file)) cmdline = [ gnatpp, "--templates={}".format(tmp_templates), tmp_ada_file, "--pipe" ] GPS.Process( cmdline, on_exit=self.on_exit, ) # Print the command line on the console GPS.Console().write("{}\n".format(" ".join(cmdline)))
"""This file is the main driver for the spark.py plug-in. """ import os, os.path, sys import GPS, os_utils spark_exe = os_utils.locate_exec_on_path ("spark") if spark_exe != "": spark_plugins = os.path.dirname(spark_exe)+"/../share/gps/plug-ins" if os.path.isfile(spark_plugins+"/spark.py"): sys.path=[spark_plugins]+sys.path else: sys.path=[GPS.get_system_dir()+'share/gps/plug-ins/spark']+sys.path import spark
This file provides support for using the gnatdist/po_gnatdist tool gnatdist/po_gnatdist is a partitioning tool for distributed applications which use features of the Distrbiuted System Annex. This package provides syntax highlighting for partition configuration language, and allows to run tool from GPS. """ import os_utils import GPS # First, try to find gnatdist/po_gnatdist executable. po_gnatdist have # preference over gnatdist gnatdist_tool = os_utils.locate_exec_on_path("po_gnatdist") if gnatdist_tool == "": gnatdist_tool = os_utils.locate_exec_on_path("gnatdist") # If gnatdist/po_gnatdist tool was found, enable its support in GPS if gnatdist_tool != "": GPS.parse_xml (""" <Language> <Name>gnatdist</Name> <Parent>Ada</Parent> <Spec_Suffix>.cfg</Spec_Suffix> <Keywords>^((c(onfiguration|hannel)|begin|use|i(s|n)|f(or|unction)|with|end|return|pr(ocedure|agma))\\b|partition(;|\s+))</Keywords> <Context> <New_Line_Comment_Start>--</New_Line_Comment_Start> <String_Delimiter>"</String_Delimiter>
def on_pref_changed (h): global ispell_command, background_color, contextual_menu_type global ispell, static, dynamic ispell_command = GPS.Preference ("Plugins/ispell/cmd").get() background_color = GPS.Preference ("Plugins/ispell/bgcolor").get() contextual_menu_type = GPS.Preference ("Plugins/ispell/menutype").get() # Activate the module if the ispell command is available. If the user # changes it to something invalid, we cannot hide everything, so we keep # the menus if not ispell \ and os_utils.locate_exec_on_path (ispell_command.split()[0]) != "": GPS.Logger ("ISPELL").log ("initialize ispell module " + ispell_command) GPS.Hook ("before_exit_action_hook").add (before_exit) ispell = Ispell() GPS.parse_xml (""" <action name="spell check comments" category="Editor" output="none"> <description>Check the spelling for all comments in the current editor</description> <filter id="Source editor"/> <shell lang="python">ispell.SpellCheckBuffer ("comment")</shell> </action> <action name="spell check editor" category="Editor" output="none"> <description>Check the spelling for the whole contents of the editor</description> <filter id="Source editor" /> <shell lang="python">ispell.SpellCheckBuffer ("")</shell> </action> <action name="spell check selection" category="Editor" output="none"> <description>Check the spelling in the current selection</description> <filter id="Source editor" /> <shell lang="python">ispell.SpellCheckBuffer ("selection")</shell> </action> <action name="spell check word" category="Editor" output="none"> <description>Check the spelling of the current word</description> <filter id="Source editor" /> <shell lang="python">ispell.SpellCheckBuffer ("word")</shell> </action> <submenu after="Selection"> <title>/Edit/Spe_ll Check</title> <menu action="spell check comments"> <title>Comments</title> </menu> <menu action="spell check editor"> <title>Editor</title> </menu> <menu action="spell check selection"> <title>Selection</title> </menu> <menu action="spell check word"> <title>Word</title> </menu> </submenu>""") # Update the command if ispell and ispell_command != ispell.cmd: GPS.Logger ("ISPELL").log ("command changed, restart process") ispell.kill() ispell = Ispell() # Activate the right kind of contextual menu if ispell: if contextual_menu_type == "static": GPS.Logger ("ISPELL").log ("Activate static contextual menu") if dynamic: dynamic.hide() if not static: static = Static_Contextual() else: static.show() elif contextual_menu_type == "dynamic": GPS.Logger ("ISPELL").log ("Activate dynamic contextual menu") if static: static.hide() if not dynamic: dynamic = Dynamic_Contextual() else: dynamic.show() else: if static: static.hide() if dynamic: dynamic.hide()
########################################################################### # No user customization below this line ########################################################################### import os.path import GPS from extensions.private.xml import X import os_utils def list_to_xml(items): return '\n'.join(str(i) for i in items) gnatcov_path = os_utils.locate_exec_on_path('gnatcov') gnatcov_install_dir = ( os.path.join(os.path.dirname(gnatcov_path), '..') if gnatcov_path else None ) class GNATcovPlugin(object): PLUGIN_MENU = '/Tools/GNATcov/' # Keep this style name synchronized with Code_Coverage.GNATcov. PROJECT_ATTRIBUTES = [ X(
import os_utils import re import tempfile import workflows.promises as promises import workflows PLUGIN_MENU = '/Analyze/Coverage/GNATcoverage' TOOL_VERSION_REGEXP = re.compile("[a-zA-Z\s]+ ([0-9]*)\.?([0-9]*w?)") def list_to_xml(items): return '\n'.join(str(i) for i in items) gnatcov_path = os_utils.locate_exec_on_path('gnatcov') gnatcov_install_dir = (os.path.join(os.path.dirname(gnatcov_path), '..') if gnatcov_path else None) class GNATcovPlugin(Module): # Keep this style name synchronized with Code_Coverage.GNATcov. PROJECT_ATTRIBUTES = [ X( 'project_attribute', package='IDE_Coverage', name='Gnatcov_Mode_Switches', label="Switches in 'gnatcov' mode", description=("Extra build switches to pass to the builder when in"
def gnatemu_on_path(self): bin = self.get_gnatemu_name() gnatemu = locate_exec_on_path(bin) return gnatemu != ''
proc.file = file proc.gg_json = gg_json elif not os.path.isfile(gg_json): _log("Aborting operation: Can't find %s." % gg_json) return else: edit_file(file, gg_json) _log("Completed generating globals.", mode="text") ################################# # Register the contextual menus # ################################# # Only register if gnatprove is on the path if os_utils.locate_exec_on_path("gnatprove"): @interactive("Ada", in_ada_file, contextual="SPARK/Globals/Show generated Globals", name="Show generated Globals", contextual_group=GPS.Contextual.Group.EXTRA_INFORMATION) def show_globals(): """ Add special lines showing the global contracts. """ show_generated_globals() @interactive("Ada", in_ada_file, contextual="SPARK/Globals/Hide generated Globals", name="Hide generated Globals", contextual_group=GPS.Contextual.Group.EXTRA_INFORMATION)
<string type=""/> </project_attribute> <project_attribute name="Switches" package="Make" editor_page="Make" editor_section="Make" hide_in="wizard library_wizard properties"> <string type=""/> </project_attribute>""") # This module needs to be initialized before the others Hook ("gps_started").add (on_gps_started, False) if os_utils.locate_exec_on_path ("ant"): try: from xml.sax import handler, make_parser ant_support=True parse_xml (""" <project_attribute name="Antfile" package="Ant" editor_page="Ant" editor_section="Ant" hide_in="wizard library_wizard" description="Ant build file to use for this project"> <string type="file"/> </project_attribute> <project_attribute name="Ant"
</target> </GPS> """ # Template to insert into target-model for each gnathub plugin template = r"""<check line="1" column="1" label="{}" switch="--plugins={}" tip="Run {} plugin"/> """ # Check for gnathub executable and GNAThub module active status: logger = GPS.Logger("MODULE.GNAThub") if os_utils.locate_exec_on_path("gnathub") and logger.active: checkboxes = reduce(lambda x, y: x+template.format(y, y, y), tools, "") GPS.parse_xml(XML.format(checkboxes)) @gps_utils.interactive(category="Gnathub", menu=gnathub_menu+"Run...", name="Run gnathub...") def show_dialog_and_run_gnathub(): target = GPS.BuildTarget("gnathub") target.execute(synchronous=False) @gps_utils.hook("compilation_finished") def __hook(category, target_name="", mode_name="", status=""): if not status and target_name == "gnathub": GPS.execute_action("gnathub display analysis")
"""This file provides support for gnatstack (static stack usage). """ ############################################################################ ## No user customization below this line ############################################################################ import GPS, os_utils, os.path tool = os_utils.locate_exec_on_path("gnatstack") if tool != "": GPS.parse_xml (""" <!-- Support for running GNATStack as a build target --> <target-model name="gnatstack" category=""> <description>Run GNATStack for analysis</description> <command-line> <arg>gnat</arg> <arg>stack</arg> <arg>-pi</arg> <arg>-Q</arg> <arg>-x</arg> <arg>-Wa</arg> <arg>-P%PP</arg> </command-line> <switches> </switches> </target-model>
<arg>%X</arg> </command-line> </target> <target model="codepeer" category="CodePeer" name="Regenerate CodePeer Report" messages_category="CodePeer"> <in-toolbar>FALSE</in-toolbar> <in-menu>FALSE</in-menu> <icon>gps-build-all</icon> <launch-mode>MANUALLY_WITH_DIALOG</launch-mode> <read-only>TRUE</read-only> <command-line> <arg>codepeer</arg> <arg>-output-only</arg> <arg>-P%PP</arg> <arg>%X</arg> </command-line> </target> </CODEPEER> """ # Check for GNAT toolchain: codepeer, gps_codepeer_bridge codepeer = os_utils.locate_exec_on_path("codepeer") if codepeer: example_root=os.path.dirname (os.path.dirname(codepeer)).replace('\\', '/')+\ '/share/examples/codepeer' xml_codepeer = xml_codepeer.replace('@EXAMPLE@', example_root) GPS.parse_xml(xml_codepeer)
def is_gnatcov_available(self): return os_utils.locate_exec_on_path('gnatcov') != ""
def on_project_changed(hook): # Change default build mode to "codepeer" # when GNAT is absent and build mode not set for the project if not os_utils.locate_exec_on_path("gprconfig"): root_project = GPS.Project.root() try: root_project.get_property("Build-Mode") except GPS.Exception: GPS.set_build_mode("codepeer") # Check for GNAT toolchain: codepeer, gps_codepeer_bridge codepeer = os_utils.locate_exec_on_path("codepeer") if codepeer: root = os.path.dirname(os.path.dirname(codepeer)).replace('\\', '/') example_root = root + '/share/examples/codepeer' try: with open(root + '/share/doc/codepeer/help.txt', 'r') as help_file: help_msg = escape(help_file.read()) except Exception: help_msg = '' xml_codepeer = xml_codepeer.format(example=example_root, root=root, help=help_msg) xmlHead = xmlHead.format(help=help_msg) GPS.parse_xml(xml_codepeer)
def gnatemu_on_path(): bin = GNATemulator.get_gnatemu_name() gnatemu = locate_exec_on_path(bin) return gnatemu != ''
prefix = "Prove" menu_prefix = "/" + prefix prove_all = "Prove All" prove_root_project = "Prove Root Project" prove_file = "Prove File" prove_line = "Prove Line" prove_subp = "Prove Subprogram" show_unprovable_code = "Show Unprovable Code" clean_up = "Clean Proofs" show_path = "Show Path" trace_category = "gnatprove_trace" # Check for GNAT toolchain: gnatprove gnatprove = os_utils.locate_exec_on_path("gnatprove") # This is the context of a subprogram declaration if there is a subprogram, # there is a corresponding declaration, and their file:line locations match. def is_subp_decl_context(self): if isinstance (self, GPS.EntityContext) and \ self.entity() and \ self.entity().category() == "subprogram" and \ self.entity().declaration() and \ self.location().file() == self.entity().declaration().file() and \ self.location().line() == self.entity().declaration().line(): return True else: return False # This is the context of a subprogram body if there is a subprogram, there is a