From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id F20AB780091 for ; Tue, 26 Sep 2023 19:22:06 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=XC96DCqG758qOfFzKQE3IQJ3/wMtEpbUJ/CBe8ZJFko=; c=relaxed/simple; d=groups.io; h=DKIM-Filter:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1695756125; v=1; b=L4N785QrWbuWjXRGgZe32F6VPIUw4zfrlqOTAxq6jOYF9Tz1c9Z6FKW3lEjw/qWaxzaeHppU zmUKjsm3Vpo45wCvl3jH81EmbMFjd//hGI/mS70QPK32/lY+RPfInghMltNJyRV/8dMDP1bBk8V idrMh2pZ+UdsukwNeNFBkQhM= X-Received: by 127.0.0.2 with SMTP id onwnYY7687511xtpQge6kxJf; Tue, 26 Sep 2023 12:22:05 -0700 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.9.1695756125153088094 for ; Tue, 26 Sep 2023 12:22:05 -0700 X-Received: from localhost.localdomain (unknown [47.201.241.95]) by linux.microsoft.com (Postfix) with ESMTPSA id 04CA720B74C0; Tue, 26 Sep 2023 12:22:03 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 04CA720B74C0 From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Bob Feng , Liming Gao , Michael D Kinney , Rebecca Cran , Sean Brogan , Yuwei Chen Subject: [edk2-devel] [PATCH v1 3/5] BaseTools/Plugin/CodeQL: Add integration helpers Date: Tue, 26 Sep 2023 15:21:12 -0400 Message-ID: <20230926192114.416-4-mikuback@linux.microsoft.com> In-Reply-To: <20230926192114.416-1-mikuback@linux.microsoft.com> References: <20230926192114.416-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mikuback@linux.microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 9oTnc1WwWHqxVNEuuXslKemhx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=L4N785Qr; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=linux.microsoft.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: Michael Kubacki Adds a Python module to the CodeQL plugin directory that exports functions commonly needed for Stuart-based platforms to easily enable CodeQL in their platform build. This functionality has already moved to edk2-pytool-extensions https://github.com/tianocore/edk2-pytool-extensions in the `edk2toolext/codeql.py` file but edk2 is too far behind to use that. Additional integration changes are needed in edk2 and the series to add those has not made it past review. In the meantime, the functions are available locally in this commit and this commit can be reverted after edk2-pytool-extensions 0.24.1 or greater is used in edk2. Cc: Bob Feng Cc: Liming Gao Cc: Michael D Kinney Cc: Rebecca Cran Cc: Sean Brogan Cc: Yuwei Chen Signed-off-by: Michael Kubacki --- BaseTools/Plugin/CodeQL/integration/__init__.py | 0 BaseTools/Plugin/CodeQL/integration/stuart_codeql.py | 79 ++++++++++++++= ++++++ 2 files changed, 79 insertions(+) diff --git a/BaseTools/Plugin/CodeQL/integration/__init__.py b/BaseTools/= Plugin/CodeQL/integration/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/BaseTools/Plugin/CodeQL/integration/stuart_codeql.py b/BaseT= ools/Plugin/CodeQL/integration/stuart_codeql.py new file mode 100644 index 000000000000..a3941d13157f --- /dev/null +++ b/BaseTools/Plugin/CodeQL/integration/stuart_codeql.py @@ -0,0 +1,79 @@ +# @file stuart_codeql.py +# +# Exports functions commonly needed for Stuart-based platforms to easily +# enable CodeQL in their platform build. +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +from edk2toolext.environment.uefi_build import UefiBuilder +from edk2toollib.utility_functions import GetHostInfo +from argparse import ArgumentParser, Namespace +from typing import Tuple + + +def add_command_line_option(parser: ArgumentParser) -> None: + """Adds the CodeQL command to the platform command line options. + + Args: + parser (ArgumentParser): The argument parser used in this build. + + """ + parser.add_argument( + '--codeql', + dest=3D'codeql', + action=3D'store_true', + default=3DFalse, + help=3D"Optional - Produces CodeQL results from the build. See " + "BaseTools/Plugin/CodeQL/Readme.md for more info.") + + +def get_scopes(codeql_enabled: bool) -> Tuple[str]: + """Returns the active CodeQL scopes for this build. + + Args: + codeql_enabled (bool): Whether CodeQL is enabled. + + Returns: + Tuple[str]: A tuple of strings containing scopes that enable the + CodeQL plugin. + """ + active_scopes =3D () + + if codeql_enabled: + if GetHostInfo().os =3D=3D "Linux": + active_scopes +=3D ("codeql-linux-ext-dep",) + else: + active_scopes +=3D ("codeql-windows-ext-dep",) + active_scopes +=3D ("codeql-build", "codeql-analyze") + + return active_scopes + + +def is_codeql_enabled_on_command_line(args: Namespace) -> bool: + """Returns whether CodeQL was enabled on the command line. + + Args: + args (Namespace): Object holding a string representation of comm= and + line arguments. + + Returns: + bool: True if CodeQL is enabled on the command line. Otherwise, = false. + """ + return args.codeql + + +def set_audit_only_mode(uefi_builder: UefiBuilder) -> None: + """Configures the CodeQL plugin to run in audit only mode. + + Args: + uefi_builder (UefiBuilder): The UefiBuilder object for this plat= form + build. + + """ + + uefi_builder.env.SetValue( + "STUART_CODEQL_AUDIT_ONLY", + "true", + "Platform Defined") --=20 2.42.0.windows.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#109084): https://edk2.groups.io/g/devel/message/109084 Mute This Topic: https://groups.io/mt/101603470/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-