Unverified Commit a3ad1ff9 authored by Karl Linden's avatar Karl Linden
Browse files

Strip unnecessary tools and extras from waflib

parent f1549b4f
# This file is sourced by wafupdate when waf is updated.
# wafupdate home page: https://gitlab.com/lilrc/wafupdate
WAFLIB_STRIP_TOOLS="
asm
bison
compiler_d
compiler_fc
cs
d
d_config
d_scan
dbus
dmd
fc
fc_config
fc_scan
flex
g95
gas
gdc
gfortran
glib2
gnu_dirs
ifort
intltool
javaw
kde4
ldc2
lua
nasm
perl
python
qt4
qt5
ruby
tex
vala
winres
"
WAFLIB_STRIP_EXTRAS="
add_objects
biber
bjam
blender
boo
boost
c_dumbpreproc
cabal
cfg_altoptions
cfg_cross_gnu
clang_compilation_database
codelite
compat15
color_gcc
color_rvct
cppcheck
cpplint
cython
dcc
distnet
doxygen
dpapi
eclipse
erlang
fc_bgxlf
fc_cray
fc_nag
fc_nec
fc_open64
fc_pgfortran
fc_solstudio
fc_xlf
file_to_object
fluid
freeimage
fsb
fsc
gccdeps
go
gob2
halide
local_rpath
make
md5_tstamp
mem_reducer
midl
misc
msvcdeps
msvs
netcache_client
nobuild
objcopy
ocaml
package
parallel_debug
pch
pep8
pgicc
pgicxx
prefork
preforkjava
preforkunix
print_commands
proc
protoc
qnxnto
relocation
remote
resx
review
rst
run_do_script
run_m_script
run_py_script
run_r_script
sas
scala
slow_qt4
smart_continue
softlink_libs
stale
stracedeps
swig
syms
sync_exec
ticgt
unc
unity
use_config
valadoc
why
win32_opts
xcode
"
#!/usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2008-2010 (ita)
"""
Assembly support, used by tools such as gas and nasm
To declare targets using assembly::
def configure(conf):
conf.load('gcc gas')
def build(bld):
bld(
features='c cstlib asm',
source = 'test.S',
target = 'asmtest')
bld(
features='asm asmprogram',
source = 'test.S',
target = 'asmtest')
Support for pure asm programs and libraries should also work::
def configure(conf):
conf.load('nasm')
conf.find_program('ld', 'ASLINK')
def build(bld):
bld(
features='asm asmprogram',
source = 'test.S',
target = 'asmtest')
"""
import os, sys
from waflib import Task, Utils
import waflib.Task
from waflib.Tools.ccroot import link_task, stlink_task
from waflib.TaskGen import extension, feature
class asm(Task.Task):
"""
Compile asm files by gas/nasm/yasm/...
"""
color = 'BLUE'
run_str = '${AS} ${ASFLAGS} ${ASMPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${AS_SRC_F}${SRC} ${AS_TGT_F}${TGT}'
@extension('.s', '.S', '.asm', '.ASM', '.spp', '.SPP')
def asm_hook(self, node):
"""
Bind the asm extension to the asm task
:param node: input file
:type node: :py:class:`waflib.Node.Node`
"""
return self.create_compiled_task('asm', node)
class asmprogram(link_task):
"Link object files into a c program"
run_str = '${ASLINK} ${ASLINKFLAGS} ${ASLNK_TGT_F}${TGT} ${ASLNK_SRC_F}${SRC}'
ext_out = ['.bin']
inst_to = '${BINDIR}'
class asmshlib(asmprogram):
"Link object files into a c shared library"
inst_to = '${LIBDIR}'
class asmstlib(stlink_task):
"Link object files into a c static library"
pass # do not remove
def configure(conf):
conf.env['ASMPATH_ST'] = '-I%s'
#!/usr/bin/env python
# encoding: utf-8
# John O'Meara, 2006
# Thomas Nagy 2009-2010 (ita)
"""
The **bison** program is a code generator which creates C or C++ files.
The generated files are compiled into object files.
"""
from waflib import Task
from waflib.TaskGen import extension
class bison(Task.Task):
"""Compile bison files"""
color = 'BLUE'
run_str = '${BISON} ${BISONFLAGS} ${SRC[0].abspath()} -o ${TGT[0].name}'
ext_out = ['.h'] # just to make sure
@extension('.y', '.yc', '.yy')
def big_bison(self, node):
"""
Create a bison task, which must be executed from the directory of the output file.
"""
has_h = '-d' in self.env['BISONFLAGS']
outs = []
if node.name.endswith('.yc'):
outs.append(node.change_ext('.tab.cc'))
if has_h:
outs.append(node.change_ext('.tab.hh'))
else:
outs.append(node.change_ext('.tab.c'))
if has_h:
outs.append(node.change_ext('.tab.h'))
tsk = self.create_task('bison', node, outs)
tsk.cwd = node.parent.get_bld().abspath()
# and the c/cxx file must be compiled too
self.source.append(outs[0])
def configure(conf):
"""
Detect the *bison* program
"""
conf.find_program('bison', var='BISON')
conf.env.BISONFLAGS = ['-d']
#!/usr/bin/env python
# encoding: utf-8
# Carlos Rafael Giani, 2007 (dv)
# Thomas Nagy, 2010 (ita)
"""
Try to detect a D compiler from the list of supported compilers::
def options(opt):
opt.load('compiler_d')
def configure(cnf):
cnf.load('compiler_d')
def build(bld):
bld.program(source='main.d', target='app')
Only three D compilers are really present at the moment:
* gdc
* dmd, the ldc compiler having a very similar command-line interface
* ldc2
"""
import os, sys, imp, types, re
from waflib import Utils, Configure, Options, Logs
d_compiler = {
'default' : ['gdc', 'dmd', 'ldc2']
}
"""
Dict mapping the platform names to lists of names of D compilers to try, in order of preference::
from waflib.Tools.compiler_d import d_compiler
d_compiler['default'] = ['gdc', 'dmd', 'ldc2']
"""
def default_compilers():
build_platform = Utils.unversioned_sys_platform()
possible_compiler_list = d_compiler.get(build_platform, d_compiler['default'])
return ' '.join(possible_compiler_list)
def configure(conf):
"""
Try to find a suitable D compiler or raise a :py:class:`waflib.Errors.ConfigurationError`.
"""
try: test_for_compiler = conf.options.check_d_compiler or default_compilers()
except AttributeError: conf.fatal("Add options(opt): opt.load('compiler_d')")
for compiler in re.split('[ ,]+', test_for_compiler):
conf.env.stash()
conf.start_msg('Checking for %r (D compiler)' % compiler)
try:
conf.load(compiler)
except conf.errors.ConfigurationError as e:
conf.env.revert()
conf.end_msg(False)
Logs.debug('compiler_d: %r' % e)
else:
if conf.env.D:
conf.end_msg(conf.env.get_flat('D'))
conf.env['COMPILER_D'] = compiler
break
conf.end_msg(False)
else:
conf.fatal('could not configure a D compiler!')
def options(opt):
"""
Restrict the compiler detection from the command-line::
$ waf configure --check-d-compiler=dmd
"""
test_for_compiler = default_compilers()
d_compiler_opts = opt.add_option_group('Configuration options')
d_compiler_opts.add_option('--check-d-compiler', default=None,
help='list of D compilers to try [%s]' % test_for_compiler, dest='check_d_compiler')
for x in test_for_compiler.split():
opt.load('%s' % x)
#!/usr/bin/env python
# encoding: utf-8
import os, sys, imp, types, re
from waflib import Utils, Configure, Options, Logs, Errors
from waflib.Tools import fc
fc_compiler = {
'win32' : ['gfortran','ifort'],
'darwin' : ['gfortran', 'g95', 'ifort'],
'linux' : ['gfortran', 'g95', 'ifort'],
'java' : ['gfortran', 'g95', 'ifort'],
'default': ['gfortran'],
'aix' : ['gfortran']
}
"""
Dict mapping the platform names to lists of names of Fortran compilers to try, in order of preference::
from waflib.Tools.compiler_c import c_compiler
c_compiler['linux'] = ['gfortran', 'g95', 'ifort']
"""
def default_compilers():
build_platform = Utils.unversioned_sys_platform()
possible_compiler_list = fc_compiler.get(build_platform, fc_compiler['default'])
return ' '.join(possible_compiler_list)
def configure(conf):
"""
Try to find a suitable Fortran compiler or raise a :py:class:`waflib.Errors.ConfigurationError`.
"""
try: test_for_compiler = conf.options.check_fortran_compiler or default_compilers()
except AttributeError: conf.fatal("Add options(opt): opt.load('compiler_fc')")
for compiler in re.split('[ ,]+', test_for_compiler):
conf.env.stash()
conf.start_msg('Checking for %r (Fortran compiler)' % compiler)
try:
conf.load(compiler)
except conf.errors.ConfigurationError as e:
conf.env.revert()
conf.end_msg(False)
Logs.debug('compiler_fortran: %r' % e)
else:
if conf.env['FC']:
conf.end_msg(conf.env.get_flat('FC'))
conf.env.COMPILER_FORTRAN = compiler
break
conf.end_msg(False)
else:
conf.fatal('could not configure a Fortran compiler!')
def options(opt):
"""
Restrict the compiler detection from the command-line::
$ waf configure --check-fortran-compiler=ifort
"""
test_for_compiler = default_compilers()
opt.load_special_tools('fc_*.py')
fortran_compiler_opts = opt.add_option_group('Configuration options')
fortran_compiler_opts.add_option('--check-fortran-compiler', default=None,
help='list of Fortran compiler to try [%s]' % test_for_compiler,
dest="check_fortran_compiler")
for x in test_for_compiler.split():
opt.load('%s' % x)
#!/usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2006-2010 (ita)
"""
C# support. A simple example::
def configure(conf):
conf.load('cs')
def build(bld):
bld(features='cs', source='main.cs', gen='foo')
Note that the configuration may compile C# snippets::
FRAG = '''
namespace Moo {
public class Test { public static int Main(string[] args) { return 0; } }
}'''
def configure(conf):
conf.check(features='cs', fragment=FRAG, compile_filename='test.cs', gen='test.exe',
bintype='exe', csflags=['-pkg:gtk-sharp-2.0'], msg='Checking for Gtksharp support')
"""
from waflib import Utils, Task, Options, Logs, Errors
from waflib.TaskGen import before_method, after_method, feature
from waflib.Tools import ccroot
from waflib.Configure import conf
import os, tempfile
ccroot.USELIB_VARS['cs'] = set(['CSFLAGS', 'ASSEMBLIES', 'RESOURCES'])
ccroot.lib_patterns['csshlib'] = ['%s']
@feature('cs')
@before_method('process_source')
def apply_cs(self):
"""
Create a C# task bound to the attribute *cs_task*. There can be only one C# task by task generator.
"""
cs_nodes = []
no_nodes = []
for x in self.to_nodes(self.source):
if x.name.endswith('.cs'):
cs_nodes.append(x)
else:
no_nodes.append(x)
self.source = no_nodes
bintype = getattr(self, 'bintype', self.gen.endswith('.dll') and 'library' or 'exe')
self.cs_task = tsk = self.create_task('mcs', cs_nodes, self.path.find_or_declare(self.gen))
tsk.env.CSTYPE = '/target:%s' % bintype
tsk.env.OUT = '/out:%s' % tsk.outputs[0].abspath()
self.env.append_value('CSFLAGS', '/platform:%s' % getattr(self, 'platform', 'anycpu'))
inst_to = getattr(self, 'install_path', bintype=='exe' and '${BINDIR}' or '${LIBDIR}')
if inst_to:
# note: we are making a copy, so the files added to cs_task.outputs won't be installed automatically
mod = getattr(self, 'chmod', bintype=='exe' and Utils.O755 or Utils.O644)
self.install_task = self.bld.install_files(inst_to, self.cs_task.outputs[:], env=self.env, chmod=mod)
@feature('cs')
@after_method('apply_cs')
def use_cs(self):
"""
C# applications honor the **use** keyword::
def build(bld):
bld(features='cs', source='My.cs', bintype='library', gen='my.dll', name='mylib')
bld(features='cs', source='Hi.cs', includes='.', bintype='exe', gen='hi.exe', use='mylib', name='hi')
"""
names = self.to_list(getattr(self, 'use', []))
get = self.bld.get_tgen_by_name
for x in names:
try:
y = get(x)
except Errors.WafError:
self.env.append_value('CSFLAGS', '/reference:%s' % x)
continue
y.post()
tsk = getattr(y, 'cs_task', None) or getattr(y, 'link_task', None)
if not tsk:
self.bld.fatal('cs task has no link task for use %r' % self)
self.cs_task.dep_nodes.extend(tsk.outputs) # dependency
self.cs_task.set_run_after(tsk) # order (redundant, the order is infered from the nodes inputs/outputs)
self.env.append_value('CSFLAGS', '/reference:%s' % tsk.outputs[0].abspath())
@feature('cs')
@after_method('apply_cs', 'use_cs')
def debug_cs(self):
"""
The C# targets may create .mdb or .pdb files::
def build(bld):
bld(features='cs', source='My.cs', bintype='library', gen='my.dll', csdebug='full')
# csdebug is a value in (True, 'full', 'pdbonly')
"""
csdebug = getattr(self, 'csdebug', self.env.CSDEBUG)
if not csdebug:
return
node = self.cs_task.outputs[0]
if self.env.CS_NAME == 'mono':
out = node.parent.find_or_declare(node.name + '.mdb')
else:
out = node.change_ext('.pdb')
self.cs_task.outputs.append(out)
try:
self.install_task.source.append(out)
except AttributeError:
pass
if csdebug == 'pdbonly':
val = ['/debug+', '/debug:pdbonly']
elif csdebug == 'full':
val = ['/debug+', '/debug:full']
else:
val = ['/debug-']
self.env.append_value('CSFLAGS', val)
class mcs(Task.Task):
"""
Compile C# files
"""
color = 'YELLOW'
run_str = '${MCS} ${CSTYPE} ${CSFLAGS} ${ASS_ST:ASSEMBLIES} ${RES_ST:RESOURCES} ${OUT} ${SRC}'
def exec_command(self, cmd, **kw):
bld = self.generator.bld
try:
if not kw.get('cwd', None):
kw['cwd'] = bld.cwd
except AttributeError:
bld.cwd = kw['cwd'] = bld.variant_dir
try:
tmp = None
if isinstance(cmd, list) and len(' '.join(cmd)) >= 8192:
program = cmd[0] #unquoted program name, otherwise exec_command will fail
cmd = [self.quote_response_command(x) for x in cmd]
(fd, tmp) = tempfile.mkstemp()
os.write(fd, '\r\n'.join(i.replace('\\', '\\\\') for i in cmd[1:]).encode())
os.close(fd)
cmd = [program, '@' + tmp]
# no return here, that's on purpose
ret = self.generator.bld.exec_command(cmd, **kw)
finally:
if tmp:
try:
os.remove(tmp)
except OSError:
pass # anti-virus and indexers can keep the files open -_-
return ret
def quote_response_command(self, flag):
# /noconfig is not allowed when using response files
if flag.lower() == '/noconfig':
return ''
if flag.find(' ') > -1:
for x in ('/r:', '/reference:', '/resource:', '/lib:', '/out:'):
if flag.startswith(x):
flag = '%s"%s"' % (x, '","'.join(flag[len(x):].split(',')))
break
else:
flag = '"%s"' % flag
return flag
def configure(conf):
"""
Find a C# compiler, set the variable MCS for the compiler and CS_NAME (mono or csc)
"""
csc = getattr(Options.options, 'cscbinary', None)
if csc:
conf.env.MCS = csc
conf.find_program(['csc', 'mcs', 'gmcs'], var='MCS')
conf.env.ASS_ST = '/r:%s'
conf.env.RES_ST = '/resource:%s'
conf.env.CS_NAME = 'csc'
if str(conf.env.MCS).lower().find('mcs') > -1:
conf.env.CS_NAME = 'mono'
def options(opt):
"""
Add a command-line option for the configuration::
$ waf configure --with-csc-binary=/foo/bar/mcs
"""
opt.add_option('--with-csc-binary', type='string', dest='cscbinary')
class fake_csshlib(Task.Task):
"""
Task used for reading a foreign .net assembly and adding the dependency on it
"""
color = 'YELLOW'
inst_to = None
def runnable_status(self):
for x in self.outputs:
x.sig = Utils.h_file(x.abspath())
return Task.SKIP_ME
@conf
def read_csshlib(self, name, paths=[]):
"""
Read a foreign .net assembly for the *use* system::
def build(bld):
bld.read_csshlib('ManagedLibrary.dll', paths=[bld.env.mylibrarypath])
bld(features='cs', source='Hi.cs', bintype='exe', gen='hi.exe', use='ManagedLibrary.dll')
:param name: Name of the library