runqueue.py 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786
  1. #!/usr/bin/env python
  2. # ex:ts=4:sw=4:sts=4:et
  3. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  4. """
  5. BitBake 'RunQueue' implementation
  6. Handles preparation and execution of a queue of tasks
  7. """
  8. # Copyright (C) 2006-2007 Richard Purdie
  9. #
  10. # SPDX-License-Identifier: GPL-2.0-only
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License version 2 as
  14. # published by the Free Software Foundation.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License along
  22. # with this program; if not, write to the Free Software Foundation, Inc.,
  23. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. import copy
  25. import os
  26. import sys
  27. import signal
  28. import stat
  29. import fcntl
  30. import errno
  31. import logging
  32. import re
  33. import bb
  34. from bb import msg, data, event
  35. from bb import monitordisk
  36. import subprocess
  37. import pickle
  38. from multiprocessing import Process
  39. import shlex
  40. bblogger = logging.getLogger("BitBake")
  41. logger = logging.getLogger("BitBake.RunQueue")
  42. __find_sha256__ = re.compile( r'(?i)(?<![a-z0-9])[a-f0-9]{64}(?![a-z0-9])' )
  43. def fn_from_tid(tid):
  44. return tid.rsplit(":", 1)[0]
  45. def taskname_from_tid(tid):
  46. return tid.rsplit(":", 1)[1]
  47. def mc_from_tid(tid):
  48. if tid.startswith('multiconfig:'):
  49. return tid.split(':')[1]
  50. return ""
  51. def split_tid(tid):
  52. (mc, fn, taskname, _) = split_tid_mcfn(tid)
  53. return (mc, fn, taskname)
  54. def split_tid_mcfn(tid):
  55. if tid.startswith('multiconfig:'):
  56. elems = tid.split(':')
  57. mc = elems[1]
  58. fn = ":".join(elems[2:-1])
  59. taskname = elems[-1]
  60. mcfn = "multiconfig:" + mc + ":" + fn
  61. else:
  62. tid = tid.rsplit(":", 1)
  63. mc = ""
  64. fn = tid[0]
  65. taskname = tid[1]
  66. mcfn = fn
  67. return (mc, fn, taskname, mcfn)
  68. def build_tid(mc, fn, taskname):
  69. if mc:
  70. return "multiconfig:" + mc + ":" + fn + ":" + taskname
  71. return fn + ":" + taskname
  72. class RunQueueStats:
  73. """
  74. Holds statistics on the tasks handled by the associated runQueue
  75. """
  76. def __init__(self, total):
  77. self.completed = 0
  78. self.skipped = 0
  79. self.failed = 0
  80. self.active = 0
  81. self.total = total
  82. def copy(self):
  83. obj = self.__class__(self.total)
  84. obj.__dict__.update(self.__dict__)
  85. return obj
  86. def taskFailed(self):
  87. self.active = self.active - 1
  88. self.failed = self.failed + 1
  89. def taskCompleted(self):
  90. self.active = self.active - 1
  91. self.completed = self.completed + 1
  92. def taskSkipped(self):
  93. self.active = self.active + 1
  94. self.skipped = self.skipped + 1
  95. def taskActive(self):
  96. self.active = self.active + 1
  97. # These values indicate the next step due to be run in the
  98. # runQueue state machine
  99. runQueuePrepare = 2
  100. runQueueSceneInit = 3
  101. runQueueSceneRun = 4
  102. runQueueRunInit = 5
  103. runQueueRunning = 6
  104. runQueueFailed = 7
  105. runQueueCleanUp = 8
  106. runQueueComplete = 9
  107. class RunQueueScheduler(object):
  108. """
  109. Control the order tasks are scheduled in.
  110. """
  111. name = "basic"
  112. def __init__(self, runqueue, rqdata):
  113. """
  114. The default scheduler just returns the first buildable task (the
  115. priority map is sorted by task number)
  116. """
  117. self.rq = runqueue
  118. self.rqdata = rqdata
  119. self.numTasks = len(self.rqdata.runtaskentries)
  120. self.prio_map = [self.rqdata.runtaskentries.keys()]
  121. self.buildable = []
  122. self.skip_maxthread = {}
  123. self.stamps = {}
  124. for tid in self.rqdata.runtaskentries:
  125. (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
  126. self.stamps[tid] = bb.build.stampfile(taskname, self.rqdata.dataCaches[mc], taskfn, noextra=True)
  127. if tid in self.rq.runq_buildable:
  128. self.buildable.append(tid)
  129. self.rev_prio_map = None
  130. def next_buildable_task(self):
  131. """
  132. Return the id of the first task we find that is buildable
  133. """
  134. self.buildable = [x for x in self.buildable if x not in self.rq.runq_running]
  135. if not self.buildable:
  136. return None
  137. # Filter out tasks that have a max number of threads that have been exceeded
  138. skip_buildable = {}
  139. for running in self.rq.runq_running.difference(self.rq.runq_complete):
  140. rtaskname = taskname_from_tid(running)
  141. if rtaskname not in self.skip_maxthread:
  142. self.skip_maxthread[rtaskname] = self.rq.cfgData.getVarFlag(rtaskname, "number_threads")
  143. if not self.skip_maxthread[rtaskname]:
  144. continue
  145. if rtaskname in skip_buildable:
  146. skip_buildable[rtaskname] += 1
  147. else:
  148. skip_buildable[rtaskname] = 1
  149. if len(self.buildable) == 1:
  150. tid = self.buildable[0]
  151. taskname = taskname_from_tid(tid)
  152. if taskname in skip_buildable and skip_buildable[taskname] >= int(self.skip_maxthread[taskname]):
  153. return None
  154. stamp = self.stamps[tid]
  155. if stamp not in self.rq.build_stamps.values():
  156. return tid
  157. if not self.rev_prio_map:
  158. self.rev_prio_map = {}
  159. for tid in self.rqdata.runtaskentries:
  160. self.rev_prio_map[tid] = self.prio_map.index(tid)
  161. best = None
  162. bestprio = None
  163. for tid in self.buildable:
  164. taskname = taskname_from_tid(tid)
  165. if taskname in skip_buildable and skip_buildable[taskname] >= int(self.skip_maxthread[taskname]):
  166. continue
  167. prio = self.rev_prio_map[tid]
  168. if bestprio is None or bestprio > prio:
  169. stamp = self.stamps[tid]
  170. if stamp in self.rq.build_stamps.values():
  171. continue
  172. bestprio = prio
  173. best = tid
  174. return best
  175. def next(self):
  176. """
  177. Return the id of the task we should build next
  178. """
  179. if self.rq.can_start_task():
  180. return self.next_buildable_task()
  181. def newbuildable(self, task):
  182. self.buildable.append(task)
  183. def describe_task(self, taskid):
  184. result = 'ID %s' % taskid
  185. if self.rev_prio_map:
  186. result = result + (' pri %d' % self.rev_prio_map[taskid])
  187. return result
  188. def dump_prio(self, comment):
  189. bb.debug(3, '%s (most important first):\n%s' %
  190. (comment,
  191. '\n'.join(['%d. %s' % (index + 1, self.describe_task(taskid)) for
  192. index, taskid in enumerate(self.prio_map)])))
  193. class RunQueueSchedulerSpeed(RunQueueScheduler):
  194. """
  195. A scheduler optimised for speed. The priority map is sorted by task weight,
  196. heavier weighted tasks (tasks needed by the most other tasks) are run first.
  197. """
  198. name = "speed"
  199. def __init__(self, runqueue, rqdata):
  200. """
  201. The priority map is sorted by task weight.
  202. """
  203. RunQueueScheduler.__init__(self, runqueue, rqdata)
  204. weights = {}
  205. for tid in self.rqdata.runtaskentries:
  206. weight = self.rqdata.runtaskentries[tid].weight
  207. if not weight in weights:
  208. weights[weight] = []
  209. weights[weight].append(tid)
  210. self.prio_map = []
  211. for weight in sorted(weights):
  212. for w in weights[weight]:
  213. self.prio_map.append(w)
  214. self.prio_map.reverse()
  215. class RunQueueSchedulerCompletion(RunQueueSchedulerSpeed):
  216. """
  217. A scheduler optimised to complete .bb files as quickly as possible. The
  218. priority map is sorted by task weight, but then reordered so once a given
  219. .bb file starts to build, it's completed as quickly as possible by
  220. running all tasks related to the same .bb file one after the after.
  221. This works well where disk space is at a premium and classes like OE's
  222. rm_work are in force.
  223. """
  224. name = "completion"
  225. def __init__(self, runqueue, rqdata):
  226. super(RunQueueSchedulerCompletion, self).__init__(runqueue, rqdata)
  227. # Extract list of tasks for each recipe, with tasks sorted
  228. # ascending from "must run first" (typically do_fetch) to
  229. # "runs last" (do_build). The speed scheduler prioritizes
  230. # tasks that must run first before the ones that run later;
  231. # this is what we depend on here.
  232. task_lists = {}
  233. for taskid in self.prio_map:
  234. fn, taskname = taskid.rsplit(':', 1)
  235. task_lists.setdefault(fn, []).append(taskname)
  236. # Now unify the different task lists. The strategy is that
  237. # common tasks get skipped and new ones get inserted after the
  238. # preceeding common one(s) as they are found. Because task
  239. # lists should differ only by their number of tasks, but not
  240. # the ordering of the common tasks, this should result in a
  241. # deterministic result that is a superset of the individual
  242. # task ordering.
  243. all_tasks = []
  244. for recipe, new_tasks in task_lists.items():
  245. index = 0
  246. old_task = all_tasks[index] if index < len(all_tasks) else None
  247. for new_task in new_tasks:
  248. if old_task == new_task:
  249. # Common task, skip it. This is the fast-path which
  250. # avoids a full search.
  251. index += 1
  252. old_task = all_tasks[index] if index < len(all_tasks) else None
  253. else:
  254. try:
  255. index = all_tasks.index(new_task)
  256. # Already present, just not at the current
  257. # place. We re-synchronized by changing the
  258. # index so that it matches again. Now
  259. # move on to the next existing task.
  260. index += 1
  261. old_task = all_tasks[index] if index < len(all_tasks) else None
  262. except ValueError:
  263. # Not present. Insert before old_task, which
  264. # remains the same (but gets shifted back).
  265. all_tasks.insert(index, new_task)
  266. index += 1
  267. bb.debug(3, 'merged task list: %s' % all_tasks)
  268. # Now reverse the order so that tasks that finish the work on one
  269. # recipe are considered more imporant (= come first). The ordering
  270. # is now so that do_build is most important.
  271. all_tasks.reverse()
  272. # Group tasks of the same kind before tasks of less important
  273. # kinds at the head of the queue (because earlier = lower
  274. # priority number = runs earlier), while preserving the
  275. # ordering by recipe. If recipe foo is more important than
  276. # bar, then the goal is to work on foo's do_populate_sysroot
  277. # before bar's do_populate_sysroot and on the more important
  278. # tasks of foo before any of the less important tasks in any
  279. # other recipe (if those other recipes are more important than
  280. # foo).
  281. #
  282. # All of this only applies when tasks are runable. Explicit
  283. # dependencies still override this ordering by priority.
  284. #
  285. # Here's an example why this priority re-ordering helps with
  286. # minimizing disk usage. Consider a recipe foo with a higher
  287. # priority than bar where foo DEPENDS on bar. Then the
  288. # implicit rule (from base.bbclass) is that foo's do_configure
  289. # depends on bar's do_populate_sysroot. This ensures that
  290. # bar's do_populate_sysroot gets done first. Normally the
  291. # tasks from foo would continue to run once that is done, and
  292. # bar only gets completed and cleaned up later. By ordering
  293. # bar's task that depend on bar's do_populate_sysroot before foo's
  294. # do_configure, that problem gets avoided.
  295. task_index = 0
  296. self.dump_prio('original priorities')
  297. for task in all_tasks:
  298. for index in range(task_index, self.numTasks):
  299. taskid = self.prio_map[index]
  300. taskname = taskid.rsplit(':', 1)[1]
  301. if taskname == task:
  302. del self.prio_map[index]
  303. self.prio_map.insert(task_index, taskid)
  304. task_index += 1
  305. self.dump_prio('completion priorities')
  306. class RunTaskEntry(object):
  307. def __init__(self):
  308. self.depends = set()
  309. self.revdeps = set()
  310. self.hash = None
  311. self.unihash = None
  312. self.task = None
  313. self.weight = 1
  314. class RunQueueData:
  315. """
  316. BitBake Run Queue implementation
  317. """
  318. def __init__(self, rq, cooker, cfgData, dataCaches, taskData, targets):
  319. self.cooker = cooker
  320. self.dataCaches = dataCaches
  321. self.taskData = taskData
  322. self.targets = targets
  323. self.rq = rq
  324. self.warn_multi_bb = False
  325. self.stampwhitelist = cfgData.getVar("BB_STAMP_WHITELIST") or ""
  326. self.multi_provider_whitelist = (cfgData.getVar("MULTI_PROVIDER_WHITELIST") or "").split()
  327. self.setscenewhitelist = get_setscene_enforce_whitelist(cfgData)
  328. self.setscenewhitelist_checked = False
  329. self.setscene_enforce = (cfgData.getVar('BB_SETSCENE_ENFORCE') == "1")
  330. self.init_progress_reporter = bb.progress.DummyMultiStageProcessProgressReporter()
  331. self.reset()
  332. def reset(self):
  333. self.runtaskentries = {}
  334. def runq_depends_names(self, ids):
  335. import re
  336. ret = []
  337. for id in ids:
  338. nam = os.path.basename(id)
  339. nam = re.sub("_[^,]*,", ",", nam)
  340. ret.extend([nam])
  341. return ret
  342. def get_task_hash(self, tid):
  343. return self.runtaskentries[tid].hash
  344. def get_task_unihash(self, tid):
  345. return self.runtaskentries[tid].unihash
  346. def get_user_idstring(self, tid, task_name_suffix = ""):
  347. return tid + task_name_suffix
  348. def get_short_user_idstring(self, task, task_name_suffix = ""):
  349. (mc, fn, taskname, taskfn) = split_tid_mcfn(task)
  350. pn = self.dataCaches[mc].pkg_fn[taskfn]
  351. taskname = taskname_from_tid(task) + task_name_suffix
  352. return "%s:%s" % (pn, taskname)
  353. def circular_depchains_handler(self, tasks):
  354. """
  355. Some tasks aren't buildable, likely due to circular dependency issues.
  356. Identify the circular dependencies and print them in a user readable format.
  357. """
  358. from copy import deepcopy
  359. valid_chains = []
  360. explored_deps = {}
  361. msgs = []
  362. class TooManyLoops(Exception):
  363. pass
  364. def chain_reorder(chain):
  365. """
  366. Reorder a dependency chain so the lowest task id is first
  367. """
  368. lowest = 0
  369. new_chain = []
  370. for entry in range(len(chain)):
  371. if chain[entry] < chain[lowest]:
  372. lowest = entry
  373. new_chain.extend(chain[lowest:])
  374. new_chain.extend(chain[:lowest])
  375. return new_chain
  376. def chain_compare_equal(chain1, chain2):
  377. """
  378. Compare two dependency chains and see if they're the same
  379. """
  380. if len(chain1) != len(chain2):
  381. return False
  382. for index in range(len(chain1)):
  383. if chain1[index] != chain2[index]:
  384. return False
  385. return True
  386. def chain_array_contains(chain, chain_array):
  387. """
  388. Return True if chain_array contains chain
  389. """
  390. for ch in chain_array:
  391. if chain_compare_equal(ch, chain):
  392. return True
  393. return False
  394. def find_chains(tid, prev_chain):
  395. prev_chain.append(tid)
  396. total_deps = []
  397. total_deps.extend(self.runtaskentries[tid].revdeps)
  398. for revdep in self.runtaskentries[tid].revdeps:
  399. if revdep in prev_chain:
  400. idx = prev_chain.index(revdep)
  401. # To prevent duplicates, reorder the chain to start with the lowest taskid
  402. # and search through an array of those we've already printed
  403. chain = prev_chain[idx:]
  404. new_chain = chain_reorder(chain)
  405. if not chain_array_contains(new_chain, valid_chains):
  406. valid_chains.append(new_chain)
  407. msgs.append("Dependency loop #%d found:\n" % len(valid_chains))
  408. for dep in new_chain:
  409. msgs.append(" Task %s (dependent Tasks %s)\n" % (dep, self.runq_depends_names(self.runtaskentries[dep].depends)))
  410. msgs.append("\n")
  411. if len(valid_chains) > 10:
  412. msgs.append("Aborted dependency loops search after 10 matches.\n")
  413. raise TooManyLoops
  414. continue
  415. scan = False
  416. if revdep not in explored_deps:
  417. scan = True
  418. elif revdep in explored_deps[revdep]:
  419. scan = True
  420. else:
  421. for dep in prev_chain:
  422. if dep in explored_deps[revdep]:
  423. scan = True
  424. if scan:
  425. find_chains(revdep, copy.deepcopy(prev_chain))
  426. for dep in explored_deps[revdep]:
  427. if dep not in total_deps:
  428. total_deps.append(dep)
  429. explored_deps[tid] = total_deps
  430. try:
  431. for task in tasks:
  432. find_chains(task, [])
  433. except TooManyLoops:
  434. pass
  435. return msgs
  436. def calculate_task_weights(self, endpoints):
  437. """
  438. Calculate a number representing the "weight" of each task. Heavier weighted tasks
  439. have more dependencies and hence should be executed sooner for maximum speed.
  440. This function also sanity checks the task list finding tasks that are not
  441. possible to execute due to circular dependencies.
  442. """
  443. numTasks = len(self.runtaskentries)
  444. weight = {}
  445. deps_left = {}
  446. task_done = {}
  447. for tid in self.runtaskentries:
  448. task_done[tid] = False
  449. weight[tid] = 1
  450. deps_left[tid] = len(self.runtaskentries[tid].revdeps)
  451. for tid in endpoints:
  452. weight[tid] = 10
  453. task_done[tid] = True
  454. while True:
  455. next_points = []
  456. for tid in endpoints:
  457. for revdep in self.runtaskentries[tid].depends:
  458. weight[revdep] = weight[revdep] + weight[tid]
  459. deps_left[revdep] = deps_left[revdep] - 1
  460. if deps_left[revdep] == 0:
  461. next_points.append(revdep)
  462. task_done[revdep] = True
  463. endpoints = next_points
  464. if len(next_points) == 0:
  465. break
  466. # Circular dependency sanity check
  467. problem_tasks = []
  468. for tid in self.runtaskentries:
  469. if task_done[tid] is False or deps_left[tid] != 0:
  470. problem_tasks.append(tid)
  471. logger.debug(2, "Task %s is not buildable", tid)
  472. logger.debug(2, "(Complete marker was %s and the remaining dependency count was %s)\n", task_done[tid], deps_left[tid])
  473. self.runtaskentries[tid].weight = weight[tid]
  474. if problem_tasks:
  475. message = "%s unbuildable tasks were found.\n" % len(problem_tasks)
  476. message = message + "These are usually caused by circular dependencies and any circular dependency chains found will be printed below. Increase the debug level to see a list of unbuildable tasks.\n\n"
  477. message = message + "Identifying dependency loops (this may take a short while)...\n"
  478. logger.error(message)
  479. msgs = self.circular_depchains_handler(problem_tasks)
  480. message = "\n"
  481. for msg in msgs:
  482. message = message + msg
  483. bb.msg.fatal("RunQueue", message)
  484. return weight
  485. def prepare(self):
  486. """
  487. Turn a set of taskData into a RunQueue and compute data needed
  488. to optimise the execution order.
  489. """
  490. runq_build = {}
  491. recursivetasks = {}
  492. recursiveitasks = {}
  493. recursivetasksselfref = set()
  494. taskData = self.taskData
  495. found = False
  496. for mc in self.taskData:
  497. if len(taskData[mc].taskentries) > 0:
  498. found = True
  499. break
  500. if not found:
  501. # Nothing to do
  502. return 0
  503. self.init_progress_reporter.start()
  504. self.init_progress_reporter.next_stage()
  505. # Step A - Work out a list of tasks to run
  506. #
  507. # Taskdata gives us a list of possible providers for every build and run
  508. # target ordered by priority. It also gives information on each of those
  509. # providers.
  510. #
  511. # To create the actual list of tasks to execute we fix the list of
  512. # providers and then resolve the dependencies into task IDs. This
  513. # process is repeated for each type of dependency (tdepends, deptask,
  514. # rdeptast, recrdeptask, idepends).
  515. def add_build_dependencies(depids, tasknames, depends, mc):
  516. for depname in depids:
  517. # Won't be in build_targets if ASSUME_PROVIDED
  518. if depname not in taskData[mc].build_targets or not taskData[mc].build_targets[depname]:
  519. continue
  520. depdata = taskData[mc].build_targets[depname][0]
  521. if depdata is None:
  522. continue
  523. for taskname in tasknames:
  524. t = depdata + ":" + taskname
  525. if t in taskData[mc].taskentries:
  526. depends.add(t)
  527. def add_runtime_dependencies(depids, tasknames, depends, mc):
  528. for depname in depids:
  529. if depname not in taskData[mc].run_targets or not taskData[mc].run_targets[depname]:
  530. continue
  531. depdata = taskData[mc].run_targets[depname][0]
  532. if depdata is None:
  533. continue
  534. for taskname in tasknames:
  535. t = depdata + ":" + taskname
  536. if t in taskData[mc].taskentries:
  537. depends.add(t)
  538. def add_mc_dependencies(mc, tid):
  539. mcdeps = taskData[mc].get_mcdepends()
  540. for dep in mcdeps:
  541. mcdependency = dep.split(':')
  542. pn = mcdependency[3]
  543. frommc = mcdependency[1]
  544. mcdep = mcdependency[2]
  545. deptask = mcdependency[4]
  546. if mc == frommc:
  547. fn = taskData[mcdep].build_targets[pn][0]
  548. newdep = '%s:%s' % (fn,deptask)
  549. taskData[mc].taskentries[tid].tdepends.append(newdep)
  550. for mc in taskData:
  551. for tid in taskData[mc].taskentries:
  552. (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
  553. #runtid = build_tid(mc, fn, taskname)
  554. #logger.debug(2, "Processing %s,%s:%s", mc, fn, taskname)
  555. depends = set()
  556. task_deps = self.dataCaches[mc].task_deps[taskfn]
  557. self.runtaskentries[tid] = RunTaskEntry()
  558. if fn in taskData[mc].failed_fns:
  559. continue
  560. # We add multiconfig dependencies before processing internal task deps (tdepends)
  561. if 'mcdepends' in task_deps and taskname in task_deps['mcdepends']:
  562. add_mc_dependencies(mc, tid)
  563. # Resolve task internal dependencies
  564. #
  565. # e.g. addtask before X after Y
  566. for t in taskData[mc].taskentries[tid].tdepends:
  567. (depmc, depfn, deptaskname, _) = split_tid_mcfn(t)
  568. depends.add(build_tid(depmc, depfn, deptaskname))
  569. # Resolve 'deptask' dependencies
  570. #
  571. # e.g. do_sometask[deptask] = "do_someothertask"
  572. # (makes sure sometask runs after someothertask of all DEPENDS)
  573. if 'deptask' in task_deps and taskname in task_deps['deptask']:
  574. tasknames = task_deps['deptask'][taskname].split()
  575. add_build_dependencies(taskData[mc].depids[taskfn], tasknames, depends, mc)
  576. # Resolve 'rdeptask' dependencies
  577. #
  578. # e.g. do_sometask[rdeptask] = "do_someothertask"
  579. # (makes sure sometask runs after someothertask of all RDEPENDS)
  580. if 'rdeptask' in task_deps and taskname in task_deps['rdeptask']:
  581. tasknames = task_deps['rdeptask'][taskname].split()
  582. add_runtime_dependencies(taskData[mc].rdepids[taskfn], tasknames, depends, mc)
  583. # Resolve inter-task dependencies
  584. #
  585. # e.g. do_sometask[depends] = "targetname:do_someothertask"
  586. # (makes sure sometask runs after targetname's someothertask)
  587. idepends = taskData[mc].taskentries[tid].idepends
  588. for (depname, idependtask) in idepends:
  589. if depname in taskData[mc].build_targets and taskData[mc].build_targets[depname] and not depname in taskData[mc].failed_deps:
  590. # Won't be in build_targets if ASSUME_PROVIDED
  591. depdata = taskData[mc].build_targets[depname][0]
  592. if depdata is not None:
  593. t = depdata + ":" + idependtask
  594. depends.add(t)
  595. if t not in taskData[mc].taskentries:
  596. bb.msg.fatal("RunQueue", "Task %s in %s depends upon non-existent task %s in %s" % (taskname, fn, idependtask, depdata))
  597. irdepends = taskData[mc].taskentries[tid].irdepends
  598. for (depname, idependtask) in irdepends:
  599. if depname in taskData[mc].run_targets:
  600. # Won't be in run_targets if ASSUME_PROVIDED
  601. if not taskData[mc].run_targets[depname]:
  602. continue
  603. depdata = taskData[mc].run_targets[depname][0]
  604. if depdata is not None:
  605. t = depdata + ":" + idependtask
  606. depends.add(t)
  607. if t not in taskData[mc].taskentries:
  608. bb.msg.fatal("RunQueue", "Task %s in %s rdepends upon non-existent task %s in %s" % (taskname, fn, idependtask, depdata))
  609. # Resolve recursive 'recrdeptask' dependencies (Part A)
  610. #
  611. # e.g. do_sometask[recrdeptask] = "do_someothertask"
  612. # (makes sure sometask runs after someothertask of all DEPENDS, RDEPENDS and intertask dependencies, recursively)
  613. # We cover the recursive part of the dependencies below
  614. if 'recrdeptask' in task_deps and taskname in task_deps['recrdeptask']:
  615. tasknames = task_deps['recrdeptask'][taskname].split()
  616. recursivetasks[tid] = tasknames
  617. add_build_dependencies(taskData[mc].depids[taskfn], tasknames, depends, mc)
  618. add_runtime_dependencies(taskData[mc].rdepids[taskfn], tasknames, depends, mc)
  619. if taskname in tasknames:
  620. recursivetasksselfref.add(tid)
  621. if 'recideptask' in task_deps and taskname in task_deps['recideptask']:
  622. recursiveitasks[tid] = []
  623. for t in task_deps['recideptask'][taskname].split():
  624. newdep = build_tid(mc, fn, t)
  625. recursiveitasks[tid].append(newdep)
  626. self.runtaskentries[tid].depends = depends
  627. # Remove all self references
  628. self.runtaskentries[tid].depends.discard(tid)
  629. #self.dump_data()
  630. self.init_progress_reporter.next_stage()
  631. # Resolve recursive 'recrdeptask' dependencies (Part B)
  632. #
  633. # e.g. do_sometask[recrdeptask] = "do_someothertask"
  634. # (makes sure sometask runs after someothertask of all DEPENDS, RDEPENDS and intertask dependencies, recursively)
  635. # We need to do this separately since we need all of runtaskentries[*].depends to be complete before this is processed
  636. # Generating/interating recursive lists of dependencies is painful and potentially slow
  637. # Precompute recursive task dependencies here by:
  638. # a) create a temp list of reverse dependencies (revdeps)
  639. # b) walk up the ends of the chains (when a given task no longer has dependencies i.e. len(deps) == 0)
  640. # c) combine the total list of dependencies in cumulativedeps
  641. # d) optimise by pre-truncating 'task' off the items in cumulativedeps (keeps items in sets lower)
  642. revdeps = {}
  643. deps = {}
  644. cumulativedeps = {}
  645. for tid in self.runtaskentries:
  646. deps[tid] = set(self.runtaskentries[tid].depends)
  647. revdeps[tid] = set()
  648. cumulativedeps[tid] = set()
  649. # Generate a temp list of reverse dependencies
  650. for tid in self.runtaskentries:
  651. for dep in self.runtaskentries[tid].depends:
  652. revdeps[dep].add(tid)
  653. # Find the dependency chain endpoints
  654. endpoints = set()
  655. for tid in self.runtaskentries:
  656. if len(deps[tid]) == 0:
  657. endpoints.add(tid)
  658. # Iterate the chains collating dependencies
  659. while endpoints:
  660. next = set()
  661. for tid in endpoints:
  662. for dep in revdeps[tid]:
  663. cumulativedeps[dep].add(fn_from_tid(tid))
  664. cumulativedeps[dep].update(cumulativedeps[tid])
  665. if tid in deps[dep]:
  666. deps[dep].remove(tid)
  667. if len(deps[dep]) == 0:
  668. next.add(dep)
  669. endpoints = next
  670. #for tid in deps:
  671. # if len(deps[tid]) != 0:
  672. # bb.warn("Sanity test failure, dependencies left for %s (%s)" % (tid, deps[tid]))
  673. # Loop here since recrdeptasks can depend upon other recrdeptasks and we have to
  674. # resolve these recursively until we aren't adding any further extra dependencies
  675. extradeps = True
  676. while extradeps:
  677. extradeps = 0
  678. for tid in recursivetasks:
  679. tasknames = recursivetasks[tid]
  680. totaldeps = set(self.runtaskentries[tid].depends)
  681. if tid in recursiveitasks:
  682. totaldeps.update(recursiveitasks[tid])
  683. for dep in recursiveitasks[tid]:
  684. if dep not in self.runtaskentries:
  685. continue
  686. totaldeps.update(self.runtaskentries[dep].depends)
  687. deps = set()
  688. for dep in totaldeps:
  689. if dep in cumulativedeps:
  690. deps.update(cumulativedeps[dep])
  691. for t in deps:
  692. for taskname in tasknames:
  693. newtid = t + ":" + taskname
  694. if newtid == tid:
  695. continue
  696. if newtid in self.runtaskentries and newtid not in self.runtaskentries[tid].depends:
  697. extradeps += 1
  698. self.runtaskentries[tid].depends.add(newtid)
  699. # Handle recursive tasks which depend upon other recursive tasks
  700. deps = set()
  701. for dep in self.runtaskentries[tid].depends.intersection(recursivetasks):
  702. deps.update(self.runtaskentries[dep].depends.difference(self.runtaskentries[tid].depends))
  703. for newtid in deps:
  704. for taskname in tasknames:
  705. if not newtid.endswith(":" + taskname):
  706. continue
  707. if newtid in self.runtaskentries:
  708. extradeps += 1
  709. self.runtaskentries[tid].depends.add(newtid)
  710. bb.debug(1, "Added %s recursive dependencies in this loop" % extradeps)
  711. # Remove recrdeptask circular references so that do_a[recrdeptask] = "do_a do_b" can work
  712. for tid in recursivetasksselfref:
  713. self.runtaskentries[tid].depends.difference_update(recursivetasksselfref)
  714. self.init_progress_reporter.next_stage()
  715. #self.dump_data()
  716. # Step B - Mark all active tasks
  717. #
  718. # Start with the tasks we were asked to run and mark all dependencies
  719. # as active too. If the task is to be 'forced', clear its stamp. Once
  720. # all active tasks are marked, prune the ones we don't need.
  721. logger.verbose("Marking Active Tasks")
  722. def mark_active(tid, depth):
  723. """
  724. Mark an item as active along with its depends
  725. (calls itself recursively)
  726. """
  727. if tid in runq_build:
  728. return
  729. runq_build[tid] = 1
  730. depends = self.runtaskentries[tid].depends
  731. for depend in depends:
  732. mark_active(depend, depth+1)
  733. self.target_tids = []
  734. for (mc, target, task, fn) in self.targets:
  735. if target not in taskData[mc].build_targets or not taskData[mc].build_targets[target]:
  736. continue
  737. if target in taskData[mc].failed_deps:
  738. continue
  739. parents = False
  740. if task.endswith('-'):
  741. parents = True
  742. task = task[:-1]
  743. if fn in taskData[mc].failed_fns:
  744. continue
  745. # fn already has mc prefix
  746. tid = fn + ":" + task
  747. self.target_tids.append(tid)
  748. if tid not in taskData[mc].taskentries:
  749. import difflib
  750. tasks = []
  751. for x in taskData[mc].taskentries:
  752. if x.startswith(fn + ":"):
  753. tasks.append(taskname_from_tid(x))
  754. close_matches = difflib.get_close_matches(task, tasks, cutoff=0.7)
  755. if close_matches:
  756. extra = ". Close matches:\n %s" % "\n ".join(close_matches)
  757. else:
  758. extra = ""
  759. bb.msg.fatal("RunQueue", "Task %s does not exist for target %s (%s)%s" % (task, target, tid, extra))
  760. # For tasks called "XXXX-", ony run their dependencies
  761. if parents:
  762. for i in self.runtaskentries[tid].depends:
  763. mark_active(i, 1)
  764. else:
  765. mark_active(tid, 1)
  766. self.init_progress_reporter.next_stage()
  767. # Step C - Prune all inactive tasks
  768. #
  769. # Once all active tasks are marked, prune the ones we don't need.
  770. delcount = {}
  771. for tid in list(self.runtaskentries.keys()):
  772. if tid not in runq_build:
  773. delcount[tid] = self.runtaskentries[tid]
  774. del self.runtaskentries[tid]
  775. # Handle --runall
  776. if self.cooker.configuration.runall:
  777. # re-run the mark_active and then drop unused tasks from new list
  778. runq_build = {}
  779. for task in self.cooker.configuration.runall:
  780. runall_tids = set()
  781. for tid in list(self.runtaskentries):
  782. wanttid = fn_from_tid(tid) + ":do_%s" % task
  783. if wanttid in delcount:
  784. self.runtaskentries[wanttid] = delcount[wanttid]
  785. if wanttid in self.runtaskentries:
  786. runall_tids.add(wanttid)
  787. for tid in list(runall_tids):
  788. mark_active(tid,1)
  789. for tid in list(self.runtaskentries.keys()):
  790. if tid not in runq_build:
  791. delcount[tid] = self.runtaskentries[tid]
  792. del self.runtaskentries[tid]
  793. if len(self.runtaskentries) == 0:
  794. bb.msg.fatal("RunQueue", "Could not find any tasks with the tasknames %s to run within the recipes of the taskgraphs of the targets %s" % (str(self.cooker.configuration.runall), str(self.targets)))
  795. self.init_progress_reporter.next_stage()
  796. # Handle runonly
  797. if self.cooker.configuration.runonly:
  798. # re-run the mark_active and then drop unused tasks from new list
  799. runq_build = {}
  800. for task in self.cooker.configuration.runonly:
  801. runonly_tids = { k: v for k, v in self.runtaskentries.items() if taskname_from_tid(k) == "do_%s" % task }
  802. for tid in list(runonly_tids):
  803. mark_active(tid,1)
  804. for tid in list(self.runtaskentries.keys()):
  805. if tid not in runq_build:
  806. delcount[tid] = self.runtaskentries[tid]
  807. del self.runtaskentries[tid]
  808. if len(self.runtaskentries) == 0:
  809. bb.msg.fatal("RunQueue", "Could not find any tasks with the tasknames %s to run within the taskgraphs of the targets %s" % (str(self.cooker.configuration.runonly), str(self.targets)))
  810. #
  811. # Step D - Sanity checks and computation
  812. #
  813. # Check to make sure we still have tasks to run
  814. if len(self.runtaskentries) == 0:
  815. if not taskData[''].abort:
  816. bb.msg.fatal("RunQueue", "All buildable tasks have been run but the build is incomplete (--continue mode). Errors for the tasks that failed will have been printed above.")
  817. else:
  818. bb.msg.fatal("RunQueue", "No active tasks and not in --continue mode?! Please report this bug.")
  819. logger.verbose("Pruned %s inactive tasks, %s left", len(delcount), len(self.runtaskentries))
  820. logger.verbose("Assign Weightings")
  821. self.init_progress_reporter.next_stage()
  822. # Generate a list of reverse dependencies to ease future calculations
  823. for tid in self.runtaskentries:
  824. for dep in self.runtaskentries[tid].depends:
  825. self.runtaskentries[dep].revdeps.add(tid)
  826. self.init_progress_reporter.next_stage()
  827. # Identify tasks at the end of dependency chains
  828. # Error on circular dependency loops (length two)
  829. endpoints = []
  830. for tid in self.runtaskentries:
  831. revdeps = self.runtaskentries[tid].revdeps
  832. if len(revdeps) == 0:
  833. endpoints.append(tid)
  834. for dep in revdeps:
  835. if dep in self.runtaskentries[tid].depends:
  836. bb.msg.fatal("RunQueue", "Task %s has circular dependency on %s" % (tid, dep))
  837. logger.verbose("Compute totals (have %s endpoint(s))", len(endpoints))
  838. self.init_progress_reporter.next_stage()
  839. # Calculate task weights
  840. # Check of higher length circular dependencies
  841. self.runq_weight = self.calculate_task_weights(endpoints)
  842. self.init_progress_reporter.next_stage()
  843. # Sanity Check - Check for multiple tasks building the same provider
  844. for mc in self.dataCaches:
  845. prov_list = {}
  846. seen_fn = []
  847. for tid in self.runtaskentries:
  848. (tidmc, fn, taskname, taskfn) = split_tid_mcfn(tid)
  849. if taskfn in seen_fn:
  850. continue
  851. if mc != tidmc:
  852. continue
  853. seen_fn.append(taskfn)
  854. for prov in self.dataCaches[mc].fn_provides[taskfn]:
  855. if prov not in prov_list:
  856. prov_list[prov] = [taskfn]
  857. elif taskfn not in prov_list[prov]:
  858. prov_list[prov].append(taskfn)
  859. for prov in prov_list:
  860. if len(prov_list[prov]) < 2:
  861. continue
  862. if prov in self.multi_provider_whitelist:
  863. continue
  864. seen_pn = []
  865. # If two versions of the same PN are being built its fatal, we don't support it.
  866. for fn in prov_list[prov]:
  867. pn = self.dataCaches[mc].pkg_fn[fn]
  868. if pn not in seen_pn:
  869. seen_pn.append(pn)
  870. else:
  871. bb.fatal("Multiple versions of %s are due to be built (%s). Only one version of a given PN should be built in any given build. You likely need to set PREFERRED_VERSION_%s to select the correct version or don't depend on multiple versions." % (pn, " ".join(prov_list[prov]), pn))
  872. msg = "Multiple .bb files are due to be built which each provide %s:\n %s" % (prov, "\n ".join(prov_list[prov]))
  873. #
  874. # Construct a list of things which uniquely depend on each provider
  875. # since this may help the user figure out which dependency is triggering this warning
  876. #
  877. msg += "\nA list of tasks depending on these providers is shown and may help explain where the dependency comes from."
  878. deplist = {}
  879. commondeps = None
  880. for provfn in prov_list[prov]:
  881. deps = set()
  882. for tid in self.runtaskentries:
  883. fn = fn_from_tid(tid)
  884. if fn != provfn:
  885. continue
  886. for dep in self.runtaskentries[tid].revdeps:
  887. fn = fn_from_tid(dep)
  888. if fn == provfn:
  889. continue
  890. deps.add(dep)
  891. if not commondeps:
  892. commondeps = set(deps)
  893. else:
  894. commondeps &= deps
  895. deplist[provfn] = deps
  896. for provfn in deplist:
  897. msg += "\n%s has unique dependees:\n %s" % (provfn, "\n ".join(deplist[provfn] - commondeps))
  898. #
  899. # Construct a list of provides and runtime providers for each recipe
  900. # (rprovides has to cover RPROVIDES, PACKAGES, PACKAGES_DYNAMIC)
  901. #
  902. msg += "\nIt could be that one recipe provides something the other doesn't and should. The following provider and runtime provider differences may be helpful."
  903. provide_results = {}
  904. rprovide_results = {}
  905. commonprovs = None
  906. commonrprovs = None
  907. for provfn in prov_list[prov]:
  908. provides = set(self.dataCaches[mc].fn_provides[provfn])
  909. rprovides = set()
  910. for rprovide in self.dataCaches[mc].rproviders:
  911. if provfn in self.dataCaches[mc].rproviders[rprovide]:
  912. rprovides.add(rprovide)
  913. for package in self.dataCaches[mc].packages:
  914. if provfn in self.dataCaches[mc].packages[package]:
  915. rprovides.add(package)
  916. for package in self.dataCaches[mc].packages_dynamic:
  917. if provfn in self.dataCaches[mc].packages_dynamic[package]:
  918. rprovides.add(package)
  919. if not commonprovs:
  920. commonprovs = set(provides)
  921. else:
  922. commonprovs &= provides
  923. provide_results[provfn] = provides
  924. if not commonrprovs:
  925. commonrprovs = set(rprovides)
  926. else:
  927. commonrprovs &= rprovides
  928. rprovide_results[provfn] = rprovides
  929. #msg += "\nCommon provides:\n %s" % ("\n ".join(commonprovs))
  930. #msg += "\nCommon rprovides:\n %s" % ("\n ".join(commonrprovs))
  931. for provfn in prov_list[prov]:
  932. msg += "\n%s has unique provides:\n %s" % (provfn, "\n ".join(provide_results[provfn] - commonprovs))
  933. msg += "\n%s has unique rprovides:\n %s" % (provfn, "\n ".join(rprovide_results[provfn] - commonrprovs))
  934. if self.warn_multi_bb:
  935. logger.verbnote(msg)
  936. else:
  937. logger.error(msg)
  938. self.init_progress_reporter.next_stage()
  939. # Create a whitelist usable by the stamp checks
  940. self.stampfnwhitelist = {}
  941. for mc in self.taskData:
  942. self.stampfnwhitelist[mc] = []
  943. for entry in self.stampwhitelist.split():
  944. if entry not in self.taskData[mc].build_targets:
  945. continue
  946. fn = self.taskData.build_targets[entry][0]
  947. self.stampfnwhitelist[mc].append(fn)
  948. self.init_progress_reporter.next_stage()
  949. # Iterate over the task list looking for tasks with a 'setscene' function
  950. self.runq_setscene_tids = []
  951. if not self.cooker.configuration.nosetscene:
  952. for tid in self.runtaskentries:
  953. (mc, fn, taskname, _) = split_tid_mcfn(tid)
  954. setscenetid = tid + "_setscene"
  955. if setscenetid not in taskData[mc].taskentries:
  956. continue
  957. self.runq_setscene_tids.append(tid)
  958. def invalidate_task(tid, error_nostamp):
  959. (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
  960. taskdep = self.dataCaches[mc].task_deps[taskfn]
  961. if fn + ":" + taskname not in taskData[mc].taskentries:
  962. logger.warning("Task %s does not exist, invalidating this task will have no effect" % taskname)
  963. if 'nostamp' in taskdep and taskname in taskdep['nostamp']:
  964. if error_nostamp:
  965. bb.fatal("Task %s is marked nostamp, cannot invalidate this task" % taskname)
  966. else:
  967. bb.debug(1, "Task %s is marked nostamp, cannot invalidate this task" % taskname)
  968. else:
  969. logger.verbose("Invalidate task %s, %s", taskname, fn)
  970. bb.parse.siggen.invalidate_task(taskname, self.dataCaches[mc], taskfn)
  971. self.init_progress_reporter.next_stage()
  972. # Invalidate task if force mode active
  973. if self.cooker.configuration.force:
  974. for tid in self.target_tids:
  975. invalidate_task(tid, False)
  976. # Invalidate task if invalidate mode active
  977. if self.cooker.configuration.invalidate_stamp:
  978. for tid in self.target_tids:
  979. fn = fn_from_tid(tid)
  980. for st in self.cooker.configuration.invalidate_stamp.split(','):
  981. if not st.startswith("do_"):
  982. st = "do_%s" % st
  983. invalidate_task(fn + ":" + st, True)
  984. self.init_progress_reporter.next_stage()
  985. # Create and print to the logs a virtual/xxxx -> PN (fn) table
  986. for mc in taskData:
  987. virtmap = taskData[mc].get_providermap(prefix="virtual/")
  988. virtpnmap = {}
  989. for v in virtmap:
  990. virtpnmap[v] = self.dataCaches[mc].pkg_fn[virtmap[v]]
  991. bb.debug(2, "%s resolved to: %s (%s)" % (v, virtpnmap[v], virtmap[v]))
  992. if hasattr(bb.parse.siggen, "tasks_resolved"):
  993. bb.parse.siggen.tasks_resolved(virtmap, virtpnmap, self.dataCaches[mc])
  994. self.init_progress_reporter.next_stage()
  995. # Iterate over the task list and call into the siggen code
  996. dealtwith = set()
  997. todeal = set(self.runtaskentries)
  998. while len(todeal) > 0:
  999. for tid in todeal.copy():
  1000. if len(self.runtaskentries[tid].depends - dealtwith) == 0:
  1001. dealtwith.add(tid)
  1002. todeal.remove(tid)
  1003. self.prepare_task_hash(tid)
  1004. bb.parse.siggen.writeout_file_checksum_cache()
  1005. #self.dump_data()
  1006. return len(self.runtaskentries)
  1007. def prepare_task_hash(self, tid):
  1008. procdep = []
  1009. for dep in self.runtaskentries[tid].depends:
  1010. procdep.append(fn_from_tid(dep) + "." + taskname_from_tid(dep))
  1011. (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
  1012. self.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(taskfn, taskname, procdep, self.dataCaches[mc])
  1013. self.runtaskentries[tid].unihash = bb.parse.siggen.get_unihash(taskfn + "." + taskname)
  1014. def dump_data(self):
  1015. """
  1016. Dump some debug information on the internal data structures
  1017. """
  1018. logger.debug(3, "run_tasks:")
  1019. for tid in self.runtaskentries:
  1020. logger.debug(3, " %s: %s Deps %s RevDeps %s", tid,
  1021. self.runtaskentries[tid].weight,
  1022. self.runtaskentries[tid].depends,
  1023. self.runtaskentries[tid].revdeps)
  1024. class RunQueueWorker():
  1025. def __init__(self, process, pipe):
  1026. self.process = process
  1027. self.pipe = pipe
  1028. class RunQueue:
  1029. def __init__(self, cooker, cfgData, dataCaches, taskData, targets):
  1030. self.cooker = cooker
  1031. self.cfgData = cfgData
  1032. self.rqdata = RunQueueData(self, cooker, cfgData, dataCaches, taskData, targets)
  1033. self.stamppolicy = cfgData.getVar("BB_STAMP_POLICY") or "perfile"
  1034. self.hashvalidate = cfgData.getVar("BB_HASHCHECK_FUNCTION") or None
  1035. self.setsceneverify = cfgData.getVar("BB_SETSCENE_VERIFY_FUNCTION2") or None
  1036. self.depvalidate = cfgData.getVar("BB_SETSCENE_DEPVALID") or None
  1037. self.state = runQueuePrepare
  1038. # For disk space monitor
  1039. # Invoked at regular time intervals via the bitbake heartbeat event
  1040. # while the build is running. We generate a unique name for the handler
  1041. # here, just in case that there ever is more than one RunQueue instance,
  1042. # start the handler when reaching runQueueSceneRun, and stop it when
  1043. # done with the build.
  1044. self.dm = monitordisk.diskMonitor(cfgData)
  1045. self.dm_event_handler_name = '_bb_diskmonitor_' + str(id(self))
  1046. self.dm_event_handler_registered = False
  1047. self.rqexe = None
  1048. self.worker = {}
  1049. self.fakeworker = {}
  1050. def _start_worker(self, mc, fakeroot = False, rqexec = None):
  1051. logger.debug(1, "Starting bitbake-worker")
  1052. magic = "decafbad"
  1053. if self.cooker.configuration.profile:
  1054. magic = "decafbadbad"
  1055. if fakeroot:
  1056. magic = magic + "beef"
  1057. mcdata = self.cooker.databuilder.mcdata[mc]
  1058. fakerootcmd = shlex.split(mcdata.getVar("FAKEROOTCMD"))
  1059. fakerootenv = (mcdata.getVar("FAKEROOTBASEENV") or "").split()
  1060. env = os.environ.copy()
  1061. for key, value in (var.split('=') for var in fakerootenv):
  1062. env[key] = value
  1063. worker = subprocess.Popen(fakerootcmd + ["bitbake-worker", magic], stdout=subprocess.PIPE, stdin=subprocess.PIPE, env=env)
  1064. else:
  1065. worker = subprocess.Popen(["bitbake-worker", magic], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
  1066. bb.utils.nonblockingfd(worker.stdout)
  1067. workerpipe = runQueuePipe(worker.stdout, None, self.cfgData, self, rqexec)
  1068. workerdata = {
  1069. "taskdeps" : self.rqdata.dataCaches[mc].task_deps,
  1070. "fakerootenv" : self.rqdata.dataCaches[mc].fakerootenv,
  1071. "fakerootdirs" : self.rqdata.dataCaches[mc].fakerootdirs,
  1072. "fakerootnoenv" : self.rqdata.dataCaches[mc].fakerootnoenv,
  1073. "sigdata" : bb.parse.siggen.get_taskdata(),
  1074. "logdefaultdebug" : bb.msg.loggerDefaultDebugLevel,
  1075. "logdefaultverbose" : bb.msg.loggerDefaultVerbose,
  1076. "logdefaultverboselogs" : bb.msg.loggerVerboseLogs,
  1077. "logdefaultdomain" : bb.msg.loggerDefaultDomains,
  1078. "prhost" : self.cooker.prhost,
  1079. "buildname" : self.cfgData.getVar("BUILDNAME"),
  1080. "date" : self.cfgData.getVar("DATE"),
  1081. "time" : self.cfgData.getVar("TIME"),
  1082. }
  1083. worker.stdin.write(b"<cookerconfig>" + pickle.dumps(self.cooker.configuration) + b"</cookerconfig>")
  1084. worker.stdin.write(b"<extraconfigdata>" + pickle.dumps(self.cooker.extraconfigdata) + b"</extraconfigdata>")
  1085. worker.stdin.write(b"<workerdata>" + pickle.dumps(workerdata) + b"</workerdata>")
  1086. worker.stdin.flush()
  1087. return RunQueueWorker(worker, workerpipe)
  1088. def _teardown_worker(self, worker):
  1089. if not worker:
  1090. return
  1091. logger.debug(1, "Teardown for bitbake-worker")
  1092. try:
  1093. worker.process.stdin.write(b"<quit></quit>")
  1094. worker.process.stdin.flush()
  1095. worker.process.stdin.close()
  1096. except IOError:
  1097. pass
  1098. while worker.process.returncode is None:
  1099. worker.pipe.read()
  1100. worker.process.poll()
  1101. while worker.pipe.read():
  1102. continue
  1103. worker.pipe.close()
  1104. def start_worker(self):
  1105. if self.worker:
  1106. self.teardown_workers()
  1107. self.teardown = False
  1108. for mc in self.rqdata.dataCaches:
  1109. self.worker[mc] = self._start_worker(mc)
  1110. def start_fakeworker(self, rqexec, mc):
  1111. if not mc in self.fakeworker:
  1112. self.fakeworker[mc] = self._start_worker(mc, True, rqexec)
  1113. def teardown_workers(self):
  1114. self.teardown = True
  1115. for mc in self.worker:
  1116. self._teardown_worker(self.worker[mc])
  1117. self.worker = {}
  1118. for mc in self.fakeworker:
  1119. self._teardown_worker(self.fakeworker[mc])
  1120. self.fakeworker = {}
  1121. def read_workers(self):
  1122. for mc in self.worker:
  1123. self.worker[mc].pipe.read()
  1124. for mc in self.fakeworker:
  1125. self.fakeworker[mc].pipe.read()
  1126. def active_fds(self):
  1127. fds = []
  1128. for mc in self.worker:
  1129. fds.append(self.worker[mc].pipe.input)
  1130. for mc in self.fakeworker:
  1131. fds.append(self.fakeworker[mc].pipe.input)
  1132. return fds
  1133. def check_stamp_task(self, tid, taskname = None, recurse = False, cache = None):
  1134. def get_timestamp(f):
  1135. try:
  1136. if not os.access(f, os.F_OK):
  1137. return None
  1138. return os.stat(f)[stat.ST_MTIME]
  1139. except:
  1140. return None
  1141. (mc, fn, tn, taskfn) = split_tid_mcfn(tid)
  1142. if taskname is None:
  1143. taskname = tn
  1144. if self.stamppolicy == "perfile":
  1145. fulldeptree = False
  1146. else:
  1147. fulldeptree = True
  1148. stampwhitelist = []
  1149. if self.stamppolicy == "whitelist":
  1150. stampwhitelist = self.rqdata.stampfnwhitelist[mc]
  1151. stampfile = bb.build.stampfile(taskname, self.rqdata.dataCaches[mc], taskfn)
  1152. # If the stamp is missing, it's not current
  1153. if not os.access(stampfile, os.F_OK):
  1154. logger.debug(2, "Stampfile %s not available", stampfile)
  1155. return False
  1156. # If it's a 'nostamp' task, it's not current
  1157. taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn]
  1158. if 'nostamp' in taskdep and taskname in taskdep['nostamp']:
  1159. logger.debug(2, "%s.%s is nostamp\n", fn, taskname)
  1160. return False
  1161. if taskname != "do_setscene" and taskname.endswith("_setscene"):
  1162. return True
  1163. if cache is None:
  1164. cache = {}
  1165. iscurrent = True
  1166. t1 = get_timestamp(stampfile)
  1167. for dep in self.rqdata.runtaskentries[tid].depends:
  1168. if iscurrent:
  1169. (mc2, fn2, taskname2, taskfn2) = split_tid_mcfn(dep)
  1170. stampfile2 = bb.build.stampfile(taskname2, self.rqdata.dataCaches[mc2], taskfn2)
  1171. stampfile3 = bb.build.stampfile(taskname2 + "_setscene", self.rqdata.dataCaches[mc2], taskfn2)
  1172. t2 = get_timestamp(stampfile2)
  1173. t3 = get_timestamp(stampfile3)
  1174. if t3 and not t2:
  1175. continue
  1176. if t3 and t3 > t2:
  1177. continue
  1178. if fn == fn2 or (fulldeptree and fn2 not in stampwhitelist):
  1179. if not t2:
  1180. logger.debug(2, 'Stampfile %s does not exist', stampfile2)
  1181. iscurrent = False
  1182. break
  1183. if t1 < t2:
  1184. logger.debug(2, 'Stampfile %s < %s', stampfile, stampfile2)
  1185. iscurrent = False
  1186. break
  1187. if recurse and iscurrent:
  1188. if dep in cache:
  1189. iscurrent = cache[dep]
  1190. if not iscurrent:
  1191. logger.debug(2, 'Stampfile for dependency %s:%s invalid (cached)' % (fn2, taskname2))
  1192. else:
  1193. iscurrent = self.check_stamp_task(dep, recurse=True, cache=cache)
  1194. cache[dep] = iscurrent
  1195. if recurse:
  1196. cache[tid] = iscurrent
  1197. return iscurrent
  1198. def validate_hash(self, *, sq_fn, sq_task, sq_hash, sq_hashfn, siginfo, sq_unihash, d):
  1199. locs = {"sq_fn" : sq_fn, "sq_task" : sq_task, "sq_hash" : sq_hash, "sq_hashfn" : sq_hashfn,
  1200. "sq_unihash" : sq_unihash, "siginfo" : siginfo, "d" : d}
  1201. hashvalidate_args = ("(sq_fn, sq_task, sq_hash, sq_hashfn, d, siginfo=siginfo, sq_unihash=sq_unihash)",
  1202. "(sq_fn, sq_task, sq_hash, sq_hashfn, d, siginfo=siginfo)",
  1203. "(sq_fn, sq_task, sq_hash, sq_hashfn, d)")
  1204. for args in hashvalidate_args[:-1]:
  1205. try:
  1206. call = self.hashvalidate + args
  1207. return bb.utils.better_eval(call, locs)
  1208. except TypeError:
  1209. continue
  1210. # Call the last entry without a try...catch to propagate any thrown
  1211. # TypeError
  1212. call = self.hashvalidate + hashvalidate_args[-1]
  1213. return bb.utils.better_eval(call, locs)
  1214. def _execute_runqueue(self):
  1215. """
  1216. Run the tasks in a queue prepared by rqdata.prepare()
  1217. Upon failure, optionally try to recover the build using any alternate providers
  1218. (if the abort on failure configuration option isn't set)
  1219. """
  1220. retval = True
  1221. if self.state is runQueuePrepare:
  1222. self.rqexe = RunQueueExecuteDummy(self)
  1223. # NOTE: if you add, remove or significantly refactor the stages of this
  1224. # process then you should recalculate the weightings here. This is quite
  1225. # easy to do - just change the next line temporarily to pass debug=True as
  1226. # the last parameter and you'll get a printout of the weightings as well
  1227. # as a map to the lines where next_stage() was called. Of course this isn't
  1228. # critical, but it helps to keep the progress reporting accurate.
  1229. self.rqdata.init_progress_reporter = bb.progress.MultiStageProcessProgressReporter(self.cooker.data,
  1230. "Initialising tasks",
  1231. [43, 967, 4, 3, 1, 5, 3, 7, 13, 1, 2, 1, 1, 246, 35, 1, 38, 1, 35, 2, 338, 204, 142, 3, 3, 37, 244])
  1232. if self.rqdata.prepare() == 0:
  1233. self.state = runQueueComplete
  1234. else:
  1235. self.state = runQueueSceneInit
  1236. self.rqdata.init_progress_reporter.next_stage()
  1237. # we are ready to run, emit dependency info to any UI or class which
  1238. # needs it
  1239. depgraph = self.cooker.buildDependTree(self, self.rqdata.taskData)
  1240. self.rqdata.init_progress_reporter.next_stage()
  1241. bb.event.fire(bb.event.DepTreeGenerated(depgraph), self.cooker.data)
  1242. if self.state is runQueueSceneInit:
  1243. if not self.dm_event_handler_registered:
  1244. res = bb.event.register(self.dm_event_handler_name,
  1245. lambda x: self.dm.check(self) if self.state in [runQueueSceneRun, runQueueRunning, runQueueCleanUp] else False,
  1246. ('bb.event.HeartbeatEvent',))
  1247. self.dm_event_handler_registered = True
  1248. dump = self.cooker.configuration.dump_signatures
  1249. if dump:
  1250. self.rqdata.init_progress_reporter.finish()
  1251. if 'printdiff' in dump:
  1252. invalidtasks = self.print_diffscenetasks()
  1253. self.dump_signatures(dump)
  1254. if 'printdiff' in dump:
  1255. self.write_diffscenetasks(invalidtasks)
  1256. self.state = runQueueComplete
  1257. else:
  1258. self.rqdata.init_progress_reporter.next_stage()
  1259. self.start_worker()
  1260. self.rqdata.init_progress_reporter.next_stage()
  1261. self.rqexe = RunQueueExecuteScenequeue(self)
  1262. if self.state is runQueueSceneRun:
  1263. retval = self.rqexe.execute()
  1264. if self.state is runQueueRunInit:
  1265. if self.cooker.configuration.setsceneonly:
  1266. self.state = runQueueComplete
  1267. else:
  1268. # Just in case we didn't setscene
  1269. self.rqdata.init_progress_reporter.finish()
  1270. logger.info("Executing RunQueue Tasks")
  1271. self.rqexe = RunQueueExecuteTasks(self)
  1272. self.state = runQueueRunning
  1273. if self.state is runQueueRunning:
  1274. retval = self.rqexe.execute()
  1275. if self.state is runQueueCleanUp:
  1276. retval = self.rqexe.finish()
  1277. build_done = self.state is runQueueComplete or self.state is runQueueFailed
  1278. if build_done and self.dm_event_handler_registered:
  1279. bb.event.remove(self.dm_event_handler_name, None)
  1280. self.dm_event_handler_registered = False
  1281. if build_done and self.rqexe:
  1282. self.teardown_workers()
  1283. if self.rqexe.stats.failed:
  1284. logger.info("Tasks Summary: Attempted %d tasks of which %d didn't need to be rerun and %d failed.", self.rqexe.stats.completed + self.rqexe.stats.failed, self.rqexe.stats.skipped, self.rqexe.stats.failed)
  1285. else:
  1286. # Let's avoid the word "failed" if nothing actually did
  1287. logger.info("Tasks Summary: Attempted %d tasks of which %d didn't need to be rerun and all succeeded.", self.rqexe.stats.completed, self.rqexe.stats.skipped)
  1288. if self.state is runQueueFailed:
  1289. raise bb.runqueue.TaskFailure(self.rqexe.failed_tids)
  1290. if self.state is runQueueComplete:
  1291. # All done
  1292. return False
  1293. # Loop
  1294. return retval
  1295. def execute_runqueue(self):
  1296. # Catch unexpected exceptions and ensure we exit when an error occurs, not loop.
  1297. try:
  1298. return self._execute_runqueue()
  1299. except bb.runqueue.TaskFailure:
  1300. raise
  1301. except SystemExit:
  1302. raise
  1303. except bb.BBHandledException:
  1304. try:
  1305. self.teardown_workers()
  1306. except:
  1307. pass
  1308. self.state = runQueueComplete
  1309. raise
  1310. except Exception as err:
  1311. logger.exception("An uncaught exception occurred in runqueue")
  1312. try:
  1313. self.teardown_workers()
  1314. except:
  1315. pass
  1316. self.state = runQueueComplete
  1317. raise
  1318. def finish_runqueue(self, now = False):
  1319. if not self.rqexe:
  1320. self.state = runQueueComplete
  1321. return
  1322. if now:
  1323. self.rqexe.finish_now()
  1324. else:
  1325. self.rqexe.finish()
  1326. def rq_dump_sigfn(self, fn, options):
  1327. bb_cache = bb.cache.NoCache(self.cooker.databuilder)
  1328. the_data = bb_cache.loadDataFull(fn, self.cooker.collection.get_file_appends(fn))
  1329. siggen = bb.parse.siggen
  1330. dataCaches = self.rqdata.dataCaches
  1331. siggen.dump_sigfn(fn, dataCaches, options)
  1332. def dump_signatures(self, options):
  1333. fns = set()
  1334. bb.note("Reparsing files to collect dependency data")
  1335. for tid in self.rqdata.runtaskentries:
  1336. fn = fn_from_tid(tid)
  1337. fns.add(fn)
  1338. max_process = int(self.cfgData.getVar("BB_NUMBER_PARSE_THREADS") or os.cpu_count() or 1)
  1339. # We cannot use the real multiprocessing.Pool easily due to some local data
  1340. # that can't be pickled. This is a cheap multi-process solution.
  1341. launched = []
  1342. while fns:
  1343. if len(launched) < max_process:
  1344. p = Process(target=self.rq_dump_sigfn, args=(fns.pop(), options))
  1345. p.start()
  1346. launched.append(p)
  1347. for q in launched:
  1348. # The finished processes are joined when calling is_alive()
  1349. if not q.is_alive():
  1350. launched.remove(q)
  1351. for p in launched:
  1352. p.join()
  1353. bb.parse.siggen.dump_sigs(self.rqdata.dataCaches, options)
  1354. return
  1355. def print_diffscenetasks(self):
  1356. valid = []
  1357. sq_hash = []
  1358. sq_hashfn = []
  1359. sq_unihash = []
  1360. sq_fn = []
  1361. sq_taskname = []
  1362. sq_task = []
  1363. noexec = []
  1364. stamppresent = []
  1365. valid_new = set()
  1366. for tid in self.rqdata.runtaskentries:
  1367. (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
  1368. taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn]
  1369. if 'noexec' in taskdep and taskname in taskdep['noexec']:
  1370. noexec.append(tid)
  1371. continue
  1372. sq_fn.append(fn)
  1373. sq_hashfn.append(self.rqdata.dataCaches[mc].hashfn[taskfn])
  1374. sq_hash.append(self.rqdata.runtaskentries[tid].hash)
  1375. sq_unihash.append(self.rqdata.runtaskentries[tid].unihash)
  1376. sq_taskname.append(taskname)
  1377. sq_task.append(tid)
  1378. valid = self.validate_hash(sq_fn=sq_fn, sq_task=sq_taskname, sq_hash=sq_hash, sq_hashfn=sq_hashfn,
  1379. siginfo=True, sq_unihash=sq_unihash, d=self.cooker.data)
  1380. for v in valid:
  1381. valid_new.add(sq_task[v])
  1382. # Tasks which are both setscene and noexec never care about dependencies
  1383. # We therefore find tasks which are setscene and noexec and mark their
  1384. # unique dependencies as valid.
  1385. for tid in noexec:
  1386. if tid not in self.rqdata.runq_setscene_tids:
  1387. continue
  1388. for dep in self.rqdata.runtaskentries[tid].depends:
  1389. hasnoexecparents = True
  1390. for dep2 in self.rqdata.runtaskentries[dep].revdeps:
  1391. if dep2 in self.rqdata.runq_setscene_tids and dep2 in noexec:
  1392. continue
  1393. hasnoexecparents = False
  1394. break
  1395. if hasnoexecparents:
  1396. valid_new.add(dep)
  1397. invalidtasks = set()
  1398. for tid in self.rqdata.runtaskentries:
  1399. if tid not in valid_new and tid not in noexec:
  1400. invalidtasks.add(tid)
  1401. found = set()
  1402. processed = set()
  1403. for tid in invalidtasks:
  1404. toprocess = set([tid])
  1405. while toprocess:
  1406. next = set()
  1407. for t in toprocess:
  1408. for dep in self.rqdata.runtaskentries[t].depends:
  1409. if dep in invalidtasks:
  1410. found.add(tid)
  1411. if dep not in processed:
  1412. processed.add(dep)
  1413. next.add(dep)
  1414. toprocess = next
  1415. if tid in found:
  1416. toprocess = set()
  1417. tasklist = []
  1418. for tid in invalidtasks.difference(found):
  1419. tasklist.append(tid)
  1420. if tasklist:
  1421. bb.plain("The differences between the current build and any cached tasks start at the following tasks:\n" + "\n".join(tasklist))
  1422. return invalidtasks.difference(found)
  1423. def write_diffscenetasks(self, invalidtasks):
  1424. # Define recursion callback
  1425. def recursecb(key, hash1, hash2):
  1426. hashes = [hash1, hash2]
  1427. hashfiles = bb.siggen.find_siginfo(key, None, hashes, self.cfgData)
  1428. recout = []
  1429. if len(hashfiles) == 2:
  1430. out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb)
  1431. recout.extend(list(' ' + l for l in out2))
  1432. else:
  1433. recout.append("Unable to find matching sigdata for %s with hashes %s or %s" % (key, hash1, hash2))
  1434. return recout
  1435. for tid in invalidtasks:
  1436. (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
  1437. pn = self.rqdata.dataCaches[mc].pkg_fn[taskfn]
  1438. h = self.rqdata.runtaskentries[tid].hash
  1439. matches = bb.siggen.find_siginfo(pn, taskname, [], self.cfgData)
  1440. match = None
  1441. for m in matches:
  1442. if h in m:
  1443. match = m
  1444. if match is None:
  1445. bb.fatal("Can't find a task we're supposed to have written out? (hash: %s)?" % h)
  1446. matches = {k : v for k, v in iter(matches.items()) if h not in k}
  1447. if matches:
  1448. latestmatch = sorted(matches.keys(), key=lambda f: matches[f])[-1]
  1449. prevh = __find_sha256__.search(latestmatch).group(0)
  1450. output = bb.siggen.compare_sigfiles(latestmatch, match, recursecb)
  1451. bb.plain("\nTask %s:%s couldn't be used from the cache because:\n We need hash %s, closest matching task was %s\n " % (pn, taskname, h, prevh) + '\n '.join(output))
  1452. class RunQueueExecute:
  1453. def __init__(self, rq):
  1454. self.rq = rq
  1455. self.cooker = rq.cooker
  1456. self.cfgData = rq.cfgData
  1457. self.rqdata = rq.rqdata
  1458. self.number_tasks = int(self.cfgData.getVar("BB_NUMBER_THREADS") or 1)
  1459. self.scheduler = self.cfgData.getVar("BB_SCHEDULER") or "speed"
  1460. self.runq_buildable = set()
  1461. self.runq_running = set()
  1462. self.runq_complete = set()
  1463. self.build_stamps = {}
  1464. self.build_stamps2 = []
  1465. self.failed_tids = []
  1466. self.stampcache = {}
  1467. for mc in rq.worker:
  1468. rq.worker[mc].pipe.setrunqueueexec(self)
  1469. for mc in rq.fakeworker:
  1470. rq.fakeworker[mc].pipe.setrunqueueexec(self)
  1471. if self.number_tasks <= 0:
  1472. bb.fatal("Invalid BB_NUMBER_THREADS %s" % self.number_tasks)
  1473. def runqueue_process_waitpid(self, task, status):
  1474. # self.build_stamps[pid] may not exist when use shared work directory.
  1475. if task in self.build_stamps:
  1476. self.build_stamps2.remove(self.build_stamps[task])
  1477. del self.build_stamps[task]
  1478. if status != 0:
  1479. self.task_fail(task, status)
  1480. else:
  1481. self.task_complete(task)
  1482. return True
  1483. def finish_now(self):
  1484. for mc in self.rq.worker:
  1485. try:
  1486. self.rq.worker[mc].process.stdin.write(b"<finishnow></finishnow>")
  1487. self.rq.worker[mc].process.stdin.flush()
  1488. except IOError:
  1489. # worker must have died?
  1490. pass
  1491. for mc in self.rq.fakeworker:
  1492. try:
  1493. self.rq.fakeworker[mc].process.stdin.write(b"<finishnow></finishnow>")
  1494. self.rq.fakeworker[mc].process.stdin.flush()
  1495. except IOError:
  1496. # worker must have died?
  1497. pass
  1498. if len(self.failed_tids) != 0:
  1499. self.rq.state = runQueueFailed
  1500. return
  1501. self.rq.state = runQueueComplete
  1502. return
  1503. def finish(self):
  1504. self.rq.state = runQueueCleanUp
  1505. if self.stats.active > 0:
  1506. bb.event.fire(runQueueExitWait(self.stats.active), self.cfgData)
  1507. self.rq.read_workers()
  1508. return self.rq.active_fds()
  1509. if len(self.failed_tids) != 0:
  1510. self.rq.state = runQueueFailed
  1511. return True
  1512. self.rq.state = runQueueComplete
  1513. return True
  1514. def check_dependencies(self, task, taskdeps, setscene = False):
  1515. if not self.rq.depvalidate:
  1516. return False
  1517. taskdata = {}
  1518. taskdeps.add(task)
  1519. for dep in taskdeps:
  1520. (mc, fn, taskname, taskfn) = split_tid_mcfn(dep)
  1521. pn = self.rqdata.dataCaches[mc].pkg_fn[taskfn]
  1522. taskdata[dep] = [pn, taskname, fn]
  1523. call = self.rq.depvalidate + "(task, taskdata, notneeded, d)"
  1524. locs = { "task" : task, "taskdata" : taskdata, "notneeded" : self.scenequeue_notneeded, "d" : self.cooker.data }
  1525. valid = bb.utils.better_eval(call, locs)
  1526. return valid
  1527. def can_start_task(self):
  1528. can_start = self.stats.active < self.number_tasks
  1529. return can_start
  1530. class RunQueueExecuteDummy(RunQueueExecute):
  1531. def __init__(self, rq):
  1532. self.rq = rq
  1533. self.stats = RunQueueStats(0)
  1534. def finish(self):
  1535. self.rq.state = runQueueComplete
  1536. return
  1537. class RunQueueExecuteTasks(RunQueueExecute):
  1538. def __init__(self, rq):
  1539. RunQueueExecute.__init__(self, rq)
  1540. self.stats = RunQueueStats(len(self.rqdata.runtaskentries))
  1541. self.stampcache = {}
  1542. initial_covered = self.rq.scenequeue_covered.copy()
  1543. # Mark initial buildable tasks
  1544. for tid in self.rqdata.runtaskentries:
  1545. if len(self.rqdata.runtaskentries[tid].depends) == 0:
  1546. self.runq_buildable.add(tid)
  1547. if len(self.rqdata.runtaskentries[tid].revdeps) > 0 and self.rqdata.runtaskentries[tid].revdeps.issubset(self.rq.scenequeue_covered):
  1548. self.rq.scenequeue_covered.add(tid)
  1549. found = True
  1550. while found:
  1551. found = False
  1552. for tid in self.rqdata.runtaskentries:
  1553. if tid in self.rq.scenequeue_covered:
  1554. continue
  1555. logger.debug(1, 'Considering %s: %s' % (tid, str(self.rqdata.runtaskentries[tid].revdeps)))
  1556. if len(self.rqdata.runtaskentries[tid].revdeps) > 0 and self.rqdata.runtaskentries[tid].revdeps.issubset(self.rq.scenequeue_covered):
  1557. if tid in self.rq.scenequeue_notcovered:
  1558. continue
  1559. found = True
  1560. self.rq.scenequeue_covered.add(tid)
  1561. logger.debug(1, 'Skip list (pre setsceneverify) %s', sorted(self.rq.scenequeue_covered))
  1562. # Allow the metadata to elect for setscene tasks to run anyway
  1563. covered_remove = set()
  1564. if self.rq.setsceneverify:
  1565. invalidtasks = []
  1566. tasknames = {}
  1567. fns = {}
  1568. for tid in self.rqdata.runtaskentries:
  1569. (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
  1570. taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn]
  1571. fns[tid] = taskfn
  1572. tasknames[tid] = taskname
  1573. if 'noexec' in taskdep and taskname in taskdep['noexec']:
  1574. continue
  1575. if self.rq.check_stamp_task(tid, taskname + "_setscene", cache=self.stampcache):
  1576. logger.debug(2, 'Setscene stamp current for task %s', tid)
  1577. continue
  1578. if self.rq.check_stamp_task(tid, taskname, recurse = True, cache=self.stampcache):
  1579. logger.debug(2, 'Normal stamp current for task %s', tid)
  1580. continue
  1581. invalidtasks.append(tid)
  1582. call = self.rq.setsceneverify + "(covered, tasknames, fns, d, invalidtasks=invalidtasks)"
  1583. locs = { "covered" : self.rq.scenequeue_covered, "tasknames" : tasknames, "fns" : fns, "d" : self.cooker.data, "invalidtasks" : invalidtasks }
  1584. covered_remove = bb.utils.better_eval(call, locs)
  1585. def removecoveredtask(tid):
  1586. (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
  1587. taskname = taskname + '_setscene'
  1588. bb.build.del_stamp(taskname, self.rqdata.dataCaches[mc], taskfn)
  1589. self.rq.scenequeue_covered.remove(tid)
  1590. toremove = covered_remove | self.rq.scenequeue_notcovered
  1591. for task in toremove:
  1592. logger.debug(1, 'Not skipping task %s due to setsceneverify', task)
  1593. while toremove:
  1594. covered_remove = []
  1595. for task in toremove:
  1596. if task in self.rq.scenequeue_covered:
  1597. removecoveredtask(task)
  1598. for deptask in self.rqdata.runtaskentries[task].depends:
  1599. if deptask not in self.rq.scenequeue_covered:
  1600. continue
  1601. if deptask in toremove or deptask in covered_remove or deptask in initial_covered:
  1602. continue
  1603. logger.debug(1, 'Task %s depends on task %s so not skipping' % (task, deptask))
  1604. covered_remove.append(deptask)
  1605. toremove = covered_remove
  1606. logger.debug(1, 'Full skip list %s', self.rq.scenequeue_covered)
  1607. for mc in self.rqdata.dataCaches:
  1608. target_pairs = []
  1609. for tid in self.rqdata.target_tids:
  1610. (tidmc, fn, taskname, _) = split_tid_mcfn(tid)
  1611. if tidmc == mc:
  1612. target_pairs.append((fn, taskname))
  1613. event.fire(bb.event.StampUpdate(target_pairs, self.rqdata.dataCaches[mc].stamp), self.cfgData)
  1614. schedulers = self.get_schedulers()
  1615. for scheduler in schedulers:
  1616. if self.scheduler == scheduler.name:
  1617. self.sched = scheduler(self, self.rqdata)
  1618. logger.debug(1, "Using runqueue scheduler '%s'", scheduler.name)
  1619. break
  1620. else:
  1621. bb.fatal("Invalid scheduler '%s'. Available schedulers: %s" %
  1622. (self.scheduler, ", ".join(obj.name for obj in schedulers)))
  1623. def get_schedulers(self):
  1624. schedulers = set(obj for obj in globals().values()
  1625. if type(obj) is type and
  1626. issubclass(obj, RunQueueScheduler))
  1627. user_schedulers = self.cfgData.getVar("BB_SCHEDULERS")
  1628. if user_schedulers:
  1629. for sched in user_schedulers.split():
  1630. if not "." in sched:
  1631. bb.note("Ignoring scheduler '%s' from BB_SCHEDULERS: not an import" % sched)
  1632. continue
  1633. modname, name = sched.rsplit(".", 1)
  1634. try:
  1635. module = __import__(modname, fromlist=(name,))
  1636. except ImportError as exc:
  1637. logger.critical("Unable to import scheduler '%s' from '%s': %s" % (name, modname, exc))
  1638. raise SystemExit(1)
  1639. else:
  1640. schedulers.add(getattr(module, name))
  1641. return schedulers
  1642. def setbuildable(self, task):
  1643. self.runq_buildable.add(task)
  1644. self.sched.newbuildable(task)
  1645. def task_completeoutright(self, task):
  1646. """
  1647. Mark a task as completed
  1648. Look at the reverse dependencies and mark any task with
  1649. completed dependencies as buildable
  1650. """
  1651. self.runq_complete.add(task)
  1652. for revdep in self.rqdata.runtaskentries[task].revdeps:
  1653. if revdep in self.runq_running:
  1654. continue
  1655. if revdep in self.runq_buildable:
  1656. continue
  1657. alldeps = True
  1658. for dep in self.rqdata.runtaskentries[revdep].depends:
  1659. if dep not in self.runq_complete:
  1660. alldeps = False
  1661. break
  1662. if alldeps:
  1663. self.setbuildable(revdep)
  1664. logger.debug(1, "Marking task %s as buildable", revdep)
  1665. def task_complete(self, task):
  1666. self.stats.taskCompleted()
  1667. bb.event.fire(runQueueTaskCompleted(task, self.stats, self.rq), self.cfgData)
  1668. self.task_completeoutright(task)
  1669. def task_fail(self, task, exitcode):
  1670. """
  1671. Called when a task has failed
  1672. Updates the state engine with the failure
  1673. """
  1674. self.stats.taskFailed()
  1675. self.failed_tids.append(task)
  1676. bb.event.fire(runQueueTaskFailed(task, self.stats, exitcode, self.rq), self.cfgData)
  1677. if self.rqdata.taskData[''].abort:
  1678. self.rq.state = runQueueCleanUp
  1679. def task_skip(self, task, reason):
  1680. self.runq_running.add(task)
  1681. self.setbuildable(task)
  1682. bb.event.fire(runQueueTaskSkipped(task, self.stats, self.rq, reason), self.cfgData)
  1683. self.task_completeoutright(task)
  1684. self.stats.taskSkipped()
  1685. self.stats.taskCompleted()
  1686. def execute(self):
  1687. """
  1688. Run the tasks in a queue prepared by rqdata.prepare()
  1689. """
  1690. if self.rqdata.setscenewhitelist is not None and not self.rqdata.setscenewhitelist_checked:
  1691. self.rqdata.setscenewhitelist_checked = True
  1692. # Check tasks that are going to run against the whitelist
  1693. def check_norun_task(tid, showerror=False):
  1694. (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
  1695. # Ignore covered tasks
  1696. if tid in self.rq.scenequeue_covered:
  1697. return False
  1698. # Ignore stamped tasks
  1699. if self.rq.check_stamp_task(tid, taskname, cache=self.stampcache):
  1700. return False
  1701. # Ignore noexec tasks
  1702. taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn]
  1703. if 'noexec' in taskdep and taskname in taskdep['noexec']:
  1704. return False
  1705. pn = self.rqdata.dataCaches[mc].pkg_fn[taskfn]
  1706. if not check_setscene_enforce_whitelist(pn, taskname, self.rqdata.setscenewhitelist):
  1707. if showerror:
  1708. if tid in self.rqdata.runq_setscene_tids:
  1709. logger.error('Task %s.%s attempted to execute unexpectedly and should have been setscened' % (pn, taskname))
  1710. else:
  1711. logger.error('Task %s.%s attempted to execute unexpectedly' % (pn, taskname))
  1712. return True
  1713. return False
  1714. # Look to see if any tasks that we think shouldn't run are going to
  1715. unexpected = False
  1716. for tid in self.rqdata.runtaskentries:
  1717. if check_norun_task(tid):
  1718. unexpected = True
  1719. break
  1720. if unexpected:
  1721. # Run through the tasks in the rough order they'd have executed and print errors
  1722. # (since the order can be useful - usually missing sstate for the last few tasks
  1723. # is the cause of the problem)
  1724. task = self.sched.next()
  1725. while task is not None:
  1726. check_norun_task(task, showerror=True)
  1727. self.task_skip(task, 'Setscene enforcement check')
  1728. task = self.sched.next()
  1729. self.rq.state = runQueueCleanUp
  1730. return True
  1731. self.rq.read_workers()
  1732. if self.stats.total == 0:
  1733. # nothing to do
  1734. self.rq.state = runQueueCleanUp
  1735. task = self.sched.next()
  1736. if task is not None:
  1737. (mc, fn, taskname, taskfn) = split_tid_mcfn(task)
  1738. if task in self.rq.scenequeue_covered:
  1739. logger.debug(2, "Setscene covered task %s", task)
  1740. self.task_skip(task, "covered")
  1741. return True
  1742. if self.rq.check_stamp_task(task, taskname, cache=self.stampcache):
  1743. logger.debug(2, "Stamp current task %s", task)
  1744. self.task_skip(task, "existing")
  1745. return True
  1746. taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn]
  1747. if 'noexec' in taskdep and taskname in taskdep['noexec']:
  1748. startevent = runQueueTaskStarted(task, self.stats, self.rq,
  1749. noexec=True)
  1750. bb.event.fire(startevent, self.cfgData)
  1751. self.runq_running.add(task)
  1752. self.stats.taskActive()
  1753. if not (self.cooker.configuration.dry_run or self.rqdata.setscene_enforce):
  1754. bb.build.make_stamp(taskname, self.rqdata.dataCaches[mc], taskfn)
  1755. self.task_complete(task)
  1756. return True
  1757. else:
  1758. startevent = runQueueTaskStarted(task, self.stats, self.rq)
  1759. bb.event.fire(startevent, self.cfgData)
  1760. taskdepdata = self.build_taskdepdata(task)
  1761. taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn]
  1762. taskhash = self.rqdata.get_task_hash(task)
  1763. unihash = self.rqdata.get_task_unihash(task)
  1764. if 'fakeroot' in taskdep and taskname in taskdep['fakeroot'] and not (self.cooker.configuration.dry_run or self.rqdata.setscene_enforce):
  1765. if not mc in self.rq.fakeworker:
  1766. try:
  1767. self.rq.start_fakeworker(self, mc)
  1768. except OSError as exc:
  1769. logger.critical("Failed to spawn fakeroot worker to run %s: %s" % (task, str(exc)))
  1770. self.rq.state = runQueueFailed
  1771. self.stats.taskFailed()
  1772. return True
  1773. self.rq.fakeworker[mc].process.stdin.write(b"<runtask>" + pickle.dumps((taskfn, task, taskname, taskhash, unihash, False, self.cooker.collection.get_file_appends(taskfn), taskdepdata, self.rqdata.setscene_enforce)) + b"</runtask>")
  1774. self.rq.fakeworker[mc].process.stdin.flush()
  1775. else:
  1776. self.rq.worker[mc].process.stdin.write(b"<runtask>" + pickle.dumps((taskfn, task, taskname, taskhash, unihash, False, self.cooker.collection.get_file_appends(taskfn), taskdepdata, self.rqdata.setscene_enforce)) + b"</runtask>")
  1777. self.rq.worker[mc].process.stdin.flush()
  1778. self.build_stamps[task] = bb.build.stampfile(taskname, self.rqdata.dataCaches[mc], taskfn, noextra=True)
  1779. self.build_stamps2.append(self.build_stamps[task])
  1780. self.runq_running.add(task)
  1781. self.stats.taskActive()
  1782. if self.can_start_task():
  1783. return True
  1784. if self.stats.active > 0:
  1785. self.rq.read_workers()
  1786. return self.rq.active_fds()
  1787. if len(self.failed_tids) != 0:
  1788. self.rq.state = runQueueFailed
  1789. return True
  1790. # Sanity Checks
  1791. for task in self.rqdata.runtaskentries:
  1792. if task not in self.runq_buildable:
  1793. logger.error("Task %s never buildable!", task)
  1794. if task not in self.runq_running:
  1795. logger.error("Task %s never ran!", task)
  1796. if task not in self.runq_complete:
  1797. logger.error("Task %s never completed!", task)
  1798. self.rq.state = runQueueComplete
  1799. return True
  1800. def filtermcdeps(self, task, deps):
  1801. ret = set()
  1802. mainmc = mc_from_tid(task)
  1803. for dep in deps:
  1804. mc = mc_from_tid(dep)
  1805. if mc != mainmc:
  1806. continue
  1807. ret.add(dep)
  1808. return ret
  1809. # We filter out multiconfig dependencies from taskdepdata we pass to the tasks
  1810. # as most code can't handle them
  1811. def build_taskdepdata(self, task):
  1812. taskdepdata = {}
  1813. next = self.rqdata.runtaskentries[task].depends
  1814. next.add(task)
  1815. next = self.filtermcdeps(task, next)
  1816. while next:
  1817. additional = []
  1818. for revdep in next:
  1819. (mc, fn, taskname, taskfn) = split_tid_mcfn(revdep)
  1820. pn = self.rqdata.dataCaches[mc].pkg_fn[taskfn]
  1821. deps = self.rqdata.runtaskentries[revdep].depends
  1822. provides = self.rqdata.dataCaches[mc].fn_provides[taskfn]
  1823. taskhash = self.rqdata.runtaskentries[revdep].hash
  1824. unihash = self.rqdata.runtaskentries[revdep].unihash
  1825. deps = self.filtermcdeps(task, deps)
  1826. taskdepdata[revdep] = [pn, taskname, fn, deps, provides, taskhash, unihash]
  1827. for revdep2 in deps:
  1828. if revdep2 not in taskdepdata:
  1829. additional.append(revdep2)
  1830. next = additional
  1831. #bb.note("Task %s: " % task + str(taskdepdata).replace("], ", "],\n"))
  1832. return taskdepdata
  1833. class RunQueueExecuteScenequeue(RunQueueExecute):
  1834. def __init__(self, rq):
  1835. RunQueueExecute.__init__(self, rq)
  1836. self.scenequeue_covered = set()
  1837. self.scenequeue_notcovered = set()
  1838. self.scenequeue_notneeded = set()
  1839. # If we don't have any setscene functions, skip this step
  1840. if len(self.rqdata.runq_setscene_tids) == 0:
  1841. rq.scenequeue_covered = set()
  1842. rq.scenequeue_notcovered = set()
  1843. rq.state = runQueueRunInit
  1844. return
  1845. self.stats = RunQueueStats(len(self.rqdata.runq_setscene_tids))
  1846. sq_revdeps = {}
  1847. sq_revdeps_new = {}
  1848. sq_revdeps_squash = {}
  1849. self.sq_harddeps = {}
  1850. self.stamps = {}
  1851. # We need to construct a dependency graph for the setscene functions. Intermediate
  1852. # dependencies between the setscene tasks only complicate the code. This code
  1853. # therefore aims to collapse the huge runqueue dependency tree into a smaller one
  1854. # only containing the setscene functions.
  1855. self.rqdata.init_progress_reporter.next_stage()
  1856. # First process the chains up to the first setscene task.
  1857. endpoints = {}
  1858. for tid in self.rqdata.runtaskentries:
  1859. sq_revdeps[tid] = copy.copy(self.rqdata.runtaskentries[tid].revdeps)
  1860. sq_revdeps_new[tid] = set()
  1861. if (len(sq_revdeps[tid]) == 0) and tid not in self.rqdata.runq_setscene_tids:
  1862. #bb.warn("Added endpoint %s" % (tid))
  1863. endpoints[tid] = set()
  1864. self.rqdata.init_progress_reporter.next_stage()
  1865. # Secondly process the chains between setscene tasks.
  1866. for tid in self.rqdata.runq_setscene_tids:
  1867. #bb.warn("Added endpoint 2 %s" % (tid))
  1868. for dep in self.rqdata.runtaskentries[tid].depends:
  1869. if tid in sq_revdeps[dep]:
  1870. sq_revdeps[dep].remove(tid)
  1871. if dep not in endpoints:
  1872. endpoints[dep] = set()
  1873. #bb.warn(" Added endpoint 3 %s" % (dep))
  1874. endpoints[dep].add(tid)
  1875. self.rqdata.init_progress_reporter.next_stage()
  1876. def process_endpoints(endpoints):
  1877. newendpoints = {}
  1878. for point, task in endpoints.items():
  1879. tasks = set()
  1880. if task:
  1881. tasks |= task
  1882. if sq_revdeps_new[point]:
  1883. tasks |= sq_revdeps_new[point]
  1884. sq_revdeps_new[point] = set()
  1885. if point in self.rqdata.runq_setscene_tids:
  1886. sq_revdeps_new[point] = tasks
  1887. tasks = set()
  1888. continue
  1889. for dep in self.rqdata.runtaskentries[point].depends:
  1890. if point in sq_revdeps[dep]:
  1891. sq_revdeps[dep].remove(point)
  1892. if tasks:
  1893. sq_revdeps_new[dep] |= tasks
  1894. if len(sq_revdeps[dep]) == 0 and dep not in self.rqdata.runq_setscene_tids:
  1895. newendpoints[dep] = task
  1896. if len(newendpoints) != 0:
  1897. process_endpoints(newendpoints)
  1898. process_endpoints(endpoints)
  1899. self.rqdata.init_progress_reporter.next_stage()
  1900. # Build a list of setscene tasks which are "unskippable"
  1901. # These are direct endpoints referenced by the build
  1902. endpoints2 = {}
  1903. sq_revdeps2 = {}
  1904. sq_revdeps_new2 = {}
  1905. def process_endpoints2(endpoints):
  1906. newendpoints = {}
  1907. for point, task in endpoints.items():
  1908. tasks = set([point])
  1909. if task:
  1910. tasks |= task
  1911. if sq_revdeps_new2[point]:
  1912. tasks |= sq_revdeps_new2[point]
  1913. sq_revdeps_new2[point] = set()
  1914. if point in self.rqdata.runq_setscene_tids:
  1915. sq_revdeps_new2[point] = tasks
  1916. for dep in self.rqdata.runtaskentries[point].depends:
  1917. if point in sq_revdeps2[dep]:
  1918. sq_revdeps2[dep].remove(point)
  1919. if tasks:
  1920. sq_revdeps_new2[dep] |= tasks
  1921. if (len(sq_revdeps2[dep]) == 0 or len(sq_revdeps_new2[dep]) != 0) and dep not in self.rqdata.runq_setscene_tids:
  1922. newendpoints[dep] = tasks
  1923. if len(newendpoints) != 0:
  1924. process_endpoints2(newendpoints)
  1925. for tid in self.rqdata.runtaskentries:
  1926. sq_revdeps2[tid] = copy.copy(self.rqdata.runtaskentries[tid].revdeps)
  1927. sq_revdeps_new2[tid] = set()
  1928. if (len(sq_revdeps2[tid]) == 0) and tid not in self.rqdata.runq_setscene_tids:
  1929. endpoints2[tid] = set()
  1930. process_endpoints2(endpoints2)
  1931. self.unskippable = []
  1932. for tid in self.rqdata.runq_setscene_tids:
  1933. if sq_revdeps_new2[tid]:
  1934. self.unskippable.append(tid)
  1935. self.rqdata.init_progress_reporter.next_stage(len(self.rqdata.runtaskentries))
  1936. for taskcounter, tid in enumerate(self.rqdata.runtaskentries):
  1937. if tid in self.rqdata.runq_setscene_tids:
  1938. deps = set()
  1939. for dep in sq_revdeps_new[tid]:
  1940. deps.add(dep)
  1941. sq_revdeps_squash[tid] = deps
  1942. elif len(sq_revdeps_new[tid]) != 0:
  1943. bb.msg.fatal("RunQueue", "Something went badly wrong during scenequeue generation, aborting. Please report this problem.")
  1944. self.rqdata.init_progress_reporter.update(taskcounter)
  1945. self.rqdata.init_progress_reporter.next_stage()
  1946. # Resolve setscene inter-task dependencies
  1947. # e.g. do_sometask_setscene[depends] = "targetname:do_someothertask_setscene"
  1948. # Note that anything explicitly depended upon will have its reverse dependencies removed to avoid circular dependencies
  1949. for tid in self.rqdata.runq_setscene_tids:
  1950. (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
  1951. realtid = tid + "_setscene"
  1952. idepends = self.rqdata.taskData[mc].taskentries[realtid].idepends
  1953. self.stamps[tid] = bb.build.stampfile(taskname + "_setscene", self.rqdata.dataCaches[mc], taskfn, noextra=True)
  1954. for (depname, idependtask) in idepends:
  1955. if depname not in self.rqdata.taskData[mc].build_targets:
  1956. continue
  1957. depfn = self.rqdata.taskData[mc].build_targets[depname][0]
  1958. if depfn is None:
  1959. continue
  1960. deptid = depfn + ":" + idependtask.replace("_setscene", "")
  1961. if deptid not in self.rqdata.runtaskentries:
  1962. bb.msg.fatal("RunQueue", "Task %s depends upon non-existent task %s:%s" % (realtid, depfn, idependtask))
  1963. if not deptid in self.sq_harddeps:
  1964. self.sq_harddeps[deptid] = set()
  1965. self.sq_harddeps[deptid].add(tid)
  1966. sq_revdeps_squash[tid].add(deptid)
  1967. # Have to zero this to avoid circular dependencies
  1968. sq_revdeps_squash[deptid] = set()
  1969. self.rqdata.init_progress_reporter.next_stage()
  1970. for task in self.sq_harddeps:
  1971. for dep in self.sq_harddeps[task]:
  1972. sq_revdeps_squash[dep].add(task)
  1973. self.rqdata.init_progress_reporter.next_stage()
  1974. #for tid in sq_revdeps_squash:
  1975. # for dep in sq_revdeps_squash[tid]:
  1976. # data = data + "\n %s" % dep
  1977. # bb.warn("Task %s_setscene: is %s " % (tid, data
  1978. self.sq_deps = {}
  1979. self.sq_revdeps = sq_revdeps_squash
  1980. self.sq_revdeps2 = copy.deepcopy(self.sq_revdeps)
  1981. for tid in self.sq_revdeps:
  1982. self.sq_deps[tid] = set()
  1983. for tid in self.sq_revdeps:
  1984. for dep in self.sq_revdeps[tid]:
  1985. self.sq_deps[dep].add(tid)
  1986. self.rqdata.init_progress_reporter.next_stage()
  1987. for tid in self.sq_revdeps:
  1988. if len(self.sq_revdeps[tid]) == 0:
  1989. self.runq_buildable.add(tid)
  1990. self.rqdata.init_progress_reporter.finish()
  1991. self.outrightfail = []
  1992. if self.rq.hashvalidate:
  1993. sq_hash = []
  1994. sq_hashfn = []
  1995. sq_unihash = []
  1996. sq_fn = []
  1997. sq_taskname = []
  1998. sq_task = []
  1999. noexec = []
  2000. stamppresent = []
  2001. for tid in self.sq_revdeps:
  2002. (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
  2003. taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn]
  2004. if 'noexec' in taskdep and taskname in taskdep['noexec']:
  2005. noexec.append(tid)
  2006. self.task_skip(tid)
  2007. bb.build.make_stamp(taskname + "_setscene", self.rqdata.dataCaches[mc], taskfn)
  2008. continue
  2009. if self.rq.check_stamp_task(tid, taskname + "_setscene", cache=self.stampcache):
  2010. logger.debug(2, 'Setscene stamp current for task %s', tid)
  2011. stamppresent.append(tid)
  2012. self.task_skip(tid)
  2013. continue
  2014. if self.rq.check_stamp_task(tid, taskname, recurse = True, cache=self.stampcache):
  2015. logger.debug(2, 'Normal stamp current for task %s', tid)
  2016. stamppresent.append(tid)
  2017. self.task_skip(tid)
  2018. continue
  2019. sq_fn.append(fn)
  2020. sq_hashfn.append(self.rqdata.dataCaches[mc].hashfn[taskfn])
  2021. sq_hash.append(self.rqdata.runtaskentries[tid].hash)
  2022. sq_unihash.append(self.rqdata.runtaskentries[tid].unihash)
  2023. sq_taskname.append(taskname)
  2024. sq_task.append(tid)
  2025. self.cooker.data.setVar("BB_SETSCENE_STAMPCURRENT_COUNT", len(stamppresent))
  2026. valid = self.rq.validate_hash(sq_fn=sq_fn, sq_task=sq_taskname, sq_hash=sq_hash, sq_hashfn=sq_hashfn,
  2027. siginfo=False, sq_unihash=sq_unihash, d=self.cooker.data)
  2028. self.cooker.data.delVar("BB_SETSCENE_STAMPCURRENT_COUNT")
  2029. valid_new = stamppresent
  2030. for v in valid:
  2031. valid_new.append(sq_task[v])
  2032. for tid in self.sq_revdeps:
  2033. if tid not in valid_new and tid not in noexec:
  2034. logger.debug(2, 'No package found, so skipping setscene task %s', tid)
  2035. self.outrightfail.append(tid)
  2036. logger.info('Executing SetScene Tasks')
  2037. self.rq.state = runQueueSceneRun
  2038. def scenequeue_updatecounters(self, task, fail = False):
  2039. for dep in self.sq_deps[task]:
  2040. if fail and task in self.sq_harddeps and dep in self.sq_harddeps[task]:
  2041. logger.debug(2, "%s was unavailable and is a hard dependency of %s so skipping" % (task, dep))
  2042. self.scenequeue_updatecounters(dep, fail)
  2043. continue
  2044. if task not in self.sq_revdeps2[dep]:
  2045. # May already have been removed by the fail case above
  2046. continue
  2047. self.sq_revdeps2[dep].remove(task)
  2048. if len(self.sq_revdeps2[dep]) == 0:
  2049. self.runq_buildable.add(dep)
  2050. def task_completeoutright(self, task):
  2051. """
  2052. Mark a task as completed
  2053. Look at the reverse dependencies and mark any task with
  2054. completed dependencies as buildable
  2055. """
  2056. logger.debug(1, 'Found task %s which could be accelerated', task)
  2057. self.scenequeue_covered.add(task)
  2058. self.scenequeue_updatecounters(task)
  2059. def check_taskfail(self, task):
  2060. if self.rqdata.setscenewhitelist is not None:
  2061. realtask = task.split('_setscene')[0]
  2062. (mc, fn, taskname, taskfn) = split_tid_mcfn(realtask)
  2063. pn = self.rqdata.dataCaches[mc].pkg_fn[taskfn]
  2064. if not check_setscene_enforce_whitelist(pn, taskname, self.rqdata.setscenewhitelist):
  2065. logger.error('Task %s.%s failed' % (pn, taskname + "_setscene"))
  2066. self.rq.state = runQueueCleanUp
  2067. def task_complete(self, task):
  2068. self.stats.taskCompleted()
  2069. bb.event.fire(sceneQueueTaskCompleted(task, self.stats, self.rq), self.cfgData)
  2070. self.task_completeoutright(task)
  2071. def task_fail(self, task, result):
  2072. self.stats.taskFailed()
  2073. bb.event.fire(sceneQueueTaskFailed(task, self.stats, result, self), self.cfgData)
  2074. self.scenequeue_notcovered.add(task)
  2075. self.scenequeue_updatecounters(task, True)
  2076. self.check_taskfail(task)
  2077. def task_failoutright(self, task):
  2078. self.runq_running.add(task)
  2079. self.runq_buildable.add(task)
  2080. self.stats.taskSkipped()
  2081. self.stats.taskCompleted()
  2082. self.scenequeue_notcovered.add(task)
  2083. self.scenequeue_updatecounters(task, True)
  2084. def task_skip(self, task):
  2085. self.runq_running.add(task)
  2086. self.runq_buildable.add(task)
  2087. self.task_completeoutright(task)
  2088. self.stats.taskSkipped()
  2089. self.stats.taskCompleted()
  2090. def execute(self):
  2091. """
  2092. Run the tasks in a queue prepared by prepare_runqueue
  2093. """
  2094. self.rq.read_workers()
  2095. task = None
  2096. if self.can_start_task():
  2097. # Find the next setscene to run
  2098. for nexttask in self.rqdata.runq_setscene_tids:
  2099. if nexttask in self.runq_buildable and nexttask not in self.runq_running and self.stamps[nexttask] not in self.build_stamps.values():
  2100. if nexttask in self.unskippable:
  2101. logger.debug(2, "Setscene task %s is unskippable" % nexttask)
  2102. if nexttask not in self.unskippable and len(self.sq_revdeps[nexttask]) > 0 and self.sq_revdeps[nexttask].issubset(self.scenequeue_covered) and self.check_dependencies(nexttask, self.sq_revdeps[nexttask], True):
  2103. fn = fn_from_tid(nexttask)
  2104. foundtarget = False
  2105. if nexttask in self.rqdata.target_tids:
  2106. foundtarget = True
  2107. if not foundtarget:
  2108. logger.debug(2, "Skipping setscene for task %s" % nexttask)
  2109. self.task_skip(nexttask)
  2110. self.scenequeue_notneeded.add(nexttask)
  2111. return True
  2112. if nexttask in self.outrightfail:
  2113. self.task_failoutright(nexttask)
  2114. return True
  2115. task = nexttask
  2116. break
  2117. if task is not None:
  2118. (mc, fn, taskname, taskfn) = split_tid_mcfn(task)
  2119. taskname = taskname + "_setscene"
  2120. if self.rq.check_stamp_task(task, taskname_from_tid(task), recurse = True, cache=self.stampcache):
  2121. logger.debug(2, 'Stamp for underlying task %s is current, so skipping setscene variant', task)
  2122. self.task_failoutright(task)
  2123. return True
  2124. if self.cooker.configuration.force:
  2125. if task in self.rqdata.target_tids:
  2126. self.task_failoutright(task)
  2127. return True
  2128. if self.rq.check_stamp_task(task, taskname, cache=self.stampcache):
  2129. logger.debug(2, 'Setscene stamp current task %s, so skip it and its dependencies', task)
  2130. self.task_skip(task)
  2131. return True
  2132. startevent = sceneQueueTaskStarted(task, self.stats, self.rq)
  2133. bb.event.fire(startevent, self.cfgData)
  2134. taskdepdata = self.build_taskdepdata(task)
  2135. taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn]
  2136. taskhash = self.rqdata.get_task_hash(task)
  2137. unihash = self.rqdata.get_task_unihash(task)
  2138. if 'fakeroot' in taskdep and taskname in taskdep['fakeroot'] and not self.cooker.configuration.dry_run:
  2139. if not mc in self.rq.fakeworker:
  2140. self.rq.start_fakeworker(self, mc)
  2141. self.rq.fakeworker[mc].process.stdin.write(b"<runtask>" + pickle.dumps((taskfn, task, taskname, taskhash, unihash, True, self.cooker.collection.get_file_appends(taskfn), taskdepdata, False)) + b"</runtask>")
  2142. self.rq.fakeworker[mc].process.stdin.flush()
  2143. else:
  2144. self.rq.worker[mc].process.stdin.write(b"<runtask>" + pickle.dumps((taskfn, task, taskname, taskhash, unihash, True, self.cooker.collection.get_file_appends(taskfn), taskdepdata, False)) + b"</runtask>")
  2145. self.rq.worker[mc].process.stdin.flush()
  2146. self.build_stamps[task] = bb.build.stampfile(taskname, self.rqdata.dataCaches[mc], taskfn, noextra=True)
  2147. self.build_stamps2.append(self.build_stamps[task])
  2148. self.runq_running.add(task)
  2149. self.stats.taskActive()
  2150. if self.can_start_task():
  2151. return True
  2152. if self.stats.active > 0:
  2153. self.rq.read_workers()
  2154. return self.rq.active_fds()
  2155. #for tid in self.sq_revdeps:
  2156. # if tid not in self.runq_running:
  2157. # buildable = tid in self.runq_buildable
  2158. # revdeps = self.sq_revdeps[tid]
  2159. # bb.warn("Found we didn't run %s %s %s" % (tid, buildable, str(revdeps)))
  2160. self.rq.scenequeue_covered = self.scenequeue_covered
  2161. self.rq.scenequeue_notcovered = self.scenequeue_notcovered
  2162. logger.debug(1, 'We can skip tasks %s', "\n".join(sorted(self.rq.scenequeue_covered)))
  2163. self.rq.state = runQueueRunInit
  2164. completeevent = sceneQueueComplete(self.stats, self.rq)
  2165. bb.event.fire(completeevent, self.cfgData)
  2166. return True
  2167. def runqueue_process_waitpid(self, task, status):
  2168. RunQueueExecute.runqueue_process_waitpid(self, task, status)
  2169. def build_taskdepdata(self, task):
  2170. def getsetscenedeps(tid):
  2171. deps = set()
  2172. (mc, fn, taskname, _) = split_tid_mcfn(tid)
  2173. realtid = tid + "_setscene"
  2174. idepends = self.rqdata.taskData[mc].taskentries[realtid].idepends
  2175. for (depname, idependtask) in idepends:
  2176. if depname not in self.rqdata.taskData[mc].build_targets:
  2177. continue
  2178. depfn = self.rqdata.taskData[mc].build_targets[depname][0]
  2179. if depfn is None:
  2180. continue
  2181. deptid = depfn + ":" + idependtask.replace("_setscene", "")
  2182. deps.add(deptid)
  2183. return deps
  2184. taskdepdata = {}
  2185. next = getsetscenedeps(task)
  2186. next.add(task)
  2187. while next:
  2188. additional = []
  2189. for revdep in next:
  2190. (mc, fn, taskname, taskfn) = split_tid_mcfn(revdep)
  2191. pn = self.rqdata.dataCaches[mc].pkg_fn[taskfn]
  2192. deps = getsetscenedeps(revdep)
  2193. provides = self.rqdata.dataCaches[mc].fn_provides[taskfn]
  2194. taskhash = self.rqdata.runtaskentries[revdep].hash
  2195. unihash = self.rqdata.runtaskentries[revdep].unihash
  2196. taskdepdata[revdep] = [pn, taskname, fn, deps, provides, taskhash, unihash]
  2197. for revdep2 in deps:
  2198. if revdep2 not in taskdepdata:
  2199. additional.append(revdep2)
  2200. next = additional
  2201. #bb.note("Task %s: " % task + str(taskdepdata).replace("], ", "],\n"))
  2202. return taskdepdata
  2203. class TaskFailure(Exception):
  2204. """
  2205. Exception raised when a task in a runqueue fails
  2206. """
  2207. def __init__(self, x):
  2208. self.args = x
  2209. class runQueueExitWait(bb.event.Event):
  2210. """
  2211. Event when waiting for task processes to exit
  2212. """
  2213. def __init__(self, remain):
  2214. self.remain = remain
  2215. self.message = "Waiting for %s active tasks to finish" % remain
  2216. bb.event.Event.__init__(self)
  2217. class runQueueEvent(bb.event.Event):
  2218. """
  2219. Base runQueue event class
  2220. """
  2221. def __init__(self, task, stats, rq):
  2222. self.taskid = task
  2223. self.taskstring = task
  2224. self.taskname = taskname_from_tid(task)
  2225. self.taskfile = fn_from_tid(task)
  2226. self.taskhash = rq.rqdata.get_task_hash(task)
  2227. self.stats = stats.copy()
  2228. bb.event.Event.__init__(self)
  2229. class sceneQueueEvent(runQueueEvent):
  2230. """
  2231. Base sceneQueue event class
  2232. """
  2233. def __init__(self, task, stats, rq, noexec=False):
  2234. runQueueEvent.__init__(self, task, stats, rq)
  2235. self.taskstring = task + "_setscene"
  2236. self.taskname = taskname_from_tid(task) + "_setscene"
  2237. self.taskfile = fn_from_tid(task)
  2238. self.taskhash = rq.rqdata.get_task_hash(task)
  2239. class runQueueTaskStarted(runQueueEvent):
  2240. """
  2241. Event notifying a task was started
  2242. """
  2243. def __init__(self, task, stats, rq, noexec=False):
  2244. runQueueEvent.__init__(self, task, stats, rq)
  2245. self.noexec = noexec
  2246. class sceneQueueTaskStarted(sceneQueueEvent):
  2247. """
  2248. Event notifying a setscene task was started
  2249. """
  2250. def __init__(self, task, stats, rq, noexec=False):
  2251. sceneQueueEvent.__init__(self, task, stats, rq)
  2252. self.noexec = noexec
  2253. class runQueueTaskFailed(runQueueEvent):
  2254. """
  2255. Event notifying a task failed
  2256. """
  2257. def __init__(self, task, stats, exitcode, rq):
  2258. runQueueEvent.__init__(self, task, stats, rq)
  2259. self.exitcode = exitcode
  2260. def __str__(self):
  2261. return "Task (%s) failed with exit code '%s'" % (self.taskstring, self.exitcode)
  2262. class sceneQueueTaskFailed(sceneQueueEvent):
  2263. """
  2264. Event notifying a setscene task failed
  2265. """
  2266. def __init__(self, task, stats, exitcode, rq):
  2267. sceneQueueEvent.__init__(self, task, stats, rq)
  2268. self.exitcode = exitcode
  2269. def __str__(self):
  2270. return "Setscene task (%s) failed with exit code '%s' - real task will be run instead" % (self.taskstring, self.exitcode)
  2271. class sceneQueueComplete(sceneQueueEvent):
  2272. """
  2273. Event when all the sceneQueue tasks are complete
  2274. """
  2275. def __init__(self, stats, rq):
  2276. self.stats = stats.copy()
  2277. bb.event.Event.__init__(self)
  2278. class runQueueTaskCompleted(runQueueEvent):
  2279. """
  2280. Event notifying a task completed
  2281. """
  2282. class sceneQueueTaskCompleted(sceneQueueEvent):
  2283. """
  2284. Event notifying a setscene task completed
  2285. """
  2286. class runQueueTaskSkipped(runQueueEvent):
  2287. """
  2288. Event notifying a task was skipped
  2289. """
  2290. def __init__(self, task, stats, rq, reason):
  2291. runQueueEvent.__init__(self, task, stats, rq)
  2292. self.reason = reason
  2293. class runQueuePipe():
  2294. """
  2295. Abstraction for a pipe between a worker thread and the server
  2296. """
  2297. def __init__(self, pipein, pipeout, d, rq, rqexec):
  2298. self.input = pipein
  2299. if pipeout:
  2300. pipeout.close()
  2301. bb.utils.nonblockingfd(self.input)
  2302. self.queue = b""
  2303. self.d = d
  2304. self.rq = rq
  2305. self.rqexec = rqexec
  2306. def setrunqueueexec(self, rqexec):
  2307. self.rqexec = rqexec
  2308. def read(self):
  2309. for workers, name in [(self.rq.worker, "Worker"), (self.rq.fakeworker, "Fakeroot")]:
  2310. for worker in workers.values():
  2311. worker.process.poll()
  2312. if worker.process.returncode is not None and not self.rq.teardown:
  2313. bb.error("%s process (%s) exited unexpectedly (%s), shutting down..." % (name, worker.process.pid, str(worker.process.returncode)))
  2314. self.rq.finish_runqueue(True)
  2315. start = len(self.queue)
  2316. try:
  2317. self.queue = self.queue + (self.input.read(102400) or b"")
  2318. except (OSError, IOError) as e:
  2319. if e.errno != errno.EAGAIN:
  2320. raise
  2321. end = len(self.queue)
  2322. found = True
  2323. while found and len(self.queue):
  2324. found = False
  2325. index = self.queue.find(b"</event>")
  2326. while index != -1 and self.queue.startswith(b"<event>"):
  2327. try:
  2328. event = pickle.loads(self.queue[7:index])
  2329. except ValueError as e:
  2330. bb.msg.fatal("RunQueue", "failed load pickle '%s': '%s'" % (e, self.queue[7:index]))
  2331. bb.event.fire_from_worker(event, self.d)
  2332. found = True
  2333. self.queue = self.queue[index+8:]
  2334. index = self.queue.find(b"</event>")
  2335. index = self.queue.find(b"</exitcode>")
  2336. while index != -1 and self.queue.startswith(b"<exitcode>"):
  2337. try:
  2338. task, status = pickle.loads(self.queue[10:index])
  2339. except ValueError as e:
  2340. bb.msg.fatal("RunQueue", "failed load pickle '%s': '%s'" % (e, self.queue[10:index]))
  2341. self.rqexec.runqueue_process_waitpid(task, status)
  2342. found = True
  2343. self.queue = self.queue[index+11:]
  2344. index = self.queue.find(b"</exitcode>")
  2345. return (end > start)
  2346. def close(self):
  2347. while self.read():
  2348. continue
  2349. if len(self.queue) > 0:
  2350. print("Warning, worker left partial message: %s" % self.queue)
  2351. self.input.close()
  2352. def get_setscene_enforce_whitelist(d):
  2353. if d.getVar('BB_SETSCENE_ENFORCE') != '1':
  2354. return None
  2355. whitelist = (d.getVar("BB_SETSCENE_ENFORCE_WHITELIST") or "").split()
  2356. outlist = []
  2357. for item in whitelist[:]:
  2358. if item.startswith('%:'):
  2359. for target in sys.argv[1:]:
  2360. if not target.startswith('-'):
  2361. outlist.append(target.split(':')[0] + ':' + item.split(':')[1])
  2362. else:
  2363. outlist.append(item)
  2364. return outlist
  2365. def check_setscene_enforce_whitelist(pn, taskname, whitelist):
  2366. import fnmatch
  2367. if whitelist is not None:
  2368. item = '%s:%s' % (pn, taskname)
  2369. for whitelist_item in whitelist:
  2370. if fnmatch.fnmatch(item, whitelist_item):
  2371. return True
  2372. return False
  2373. return True