]> git.proxmox.com Git - mirror_edk2.git/blob - .pytool/CISettings.py
UnitTestFrameworkPkg: Change OPTIONAL keyword usage style
[mirror_edk2.git] / .pytool / CISettings.py
1 # @file
2 #
3 # Copyright (c) Microsoft Corporation.
4 # Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
5 # Copyright (c) 2020 - 2021, ARM Limited. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
7 ##
8 import os
9 import logging
10 from edk2toolext.environment import shell_environment
11 from edk2toolext.invocables.edk2_ci_build import CiBuildSettingsManager
12 from edk2toolext.invocables.edk2_setup import SetupSettingsManager, RequiredSubmodule
13 from edk2toolext.invocables.edk2_update import UpdateSettingsManager
14 from edk2toolext.invocables.edk2_pr_eval import PrEvalSettingsManager
15 from edk2toollib.utility_functions import GetHostInfo
16
17
18 class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManager, PrEvalSettingsManager):
19
20 def __init__(self):
21 self.ActualPackages = []
22 self.ActualTargets = []
23 self.ActualArchitectures = []
24 self.ActualToolChainTag = ""
25 self.UseBuiltInBaseTools = None
26 self.ActualScopes = None
27
28 # ####################################################################################### #
29 # Extra CmdLine configuration #
30 # ####################################################################################### #
31
32 def AddCommandLineOptions(self, parserObj):
33 group = parserObj.add_mutually_exclusive_group()
34 group.add_argument("-force_piptools", "--fpt", dest="force_piptools", action="store_true", default=False, help="Force the system to use pip tools")
35 group.add_argument("-no_piptools", "--npt", dest="no_piptools", action="store_true", default=False, help="Force the system to not use pip tools")
36
37 def RetrieveCommandLineOptions(self, args):
38 super().RetrieveCommandLineOptions(args)
39 if args.force_piptools:
40 self.UseBuiltInBaseTools = True
41 if args.no_piptools:
42 self.UseBuiltInBaseTools = False
43
44 # ####################################################################################### #
45 # Default Support for this Ci Build #
46 # ####################################################################################### #
47
48 def GetPackagesSupported(self):
49 ''' return iterable of edk2 packages supported by this build.
50 These should be edk2 workspace relative paths '''
51
52 return ("ArmPkg",
53 "ArmPlatformPkg",
54 "ArmVirtPkg",
55 "DynamicTablesPkg",
56 "EmulatorPkg",
57 "MdePkg",
58 "MdeModulePkg",
59 "NetworkPkg",
60 "PcAtChipsetPkg",
61 "SecurityPkg",
62 "UefiCpuPkg",
63 "FmpDevicePkg",
64 "ShellPkg",
65 "StandaloneMmPkg",
66 "FatPkg",
67 "CryptoPkg",
68 "UnitTestFrameworkPkg",
69 "OvmfPkg",
70 "RedfishPkg",
71 "UefiPayloadPkg"
72 )
73
74 def GetArchitecturesSupported(self):
75 ''' return iterable of edk2 architectures supported by this build '''
76 return (
77 "IA32",
78 "X64",
79 "ARM",
80 "AARCH64",
81 "RISCV64")
82
83 def GetTargetsSupported(self):
84 ''' return iterable of edk2 target tags supported by this build '''
85 return ("DEBUG", "RELEASE", "NO-TARGET", "NOOPT")
86
87 # ####################################################################################### #
88 # Verify and Save requested Ci Build Config #
89 # ####################################################################################### #
90
91 def SetPackages(self, list_of_requested_packages):
92 ''' Confirm the requested package list is valid and configure SettingsManager
93 to build the requested packages.
94
95 Raise UnsupportedException if a requested_package is not supported
96 '''
97 unsupported = set(list_of_requested_packages) - \
98 set(self.GetPackagesSupported())
99 if(len(unsupported) > 0):
100 logging.critical(
101 "Unsupported Package Requested: " + " ".join(unsupported))
102 raise Exception("Unsupported Package Requested: " +
103 " ".join(unsupported))
104 self.ActualPackages = list_of_requested_packages
105
106 def SetArchitectures(self, list_of_requested_architectures):
107 ''' Confirm the requests architecture list is valid and configure SettingsManager
108 to run only the requested architectures.
109
110 Raise Exception if a list_of_requested_architectures is not supported
111 '''
112 unsupported = set(list_of_requested_architectures) - \
113 set(self.GetArchitecturesSupported())
114 if(len(unsupported) > 0):
115 logging.critical(
116 "Unsupported Architecture Requested: " + " ".join(unsupported))
117 raise Exception(
118 "Unsupported Architecture Requested: " + " ".join(unsupported))
119 self.ActualArchitectures = list_of_requested_architectures
120
121 def SetTargets(self, list_of_requested_target):
122 ''' Confirm the request target list is valid and configure SettingsManager
123 to run only the requested targets.
124
125 Raise UnsupportedException if a requested_target is not supported
126 '''
127 unsupported = set(list_of_requested_target) - \
128 set(self.GetTargetsSupported())
129 if(len(unsupported) > 0):
130 logging.critical(
131 "Unsupported Targets Requested: " + " ".join(unsupported))
132 raise Exception("Unsupported Targets Requested: " +
133 " ".join(unsupported))
134 self.ActualTargets = list_of_requested_target
135
136 # ####################################################################################### #
137 # Actual Configuration for Ci Build #
138 # ####################################################################################### #
139
140 def GetActiveScopes(self):
141 ''' return tuple containing scopes that should be active for this process '''
142 if self.ActualScopes is None:
143 scopes = ("cibuild", "edk2-build", "host-based-test")
144
145 self.ActualToolChainTag = shell_environment.GetBuildVars().GetValue("TOOL_CHAIN_TAG", "")
146
147 is_linux = GetHostInfo().os.upper() == "LINUX"
148
149 if self.UseBuiltInBaseTools is None:
150 is_linux = GetHostInfo().os.upper() == "LINUX"
151 # try and import the pip module for basetools
152 try:
153 import edk2basetools
154 self.UseBuiltInBaseTools = True
155 except ImportError:
156 self.UseBuiltInBaseTools = False
157 pass
158
159 if self.UseBuiltInBaseTools == True:
160 scopes += ('pipbuild-unix',) if is_linux else ('pipbuild-win',)
161 logging.warning("Using Pip Tools based BaseTools")
162 else:
163 logging.warning("Falling back to using in-tree BaseTools")
164
165 if is_linux and self.ActualToolChainTag.upper().startswith("GCC"):
166 if "AARCH64" in self.ActualArchitectures:
167 scopes += ("gcc_aarch64_linux",)
168 if "ARM" in self.ActualArchitectures:
169 scopes += ("gcc_arm_linux",)
170 if "RISCV64" in self.ActualArchitectures:
171 scopes += ("gcc_riscv64_unknown",)
172 self.ActualScopes = scopes
173 return self.ActualScopes
174
175 def GetRequiredSubmodules(self):
176 ''' return iterable containing RequiredSubmodule objects.
177 If no RequiredSubmodules return an empty iterable
178 '''
179 rs = []
180 rs.append(RequiredSubmodule(
181 "ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3", False))
182 rs.append(RequiredSubmodule(
183 "CryptoPkg/Library/OpensslLib/openssl", False))
184 rs.append(RequiredSubmodule(
185 "UnitTestFrameworkPkg/Library/CmockaLib/cmocka", False))
186 rs.append(RequiredSubmodule(
187 "MdeModulePkg/Universal/RegularExpressionDxe/oniguruma", False))
188 rs.append(RequiredSubmodule(
189 "MdeModulePkg/Library/BrotliCustomDecompressLib/brotli", False))
190 rs.append(RequiredSubmodule(
191 "BaseTools/Source/C/BrotliCompress/brotli", False))
192 rs.append(RequiredSubmodule(
193 "RedfishPkg/Library/JsonLib/jansson", False))
194 return rs
195
196 def GetName(self):
197 return "Edk2"
198
199 def GetDependencies(self):
200 return [
201 ]
202
203 def GetPackagesPath(self):
204 return ()
205
206 def GetWorkspaceRoot(self):
207 ''' get WorkspacePath '''
208 return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
209
210 def FilterPackagesToTest(self, changedFilesList: list, potentialPackagesList: list) -> list:
211 ''' Filter potential packages to test based on changed files. '''
212 build_these_packages = []
213 possible_packages = potentialPackagesList.copy()
214 for f in changedFilesList:
215 # split each part of path for comparison later
216 nodes = f.split("/")
217
218 # python file change in .pytool folder causes building all
219 if f.endswith(".py") and ".pytool" in nodes:
220 build_these_packages = possible_packages
221 break
222
223 # BaseTools files that might change the build
224 if "BaseTools" in nodes:
225 if os.path.splitext(f) not in [".txt", ".md"]:
226 build_these_packages = possible_packages
227 break
228 return build_these_packages