blob: 2708386567c4d8dbe04b5b3ff95cc59ed8c68c76 [file] [log] [blame]
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3VERSION='0.1'
4APPNAME='ndnjs'
5
6YUICOMPRESSOR_URL="http://github.com/downloads/yui/yuicompressor/"
7YUICOMPRESSOR_NAME="yuicompressor-2.4.7"
8
9CLOSURE_COMPILER="http://closure-compiler.googlecode.com/files/compiler-20121212.zip"
10
11from waflib import Task, TaskGen, Utils, Logs
12import urllib, subprocess, os, shutil
13
14def options (opt):
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080015 js = opt.add_option_group ("ndn.js compilation options")
16
17 js.add_option('--no-js',action='store_false',default=True,dest='js',
18 help='''Disable ndn.js compilation and installation''')
Alexander Afanasyev78664742013-02-28 19:40:49 -080019 js.add_option('--js-dir',action='store',dest='jsdir',
20 help='''Directory where .js files will be installed (Default: ${PREFIX}/share/ndn-js)''')
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080021 js.add_option('--yui',action='store_true',default=False,dest='yui',
22 help='''Download and use yuicompressor-2.4.7 (http://yui.github.com/yuicompressor/)''')
Alexander Afanasyev53dca592013-03-13 16:20:32 -070023 js.add_option('--no-compiler',action='store_false',default=True,dest='compiler',
24 help='''Disable download and use of closure-compiler-r2388 (https://code.google.com/p/closure-compiler/)''')
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080025
26 ws = opt.add_option_group ("ws-proxy options")
27 ws.add_option ('--no-ws',action='store_false',default=True,dest='ws',
28 help='''Disable ws-proxy installation''')
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080029
30def configure (conf):
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080031 if conf.options.js:
32 conf.env.JS = 1
Alexander Afanasyev78664742013-02-28 19:40:49 -080033 if not conf.env.JSDIR:
34 if conf.options.jsdir or Utils.is_win32:
35 conf.env.JSDIR=os.path.abspath (os.path.expanduser (conf.options.jsdir))
36 else:
37 conf.env.JSDIR=Utils.subst_vars ('${PREFIX}/bin',conf.env)
38
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080039 if conf.options.yui:
40 conf.start_msg ("Checking for yuicompressor")
41 if os.path.exists('tools/yuicompressor.jar'):
42 conf.end_msg('tools/yuicompressor.jar')
43 conf.env.HAVE_YUI = 1
44 else:
45 conf.end_msg('not found','YELLOW')
46 url="%s%s.zip" % (YUICOMPRESSOR_URL, YUICOMPRESSOR_NAME)
47 Logs.info ("Downloading yuicompressor from %s..." % url)
48 urllib.urlretrieve (url, "build/yuicompressor.zip")
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080049
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080050 filename='%s/build/%s.jar' % (YUICOMPRESSOR_NAME,YUICOMPRESSOR_NAME)
51 subprocess.check_call (['unzip', '-qq', '-o', '-j', 'build/yuicompressor.zip',
52 filename, '-d', 'tools/'])
53 os.rename ("tools/%s.jar" % YUICOMPRESSOR_NAME, "tools/yuicompressor.jar")
54 conf.env.HAVE_YUI = 1
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080055
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080056 if conf.options.compiler:
57 conf.start_msg ("Checking for closure-compiler")
58 if os.path.exists('tools/compiler.jar'):
59 conf.end_msg('tools/compiler.jar')
60 conf.env.HAVE_COMPILER = 1
61 else:
62 conf.end_msg('not found','YELLOW')
63 Logs.info ("Downloading closure-compiler from %s..." % CLOSURE_COMPILER)
64 urllib.urlretrieve (CLOSURE_COMPILER, "build/closure-compiler.zip")
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080065
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080066 subprocess.check_call (['unzip', '-qq', '-o', '-j', 'build/closure-compiler.zip', 'compiler.jar', '-d', 'tools/'])
67 conf.env.HAVE_COMPILER = 1
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080068
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080069 if conf.options.ws:
70 conf.env.WS = 1
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080071
Alexander Afanasyev181a8b92013-02-28 13:28:53 -080072def build (bld):
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080073 if bld.env['JS']:
74 securityLib = ["contrib/securityLib/sha256.js",
75 "contrib/securityLib/base64.js",
76 "contrib/securityLib/rsa.js",
77 "contrib/securityLib/rsa2.js",
78 "contrib/securityLib/rsapem-1.1.js",
79 "contrib/securityLib/rsasign-1.2.js",
80 "contrib/securityLib/asn1hex-1.1.js",
81 "contrib/securityLib/x509-1.1.js",
82 "contrib/securityLib/jsbn.js",
83 "contrib/securityLib/jsbn2.js"]
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080084
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080085 ndnjs = ["js/Closure.js",
86 "js/WebSocketTransport.js",
87 "js/util/CCNProtocolDTags.js",
88 "js/util/CCNTime.js",
89 "js/util/ExponentialReExpressClosure.js",
90 "js/Name.js",
91 "js/ContentObject.js",
92 "js/encoding/DateFormat.js",
93 "js/Interest.js",
94 "js/Key.js",
95 "js/PublisherID.js",
96 "js/PublisherPublicKeyDigest.js",
97 "js/FaceInstance.js",
98 "js/ForwardingEntry.js",
99 "js/encoding/DynamicUint8Array.js",
100 "js/encoding/BinaryXMLEncoder.js",
101 "js/encoding/BinaryXMLDecoder.js",
102 "js/encoding/BinaryXMLStructureDecoder.js",
103 "js/encoding/DataUtils.js",
104 "js/encoding/EncodingUtils.js",
105 "js/security/KeyManager.js",
106 "js/security/Witness.js"] + securityLib + ["js/NDN.js"]
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -0800107
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -0800108 ndnjs = bld (features="combine",
Alexander Afanasyevad659622013-03-02 13:50:58 -0800109 target="ndn-js",
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -0800110 source=ndnjs,
Alexander Afanasyev78664742013-02-28 19:40:49 -0800111 install_path="${JSDIR}")
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -0800112
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -0800113 if bld.env['HAVE_YUI']:
114 ndnjs.yui = True
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -0800115
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -0800116 if bld.env['HAVE_COMPILER']:
117 ndnjs.compiler = True
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -0800118
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -0800119 if bld.env['WS']:
Alexander Afanasyev78664742013-02-28 19:40:49 -0800120 bld.install_as ('${BINDIR}/ccnx-wsproxy-tcp.js', 'wsproxy/wsproxy-tcp.js', chmod=Utils.O755)
121 bld.install_as ('${BINDIR}/ccnx-wsproxy-udp.js', 'wsproxy/wsproxy-udp.js', chmod=Utils.O755)
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -0800122
123@TaskGen.extension('.js')
124def js_hook(self, node):
125 node.sig=Utils.h_file (node.abspath())
126
127@TaskGen.feature('combine')
128@TaskGen.after_method('process_source')
129def apply_combine(self):
130 out = "%s.js" % self.target
131 tasks = []
132 task = self.create_task ('combine', self.source)
133 task.set_outputs (task.generator.path.find_or_declare (out))
134 tasks.append (task)
135
136 if getattr(self, 'yui', False):
137 out_yui = "%s.min.yui.js" % self.target
138 yui = self.create_task ('yuicompressor')
139 yui.combine = task
140 yui.set_outputs (yui.generator.path.find_or_declare (out_yui))
141 tasks.append (yui)
142
143 if getattr(self, 'compiler', False):
144 out_min = "%s.min.js" % self.target
145 compiler = self.create_task ('closure_compiler')
146 compiler.combine = task
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -0800147 compiler.set_outputs (compiler.generator.path.find_or_declare (out_min))
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -0800148 tasks.append (compiler)
149
150 try:
151 for task in tasks:
152 self.bld.install_files (self.install_path, task.outputs[:], env=self.env)
153 except:
154 pass
155
156class combine (Task.Task):
157 def run(self):
158 outFile = self.outputs[0]
159 self.outputs[0].write ("", "w") # make file empty
160 for inFile in self.inputs:
161 self.outputs[0].write (inFile.read (), 'a')
162
163class yuicompressor (Task.Task):
164 after="combine"
165 color='PINK'
166 def __str__(self):
167 src_str=self.combine.outputs[0].nice_path()
168 tgt_str=self.outputs[0].nice_path()
169 return'%s: %s -> %s\n'%(self.__class__.__name__.replace('_task',''),src_str,tgt_str)
170
171 def run(self):
172 return self.exec_command(['java',
173 '-jar', '../tools/yuicompressor.jar',
174 '-o', self.outputs[0].abspath(),
175 self.combine.outputs[0].abspath()])
176
177class closure_compiler (Task.Task):
178 after="combine"
179 color='PINK'
180 def __str__(self):
181 src_str=self.combine.outputs[0].nice_path()
182 tgt_str=self.outputs[0].nice_path()
183 return'%s: %s -> %s\n'%(self.__class__.__name__.replace('_task',''),src_str,tgt_str)
184
185 def run(self):
186 return self.exec_command(['java',
187 '-jar', '../tools/compiler.jar',
188 '--js', self.combine.outputs[0].abspath(),
189 '--js_output_file', self.outputs[0].abspath()])