Skip to content

Commit 0b43a7d

Browse files
makubackiJavagedes
authored andcommitted
edk2_pr_eval: Consider build variables in Policy 4
Use build variables in Policy 4 as the default input variables to the DSC parser. Update the input variables with any explicitly set by the platform code in its implementation of `GetPlatformDscAndConfig()`. Require at least one target to be set. Signed-off-by: Michael Kubacki <[email protected]>
1 parent 3b21619 commit 0b43a7d

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed

edk2toolext/invocables/edk2_pr_eval.py

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from edk2toollib.utility_functions import RunCmd
3232

3333
from edk2toolext import edk2_logging
34+
from edk2toolext.environment import shell_environment
3435
from edk2toolext.invocables.edk2_multipkg_aware_invocable import (
3536
Edk2MultiPkgAwareInvocable,
3637
MultiPkgAwareSettingsInterface,
@@ -311,29 +312,46 @@ def get_packages_to_build(self, possible_packages: list) -> dict:
311312
if len(remaining_packages) != 1:
312313
raise Exception("Policy 4 can only be used by builds for a single package")
313314

314-
# files are all the files changed edk2 workspace root relative path
315-
changed_modules = self._get_unique_module_infs_changed(files)
316-
changed_modules = [Path(m) for m in changed_modules]
317-
318-
# now check DSC
319-
dsc = DscParser().SetEdk2Path(self.edk2_path_obj)
320-
# given that PR eval runs before dependencies are downloaded we must tolerate errors
321-
dsc.SetNoFailMode()
322-
dsc.SetInputVars(PlatformDscInfo[1])
323-
dsc.ParseFile(PlatformDscInfo[0])
324-
allinfs = dsc.OtherMods + dsc.ThreeMods + dsc.SixMods + dsc.Libs # get list of all INF files
325-
allinfs = [Path(i) for i in allinfs]
326-
327-
#
328-
# Note: for now we assume that remaining_packages has only 1 package and that it corresponds
329-
# to the DSC file provided.
330-
#
331-
for p in remaining_packages[:]: # slice so we can delete as we go
332-
for cm in changed_modules:
333-
if cm in allinfs: # is the changed module listed in the DSC file?
334-
packages_to_build[p] = f"Policy 4 - Package Dsc depends on {str(cm)}"
335-
remaining_packages.remove(p) # remove from remaining packages
336-
break
315+
if self.requested_target_list is None:
316+
raise ValueError("Policy 4 requires a target to be set.")
317+
318+
for target in self.requested_target_list:
319+
if target not in self.PlatformSettings.GetTargetsSupported():
320+
raise ValueError(f"Target {target} is not supported by this platform.")
321+
322+
# files are all the files changed edk2 workspace root relative path
323+
changed_modules = self._get_unique_module_infs_changed(files)
324+
changed_modules = [Path(m) for m in changed_modules]
325+
326+
# now check the DSC
327+
dsc = DscParser().SetEdk2Path(self.edk2_path_obj)
328+
# given that PR eval runs before dependencies are downloaded we must tolerate errors
329+
dsc.SetNoFailMode()
330+
331+
# start with any default values explicitly passed by the GetPlatformDscAndConfig() implementation
332+
input_vars = {}
333+
if PlatformDscInfo[1] is not None:
334+
input_vars.update(PlatformDscInfo[1])
335+
336+
# update with build variables resolved against the current target
337+
input_vars.update(shell_environment.GetBuildVars().GetAllBuildKeyValues(target))
338+
339+
dsc.SetInputVars(input_vars)
340+
dsc.ParseFile(PlatformDscInfo[0])
341+
342+
allinfs = dsc.OtherMods + dsc.ThreeMods + dsc.SixMods + dsc.Libs # get list of all INF files
343+
allinfs = [Path(i) for i in allinfs]
344+
345+
#
346+
# Note: for now we assume that remaining_packages has only 1 package and that it corresponds
347+
# to the DSC file provided.
348+
#
349+
for p in remaining_packages[:]: # slice so we can delete as we go
350+
for cm in changed_modules:
351+
if cm in allinfs: # is the changed module listed in the DSC file?
352+
packages_to_build[p] = f"Policy 4 - Package Dsc depends on {str(cm)}"
353+
remaining_packages.remove(p) # remove from remaining packages
354+
break
337355

338356
#
339357
# Policy 5: If a file changed is a Library INF file, then build all packages that depend on that Library

0 commit comments

Comments
 (0)