blob: 36530f2dd8acf7b5c5c2c6c72e7ce909496f8b63 [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):
15 opt.add_option('--js-path', action='store',dest='js_path',
16 help='''Path to install combined and compressed .js files''')
17 opt.add_option('--yui',action='store_true',default=False,dest='yui',
18 help='''Download and use yuicompressor-2.4.7 (http://yui.github.com/yuicompressor/)''')
19 opt.add_option('--compiler',action='store_true',default=False,dest='compiler',
20 help='''Download and use closure-compiler-r2388 (https://code.google.com/p/closure-compiler/)''')
21
22def configure (conf):
23 if conf.options.yui:
24 conf.start_msg ("Checking for yuicompressor")
25 if os.path.exists('tools/yuicompressor.jar'):
26 conf.end_msg('tools/yuicompressor.jar')
27 conf.env.HAVE_YUI = 1
28 else:
29 conf.end_msg('not found','YELLOW')
30 url="%s%s.zip" % (YUICOMPRESSOR_URL, YUICOMPRESSOR_NAME)
31 Logs.info ("Downloading yuicompressor from %s..." % url)
32 urllib.urlretrieve (url, "build/yuicompressor.zip")
33
34 filename='%s/build/%s.jar' % (YUICOMPRESSOR_NAME,YUICOMPRESSOR_NAME)
35 subprocess.check_call (['unzip', '-qq', '-o', '-j', 'build/yuicompressor.zip',
36 filename, '-d', 'tools/'])
37 os.rename ("tools/%s.jar" % YUICOMPRESSOR_NAME, "tools/yuicompressor.jar")
38 conf.env.HAVE_YUI = 1
39
40 if conf.options.compiler:
41 conf.start_msg ("Checking for closure-compiler")
42 if os.path.exists('tools/compiler.jar'):
43 conf.end_msg('tools/compiler.jar')
44 conf.env.HAVE_COMPILER = 1
45 else:
46 conf.end_msg('not found','YELLOW')
47 Logs.info ("Downloading closure-compiler from %s..." % CLOSURE_COMPILER)
48 urllib.urlretrieve (CLOSURE_COMPILER, "build/closure-compiler.zip")
49
50 subprocess.check_call (['unzip', '-qq', '-o', '-j', 'build/closure-compiler.zip', 'compiler.jar', '-d', 'tools/'])
51 conf.env.HAVE_COMPILER = 1
52
53 if conf.options.js_path:
54 conf.env.JS_PATH = conf.options.js_path
55
Alexander Afanasyev181a8b92013-02-28 13:28:53 -080056def build (bld):
Alexander Afanasyevf6b7dd42013-02-28 16:38:59 -080057 securityLib = ["contrib/securityLib/sha256.js",
58 "contrib/securityLib/base64.js",
59 "contrib/securityLib/rsa.js",
60 "contrib/securityLib/rsa2.js",
61 "contrib/securityLib/rsapem-1.1.js",
62 "contrib/securityLib/rsasign-1.2.js",
63 "contrib/securityLib/asn1hex-1.1.js",
64 "contrib/securityLib/x509-1.1.js",
65 "contrib/securityLib/jsbn.js",
66 "contrib/securityLib/jsbn2.js"]
67
68 ndnjs = ["js/Closure.js",
69 "js/WebSocketTransport.js",
70 "js/util/CCNProtocolDTags.js",
71 "js/util/CCNTime.js",
72 "js/util/ExponentialReExpressClosure.js",
73 "js/Name.js",
74 "js/ContentObject.js",
75 "js/encoding/DateFormat.js",
76 "js/Interest.js",
77 "js/Key.js",
78 "js/PublisherID.js",
79 "js/PublisherPublicKeyDigest.js",
80 "js/FaceInstance.js",
81 "js/ForwardingEntry.js",
82 "js/encoding/DynamicUint8Array.js",
83 "js/encoding/BinaryXMLEncoder.js",
84 "js/encoding/BinaryXMLDecoder.js",
85 "js/encoding/BinaryXMLStructureDecoder.js",
86 "js/encoding/DataUtils.js",
87 "js/encoding/EncodingUtils.js",
88 "js/security/KeyManager.js",
89 "js/security/Witness.js"] + securityLib + ["js/NDN.js"]
90
91 ndnjs = bld (features="combine",
92 target="ndn",
93 source=ndnjs)
94
95 if bld.env['HAVE_YUI']:
96 ndnjs.yui = True
97
98 if bld.env['HAVE_COMPILER']:
99 ndnjs.compiler = True
100
101 if bld.env['JS_PATH']:
102 ndnjs.install_path = bld.env['JS_PATH']
103
104
105@TaskGen.extension('.js')
106def js_hook(self, node):
107 node.sig=Utils.h_file (node.abspath())
108
109@TaskGen.feature('combine')
110@TaskGen.after_method('process_source')
111def apply_combine(self):
112 out = "%s.js" % self.target
113 tasks = []
114 task = self.create_task ('combine', self.source)
115 task.set_outputs (task.generator.path.find_or_declare (out))
116 tasks.append (task)
117
118 if getattr(self, 'yui', False):
119 out_yui = "%s.min.yui.js" % self.target
120 yui = self.create_task ('yuicompressor')
121 yui.combine = task
122 yui.set_outputs (yui.generator.path.find_or_declare (out_yui))
123 tasks.append (yui)
124
125 if getattr(self, 'compiler', False):
126 out_min = "%s.min.js" % self.target
127 compiler = self.create_task ('closure_compiler')
128 compiler.combine = task
129 compiler.set_outputs (yui.generator.path.find_or_declare (out_min))
130 tasks.append (compiler)
131
132 try:
133 for task in tasks:
134 self.bld.install_files (self.install_path, task.outputs[:], env=self.env)
135 except:
136 pass
137
138class combine (Task.Task):
139 def run(self):
140 outFile = self.outputs[0]
141 self.outputs[0].write ("", "w") # make file empty
142 for inFile in self.inputs:
143 self.outputs[0].write (inFile.read (), 'a')
144
145class yuicompressor (Task.Task):
146 after="combine"
147 color='PINK'
148 def __str__(self):
149 src_str=self.combine.outputs[0].nice_path()
150 tgt_str=self.outputs[0].nice_path()
151 return'%s: %s -> %s\n'%(self.__class__.__name__.replace('_task',''),src_str,tgt_str)
152
153 def run(self):
154 return self.exec_command(['java',
155 '-jar', '../tools/yuicompressor.jar',
156 '-o', self.outputs[0].abspath(),
157 self.combine.outputs[0].abspath()])
158
159class closure_compiler (Task.Task):
160 after="combine"
161 color='PINK'
162 def __str__(self):
163 src_str=self.combine.outputs[0].nice_path()
164 tgt_str=self.outputs[0].nice_path()
165 return'%s: %s -> %s\n'%(self.__class__.__name__.replace('_task',''),src_str,tgt_str)
166
167 def run(self):
168 return self.exec_command(['java',
169 '-jar', '../tools/compiler.jar',
170 '--js', self.combine.outputs[0].abspath(),
171 '--js_output_file', self.outputs[0].abspath()])