3 # based on playground/evil in the waf svn tree
6 import Scripting
, Utils
, Options
, Logs
, Environment
, fnmatch
7 from Constants
import *
10 '''run a single build task'''
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()
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']:
26 s
= getattr(t
, attr
, [])
28 relpath
= k
.relpath_gen(cwd_node
)
29 if fnmatch
.fnmatch(relpath
, cmd
):
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
47 Scripting
.commands
= Options
.arg_line
[:]
49 while Scripting
.commands
:
50 x
= Scripting
.commands
.pop(0)
52 ini
= datetime
.datetime
.now()
54 fun
= Scripting
.configure
58 fun
= getattr(Utils
.g_module
, x
, None)
60 # this is the new addition on top of main from Scripting.py
65 ctx
= getattr(Utils
.g_module
, x
+ '_context', Utils
.Context
)()
67 if x
in ['init', 'shutdown', 'dist', 'distclean', 'distcheck']:
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
101 proj
= Environment
.Environment(Options
.lockfile
)
103 raise Utils
.WafError("Project not configured (run 'waf configure' first)")
105 bld
.load_dirs(proj
[SRCDIR
], proj
[BLDDIR
])
108 Logs
.info("Waf: Entering directory `%s'" % bld
.bldnode
.abspath())
109 bld
.add_subdirs([os
.path
.split(Utils
.g_module
.root_path
)[0]])