From patchwork Fri Nov 26 11:06:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 48180 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7BEF03858037 for ; Fri, 26 Nov 2021 11:06:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BEF03858037 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1637924819; bh=Ao75LC6yPaV8i0cx6lkY/g00/2E8EC07b9rCCs0QiB8=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=xq5o3HrSUu2U3HZjmd2RaacgeJ+UxD3vdYiJYTDABk5hfcITefG7UqKYrvKJsDr1I 6ocdXZMeRRnnU0iizsRVMn1m/J7ulR9qmY0epmcXzuSbu9RwdvjoCiVl4c0Qkdh0iU VokDdG4eW9/41EsewOlGoWwOno2ByutIfFEPcONU= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by sourceware.org (Postfix) with ESMTPS id A24C23858414 for ; Fri, 26 Nov 2021 11:06:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A24C23858414 Received: by mail-wm1-x34a.google.com with SMTP id j25-20020a05600c1c1900b00332372c252dso5203168wms.1 for ; Fri, 26 Nov 2021 03:06:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=Ao75LC6yPaV8i0cx6lkY/g00/2E8EC07b9rCCs0QiB8=; b=J8AoIsVoSN2x5x9tZJ3sTBxa2MhWm3NKBvzpg5RXp7wtZyOsE5cwroOtSWpJN8iQbj Hy+injnw474kkWUlzaJAG/RJ3Q497oT0GUc93+74P6U+25qO4RFWqhHwHiWK6bDsjlcW 95eozUL0kqTZ6ItjmvXvnsqA99iATBplmPFeGbRAo4Nw6S6H7+xHY459tUJayAgEWkvw C/uVXuz1UpSKwzENF7jvHjNmDP3WIqKh796rfwwo5Mn1oOMvbU1MxBHaf9FtzRNlXbQS sv9GgeXEyMza/P2T3c1Qx22CvEovN9uTVtHtOuWTVX6TYvpy5syhmhFgGuCStovylz5J JznA== X-Gm-Message-State: AOAM533fMA4a6bQ/Dcwj8rKYIrepBdD3eqW7zptVm1UU8dTiGPBxoBzO ga+czIKGiORKAyJVEl3XzWWktkQCWQAYzg25PjAuUnxn0GPhqGtIJsaE2KdSlivVm7s3jSuzdre XD6CwUdLgFySmz8IbtNOvqRIsVGM4jg+A78NRnGHUIpZLwYRs2CbeU+O9S7wD7qeMY7pK2LY= X-Google-Smtp-Source: ABdhPJyEYBoXxjh7/Ds/v+eKQBH6Ocazu1ahQEwnvRDePa6UR2iRaLf+M1onrC1k6X75DBKtZq6Kk+AnLpPjsg== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:68c0:83af:95cc:64ea]) (user=maennich job=sendgmr) by 2002:a7b:c94e:: with SMTP id i14mr14392779wml.85.1637924813408; Fri, 26 Nov 2021 03:06:53 -0800 (PST) Date: Fri, 26 Nov 2021 11:06:42 +0000 Message-Id: <20211126110642.4164044-1-maennich@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH] abidiff: improve whitespace generation in symbol diff report To: libabigail@sourceware.org X-Spam-Status: No, score=-22.8 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Matthias Maennich via Libabigail From: =?utf-8?q?Matthias_M=C3=A4nnich?= Reply-To: Matthias Maennich Cc: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" maybe_report_diff_for_symbol() has a few issues: 1. The responsibility for newline emission is somewhat unclear and indeed it would emit spurious blank lines before most of the sub-diffs it reports. 2. Different sub-diff text and terminal commas are emitted according to whether or not there had been a previous sub-diff - making the output harder to grep and post-process. 3. The function also returns a bool but that return value is never used. Hence, change the function to return void, the function stanzas to always emit newline-terminated lines and ensure the wording and punctuation of each sub-diff do not vary. This also tweaks (shortens) the wording used for CRC diffs. * src/abg-reporter-priv.cc (maybe_report_diff_for_symbol): Make return void. Simplify and fix new-line emission. Remove comma emission. Tweak CRC wording. * src/abg-reporter-priv.h (maybe_report_diff_for_symbol): Return void. * tests/data/test-abidiff-exit/test-crc-report.txt: Shorten CRC wording. * tests/data/test-abidiff/test-crc-report.txt: Likewise. * tests/data/test-diff-filter/test-PR27569-report-0.txt: Likewise. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- src/abg-reporter-priv.cc | 88 +++++-------------- src/abg-reporter-priv.h | 2 +- .../test-abidiff-exit/test-crc-report.txt | 6 +- tests/data/test-abidiff/test-crc-report.txt | 3 +- .../test-PR27569-report-0.txt | 3 +- 5 files changed, 25 insertions(+), 77 deletions(-) diff --git a/src/abg-reporter-priv.cc b/src/abg-reporter-priv.cc index 3091f6ca4b83..7012f5dcdce0 100644 --- a/src/abg-reporter-priv.cc +++ b/src/abg-reporter-priv.cc @@ -1081,20 +1081,15 @@ maybe_report_diff_for_member(const decl_base_sptr& decl1, /// @param the output stream to emit the report to. /// /// @param indent the indentation string to use. -/// -/// @return true if a report was emitted to the output stream @p out, -/// false otherwise. -bool +void maybe_report_diff_for_symbol(const elf_symbol_sptr& symbol1, const elf_symbol_sptr& symbol2, const diff_context_sptr& ctxt, ostream& out, const string& indent) { - bool reported = false; - if (!symbol1 || !symbol2 || symbol1 == symbol2) - return reported; + return; if (symbol1->get_size() != symbol2->get_size()) { @@ -1104,108 +1099,65 @@ maybe_report_diff_for_symbol(const elf_symbol_sptr& symbol1, symbol2->get_size(), *ctxt, out, /*show_bits_or_bytes=*/false); - reported = true; + out << "\n"; } if (symbol1->get_name() != symbol2->get_name()) { - if (reported) - out << ",\n" << indent - << "its name "; - else - out << "\n" << indent << "name of symbol "; - - out << "changed from " + out << indent << "symbol name changed from " << symbol1->get_name() << " to " - << symbol2->get_name(); - - reported = true; + << symbol2->get_name() + << "\n"; } if (symbol1->get_type() != symbol2->get_type()) { - if (reported) - out << ",\n" << indent - << "its type "; - else - out << "\n" << indent << "type of symbol "; - - out << "changed from '" + out << indent << "symbol type changed from '" << symbol1->get_type() << "' to '" << symbol2->get_type() - << "'"; - - reported = true; + << "'\n"; } if (symbol1->is_public() != symbol2->is_public()) { - if (reported) - out << ",\n" << indent - << "it became "; - else - out << "\n" << indent << "symbol became "; - + out << indent << "symbol became "; if (symbol2->is_public()) out << "exported"; else out << "non-exported"; - - reported = true; + out << "\n"; } if (symbol1->is_defined() != symbol2->is_defined()) { - if (reported) - out << ",\n" << indent - << "it became "; - else - out << "\n" << indent << "symbol became "; - + out << indent << "symbol became "; if (symbol2->is_defined()) out << "defined"; else out << "undefined"; - - reported = true; + out << "\n"; } if (symbol1->get_version() != symbol2->get_version()) { - if (reported) - out << ",\n" << indent - << "its version changed from "; - else - out << "\n" << indent << "symbol version changed from "; - - out << symbol1->get_version().str() + out << indent << "symbol version changed from " + << symbol1->get_version().str() << " to " - << symbol2->get_version().str(); - - reported = true; + << symbol2->get_version().str() + << "\n"; } if (symbol1->get_crc() != 0 && symbol2->get_crc() != 0 && symbol1->get_crc() != symbol2->get_crc()) { - if (reported) - out << ",\n" << indent << "its CRC (modversions) changed from "; - else - out << "\n" << indent << "CRC value (modversions) changed from "; - - out << std::showbase << std::hex + out << indent << "CRC (modversions) changed from " + << std::showbase << std::hex << symbol1->get_crc() << " to " << symbol2->get_crc() - << std::noshowbase << std::dec; - - reported = true; + << std::noshowbase << std::dec + << "\n"; } - - if (reported) - out << "\n"; - - return reported; } /// For a given symbol, emit a string made of its name and version. diff --git a/src/abg-reporter-priv.h b/src/abg-reporter-priv.h index 65786a0fa9c5..a7c4878c3279 100644 --- a/src/abg-reporter-priv.h +++ b/src/abg-reporter-priv.h @@ -206,7 +206,7 @@ maybe_report_diff_for_member(const decl_base_sptr& decl1, ostream& out, const string& indent); -bool +void maybe_report_diff_for_symbol(const elf_symbol_sptr& symbol1, const elf_symbol_sptr& symbol2, const diff_context_sptr& ctxt, diff --git a/tests/data/test-abidiff-exit/test-crc-report.txt b/tests/data/test-abidiff-exit/test-crc-report.txt index ddba41f40dad..2dbfa555b4ce 100644 --- a/tests/data/test-abidiff-exit/test-crc-report.txt +++ b/tests/data/test-abidiff-exit/test-crc-report.txt @@ -4,12 +4,10 @@ Variables changes summary: 0 Removed, 1 Changed, 0 Added variable 1 function with some indirect sub-type change: [C] 'function void func1(E)' has some indirect sub-type changes: - - CRC value (modversions) changed from 0x10000001 to 0x10000002 + CRC (modversions) changed from 0x10000001 to 0x10000002 1 Changed variable: [C] 'int var1' was changed: - - CRC value (modversions) changed from 0x30000001 to 0x30000002 + CRC (modversions) changed from 0x30000001 to 0x30000002 diff --git a/tests/data/test-abidiff/test-crc-report.txt b/tests/data/test-abidiff/test-crc-report.txt index 4572a207a5ae..9bea309e2a2f 100644 --- a/tests/data/test-abidiff/test-crc-report.txt +++ b/tests/data/test-abidiff/test-crc-report.txt @@ -4,6 +4,5 @@ Variables changes summary: 0 Removed, 0 Changed, 0 Added variable 1 function with some indirect sub-type change: [C] 'function void exported_function()' has some indirect sub-type changes: - - CRC value (modversions) changed from 0xe52d5bcf to 0xe52d5bd0 + CRC (modversions) changed from 0xe52d5bcf to 0xe52d5bd0 diff --git a/tests/data/test-diff-filter/test-PR27569-report-0.txt b/tests/data/test-diff-filter/test-PR27569-report-0.txt index 419c9fd4777c..99febd66601c 100644 --- a/tests/data/test-diff-filter/test-PR27569-report-0.txt +++ b/tests/data/test-diff-filter/test-PR27569-report-0.txt @@ -4,7 +4,6 @@ Variables changes summary: 0 Removed, 0 Changed, 0 Added variable 1 function with some indirect sub-type change: [C] 'function void device_add_disk(gendisk*)' at genhd.h:420:1 has some indirect sub-type changes: - - CRC value (modversions) changed from 0x8afa957c to 0xa3bc03c + CRC (modversions) changed from 0x8afa957c to 0xa3bc03c parameter 2 of type 'int' was added