-
Notifications
You must be signed in to change notification settings - Fork 0
/
hwaf-base.py
1046 lines (941 loc) · 34.4 KB
/
hwaf-base.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- python -*-
# stdlib imports
import os
import os.path as osp
import sys
# waf imports ---
import waflib.Options
import waflib.Utils
import waflib.Logs as msg
from waflib.Configure import conf
_heptooldir = osp.dirname(osp.abspath(__file__))
# add this directory to sys.path to ease the loading of other hepwaf tools
if not _heptooldir in sys.path: sys.path.append(_heptooldir)
WSCRIPT_FILE = 'wscript'
### ---------------------------------------------------------------------------
def options(ctx):
if 'darwin' in sys.platform:
ctx.add_option(
'--use-macports',
default=None,
action='store_true',
help="Enable MacPorts")
ctx.add_option(
'--use-fink',
default=None,
action='store_true',
help="Enable Fink")
pass
ctx.add_option(
'--relocate-from',
default=None,
help='top-level path to relocate against (default=${PREFIX})',
)
ctx.add_option(
'--project-version',
default=None,
help='modify the project version used during build',
)
ctx.add_option(
'--local-cfg',
default="local.conf",
help="Path to the local config file listing all type of configuration infos")
ctx.load('hwaf-system', tooldir=_heptooldir)
ctx.load('hwaf-dist', tooldir=_heptooldir)
ctx.load('hwaf-project-mgr', tooldir=_heptooldir)
ctx.load('hwaf-runtime', tooldir=_heptooldir)
ctx.load('hwaf-rules', tooldir=_heptooldir)
ctx.load('hwaf-cmtcompat', tooldir=_heptooldir)
pkgdir = 'src'
if osp.exists(pkgdir):
pkgs = hwaf_find_suboptions(pkgdir)
ctx.recurse(pkgs, mandatory=False)
return
### ---------------------------------------------------------------------------
def configure(ctx):
if ctx.options.local_cfg:
fname = osp.abspath(ctx.options.local_cfg)
ctx.start_msg("Manifest file")
ctx.end_msg(fname)
ok = ctx.read_cfg(fname)
ctx.start_msg("Manifest file processing")
ctx.end_msg(ok)
pass
if not ctx.env.HWAF_MODULES: ctx.env.HWAF_MODULES = []
if not ctx.env.HWAF_ENV_SPY: ctx.env.HWAF_ENV_SPY = []
ctx.load('hwaf-system', tooldir=_heptooldir)
ctx.load('hwaf-dist', tooldir=_heptooldir)
ctx.load('hwaf-project-mgr', tooldir=_heptooldir)
ctx.load('hwaf-runtime', tooldir=_heptooldir)
ctx.load('hwaf-rules', tooldir=_heptooldir)
ctx.load('hwaf-cmtcompat', tooldir=_heptooldir)
# register a couple of runtime environment variables
ctx.declare_runtime_env('PATH')
ctx.declare_runtime_env('RPATH')
ctx.declare_runtime_env('LD_LIBRARY_PATH')
ctx.declare_runtime_env('PYTHONPATH')
if ctx.is_darwin():
ctx.declare_runtime_env('DYLD_LIBRARY_PATH')
pass
ctx.declare_runtime_env('PKG_CONFIG_PATH')
ctx.declare_runtime_env('CMTCFG')
for k in ['CPPFLAGS',
'CFLAGS',
'CCFLAGS',
'CXXFLAGS',
'FCFLAGS',
'LINKFLAGS',
'SHLINKFLAGS',
'SHLIB_MARKER',
'AR',
'ARFLAGS',
'CC',
'CXX',
'LINK_CC',
'LINK_CXX',
'LIBPATH',
'DEFINES',
'EXTERNAL_AREA',
'INSTALL_AREA',
'INSTALL_AREA_BINDIR',
'INSTALL_AREA_LIBDIR',
'PREFIX',
'DESTDIR',
'BINDIR',
'LIBDIR',
'HOME',
'EDITOR',
'USER',
'LANG',
'LC_ALL',
'TERM',
'TERMCAP',
'HISTORY',
'HISTSIZE',
'PS1',
'SHELL',
'PWD',
'OLDPWD',
'DISPLAY',
]:
ctx.declare_runtime_env(k)
pass
# configure project
ctx._hwaf_configure_project()
# display project infos...
msg.info('='*80)
ctx.msg('project', '%s-%s' % (ctx.env.HWAF_PROJECT_NAME,
ctx.env.HWAF_PROJECT_VERSION))
ctx.msg('prefix', ctx.env.PREFIX)
if ctx.env.DESTDIR:
ctx.msg('destdir', ctx.env.DESTDIR)
pass
ctx.msg('pkg dir', ctx.env.CMTPKGS)
ctx.msg('variant', ctx.env.CMTCFG)
ctx.msg('arch', ctx.env.CFG_ARCH)
ctx.msg('OS', ctx.env.CFG_OS)
ctx.msg('compiler', ctx.env.CFG_COMPILER)
ctx.msg('build-type', ctx.env.CFG_TYPE)
deps = ctx.hwaf_project_deps()
if deps: deps = ','.join(deps)
else: deps = 'None'
ctx.msg('projects deps', deps)
ctx.msg('install-area', ctx.env.INSTALL_AREA)
ctx.msg('njobs-max', waflib.Options.options.jobs)
msg.info('='*80)
# environment has been bootstrapped
# loop back over ctx.options.xyz in case some environment variables
# need to be expanded
opts = [o for o in dir(ctx.options)]
for k in opts:
v = getattr(ctx.options, k)
if v == None or not isinstance(v, type("")):
continue
v = waflib.Utils.subst_vars(v, ctx.env)
setattr(ctx.options, k, v)
pass
# loading the tool which logs the environment modifications
ctx.load('hwaf-spy-env', tooldir=_heptooldir)
ctx.hwaf_setup_spy_env()
return
def build(ctx):
ctx.load('hwaf-system', tooldir=_heptooldir)
ctx.load('hwaf-dist', tooldir=_heptooldir)
ctx.load('hwaf-project-mgr', tooldir=_heptooldir)
ctx.load('hwaf-runtime', tooldir=_heptooldir)
ctx.load('hwaf-rules', tooldir=_heptooldir)
ctx.load('hwaf-spy-env', tooldir=_heptooldir)
ctx.load('hwaf-cmtcompat', tooldir=_heptooldir)
ctx._hwaf_create_project_hwaf_module()
ctx._hwaf_load_project_hwaf_module(do_export=False)
return
### ---------------------------------------------------------------------------
@conf
def hwaf_get_install_path(self, k, destdir=True):
"""
Installation path obtained from ``self.dest`` and prefixed by the destdir.
The variables such as '${PREFIX}/bin' are substituted.
"""
dest = waflib.Utils.subst_vars(k, self.env)
dest = dest.replace('/', os.sep)
if destdir and self.env.DESTDIR:
destdir = self.env.DESTDIR
dest = os.path.join(destdir, osp.splitdrive(dest)[1].lstrip(os.sep))
pass
return dest
### ---------------------------------------------------------------------------
@conf
def hwaf_find_subpackages(self, directory='.'):
srcs = []
root_node = self.path.find_dir(directory)
dirs = root_node.ant_glob('**/*', src=False, dir=True)
for d in dirs:
#msg.debug ("##> %s (type: %s)" % (d.abspath(), type(d)))
node = d
if node and node.ant_glob(WSCRIPT_FILE):
srcs.append(d)
pass
return srcs
### ---------------------------------------------------------------------------
def hwaf_find_suboptions(directory='.'):
pkgs = []
for root, dirs, files in os.walk(directory):
if WSCRIPT_FILE in files:
pkgs.append(root)
continue
return pkgs
### ---------------------------------------------------------------------------
@conf
def find_at(ctx, check, what, where, **kwargs):
def _subst(v):
v = waflib.Utils.subst_vars(v, ctx.env)
return v
where = _subst(where)
if not osp.exists(where):
return False
os_env = dict(os.environ)
pkgp = os.getenv("PKG_CONFIG_PATH", "")
try:
WHAT = what.upper()
ctx.env.stash()
ctx.env[WHAT + "_HOME"] = where
incdir = osp.join(where, "include")
bindir = osp.join(where, "bin")
libdir = osp.join(where, "lib")
incdir = getattr(ctx.options, 'with_%s_includes' % what, incdir)
libdir = getattr(ctx.options, 'with_%s_libs' % what, libdir)
if isinstance(incdir, (list, tuple)):
if len(incdir)>0: incdir=incdir[0]
else: incdir=osp.join(where, "include")
if isinstance(libdir, (list, tuple)):
if len(libdir)>0: libdir=libdir[0]
else: libdir=osp.join(where, "lib")
ctx.env.prepend_value('PATH', bindir)
ctx.env.prepend_value('RPATH', libdir)
ctx.env.prepend_value('LD_LIBRARY_PATH', libdir)
os_keys = ("PATH", "RPATH", "LD_LIBRARY_PATH")
if ctx.is_darwin():
os_keys += ("DYLD_LIBRARY_PATH",)
ctx.env.prepend_value('DYLD_LIBRARY_PATH', libdir)
os.environ['DYLD_LIBRARY_PATH'] = os.sep.join(ctx.env['DYLD_LIBRARY_PATH'])
pass
pkgconf_path = osp.join(where, "lib/pkgconfig")
ctx.env.prepend_value('PKG_CONFIG_PATH', pkgconf_path)
ctx.to_log("Pkg config path: %s" % ctx.env.PKG_CONFIG_PATH)
for kk in os_keys:
os.environ[kk] = os.pathsep.join(ctx.env[kk]+[os.getenv(kk,'')])
pass
if pkgp:
os.environ["PKG_CONFIG_PATH"] = os.pathsep.join((pkgconf_path,pkgp))
else:
os.environ["PKG_CONFIG_PATH"] = pkgconf_path
if osp.exists(incdir):
ctx.parse_flags(_subst("${CPPPATH_ST}") % incdir,
uselib_store=kwargs["uselib_store"])
if osp.exists(libdir):
ctx.parse_flags(_subst("${LIBPATH_ST}") % libdir,
uselib_store=kwargs["uselib_store"])
this_kwargs = kwargs.copy()
this_kwargs['check_path'] = where
if check == ctx.check_cfg:
# check if the special xyz-config binary exists...
if not this_kwargs['package'] and not osp.exists(bindir):
ctx.fatal("no such directory [%s]" % bindir)
pass
pass
check(**this_kwargs)
setattr(ctx.options, 'with_%s_incdir' % what, incdir)
setattr(ctx.options, 'with_%s_libdir' % what, libdir)
return True
except ctx.errors.ConfigurationError:
os.environ = os_env
os.environ["PKG_CONFIG_PATH"] = pkgp
ctx.end_msg("failed", color="YELLOW")
ctx.env.revert()
return False
return False
### ---------------------------------------------------------------------------
@conf
def check_with(ctx, check, what, *args, **kwargs):
"""
Perform `check`, also looking at directories specified by the --with-X
commandline option and X_HOME environment variable (X = what.upper())
The extra_args
"""
import os
from os.path import abspath
# adds 'extra_paths' and other defaults...
kwargs = ctx._findbase_setup(kwargs)
with_dir = getattr(ctx.options, "with_" + what, None)
env_dir = os.environ.get(what.upper() + "_HOME", None)
paths = [with_dir, env_dir] + kwargs.pop("extra_paths", [])
WHAT = what.upper()
kwargs["uselib_store"] = kwargs.get("uselib_store", WHAT)
kwargs["use"] = waflib.Utils.to_list(kwargs.get("use", [])) + \
waflib.Utils.to_list(kwargs["uselib_store"])
for path in [abspath(p) for p in paths if p]:
path = waflib.Utils.subst_vars(path, ctx.env)
ctx.in_msg = 0
ctx.to_log("Checking for %s in %s" % (what, path))
if ctx.find_at(check, what, path, **kwargs):
#print ">> found %s at %s" % (what, path)
ctx.in_msg = 0
ctx.msg("Found %s at" % what, path, color="WHITE")
ctx.declare_runtime_env(WHAT + "_HOME")
return
pass
ctx.in_msg = 0
check(**kwargs)
ctx.in_msg = 0
ctx.msg("Found %s at" % what, "(local environment)", color="WHITE")
# FIXME: handle windows ?
ctx.env[WHAT + "_HOME"] = "/usr"
ctx.declare_runtime_env(WHAT + "_HOME")
return
### ---------------------------------------------------------------------------
@conf
def _findbase_setup(ctx, kwargs):
extra_paths = []
if ctx.is_linux() or \
ctx.is_freebsd() or \
ctx.is_darwin():
extra_paths.extend([
#"/usr",
#"/usr/local",
])
# FIXME: should use use_macports...
if ctx.is_darwin(): # and ctx.options.use_macports:
extra_paths.extend([
# macports
"/opt/local",
])
# FIXME: should use with_fink
if ctx.is_darwin(): # and ctx.options.with_fink:
extra_paths.extend([
# fink
"/sw",
])
kwargs['extra_paths'] = waflib.Utils.to_list(
kwargs.get('extra_paths', [])) + extra_paths
kwargs['_check_mandatory'] = kwargs.get('mandatory', True)
kwargs[ 'mandatory'] = kwargs.get('mandatory', True)
return kwargs
### ---------------------------------------------------------------------------
@conf
def read_cfg(ctx, fname):
"""
read_cfg reads a MANIFEST-like file to extract a configuration.
That configuration file must be in a format that ConfigParser understands.
"""
fname = osp.abspath(fname)
if not osp.exists(fname):
ctx.fatal("no such file [%s]" % fname)
return False
try: from ConfigParser import SafeConfigParser as CfgParser
except ImportError: from configparser import ConfigParser as CfgParser
cfg = CfgParser()
cfg.optionxform = str
cfg.read([fname])
# top-level config
if cfg.has_section('hwaf-cfg'):
section = 'hwaf-cfg'
for k in ('cmtcfg', 'prefix', 'projects', 'cmtpkgs'):
if cfg.has_option(section, k):
#msg.info("....[%s]..." % k)
if not (None == getattr(ctx.options, k)):
# user provided a value from command-line: that wins.
pass
else:
v = cfg.get(section, k)
setattr(ctx.options, k, v)
#ctx.msg(k, v)
pass
pass
pass
# env-level config
if cfg.has_section('hwaf-env'):
for k in cfg.options('hwaf-env'):
# FIXME: make sure variable interpolation works at some point
ctx.env[k] = cfg.get('hwaf-env', k)
pass
pass
def _as_string(v):
if isinstance(v, (list, tuple)):
if len(v)==1: v=v[0]
else: raise ValueError('expected a 1-item collection (got: %r)' % v)
return v
# toolchain config
if cfg.has_section('hwaf-toolchain'):
section = 'hwaf-toolchain'
secattr = section.replace('-','_')
if cfg.has_option(section, 'path'):
v = cfg.get(section, 'path')
v = _as_string(v)
setattr(ctx.options, 'with_%s' % secattr, v)
if cfg.has_option(section, 'incdir'):
v = cfg.get(section, 'incdir')
v = _as_string(v)
setattr(ctx.options, 'with_%s_incdir' % secattr, v)
pass
if cfg.has_option(section, 'libdir'):
v = cfg.get(section, 'libdir')
v = _as_string(v)
setattr(ctx.options, 'with_%s_libdir' % secattr, v)
pass
pass
# pkg-level config
for section in cfg.sections():
if section.startswith('hwaf-'):
continue
#print "*** section=[%s]..." % section
if not hasattr(ctx.options, 'with_%s' % section):
continue
v = getattr(ctx.options, 'with_%s' % section)
#print "*** section=[%s]... >> %s" % (section, v)
if not (v == None):
# user provided a value from command-line
continue
if cfg.has_option(section, 'path'):
v = cfg.get(section, 'path')
v = _as_string(v)
setattr(ctx.options, 'with_%s' % section, v)
pass
if cfg.has_option(section, 'incdir'):
v = cfg.get(section, 'incdir')
v = _as_string(v)
setattr(ctx.options, 'with_%s_incdir' % section, v)
pass
if cfg.has_option(section, 'libdir'):
v = cfg.get(section, 'libdir')
v = _as_string(v)
setattr(ctx.options, 'with_%s_libdir' % section, v)
pass
pass
return True
### ---------------------------------------------------------------------------
@conf
def copy_uselib_defs(ctx, dst, src):
for n in ('LIB', 'LIBPATH',
'STLIB', 'STLIBPATH',
'LINKFLAGS', 'RPATH',
'CFLAGS', 'CXXFLAGS',
'DFLAGS',
'INCLUDES',
'CXXDEPS', 'CCDEPS', 'LINKDEPS',
'DEFINES',
'FRAMEWORK', 'FRAMEWORKPATH',
'ARCH'):
ctx.env['%s_%s' % (n,dst)] = ctx.env['%s_%s' % (n,src)]
ctx.env.append_unique('DEFINES', 'HAVE_%s=1' % dst.upper())
return
### ---------------------------------------------------------------------------
@conf
def define_uselib(self, name, libpath, libname, incpath, incname):
"""
define_uselib creates the proper uselib variables based on the ``name``
with the correct library-path ``libpath``, library name ``libname``,
include-path ``incpath`` and header file ``incname``
"""
ctx = self
n = name
if libpath:
libpath = waflib.Utils.to_list(libpath)
ctx.env['LIBPATH_%s'%n] = libpath
pass
if libname:
libname = waflib.Utils.to_list(libname)
ctx.env['LIB_%s'%n] = libname
pass
if incpath:
incpath = waflib.Utils.to_list(incpath)
ctx.env['INCLUDES_%s'%n] = incpath
pass
NAME = name.upper().replace('-','_')
ctx.env.append_unique('DEFINES', 'HAVE_%s=1' % NAME)
return
### ------------------------------------------------------------------------
@conf
def declare_runtime_env(self, k):
'''
declare_runtime_env register a particular key ``k`` as the name of an
environment variable the project will need at runtime.
'''
if not self.env.HWAF_RUNTIME_ENVVARS:
self.env.HWAF_RUNTIME_ENVVARS = []
pass
if msg.verbose and os.getenv('HWAF_DEBUG_RUNTIME', None):
v = self.env[k]
if v and isinstance(v, (list,tuple)) and len(v) != 1:
raise KeyError("env[%s]=%s" % (k,v))
self.env.append_unique('HWAF_RUNTIME_ENVVARS', k)
return
### ------------------------------------------------------------------------
@conf
def declare_runtime_alias(self, dst, src):
'''
declare_runtime_alias declares an alias, alive at runtime.
ex:
ctx.declare_runtime_alias("athena", "athena.py")
ctx.declare_runtime_alias("ll", "ls -l")
'''
if not self.env.HWAF_RUNTIME_ALIASES:
self.env.HWAF_RUNTIME_ALIASES = []
pass
if msg.verbose:
for alias in self.env.HWAF_RUNTIME_ALIASES:
k,v = alias
if k == dst:
raise KeyError("the alias [%s] was already defined (to=%r)" % (k,v))
self.env.append_unique('HWAF_RUNTIME_ALIASES', [(dst, src)])
return
### ------------------------------------------------------------------------
@conf
def hwaf_declare_macro(self, name, value):
'''
hwaf_declare_macro declares a macro with name `name` and value `value`
@param name: a string
@param value: a string or a list of 1-dict {hwaf-tag:"value"}
hwaf-tag can be a simple string or a tuple of strings.
'''
value = self._hwaf_select_value(value)
if self.env[name]:
old_value = self.hwaf_subst_vars(self.env[name])
new_value = self.hwaf_subst_vars(value)
if old_value != new_value:
raise waflib.Errors.WafError(
"package [%s] re-declares pre-existing macro [%s]\n old-value=%r\n new-value=%r"
% (self.path.name, name, old_value, new_value)
)
self.env[name] = value
return
### ------------------------------------------------------------------------
@conf
def hwaf_macro_prepend(self, name, value):
'''
hwaf_macro_prepend prepends a value `value` to a macro named `name`
@param name: a string
@param value: a string or a list of 1-dict {hwaf-tag:"value"}
hwaf-tag can be a simple string or a tuple of strings.
'''
value = self._hwaf_select_value(value)
if value:
self.env.prepend_value(name, value)
return
### ------------------------------------------------------------------------
@conf
def hwaf_macro_append(self, name, value):
'''
hwaf_macro_append appends a value `value` to a macro named `name`
@param name: a string
@param value: a string or a list of 1-dict {hwaf-tag:"value"}
hwaf-tag can be a simple string or a tuple of strings.
'''
value = self._hwaf_select_value(value)
if value:
self.env.append_value(name, value)
return
### ------------------------------------------------------------------------
@conf
def hwaf_macro_remove(self, name, value):
'''
hwaf_macro_remove removes a value `value` to a macro named `name`
@param name: a string
@param value: a string or a list of 1-dict {hwaf-tag:"value"}
hwaf-tag can be a simple string or a tuple of strings.
'''
## FIXME
return
### ------------------------------------------------------------------------
@conf
def hwaf_declare_tag(self, name, content):
'''
hwaf_declare_tag declares a tag with name `name` and `content`,
a list of strings defining the associated content of that tag.
@param name: a string
@param content: a string or a list of strings
e.x:
ctx.hwaf_declare_tag("x86_64-slc6-gcc46-dbg",
content=["x86_64", "x86_64-slc6", "linux", "slc6", "gcc"])
'''
self.env['HWAF_TAGS'][name] = content
if name in self.env['HWAF_ACTIVE_TAGS']:
#msg.debug("re-applying tag [%s]..." % name)
#msg.debug("re-applying tag [%s] - content: %s" % (name,content))
self.hwaf_apply_tag(name)
return
### ------------------------------------------------------------------------
@conf
def hwaf_apply_tag(self, *tag):
'''
hwaf_apply_tag activates a tag with name `tag`
@param name: a string or a list of strings
e.x:
ctx.hwaf_apply_tag("x86_64-slc6-gcc46-dbg")
ctx.hwaf_apply_tag("tag1 tag2")
ctx.hwaf_apply_tag("tag1", "tag2")
'''
if isinstance(tag, type("")):
tag = waflib.Utils.to_list(tag)
for name in tag:
try:
#msg.debug("applying tag [%s]..." % name)
content = self.env['HWAF_TAGS'][name]
self.env.append_unique('HWAF_ACTIVE_TAGS', [name])
# FIXME: recursively apply_tag for content as well ?
# but then, a declare_tag for each tag content is needed!
# for tag in content:
# if not tag in self.env.HWAF_ACTIVE_TAGS:
# self.hwaf_apply_tag(tag)
self.env.append_unique('HWAF_ACTIVE_TAGS', content)
#msg.debug("applying tag content: %s..." % (content,))
#msg.debug("applying tag [%s]... [done]" % name)
except KeyError:
raise waflib.Errors.WafError("package [%s]: no such tag (%s) in HWAF_TAGS" % (self.path.name, name))
pass
pass
### ------------------------------------------------------------------------
@conf
def _hwaf_select_value(self, value):
'''
hwaf_select_value selects a value from the dict `value` corresponding
to the set of currently live tags.
'''
tags = self.env['HWAF_ACTIVE_TAGS']
default = None
for d in value:
v = list((k,v) for k,v in d.items())[0]
#msg.debug('list= %s' % (v,))
if isinstance(v[1], type("")):
if v[0] in tags:
return waflib.Utils.subst_vars(v[1], self.env)
if v[0] == "default":
default = v[1]
pass
else:
if v[0] in tags:
out = []
for o in v[1]:
out.append(waflib.Utils.subst_vars(o, self.env))
return out
if v[0] == "default":
default = v[1]
pass
pass
pass
#msg.debug('select default value: %s' % (value,))
if isinstance(default, type("")):
return waflib.Utils.subst_vars(default, self.env)
out = []
for o in default:
out.append(waflib.Utils.subst_vars(o, self.env))
return out
### ------------------------------------------------------------------------
@conf
def hwaf_declare_path(self, name, value):
'''
hwaf_declare_path declares a path `name` with value `value`
@param name: a string
@param value: a string or a list of 1-dict {hwaf-tag:"value"}
hwaf-tag can be a simple string or a tuple of strings.
'''
value = self._hwaf_select_value(value)
if self.env[name]:
old_value = self.hwaf_subst_vars(self.env[name])
new_value = self.hwaf_subst_vars(value)
if old_value != new_value:
raise waflib.Errors.WafError(
"package [%s] re-declares pre-existing path [%s]\n old-value=%r\n new-value=%r"
% (self.path.name, name, old_value, new_value)
)
self.env[name] = value
self.declare_runtime_env(name)
return
### ------------------------------------------------------------------------
@conf
def hwaf_path_prepend(self, name, value):
'''
hwaf_path_prepend prepends a value `value` to a path named `name`
@param name: a string
@param value: a string or a list of 1-dict {hwaf-tag:"value"}
hwaf-tag can be a simple string or a tuple of strings.
'''
value = self._hwaf_select_value(value)
self.env.prepend_value(name, value)
return
### ------------------------------------------------------------------------
@conf
def hwaf_path_append(self, name, value):
'''
hwaf_path_append appends a value `value` to a path named `name`
@param name: a string
@param value: a string or a list of 1-dict {hwaf-tag:"value"}
hwaf-tag can be a simple string or a tuple of strings.
'''
value = self._hwaf_select_value(value)
self.env.append_value(name, value)
return
### ------------------------------------------------------------------------
@conf
def hwaf_path_remove(self, name, value):
'''
hwaf_path_remove removes a value `value` to a path named `name`
@param name: a string
@param value: a string or a list of 1-dict {hwaf-tag:"value"}
hwaf-tag can be a simple string or a tuple of strings.
'''
remove = self._hwaf_select_value(value)
cur_val = waflib.Utils.to_list(self.env[name])
new_val = []
for x in cur_val:
## FIXME: what are the CMT semantics ?
if x == remove or remove in x:
continue
new_val.append(x)
pass
self.env[name] = new_val
return
### ------------------------------------------------------------------------
@conf
def hwaf_export_module(self, fname=WSCRIPT_FILE):
'''
hwaf_export_module registers the ``fname`` file for export.
it will be installed in the ${PREFIX}/share/hwaf directory to be picked
up by dependent projects.
'''
if not self.env.HWAF_MODULES:
self.env.HWAF_MODULES = []
pass
node = None
if osp.isabs(fname): node = self.root.find_or_declare(fname)
else: node = self.path.find_node(fname)
if not node: self.fatal("could not find [%s]" % fname)
#msg.info("::: exporting [%s]" % node.abspath())
self.env.append_unique('HWAF_MODULES', node.abspath())
### ------------------------------------------------------------------------
@conf
def _hwaf_load_fct(ctx, pkgname, fname):
import imp
node = ctx.path.find_node(fname)
if not node:
ctx.fatal(
"pkg [%s (dir=%s)]: file [%s] does not exist" %
(pkgname, ctx.path.path_from(ctx.pkgdir), fname)
)
name = node.abspath()
f = open(name, 'r')
mod_name = '.'.join(['__hwaf__']+pkgname.split('/')+f.name[:-3].split('/'))
mod = imp.load_source(mod_name, f.name, f)
f.close()
fun = getattr(mod, ctx.fun, None)
if fun:
fun(ctx)
pass
### ------------------------------------------------------------------------
@conf
def hwaf_subst_vars(self, value, env=None):
'''
hwaf_subst_vars recursively calls waflib.Utils.subst_vars on `value` as
long as a '${xxx}' variable is in the string
'''
if env is None: env=self.env
orig_value = value
i = 1024
while i > 0:
i -= 1
value = waflib.Utils.subst_vars(value, env)
if value.count('${') <= 0:
return value
self.fatal('package [%s] reached maximum recursive limit when resolving value %r' % orig_value)
return
### ------------------------------------------------------------------------
@conf
def _get_env_for_subproc(self, os_env_keys=None):
import os
#env = dict(os.environ)
#waf_env = dict(self.env)
#for k,v in waf_env.items():
env = dict(os.environ)
#env = dict(self.env)
if not os_env_keys:
os_env_keys = []
os_env_keys += self.env.HWAF_RUNTIME_ENVVARS
for k,v in dict(self.env).items():
if not k in os_env_keys:
try: del env[k]
except KeyError:pass
continue
v = self.env[k]
#print("-- %s %s %r" % (k, type(k), v))
if isinstance(v, (list,tuple)):
v = list(v)
for i,_ in enumerate(v):
if hasattr(v[i], 'abspath'):
v[i] = v[i].abspath()
else:
v[i] = str(v[i])
pass
pass
# handle xyzPATH variables (LD_LIBRARY_PATH, PYTHONPATH,...)
if k.lower().endswith('path'):
#print (">>> %s: %r" % (k,v))
env[k] = os.pathsep.join(v)
else:
env[k] = ' '.join(v)
else:
env[k] = str(v)
pass
pass
bld_area = self.env['BUILD_INSTALL_AREA']
if bld_area:
env['LD_LIBRARY_PATH'] = os.pathsep.join(
[os.path.join(bld_area,'lib')]
+waflib.Utils.to_list(self.env['LD_LIBRARY_PATH'])
+[os.environ.get('LD_LIBRARY_PATH','')])
env['PATH'] = os.pathsep.join(
[os.path.join(bld_area,'bin')]
+waflib.Utils.to_list(self.env['PATH'])
+[os.environ.get('PATH','')])
env['PYTHONPATH'] = os.pathsep.join(
[os.path.join(bld_area,'python')]
+waflib.Utils.to_list(self.env['PYTHONPATH'])
+[os.environ.get('PYTHONPATH','')])
if self.is_darwin():
env['DYLD_LIBRARY_PATH'] = os.pathsep.join(
[os.path.join(bld_area,'lib')]
+waflib.Utils.to_list(self.env['DYLD_LIBRARY_PATH'])
+[os.environ.get('DYLD_LIBRARY_PATH','')])
pass
else:
env['LD_LIBRARY_PATH'] = os.pathsep.join(
waflib.Utils.to_list(self.env['LD_LIBRARY_PATH'])
+[os.environ.get('LD_LIBRARY_PATH','')])
env['PATH'] = os.pathsep.join(
waflib.Utils.to_list(self.env['PATH'])
+[os.environ.get('PATH','')])
env['PYTHONPATH'] = os.pathsep.join(
waflib.Utils.to_list(self.env['PYTHONPATH'])
+[os.environ.get('PYTHONPATH','')])
if self.is_darwin():
env['DYLD_LIBRARY_PATH'] = os.pathsep.join(
waflib.Utils.to_list(self.env['DYLD_LIBRARY_PATH'])
+[os.environ.get('DYLD_LIBRARY_PATH','')])
pass
pass
if not self.is_windows():
env['CPPFLAGS'] = ' '.join('-D'+k for k in self.env['DEFINES'])
pass
for k in (#'CPPFLAGS',
'CFLAGS',
'CCFLAGS',
'CXXFLAGS',
'FCFLAGS',
'LINKFLAGS',
'SHLINKFLAGS',
'AR',
'ARFLAGS',
'CC',
'CXX',
'LINK_CC',
'LINK_CXX',
):
v = self.env.get_flat(k)
env[k] = str(v)
pass
env['SHLINKFLAGS'] += ' '+self.env.get_flat('LINKFLAGS_cshlib')
env['SHEXT'] = self.dso_ext()[1:]
for k,v in env.items():
if not isinstance(v, str):
raise KeyError("env[%s]=%s" % (k,v))
return env
### ------------------------------------------------------------------------
@conf
def _get_pkg_name(self):
pkg_name = self.hwaf_pkg_name(self.path)
return osp.basename(pkg_name)
### ------------------------------------------------------------------------
@conf
def _get_pkg_version_defines(self):
pkg_name = _get_pkg_name(self)
pkg_vers = "%s-XX-XX-XX" % pkg_name
pkg_defines = ['PACKAGE_VERSION="%s"' % pkg_vers,
'PACKAGE_VERSION_UQ=%s'% pkg_vers]
# first: try version.hwaf
version_hwaf = self.path.get_src().find_resource('version.hwaf')
if version_hwaf:
pkg_vers = version_hwaf.read().strip()
pkg_defines = ['PACKAGE_VERSION="%s"' % pkg_vers,
'PACKAGE_VERSION_UQ=%s'% pkg_vers]
return pkg_defines
# then: try cmt/version.cmt
cmt_dir_node = self.path.get_src().find_dir('cmt')
if not cmt_dir_node:
return pkg_defines
version_cmt = cmt_dir_node.find_resource('version.cmt')
if not version_cmt:
return pkg_defines
pkg_vers = version_cmt.read().strip()
pkg_defines = ['PACKAGE_VERSION="%s"' % pkg_vers,
'PACKAGE_VERSION_UQ=%s'% pkg_vers]
#msg.debug("*** %s %r" % (pkg_name, pkg_vers))
return pkg_defines
### ------------------------------------------------------------------------
import waflib.Build