1# benchmark -- automated system for testing distcc correctness
2# and performance on various source trees.
3
4# Copyright (C) 2002, 2003 by Martin Pool
5# Copyright 2008 Google Inc.
6#
7# This program is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License
9# as published by the Free Software Foundation; either version 2
10# of the License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20# USA.
21
22# Tuples of (name, default, descr)
23all_actions = [('download', True, ''),
24               ('md5check', True, 'check file was downloaded correctly'),
25               ('sweep', True, 'remove build directory before unpacking'),
26               ('unpack', True, 'unpack source'),
27               ('configure', True, ''),
28               ('build', True, ''),
29               ('clean', True, 'run "make clean" or equivalent'),
30               ('scrub', False, 'remove build directory')]
31
32# Actions done on a per-project (rather than a per-build) basis
33project_actions = ('download', 'md5check')
34
35
36
37def action_help():
38    print "Actions:"
39    for action, default, descr in all_actions:
40        default_ch = default and '*' or ' '
41        print " %c  %-20s %s" % (default_ch, action, descr)
42    print " (* = on by default)"
43
44
45# Filter out only actions where 'default' is true
46default_actions = [a[0] for a in all_actions if a[1]]
47
48
49def parse_opt_actions(optarg):
50    opt_actions = optarg.split(',')
51    action_names = [a[0] for a in all_actions]
52    for oa in opt_actions:
53        if oa not in action_names:
54            raise ValueError, ("no such action: %s" % `oa`)
55    return opt_actions
56
57
58def remove_unnecessary_actions(opt_actions, force, did_download, did_configure):
59    """Given a list of actions (as a string), and a force value
60    (as described in the help text for benchmark.py), and a
61    bool indicating whether 'configure' was successfully run
62    for this build or not, return a new list which is the actions
63    to actually perform for this build.
64
65    Returns two lists: one that can be done on a per-project basis,
66    and one that has to be done on a per-build basis (as we build the
67    project with various different flags).
68    """
69
70    if force == 0 and did_configure and did_download:
71        remove = ('download', 'md5check', 'sweep', 'unpack', 'configure')
72    elif force <= 1 and did_download:
73        remove = ('download', )
74    else:
75        remove = ()
76
77    new_project_actions = [oa for oa in opt_actions
78                           if oa in project_actions and oa not in remove]
79    new_build_actions = [oa for oa in opt_actions
80                         if oa not in project_actions and oa not in remove]
81    return new_project_actions, new_build_actions
82