Convert mtime from a time_t to a struct timespec.
[Samba.git] / buildtools / wafsamba / samba_wildcard.py
blob5bf12672a950e8b3525facf143a9031b6315bc46
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 *
8 from samba_utils import *
10 def run_task(t, k):
11 '''run a single build task'''
12 ret = t.run()
13 if ret:
14 raise Utils.WafError("Failed to build %s: %u" % (k, ret))
17 def run_named_build_task(cmd):
18 '''run a named build task, matching the cmd name using fnmatch
19 wildcards against inputs and outputs of all build tasks'''
20 bld = fake_build_environment()
21 found = False
22 cwd_node = bld.root.find_dir(os.getcwd())
23 top_node = bld.root.find_dir(bld.srcnode.abspath())
25 cmd = os.path.normpath(cmd)
27 # cope with builds of bin/*/*
28 if os.path.islink(cmd):
29 cmd = os_path_relpath(os.readlink(cmd), os.getcwd())
31 if cmd[0:12] == "bin/default/":
32 cmd = cmd[12:]
34 for g in bld.task_manager.groups:
35 for attr in ['outputs', 'inputs']:
36 for t in g.tasks:
37 s = getattr(t, attr, [])
38 for k in s:
39 relpath1 = k.relpath_gen(cwd_node)
40 relpath2 = k.relpath_gen(top_node)
41 if (fnmatch.fnmatch(relpath1, cmd) or
42 fnmatch.fnmatch(relpath2, cmd)):
43 t.position = [0,0]
44 print(t.display())
45 run_task(t, k)
46 found = True
49 if not found:
50 raise Utils.WafError("Unable to find build target matching %s" % cmd)
54 def wildcard_main(missing_cmd_fn):
55 '''this replaces main from Scripting, allowing us to override the
56 behaviour for unknown commands
58 If a unknown command is found, then missing_cmd_fn() is called with
59 the name of the requested command
60 '''
61 Scripting.commands = Options.arg_line[:]
63 while Scripting.commands:
64 x = Scripting.commands.pop(0)
66 ini = datetime.datetime.now()
67 if x == 'configure':
68 fun = Scripting.configure
69 elif x == 'build':
70 fun = Scripting.build
71 else:
72 fun = getattr(Utils.g_module, x, None)
74 # this is the new addition on top of main from Scripting.py
75 if not fun:
76 missing_cmd_fn(x)
77 break
79 ctx = getattr(Utils.g_module, x + '_context', Utils.Context)()
81 if x in ['init', 'shutdown', 'dist', 'distclean', 'distcheck']:
82 try:
83 fun(ctx)
84 except TypeError:
85 fun()
86 else:
87 fun(ctx)
89 ela = ''
90 if not Options.options.progress_bar:
91 ela = ' (%s)' % Utils.get_elapsed_time(ini)
93 if x != 'init' and x != 'shutdown':
94 Logs.info('%r finished successfully%s' % (x, ela))
96 if not Scripting.commands and x != 'shutdown':
97 Scripting.commands.append('shutdown')
102 def fake_build_environment():
103 """create all the tasks for the project, but do not run the build
104 return the build context in use"""
105 bld = getattr(Utils.g_module, 'build_context', Utils.Context)()
106 bld = Scripting.check_configured(bld)
108 Options.commands['install'] = False
109 Options.commands['uninstall'] = False
110 Options.is_install = False
112 bld.is_install = 0 # False
114 try:
115 proj = Environment.Environment(Options.lockfile)
116 except IOError:
117 raise Utils.WafError("Project not configured (run 'waf configure' first)")
119 bld.load_dirs(proj[SRCDIR], proj[BLDDIR])
120 bld.load_envs()
122 Logs.info("Waf: Entering directory `%s'" % bld.bldnode.abspath())
123 bld.add_subdirs([os.path.split(Utils.g_module.root_path)[0]])
125 bld.pre_build()
126 bld.flush()
127 return bld