Merge pull request #8668 from electron/fix-mas
[platform/framework/web/crosswalk-tizen.git] / script / upload-node-headers.py
1 #!/usr/bin/env python
2
3 import argparse
4 import glob
5 import os
6 import shutil
7 import sys
8 import tarfile
9
10 from lib.config import PLATFORM, get_target_arch, s3_config
11 from lib.util import execute, safe_mkdir, scoped_cwd, s3put
12
13
14 SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
15 DIST_DIR    = os.path.join(SOURCE_ROOT, 'dist')
16 NODE_DIR    = os.path.join(SOURCE_ROOT, 'vendor', 'node')
17 OUT_DIR     = os.path.join(SOURCE_ROOT, 'out', 'R')
18
19 HEADERS_SUFFIX = [
20   '.h',
21   '.gypi',
22 ]
23 HEADERS_DIRS = [
24   'src',
25   'deps/http_parser',
26   'deps/zlib',
27   'deps/uv',
28   'deps/npm',
29   'deps/mdb_v8',
30 ]
31 HEADERS_FILES = [
32   'common.gypi',
33   'config.gypi',
34 ]
35
36
37 def main():
38   safe_mkdir(DIST_DIR)
39
40   args = parse_args()
41   node_headers_dir = os.path.join(DIST_DIR, 'node-{0}'.format(args.version))
42   iojs_headers_dir = os.path.join(DIST_DIR, 'iojs-{0}'.format(args.version))
43   iojs2_headers_dir = os.path.join(DIST_DIR,
44                                    'iojs-{0}-headers'.format(args.version))
45
46   copy_headers(node_headers_dir)
47   create_header_tarball(node_headers_dir)
48   copy_headers(iojs_headers_dir)
49   create_header_tarball(iojs_headers_dir)
50   copy_headers(iojs2_headers_dir)
51   create_header_tarball(iojs2_headers_dir)
52
53   # Upload node's headers to S3.
54   bucket, access_key, secret_key = s3_config()
55   upload_node(bucket, access_key, secret_key, args.version)
56
57
58 def parse_args():
59   parser = argparse.ArgumentParser(description='upload sumsha file')
60   parser.add_argument('-v', '--version', help='Specify the version',
61                       required=True)
62   return parser.parse_args()
63
64
65 def copy_headers(dist_headers_dir):
66   safe_mkdir(dist_headers_dir)
67
68   # Copy standard node headers from node. repository.
69   for include_path in HEADERS_DIRS:
70     abs_path = os.path.join(NODE_DIR, include_path)
71     for dirpath, _, filenames in os.walk(abs_path):
72       for filename in filenames:
73         extension = os.path.splitext(filename)[1]
74         if extension not in HEADERS_SUFFIX:
75           continue
76         copy_source_file(os.path.join(dirpath, filename), NODE_DIR,
77                          dist_headers_dir)
78   for other_file in HEADERS_FILES:
79     copy_source_file(os.path.join(NODE_DIR, other_file), NODE_DIR,
80                      dist_headers_dir)
81
82   # Copy V8 headers from chromium's repository.
83   src = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', 'download',
84                     'libchromiumcontent', 'src')
85   for dirpath, _, filenames in os.walk(os.path.join(src, 'v8')):
86     for filename in filenames:
87       extension = os.path.splitext(filename)[1]
88       if extension not in HEADERS_SUFFIX:
89         continue
90       copy_source_file(os.path.join(dirpath, filename), src,
91                        os.path.join(dist_headers_dir, 'deps'))
92
93
94 def create_header_tarball(dist_headers_dir):
95   target = dist_headers_dir + '.tar.gz'
96   with scoped_cwd(DIST_DIR):
97     tarball = tarfile.open(name=target, mode='w:gz')
98     tarball.add(os.path.relpath(dist_headers_dir))
99     tarball.close()
100
101
102 def copy_source_file(source, start, destination):
103   relative = os.path.relpath(source, start=start)
104   final_destination = os.path.join(destination, relative)
105   safe_mkdir(os.path.dirname(final_destination))
106   shutil.copy2(source, final_destination)
107
108
109 def upload_node(bucket, access_key, secret_key, version):
110   with scoped_cwd(DIST_DIR):
111     s3put(bucket, access_key, secret_key, DIST_DIR,
112           'atom-shell/dist/{0}'.format(version), glob.glob('node-*.tar.gz'))
113     s3put(bucket, access_key, secret_key, DIST_DIR,
114           'atom-shell/dist/{0}'.format(version), glob.glob('iojs-*.tar.gz'))
115
116   if PLATFORM == 'win32':
117     if get_target_arch() == 'ia32':
118       node_lib = os.path.join(DIST_DIR, 'node.lib')
119       iojs_lib = os.path.join(DIST_DIR, 'win-x86', 'iojs.lib')
120     else:
121       node_lib = os.path.join(DIST_DIR, 'x64', 'node.lib')
122       iojs_lib = os.path.join(DIST_DIR, 'win-x64', 'iojs.lib')
123     safe_mkdir(os.path.dirname(node_lib))
124     safe_mkdir(os.path.dirname(iojs_lib))
125
126     # Copy atom.lib to node.lib and iojs.lib.
127     atom_lib = os.path.join(OUT_DIR, 'node.dll.lib')
128     shutil.copy2(atom_lib, node_lib)
129     shutil.copy2(atom_lib, iojs_lib)
130
131     # Upload the node.lib.
132     s3put(bucket, access_key, secret_key, DIST_DIR,
133           'atom-shell/dist/{0}'.format(version), [node_lib])
134
135     # Upload the iojs.lib.
136     s3put(bucket, access_key, secret_key, DIST_DIR,
137           'atom-shell/dist/{0}'.format(version), [iojs_lib])
138
139
140 if __name__ == '__main__':
141   sys.exit(main())