-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
executable file
·106 lines (95 loc) · 3.14 KB
/
setup.py
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/python
# vim: ts=4 sw=4 expandtab
from distutils.core import setup, Extension
import distutils.command.build
import distutils.command.clean
import os
import subprocess
import sys
class _BuildError(Exception):
pass
def _runmakefiles(distutils_dir, build_opt=1, target=None):
args = ['BUILD_OPT=%i' % build_opt]
if distutils_dir:
args.append('DISTUTILS_DIR=%s' % distutils_dir)
if target:
args.append(target)
# First build SpiderMonkey. Force it to link statically against the CRT to
# make deployment easier.
if os.name == 'nt':
args.append('XCFLAGS=-MT')
ret = subprocess.call(['make', '-f', 'Makefile.ref', '-C',
'spidermonkey/src'] + args)
if ret != 0:
raise _BuildError, 'Error running make.'
# Then copy the files to the build directory.
ret = subprocess.call(['make', '-f', 'Makefile.SpiderMonkey'] + args)
if ret != 0:
raise _BuildError, 'Error running make.'
class _MyBuild(distutils.command.build.build):
def run(self):
# py2exe is calling reinitialize_command without finalizing.
self.ensure_finalized()
_runmakefiles(self.build_platlib)
distutils.command.build.build.run(self)
class _MyClean(distutils.command.clean.clean):
def run(self):
_runmakefiles(None, target='clean')
distutils.command.clean.clean.run(self)
if __name__ == '__main__':
if os.name == 'nt':
library = 'js32'
else:
library = 'js'
pyspidermonkey = Extension(
'javascriptlint.pyspidermonkey',
include_dirs = ['spidermonkey/src', 'build/spidermonkey'],
library_dirs = ['build/spidermonkey'],
libraries = [library],
sources = [
'javascriptlint/pyspidermonkey/pyspidermonkey.c',
'javascriptlint/pyspidermonkey/nodepos.c'
]
)
cmdclass = {
'build': _MyBuild,
'clean': _MyClean,
}
args = {}
args.update(
name = 'javascriptlint',
version = '1.0',
author = 'Matthias Miller',
author_email = '[email protected]',
url = 'http://www.javascriptlint.com/',
cmdclass = cmdclass,
description = 'JavaScript Lint',
ext_modules = [pyspidermonkey],
packages = ['javascriptlint'],
scripts = ['jsl']
)
try:
import py2exe
except ImportError:
pass
else:
class _MyPy2Exe(py2exe.build_exe.py2exe):
def run(self):
py2exe.build_exe.py2exe.run(self)
for exe in self.console_exe_files:
ret = subprocess.call(['upx', '-9', exe])
if ret != 0:
raise _BuildError, 'Error running upx on %s' % exe
args['cmdclass']['py2exe'] = _MyPy2Exe
args.update(
console = ['jsl'],
options = {
'py2exe': {
'excludes': ['javascriptlint.spidermonkey_'],
'bundle_files': 1,
'optimize': 2,
}
},
zipfile = None
)
setup(**args)