]> git.proxmox.com Git - mirror_edk2.git/blob - .pytool/CISettings.py
.pytool: Add CISettings.py and Readme.md
[mirror_edk2.git] / .pytool / CISettings.py
1 # @file
2 #
3 # Copyright (c) Microsoft Corporation.
4 # SPDX-License-Identifier: BSD-2-Clause-Patent
5 ##
6 import os
7 import logging
8 from edk2toolext.environment import shell_environment
9 from edk2toolext.invocables.edk2_ci_build import CiBuildSettingsManager
10 from edk2toolext.invocables.edk2_setup import SetupSettingsManager, RequiredSubmodule
11 from edk2toolext.invocables.edk2_update import UpdateSettingsManager
12 from edk2toolext.invocables.edk2_pr_eval import PrEvalSettingsManager
13 from edk2toollib.utility_functions import GetHostInfo
14
15
16 class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManager, PrEvalSettingsManager):
17
18 def __init__(self):
19 self.ActualPackages = []
20 self.ActualTargets = []
21 self.ActualArchitectures = []
22 self.ActualToolChainTag = ""
23
24 # ####################################################################################### #
25 # Extra CmdLine configuration #
26 # ####################################################################################### #
27
28 def AddCommandLineOptions(self, parserObj):
29 pass
30
31 def RetrieveCommandLineOptions(self, args):
32 pass
33
34 # ####################################################################################### #
35 # Default Support for this Ci Build #
36 # ####################################################################################### #
37
38 def GetPackagesSupported(self):
39 ''' return iterable of edk2 packages supported by this build.
40 These should be edk2 workspace relative paths '''
41
42 return ("MdePkg",
43 "MdeModulePkg",
44 "NetworkPkg",
45 "PcAtChipsetPkg",
46 "SecurityPkg",
47 "UefiCpuPkg",
48 "FmpDevicePkg",
49 "ShellPkg",
50 "FatPkg",
51 "CryptoPkg"
52 )
53
54 def GetArchitecturesSupported(self):
55 ''' return iterable of edk2 architectures supported by this build '''
56 return ("IA32",
57 "X64",
58 "ARM",
59 "AARCH64")
60
61 def GetTargetsSupported(self):
62 ''' return iterable of edk2 target tags supported by this build '''
63 return ("DEBUG", "RELEASE", "NO-TARGET", "NOOPT")
64
65 # ####################################################################################### #
66 # Verify and Save requested Ci Build Config #
67 # ####################################################################################### #
68
69 def SetPackages(self, list_of_requested_packages):
70 ''' Confirm the requested package list is valid and configure SettingsManager
71 to build the requested packages.
72
73 Raise UnsupportedException if a requested_package is not supported
74 '''
75 unsupported = set(list_of_requested_packages) - \
76 set(self.GetPackagesSupported())
77 if(len(unsupported) > 0):
78 logging.critical(
79 "Unsupported Package Requested: " + " ".join(unsupported))
80 raise Exception("Unsupported Package Requested: " +
81 " ".join(unsupported))
82 self.ActualPackages = list_of_requested_packages
83
84 def SetArchitectures(self, list_of_requested_architectures):
85 ''' Confirm the requests architecture list is valid and configure SettingsManager
86 to run only the requested architectures.
87
88 Raise Exception if a list_of_requested_architectures is not supported
89 '''
90 unsupported = set(list_of_requested_architectures) - \
91 set(self.GetArchitecturesSupported())
92 if(len(unsupported) > 0):
93 logging.critical(
94 "Unsupported Architecture Requested: " + " ".join(unsupported))
95 raise Exception(
96 "Unsupported Architecture Requested: " + " ".join(unsupported))
97 self.ActualArchitectures = list_of_requested_architectures
98
99 def SetTargets(self, list_of_requested_target):
100 ''' Confirm the request target list is valid and configure SettingsManager
101 to run only the requested targets.
102
103 Raise UnsupportedException if a requested_target is not supported
104 '''
105 unsupported = set(list_of_requested_target) - \
106 set(self.GetTargetsSupported())
107 if(len(unsupported) > 0):
108 logging.critical(
109 "Unsupported Targets Requested: " + " ".join(unsupported))
110 raise Exception("Unsupported Targets Requested: " +
111 " ".join(unsupported))
112 self.ActualTargets = list_of_requested_target
113
114 # ####################################################################################### #
115 # Actual Configuration for Ci Build #
116 # ####################################################################################### #
117
118 def GetActiveScopes(self):
119 ''' return tuple containing scopes that should be active for this process '''
120 scopes = ("cibuild","edk2-build")
121
122 self.ActualToolChainTag = shell_environment.GetBuildVars().GetValue("TOOL_CHAIN_TAG", "")
123
124 if GetHostInfo().os.upper() == "LINUX" and self.ActualToolChainTag.upper().startswith("GCC"):
125 if "AARCH64" in self.ActualArchitectures:
126 scopes += ("gcc_aarch64_linux",)
127 if "ARM" in self.ActualArchitectures:
128 scopes += ("gcc_arm_linux",)
129
130 return scopes
131
132 def GetRequiredSubmodules(self):
133 ''' return iterable containing RequiredSubmodule objects.
134 If no RequiredSubmodules return an empty iterable
135 '''
136 rs=[]
137 rs.append(RequiredSubmodule(
138 "ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3", False))
139 rs.append(RequiredSubmodule(
140 "CryptoPkg/Library/OpensslLib/openssl", False))
141 return rs
142
143 def GetName(self):
144 return "Edk2"
145
146 def GetDependencies(self):
147 return []
148
149 def GetPackagesPath(self):
150 return ()
151
152 def GetWorkspaceRoot(self):
153 ''' get WorkspacePath '''
154 return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
155
156 def FilterPackagesToTest(self, changedFilesList: list, potentialPackagesList: list) -> list:
157 ''' Filter potential packages to test based on changed files. '''
158 build_these_packages=[]
159 possible_packages=potentialPackagesList.copy()
160 for f in changedFilesList:
161 nodes=f.split("/") # split each part of path for comparison later
162
163 # python file change in .pytool folder causes building all
164 if f.endswith(".py") and ".pytool" in nodes:
165 build_these_packages = possible_packages
166 break
167
168 # BaseTools files that might change the build
169 if "BaseTools" in nodes:
170 if os.path.splitext(f) not in [".txt", ".md"]:
171 build_these_packages = possible_packages
172 break
173 return build_these_packages