mirror of https://gitlab.com/ita1024/waf.git
Improve the Erlang module #2095
This commit is contained in:
parent
69157c7b68
commit
d35cd0cf12
|
@ -1,15 +1,17 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
#Thomas Nagy, 2010 (ita), Przemyslaw Rzepecki, 2016
|
# Thomas Nagy, 2010 (ita)
|
||||||
|
# Przemyslaw Rzepecki, 2016
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Erlang support
|
Erlang support
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from waflib import Task, TaskGen
|
|
||||||
from waflib.TaskGen import extension, feature, after_method, before_method
|
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
|
from waflib import Task, TaskGen
|
||||||
|
from waflib.TaskGen import feature, after_method, before_method
|
||||||
|
# to load the method "to_incnodes" below
|
||||||
|
from waflib.Tools import ccroot
|
||||||
|
|
||||||
# Those flags are required by the Erlang VM to execute/evaluate code in
|
# Those flags are required by the Erlang VM to execute/evaluate code in
|
||||||
# non-interactive mode. It is used in this tool to create Erlang modules
|
# non-interactive mode. It is used in this tool to create Erlang modules
|
||||||
|
@ -17,73 +19,48 @@ import re
|
||||||
# 'erl' command with ERL_FLAGS environment variable.
|
# 'erl' command with ERL_FLAGS environment variable.
|
||||||
EXEC_NON_INTERACTIVE = ['-noshell', '-noinput', '-eval']
|
EXEC_NON_INTERACTIVE = ['-noshell', '-noinput', '-eval']
|
||||||
|
|
||||||
def scan_meth(task):
|
|
||||||
node = task.inputs[0]
|
|
||||||
parent = node.parent
|
|
||||||
|
|
||||||
deps = []
|
|
||||||
scanned = set([])
|
|
||||||
nodes_to_scan = [node]
|
|
||||||
|
|
||||||
for n in nodes_to_scan:
|
|
||||||
if n.abspath() in scanned:
|
|
||||||
continue
|
|
||||||
|
|
||||||
for i in re.findall('-include\("(.*)"\)\.', n.read()):
|
|
||||||
found = False
|
|
||||||
for d in task.includes_nodes:
|
|
||||||
r = task.generator.path.find_resource(os.path.join(d,i))
|
|
||||||
if r:
|
|
||||||
deps.append(r)
|
|
||||||
nodes_to_scan.append(r)
|
|
||||||
found = True
|
|
||||||
break
|
|
||||||
r = task.generator.bld.root.find_resource(os.path.join(d,i))
|
|
||||||
if r:
|
|
||||||
deps.append(r)
|
|
||||||
nodes_to_scan.append(r)
|
|
||||||
found = True
|
|
||||||
break
|
|
||||||
if not found:
|
|
||||||
pass
|
|
||||||
scanned.add(n.abspath())
|
|
||||||
|
|
||||||
return (deps, [])
|
|
||||||
|
|
||||||
def configure(conf):
|
def configure(conf):
|
||||||
conf.find_program('erlc', var='ERLC')
|
conf.find_program('erlc', var='ERLC')
|
||||||
conf.find_program('erl', var='ERL')
|
conf.find_program('erl', var='ERL')
|
||||||
conf.add_os_flags('ERLC_FLAGS')
|
conf.add_os_flags('ERLC_FLAGS')
|
||||||
conf.add_os_flags('ERL_FLAGS')
|
conf.add_os_flags('ERL_FLAGS')
|
||||||
|
conf.env.ERLC_DEF_PATTERN = '-D%s'
|
||||||
|
conf.env.ERLC_INC_PATTERN = '-I%s'
|
||||||
|
|
||||||
@TaskGen.extension('.erl')
|
@TaskGen.extension('.erl')
|
||||||
def process(self, node):
|
def process_erl_node(self, node):
|
||||||
tsk = self.create_task('erl', node, node.change_ext('.beam'))
|
tsk = self.create_task('erl', node, node.change_ext('.beam'))
|
||||||
tsk.includes_nodes = self.to_list(getattr(self, 'includes', [])) + self.env['INCLUDES'] + [node.parent.abspath()]
|
tsk.erlc_incnodes = [tsk.outputs[0].parent] + self.to_incnodes(self.includes)
|
||||||
tsk.defines = self.to_list(getattr(self, 'defines', [])) + self.env['DEFINES']
|
tsk.env.append_value('ERLC_INCPATHS', [x.abspath() for x in tsk.erlc_incnodes])
|
||||||
tsk.flags = self.to_list(getattr(self, 'flags', [])) + self.env['ERLC_FLAGS']
|
tsk.env.append_value('ERLC_DEFINES', self.to_list(getattr(self, 'defines', [])))
|
||||||
|
tsk.env.append_value('ERLC_FLAGS', self.to_list(getattr(self, 'flags', [])))
|
||||||
|
tsk.cwd = tsk.outputs[0].parent
|
||||||
|
|
||||||
class erl(Task.Task):
|
class erl(Task.Task):
|
||||||
scan=scan_meth
|
color = 'GREEN'
|
||||||
color='GREEN'
|
run_str = '${ERLC} ${ERL_FLAGS} ${ERLC_INC_PATTERN:ERLC_INCPATHS} ${ERLC_DEF_PATTERN:ERLC_DEFINES} ${SRC}'
|
||||||
vars = ['ERLC_FLAGS', 'ERLC', 'ERL', 'INCLUDES', 'DEFINES']
|
|
||||||
|
|
||||||
def run(self):
|
def scan(task):
|
||||||
output=self.inputs[0].change_ext('.beam')
|
node = task.inputs[0]
|
||||||
erlc = self.generator.env["ERLC"]
|
|
||||||
inca = [i for i in self.includes_nodes if os.path.isabs(i)]
|
deps = []
|
||||||
incr = [self.generator.path.find_dir(i) for i in self.includes_nodes if not os.path.isabs(i)]
|
scanned = set([])
|
||||||
incr = filter(lambda x:x, incr)
|
nodes_to_scan = [node]
|
||||||
incb = [i.get_bld() for i in incr]
|
|
||||||
inc = inca + [i.abspath() for i in incr+incb]
|
for n in nodes_to_scan:
|
||||||
r = self.exec_command(
|
if n.abspath() in scanned:
|
||||||
erlc + self.flags
|
continue
|
||||||
+ ["-I"+i for i in inc]
|
|
||||||
+ ["-D"+d for d in self.defines]
|
for i in re.findall('-include\("(.*)"\)\.', n.read()):
|
||||||
+ [self.inputs[0].path_from(output.parent)],
|
for d in task.erlc_incnodes:
|
||||||
cwd=output.parent.abspath(),
|
r = d.find_node(i)
|
||||||
shell=False)
|
if r:
|
||||||
return r
|
deps.append(r)
|
||||||
|
nodes_to_scan.append(r)
|
||||||
|
break
|
||||||
|
scanned.add(n.abspath())
|
||||||
|
|
||||||
|
return (deps, [])
|
||||||
|
|
||||||
@TaskGen.extension('.beam')
|
@TaskGen.extension('.beam')
|
||||||
def process(self, node):
|
def process(self, node):
|
||||||
|
@ -92,40 +69,29 @@ def process(self, node):
|
||||||
|
|
||||||
class erl_test(Task.Task):
|
class erl_test(Task.Task):
|
||||||
color = 'BLUE'
|
color = 'BLUE'
|
||||||
vars = ['ERL', 'ERL_FLAGS']
|
run_str = '${ERL} ${ERL_FLAGS} ${ERL_TEST_FLAGS}'
|
||||||
|
|
||||||
def run(self):
|
|
||||||
test_list = ", ".join([m.change_ext("").path_from(m.parent)+":test()" for m in self.modules])
|
|
||||||
flags = " ".join(self.flags)
|
|
||||||
return self.exec_command(
|
|
||||||
self.generator.env.ERL
|
|
||||||
+ self.generator.env.ERL_FLAGS
|
|
||||||
+ self.flags
|
|
||||||
+ EXEC_NON_INTERACTIVE
|
|
||||||
+ ['halt(case lists:all(fun(Elem) -> Elem == ok end, [%s]) of true -> 0; false -> 1 end).' % test_list],
|
|
||||||
cwd = self.modules[0].parent.abspath())
|
|
||||||
|
|
||||||
@feature('eunit')
|
@feature('eunit')
|
||||||
@after_method('process_source')
|
@after_method('process_source')
|
||||||
def addtestrun(self):
|
def add_erl_test_run(self):
|
||||||
test_modules = [t.outputs[0] for t in self.tasks]
|
test_modules = [t.outputs[0] for t in self.tasks]
|
||||||
test_task = self.create_task('erl_test')
|
test_task = self.create_task('erl_test')
|
||||||
test_task.set_inputs(self.source + test_modules)
|
test_task.set_inputs(self.source + test_modules)
|
||||||
test_task.modules = test_modules
|
test_task.cwd = test_modules[0].parent
|
||||||
test_task.flags = self.to_list(getattr(self, 'flags', []))
|
|
||||||
|
test_task.env.append_value('ERL_FLAGS', self.to_list(getattr(self, 'flags', [])))
|
||||||
|
|
||||||
|
test_list = ", ".join([m.change_ext("").path_from(test_task.cwd)+":test()" for m in test_modules])
|
||||||
|
test_flag = 'halt(case lists:all(fun(Elem) -> Elem == ok end, [%s]) of true -> 0; false -> 1 end).' % test_list
|
||||||
|
test_task.env.append_value('ERL_TEST_FLAGS', EXEC_NON_INTERACTIVE)
|
||||||
|
test_task.env.append_value('ERL_TEST_FLAGS', test_flag)
|
||||||
|
|
||||||
|
|
||||||
class edoc(Task.Task):
|
class edoc(Task.Task):
|
||||||
color = 'BLUE'
|
color = 'BLUE'
|
||||||
vars = ['ERL_FLAGS', 'ERL']
|
run_str = "${ERL} ${ERL_FLAGS} ${ERL_DOC_FLAGS}"
|
||||||
|
def keyword(self):
|
||||||
def run(self):
|
return 'Generating edoc'
|
||||||
self.exec_command(
|
|
||||||
self.generator.env.ERL
|
|
||||||
+ self.generator.env.ERL_FLAGS
|
|
||||||
+ EXEC_NON_INTERACTIVE
|
|
||||||
+ ['edoc:files([\"'+self.inputs[0].abspath()+'\"]), halt(0).'],
|
|
||||||
cwd = self.outputs[0].parent.abspath()
|
|
||||||
)
|
|
||||||
|
|
||||||
@feature('edoc')
|
@feature('edoc')
|
||||||
@before_method('process_source')
|
@before_method('process_source')
|
||||||
|
@ -136,4 +102,9 @@ def add_edoc_task(self):
|
||||||
t = e.change_ext('.html')
|
t = e.change_ext('.html')
|
||||||
png = t.parent.make_node('erlang.png')
|
png = t.parent.make_node('erlang.png')
|
||||||
css = t.parent.make_node('stylesheet.css')
|
css = t.parent.make_node('stylesheet.css')
|
||||||
self.create_task('edoc', e, [t, png, css])
|
tsk = self.create_task('edoc', e, [t, png, css])
|
||||||
|
tsk.cwd = tsk.outputs[0].parent
|
||||||
|
tsk.env.append_value('ERL_DOC_FLAGS', EXEC_NON_INTERACTIVE)
|
||||||
|
tsk.env.append_value('ERL_DOC_FLAGS', 'edoc:files(["%s"]), halt(0).' % tsk.inputs[0].abspath())
|
||||||
|
# TODO the above can break if a file path contains '"'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue