/script/upload-node-headers.py

https://github.com/brave/muon
Python | 147 lines | 112 code | 28 blank | 7 comment | 14 complexity | c16ca62bb91c5daddcc3e368b3f9c19b MD5 | raw file
  1. #!/usr/bin/env python
  2. import argparse
  3. import glob
  4. import os
  5. import shutil
  6. import sys
  7. import tarfile
  8. from lib.config import PLATFORM, output_dir, SOURCE_ROOT, CHROMIUM_ROOT, dist_dir, get_target_arch, s3_config
  9. from lib.util import execute, safe_mkdir, scoped_cwd, s3put
  10. NODE_DIR = os.path.join(SOURCE_ROOT, 'vendor', 'node')
  11. HEADERS_SUFFIX = [
  12. '.h',
  13. '.gypi',
  14. ]
  15. HEADERS_DIRS = [
  16. 'src',
  17. 'deps/http_parser',
  18. 'deps/zlib',
  19. 'deps/uv',
  20. 'deps/npm',
  21. 'deps/mdb_v8',
  22. ]
  23. HEADERS_FILES = [
  24. 'common.gypi',
  25. 'config.gypi',
  26. ]
  27. def main():
  28. safe_mkdir(dist_dir())
  29. args = parse_args()
  30. node_headers_dir = os.path.join(dist_dir(), 'node-{0}'.format(args.version))
  31. node2_headers_dir = os.path.join(dist_dir(),
  32. 'node-{0}-headers'.format(args.version))
  33. iojs_headers_dir = os.path.join(dist_dir(), 'iojs-{0}'.format(args.version))
  34. iojs2_headers_dir = os.path.join(dist_dir(),
  35. 'iojs-{0}-headers'.format(args.version))
  36. copy_headers(node_headers_dir)
  37. create_header_tarball(node_headers_dir)
  38. copy_headers(node2_headers_dir)
  39. create_header_tarball(node2_headers_dir)
  40. copy_headers(iojs_headers_dir)
  41. create_header_tarball(iojs_headers_dir)
  42. copy_headers(iojs2_headers_dir)
  43. create_header_tarball(iojs2_headers_dir)
  44. # Upload node's headers to S3.
  45. bucket, access_key, secret_key = s3_config()
  46. upload_node(bucket, access_key, secret_key, args.version)
  47. def parse_args():
  48. parser = argparse.ArgumentParser(description='upload sumsha file')
  49. parser.add_argument('-v', '--version', help='Specify the version',
  50. required=True)
  51. return parser.parse_args()
  52. def copy_headers(dist_headers_dir):
  53. safe_mkdir(dist_headers_dir)
  54. # Copy standard node headers from node. repository.
  55. for include_path in HEADERS_DIRS:
  56. abs_path = os.path.join(NODE_DIR, include_path)
  57. for dirpath, _, filenames in os.walk(abs_path):
  58. for filename in filenames:
  59. extension = os.path.splitext(filename)[1]
  60. if extension not in HEADERS_SUFFIX:
  61. continue
  62. copy_source_file(os.path.join(dirpath, filename), NODE_DIR,
  63. dist_headers_dir)
  64. for other_file in HEADERS_FILES:
  65. copy_source_file(os.path.join(NODE_DIR, other_file), NODE_DIR,
  66. dist_headers_dir)
  67. # Copy V8 headers from chromium's repository.
  68. src = CHROMIUM_ROOT
  69. for dirpath, _, filenames in os.walk(os.path.join(src, 'v8')):
  70. for filename in filenames:
  71. extension = os.path.splitext(filename)[1]
  72. if extension not in HEADERS_SUFFIX:
  73. continue
  74. copy_source_file(os.path.join(dirpath, filename), src,
  75. os.path.join(dist_headers_dir, 'deps'))
  76. def create_header_tarball(dist_headers_dir):
  77. target = dist_headers_dir + '.tar.gz'
  78. with scoped_cwd(dist_dir()):
  79. tarball = tarfile.open(name=target, mode='w:gz')
  80. tarball.add(os.path.relpath(dist_headers_dir))
  81. tarball.close()
  82. def copy_source_file(source, start, destination):
  83. relative = os.path.relpath(source, start=start)
  84. final_destination = os.path.join(destination, relative)
  85. safe_mkdir(os.path.dirname(final_destination))
  86. shutil.copy2(source, final_destination)
  87. def upload_node(bucket, access_key, secret_key, version):
  88. with scoped_cwd(dist_dir()):
  89. s3put(bucket, access_key, secret_key, dist_dir(),
  90. 'atom-shell/dist/{0}'.format(version), glob.glob('node-*.tar.gz'))
  91. s3put(bucket, access_key, secret_key, dist_dir(),
  92. 'atom-shell/dist/{0}'.format(version), glob.glob('iojs-*.tar.gz'))
  93. if PLATFORM == 'win32':
  94. if get_target_arch() != 'x64':
  95. node_lib = os.path.join(dist_dir(), 'node.lib')
  96. node2_lib = os.path.join(dist_dir(), 'win-x86', 'node.lib')
  97. iojs_lib = os.path.join(dist_dir(), 'win-x86', 'iojs.lib')
  98. else:
  99. node_lib = os.path.join(dist_dir(), 'x64', 'node.lib')
  100. node2_lib = os.path.join(dist_dir(), 'win-x64', 'node.lib')
  101. iojs_lib = os.path.join(dist_dir(), 'win-x64', 'iojs.lib')
  102. safe_mkdir(os.path.dirname(node_lib))
  103. safe_mkdir(os.path.dirname(node2_lib))
  104. safe_mkdir(os.path.dirname(iojs_lib))
  105. # Copy atom.lib to node.lib and iojs.lib.
  106. atom_lib = os.path.join(output_dir(), 'node_import.lib')
  107. shutil.copy2(atom_lib, node_lib)
  108. shutil.copy2(atom_lib, node2_lib)
  109. shutil.copy2(atom_lib, iojs_lib)
  110. # Upload the node.lib.
  111. s3put(bucket, access_key, secret_key, dist_dir(),
  112. 'atom-shell/dist/{0}'.format(version), [node_lib])
  113. s3put(bucket, access_key, secret_key, dist_dir(),
  114. 'atom-shell/dist/{0}'.format(version), [node2_lib])
  115. # Upload the iojs.lib.
  116. s3put(bucket, access_key, secret_key, dist_dir(),
  117. 'atom-shell/dist/{0}'.format(version), [iojs_lib])
  118. if __name__ == '__main__':
  119. sys.exit(main())