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