configure.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. '''
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. '''
  7. import sys, os, re
  8. sys.dont_write_bytecode = True
  9. scriptPath = os.path.dirname(os.path.realpath(__file__))
  10. sys.path.append(scriptPath + '/../cmake')
  11. import run_cmake
  12. sys.path.append(scriptPath + '/build')
  13. import qt_version
  14. executePath = os.getcwd()
  15. def finish(code):
  16. global executePath
  17. os.chdir(executePath)
  18. sys.exit(code)
  19. def error(message):
  20. print('[ERROR] ' + message)
  21. finish(1)
  22. if sys.platform == 'win32' and 'COMSPEC' not in os.environ:
  23. error('COMSPEC environment variable is not set.')
  24. scriptName = os.path.basename(scriptPath)
  25. arguments = sys.argv[1:]
  26. officialTarget = ''
  27. officialTargetFile = scriptPath + '/build/target'
  28. if os.path.isfile(officialTargetFile):
  29. with open(officialTargetFile, 'r') as f:
  30. for line in f:
  31. officialTarget = line.strip()
  32. arch = ''
  33. if officialTarget in ['win', 'uwp']:
  34. arch = 'x86'
  35. elif officialTarget in ['win64', 'uwp64']:
  36. arch = 'x64'
  37. elif officialTarget in ['winarm', 'uwparm']:
  38. arch = 'arm'
  39. if not qt_version.resolve(arch):
  40. error('Unsupported platform.')
  41. if 'qt6' in arguments:
  42. arguments.remove('qt6')
  43. if officialTarget != '':
  44. officialApiIdFile = scriptPath + '/../../DesktopPrivate/custom_api_id.h'
  45. if not os.path.isfile(officialApiIdFile):
  46. error('DesktopPrivate/custom_api_id.h not found.')
  47. with open(officialApiIdFile, 'r') as f:
  48. for line in f:
  49. apiIdMatch = re.search(r'ApiId\s+=\s+(\d+)', line)
  50. apiHashMatch = re.search(r'ApiHash\s+=\s+"([a-fA-F\d]+)"', line)
  51. if apiIdMatch:
  52. arguments.append('-DTDESKTOP_API_ID=' + apiIdMatch.group(1))
  53. elif apiHashMatch:
  54. arguments.append('-DTDESKTOP_API_HASH=' + apiHashMatch.group(1))
  55. if arch != '':
  56. arguments.append(arch)
  57. finish(run_cmake.run(scriptName, arguments))