Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / build / toolchain / android / find_android_compiler.py
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 # This script locates the Android compilers given the bin directory of the
6 # android toolchain.
7
8 import glob
9 import subprocess
10 import sys
11
12 if len(sys.argv) != 2:
13   print "Error: expecting one argument of the android toolchain dir."
14   sys.exit(1)
15
16 # TODO(brettw) this logic seems like a bad idea. It was copied from
17 # common.gypi. It seems like the toolchain should just know the name given the
18 # current platform rather than having to rely on glob.
19 android_toolchain = sys.argv[1]
20 cc = glob.glob(android_toolchain + "/*-gcc")
21 cxx = glob.glob(android_toolchain + "/*-g++")
22
23 # We tolerate "no matches." In the Android AOSP WebView build, it runs this
24 # logic and the directory doesn't exist, giving no matches. But that build runs
25 # GYP to generate Android Makefiles which specify the compiler separately. So
26 # all we need to do in this case is ignore the error and continue with empty
27 # target compilers.
28 if len(cc) == 0:
29   cc = [""]
30 if len(cxx) == 0:
31   cxx = [""]
32 if len(cc) != 1 or len(cxx) != 1:
33   print "More than one matching compiler."
34   sys.exit(1)
35
36 # Get the host compilers from the current path.
37 which_gcc = subprocess.check_output(["which gcc"], shell=True).strip()
38 which_gxx = subprocess.check_output(["which g++"], shell=True).strip()
39
40 print ('["' + cc[0] + '","' + cxx[0] + '","' + which_gcc + '","' +
41        which_gxx + '"]')