-
Notifications
You must be signed in to change notification settings - Fork 0
/
waf_java_utils.py
159 lines (134 loc) · 4.74 KB
/
waf_java_utils.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
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
#!/usr/bin/env python
# encoding: utf-8
import os
from waflib import Task, Utils, TaskGen, Node
from waflib.Tools import ccroot
######################
##### configure ######
######################
def configure (conf):
conf.load ("javaw")
pathdir = os.path.dirname (conf.env.JAVAC[0])
conf.check_jni_headers()
# Define rule for compiling with javac
run_str = "${JAVAC} -cp ${CLASSPATH} -d ${OUTDIR} ${JAVACFLAGS} ${SRC}"
conf.env.JAVAC_RUN_STR = run_str
if os.path.exists(pathdir+"/bin/javah"): # valid for JDK<10
conf.find_program ("javah", var = "JAVAH", path_list = pathdir)
# Define rule for compiling with javah (${_CLASS} is computed from ${SRC})
conf.env.JAVAH_RUN_STR = "${JAVAH} -jni -cp ${CLASSPATH} -o ${TGT} ${_CLASS}"
else:
conf.env.JAVAH_RUN_STR = "${JAVAC} -cp ${CLASSPATH} ${SRC} -h ${TGT}"
# Define rule for compiling with jar (${JAROPTS} is computed from ${SRC})
conf.env.JAR_RUN_STR = "${JAR} ${JARCREATE} ${TGT} ${JAROPTS}"
if not conf.env.JARCREATE:
conf.env.JARCREATE = "cf"
######################
####### Utils ########
######################
@TaskGen.feature ("myjavac", "myjavah")
@TaskGen.after_method ("process_source")
def process_use_wrapper (self):
self.process_use ()
@TaskGen.feature ("myjavac", "myjavah")
@TaskGen.after_method ("process_use")
def propagate_uselib_vars_wrapper (self):
self.propagate_uselib_vars ()
@TaskGen.feature ("myjavac", "myjavah")
@TaskGen.after_method ("propagate_uselib_vars")
def set_classpath_wrapper (self):
self.set_classpath ()
######################
####### JAVAH ########
######################
ccroot.USELIB_VARS['myjavah']=set(['CLASSPATH'])
@TaskGen.feature("myjavah")
@TaskGen.before_method("process_rule")
def myjavah_feature (self):
self.color = "GREEN"
self.rule = self.env.JAVAH_RUN_STR
_class = self.source.replace (os.path.sep, ".")
if _class.endswith (".class"):
_class = _class[:-6]
self.env._CLASS = _class
######################
####### JAVAC ########
######################
ccroot.USELIB_VARS['myjavac']=set(['CLASSPATH','JAVACFLAGS'])
@TaskGen.feature("myjavac")
@TaskGen.before_method("process_rule")
def myjavac_feature (self):
self.color = "GREEN"
self.rule = self.env.JAVAC_RUN_STR
outdir = getattr (self, "outdir", None)
if outdir:
if not isinstance(outdir, Node.Node):
outdir = self.path.get_bld().make_node(self.outdir)
else:
outdir = self.path.get_bld()
outdir.mkdir()
self.env.OUTDIR = outdir.abspath()
######################
######## JAR #########
######################
@TaskGen.feature("myjar")
@TaskGen.before_method("process_rule")
def myjar_feature (self):
self.color = "YELLOW"
self.rule = self.env.JAR_RUN_STR
basedir = getattr (self, "basedir" , None)
if basedir:
if not isinstance (self.basedir, Node.Node):
basedir = self.path.get_bld ().make_node (basedir)
else:
basedir = self.path.get_bld()
if not basedir:
self.bld.fatal ("Could not find the basedir %r for %r"%(self.basedir, self))
self.env.JAROPTS = [ "-C", basedir.bldpath () ]
if isinstance (self.source, list):
self.env.JAROPTS += self.source
else:
self.env.JAROPTS += [ self.source ]
######################
##### Java test ######
######################
ccroot.USELIB_VARS['javatest']=set(["CLASSPATH", "LD_LIBRARY_PATH"])
@TaskGen.feature("javatest")
@TaskGen.after_method("process_source")
def make_test_java (self):
if len (self.tasks) != 1 or len(self.tasks[0].outputs) != 1:
self.bld.fatal ("Expecting 1 task with 1 output in %r" % self)
tgtnode = self.tasks[0].outputs[0]
cl = os.path.splitext(os.path.basename(tgtnode.abspath()))[0]
self.name = "utest_java_" + cl
if hasattr (self, "classname_extra"):
cl = self.classname_extra + " " + cl
outnode = tgtnode.parent.make_node (self.name)
tsk = self.create_task ("java_gen_test", tgt = outnode, classnames = cl,
classpath_extra = [ tgtnode.parent.abspath(), "." ])
tsk.set_run_after (self.tasks[0])
self.link_task = tsk
self.ut_paths = self.path.abspath()
self.meths.append("make_test")
class java_gen_test (Task.Task):
"""
Generate a java test
"""
color = "PINK"
vars = [ "CLASSPATH", "JAVA", "LD_LIBRARY_PATH" ]
script_format = "#!/bin/bash\n%s -Djava.library.path=%s -cp %s %s\n"
script_format += "if [ $? -eq 0 ] ; then\n echo 'OK (1 test)'\n exit 0\n"
script_format += "else\n echo 'Run: 1 Failures: 1 Errors: 0'\n exit 1\nfi\n"
def run (self):
if isinstance (self.env.JAVA, list):
java = self.env.JAVA[0]
else:
java = self.env.JAVA
if isinstance (self.env.LD_LIBRARY_PATH, list):
ldlibpath = ":".join(self.env.LD_LIBRARY_PATH)
else:
ldlibpath = self.env.LD_LIBRARY_PATH
cp = self.env.CLASSPATH + os.pathsep.join(self.classpath_extra) + os.pathsep
s = self.script_format % (java, ldlibpath, cp, self.classnames)
self.outputs[0].write(s)
self.outputs[0].chmod (Utils.O755)