Skip to content

Commit 0971b01

Browse files
Add new GPS.Project.get_executable_file function
To handle the case where the root project extends another project, defining a new exec directory without defining a new main file. We always want to compute the executable's path from a project's exec directory. Deprecate the GPS.File.executable_path property, since it can't handle complex cases involving extended projects: its usage has been replaced by the API instead. Fixes eng/shared/integration-testsuite#15
1 parent 0a20dfd commit 0971b01

File tree

6 files changed

+54
-9
lines changed

6 files changed

+54
-9
lines changed

docs/users_guide/GPS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,8 @@ Classes
18141814

18151815
.. automethod:: GPS.Project.get_config
18161816

1817+
.. automethod:: GPS.Project.get_executable_file
1818+
18171819
.. automethod:: GPS.Project.get_executable_name
18181820

18191821
.. automethod:: GPS.Project.get_extended_project

docs/users_guide/GPS/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5982,6 +5982,12 @@ class File(object):
59825982

59835983
executable_path = None
59845984
"""
5985+
OBSOLESCENT.
5986+
5987+
This property is deprecated since it does not handle extended projects
5988+
properly. Please use the :func:`GPS.Project.get_executable_file`
5989+
function instead.
5990+
59855991
Return a :class:`File` instance of the executable associated with this
59865992
file.
59875993
@@ -9055,6 +9061,16 @@ def get_executable_name(self, main):
90559061
"""
90569062
pass # implemented in Ada
90579063

9064+
def get_executable_file(self, main):
9065+
"""
9066+
Returns the executable file computed from `main`.
9067+
This handles extended projects as well.
9068+
9069+
:param GPS.File main: the main source file
9070+
:return: An instance of :class:`GPS.Project`
9071+
"""
9072+
pass # implemented via a Python extension
9073+
90589074
def get_extended_project(self):
90599075
"""
90609076
Return the project extended by project.

share/support/core/projects.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212

1313
import GPS
14+
import extensions
15+
import os.path
1416

1517
XML = r"""<?xml version="1.0" ?>
1618
<GNAT_Studio>
@@ -513,3 +515,25 @@
513515
"""
514516

515517
GPS.parse_xml(XML)
518+
519+
520+
"""
521+
Extension of the GPS.Project class.
522+
523+
Used to provide small helpers on top of existing functions
524+
implemented in Ada.
525+
"""
526+
@extensions.extend_module(GPS)
527+
class Project:
528+
def get_executable_file(self, main):
529+
"""
530+
Returns the executable file computed from `main`.
531+
This handles extended projects as well.
532+
533+
:param GPS.File main: the main source file
534+
:return: An instance of :class:`GPS.Project`
535+
"""
536+
exe_name = self.get_executable_name(main)
537+
exec_dir = self.exec_dir()
538+
exec_file = GPS.File(os.path.join(exec_dir, exe_name))
539+
return exec_file

share/support/ui/board_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ def __flash_wf(self, main_name):
497497
return
498498

499499
# Get the executable path
500-
exe = GPS.File(main_name).executable_path.path
500+
exe = GPS.Project.root().get_executable_file(GPS.File(main_name)).path
501501

502502
# Retrieve the load address of the executable with objdump
503503
self.__display_message("Retrieving the load address.")

share/support/ui/gnatcov.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ def run_gnatcov_wf(self, main_name):
797797
return
798798

799799
# Get the executable to analyze
800-
exe = str(GPS.File(main_name).executable_path)
800+
exe = GPS.Project.root().get_executable_file(GPS.File(main_name)).path
801801

802802
# Run GNATcov on it
803803
p = promises.TargetWrapper("Run under GNATcov")
@@ -910,7 +910,7 @@ def run_gnatcov_with_instrumentation_wf(self, main_name):
910910
GNATcovPlugin.check_for_defined_level(cmds=["instrument", "coverage"])
911911

912912
# Get the executable to analyze
913-
exe = str(GPS.File(main_name).executable_path)
913+
exe = GPS.Project.root().get_executable_file(GPS.File(main_name)).path
914914

915915
# Don't build/install the GNATcov runtime if a prebuilt one has been
916916
# specified.

share/support/ui/gnatemulator.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from modules import Module
1212
import workflows.promises as promises
1313
import workflows
14+
import os.path
1415
from os_utils import locate_exec_on_path
1516
from gs_utils.console_process import Console_Process
1617

@@ -224,11 +225,11 @@ def build_and_run(main_name, in_console=True):
224225
except RuntimeError:
225226
return
226227

227-
# Get the name of the generated binary
228-
bin_name = GPS.File(main_name).executable_path.path
228+
# Get the path of the generated binary, computing it from the root project.
229+
exec_file = GPS.Project.root().get_executable_file(GPS.File(main_name))
229230

230231
# STEP 2 launch with Emulator
231-
yield GNATemulator.run_gnatemu([bin_name], in_console)
232+
yield GNATemulator.run_gnatemu([exec_file.path], in_console)
232233

233234
@staticmethod
234235
def build_and_debug(main_name):
@@ -249,7 +250,9 @@ def build_and_debug(main_name):
249250
# Build error, we stop there
250251
return
251252

252-
binary = GPS.File(main_name).executable_path.path
253+
# Get the executable path
254+
exe = GPS.Project.root().get_executable_file(GPS.File(main_name)).path
255+
253256
# STEP 2 Switch to the "Debug" perspective To have GNATemu console in
254257
# the debugger perspective.
255258

@@ -266,14 +269,14 @@ def build_and_debug(main_name):
266269

267270
yield GNATemulator.run_gnatemu(["--freeze-on-startup",
268271
"--gdb=%s" % debug_port,
269-
binary])
272+
exe])
270273

271274
log("... done.")
272275

273276
# STEP 3 launch the debugger
274277
try:
275278
debugger_promise = promises.DebuggerWrapper(
276-
GPS.File(binary),
279+
GPS.File(exe),
277280
remote_target="localhost:" + debug_port,
278281
remote_protocol="remote")
279282
except Exception:

0 commit comments

Comments
 (0)