public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/gcov-proper-exit-code)] gcov: return proper exit code when error happens Date: Mon, 18 Oct 2021 09:32:22 +0000 (GMT) [thread overview] Message-ID: <20211018093222.6398E3858400@sourceware.org> (raw) https://gcc.gnu.org/g:ff180fbff7141f8cae67ed829ad57c597e719062 commit ff180fbff7141f8cae67ed829ad57c597e719062 Author: Martin Liska <mliska@suse.cz> Date: Mon Oct 18 11:30:55 2021 +0200 gcov: return proper exit code when error happens PR gcov-profile/102746 PR gcov-profile/102747 gcc/ChangeLog: * gcov.c (main): Return return_code. (output_gcov_file): Mark return_code when error happens. (generate_results): Likewise. (read_graph_file): Likewise. (read_count_file): Likewise. Diff: --- gcc/gcov.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/gcc/gcov.c b/gcc/gcov.c index 3672ae7a6f8..34f53ac2d78 100644 --- a/gcc/gcov.c +++ b/gcc/gcov.c @@ -638,6 +638,9 @@ static int flag_preserve_paths = 0; static int flag_counts = 0; +/* Return code of the tool invocation. */ +static int return_code = 0; + /* Forward declarations. */ static int process_args (int, char **); static void print_usage (int) ATTRIBUTE_NORETURN; @@ -907,7 +910,7 @@ main (int argc, char **argv) if (!flag_use_stdout) executed_summary (total_lines, total_executed); - return 0; + return return_code; } \f /* Print a usage message and exit. If ERROR_P is nonzero, this is an error, @@ -1467,12 +1470,18 @@ output_gcov_file (const char *file_name, source_info *src) fnotice (stdout, "Creating '%s'\n", gcov_file_name); output_lines (gcov_file, src); if (ferror (gcov_file)) - fnotice (stderr, "Error writing output file '%s'\n", - gcov_file_name); + { + fnotice (stderr, "Error writing output file '%s'\n", + gcov_file_name); + return_code = 6; + } fclose (gcov_file); } else - fnotice (stderr, "Could not open output file '%s'\n", gcov_file_name); + { + fnotice (stderr, "Could not open output file '%s'\n", gcov_file_name); + return_code = 6; + } } else { @@ -1594,6 +1603,7 @@ generate_results (const char *file_name) { fnotice (stderr, "Cannot open JSON output file %s\n", gcov_intermediate_filename.c_str ()); + return_code = 6; return; } @@ -1602,6 +1612,7 @@ generate_results (const char *file_name) { fnotice (stderr, "Error writing JSON output file %s\n", gcov_intermediate_filename.c_str ()); + return_code = 6; return; } } @@ -1790,12 +1801,14 @@ read_graph_file (void) if (!gcov_open (bbg_file_name, 1)) { fnotice (stderr, "%s:cannot open notes file\n", bbg_file_name); + return_code = 1; return; } bbg_file_time = gcov_time (); if (!gcov_magic (gcov_read_unsigned (), GCOV_NOTE_MAGIC)) { fnotice (stderr, "%s:not a gcov notes file\n", bbg_file_name); + return_code = 2; gcov_close (); return; } @@ -1810,6 +1823,7 @@ read_graph_file (void) fnotice (stderr, "%s:version '%.4s', prefer '%.4s'\n", bbg_file_name, v, e); + return_code = 3; } bbg_stamp = gcov_read_unsigned (); /* Read checksum. */ @@ -1977,6 +1991,7 @@ read_graph_file (void) { corrupt:; fnotice (stderr, "%s:corrupted\n", bbg_file_name); + return_code = 4; break; } } @@ -2009,6 +2024,7 @@ read_count_file (void) if (!gcov_magic (gcov_read_unsigned (), GCOV_DATA_MAGIC)) { fnotice (stderr, "%s:not a gcov data file\n", da_file_name); + return_code = 2; cleanup:; gcov_close (); return 1; @@ -2023,11 +2039,13 @@ read_count_file (void) fnotice (stderr, "%s:version '%.4s', prefer version '%.4s'\n", da_file_name, v, e); + return_code = 3; } tag = gcov_read_unsigned (); if (tag != bbg_stamp) { fnotice (stderr, "%s:stamp mismatch with notes file\n", da_file_name); + return_code = 5; goto cleanup; } @@ -2088,6 +2106,7 @@ read_count_file (void) ? N_("%s:overflowed\n") : N_("%s:corrupted\n"), da_file_name); + return_code = 4; goto cleanup; } }
reply other threads:[~2021-10-18 9:32 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211018093222.6398E3858400@sourceware.org \ --to=marxin@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).