Skip to content

Commit b531ca4

Browse files
makubackimergify[bot]
authored andcommitted
BaseTools/Plugin/CodeQL: Add integration helpers
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 <bob.c.feng@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Rebecca Cran <rebecca@bsdio.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Yuwei Chen <yuwei.chen@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Sean Brogan <sean.brogan@microsoft.com> Acked-by: Laszlo Ersek <lersek@redhat.com> Acked-by: Michael D Kinney <michael.d.kinney@intel.com>
1 parent 5464d0b commit b531ca4

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

BaseTools/Plugin/CodeQL/integration/__init__.py

Whitespace-only changes.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# @file stuart_codeql.py
2+
#
3+
# Exports functions commonly needed for Stuart-based platforms to easily
4+
# enable CodeQL in their platform build.
5+
#
6+
# Copyright (c) Microsoft Corporation. All rights reserved.
7+
# SPDX-License-Identifier: BSD-2-Clause-Patent
8+
##
9+
10+
from edk2toolext.environment.uefi_build import UefiBuilder
11+
from edk2toollib.utility_functions import GetHostInfo
12+
from argparse import ArgumentParser, Namespace
13+
from typing import Tuple
14+
15+
16+
def add_command_line_option(parser: ArgumentParser) -> None:
17+
"""Adds the CodeQL command to the platform command line options.
18+
19+
Args:
20+
parser (ArgumentParser): The argument parser used in this build.
21+
22+
"""
23+
parser.add_argument(
24+
'--codeql',
25+
dest='codeql',
26+
action='store_true',
27+
default=False,
28+
help="Optional - Produces CodeQL results from the build. See "
29+
"BaseTools/Plugin/CodeQL/Readme.md for more info.")
30+
31+
32+
def get_scopes(codeql_enabled: bool) -> Tuple[str]:
33+
"""Returns the active CodeQL scopes for this build.
34+
35+
Args:
36+
codeql_enabled (bool): Whether CodeQL is enabled.
37+
38+
Returns:
39+
Tuple[str]: A tuple of strings containing scopes that enable the
40+
CodeQL plugin.
41+
"""
42+
active_scopes = ()
43+
44+
if codeql_enabled:
45+
if GetHostInfo().os == "Linux":
46+
active_scopes += ("codeql-linux-ext-dep",)
47+
else:
48+
active_scopes += ("codeql-windows-ext-dep",)
49+
active_scopes += ("codeql-build", "codeql-analyze")
50+
51+
return active_scopes
52+
53+
54+
def is_codeql_enabled_on_command_line(args: Namespace) -> bool:
55+
"""Returns whether CodeQL was enabled on the command line.
56+
57+
Args:
58+
args (Namespace): Object holding a string representation of command
59+
line arguments.
60+
61+
Returns:
62+
bool: True if CodeQL is enabled on the command line. Otherwise, false.
63+
"""
64+
return args.codeql
65+
66+
67+
def set_audit_only_mode(uefi_builder: UefiBuilder) -> None:
68+
"""Configures the CodeQL plugin to run in audit only mode.
69+
70+
Args:
71+
uefi_builder (UefiBuilder): The UefiBuilder object for this platform
72+
build.
73+
74+
"""
75+
76+
uefi_builder.env.SetValue(
77+
"STUART_CODEQL_AUDIT_ONLY",
78+
"true",
79+
"Platform Defined")

0 commit comments

Comments
 (0)