]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/AutoGen/AutoGenWorker.py
6c6ef4964741a2d0dcb7c8ad9b7ddd4e16dcf03d
2 # Create makefile for MS nmake and GNU make
4 # Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
7 from __future__
import absolute_import
8 import multiprocessing
as mp
10 from Common
.Misc
import PathClass
11 from AutoGen
.ModuleAutoGen
import ModuleAutoGen
12 from AutoGen
.ModuleAutoGenHelper
import WorkSpaceInfo
,AutoGenInfo
13 import Common
.GlobalData
as GlobalData
14 import Common
.EdkLogger
as EdkLogger
16 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
17 from AutoGen
.AutoGen
import AutoGen
18 from Workspace
.WorkspaceDatabase
import BuildDB
19 from queue
import Empty
22 from AutoGen
.DataPipe
import MemoryDataPipe
29 class AutoGenManager(threading
.Thread
):
30 def __init__(self
,autogen_workers
, feedback_q
,error_event
):
31 super(AutoGenManager
,self
).__init
__()
32 self
.autogen_workers
= autogen_workers
33 self
.feedback_q
= feedback_q
34 self
.terminate
= False
36 self
.error_event
= error_event
41 badnews
= self
.feedback_q
.get()
48 self
.TerminateWorkers()
49 if fin_num
== len(self
.autogen_workers
):
51 for w
in self
.autogen_workers
:
58 taskq
= self
.autogen_workers
[0].module_queue
60 clearQ(self
.feedback_q
)
62 def TerminateWorkers(self
):
63 self
.error_event
.set()
65 self
.feedback_q
.put(None)
66 class AutoGenWorkerInProcess(mp
.Process
):
67 def __init__(self
,module_queue
,data_pipe_file_path
,feedback_q
,file_lock
,error_event
):
68 mp
.Process
.__init
__(self
)
69 self
.module_queue
= module_queue
70 self
.data_pipe_file_path
=data_pipe_file_path
72 self
.feedback_q
= feedback_q
73 self
.PlatformMetaFileSet
= {}
74 self
.file_lock
= file_lock
75 self
.error_event
= error_event
76 def GetPlatformMetaFile(self
,filepath
,root
):
78 return self
.PlatformMetaFileSet
[(filepath
,root
)]
80 self
.PlatformMetaFileSet
[(filepath
,root
)] = filepath
81 return self
.PlatformMetaFileSet
[(filepath
,root
)]
86 if not os
.path
.exists(self
.data_pipe_file_path
):
87 self
.feedback_q
.put(taskname
+ ":" + "load data pipe %s failed." % self
.data_pipe_file_path
)
88 self
.data_pipe
= MemoryDataPipe()
89 self
.data_pipe
.load(self
.data_pipe_file_path
)
90 EdkLogger
.Initialize()
91 loglevel
= self
.data_pipe
.Get("LogLevel")
93 loglevel
= EdkLogger
.INFO
94 EdkLogger
.SetLevel(loglevel
)
95 logfile
= self
.data_pipe
.Get("LogFile")
97 EdkLogger
.SetLogFile(logfile
)
98 target
= self
.data_pipe
.Get("P_Info").get("Target")
99 toolchain
= self
.data_pipe
.Get("P_Info").get("ToolChain")
100 archlist
= self
.data_pipe
.Get("P_Info").get("ArchList")
102 active_p
= self
.data_pipe
.Get("P_Info").get("ActivePlatform")
103 workspacedir
= self
.data_pipe
.Get("P_Info").get("WorkspaceDir")
104 PackagesPath
= os
.getenv("PACKAGES_PATH")
105 mws
.setWs(workspacedir
, PackagesPath
)
106 self
.Wa
= WorkSpaceInfo(
107 workspacedir
,active_p
,target
,toolchain
,archlist
109 self
.Wa
._SrcTimeStamp
= self
.data_pipe
.Get("Workspace_timestamp")
110 GlobalData
.gGlobalDefines
= self
.data_pipe
.Get("G_defines")
111 GlobalData
.gCommandLineDefines
= self
.data_pipe
.Get("CL_defines")
112 os
.environ
._data
= self
.data_pipe
.Get("Env_Var")
113 GlobalData
.gWorkspace
= workspacedir
114 GlobalData
.gDisableIncludePathCheck
= False
115 GlobalData
.gFdfParser
= self
.data_pipe
.Get("FdfParser")
116 GlobalData
.gDatabasePath
= self
.data_pipe
.Get("DatabasePath")
117 pcd_from_build_option
= []
118 for pcd_tuple
in self
.data_pipe
.Get("BuildOptPcd"):
119 pcd_id
= ".".join((pcd_tuple
[0],pcd_tuple
[1]))
120 if pcd_tuple
[2].strip():
121 pcd_id
= ".".join((pcd_id
,pcd_tuple
[2]))
122 pcd_from_build_option
.append("=".join((pcd_id
,pcd_tuple
[3])))
123 GlobalData
.BuildOptionPcd
= pcd_from_build_option
125 FfsCmd
= self
.data_pipe
.Get("FfsCommand")
128 PlatformMetaFile
= self
.GetPlatformMetaFile(self
.data_pipe
.Get("P_Info").get("ActivePlatform"),
129 self
.data_pipe
.Get("P_Info").get("WorkspaceDir"))
130 libConstPcd
= self
.data_pipe
.Get("LibConstPcd")
131 Refes
= self
.data_pipe
.Get("REFS")
133 if self
.module_queue
.empty():
135 if self
.error_event
.is_set():
138 module_file
,module_root
,module_path
,module_basename
,module_originalpath
,module_arch
,IsLib
= self
.module_queue
.get_nowait()
139 modulefullpath
= os
.path
.join(module_root
,module_file
)
140 taskname
= " : ".join((modulefullpath
,module_arch
))
141 module_metafile
= PathClass(module_file
,module_root
)
143 module_metafile
.Path
= module_path
145 module_metafile
.BaseName
= module_basename
146 if module_originalpath
:
147 module_metafile
.OriginalPath
= PathClass(module_originalpath
,module_root
)
149 target
= self
.data_pipe
.Get("P_Info").get("Target")
150 toolchain
= self
.data_pipe
.Get("P_Info").get("ToolChain")
151 Ma
= ModuleAutoGen(self
.Wa
,module_metafile
,target
,toolchain
,arch
,PlatformMetaFile
,self
.data_pipe
)
154 if (Ma
.MetaFile
.File
,Ma
.MetaFile
.Root
,Ma
.Arch
,Ma
.MetaFile
.Path
) in libConstPcd
:
155 Ma
.ConstPcd
= libConstPcd
[(Ma
.MetaFile
.File
,Ma
.MetaFile
.Root
,Ma
.Arch
,Ma
.MetaFile
.Path
)]
156 if (Ma
.MetaFile
.File
,Ma
.MetaFile
.Root
,Ma
.Arch
,Ma
.MetaFile
.Path
) in Refes
:
157 Ma
.ReferenceModules
= Refes
[(Ma
.MetaFile
.File
,Ma
.MetaFile
.Root
,Ma
.Arch
,Ma
.MetaFile
.Path
)]
158 Ma
.CreateCodeFile(False)
159 Ma
.CreateMakeFile(False,GenFfsList
=FfsCmd
.get((Ma
.MetaFile
.File
, Ma
.Arch
),[]))
163 traceback
.print_exc(file=sys
.stdout
)
164 self
.feedback_q
.put(taskname
)
166 self
.feedback_q
.put("Done")
167 def printStatus(self
):
168 print("Processs ID: %d Run %d modules in AutoGen " % (os
.getpid(),len(AutoGen
.Cache())))
169 print("Processs ID: %d Run %d modules in AutoGenInfo " % (os
.getpid(),len(AutoGenInfo
.GetCache())))
171 for buildobj
in BuildDB
.BuildObject
.GetCache().values():
172 if str(buildobj
).lower().endswith("dec"):
174 groupobj
['dec'].append(str(buildobj
))
176 groupobj
['dec'] = [str(buildobj
)]
177 if str(buildobj
).lower().endswith("dsc"):
179 groupobj
['dsc'].append(str(buildobj
))
181 groupobj
['dsc'] = [str(buildobj
)]
183 if str(buildobj
).lower().endswith("inf"):
185 groupobj
['inf'].append(str(buildobj
))
187 groupobj
['inf'] = [str(buildobj
)]
189 print("Processs ID: %d Run %d pkg in WDB " % (os
.getpid(),len(groupobj
.get("dec",[]))))
190 print("Processs ID: %d Run %d pla in WDB " % (os
.getpid(),len(groupobj
.get("dsc",[]))))
191 print("Processs ID: %d Run %d inf in WDB " % (os
.getpid(),len(groupobj
.get("inf",[]))))