2020-06-18 12:52:58 +02:00
|
|
|
# @file EccCheck.py
|
|
|
|
#
|
2021-07-06 22:55:38 +02:00
|
|
|
# Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
|
2020-06-18 12:52:58 +02:00
|
|
|
# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
|
|
##
|
|
|
|
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import re
|
|
|
|
import csv
|
|
|
|
import xml.dom.minidom
|
|
|
|
from typing import List, Dict, Tuple
|
|
|
|
import logging
|
|
|
|
from io import StringIO
|
|
|
|
from edk2toolext.environment import shell_environment
|
|
|
|
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin
|
|
|
|
from edk2toolext.environment.var_dict import VarDict
|
|
|
|
from edk2toollib.utility_functions import RunCmd
|
|
|
|
|
|
|
|
|
|
|
|
class EccCheck(ICiBuildPlugin):
|
|
|
|
"""
|
|
|
|
A CiBuildPlugin that finds the Ecc issues of newly added code in pull request.
|
|
|
|
|
|
|
|
Configuration options:
|
|
|
|
"EccCheck": {
|
|
|
|
"ExceptionList": [],
|
|
|
|
"IgnoreFiles": []
|
|
|
|
},
|
|
|
|
"""
|
|
|
|
|
|
|
|
FindModifyFile = re.compile(r'\+\+\+ b\/(.*)')
|
|
|
|
LineScopePattern = (r'@@ -\d*\,*\d* \+\d*\,*\d* @@.*')
|
|
|
|
LineNumRange = re.compile(r'@@ -\d*\,*\d* \+(\d*)\,*(\d*) @@.*')
|
|
|
|
|
|
|
|
def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
|
|
|
|
""" Provide the testcase name and classname for use in reporting
|
|
|
|
testclassname: a descriptive string for the testcase can include whitespace
|
|
|
|
classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>
|
|
|
|
|
|
|
|
Args:
|
|
|
|
packagename: string containing name of package to build
|
|
|
|
environment: The VarDict for the test to run in
|
|
|
|
Returns:
|
|
|
|
a tuple containing the testcase name and the classname
|
|
|
|
(testcasename, classname)
|
|
|
|
"""
|
|
|
|
return ("Check for efi coding style for " + packagename, packagename + ".EccCheck")
|
|
|
|
|
|
|
|
##
|
|
|
|
# External function of plugin. This function is used to perform the task of the ci_build_plugin Plugin
|
|
|
|
#
|
|
|
|
# - package is the edk2 path to package. This means workspace/packagepath relative.
|
|
|
|
# - edk2path object configured with workspace and packages path
|
|
|
|
# - PkgConfig Object (dict) for the pkg
|
|
|
|
# - EnvConfig Object
|
|
|
|
# - Plugin Manager Instance
|
|
|
|
# - Plugin Helper Obj Instance
|
|
|
|
# - Junit Logger
|
|
|
|
# - output_stream the StringIO output stream from this plugin via logging
|
|
|
|
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
|
2021-07-06 22:55:39 +02:00
|
|
|
workspace_path = Edk2pathObj.WorkspacePath
|
2021-07-06 22:55:38 +02:00
|
|
|
basetools_path = environment.GetValue("EDK_TOOLS_PATH")
|
|
|
|
python_path = os.path.join(basetools_path, "Source", "Python")
|
2020-06-18 12:52:58 +02:00
|
|
|
env = shell_environment.GetEnvironment()
|
|
|
|
env.set_shell_var('PYTHONPATH', python_path)
|
2021-07-06 22:55:39 +02:00
|
|
|
env.set_shell_var('WORKSPACE', workspace_path)
|
2021-07-06 22:55:41 +02:00
|
|
|
env.set_shell_var('PACKAGES_PATH', os.pathsep.join(Edk2pathObj.PackagePathList))
|
2020-06-18 12:52:58 +02:00
|
|
|
self.ECC_PASS = True
|
2021-11-23 06:13:41 +01:00
|
|
|
|
2023-02-01 15:47:50 +01:00
|
|
|
abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSystemFromEdk2RelativePath(packagename)
|
|
|
|
|
|
|
|
if abs_pkg_path is None:
|
|
|
|
tc.SetSkipped()
|
|
|
|
tc.LogStdError("No Package folder {0}".format(abs_pkg_path))
|
|
|
|
return 0
|
|
|
|
|
2021-11-23 06:13:41 +01:00
|
|
|
# Create temp directory
|
|
|
|
temp_path = os.path.join(workspace_path, 'Build', '.pytool', 'Plugin', 'EccCheck')
|
2021-11-23 06:20:48 +01:00
|
|
|
try:
|
|
|
|
# Delete temp directory
|
|
|
|
if os.path.exists(temp_path):
|
|
|
|
shutil.rmtree(temp_path)
|
|
|
|
# Copy package being scanned to temp_path
|
|
|
|
shutil.copytree (
|
2023-02-01 15:47:50 +01:00
|
|
|
abs_pkg_path,
|
2021-11-23 06:20:48 +01:00
|
|
|
os.path.join(temp_path, packagename),
|
|
|
|
symlinks=True
|
|
|
|
)
|
|
|
|
# Copy exception.xml to temp_path
|
|
|
|
shutil.copyfile (
|
|
|
|
os.path.join(basetools_path, "Source", "Python", "Ecc", "exception.xml"),
|
|
|
|
os.path.join(temp_path, "exception.xml")
|
|
|
|
)
|
2021-11-23 06:29:38 +01:00
|
|
|
# Output file to use for git diff operations
|
|
|
|
temp_diff_output = os.path.join (temp_path, 'diff.txt')
|
2021-11-23 06:13:41 +01:00
|
|
|
|
2021-11-23 06:20:48 +01:00
|
|
|
self.ApplyConfig(pkgconfig, temp_path, packagename)
|
2021-11-23 06:29:38 +01:00
|
|
|
modify_dir_list = self.GetModifyDir(packagename, temp_diff_output)
|
|
|
|
patch = self.GetDiff(packagename, temp_diff_output)
|
2021-11-23 06:20:48 +01:00
|
|
|
ecc_diff_range = self.GetDiffRange(patch, packagename, temp_path)
|
|
|
|
#
|
|
|
|
# Use temp_path as working directory when running ECC tool
|
|
|
|
#
|
|
|
|
self.GenerateEccReport(modify_dir_list, ecc_diff_range, temp_path, basetools_path)
|
|
|
|
ecc_log = os.path.join(temp_path, "Ecc.log")
|
|
|
|
if self.ECC_PASS:
|
|
|
|
# Delete temp directory
|
|
|
|
if os.path.exists(temp_path):
|
|
|
|
shutil.rmtree(temp_path)
|
|
|
|
tc.SetSuccess()
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
with open(ecc_log, encoding='utf8') as output:
|
|
|
|
ecc_output = output.readlines()
|
|
|
|
for line in ecc_output:
|
|
|
|
logging.error(line.strip())
|
|
|
|
# Delete temp directory
|
|
|
|
if os.path.exists(temp_path):
|
|
|
|
shutil.rmtree(temp_path)
|
|
|
|
tc.SetFailed("EccCheck failed for {0}".format(packagename), "CHECK FAILED")
|
|
|
|
return 1
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
# If EccCheck is interrupted by keybard interrupt, then return failure
|
2021-11-23 06:13:41 +01:00
|
|
|
# Delete temp directory
|
|
|
|
if os.path.exists(temp_path):
|
|
|
|
shutil.rmtree(temp_path)
|
2021-11-23 06:20:48 +01:00
|
|
|
tc.SetFailed("EccCheck interrupted for {0}".format(packagename), "CHECK FAILED")
|
|
|
|
return 1
|
2020-06-18 12:52:58 +02:00
|
|
|
else:
|
2021-11-23 06:20:48 +01:00
|
|
|
# If EccCheck fails for any other exception type, raise the exception
|
2021-11-23 06:13:41 +01:00
|
|
|
# Delete temp directory
|
|
|
|
if os.path.exists(temp_path):
|
|
|
|
shutil.rmtree(temp_path)
|
2021-11-23 06:20:48 +01:00
|
|
|
tc.SetFailed("EccCheck exception for {0}".format(packagename), "CHECK FAILED")
|
|
|
|
raise
|
2020-06-18 12:52:58 +02:00
|
|
|
return 1
|
|
|
|
|
2021-11-23 06:29:38 +01:00
|
|
|
def GetDiff(self, pkg: str, temp_diff_output: str) -> List[str]:
|
|
|
|
patch = []
|
|
|
|
#
|
|
|
|
# Generate unified diff between origin/master and HEAD.
|
|
|
|
#
|
|
|
|
params = "diff --output={} --unified=0 origin/master HEAD".format(temp_diff_output)
|
|
|
|
RunCmd("git", params)
|
|
|
|
with open(temp_diff_output) as file:
|
|
|
|
patch = file.read().strip().split('\n')
|
2020-06-18 12:52:58 +02:00
|
|
|
return patch
|
|
|
|
|
2021-11-23 06:29:38 +01:00
|
|
|
def GetModifyDir(self, pkg: str, temp_diff_output: str) -> List[str]:
|
|
|
|
#
|
|
|
|
# Generate diff between origin/master and HEAD using --diff-filter to
|
|
|
|
# exclude deleted and renamed files that do not need to be scanned by
|
|
|
|
# ECC. Also use --name-status to only generate the names of the files
|
|
|
|
# with differences. The output format of this git diff command is a
|
|
|
|
# list of files with the change status and the filename. The filename
|
|
|
|
# is always at the end of the line. Examples:
|
|
|
|
#
|
|
|
|
# M MdeModulePkg/Application/CapsuleApp/CapsuleApp.h
|
|
|
|
# M MdeModulePkg/Application/UiApp/FrontPage.h
|
|
|
|
#
|
|
|
|
params = "diff --output={} --diff-filter=dr --name-status origin/master HEAD".format(temp_diff_output)
|
|
|
|
RunCmd("git", params)
|
|
|
|
dir_list = []
|
|
|
|
with open(temp_diff_output) as file:
|
|
|
|
dir_list = file.read().strip().split('\n')
|
|
|
|
|
2020-06-18 12:52:58 +02:00
|
|
|
modify_dir_list = []
|
|
|
|
for modify_dir in dir_list:
|
2021-11-23 06:29:38 +01:00
|
|
|
#
|
|
|
|
# Parse file name from the end of the line
|
|
|
|
#
|
|
|
|
file_path = modify_dir.strip().split()
|
|
|
|
#
|
|
|
|
# Skip lines that do not have at least 2 elements (status and file name)
|
|
|
|
#
|
|
|
|
if len(file_path) < 2:
|
2020-06-18 12:52:58 +02:00
|
|
|
continue
|
2021-11-23 06:29:38 +01:00
|
|
|
#
|
|
|
|
# Parse the directory name from the file name
|
|
|
|
#
|
|
|
|
file_dir = os.path.dirname(file_path[-1])
|
|
|
|
#
|
.pytool/EccCheck: Trim leading path to modified directory
The code changes in the patch is for trimming the leading path
to the modified directory in the .pytool/EccCheck script.
This is necessary when running Ecc on other repositories,
such as edk2-platforms, where the platform package is located
in a subfolder, like Platform/AMD/AmdPlatformPkg.
The EccCheck script checks for modified directories and expects them to start with the package name.
#
# Skip directory names that do not start with the package being scanned.
#
if file_dir.split('/')[0] != pkg:
continue
However, if the package name is in a subfolder,
the "git diff" command gives a relative path,
like Platform/AMD, which causes the condition to be false.
"M Platform/AMD/AmdPlatformPkg/Universal/LogoDxe/Logo.c"
As a result, EccCheck does not happen on modified files.
To fix this issue, the leading path needs to be trimmed
so that it starts from the directory name.
This change will not affect the existing check for the edk2 repository,
where all package names are at the first level directory.
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Joey Vagedes <joey.vagedes@gmail.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
2024-08-31 11:19:30 +02:00
|
|
|
# strip the prefix path till the package name
|
|
|
|
#
|
|
|
|
if pkg in file_dir:
|
|
|
|
file_dir = file_dir[file_dir.find(pkg):]
|
|
|
|
#
|
2021-11-23 06:29:38 +01:00
|
|
|
# Skip directory names that do not start with the package being scanned.
|
|
|
|
#
|
|
|
|
if file_dir.split('/')[0] != pkg:
|
|
|
|
continue
|
|
|
|
#
|
|
|
|
# Skip directory names that are identical to the package being scanned.
|
|
|
|
# The assumption here is that there are no source files at the package
|
|
|
|
# root. Instead, the only expected files in the package root are
|
|
|
|
# EDK II meta data files (DEC, DSC, FDF).
|
|
|
|
#
|
|
|
|
if file_dir == pkg:
|
2020-06-18 12:52:58 +02:00
|
|
|
continue
|
2021-11-23 06:29:38 +01:00
|
|
|
#
|
|
|
|
# Skip directory names that are already in the modified dir list
|
|
|
|
#
|
|
|
|
if file_dir in modify_dir_list:
|
|
|
|
continue
|
|
|
|
#
|
|
|
|
# Add the candidate directory to scan to the modified dir list
|
|
|
|
#
|
|
|
|
modify_dir_list.append(file_dir)
|
2020-06-18 12:52:58 +02:00
|
|
|
|
2021-11-23 06:29:38 +01:00
|
|
|
#
|
|
|
|
# Remove duplicates from modify_dir_list
|
|
|
|
# Given a folder path, ECC performs a recursive scan of that folder.
|
|
|
|
# If a parent and child folder are both present in modify_dir_list,
|
|
|
|
# then ECC will perform redudanct scans of source files. In order
|
|
|
|
# to prevent redundant scans, if a parent and child folder are both
|
|
|
|
# present, then remove all the child folders.
|
|
|
|
#
|
|
|
|
# For example, if modified_dir_list contains the following elements:
|
|
|
|
# MdeModulePkg/Core/Dxe
|
|
|
|
# MdeModulePkg/Core/Dxe/Hand
|
|
|
|
# MdeModulePkg/Core/Dxe/Mem
|
|
|
|
#
|
|
|
|
# Then MdeModulePkg/Core/Dxe/Hand and MdeModulePkg/Core/Dxe/Mem should
|
|
|
|
# be removed because the files in those folders are covered by a scan
|
|
|
|
# of MdeModulePkg/Core/Dxe.
|
|
|
|
#
|
|
|
|
filtered_list = []
|
|
|
|
for dir1 in modify_dir_list:
|
|
|
|
Append = True
|
|
|
|
for dir2 in modify_dir_list:
|
|
|
|
if dir1 == dir2:
|
|
|
|
continue
|
|
|
|
common = os.path.commonpath([dir1, dir2])
|
|
|
|
if os.path.normpath(common) == os.path.normpath(dir2):
|
|
|
|
Append = False
|
|
|
|
break
|
|
|
|
if Append and dir1 not in filtered_list:
|
|
|
|
filtered_list.append(dir1)
|
|
|
|
return filtered_list
|
2020-06-18 12:52:58 +02:00
|
|
|
|
2021-11-23 06:13:41 +01:00
|
|
|
def GetDiffRange(self, patch_diff: List[str], pkg: str, temp_path: str) -> Dict[str, List[Tuple[int, int]]]:
|
2020-06-18 12:52:58 +02:00
|
|
|
IsDelete = True
|
|
|
|
StartCheck = False
|
|
|
|
range_directory: Dict[str, List[Tuple[int, int]]] = {}
|
|
|
|
for line in patch_diff:
|
|
|
|
modify_file = self.FindModifyFile.findall(line)
|
|
|
|
if modify_file and pkg in modify_file[0] and not StartCheck and os.path.isfile(modify_file[0]):
|
2021-11-23 06:13:41 +01:00
|
|
|
modify_file_comment_dic = self.GetCommentRange(modify_file[0], temp_path)
|
2020-06-18 12:52:58 +02:00
|
|
|
IsDelete = False
|
|
|
|
StartCheck = True
|
|
|
|
modify_file_dic = modify_file[0]
|
|
|
|
modify_file_dic = modify_file_dic.replace("/", os.sep)
|
|
|
|
range_directory[modify_file_dic] = []
|
|
|
|
elif line.startswith('--- '):
|
|
|
|
StartCheck = False
|
|
|
|
elif re.match(self.LineScopePattern, line, re.I) and not IsDelete and StartCheck:
|
|
|
|
start_line = self.LineNumRange.search(line).group(1)
|
|
|
|
line_range = self.LineNumRange.search(line).group(2)
|
|
|
|
if not line_range:
|
|
|
|
line_range = '1'
|
|
|
|
range_directory[modify_file_dic].append((int(start_line), int(start_line) + int(line_range) - 1))
|
|
|
|
for i in modify_file_comment_dic:
|
|
|
|
if int(i[0]) <= int(start_line) <= int(i[1]):
|
|
|
|
range_directory[modify_file_dic].append(i)
|
|
|
|
return range_directory
|
|
|
|
|
2021-11-23 06:13:41 +01:00
|
|
|
def GetCommentRange(self, modify_file: str, temp_path: str) -> List[Tuple[int, int]]:
|
|
|
|
comment_range: List[Tuple[int, int]] = []
|
|
|
|
modify_file_path = os.path.join(temp_path, modify_file)
|
|
|
|
if not os.path.exists (modify_file_path):
|
|
|
|
return comment_range
|
2020-06-18 12:52:58 +02:00
|
|
|
with open(modify_file_path) as f:
|
|
|
|
line_no = 1
|
|
|
|
Start = False
|
|
|
|
for line in f:
|
|
|
|
if line.startswith('/**'):
|
|
|
|
start_no = line_no
|
|
|
|
Start = True
|
|
|
|
if line.startswith('**/') and Start:
|
|
|
|
end_no = line_no
|
|
|
|
Start = False
|
|
|
|
comment_range.append((int(start_no), int(end_no)))
|
|
|
|
line_no += 1
|
|
|
|
|
|
|
|
if comment_range and comment_range[0][0] == 1:
|
|
|
|
del comment_range[0]
|
|
|
|
return comment_range
|
|
|
|
|
|
|
|
def GenerateEccReport(self, modify_dir_list: List[str], ecc_diff_range: Dict[str, List[Tuple[int, int]]],
|
2021-11-23 06:13:41 +01:00
|
|
|
temp_path: str, basetools_path: str) -> None:
|
2020-06-18 12:52:58 +02:00
|
|
|
ecc_need = False
|
|
|
|
ecc_run = True
|
2021-11-23 06:13:41 +01:00
|
|
|
config = os.path.normpath(os.path.join(basetools_path, "Source", "Python", "Ecc", "config.ini"))
|
|
|
|
exception = os.path.normpath(os.path.join(temp_path, "exception.xml"))
|
|
|
|
report = os.path.normpath(os.path.join(temp_path, "Ecc.csv"))
|
2020-06-18 12:52:58 +02:00
|
|
|
for modify_dir in modify_dir_list:
|
2021-11-23 06:13:41 +01:00
|
|
|
target = os.path.normpath(os.path.join(temp_path, modify_dir))
|
2020-06-18 12:52:58 +02:00
|
|
|
logging.info('Run ECC tool for the commit in %s' % modify_dir)
|
|
|
|
ecc_need = True
|
|
|
|
ecc_params = "-c {0} -e {1} -t {2} -r {3}".format(config, exception, target, report)
|
2021-11-23 06:13:41 +01:00
|
|
|
return_code = RunCmd("Ecc", ecc_params, workingdir=temp_path)
|
2020-06-18 12:52:58 +02:00
|
|
|
if return_code != 0:
|
|
|
|
ecc_run = False
|
|
|
|
break
|
|
|
|
if not ecc_run:
|
|
|
|
logging.error('Fail to run ECC tool')
|
2021-11-23 06:13:41 +01:00
|
|
|
self.ParseEccReport(ecc_diff_range, temp_path)
|
2020-06-18 12:52:58 +02:00
|
|
|
|
|
|
|
if not ecc_need:
|
|
|
|
logging.info("Doesn't need run ECC check")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
2021-11-23 06:13:41 +01:00
|
|
|
def ParseEccReport(self, ecc_diff_range: Dict[str, List[Tuple[int, int]]], temp_path: str) -> None:
|
|
|
|
ecc_log = os.path.join(temp_path, "Ecc.log")
|
|
|
|
ecc_csv = os.path.join(temp_path, "Ecc.csv")
|
2020-06-18 12:52:58 +02:00
|
|
|
row_lines = []
|
|
|
|
ignore_error_code = self.GetIgnoreErrorCode()
|
2021-07-06 22:55:40 +02:00
|
|
|
if os.path.exists(ecc_csv):
|
2020-06-18 12:52:58 +02:00
|
|
|
with open(ecc_csv) as csv_file:
|
|
|
|
reader = csv.reader(csv_file)
|
|
|
|
for row in reader:
|
|
|
|
for modify_file in ecc_diff_range:
|
|
|
|
if modify_file in row[3]:
|
|
|
|
for i in ecc_diff_range[modify_file]:
|
|
|
|
line_no = int(row[4])
|
|
|
|
if i[0] <= line_no <= i[1] and row[1] not in ignore_error_code:
|
|
|
|
row[0] = '\nEFI coding style error'
|
|
|
|
row[1] = 'Error code: ' + row[1]
|
|
|
|
row[3] = 'file: ' + row[3]
|
|
|
|
row[4] = 'Line number: ' + row[4]
|
|
|
|
row_line = '\n *'.join(row)
|
|
|
|
row_lines.append(row_line)
|
|
|
|
break
|
|
|
|
break
|
|
|
|
if row_lines:
|
|
|
|
self.ECC_PASS = False
|
|
|
|
|
|
|
|
with open(ecc_log, 'a') as log:
|
|
|
|
all_line = '\n'.join(row_lines)
|
|
|
|
all_line = all_line + '\n'
|
|
|
|
log.writelines(all_line)
|
|
|
|
return
|
|
|
|
|
2021-11-23 06:13:41 +01:00
|
|
|
def ApplyConfig(self, pkgconfig: Dict[str, List[str]], temp_path: str, pkg: str) -> None:
|
2020-06-18 12:52:58 +02:00
|
|
|
if "IgnoreFiles" in pkgconfig:
|
|
|
|
for a in pkgconfig["IgnoreFiles"]:
|
2021-11-23 06:13:41 +01:00
|
|
|
a = os.path.join(temp_path, pkg, a)
|
2020-06-18 12:52:58 +02:00
|
|
|
a = a.replace(os.sep, "/")
|
|
|
|
|
|
|
|
logging.info("Ignoring Files {0}".format(a))
|
|
|
|
if os.path.exists(a):
|
|
|
|
if os.path.isfile(a):
|
2021-11-23 06:13:41 +01:00
|
|
|
os.remove(a)
|
2020-06-18 12:52:58 +02:00
|
|
|
elif os.path.isdir(a):
|
|
|
|
shutil.rmtree(a)
|
|
|
|
else:
|
|
|
|
logging.error("EccCheck.IgnoreInf -> {0} not found in filesystem. Invalid ignore files".format(a))
|
|
|
|
|
|
|
|
if "ExceptionList" in pkgconfig:
|
|
|
|
exception_list = pkgconfig["ExceptionList"]
|
2021-11-23 06:13:41 +01:00
|
|
|
exception_xml = os.path.join(temp_path, "exception.xml")
|
2020-06-18 12:52:58 +02:00
|
|
|
try:
|
|
|
|
logging.info("Appending exceptions")
|
|
|
|
self.AppendException(exception_list, exception_xml)
|
|
|
|
except Exception as e:
|
|
|
|
logging.error("Fail to apply exceptions")
|
|
|
|
raise e
|
|
|
|
return
|
|
|
|
|
|
|
|
def AppendException(self, exception_list: List[str], exception_xml: str) -> None:
|
|
|
|
error_code_list = exception_list[::2]
|
|
|
|
keyword_list = exception_list[1::2]
|
|
|
|
dom_tree = xml.dom.minidom.parse(exception_xml)
|
|
|
|
root_node = dom_tree.documentElement
|
|
|
|
for error_code, keyword in zip(error_code_list, keyword_list):
|
|
|
|
customer_node = dom_tree.createElement("Exception")
|
|
|
|
keyword_node = dom_tree.createElement("KeyWord")
|
|
|
|
keyword_node_text_value = dom_tree.createTextNode(keyword)
|
|
|
|
keyword_node.appendChild(keyword_node_text_value)
|
|
|
|
customer_node.appendChild(keyword_node)
|
|
|
|
error_code_node = dom_tree.createElement("ErrorID")
|
|
|
|
error_code_text_value = dom_tree.createTextNode(error_code)
|
|
|
|
error_code_node.appendChild(error_code_text_value)
|
|
|
|
customer_node.appendChild(error_code_node)
|
|
|
|
root_node.appendChild(customer_node)
|
|
|
|
with open(exception_xml, 'w') as f:
|
|
|
|
dom_tree.writexml(f, indent='', addindent='', newl='\n', encoding='UTF-8')
|
|
|
|
return
|
|
|
|
|
|
|
|
def GetIgnoreErrorCode(self) -> set:
|
|
|
|
"""
|
|
|
|
Below are kinds of error code that are accurate in ecc scanning of edk2 level.
|
|
|
|
But EccCheck plugin is partial scanning so they are always false positive issues.
|
|
|
|
The mapping relationship of error code and error message is listed BaseTools/Sourc/Python/Ecc/EccToolError.py
|
|
|
|
"""
|
|
|
|
ignore_error_code = {
|
|
|
|
"10000",
|
|
|
|
"10001",
|
|
|
|
"10002",
|
|
|
|
"10003",
|
|
|
|
"10004",
|
|
|
|
"10005",
|
|
|
|
"10006",
|
|
|
|
"10007",
|
|
|
|
"10008",
|
|
|
|
"10009",
|
|
|
|
"10010",
|
|
|
|
"10011",
|
|
|
|
"10012",
|
|
|
|
"10013",
|
|
|
|
"10015",
|
|
|
|
"10016",
|
|
|
|
"10017",
|
|
|
|
"10022",
|
|
|
|
}
|
|
|
|
return ignore_error_code
|