upload-node-headers.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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, get_target_arch, s3_config
  9. from lib.util import execute, safe_mkdir, scoped_cwd, s3put
  10. SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
  11. DIST_DIR = os.path.join(SOURCE_ROOT, 'dist')
  12. NODE_DIR = os.path.join(SOURCE_ROOT, 'vendor', 'node')
  13. OUT_DIR = os.path.join(SOURCE_ROOT, 'out', 'R')
  14. HEADERS_SUFFIX = [
  15. '.h',
  16. '.gypi',
  17. ]
  18. HEADERS_DIRS = [
  19. 'src',
  20. 'deps/http_parser',
  21. 'deps/zlib',
  22. 'deps/uv',
  23. 'deps/npm',
  24. 'deps/mdb_v8',
  25. ]
  26. HEADERS_FILES = [
  27. 'common.gypi',
  28. 'config.gypi',
  29. ]
  30. def main():
  31. safe_mkdir(DIST_DIR)
  32. args = parse_args()
  33. node_headers_dir = os.path.join(DIST_DIR, 'node-{0}'.format(args.version))
  34. iojs_headers_dir = os.path.join(DIST_DIR, 'iojs-{0}'.format(args.version))
  35. iojs2_headers_dir = os.path.join(DIST_DIR,
  36. 'iojs-{0}-headers'.format(args.version))
  37. copy_headers(node_headers_dir)
  38. create_header_tarball(node_headers_dir)
  39. copy_headers(iojs_headers_dir)
  40. create_header_tarball(iojs_headers_dir)
  41. copy_headers(iojs2_headers_dir)
  42. create_header_tarball(iojs2_headers_dir)
  43. # Upload node's headers to S3.
  44. bucket, access_key, secret_key = s3_config()
  45. upload_node(bucket, access_key, secret_key, args.version)
  46. def parse_args():
  47. parser = argparse.ArgumentParser(description='upload sumsha file')
  48. parser.add_argument('-v', '--version', help='Specify the version',
  49. required=True)
  50. return parser.parse_args()
  51. def copy_headers(dist_headers_dir):
  52. safe_mkdir(dist_headers_dir)
  53. # Copy standard node headers from node. repository.
  54. for include_path in HEADERS_DIRS:
  55. abs_path = os.path.join(NODE_DIR, include_path)
  56. for dirpath, _, filenames in os.walk(abs_path):
  57. for filename in filenames:
  58. extension = os.path.splitext(filename)[1]
  59. if extension not in HEADERS_SUFFIX:
  60. continue
  61. copy_source_file(os.path.join(dirpath, filename), NODE_DIR,
  62. dist_headers_dir)
  63. for other_file in HEADERS_FILES:
  64. copy_source_file(os.path.join(NODE_DIR, other_file), NODE_DIR,
  65. dist_headers_dir)
  66. # Copy V8 headers from chromium's repository.
  67. src = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', 'download',
  68. 'libchromiumcontent', 'src')
  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() == 'ia32':
  95. node_lib = os.path.join(DIST_DIR, 'node.lib')
  96. iojs_lib = os.path.join(DIST_DIR, 'win-x86', 'iojs.lib')
  97. else:
  98. node_lib = os.path.join(DIST_DIR, 'x64', 'node.lib')
  99. iojs_lib = os.path.join(DIST_DIR, 'win-x64', 'iojs.lib')
  100. safe_mkdir(os.path.dirname(node_lib))
  101. safe_mkdir(os.path.dirname(iojs_lib))
  102. # Copy atom.lib to node.lib and iojs.lib.
  103. atom_lib = os.path.join(OUT_DIR, 'node.dll.lib')
  104. shutil.copy2(atom_lib, node_lib)
  105. shutil.copy2(atom_lib, iojs_lib)
  106. # Upload the node.lib.
  107. s3put(bucket, access_key, secret_key, DIST_DIR,
  108. 'atom-shell/dist/{0}'.format(version), [node_lib])
  109. # Upload the iojs.lib.
  110. s3put(bucket, access_key, secret_key, DIST_DIR,
  111. 'atom-shell/dist/{0}'.format(version), [iojs_lib])
  112. if __name__ == '__main__':
  113. sys.exit(main())