From patchwork Wed Jul 24 22:18:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1964566 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ft6tcct4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WTpQx4LHTz1yY9 for ; Thu, 25 Jul 2024 08:22:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DDEA6385DDD7 for ; Wed, 24 Jul 2024 22:21:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id B68D9385DDCC for ; Wed, 24 Jul 2024 22:18:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B68D9385DDCC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B68D9385DDCC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721859538; cv=none; b=EIwReSVVcVpJl44QaLWjEoMru3wlHCGIcNLN+WLxbu7wUXrHgCQxxIyaFfLBQqF+kGlYWQRHJdut41Y+pEpFmi6lyXb3CwCEF/rgx1lpuD4ARsEWZaFqTyNsxRGo8GLfObEVwXKBEYg4nyV8x185rGJi0CtO9C5qGXM0wq+rEhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721859538; c=relaxed/simple; bh=Ii3K3iix1SrD7LVKXnt62gCLIWVwWKxGfVZ6UslSTWs=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Hjm3Fzn7k9nW2f+qp8SEKQzy9MgW7CZB8D5D/cfWGV79+PUXFtFaa2UqTQIm40J7T7DAKNf6Rro4sd6XFJHsasn9Qm/insiSZvrXDVnBd8fZhv1q3rXqLsqozQUOroeBiWgixr10U3s63YYZ6MfUF2YTS4oc2sKEvLgWaNztbgg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721859535; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I0lr7gk5mcrwrKd1Ey7/l/+yP8SCRSwRJBWRo0E6ANU=; b=ft6tcct4PqNdWXwiD2Y6xbkgo8bMQt3iCi/2+ZnuzZ4D2sqoWzOjAUtoSAvzJQVfPjv8vZ BJOwOMWN5y8BY+HQ6qySENVdb/mYjpc7Rkq18Qx55KZQv5x7bniFPzKugY3GvG9Eml82vw BHChtyf8rMVLFVLxTJu4TwJxdObSrGE= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-73-tXC6ZwhFOve5HafWgqlgGg-1; Wed, 24 Jul 2024 18:18:53 -0400 X-MC-Unique: tXC6ZwhFOve5HafWgqlgGg-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E0E1919560A1 for ; Wed, 24 Jul 2024 22:18:52 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.33.183]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0714C1955F40; Wed, 24 Jul 2024 22:18:51 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 11/16] =?utf-8?q?diagnostics=3A_SARIF_output=3A_add_=22worki?= =?utf-8?q?ngDirectory=22_property_=28=C2=A73=2E20=2E19=29?= Date: Wed, 24 Jul 2024 18:18:19 -0400 Message-Id: <20240724221824.585054-12-dmalcolm@redhat.com> In-Reply-To: <20240724221824.585054-1-dmalcolm@redhat.com> References: <20240724221824.585054-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * diagnostic-format-sarif.cc (sarif_builder::make_artifact_location_object): Make public. (sarif_invocation::sarif_invocation): Add param "builder". Use it to potentially populate the "workingDirectory" property with the result of pwd (ยง3.20.19). (sarif_builder::sarif_builder): Pass *this to m_invocation_obj's ctor. gcc/testsuite/ChangeLog: * c-c++-common/diagnostic-format-sarif-file-1.c: Verify that we have a "workingDirectory" property. Signed-off-by: David Malcolm --- gcc/diagnostic-format-sarif.cc | 15 ++++++++++----- .../c-c++-common/diagnostic-format-sarif-file-1.c | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index 847e1eb9bdfc..9be84fb268a5 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -125,7 +125,7 @@ class sarif_tool_component : public sarif_object {}; class sarif_invocation : public sarif_object { public: - sarif_invocation (); + sarif_invocation (sarif_builder &builder); void add_notification_for_ice (diagnostic_context &context, const diagnostic_info &diagnostic, @@ -378,6 +378,9 @@ public: std::unique_ptr maybe_make_artifact_content_object (const char *filename) const; + std::unique_ptr + make_artifact_location_object (const char *filename); + private: std::unique_ptr make_result_object (diagnostic_context &context, @@ -404,8 +407,6 @@ private: std::unique_ptr make_artifact_location_object (location_t loc); std::unique_ptr - make_artifact_location_object (const char *filename); - std::unique_ptr make_artifact_location_object_for_pwd () const; std::unique_ptr maybe_make_region_object (location_t loc, @@ -512,10 +513,14 @@ sarif_object::get_or_create_properties () /* class sarif_invocation : public sarif_object. */ -sarif_invocation::sarif_invocation () +sarif_invocation::sarif_invocation (sarif_builder &builder) : m_notifications_arr (::make_unique ()), m_success (true) { + // "workingDirectory" property (SARIF v2.1.0 section 3.20.19) + if (const char *pwd = getpwd ()) + set ("workingDirectory", + builder.make_artifact_location_object (pwd)); } /* Handle an internal compiler error DIAGNOSTIC occurring on CONTEXT. @@ -747,7 +752,7 @@ sarif_builder::sarif_builder (diagnostic_context &context, const char *main_input_filename_, bool formatted) : m_context (context), - m_invocation_obj (::make_unique ()), + m_invocation_obj (::make_unique (*this)), m_results_array (new json::array ()), m_cur_group_result (nullptr), m_seen_any_relative_paths (false), diff --git a/gcc/testsuite/c-c++-common/diagnostic-format-sarif-file-1.c b/gcc/testsuite/c-c++-common/diagnostic-format-sarif-file-1.c index 50375465483d..0a3778323792 100644 --- a/gcc/testsuite/c-c++-common/diagnostic-format-sarif-file-1.c +++ b/gcc/testsuite/c-c++-common/diagnostic-format-sarif-file-1.c @@ -32,6 +32,7 @@ { dg-final { scan-sarif-file "\"informationUri\": \"" } } { dg-final { scan-sarif-file "\"invocations\": \\\[" } } + { dg-final { scan-sarif-file {"workingDirectory": } } } { dg-final { scan-sarif-file "\"toolExecutionNotifications\": \\\[\\\]" } } { dg-final { scan-sarif-file "\"executionSuccessful\": true" } }