Skip to content

Commit dcc962c

Browse files
committed
Move compiling native module to nw_util; Fix win32 build
1 parent e386088 commit dcc962c

File tree

2 files changed

+93
-81
lines changed

2 files changed

+93
-81
lines changed

test/sanity/native-module-buffer/test.py

Lines changed: 4 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3,96 +3,20 @@
33
import shutil
44
import subprocess
55
import platform
6-
from subprocess import Popen, PIPE
76
import sys
87

8+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9+
from nw_util import *
10+
911
from selenium import webdriver
1012
from selenium.webdriver.chrome.options import Options
1113
chrome_options = Options()
1214
testdir = os.path.dirname(os.path.abspath(__file__))
1315
chrome_options.add_argument("nwapp=" + testdir)
14-
nw_tools = os.path.normpath(os.path.join(testdir, os.pardir, os.pardir, os.pardir, 'tools'))
15-
sys.path.append(nw_tools)
16-
import getnwversion
17-
import getnwisrelease
18-
19-
def find_executable(executable, path=None):
20-
"""Find if 'executable' can be run. Looks for it in 'path'
21-
(string that lists directories separated by 'os.pathsep';
22-
defaults to os.environ['PATH']). Checks for all executable
23-
extensions. Returns full path or None if no command is found.
24-
"""
25-
if path is None:
26-
path = os.environ['PATH']
27-
paths = path.split(os.pathsep)
28-
extlist = ['']
29-
if os.name == 'os2':
30-
(base, ext) = os.path.splitext(executable)
31-
# executable files on OS/2 can have an arbitrary extension, but
32-
# .exe is automatically appended if no dot is present in the name
33-
if not ext:
34-
executable = executable + ".exe"
35-
elif sys.platform == 'win32':
36-
pathext = os.environ['PATHEXT'].lower().split(os.pathsep)
37-
(base, ext) = os.path.splitext(executable)
38-
if ext.lower() not in pathext:
39-
extlist = pathext
40-
for ext in extlist:
41-
execname = executable + ext
42-
if os.path.isfile(execname):
43-
return execname
44-
else:
45-
for p in paths:
46-
f = os.path.join(p, execname)
47-
if os.path.isfile(f):
48-
return f
49-
else:
50-
return None
5116

5217
os.chdir(testdir)
5318

54-
header_path = os.path.abspath("../../../tmp/node")
55-
56-
nw_version = getnwversion.nw_version
57-
if getnwisrelease.release == 0:
58-
nw_version += getnwisrelease.postfix
59-
60-
arch = ''
61-
_arch = platform.architecture()[0]
62-
if _arch == '64bit':
63-
arch = 'x64'
64-
elif _arch == '32bit':
65-
arch = 'ia32'
66-
else:
67-
print 'Unsupported arch: ' + _arch
68-
exit(-1)
69-
70-
nw_gyp_path = find_executable('nw-gyp')
71-
npm_path = find_executable('npm')
72-
npm_cmdline = [npm_path, 'install']
73-
74-
if sys.platform in ('win32', 'cygwin'):
75-
nw_gyp_path = os.path.join(os.path.dirname(nw_gyp_path),
76-
'node_modules', 'nw-gyp', 'bin', 'nw-gyp.js')
77-
npm_cmdline = [npm_path, 'install', '--msvs_version=2015']
78-
79-
print "nw_gyp: ", nw_gyp_path
80-
print "npm_path: ", npm_path
81-
print "header path: ", header_path
82-
print "command line: ", npm_cmdline
83-
84-
npm_env = {'npm_config_nodedir': header_path, 'npm_config_target': nw_version,
85-
'npm_config_arch': arch, 'npm_config_target_arch': arch,
86-
'npm_config_runtime': 'node-webkit', 'npm_config_build_from_source': "true",
87-
'npm_config_node_gyp': nw_gyp_path, 'PATH': os.getenv('PATH')}
88-
89-
os.environ.update(npm_env)
90-
91-
proc = Popen(npm_cmdline, stdout=PIPE, stderr=PIPE, env=os.environ)
92-
out, err = proc.communicate()
93-
print out
94-
print err
95-
assert(proc.returncode == 0)
19+
install_native_modules()
9620

9721
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
9822
try:

test/sanity/nw_util.py

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,97 @@
66

77
import logging
88
import os
9+
import sys
910
import shutil
1011
import tempfile
11-
12+
from subprocess import Popen, PIPE
13+
14+
def find_executable(executable, path=None):
15+
"""Find if 'executable' can be run. Looks for it in 'path'
16+
(string that lists directories separated by 'os.pathsep';
17+
defaults to os.environ['PATH']). Checks for all executable
18+
extensions. Returns full path or None if no command is found.
19+
"""
20+
if path is None:
21+
path = os.environ['PATH']
22+
paths = path.split(os.pathsep)
23+
extlist = ['']
24+
if os.name == 'os2':
25+
(base, ext) = os.path.splitext(executable)
26+
# executable files on OS/2 can have an arbitrary extension, but
27+
# .exe is automatically appended if no dot is present in the name
28+
if not ext:
29+
executable = executable + ".exe"
30+
elif sys.platform == 'win32':
31+
pathext = os.environ['PATHEXT'].lower().split(os.pathsep)
32+
(base, ext) = os.path.splitext(executable)
33+
if ext.lower() not in pathext:
34+
extlist = pathext
35+
for ext in extlist:
36+
execname = executable + ext
37+
if os.path.isfile(execname):
38+
return execname
39+
else:
40+
for p in paths:
41+
f = os.path.join(p, execname)
42+
if os.path.isfile(f):
43+
return f
44+
else:
45+
return None
46+
47+
def install_native_modules():
48+
nw_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
49+
nw_tools = os.path.join(nw_dir, 'tools')
50+
sys.path.append(nw_tools)
51+
import getnwversion
52+
import getnwisrelease
53+
54+
header_path = os.path.join(nw_dir, 'tmp', 'node')
55+
56+
nw_version = getnwversion.nw_version
57+
if getnwisrelease.release == 0:
58+
nw_version += getnwisrelease.postfix
59+
60+
arch = ''
61+
_arch = platform.architecture()[0]
62+
if _arch == '64bit':
63+
arch = 'x64'
64+
elif _arch == '32bit':
65+
arch = 'ia32'
66+
else:
67+
print 'Unsupported arch: ' + _arch
68+
exit(-1)
69+
70+
target_arch = arch
71+
if 'target_arch=ia32' in os.getenv('GYP_DEFINES'):
72+
target_arch='ia32'
73+
74+
nw_gyp_path = find_executable('nw-gyp')
75+
npm_path = find_executable('npm')
76+
npm_cmdline = [npm_path, 'install']
77+
78+
if sys.platform in ('win32', 'cygwin'):
79+
nw_gyp_path = os.path.join(os.path.dirname(nw_gyp_path),
80+
'node_modules', 'nw-gyp', 'bin', 'nw-gyp.js')
81+
npm_cmdline = [npm_path, 'install', '--msvs_version=2015']
82+
83+
print "nw_gyp: ", nw_gyp_path
84+
print "npm_path: ", npm_path
85+
print "header path: ", header_path
86+
print "command line: ", npm_cmdline
87+
88+
npm_env = {'npm_config_nodedir': header_path, 'npm_config_target': nw_version,
89+
'npm_config_arch': arch, 'npm_config_target_arch': target_arch,
90+
'npm_config_runtime': 'node-webkit', 'npm_config_build_from_source': "true",
91+
'npm_config_node_gyp': nw_gyp_path, 'PATH': os.getenv('PATH')}
92+
93+
os.environ.update(npm_env)
94+
95+
proc = Popen(npm_cmdline, stdout=PIPE, stderr=PIPE, env=os.environ)
96+
out, err = proc.communicate()
97+
print out
98+
print err
99+
assert(proc.returncode == 0)
12100

13101
def wait_for_element_id(driver, elem_id, timeout=10):
14102
ret = ''

0 commit comments

Comments
 (0)