/usr/share/gps/plug-ins/gcov.py is in gnat-gps-common 5.0-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | """ Provides the "Tools/Gcov/Compute coverage files" and "Remove coverage files"
menus, which executes gcov automatically.
This script will also perform checks along the way to guide through the
procedure of obtaining gcov info.
The output of the gcov process is displayed in a separate console.
At the end of the processing, the open editors are decorated with coverage
information.
Note that GPS calls gcov so that the .gcov files are generated
- in the directory pointed to by the "GCOV_ROOT" environment variable, or
- in the object directory of the root project, if this variable is not set
"""
###########################################################################
## No user customization below this line
###########################################################################
import GPS, os
from GPS import *
from os import *
# A class to display the output of gcov in a separate console.
class Gcov_Process (GPS.Console, GPS.Process):
def on_output (self, unmatched, matched):
self.write (unmatched + matched)
def on_exit (self, status, remaining_output):
self.write (remaining_output)
if status == 0:
self.write ("process terminated successfully")
else:
self.write ("process terminated [" + str(status) + "]")
# Show coverage report
analysis = CodeAnalysis.get ("Coverage")
analysis.add_all_gcov_project_info()
analysis.show_analysis_report()
self.kill()
def on_input (self, input):
self.send (input)
def on_destroy (self):
self.kill ()
def __init__ (self, process, args=""):
GPS.Console.__init__ \
(self, "Executing gcov", \
on_input=Gcov_Process.on_input, \
on_destroy=Gcov_Process.on_destroy, \
force=True)
GPS.Process.__init__ \
(self, process + ' ' + args, ".+", \
remote_server="Build_Server", \
on_exit=Gcov_Process.on_exit, \
on_match=Gcov_Process.on_output)
# Actual menu implementation
def run_gcov(menu):
# Verify that the version of gcov is recent enough to support response
# files and reading of .gc?? data in multiple directories.
try:
p = Process ("gcov --version")
out = p.get_result()
paren = out.find ("(", out.find ("GNAT"))
date = int (out[paren+1:paren+9])
if date < 20071005:
MDI.dialog ("Your version of gcov is dated " + str (date) +
".\nThis plug-in requires gcov for GNAT dated 20071005 or later.")
return;
except:
MDI.dialog ("""Could not read gcov version number.
Make sure you are using gcov for GNAT dated 20071005 or later.""")
# Determine the root project
root_project = Project.root()
previous_dir = pwd()
# Determine where to create the gcov info
GCOV_ROOT = getenv ("GCOV_ROOT")
if GCOV_ROOT == None or GCOV_ROOT == "":
root_object_dirs = root_project.object_dirs (False)
if not root_object_dirs:
MDI.dialog ("""The root project does not have an object directory.
Please add one, or set the enviroment variable GCOV_ROOT to
the directory where you would like the gcov files to be
generated.""")
return
else:
gcov_dir = root_object_dirs [0]
else:
gcov_dir = GCOV_ROOT
if not access (gcov_dir, R_OK and W_OK):
MDI.dialog (""" Could not access the directory:
""" + gcov_dir + """
Please point the environment variable GCOV_ROOT to a directory
on which you have permission to read and write.
""")
cd (gcov_dir)
# List all the projects
projects = root_project.dependencies(True)
# Write the response file
res=file("gcov_input.txt", 'wb')
gcda_file_found = False
gcno_file_found = False
for p in projects:
if p.object_dirs (False) == []:
object_dir = None
else:
object_dir = p.object_dirs(False)[0]
if object_dir != None and object_dir != "":
sources = p.sources(False)
for s in sources:
n = s.name()
basename=n[max(n.rfind('\\'), n.rfind('/'))+1:len(n)]
unit=basename[0:basename.rfind('.')]
gcda = object_dir + sep + unit + ".gcda"
# If we have not yet found at least one .gcno file, attempt to
# find one. This is to improve the precision of error messages,
# and detect the case where compilation was successful but the
# executable has never been run.
if not gcno_file_found:
gcno = object_dir + sep + unit + ".gcno"
if access (gcno, F_OK):
gcno_file_found = True
if access (gcda, F_OK):
gcda_file_found = True
# Write one entry in response file
# Escape all backslashes.
gcda = gcda.replace('\\', '\\\\')
res.write ('"' + gcda + '"' +"\n")
res.close()
if not gcno_file_found:
# No gcno file was found: display an appropriate message.
MDI.dialog (""" No ".gcno" file was found in any of the object directories.
Make sure you have compiled the sources of interest with
the "Code coverage" flags.""")
else:
if not gcda_file_found:
# Some gcno files were found, but no gcna files.
MDI.dialog (""" No ".gcda" file was found in any of the object directories.
Make sure you have run the executable(s) at least once.
""")
else:
# Run gcov
Gcov_Process ("gcov", "@gcov_input.txt")
cd (previous_dir)
def remove_gcov(menu):
if not MDI.yes_no_dialog (
"This will remove all .gcov and .gcda files, are you sure ?"):
return
# Look in all the projects
for p in Project.root().dependencies(True):
object_dirs = p.object_dirs(False)
if len (object_dirs) > 0:
object_dir = object_dirs [0]
# Browse in the object dirs
for f in listdir (object_dir):
# if f is a .gcda or a .gcov, remove it
if f.find (".gcda") != -1 or f.find (".gcov") != -1:
remove (object_dir + sep + f)
def on_preferences_changed(name):
global compute_menu
global cleanup_menu
toolchain = GPS.Preference("Coverage-Toolchain").get()
if toolchain == "Gcov":
compute_menu.show()
cleanup_menu.show()
else:
compute_menu.hide()
cleanup_menu.hide()
def on_gps_started (hook):
global compute_menu
global cleanup_menu
# Create menu items
compute_menu = Menu.create ("/Tools/Covera_ge/_Gcov/Compute coverage files",
on_activate=run_gcov,
ref="Show report",
add_before=True)
cleanup_menu = Menu.create ("/Tools/Covera_ge/_Gcov/Remove coverage files",
on_activate=remove_gcov,
ref="Show report",
add_before=True)
Menu.create ("/Tools/Covera_ge/-",
ref="Gcov",
add_before=False)
# Register preference change hook and run it for setup menu items' names.
GPS.Hook ("preferences_changed").add (on_preferences_changed)
on_preferences_changed("preferences_changed")
# Register GPS startup hook.
GPS.Hook ("gps_started").add (on_gps_started)
|