1c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#!/usr/bin/env python 2c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# 3c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# Copyright 2013 The Chromium Authors. All rights reserved. 4c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be 5c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# found in the LICENSE file. 63551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)"""An Ant wrapper that suppresses useless Ant output. 8c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 9c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)Ant build scripts output "BUILD SUCCESSFUL" and build timing at the end of 10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)every build. In the Android build, this just adds a lot of useless noise to the 11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)build output. This script forwards its arguments to ant, and prints Ant's 12c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)output up until the BUILD SUCCESSFUL line. 13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)Also, when a command fails, this script will re-run that ant command with the 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)'-verbose' argument so that the failure is easier to debug. 16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)""" 17c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)import sys 19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)import traceback 20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)from util import build_utils 22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 23c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)def main(argv): 25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) try: 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) args = argv[1:] 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) stdout = build_utils.CheckOutput(['ant'] + args) 2823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) except build_utils.CalledProcessError: 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) # It is very difficult to diagnose ant failures without the '-verbose' 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) # argument. So, when an ant command fails, re-run it with '-verbose' so that 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) # the cause of the failure is easier to identify. 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) verbose_args = ['-verbose'] + [a for a in argv[1:] if a != '-quiet'] 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) try: 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) stdout = build_utils.CheckOutput(['ant'] + verbose_args) 3523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) except build_utils.CalledProcessError: 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) traceback.print_exc() 37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) sys.exit(1) 38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) # If this did sys.exit(1), building again would succeed (which would be 40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) # awkward). Instead, just print a big warning. 4123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) build_utils.PrintBigWarning( 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 'This is unexpected. `ant ' + ' '.join(args) + '` failed.' + 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 'But, running `ant ' + ' '.join(verbose_args) + '` passed.') 44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) stdout = stdout.strip().split('\n') 46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for line in stdout: 47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if line.strip() == 'BUILD SUCCESSFUL': 48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) break 49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) print line 50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 52c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)if __name__ == '__main__': 53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) sys.exit(main(sys.argv)) 54