blob: 72b9c4bac6a4df04776779c90e081cc4cc4b59d0 [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''')
19 js.add_option('--yui',action='store_true',default=False,dest='yui',
20 help='''Download and use yuicompressor-2.4.7 (http://yui.github.com/yuicompressor/)''')
21 js.add_option('--compiler',action='store_true',default=False,dest='compiler',
22 help='''Download and use closure-compiler-r2388 (https://code.google.com/p/closure-compiler/)''')
23
24 ws = opt.add_option_group ("ws-proxy options")
25 ws.add_option ('--no-ws',action='store_false',default=True,dest='ws',
26 help='''Disable ws-proxy installation''')
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080027
28def configure (conf):
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080029 if conf.options.js:
30 conf.env.JS = 1
31 if conf.options.yui:
32 conf.start_msg ("Checking for yuicompressor")
33 if os.path.exists('tools/yuicompressor.jar'):
34 conf.end_msg('tools/yuicompressor.jar')
35 conf.env.HAVE_YUI = 1
36 else:
37 conf.end_msg('not found','YELLOW')
38 url="%s%s.zip" % (YUICOMPRESSOR_URL, YUICOMPRESSOR_NAME)
39 Logs.info ("Downloading yuicompressor from %s..." % url)
40 urllib.urlretrieve (url, "build/yuicompressor.zip")
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080041
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080042 filename='%s/build/%s.jar' % (YUICOMPRESSOR_NAME,YUICOMPRESSOR_NAME)
43 subprocess.check_call (['unzip', '-qq', '-o', '-j', 'build/yuicompressor.zip',
44 filename, '-d', 'tools/'])
45 os.rename ("tools/%s.jar" % YUICOMPRESSOR_NAME, "tools/yuicompressor.jar")
46 conf.env.HAVE_YUI = 1
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080047
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080048 if conf.options.compiler:
49 conf.start_msg ("Checking for closure-compiler")
50 if os.path.exists('tools/compiler.jar'):
51 conf.end_msg('tools/compiler.jar')
52 conf.env.HAVE_COMPILER = 1
53 else:
54 conf.end_msg('not found','YELLOW')
55 Logs.info ("Downloading closure-compiler from %s..." % CLOSURE_COMPILER)
56 urllib.urlretrieve (CLOSURE_COMPILER, "build/closure-compiler.zip")
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080057
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080058 subprocess.check_call (['unzip', '-qq', '-o', '-j', 'build/closure-compiler.zip', 'compiler.jar', '-d', 'tools/'])
59 conf.env.HAVE_COMPILER = 1
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080060
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080061 if conf.options.ws:
62 conf.env.WS = 1
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080063
Alexander Afanasyev181a8b92013-02-28 13:28:53 -080064def build (bld):
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080065 if bld.env['JS']:
66 securityLib = ["contrib/securityLib/sha256.js",
67 "contrib/securityLib/base64.js",
68 "contrib/securityLib/rsa.js",
69 "contrib/securityLib/rsa2.js",
70 "contrib/securityLib/rsapem-1.1.js",
71 "contrib/securityLib/rsasign-1.2.js",
72 "contrib/securityLib/asn1hex-1.1.js",
73 "contrib/securityLib/x509-1.1.js",
74 "contrib/securityLib/jsbn.js",
75 "contrib/securityLib/jsbn2.js"]
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080076
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -080077 ndnjs = ["js/Closure.js",
78 "js/WebSocketTransport.js",
79 "js/util/CCNProtocolDTags.js",
80 "js/util/CCNTime.js",
81 "js/util/ExponentialReExpressClosure.js",
82 "js/Name.js",
83 "js/ContentObject.js",
84 "js/encoding/DateFormat.js",
85 "js/Interest.js",
86 "js/Key.js",
87 "js/PublisherID.js",
88 "js/PublisherPublicKeyDigest.js",
89 "js/FaceInstance.js",
90 "js/ForwardingEntry.js",
91 "js/encoding/DynamicUint8Array.js",
92 "js/encoding/BinaryXMLEncoder.js",
93 "js/encoding/BinaryXMLDecoder.js",
94 "js/encoding/BinaryXMLStructureDecoder.js",
95 "js/encoding/DataUtils.js",
96 "js/encoding/EncodingUtils.js",
97 "js/security/KeyManager.js",
98 "js/security/Witness.js"] + securityLib + ["js/NDN.js"]
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080099
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -0800100 ndnjs = bld (features="combine",
101 target="ndn",
102 source=ndnjs,
103 install_path="${PREFIX}")
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -0800104
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -0800105 if bld.env['HAVE_YUI']:
106 ndnjs.yui = True
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -0800107
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -0800108 if bld.env['HAVE_COMPILER']:
109 ndnjs.compiler = True
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -0800110
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -0800111 if bld.env['WS']:
112 bld.install_as ('${BINDIR}/websocket-ccnd-proxy-tcp', 'wsproxy/wsproxy-tcp.js', chmod=Utils.O755)
113 bld.install_as ('${BINDIR}/websocket-ccnd-proxy-udp', 'wsproxy/wsproxy-udp.js', chmod=Utils.O755)
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -0800114
115@TaskGen.extension('.js')
116def js_hook(self, node):
117 node.sig=Utils.h_file (node.abspath())
118
119@TaskGen.feature('combine')
120@TaskGen.after_method('process_source')
121def apply_combine(self):
122 out = "%s.js" % self.target
123 tasks = []
124 task = self.create_task ('combine', self.source)
125 task.set_outputs (task.generator.path.find_or_declare (out))
126 tasks.append (task)
127
128 if getattr(self, 'yui', False):
129 out_yui = "%s.min.yui.js" % self.target
130 yui = self.create_task ('yuicompressor')
131 yui.combine = task
132 yui.set_outputs (yui.generator.path.find_or_declare (out_yui))
133 tasks.append (yui)
134
135 if getattr(self, 'compiler', False):
136 out_min = "%s.min.js" % self.target
137 compiler = self.create_task ('closure_compiler')
138 compiler.combine = task
Alexander Afanasyev57dce8b2013-02-28 19:20:21 -0800139 compiler.set_outputs (compiler.generator.path.find_or_declare (out_min))
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -0800140 tasks.append (compiler)
141
142 try:
143 for task in tasks:
144 self.bld.install_files (self.install_path, task.outputs[:], env=self.env)
145 except:
146 pass
147
148class combine (Task.Task):
149 def run(self):
150 outFile = self.outputs[0]
151 self.outputs[0].write ("", "w") # make file empty
152 for inFile in self.inputs:
153 self.outputs[0].write (inFile.read (), 'a')
154
155class yuicompressor (Task.Task):
156 after="combine"
157 color='PINK'
158 def __str__(self):
159 src_str=self.combine.outputs[0].nice_path()
160 tgt_str=self.outputs[0].nice_path()
161 return'%s: %s -> %s\n'%(self.__class__.__name__.replace('_task',''),src_str,tgt_str)
162
163 def run(self):
164 return self.exec_command(['java',
165 '-jar', '../tools/yuicompressor.jar',
166 '-o', self.outputs[0].abspath(),
167 self.combine.outputs[0].abspath()])
168
169class closure_compiler (Task.Task):
170 after="combine"
171 color='PINK'
172 def __str__(self):
173 src_str=self.combine.outputs[0].nice_path()
174 tgt_str=self.outputs[0].nice_path()
175 return'%s: %s -> %s\n'%(self.__class__.__name__.replace('_task',''),src_str,tgt_str)
176
177 def run(self):
178 return self.exec_command(['java',
179 '-jar', '../tools/compiler.jar',
180 '--js', self.combine.outputs[0].abspath(),
181 '--js_output_file', self.outputs[0].abspath()])