-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwscript
187 lines (158 loc) · 7.65 KB
/
wscript
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
VERSION='0.2'
APPNAME='ndnjs'
YUICOMPRESSOR_URL="http://github.com/downloads/yui/yuicompressor/"
YUICOMPRESSOR_NAME="yuicompressor-2.4.7"
CLOSURE_COMPILER="http://closure-compiler.googlecode.com/files/compiler-20121212.zip"
from waflib import Task, TaskGen, Utils, Logs
import urllib, subprocess, os, shutil
def options (opt):
js = opt.add_option_group ("ndn.js compilation options")
js.add_option('--no-js',action='store_false',default=True,dest='js',
help='''Disable ndn.js compilation and installation''')
js.add_option('--js-dir',action='store',dest='jsdir',
help='''Directory where .js files will be installed (Default: ${PREFIX}/share/ndn-js)''')
js.add_option('--yui',action='store_true',default=False,dest='yui',
help='''Download and use yuicompressor-2.4.7 (http://yui.github.com/yuicompressor/)''')
js.add_option('--no-compiler',action='store_false',default=True,dest='compiler',
help='''Disable download and use of closure-compiler-r2388 (https://code.google.com/p/closure-compiler/)''')
ws = opt.add_option_group ("ws-proxy options")
ws.add_option ('--no-ws',action='store_false',default=True,dest='ws',
help='''Disable ws-proxy installation''')
def configure (conf):
if conf.options.js:
conf.env.JS = 1
if not conf.env.JSDIR:
if conf.options.jsdir or Utils.is_win32:
conf.env.JSDIR=os.path.abspath (os.path.expanduser (conf.options.jsdir))
else:
conf.env.JSDIR=Utils.subst_vars ('${PREFIX}/bin',conf.env)
if conf.options.yui:
conf.start_msg ("Checking for yuicompressor")
if os.path.exists('tools/yuicompressor.jar'):
conf.end_msg('tools/yuicompressor.jar')
conf.env.HAVE_YUI = 1
else:
conf.end_msg('not found','YELLOW')
url="%s%s.zip" % (YUICOMPRESSOR_URL, YUICOMPRESSOR_NAME)
Logs.info ("Downloading yuicompressor from %s..." % url)
urllib.urlretrieve (url, "build/yuicompressor.zip")
filename='%s/build/%s.jar' % (YUICOMPRESSOR_NAME,YUICOMPRESSOR_NAME)
subprocess.check_call (['unzip', '-qq', '-o', '-j', 'build/yuicompressor.zip',
filename, '-d', 'tools/'])
os.rename ("tools/%s.jar" % YUICOMPRESSOR_NAME, "tools/yuicompressor.jar")
conf.env.HAVE_YUI = 1
if conf.options.compiler:
conf.start_msg ("Checking for closure-compiler")
if os.path.exists('tools/compiler.jar'):
conf.end_msg('tools/compiler.jar')
conf.env.HAVE_COMPILER = 1
else:
conf.end_msg('not found','YELLOW')
Logs.info ("Downloading closure-compiler from %s..." % CLOSURE_COMPILER)
urllib.urlretrieve (CLOSURE_COMPILER, "build/closure-compiler.zip")
subprocess.check_call (['unzip', '-qq', '-o', '-j', 'build/closure-compiler.zip', 'compiler.jar', '-d', 'tools/'])
conf.env.HAVE_COMPILER = 1
if conf.options.ws:
conf.env.WS = 1
def build (bld):
if bld.env['JS']:
securityLib = ["lib/browser/securityLib/core.js",
"lib/browser/securityLib/sha256.js",
"lib/browser/securityLib/base64.js",
"lib/browser/securityLib/rsa.js",
"lib/browser/securityLib/rsa2.js",
"lib/browser/securityLib/crypto-1.0.js",
"lib/browser/securityLib/rsapem-1.1.js",
"lib/browser/securityLib/rsasign-1.2.js",
"lib/browser/securityLib/asn1hex-1.1.js",
"lib/browser/securityLib/x509-1.1.js",
"lib/browser/securityLib/jsbn.js",
"lib/browser/securityLib/jsbn2.js"]
ndnjs = ["lib/WebSocketTransport.js",
"lib/browser/browserify.js",
"lib/util/CCNProtocolDTags.js",
"lib/util/CCNTime.js",
"lib/util/DataUtils.js",
"lib/Name.js",
"lib/ContentObject.js",
"lib/Interest.js",
"lib/Key.js",
"lib/PublisherID.js",
"lib/PublisherPublicKeyDigest.js",
"lib/ForwardingEntry.js",
"lib/util/DynamicBuffer.js",
"lib/util/BinaryXMLEncoder.js",
"lib/util/BinaryXMLDecoder.js",
"lib/util/BinaryXMLStructureDecoder.js",
"lib/util/BinaryXMLElementReader.js",
"lib/NDN.js"] + securityLib
ndnjs = bld (features="combine",
target="ndn",
source=ndnjs,
install_path="${JSDIR}")
if bld.env['HAVE_YUI']:
ndnjs.yui = True
if bld.env['HAVE_COMPILER']:
ndnjs.compiler = True
if bld.env['WS']:
bld.install_as ('${BINDIR}/ccnx-wsproxy-tcp.js', 'wsproxy/wsproxy-tcp.js', chmod=Utils.O755)
bld.install_as ('${BINDIR}/ccnx-wsproxy-udp.js', 'wsproxy/wsproxy-udp.js', chmod=Utils.O755)
@TaskGen.extension('.js')
def js_hook(self, node):
node.sig=Utils.h_file (node.abspath())
@TaskGen.feature('combine')
@TaskGen.after_method('process_source')
def apply_combine(self):
out = "%s.js" % self.target
tasks = []
task = self.create_task ('combine', self.source)
task.set_outputs (task.generator.path.find_or_declare (out))
tasks.append (task)
if getattr(self, 'yui', False):
out_yui = "%s.min.yui.js" % self.target
yui = self.create_task ('yuicompressor')
yui.combine = task
yui.set_outputs (yui.generator.path.find_or_declare (out_yui))
tasks.append (yui)
if getattr(self, 'compiler', False):
out_min = "%s.min.js" % self.target
compiler = self.create_task ('closure_compiler')
compiler.combine = task
compiler.set_outputs (compiler.generator.path.find_or_declare (out_min))
tasks.append (compiler)
try:
for task in tasks:
self.bld.install_files (self.install_path, task.outputs[:], env=self.env)
except:
pass
class combine (Task.Task):
def run(self):
outFile = self.outputs[0]
self.outputs[0].write ("", "w") # make file empty
for inFile in self.inputs:
self.outputs[0].write (inFile.read (), 'a')
class yuicompressor (Task.Task):
after="combine"
color='PINK'
def __str__(self):
src_str=self.combine.outputs[0].nice_path()
tgt_str=self.outputs[0].nice_path()
return'%s: %s -> %s\n'%(self.__class__.__name__.replace('_task',''),src_str,tgt_str)
def run(self):
return self.exec_command(['java',
'-jar', '../tools/yuicompressor.jar',
'-o', self.outputs[0].abspath(),
self.combine.outputs[0].abspath()])
class closure_compiler (Task.Task):
after="combine"
color='PINK'
def __str__(self):
src_str=self.combine.outputs[0].nice_path()
tgt_str=self.outputs[0].nice_path()
return'%s: %s -> %s\n'%(self.__class__.__name__.replace('_task',''),src_str,tgt_str)
def run(self):
return self.exec_command(['java',
'-jar', '../tools/compiler.jar',
'--js', self.combine.outputs[0].abspath(),
'--js_output_file', self.outputs[0].abspath()])