Skip to content

Commit

Permalink
edk2_pr_eval: Add Policy 5 (#476)
Browse files Browse the repository at this point in the history
Policy 5 is used when a library INF has been changed. Policy 5 will parse each package's dsc (Found via <pkg>.ci.yaml::PrEval.DscPath) and mark a package to be built if that package has a dependency on the changed library INF.

Consuming repo's must update each package's ci.yaml file to now include a new top-level section "PrEval" with an entry "DscPath". This will be the package's DSC used to compile all components and libraries the package provides.
  • Loading branch information
Javagedes authored May 26, 2023
1 parent 485ec15 commit 6708666
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 6 deletions.
37 changes: 37 additions & 0 deletions edk2toolext/invocables/edk2_pr_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
file. This provides platform specific information to Edk2PrEval invocable
while allowing the invocable itself to remain platform agnostic.
"""
import yaml
import os
import logging
from io import StringIO
Expand Down Expand Up @@ -306,6 +307,26 @@ def get_packages_to_build(self, possible_packages: list) -> dict:
remaining_packages.remove(p) # remove from remaining packages
break

#
# Policy 5: If a file changed is a Library INF file, then build all packages that depend on that Library
# Only supported on packages with a ci.dsc file which contains PrEval.DscPath section.
#
for f in filter(lambda f: Path(f).suffix == ".inf", files):
for p in remaining_packages[:]:
dsc, defines = self._get_package_ci_information(p)
if not dsc:
logging.debug(f"Policy 5 - Package {p} skipped due to missing ci.dsc file or missing DscPath"
"section of the PrEval settings.")
continue

dsc_parser = DscParser()
dsc_parser.SetEdk2Path(self.edk2_path_obj).SetInputVars(defines)
dsc_parser.ParseFile(dsc)

if f in dsc_parser.Libs:
packages_to_build[p] = f"Policy 5 - Package depends on Library {f}"
remaining_packages.remove(p)

# All done now return result

return packages_to_build
Expand Down Expand Up @@ -479,6 +500,22 @@ def _walk_dir_for_filetypes(self, extensionlist, directory, ignorelist=None):

return returnlist

def _get_package_ci_information(self, pkg_name: str) -> str:
pkg_path = Path(self.edk2_path_obj.GetAbsolutePathOnThisSystemFromEdk2RelativePath(pkg_name))
ci_file = pkg_path.joinpath(f'{pkg_name}.ci.yaml')
dsc = None
defines = None

if not ci_file.exists():
return (None, None)

with open(ci_file, 'r') as f:
data = yaml.safe_load(f)
dsc = data.get("PrEval", {"DscPath": None})["DscPath"]
dsc = str(pkg_path / dsc) if dsc else None
defines = data.get("Defines", {})
return (dsc, defines)


def main():
"""Entry point to invoke Edk2PrEval."""
Expand Down
29 changes: 27 additions & 2 deletions tests.integration/edk2_stuart_pr_eval.robot
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ Test Stuart PR for Policy 1 special files in PrEvalSettingsManager

[Teardown] Delete branch ${branch_name} ${default_branch} ${ws_root}

Test Stuart PR for Policy 2 in package change of private inf file
Test Stuart PR for Policy 2 in package change of private file
[Tags] PrEval Edk2
${branch_name}= Set Variable PR_Rand_${{random.randint(0, 10000)}}
${file_to_modify}= Set Variable MdePkg${/}Library${/}BaseLib${/}BaseLib.inf
${file_to_modify}= Set Variable MdePkg${/}Library${/}BaseLib${/}Cpu.c

Reset git repo to default branch ${ws_root} ${default_branch}
Make new branch ${branch_name} ${ws_root}
Expand Down Expand Up @@ -195,6 +195,31 @@ Test Stuart PR for Policy 4 module c file changed that platform dsc does not dep

[Teardown] Delete branch ${branch_name} ${default_branch} ${ws_root}

Test Stuart PR for Policy 5 library inf changed
[Tags] PrEval Edk2
${branch_name}= Set Variable PR_Rand_${{random.randint(0, 10000)}}
${file_to_modify}= Set Variable MdePkg${/}Library${/}BaseLib${/}BaseLib.inf

Reset git repo to default branch ${ws_root} ${default_branch}
Make new branch ${branch_name} ${ws_root}

Append To File ${ws_root}${/}${file_to_modify}
... Hello World!! Making a change for fun.

Stage changed file ${file_to_modify} ${ws_root}
Commit changes "Changes" ${ws_root}

# Core CI test same package # policy 2
${pkgs}= Stuart pr evaluation ${core_ci_file} MdePkg ${default_branch} ${EMPTY} ${ws_root}
Confirm same contents ${pkgs} MdePkg

# Core CI test another package and make sure a it doesn't need to build
${pkgs}= Stuart pr evaluation ${core_ci_file} MdeModulePkg ${default_branch} ${EMPTY} ${ws_root}
Confirm same contents ${pkgs} MdeModulePkg

[Teardown] Delete branch ${branch_name} ${default_branch} ${ws_root}

Test Stuart PR for all policies when a PR contains a deleted file
[Tags] PrEval Delete Edk2
Expand Down
33 changes: 29 additions & 4 deletions tests.integration/mu_stuart_pr_eval.robot
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ Test Stuart PR using ProjectMu for Policy 1 special files in PrEvalSettingsManag

[Teardown] Delete branch ${branch_name} ${default_branch} ${ws_root}

Test Stuart PR using ProjectMu for Policy 2 in package change of private inf file
Test Stuart PR using ProjectMu for Policy 2 in package change of private file
[Tags] PrEval ProjectMu
${branch_name}= Set Variable PR_Rand_${{random.randint(0, 10000)}}
${file_to_modify}= Set Variable MdePkg${/}Library${/}BaseLib${/}BaseLib.inf
${file_to_modify}= Set Variable MdePkg${/}Library${/}BaseLib${/}Cpu.c

Reset git repo to default branch ${ws_root} ${default_branch}
Make new branch ${branch_name} ${ws_root}
Expand Down Expand Up @@ -162,6 +162,31 @@ Test Stuart PR using ProjectMu for Policy 3 for package dependency on change of

[Teardown] Delete branch ${branch_name} ${default_branch} ${ws_root}

Test Stuart PR using ProjectMu for Policy 5 library inf changed
[Tags] PrEval ProjectMu
${branch_name}= Set Variable PR_Rand_${{random.randint(0, 10000)}}
${file_to_modify}= Set Variable MdePkg${/}Library${/}BaseLib${/}BaseLib.inf

Reset git repo to default branch ${ws_root} ${default_branch}
Make new branch ${branch_name} ${ws_root}

Append To File ${ws_root}${/}${file_to_modify}
... Hello World!! Making a change for fun.

Stage changed file ${file_to_modify} ${ws_root}
Commit changes "Changes" ${ws_root}

# Core CI test same package # policy 2
${pkgs}= Stuart pr evaluation ${core_ci_file} MdePkg ${default_branch} ${EMPTY} ${ws_root}
Confirm same contents ${pkgs} MdePkg

# Core CI test another package and make sure a it doesn't need to build
${pkgs}= Stuart pr evaluation ${core_ci_file} MdeModulePkg ${default_branch} ${EMPTY} ${ws_root}
Confirm same contents ${pkgs} MdeModulePkg

[Teardown] Delete branch ${branch_name} ${default_branch} ${ws_root}

Test Stuart PR using ProjectMu for all policies when a PR contains a deleted file
[Tags] PrEval Delete ProjectMu
Expand Down Expand Up @@ -195,9 +220,9 @@ Test Stuart PR using ProjectMu for all policies when a PR contains a deleted fol
Stage changed file ${file_to_modify} ${ws_root}
Commit changes "Changes" ${ws_root}

# Platform CI test DSC dependency on implementation file # Policy 4
# PcAtChipsetPkg uses BasePrintLib/BasePrintLib.inf, Policy 5 requires it be built
${pkgs}= Stuart pr evaluation ${core_ci_file} PcAtChipsetPkg ${default_branch} ${EMPTY} ${ws_root}
Should Be Empty ${pkgs}
Confirm same contents ${pkgs} PcAtChipsetPkg

[Teardown] Delete branch ${branch_name} ${default_branch} ${ws_root}

Expand Down

0 comments on commit 6708666

Please sign in to comment.