3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 """An Ant wrapper that suppresses useless Ant output.
9 Ant build scripts output "BUILD SUCCESSFUL" and build timing at the end of
10 every build. In the Android build, this just adds a lot of useless noise to the
11 build output. This script forwards its arguments to ant, and prints Ant's
12 output up until the BUILD SUCCESSFUL line.
14 Also, when a command fails, this script will re-run that ant command with the
15 '-verbose' argument so that the failure is easier to debug.
22 from util
import build_utils
26 option_parser
= optparse
.OptionParser()
27 build_utils
.AddDepfileOption(option_parser
)
28 options
, args
= option_parser
.parse_args(argv
[1:])
31 stdout
= build_utils
.CheckOutput(['ant'] + args
)
32 except build_utils
.CalledProcessError
:
33 # It is very difficult to diagnose ant failures without the '-verbose'
34 # argument. So, when an ant command fails, re-run it with '-verbose' so that
35 # the cause of the failure is easier to identify.
36 verbose_args
= ['-verbose'] + [a
for a
in args
if a
!= '-quiet']
38 stdout
= build_utils
.CheckOutput(['ant'] + verbose_args
)
39 except build_utils
.CalledProcessError
:
43 # If this did sys.exit(1), building again would succeed (which would be
44 # awkward). Instead, just print a big warning.
45 build_utils
.PrintBigWarning(
46 'This is unexpected. `ant ' + ' '.join(args
) + '` failed.' +
47 'But, running `ant ' + ' '.join(verbose_args
) + '` passed.')
49 stdout
= stdout
.strip().split('\n')
51 if line
.strip() == 'BUILD SUCCESSFUL':
56 assert '-buildfile' in args
57 ant_buildfile
= args
[args
.index('-buildfile') + 1]
59 build_utils
.WriteDepfile(
61 [ant_buildfile
] + build_utils
.GetPythonDependencies())
64 if __name__
== '__main__':
65 sys
.exit(main(sys
.argv
))