Skip to content

Commit 362832b

Browse files
committed
package binrary for all
1 parent 237ad34 commit 362832b

File tree

5 files changed

+238
-0
lines changed

5 files changed

+238
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.DS_Store
22
tests/node_modules
3+
*.pyc
4+

nw.gypi

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,25 @@
329329
},
330330
],
331331
},
332+
{
333+
'target_name': 'nw_package_bin',
334+
'type': 'none',
335+
'actions': [
336+
{
337+
'action_name': 'package_nw_binaries',
338+
'variables':{
339+
'package_script': '<(DEPTH)/content/nw/tools/package_binaries.py',
340+
},
341+
'inputs': [
342+
'<(package_script)',
343+
],
344+
'outputs':[
345+
'<(PRODUCT_DIR)/new_package.re',
346+
],
347+
'action': ['python', '<(package_script)'],
348+
},
349+
],
350+
},
332351
{
333352
'target_name': 'nw',
334353
'type': 'executable',

tools/getnwisrelease.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sys,os,re
2+
3+
nw_version_h = os.path.join(os.path.dirname(__file__), '..', 'src',
4+
'nw_version.h')
5+
6+
f = open(nw_version_h)
7+
8+
9+
for line in f:
10+
if re.match('#define NW_VERSION_IS_RELEASE', line):
11+
release = int(line.split()[2])
12+
#print release
13+

tools/getnwversion.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import os,re
2+
3+
node_version_h = os.path.join(os.path.dirname(__file__), '..', 'src',
4+
'nw_version.h')
5+
6+
f = open(node_version_h)
7+
8+
9+
for line in f:
10+
if re.match('#define NW_MAJOR_VERSION', line):
11+
major = line.split()[2]
12+
if re.match('#define NW_MINOR_VERSION', line):
13+
minor = line.split()[2]
14+
if re.match('#define NW_PATCH_VERSION', line):
15+
patch = line.split()[2]
16+
17+
nw_version = '%(major)s.%(minor)s.%(patch)s'% locals()
18+
19+
#print '%(major)s.%(minor)s.%(patch)s'% locals()
20+
21+
22+
23+

tools/package_binaries.py

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
#!/usr/bin/env python
2+
import os
3+
import shutil
4+
import tarfile
5+
import sys
6+
7+
8+
script_dir = os.path.dirname(__file__)
9+
nw_root = os.path.normpath(os.path.join(script_dir, os.pardir))
10+
project_root = os.path.normpath(os.path.join(nw_root, os.pardir, os.pardir));
11+
#default project path
12+
project_root = os.path.join(project_root, 'out', 'Release')
13+
14+
15+
#parse command line arguments
16+
"""
17+
-p <path>, the absolute path of executable files
18+
"""
19+
if '-p' in sys.argv:
20+
tmp = sys.argv[sys.argv.index('-p') + 1]
21+
if not os.path.isabs(tmp):
22+
print 'the path is not an absolute path.\n'
23+
exit()
24+
25+
if not os.path.exists(tmp):
26+
print 'the directory does not exist.\n'
27+
exit()
28+
29+
project_root = tmp
30+
31+
32+
33+
#get platform information
34+
if sys.platform.startswith('linux'):
35+
platform_name = 'linux'
36+
37+
if sys.platform in ('win32', 'cygwin'):
38+
platform_name = 'win'
39+
40+
if sys.platform == 'darwin':
41+
platform_name = 'osx'
42+
43+
#judge whether the target exist or not
44+
if platform_name == 'linux' and not os.path.exists(
45+
os.path.join(project_root, 'nw')):
46+
print 'nw file does not exist.\n'
47+
exit()
48+
49+
if platform_name == 'win' and not os.path.exists(
50+
os.path.join(project_root, 'nw.exe')):
51+
print 'nw file does not exist.\n'
52+
exit()
53+
54+
if platform_name == 'osx' and not os.path.exists(
55+
os.path.join(project_root, 'node-webkit.app')):
56+
print 'nw file does not exist.\n'
57+
exit()
58+
59+
required_file_linux = (
60+
'nw',
61+
'nw.pak',
62+
'libffmpegsumo.so',
63+
)
64+
65+
required_file_win = (
66+
'ffmpegsumo.dll',
67+
'icudt.dll',
68+
'libEGL.dll',
69+
'libGLESv2.dll',
70+
'nw.exe',
71+
'nw.pak',
72+
)
73+
74+
required_file_mac = (
75+
'node-webkit.app',
76+
)
77+
78+
79+
if (platform_name == 'linux'):
80+
required_file = required_file_linux
81+
82+
if (platform_name == 'win'):
83+
required_file = required_file_win
84+
85+
if (platform_name == 'osx'):
86+
required_file = required_file_mac
87+
88+
#generate binary tar name
89+
import getnwisrelease
90+
import getnwversion
91+
import platform
92+
93+
nw_version = 'v' + getnwversion.nw_version
94+
is_release = getnwisrelease.release
95+
96+
if is_release == 0:
97+
nw_version += '-pre'
98+
99+
bits = platform.architecture()[0]
100+
101+
if bits == '64bit':
102+
arch = 'x64'
103+
else:
104+
arch = 'ia32'
105+
106+
107+
tarname = 'node-webkit-' + nw_version
108+
109+
binary_name = tarname + '-' + platform_name + '-' + arch
110+
binary_tar = binary_name + '.tar.gz'
111+
112+
#use zip in mac and windows
113+
if platform_name in ('win', 'osx'):
114+
binary_tar = binary_name + '.zip'
115+
116+
117+
#make directory for binary_tar
118+
binary_store_path = os.path.join(project_root,
119+
'node-webkit-binaries')
120+
121+
122+
if not os.path.exists(binary_store_path):
123+
os.mkdir(binary_store_path)
124+
125+
126+
binary_full_path = os.path.join(binary_store_path, binary_name)
127+
binary_tar_full_path = os.path.join(binary_store_path, binary_tar)
128+
129+
130+
if os.path.exists(binary_full_path):
131+
shutil.rmtree(binary_full_path)
132+
133+
os.mkdir(binary_full_path)
134+
135+
136+
#copy file to binary
137+
print 'Begin copy file.'
138+
for file in required_file:
139+
shutil.copy(os.path.join(project_root, file),
140+
os.path.join(binary_full_path, file))
141+
142+
print 'copy file end.\n'
143+
144+
if (os.path.isfile(binary_tar_full_path)):
145+
os.remove(binary_tar_full_path)
146+
147+
148+
print 'Begin compress file'
149+
150+
151+
if platform_name in ('win', 'osx'):
152+
"""
153+
If there are sub directors, this should be modified
154+
"""
155+
import zipfile
156+
zip = zipfile.ZipFile(binary_tar_full_path, 'w',
157+
compression=zipfile.ZIP_DEFLATED)
158+
159+
for dirpath, dirnames, filenames in os.walk(binary_full_path):
160+
for name in filenames:
161+
path = os.path.normpath(os.path.join(dirpath, name))
162+
163+
if os.path.isfile(path):
164+
zip.write(path, os.path.join(os.path.basename(binary_full_path), name))
165+
166+
167+
zip.close()
168+
169+
else:
170+
tar = tarfile.open(binary_tar_full_path, 'w:gz')
171+
tar.add(binary_full_path, os.path.basename(binary_full_path))
172+
tar.close()
173+
174+
175+
print 'compress file end.\n'
176+
177+
178+
print 'the binaries files store in path:', os.path.normpath(
179+
os.path.join(os.getcwd(), binary_store_path))
180+
181+

0 commit comments

Comments
 (0)