3 # Thomas Nagy, 2010 (ita)
8 scalac outputs files a bit where it wants to
12 from waflib
import Task
, Utils
, Node
13 from waflib
.TaskGen
import feature
, before_method
, after_method
15 from waflib
.Tools
import ccroot
16 ccroot
.USELIB_VARS
['scalac'] = set(['CLASSPATH', 'SCALACFLAGS'])
18 from waflib
.Tools
import javaw
21 @before_method('process_source')
22 def apply_scalac(self
):
24 Utils
.def_attrs(self
, jarname
='', classpath
='',
25 sourcepath
='.', srcdir
='.',
26 jar_mf_attributes
={}, jar_mf_classpath
=[])
28 outdir
= getattr(self
, 'outdir', None)
30 if not isinstance(outdir
, Node
.Node
):
31 outdir
= self
.path
.get_bld().make_node(self
.outdir
)
33 outdir
= self
.path
.get_bld()
35 self
.env
['OUTDIR'] = outdir
.abspath()
37 self
.scalac_task
= tsk
= self
.create_task('scalac')
40 srcdir
= getattr(self
, 'srcdir', '')
41 if isinstance(srcdir
, Node
.Node
):
43 for x
in Utils
.to_list(srcdir
):
44 if isinstance(x
, Node
.Node
):
47 y
= self
.path
.find_dir(x
)
49 self
.bld
.fatal('Could not find the folder %s from %s' % (x
, self
.path
))
54 feature('scalac')(javaw
.use_javac_files
)
55 after_method('apply_scalac')(javaw
.use_javac_files
)
57 feature('scalac')(javaw
.set_classpath
)
58 after_method('apply_scalac', 'use_scalac_files')(javaw
.set_classpath
)
61 SOURCE_RE
= '**/*.scala'
62 class scalac(javaw
.javac
):
64 vars = ['CLASSPATH', 'SCALACFLAGS', 'SCALAC', 'OUTDIR']
66 def runnable_status(self
):
68 Wait for dependent tasks to be complete, then read the file system to find the input nodes.
70 for t
in self
.run_after
:
78 self
.inputs
.extend(x
.ant_glob(SOURCE_RE
, remove
=False))
79 return super(javaw
.javac
, self
).runnable_status()
83 Execute the scalac compiler
88 wd
= bld
.bldnode
.abspath()
90 if isinstance(xx
, str):
93 self
.last_cmd
= lst
= []
94 lst
.extend(to_list(env
['SCALAC']))
95 lst
.extend(['-classpath'])
96 lst
.extend(to_list(env
['CLASSPATH']))
98 lst
.extend(to_list(env
['OUTDIR']))
99 lst
.extend(to_list(env
['SCALACFLAGS']))
100 lst
.extend([a
.abspath() for a
in self
.inputs
])
101 lst
= [x
for x
in lst
if x
]
103 self
.out
= self
.generator
.bld
.cmd_and_log(lst
, cwd
=wd
, env
=env
.env
or None, output
=0, quiet
=0)[1]
105 self
.generator
.bld
.cmd_and_log(lst
, cwd
=wd
, env
=env
.env
or None)
109 Detect the scalac program
111 # If SCALA_HOME is set, we prepend it to the path list
112 java_path
= self
.environ
['PATH'].split(os
.pathsep
)
115 if 'SCALA_HOME' in self
.environ
:
116 java_path
= [os
.path
.join(self
.environ
['SCALA_HOME'], 'bin')] + java_path
117 self
.env
['SCALA_HOME'] = [self
.environ
['SCALA_HOME']]
119 for x
in 'scalac scala'.split():
120 self
.find_program(x
, var
=x
.upper(), path_list
=java_path
)
122 if 'CLASSPATH' in self
.environ
:
123 v
['CLASSPATH'] = self
.environ
['CLASSPATH']
125 v
.SCALACFLAGS
= ['-verbose']
127 self
.fatal('scalac is required for compiling scala classes')