Home | History | Annotate | Download | only in barcode_tools
      1 #!/usr/bin/env python
      2 # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3 #
      4 # Use of this source code is governed by a BSD-style license
      5 # that can be found in the LICENSE file in the root of the source
      6 # tree. An additional intellectual property rights grant can be found
      7 # in the file PATENTS.  All contributing project authors may
      8 # be found in the AUTHORS file in the root of the source tree.
      9 
     10 import os
     11 import subprocess
     12 import sys
     13 
     14 
     15 def run_ant_build_command(path_to_ant_build_file):
     16   """Tries to build the passed build file with ant."""
     17   ant_executable = 'ant'
     18   if sys.platform == 'win32':
     19     if os.getenv('ANT_HOME'):
     20       ant_executable = os.path.join(os.getenv('ANT_HOME'), 'bin', 'ant.bat')
     21     else:
     22       ant_executable = 'ant.bat'
     23   cmd = [ant_executable, '-buildfile', path_to_ant_build_file]
     24   try:
     25     process = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
     26     process.wait()
     27     if process.returncode != 0:
     28       print >> sys.stderr, 'Failed to execute: %s' % ' '.join(cmd)
     29     return process.returncode
     30   except subprocess.CalledProcessError as e:
     31     print >> sys.stderr, 'Failed to execute: %s.\nCause: %s' % (' '.join(cmd),
     32                                                                 e)
     33     return -1
     34 
     35 def _main():
     36   core_build = os.path.join('third_party', 'zxing', 'core', 'build.xml')
     37   run_ant_build_command(core_build)
     38 
     39   javase_build = os.path.join('third_party', 'zxing', 'javase', 'build.xml')
     40   return run_ant_build_command(javase_build)
     41 
     42 
     43 if __name__ == '__main__':
     44   sys.exit(_main())
     45