diff options
Diffstat (limited to 'bitbake/lib/bb/cooker.py')
-rw-r--r-- | bitbake/lib/bb/cooker.py | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py index ca37cfea95..ceaaac11ee 100644 --- a/bitbake/lib/bb/cooker.py +++ b/bitbake/lib/bb/cooker.py | |||
@@ -8,7 +8,7 @@ | |||
8 | # | 8 | # |
9 | # SPDX-License-Identifier: GPL-2.0-only | 9 | # SPDX-License-Identifier: GPL-2.0-only |
10 | # | 10 | # |
11 | 11 | import enum | |
12 | import sys, os, glob, os.path, re, time | 12 | import sys, os, glob, os.path, re, time |
13 | import itertools | 13 | import itertools |
14 | import logging | 14 | import logging |
@@ -48,16 +48,15 @@ class CollectionError(bb.BBHandledException): | |||
48 | Exception raised when layer configuration is incorrect | 48 | Exception raised when layer configuration is incorrect |
49 | """ | 49 | """ |
50 | 50 | ||
51 | class state: | ||
52 | initial, parsing, running, shutdown, forceshutdown, stopped, error = list(range(7)) | ||
53 | 51 | ||
54 | @classmethod | 52 | class State(enum.Enum): |
55 | def get_name(cls, code): | 53 | INITIAL = 0, |
56 | for name in dir(cls): | 54 | PARSING = 1, |
57 | value = getattr(cls, name) | 55 | RUNNING = 2, |
58 | if type(value) == type(cls.initial) and value == code: | 56 | SHUTDOWN = 3, |
59 | return name | 57 | FORCE_SHUTDOWN = 4, |
60 | raise ValueError("Invalid status code: %s" % code) | 58 | STOPPED = 5, |
59 | ERROR = 6 | ||
61 | 60 | ||
62 | 61 | ||
63 | class SkippedPackage: | 62 | class SkippedPackage: |
@@ -180,7 +179,7 @@ class BBCooker: | |||
180 | pass | 179 | pass |
181 | 180 | ||
182 | self.command = bb.command.Command(self, self.process_server) | 181 | self.command = bb.command.Command(self, self.process_server) |
183 | self.state = state.initial | 182 | self.state = State.INITIAL |
184 | 183 | ||
185 | self.parser = None | 184 | self.parser = None |
186 | 185 | ||
@@ -226,23 +225,22 @@ class BBCooker: | |||
226 | bb.warn("Cooker received SIGTERM, shutting down...") | 225 | bb.warn("Cooker received SIGTERM, shutting down...") |
227 | elif signum == signal.SIGHUP: | 226 | elif signum == signal.SIGHUP: |
228 | bb.warn("Cooker received SIGHUP, shutting down...") | 227 | bb.warn("Cooker received SIGHUP, shutting down...") |
229 | self.state = state.forceshutdown | 228 | self.state = State.FORCE_SHUTDOWN |
230 | bb.event._should_exit.set() | 229 | bb.event._should_exit.set() |
231 | 230 | ||
232 | def setFeatures(self, features): | 231 | def setFeatures(self, features): |
233 | # we only accept a new feature set if we're in state initial, so we can reset without problems | 232 | # we only accept a new feature set if we're in state initial, so we can reset without problems |
234 | if not self.state in [state.initial, state.shutdown, state.forceshutdown, state.stopped, state.error]: | 233 | if not self.state in [State.INITIAL, State.SHUTDOWN, State.FORCE_SHUTDOWN, State.STOPPED, State.ERROR]: |
235 | raise Exception("Illegal state for feature set change") | 234 | raise Exception("Illegal state for feature set change") |
236 | original_featureset = list(self.featureset) | 235 | original_featureset = list(self.featureset) |
237 | for feature in features: | 236 | for feature in features: |
238 | self.featureset.setFeature(feature) | 237 | self.featureset.setFeature(feature) |
239 | bb.debug(1, "Features set %s (was %s)" % (original_featureset, list(self.featureset))) | 238 | bb.debug(1, "Features set %s (was %s)" % (original_featureset, list(self.featureset))) |
240 | if (original_featureset != list(self.featureset)) and self.state != state.error and hasattr(self, "data"): | 239 | if (original_featureset != list(self.featureset)) and self.state != State.ERROR and hasattr(self, "data"): |
241 | self.reset() | 240 | self.reset() |
242 | 241 | ||
243 | def initConfigurationData(self): | 242 | def initConfigurationData(self): |
244 | 243 | self.state = State.INITIAL | |
245 | self.state = state.initial | ||
246 | self.caches_array = [] | 244 | self.caches_array = [] |
247 | 245 | ||
248 | sys.path = self.orig_syspath.copy() | 246 | sys.path = self.orig_syspath.copy() |
@@ -1398,11 +1396,11 @@ class BBCooker: | |||
1398 | 1396 | ||
1399 | msg = None | 1397 | msg = None |
1400 | interrupted = 0 | 1398 | interrupted = 0 |
1401 | if halt or self.state == state.forceshutdown: | 1399 | if halt or self.state == State.FORCE_SHUTDOWN: |
1402 | rq.finish_runqueue(True) | 1400 | rq.finish_runqueue(True) |
1403 | msg = "Forced shutdown" | 1401 | msg = "Forced shutdown" |
1404 | interrupted = 2 | 1402 | interrupted = 2 |
1405 | elif self.state == state.shutdown: | 1403 | elif self.state == State.SHUTDOWN: |
1406 | rq.finish_runqueue(False) | 1404 | rq.finish_runqueue(False) |
1407 | msg = "Stopped build" | 1405 | msg = "Stopped build" |
1408 | interrupted = 1 | 1406 | interrupted = 1 |
@@ -1472,12 +1470,12 @@ class BBCooker: | |||
1472 | def buildTargetsIdle(server, rq, halt): | 1470 | def buildTargetsIdle(server, rq, halt): |
1473 | msg = None | 1471 | msg = None |
1474 | interrupted = 0 | 1472 | interrupted = 0 |
1475 | if halt or self.state == state.forceshutdown: | 1473 | if halt or self.state == State.FORCE_SHUTDOWN: |
1476 | bb.event._should_exit.set() | 1474 | bb.event._should_exit.set() |
1477 | rq.finish_runqueue(True) | 1475 | rq.finish_runqueue(True) |
1478 | msg = "Forced shutdown" | 1476 | msg = "Forced shutdown" |
1479 | interrupted = 2 | 1477 | interrupted = 2 |
1480 | elif self.state == state.shutdown: | 1478 | elif self.state == State.SHUTDOWN: |
1481 | rq.finish_runqueue(False) | 1479 | rq.finish_runqueue(False) |
1482 | msg = "Stopped build" | 1480 | msg = "Stopped build" |
1483 | interrupted = 1 | 1481 | interrupted = 1 |
@@ -1572,7 +1570,7 @@ class BBCooker: | |||
1572 | 1570 | ||
1573 | 1571 | ||
1574 | def updateCacheSync(self): | 1572 | def updateCacheSync(self): |
1575 | if self.state == state.running: | 1573 | if self.state == State.RUNNING: |
1576 | return | 1574 | return |
1577 | 1575 | ||
1578 | if not self.baseconfig_valid: | 1576 | if not self.baseconfig_valid: |
@@ -1582,19 +1580,19 @@ class BBCooker: | |||
1582 | 1580 | ||
1583 | # This is called for all async commands when self.state != running | 1581 | # This is called for all async commands when self.state != running |
1584 | def updateCache(self): | 1582 | def updateCache(self): |
1585 | if self.state == state.running: | 1583 | if self.state == State.RUNNING: |
1586 | return | 1584 | return |
1587 | 1585 | ||
1588 | if self.state in (state.shutdown, state.forceshutdown, state.error): | 1586 | if self.state in (State.SHUTDOWN, State.FORCE_SHUTDOWN, State.ERROR): |
1589 | if hasattr(self.parser, 'shutdown'): | 1587 | if hasattr(self.parser, 'shutdown'): |
1590 | self.parser.shutdown(clean=False) | 1588 | self.parser.shutdown(clean=False) |
1591 | self.parser.final_cleanup() | 1589 | self.parser.final_cleanup() |
1592 | raise bb.BBHandledException() | 1590 | raise bb.BBHandledException() |
1593 | 1591 | ||
1594 | if self.state != state.parsing: | 1592 | if self.state != State.PARSING: |
1595 | self.updateCacheSync() | 1593 | self.updateCacheSync() |
1596 | 1594 | ||
1597 | if self.state != state.parsing and not self.parsecache_valid: | 1595 | if self.state != State.PARSING and not self.parsecache_valid: |
1598 | bb.server.process.serverlog("Parsing started") | 1596 | bb.server.process.serverlog("Parsing started") |
1599 | self.parsewatched = {} | 1597 | self.parsewatched = {} |
1600 | 1598 | ||
@@ -1628,7 +1626,7 @@ class BBCooker: | |||
1628 | self.parser = CookerParser(self, mcfilelist, total_masked) | 1626 | self.parser = CookerParser(self, mcfilelist, total_masked) |
1629 | self._parsecache_set(True) | 1627 | self._parsecache_set(True) |
1630 | 1628 | ||
1631 | self.state = state.parsing | 1629 | self.state = State.PARSING |
1632 | 1630 | ||
1633 | if not self.parser.parse_next(): | 1631 | if not self.parser.parse_next(): |
1634 | collectlog.debug("parsing complete") | 1632 | collectlog.debug("parsing complete") |
@@ -1638,7 +1636,7 @@ class BBCooker: | |||
1638 | self.handlePrefProviders() | 1636 | self.handlePrefProviders() |
1639 | for mc in self.multiconfigs: | 1637 | for mc in self.multiconfigs: |
1640 | self.recipecaches[mc].bbfile_priority = self.collections[mc].collection_priorities(self.recipecaches[mc].pkg_fn, self.parser.mcfilelist[mc], self.data) | 1638 | self.recipecaches[mc].bbfile_priority = self.collections[mc].collection_priorities(self.recipecaches[mc].pkg_fn, self.parser.mcfilelist[mc], self.data) |
1641 | self.state = state.running | 1639 | self.state = State.RUNNING |
1642 | 1640 | ||
1643 | # Send an event listing all stamps reachable after parsing | 1641 | # Send an event listing all stamps reachable after parsing |
1644 | # which the metadata may use to clean up stale data | 1642 | # which the metadata may use to clean up stale data |
@@ -1711,10 +1709,10 @@ class BBCooker: | |||
1711 | 1709 | ||
1712 | def shutdown(self, force=False): | 1710 | def shutdown(self, force=False): |
1713 | if force: | 1711 | if force: |
1714 | self.state = state.forceshutdown | 1712 | self.state = State.FORCE_SHUTDOWN |
1715 | bb.event._should_exit.set() | 1713 | bb.event._should_exit.set() |
1716 | else: | 1714 | else: |
1717 | self.state = state.shutdown | 1715 | self.state = State.SHUTDOWN |
1718 | 1716 | ||
1719 | if self.parser: | 1717 | if self.parser: |
1720 | self.parser.shutdown(clean=False) | 1718 | self.parser.shutdown(clean=False) |
@@ -1724,7 +1722,7 @@ class BBCooker: | |||
1724 | if hasattr(self.parser, 'shutdown'): | 1722 | if hasattr(self.parser, 'shutdown'): |
1725 | self.parser.shutdown(clean=False) | 1723 | self.parser.shutdown(clean=False) |
1726 | self.parser.final_cleanup() | 1724 | self.parser.final_cleanup() |
1727 | self.state = state.initial | 1725 | self.state = State.INITIAL |
1728 | bb.event._should_exit.clear() | 1726 | bb.event._should_exit.clear() |
1729 | 1727 | ||
1730 | def reset(self): | 1728 | def reset(self): |