]>
Commit | Line | Data |
---|---|---|
673d09a2 FB |
1 | ## @file\r |
2 | # Create makefile for MS nmake and GNU make\r | |
3 | #\r | |
4 | # Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r | |
5 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | #\r | |
7 | from __future__ import absolute_import\r | |
8 | import multiprocessing as mp\r | |
9 | import threading\r | |
10 | from Common.Misc import PathClass\r | |
11 | from AutoGen.ModuleAutoGen import ModuleAutoGen\r | |
12 | from AutoGen.ModuleAutoGenHelper import WorkSpaceInfo,AutoGenInfo\r | |
13 | import Common.GlobalData as GlobalData\r | |
14 | import Common.EdkLogger as EdkLogger\r | |
15 | import os\r | |
16 | from Common.MultipleWorkspace import MultipleWorkspace as mws\r | |
17 | from AutoGen.AutoGen import AutoGen\r | |
18 | from Workspace.WorkspaceDatabase import BuildDB\r | |
19 | from queue import Empty\r | |
20 | import traceback\r | |
21 | import sys\r | |
22 | from AutoGen.DataPipe import MemoryDataPipe\r | |
23 | def clearQ(q):\r | |
24 | try:\r | |
25 | while True:\r | |
26 | q.get_nowait()\r | |
27 | except Empty:\r | |
28 | pass\r | |
29 | class AutoGenManager(threading.Thread):\r | |
30 | def __init__(self,autogen_workers, feedback_q,error_event):\r | |
31 | super(AutoGenManager,self).__init__()\r | |
32 | self.autogen_workers = autogen_workers\r | |
33 | self.feedback_q = feedback_q\r | |
34 | self.terminate = False\r | |
35 | self.Status = True\r | |
36 | self.error_event = error_event\r | |
37 | def run(self):\r | |
38 | try:\r | |
39 | fin_num = 0\r | |
40 | while True:\r | |
41 | badnews = self.feedback_q.get()\r | |
42 | if badnews is None:\r | |
43 | break\r | |
44 | if badnews == "Done":\r | |
45 | fin_num += 1\r | |
46 | else:\r | |
47 | self.Status = False\r | |
48 | self.TerminateWorkers()\r | |
49 | if fin_num == len(self.autogen_workers):\r | |
50 | self.clearQueue()\r | |
51 | for w in self.autogen_workers:\r | |
52 | w.join()\r | |
53 | break\r | |
54 | except Exception:\r | |
55 | return\r | |
56 | \r | |
57 | def clearQueue(self):\r | |
58 | taskq = self.autogen_workers[0].module_queue\r | |
59 | clearQ(taskq)\r | |
60 | clearQ(self.feedback_q)\r | |
61 | \r | |
62 | def TerminateWorkers(self):\r | |
63 | self.error_event.set()\r | |
64 | def kill(self):\r | |
65 | self.feedback_q.put(None)\r | |
66 | class AutoGenWorkerInProcess(mp.Process):\r | |
3285fbda | 67 | def __init__(self,module_queue,data_pipe_file_path,feedback_q,file_lock, share_data,error_event):\r |
673d09a2 FB |
68 | mp.Process.__init__(self)\r |
69 | self.module_queue = module_queue\r | |
70 | self.data_pipe_file_path =data_pipe_file_path\r | |
71 | self.data_pipe = None\r | |
72 | self.feedback_q = feedback_q\r | |
73 | self.PlatformMetaFileSet = {}\r | |
74 | self.file_lock = file_lock\r | |
3285fbda | 75 | self.share_data = share_data\r |
673d09a2 FB |
76 | self.error_event = error_event\r |
77 | def GetPlatformMetaFile(self,filepath,root):\r | |
78 | try:\r | |
79 | return self.PlatformMetaFileSet[(filepath,root)]\r | |
80 | except:\r | |
81 | self.PlatformMetaFileSet[(filepath,root)] = filepath\r | |
82 | return self.PlatformMetaFileSet[(filepath,root)]\r | |
83 | def run(self):\r | |
84 | try:\r | |
85 | taskname = "Init"\r | |
86 | with self.file_lock:\r | |
87 | if not os.path.exists(self.data_pipe_file_path):\r | |
88 | self.feedback_q.put(taskname + ":" + "load data pipe %s failed." % self.data_pipe_file_path)\r | |
89 | self.data_pipe = MemoryDataPipe()\r | |
90 | self.data_pipe.load(self.data_pipe_file_path)\r | |
91 | EdkLogger.Initialize()\r | |
92 | loglevel = self.data_pipe.Get("LogLevel")\r | |
93 | if not loglevel:\r | |
94 | loglevel = EdkLogger.INFO\r | |
95 | EdkLogger.SetLevel(loglevel)\r | |
96 | logfile = self.data_pipe.Get("LogFile")\r | |
97 | if logfile:\r | |
98 | EdkLogger.SetLogFile(logfile)\r | |
99 | target = self.data_pipe.Get("P_Info").get("Target")\r | |
100 | toolchain = self.data_pipe.Get("P_Info").get("ToolChain")\r | |
101 | archlist = self.data_pipe.Get("P_Info").get("ArchList")\r | |
102 | \r | |
103 | active_p = self.data_pipe.Get("P_Info").get("ActivePlatform")\r | |
104 | workspacedir = self.data_pipe.Get("P_Info").get("WorkspaceDir")\r | |
105 | PackagesPath = os.getenv("PACKAGES_PATH")\r | |
106 | mws.setWs(workspacedir, PackagesPath)\r | |
107 | self.Wa = WorkSpaceInfo(\r | |
108 | workspacedir,active_p,target,toolchain,archlist\r | |
109 | )\r | |
110 | self.Wa._SrcTimeStamp = self.data_pipe.Get("Workspace_timestamp")\r | |
111 | GlobalData.gGlobalDefines = self.data_pipe.Get("G_defines")\r | |
112 | GlobalData.gCommandLineDefines = self.data_pipe.Get("CL_defines")\r | |
113 | os.environ._data = self.data_pipe.Get("Env_Var")\r | |
114 | GlobalData.gWorkspace = workspacedir\r | |
115 | GlobalData.gDisableIncludePathCheck = False\r | |
116 | GlobalData.gFdfParser = self.data_pipe.Get("FdfParser")\r | |
117 | GlobalData.gDatabasePath = self.data_pipe.Get("DatabasePath")\r | |
118 | pcd_from_build_option = []\r | |
119 | for pcd_tuple in self.data_pipe.Get("BuildOptPcd"):\r | |
120 | pcd_id = ".".join((pcd_tuple[0],pcd_tuple[1]))\r | |
121 | if pcd_tuple[2].strip():\r | |
122 | pcd_id = ".".join((pcd_id,pcd_tuple[2]))\r | |
123 | pcd_from_build_option.append("=".join((pcd_id,pcd_tuple[3])))\r | |
124 | GlobalData.BuildOptionPcd = pcd_from_build_option\r | |
125 | module_count = 0\r | |
126 | FfsCmd = self.data_pipe.Get("FfsCommand")\r | |
127 | if FfsCmd is None:\r | |
128 | FfsCmd = {}\r | |
129 | PlatformMetaFile = self.GetPlatformMetaFile(self.data_pipe.Get("P_Info").get("ActivePlatform"),\r | |
130 | self.data_pipe.Get("P_Info").get("WorkspaceDir"))\r | |
131 | libConstPcd = self.data_pipe.Get("LibConstPcd")\r | |
132 | Refes = self.data_pipe.Get("REFS")\r | |
133 | while True:\r | |
134 | if self.module_queue.empty():\r | |
135 | break\r | |
136 | if self.error_event.is_set():\r | |
137 | break\r | |
138 | module_count += 1\r | |
139 | module_file,module_root,module_path,module_basename,module_originalpath,module_arch,IsLib = self.module_queue.get_nowait()\r | |
140 | modulefullpath = os.path.join(module_root,module_file)\r | |
141 | taskname = " : ".join((modulefullpath,module_arch))\r | |
142 | module_metafile = PathClass(module_file,module_root)\r | |
143 | if module_path:\r | |
144 | module_metafile.Path = module_path\r | |
145 | if module_basename:\r | |
146 | module_metafile.BaseName = module_basename\r | |
147 | if module_originalpath:\r | |
148 | module_metafile.OriginalPath = PathClass(module_originalpath,module_root)\r | |
149 | arch = module_arch\r | |
150 | target = self.data_pipe.Get("P_Info").get("Target")\r | |
151 | toolchain = self.data_pipe.Get("P_Info").get("ToolChain")\r | |
152 | Ma = ModuleAutoGen(self.Wa,module_metafile,target,toolchain,arch,PlatformMetaFile,self.data_pipe)\r | |
153 | Ma.IsLibrary = IsLib\r | |
154 | if IsLib:\r | |
155 | if (Ma.MetaFile.File,Ma.MetaFile.Root,Ma.Arch,Ma.MetaFile.Path) in libConstPcd:\r | |
156 | Ma.ConstPcd = libConstPcd[(Ma.MetaFile.File,Ma.MetaFile.Root,Ma.Arch,Ma.MetaFile.Path)]\r | |
157 | if (Ma.MetaFile.File,Ma.MetaFile.Root,Ma.Arch,Ma.MetaFile.Path) in Refes:\r | |
158 | Ma.ReferenceModules = Refes[(Ma.MetaFile.File,Ma.MetaFile.Root,Ma.Arch,Ma.MetaFile.Path)]\r | |
159 | Ma.CreateCodeFile(False)\r | |
160 | Ma.CreateMakeFile(False,GenFfsList=FfsCmd.get((Ma.MetaFile.File, Ma.Arch),[]))\r | |
161 | except Empty:\r | |
162 | pass\r | |
163 | except:\r | |
164 | traceback.print_exc(file=sys.stdout)\r | |
165 | self.feedback_q.put(taskname)\r | |
166 | finally:\r | |
167 | self.feedback_q.put("Done")\r | |
168 | def printStatus(self):\r | |
169 | print("Processs ID: %d Run %d modules in AutoGen " % (os.getpid(),len(AutoGen.Cache())))\r | |
170 | print("Processs ID: %d Run %d modules in AutoGenInfo " % (os.getpid(),len(AutoGenInfo.GetCache())))\r | |
171 | groupobj = {}\r | |
172 | for buildobj in BuildDB.BuildObject.GetCache().values():\r | |
173 | if str(buildobj).lower().endswith("dec"):\r | |
174 | try:\r | |
175 | groupobj['dec'].append(str(buildobj))\r | |
176 | except:\r | |
177 | groupobj['dec'] = [str(buildobj)]\r | |
178 | if str(buildobj).lower().endswith("dsc"):\r | |
179 | try:\r | |
180 | groupobj['dsc'].append(str(buildobj))\r | |
181 | except:\r | |
182 | groupobj['dsc'] = [str(buildobj)]\r | |
183 | \r | |
184 | if str(buildobj).lower().endswith("inf"):\r | |
185 | try:\r | |
186 | groupobj['inf'].append(str(buildobj))\r | |
187 | except:\r | |
188 | groupobj['inf'] = [str(buildobj)]\r | |
189 | \r | |
190 | print("Processs ID: %d Run %d pkg in WDB " % (os.getpid(),len(groupobj.get("dec",[]))))\r | |
191 | print("Processs ID: %d Run %d pla in WDB " % (os.getpid(),len(groupobj.get("dsc",[]))))\r | |
192 | print("Processs ID: %d Run %d inf in WDB " % (os.getpid(),len(groupobj.get("inf",[]))))\r |