bitbake-server 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python3
  2. #
  3. # SPDX-License-Identifier: GPL-2.0-only
  4. #
  5. # Copyright (C) 2020 Richard Purdie
  6. #
  7. import os
  8. import sys
  9. import warnings
  10. warnings.simplefilter("default")
  11. import logging
  12. sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
  13. if sys.getfilesystemencoding() != "utf-8":
  14. sys.exit("Please use a locale setting which supports UTF-8 (such as LANG=en_US.UTF-8).\nPython can't change the filesystem locale after loading so we need a UTF-8 when Python starts or things won't work.")
  15. # Users shouldn't be running this code directly
  16. if len(sys.argv) != 10 or not sys.argv[1].startswith("decafbad"):
  17. print("bitbake-server is meant for internal execution by bitbake itself, please don't use it standalone.")
  18. sys.exit(1)
  19. import bb.server.process
  20. lockfd = int(sys.argv[2])
  21. readypipeinfd = int(sys.argv[3])
  22. logfile = sys.argv[4]
  23. lockname = sys.argv[5]
  24. sockname = sys.argv[6]
  25. timeout = float(sys.argv[7])
  26. xmlrpcinterface = (sys.argv[8], int(sys.argv[9]))
  27. if xmlrpcinterface[0] == "None":
  28. xmlrpcinterface = (None, xmlrpcinterface[1])
  29. # Replace standard fds with our own
  30. with open('/dev/null', 'r') as si:
  31. os.dup2(si.fileno(), sys.stdin.fileno())
  32. so = open(logfile, 'a+')
  33. os.dup2(so.fileno(), sys.stdout.fileno())
  34. os.dup2(so.fileno(), sys.stderr.fileno())
  35. # Have stdout and stderr be the same so log output matches chronologically
  36. # and there aren't two seperate buffers
  37. sys.stderr = sys.stdout
  38. logger = logging.getLogger("BitBake")
  39. # Ensure logging messages get sent to the UI as events
  40. handler = bb.event.LogHandler()
  41. logger.addHandler(handler)
  42. bb.server.process.execServer(lockfd, readypipeinfd, lockname, sockname, timeout, xmlrpcinterface)