Skip to content

Commit 23eee2d

Browse files
authored
Add CodeQL Stuart parameter to this repo (microsoft#136)
## Description Allows CodeQL to be run locally by specifying `--codeql` when providing `stuart_update` and `stuart_ci_build` commands in this repo. - `stuart_update` - Automatically downloads the CodeQL CLI application appropriate for your host operating system - Note: This may take several minutes depending on your Internet connection speed - `stuart_ci_build` - Automatically runs CodeQL against the packages built after they are built. NOTE: Running with CodeQL will increase your overall build time for a couple of reasons: 1. Every package must be clean built to get proper results 2. The CodeQL analysis phase takes a while to run (1) happens automatically, you do not need to specify a clean build manually For more information, such as: 1. How to view results 2. How to modify the CodeQL rules run 3. How to include/exclude files/rules at various levels of granularity And more... Go to the CodeQL plugin readme: https://github.com/microsoft/mu_basecore/blob/HEAD/.pytool/Plugin/CodeQL/Readme.md --- - [ ] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... ## How This Was Tested Verified `--codeql` usage with `stuart_update` and `stuart_ci_build` locally. ## Integration Instructions See earlier PR description and CodeQL plugin readme: https://github.com/microsoft/mu_basecore/blob/HEAD/.pytool/Plugin/CodeQL/Readme.md Signed-off-by: Michael Kubacki <[email protected]>
1 parent afe41b5 commit 23eee2d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

.pytool/CISettings.py

+42
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,26 @@
33
# Copyright (c) Microsoft Corporation. All rights reserved.
44
# SPDX-License-Identifier: BSD-2-Clause-Patent
55
##
6+
import glob
67
import os
78
import logging
9+
import sys
810
from edk2toolext.environment import shell_environment
911
from edk2toolext.invocables.edk2_ci_build import CiBuildSettingsManager
1012
from edk2toolext.invocables.edk2_ci_setup import CiSetupSettingsManager
1113
from edk2toolext.invocables.edk2_setup import SetupSettingsManager
1214
from edk2toolext.invocables.edk2_update import UpdateSettingsManager
1315
from edk2toolext.invocables.edk2_pr_eval import PrEvalSettingsManager
1416
from edk2toollib.utility_functions import GetHostInfo
17+
from pathlib import Path
18+
19+
try:
20+
# May not be present until submodules are populated
21+
root = Path(__file__).parent.parent.resolve()
22+
sys.path.append(str(root / 'MU_BASECORE' / '.pytool' / 'Plugin' / 'CodeQL' / 'integration'))
23+
import stuart_codeql as codeql_helpers
24+
except ImportError:
25+
pass
1526

1627

1728
class Settings(
@@ -52,13 +63,23 @@ def AddCommandLineOptions(self, parserObj):
5263
help="Force the system to not use pip tools",
5364
)
5465

66+
try:
67+
codeql_helpers.add_command_line_option(parserObj)
68+
except NameError:
69+
pass
70+
5571
def RetrieveCommandLineOptions(self, args):
5672
super().RetrieveCommandLineOptions(args)
5773
if args.force_piptools:
5874
self.UseBuiltInBaseTools = True
5975
if args.no_piptools:
6076
self.UseBuiltInBaseTools = False
6177

78+
try:
79+
self.codeql = codeql_helpers.is_codeql_enabled_on_command_line(args)
80+
except NameError:
81+
pass
82+
6283
# ####################################################################################### #
6384
# Default Support for this Ci Build #
6485
# ####################################################################################### #
@@ -169,7 +190,28 @@ def GetActiveScopes(self):
169190
scopes += ("gcc_arm_linux",)
170191
if "RISCV64" in self.ActualArchitectures:
171192
scopes += ("gcc_riscv64_unknown",)
193+
194+
try:
195+
scopes += codeql_helpers.get_scopes(self.codeql)
196+
197+
if self.codeql:
198+
shell_environment.GetBuildVars().SetValue(
199+
"STUART_CODEQL_AUDIT_ONLY",
200+
"TRUE",
201+
"Set in CISettings.py")
202+
codeql_filter_files = [str(n) for n in glob.glob(
203+
os.path.join(self.GetWorkspaceRoot(),
204+
'**/CodeQlFilters.yml'),
205+
recursive=True)]
206+
shell_environment.GetBuildVars().SetValue(
207+
"STUART_CODEQL_FILTER_FILES",
208+
','.join(codeql_filter_files),
209+
"Set in CISettings.py")
210+
except NameError:
211+
pass
212+
172213
self.ActualScopes = scopes
214+
173215
return self.ActualScopes
174216

175217
def GetRequiredSubmodules(self):

0 commit comments

Comments
 (0)