forked from tianocore/edk2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I185c8956dfe803b1f202c5a005b5e0cc80aadc2e Signed-off-by: Shenglei Zhang <[email protected]>
- Loading branch information
1 parent
ec9247e
commit 20957b8
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import os | ||
import logging | ||
import re | ||
from io import StringIO | ||
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin | ||
from edk2toolext.environment.var_dict import VarDict | ||
from edk2toollib.utility_functions import RunCmd | ||
|
||
class LicenseCheck(ICiBuildPlugin): | ||
|
||
""" | ||
A CiBuildPlugin to check the license for new added files. | ||
Configuration options: | ||
"LicenseCheck": { | ||
"IgnoreFiles": [] | ||
}, | ||
""" | ||
|
||
license_format_preflix = 'SPDX-License-Identifier' | ||
|
||
bsd2_patent = 'BSD-2-Clause-Patent' | ||
|
||
bsd3_patent = 'BSD-3-Clause-Patent' | ||
|
||
Readdedfileformat = re.compile(r'\+\+\+ b\/(.*)\n') | ||
|
||
file_extension_list = [".c", ".h", ".inf", ".dsc", ".dec", ".py", ".bat", ".sh", ".uni", ".yaml", ".fdf", ".inc", "yml", ".asm", \ | ||
".asm16", ".asl", ".vfr", ".s", ".S", ".aslc", ".nasm", ".nasmb", ".idf", ".Vfr", ".H"] | ||
|
||
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 license for " + packagename, packagename + ".LicenseCheck") | ||
|
||
## | ||
# 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): | ||
edk2_path = Edk2pathObj.WorkspacePath | ||
|
||
return_buffer = StringIO() | ||
params = "diff --unified=0 origin/master HEAD" | ||
RunCmd("git", params, outstream=return_buffer) | ||
p = return_buffer.getvalue().strip() | ||
patch = p.split("\n") | ||
return_buffer.close() | ||
|
||
if "IgnoreFiles" in pkgconfig: | ||
ignore_files = pkgconfig["IgnoreFiles"] | ||
|
||
self.ok = True | ||
self.startcheck = False | ||
self.license = True | ||
line_index = 0 | ||
for line in patch: | ||
if line.startswith('--- /dev/null'): | ||
nextline = patch[line_index + 1] | ||
added_file = self.Readdedfileformat.search(nextline).group(1) | ||
for f in ignore_files: | ||
if f in added_file: | ||
continue | ||
added_file_extension = os.path.splitext(added_file)[1] | ||
if added_file_extension in self.file_extension_list: | ||
self.startcheck = True | ||
self.license = False | ||
if self.startcheck and self.license_format_preflix in line: | ||
if self.bsd2_patent in line or self.bsd3_patent in line: | ||
self.license = True | ||
if line_index + 1 == count or patch[line_index + 1].startswith('diff --') and self.startcheck: | ||
if not self.license: | ||
error_message = "Invalid License in: " + added_file | ||
logging.error(error_message) | ||
self.startcheck = False | ||
self.license = True | ||
line_index = line_index + 1 | ||
|
||
if self.license: | ||
return 0 | ||
else: | ||
return 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## @file | ||
# CiBuildPlugin used to check char encoding | ||
# | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
## | ||
{ | ||
"scope": "cibuild", | ||
"name": "License Check Test", | ||
"module": "LicenseCheck" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Character Encoding Check Plugin | ||
|
||
This CiBuildPlugin scans all the files in a package to make sure each file is | ||
correctly encoded and all characters can be read. Improper encoding causes | ||
tools to fail in some situations especially in different locals. | ||
|
||
## Configuration | ||
|
||
The plugin can be configured to ignore certain files. | ||
|
||
``` yaml | ||
"CharEncodingCheck": { | ||
"IgnoreFiles": [] | ||
} | ||
``` | ||
### IgnoreFiles | ||
|
||
OPTIONAL List of file to ignore. |