]> git.proxmox.com Git - mirror_edk2.git/blob - .pytool/CISettings.py
6f7daeca076bef97380ccdc4f745e3b72f13d6b9
[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 "ArmVirtPkg",
54 "DynamicTablesPkg",
55 "EmulatorPkg",
56 "MdePkg",
57 "MdeModulePkg",
58 "NetworkPkg",
59 "PcAtChipsetPkg",
60 "SecurityPkg",
61 "UefiCpuPkg",
62 "FmpDevicePkg",
63 "ShellPkg",
64 "StandaloneMmPkg",
65 "FatPkg",
66 "CryptoPkg",
67 "UnitTestFrameworkPkg",
68 "OvmfPkg",
69 "RedfishPkg"
70 )
71
72 def GetArchitecturesSupported(self):
73 ''' return iterable of edk2 architectures supported by this build '''
74 return (
75 "IA32",
76 "X64",
77 "ARM",
78 "AARCH64",
79 "RISCV64")
80
81 def GetTargetsSupported(self):
82 ''' return iterable of edk2 target tags supported by this build '''
83 return ("DEBUG", "RELEASE", "NO-TARGET", "NOOPT")
84
85 # ####################################################################################### #
86 # Verify and Save requested Ci Build Config #
87 # ####################################################################################### #
88
89 def SetPackages(self, list_of_requested_packages):
90 ''' Confirm the requested package list is valid and configure SettingsManager
91 to build the requested packages.
92
93 Raise UnsupportedException if a requested_package is not supported
94 '''
95 unsupported = set(list_of_requested_packages) - \
96 set(self.GetPackagesSupported())
97 if(len(unsupported) > 0):
98 logging.critical(
99 "Unsupported Package Requested: " + " ".join(unsupported))
100 raise Exception("Unsupported Package Requested: " +
101 " ".join(unsupported))
102 self.ActualPackages = list_of_requested_packages
103
104 def SetArchitectures(self, list_of_requested_architectures):
105 ''' Confirm the requests architecture list is valid and configure SettingsManager
106 to run only the requested architectures.
107
108 Raise Exception if a list_of_requested_architectures is not supported
109 '''
110 unsupported = set(list_of_requested_architectures) - \
111 set(self.GetArchitecturesSupported())
112 if(len(unsupported) > 0):
113 logging.critical(
114 "Unsupported Architecture Requested: " + " ".join(unsupported))
115 raise Exception(
116 "Unsupported Architecture Requested: " + " ".join(unsupported))
117 self.ActualArchitectures = list_of_requested_architectures
118
119 def SetTargets(self, list_of_requested_target):
120 ''' Confirm the request target list is valid and configure SettingsManager
121 to run only the requested targets.
122
123 Raise UnsupportedException if a requested_target is not supported
124 '''
125 unsupported = set(list_of_requested_target) - \
126 set(self.GetTargetsSupported())
127 if(len(unsupported) > 0):
128 logging.critical(
129 "Unsupported Targets Requested: " + " ".join(unsupported))
130 raise Exception("Unsupported Targets Requested: " +
131 " ".join(unsupported))
132 self.ActualTargets = list_of_requested_target
133
134 # ####################################################################################### #
135 # Actual Configuration for Ci Build #
136 # ####################################################################################### #
137
138 def GetActiveScopes(self):
139 ''' return tuple containing scopes that should be active for this process '''
140 if self.ActualScopes is None:
141 scopes = ("cibuild", "edk2-build", "host-based-test")
142
143 self.ActualToolChainTag = shell_environment.GetBuildVars().GetValue("TOOL_CHAIN_TAG", "")
144
145 is_linux = GetHostInfo().os.upper() == "LINUX"
146
147 if self.UseBuiltInBaseTools is None:
148 is_linux = GetHostInfo().os.upper() == "LINUX"
149 # try and import the pip module for basetools
150 try:
151 import edk2basetools
152 self.UseBuiltInBaseTools = True
153 except ImportError:
154 self.UseBuiltInBaseTools = False
155 pass
156
157 if self.UseBuiltInBaseTools == True:
158 scopes += ('pipbuild-unix',) if is_linux else ('pipbuild-win',)
159 logging.warning("Using Pip Tools based BaseTools")
160 else:
161 logging.warning("Falling back to using in-tree BaseTools")
162
163 if is_linux and self.ActualToolChainTag.upper().startswith("GCC"):
164 if "AARCH64" in self.ActualArchitectures:
165 scopes += ("gcc_aarch64_linux",)
166 if "ARM" in self.ActualArchitectures:
167 scopes += ("gcc_arm_linux",)
168 if "RISCV64" in self.ActualArchitectures:
169 scopes += ("gcc_riscv64_unknown",)
170 self.ActualScopes = scopes
171 return self.ActualScopes
172
173 def GetRequiredSubmodules(self):
174 ''' return iterable containing RequiredSubmodule objects.
175 If no RequiredSubmodules return an empty iterable
176 '''
177 rs = []
178 rs.append(RequiredSubmodule(
179 "ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3", False))
180 rs.append(RequiredSubmodule(
181 "CryptoPkg/Library/OpensslLib/openssl", False))
182 rs.append(RequiredSubmodule(
183 "UnitTestFrameworkPkg/Library/CmockaLib/cmocka", False))
184 rs.append(RequiredSubmodule(
185 "MdeModulePkg/Universal/RegularExpressionDxe/oniguruma", False))
186 rs.append(RequiredSubmodule(
187 "MdeModulePkg/Library/BrotliCustomDecompressLib/brotli", False))
188 rs.append(RequiredSubmodule(
189 "BaseTools/Source/C/BrotliCompress/brotli", False))
190 rs.append(RequiredSubmodule(
191 "RedfishPkg/Library/JsonLib/jansson", False))
192 return rs
193
194 def GetName(self):
195 return "Edk2"
196
197 def GetDependencies(self):
198 return [
199 ]
200
201 def GetPackagesPath(self):
202 return ()
203
204 def GetWorkspaceRoot(self):
205 ''' get WorkspacePath '''
206 return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
207
208 def FilterPackagesToTest(self, changedFilesList: list, potentialPackagesList: list) -> list:
209 ''' Filter potential packages to test based on changed files. '''
210 build_these_packages = []
211 possible_packages = potentialPackagesList.copy()
212 for f in changedFilesList:
213 # split each part of path for comparison later
214 nodes = f.split("/")
215
216 # python file change in .pytool folder causes building all
217 if f.endswith(".py") and ".pytool" in nodes:
218 build_these_packages = possible_packages
219 break
220
221 # BaseTools files that might change the build
222 if "BaseTools" in nodes:
223 if os.path.splitext(f) not in [".txt", ".md"]:
224 build_these_packages = possible_packages
225 break
226 return build_these_packages