AdaCore / gnatstudio

GNAT Studio is a powerful and lightweight IDE for Ada and SPARK.
399 stars 52 forks source link

GPS.Process on_exit callback $3 parameter is erroneous #143

Open dsauvage opened 1 year ago

dsauvage commented 1 year ago

GPS.Process on_exit callback $3 parameter is erroneous

Environment:

Debian GNU/Linux 10 X86_64 GNAT Studio 23.0w (20220512)

Bug Description:

When using GPS.Process and its on_exit callback in GNAT Studio plugins [1];

A. When no regexp is used, and on_match is set to None [2]

The issue is that the third parameter given to the on_exit callback contains twice all the output since the process has been launched.

B. When regexp is used, and on_match is set [3]

The issue is that the third parameter given to the on_exit callback contains all the output since the process has been launched, and not only "the output of the process since the last call to on match()", as specified in the documentation.

When different regexp is used, i.e regexp='^[\x20-\x7E]', this issue can occurs randomly

[1] https://docs.adacore.com/live/wave/gps/html/gps_ug/GPS.html#gps-process on_exit is a subprogram called when the process has exited. You can no longer send input to it at this stage. Its parameters are:

$1 = the instance of GPS.Process

$2 = the exit status

$3 = the output of the process since the last call to on_match()

[2] proc = backend.process(command=command,regexp='',on_match=None, before_kill=on_kill, remote_server="Execution_Server", on_exit=on_exit, strip_cr=False, progress_regexp="^ *completed (\d*) out of (\d*)")

[3] proc = GPS.Process(command=command,regexp='.+',on_match=on_match, before_kill=on_kill, remote_server="Execution_Server", on_exit=on_exit, strip_cr=False, progress_regexp="^ *completed (\d*)

AdrienBoulanger commented 1 year ago

Hi @dsauvage, I can't reproduce the behavior with the following basic plugin:

import GPS
from gs_utils import interactive

# Create a contextual action starting gprbuild and show the output when
# stopping the process in the TEST console
@interactive(contextual="Test/launch command",
             name="test on exit")
def align_colons():
    def on_exit(p, status, out):
        GPS.Console("TEST").write("Process finished with: %i\n" % status)
        GPS.Console("TEST").write("Remaining output:\n %s\n" % out)

    def on_kill(p, out):
        GPS.Console("TEST").write("Before kill:\n %s\n" % out)

    command = ["gprbuild", "-d", "-Ptest.gpr", "-f"]
    proc = GPS.Process(command=command,
                       regexp="",
                       on_match=None,
                       before_kill=on_kill,
                       on_exit=on_exit,
                       strip_cr=False,
                       progress_regexp="^ *completed (\d*) out of (\d*).*$")
    proc.wait()
    GPS.Console("TEST").write("\n")

No duplication in stdout when regexp is not set. I tested it with both the current wavefront and 20220512 Can you share your plugin and the command?

dsauvage commented 1 year ago

Hi @AdrienBoulanger, thanks for your feedback, we will evaluate making a reduced reproducer.