smplpkgs.py
Go to the documentation of this file.
1 # -*- python -*-
2 '''This tool implements a source package following a few contentions.
3 
4 Your source package may build any combination of the following:
5 
6  - shared libraries
7  - headers exposing an API to libraries
8  - a ROOT dictionary for this API
9  - main programs
10  - test programs
11 
12 This tool will produce various methods on the build context. You can
13 avoid passing <name> to them if you set APPNAME in your wscript file.
14 
15 '''
16 
17 import os.path as osp
18 from waflib.Utils import to_list
19 from waflib.Configure import conf
20 import waflib.Context
21 from waflib.Logs import debug, info, error, warn
22 
23 _tooldir = osp.dirname(osp.abspath(__file__))
24 
25 def options(opt):
26  opt.load('compiler_cxx')
27  opt.load('waf_unit_test')
28 
29 
30 def configure(cfg):
31  cfg.load('compiler_cxx')
32  cfg.load('waf_unit_test')
33 
34  cfg.env.append_unique('CXXFLAGS',['-std=c++17'])
35 
36  cfg.find_program('python', var='PYTHON', mandatory=True)
37  cfg.find_program('bash', var='BASH', mandatory=True)
38 
39  pass
40 
41 def build(bld):
42  from waflib.Tools import waf_unit_test
43  bld.add_post_fun(waf_unit_test.summary)
44 
45 
46 @conf
47 def smplpkg(bld, name, use='', app_use='', test_use=''):
48  use = list(set(to_list(use)))
49  app_use = list(set(use + to_list(app_use)))
50  test_use = list(set(use + to_list(test_use)))
51 
52  includes = []
53  headers = []
54  source = []
55 
56  incdir = bld.path.find_dir('inc')
57  srcdir = bld.path.find_dir('src')
58  dictdir = bld.path.find_dir('dict')
59 
60  testsrc = bld.path.ant_glob('test/test_*.cxx')
61  test_scripts = bld.path.ant_glob('test/test_*.sh') + bld.path.ant_glob('test/test_*.py')
62  appsdir = bld.path.find_dir('apps')
63 
64  if incdir:
65  headers += incdir.ant_glob(name + '/*.h')
66  includes += ['inc']
67  bld.env['INCLUDES_'+name] = [incdir.abspath()]
68 
69  if headers:
70  bld.install_files('${PREFIX}/include/%s' % name, headers)
71 
72  if srcdir:
73  source += srcdir.ant_glob('*.cxx')
74  source += srcdir.ant_glob('*.cu') # cuda
75 
76  # fixme: I should move this out of here.
77  # root dictionary
78  if dictdir:
79  if not headers:
80  error('No header files for ROOT dictionary "%s"' % name)
81  #print 'Building ROOT dictionary: %s using %s' % (name,use)
82  if 'ROOTSYS' in use:
83  linkdef = dictdir.find_resource('LinkDef.h')
84  bld.gen_rootcling_dict(name, linkdef,
85  headers = headers,
86  includes = includes,
87  use = use)
88  source.append(bld.path.find_or_declare(name+'Dict.cxx'))
89  else:
90  warn('No ROOT dictionary will be generated for "%s" unless "ROOTSYS" added to "use"' % name)
91 
92  def get_rpath(uselst, local=True):
93  ret = set([bld.env["PREFIX"]+"/lib"])
94  for one in uselst:
95  libpath = bld.env["LIBPATH_"+one]
96  for l in libpath:
97  ret.add(l)
98  if local:
99  if one.startswith("WireCell"):
100  sd = one[8:].lower()
101  blddir = bld.path.find_or_declare(bld.out_dir)
102  pkgdir = blddir.find_or_declare(sd).abspath()
103  #print pkgdir
104  ret.add(pkgdir)
105  ret = list(ret)
106  return ret
107 
108  # the library
109  if incdir and srcdir:
110  #print "Building library: %s using %s"%(name, use)
111  bld(features = 'cxx cxxshlib',
112  name = name,
113  source = source,
114  target = name,
115  #rpath = get_rpath(use),
116  includes = 'inc',
117  export_includes = 'inc',
118  use = use)
119 
120  if (testsrc or test_scripts) and not bld.options.no_tests:
121  for test_main in testsrc:
122  #print 'Building %s test: %s using %s' % (name, test_main, test_use)
123  rpath = get_rpath(test_use + [name])
124  #print rpath
125  bld.program(features = 'test',
126  source = [test_main],
127  ut_cwd = bld.path,
128  target = test_main.name.replace('.cxx',''),
129  install_path = None,
130  rpath = rpath,
131  includes = ['inc','test','tests'],
132  use = test_use + [name])
133  for test_script in test_scripts:
134  interp = "${BASH}"
135  if test_script.abspath().endswith(".py"):
136  interp = "${PYTHON}"
137  #print 'Building %s test %s script: %s using %s' % (name, interp, test_script, test_use)
138  bld(features="test_scripts",
139  ut_cwd = bld.path,
140  test_scripts_source = test_script,
141  test_scripts_template = "pwd && " + interp + " ${SCRIPT}")
142 
143  if appsdir:
144  for app in appsdir.ant_glob('*.cxx'):
145  #print 'Building %s app: %s using %s' % (name, app, app_use)
146  bld.program(source = [app],
147  target = app.name.replace('.cxx',''),
148  includes = 'inc',
149  rpath = get_rpath(app_use + [name], local=False),
150  use = app_use + [name])
151 
def build(bld)
Definition: smplpkgs.py:41
error
Definition: include.cc:26
def options(opt)
Definition: smplpkgs.py:25
def configure(cfg)
Definition: smplpkgs.py:30
def smplpkg(bld, name, use='', app_use='', test_use='')
Definition: smplpkgs.py:47