4 # Copyright 2008, The Android Open Source Project
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 """Contains utility functions for interacting with the Android build system."""
31 """Returns the full pathname of the "top" of the Android development tree.
33 Assumes build environment has been properly configured by envsetup &
37 the absolute file path of the Android build root.
40 AbortError: if Android build root could not be found.
42 # TODO: does this need to be reimplemented to be like gettop() in envsetup.sh
43 root_path = os.getenv("ANDROID_BUILD_TOP")
45 logger.Log("Error: ANDROID_BUILD_TOP not defined. Please run envsetup.sh")
46 raise errors.AbortError
51 """Identify the host os and arch.
54 The triple (HOST_OS, HOST_ARCH, HOST_OS-HOST_ARCH).
57 AbortError: If the os and/or arch could not be found.
59 command = ("CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core "
60 "make --no-print-directory -C \"%s\" -f build/core/config.mk "
61 "dumpvar-report_config") % GetTop()
63 # Use the shell b/c we set some env variables before the make command.
64 config = subprocess.Popen(command, stdout=subprocess.PIPE,
65 shell=True).communicate()[0]
66 host_os = re.search("HOST_OS=(\w+)", config).group(1)
67 host_arch = re.search("HOST_ARCH=(\w+)", config).group(1)
68 if not (host_os and host_arch):
69 logger.Log("Error: Could not get host's OS and/or ARCH")
70 raise errors.AbortError
71 return (host_os, host_arch, "%s-%s" % (host_os, host_arch))
75 """Compute the full pathname to the host binary directory.
77 Typically $ANDROID_BUILD_TOP/out/host/linux-x86/bin.
79 Assumes build environment has been properly configured by envsetup &
83 The absolute file path of the Android host binary directory.
86 AbortError: if Android host binary directory could not be found.
88 (_, _, os_arch) = GetHostOsArch()
89 path = os.path.join(GetTop(), "out", "host", os_arch, "bin")
90 if not os.path.exists(path):
91 logger.Log("Error: Host bin path could not be found %s" % path)
92 raise errors.AbortError
97 """Returns the full pathname to the target/product directory.
99 Typically the value of the env variable $ANDROID_PRODUCT_OUT.
101 Assumes build environment has been properly configured by envsetup &
105 The absolute file path of the Android product directory.
108 AbortError: if Android product directory could not be found.
110 path = os.getenv("ANDROID_PRODUCT_OUT")
112 logger.Log("Error: ANDROID_PRODUCT_OUT not defined. Please run envsetup.sh")
113 raise errors.AbortError
117 def GetTargetSystemBin():
118 """Returns the full pathname to the target/product system/bin directory.
120 Typically the value of the env variable $ANDROID_PRODUCT_OUT/system/bin
122 Assumes build environment has been properly configured by envsetup &
126 The absolute file path of the Android target system bin directory.
129 AbortError: if Android target system bin directory could not be found.
131 path = os.path.join(GetProductOut(), "system", "bin")
132 if not os.path.exists(path):
133 logger.Log("Error: Target system bin path could not be found")
134 raise errors.AbortError
137 def GetHostLibraryPath():
138 """Returns the full pathname to the host java library output directory.
140 Typically $ANDROID_BUILD_TOP/out/host/<host_os>/framework.
142 Assumes build environment has been properly configured by envsetup &
146 The absolute file path of the Android host java library directory.
149 AbortError: if Android host java library directory could not be found.
151 (_, _, os_arch) = GetHostOsArch()
152 path = os.path.join(GetTop(), "out", "host", os_arch, "framework")
153 if not os.path.exists(path):
154 logger.Log("Error: Host library path could not be found %s" % path)
155 raise errors.AbortError
158 def GetTestAppPath():
159 """Returns the full pathname to the test app build output directory.
161 Typically $ANDROID_PRODUCT_OUT/data/app
163 Assumes build environment has been properly configured by envsetup &
167 The absolute file path of the Android test app build directory.
169 return os.path.join(GetProductOut(), "data", "app")