build: strip -single_module when doing bundle on mac OS X
[Samba.git] / buildtools / wafsamba / samba_wildcard.py
blobecf3498c85be48b7fa97f6ae9625dcabba98aa83
1 #! /usr/bin/env python
3 # based on playground/evil in the waf svn tree
5 import os, datetime
6 import Scripting, Utils, Options, Logs, Environment, fnmatch
7 from Constants import *
9 def run_task(t, k):
10 '''run a single build task'''
11 ret = t.run()
12 if ret:
13 raise Utils.WafError("Failed to build %s: %u" % (k, ret))
16 def run_named_build_task(cmd):
17 '''run a named build task, matching the cmd name using fnmatch
18 wildcards against inputs and outputs of all build tasks'''
19 bld = fake_build_environment()
20 found = False
21 cwd_node = bld.root.find_dir(os.getcwd())
22 cmd = os.path.normpath(cmd)
23 for g in bld.task_manager.groups:
24 for attr in ['outputs', 'inputs']:
25 for t in g.tasks:
26 s = getattr(t, attr, [])
27 for k in s:
28 relpath = k.relpath_gen(cwd_node)
29 if fnmatch.fnmatch(relpath, cmd):
30 t.position= [0,0]
31 print(t.display())
32 run_task(t, k)
33 return
35 if not found:
36 raise Utils.WafError("Unable to find build target matching %s" % cmd)
40 def wildcard_main(missing_cmd_fn):
41 '''this replaces main from Scripting, allowing us to override the
42 behaviour for unknown commands
44 If a unknown command is found, then missing_cmd_fn() is called with
45 the name of the requested command
46 '''
47 Scripting.commands = Options.arg_line[:]
49 while Scripting.commands:
50 x = Scripting.commands.pop(0)
52 ini = datetime.datetime.now()
53 if x == 'configure':
54 fun = Scripting.configure
55 elif x == 'build':
56 fun = Scripting.build
57 else:
58 fun = getattr(Utils.g_module, x, None)
60 # this is the new addition on top of main from Scripting.py
61 if not fun:
62 missing_cmd_fn(x)
63 break
65 ctx = getattr(Utils.g_module, x + '_context', Utils.Context)()
67 if x in ['init', 'shutdown', 'dist', 'distclean', 'distcheck']:
68 try:
69 fun(ctx)
70 except TypeError:
71 fun()
72 else:
73 fun(ctx)
75 ela = ''
76 if not Options.options.progress_bar:
77 ela = ' (%s)' % Utils.get_elapsed_time(ini)
79 if x != 'init' and x != 'shutdown':
80 Logs.info('%r finished successfully%s' % (x, ela))
82 if not Scripting.commands and x != 'shutdown':
83 Scripting.commands.append('shutdown')
88 def fake_build_environment():
89 """create all the tasks for the project, but do not run the build
90 return the build context in use"""
91 bld = getattr(Utils.g_module, 'build_context', Utils.Context)()
92 bld = Scripting.check_configured(bld)
94 Options.commands['install'] = False
95 Options.commands['uninstall'] = False
96 Options.is_install = False
98 bld.is_install = 0 # False
100 try:
101 proj = Environment.Environment(Options.lockfile)
102 except IOError:
103 raise Utils.WafError("Project not configured (run 'waf configure' first)")
105 bld.load_dirs(proj[SRCDIR], proj[BLDDIR])
106 bld.load_envs()
108 Logs.info("Waf: Entering directory `%s'" % bld.bldnode.abspath())
109 bld.add_subdirs([os.path.split(Utils.g_module.root_path)[0]])
111 bld.pre_build()
112 bld.flush()
113 return bld