forked from nwjs/nw.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-nw-headers.py
More file actions
91 lines (83 loc) · 3.58 KB
/
Copy pathmake-nw-headers.py
File metadata and controls
91 lines (83 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
import os
import tarfile
import sys
import getnwversion
import shutil
import distutils.core
import re
script_dir = os.path.dirname(__file__)
nw_root = os.path.normpath(os.path.join(script_dir, os.pardir))
project_root = os.path.normpath(os.path.join(nw_root, os.pardir, os.pardir))
third_party_dir = os.path.normpath(os.path.join(project_root, 'third_party'))
tmp_dir = tmp_dir = os.path.normpath(os.path.join(nw_root, 'tmp'))
nw_version = getnwversion.nw_version
#parse command line arguments
'''
-t, the version of nw-headers to download
'''
if '-t' in sys.argv:
nw_version = sys.argv[sys.argv.index('-t') + 1]
tarname = 'node-v' + nw_version + '.tar.gz'
tarpath = os.path.join(tmp_dir, tarname)
#make tmpdir
if os.path.exists(tmp_dir):
pass
else:
os.mkdir(tmp_dir)
# prepare the files to compress
print 'Begin copy file'
base = os.path.join(third_party_dir, 'node')
for dirpath, dirnames, filenames in os.walk(base):
relpath = dirpath.replace(third_party_dir + os.sep, '')
for dirs in dirnames:
if dirs =='gyp' or dirs == 'gyp_addon':
try:
shutil.copytree(os.path.join(dirpath, dirs), os.path.join(tmp_dir, relpath, dirs))
except:
distutils.dir_util.copy_tree(os.path.join(dirpath, dirs), os.path.join(tmp_dir, relpath, dirs))
for files in filenames:
if files.endswith('.h') or files.endswith('.gypi') or files == 'gyp' or files == 'gyp_addon':
if not os.path.exists(os.path.join(tmp_dir, relpath)):
os.makedirs(os.path.join(tmp_dir, relpath))
shutil.copyfile(os.path.join(dirpath, files), os.path.join(tmp_dir, relpath, files))
shutil.rmtree(os.path.join(tmp_dir, 'node', 'deps', 'v8'))
base = os.path.join(project_root, 'v8')
for dirpath, dirnames, filenames in os.walk(base):
relpath = dirpath.replace(project_root + os.sep, '')
relpath = os.path.join('node', 'deps', relpath)
for dirs in dirnames:
if dirs == 'gyp' or dirs == 'gyp_addon':
try:
shutil.copytree(os.path.join(dirpath, dirs), os.path.join(tmp_dir, relpath, dirs))
except:
distutils.dir_util.copy_tree(os.path.join(dirpath, dirs), os.path.join(tmp_dir, relpath, dirs))
for files in filenames:
if files.endswith('.h') or files.endswith('.gypi') or files == 'gyp' or files == 'gyp_addon':
if not os.path.exists(os.path.join(tmp_dir, relpath)):
os.makedirs(os.path.join(tmp_dir, relpath))
shutil.copyfile(os.path.join(dirpath, files), os.path.join(tmp_dir, relpath, files))
if os.path.exists(os.path.join(tmp_dir, 'node', 'deps', 'v8', 'build')):
shutil.rmtree(os.path.join(tmp_dir, 'node', 'deps', 'v8', 'build'))
if os.path.exists(os.path.join(tmp_dir, 'node', 'deps', 'v8', 'test')):
shutil.rmtree(os.path.join(tmp_dir, 'node', 'deps', 'v8', 'test'))
if os.path.exists(os.path.join(tmp_dir, 'node', 'deps', 'v8', 'out')):
shutil.rmtree(os.path.join(tmp_dir, 'node', 'deps', 'v8', 'out'))
if os.path.exists(os.path.join(tmp_dir, 'node', 'deps', 'npm', 'node_modules')):
shutil.rmtree(os.path.join(tmp_dir, 'node', 'deps', 'npm', 'node_modules'))
rfile = open(os.path.join(tmp_dir, 'node', 'src', 'node.h'), 'r')
filer = rfile.read()
sub = re.sub('third_party/node/deps/uv/include/uv.h', 'uv.h', filer, 0)
rfile.close()
wfile = open(os.path.join(tmp_dir, 'node', 'src', 'node.h'), 'w')
wfile.write(sub)
wfile.close()
print 'copy file end'
print 'Begin compress file'
tar = tarfile.open(tarpath, 'w:gz')
for dirpath, dirnames, filenames in os.walk(tmp_dir):
for name in filenames:
path = os.path.normpath(os.path.join(dirpath, name))
tar.add(path, path.replace(tmp_dir + os.sep, ''))
tar.close()
print 'compress end'