profile_toolchain.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python3
  2. import contextlib
  3. import sys
  4. import os
  5. import optparse
  6. import json
  7. sys.path.append("%s/../../build" % os.path.dirname(os.path.realpath(__file__)))
  8. import find_depot_tools
  9. from vs_toolchain import \
  10. SetEnvironmentAndGetRuntimeDllDirs, \
  11. SetEnvironmentAndGetSDKDir, \
  12. NormalizePath
  13. sys.path.append("%s/win_toolchain" % find_depot_tools.add_depot_tools_to_path())
  14. from get_toolchain_if_necessary import CalculateHash
  15. @contextlib.contextmanager
  16. def cwd(directory):
  17. curdir = os.getcwd()
  18. try:
  19. os.chdir(directory)
  20. yield
  21. finally:
  22. os.chdir(curdir)
  23. def calculate_hash(root):
  24. with cwd(root):
  25. return CalculateHash('.', None)
  26. def windows_installed_software():
  27. # file_path = os.path.join(os.getcwd(), 'installed_software.json')
  28. # return json.loads(open('installed_software.json').read().decode('utf-8'))
  29. f = open('installed_software.json', encoding='utf-8-sig')
  30. return json.load(f)
  31. def windows_profile():
  32. runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs()
  33. win_sdk_dir = SetEnvironmentAndGetSDKDir()
  34. path = NormalizePath(os.environ['GYP_MSVS_OVERRIDE_PATH'])
  35. # since current windows executable are symbols path dependent,
  36. # profile the current directory too
  37. return {
  38. 'pwd': os.getcwd(),
  39. 'installed_software': windows_installed_software(),
  40. 'sdks': [
  41. {'name': 'vs', 'path': path, 'hash': calculate_hash(path)},
  42. {
  43. 'name': 'wsdk',
  44. 'path': win_sdk_dir,
  45. 'hash': calculate_hash(win_sdk_dir),
  46. },
  47. ],
  48. 'runtime_lib_dirs': runtime_dll_dirs,
  49. }
  50. def main(options):
  51. if sys.platform == 'win32':
  52. with open(options.output_json, 'w') as f:
  53. json.dump(windows_profile(), f)
  54. else:
  55. raise OSError("Unsupported OS")
  56. if __name__ == '__main__':
  57. parser = optparse.OptionParser()
  58. parser.add_option('--output-json', metavar='FILE', default='profile.json',
  59. help='write information about toolchain to FILE')
  60. opts, args = parser.parse_args()
  61. sys.exit(main(opts))