blob: 584ef5279cb8aead02cf81bc0b28381c1b1bff70 [file] [log] [blame]
The Android Open Source Project6ffae012009-03-18 17:39:43 -07001#!/usr/bin/python2.4
2#
3#
4# Copyright 2008, The Android Open Source Project
5#
Nicolas Cataniaff096c12009-05-01 11:55:36 -07006# 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
The Android Open Source Project6ffae012009-03-18 17:39:43 -07009#
Nicolas Cataniaff096c12009-05-01 11:55:36 -070010# http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project6ffae012009-03-18 17:39:43 -070011#
Nicolas Cataniaff096c12009-05-01 11:55:36 -070012# 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
The Android Open Source Project6ffae012009-03-18 17:39:43 -070016# limitations under the License.
17
18"""Contains utility functions for interacting with the Android build system."""
19
20# Python imports
21import os
Nicolas Cataniaff096c12009-05-01 11:55:36 -070022import re
23import subprocess
The Android Open Source Project6ffae012009-03-18 17:39:43 -070024
25# local imports
26import errors
27import logger
28
29
30def GetTop():
31 """Returns the full pathname of the "top" of the Android development tree.
32
33 Assumes build environment has been properly configured by envsetup &
34 lunch/choosecombo.
35
36 Returns:
37 the absolute file path of the Android build root.
38
39 Raises:
40 AbortError: if Android build root could not be found.
41 """
42 # TODO: does this need to be reimplemented to be like gettop() in envsetup.sh
Nicolas Cataniaff096c12009-05-01 11:55:36 -070043 root_path = os.getenv("ANDROID_BUILD_TOP")
The Android Open Source Project6ffae012009-03-18 17:39:43 -070044 if root_path is None:
Nicolas Cataniaff096c12009-05-01 11:55:36 -070045 logger.Log("Error: ANDROID_BUILD_TOP not defined. Please run envsetup.sh")
The Android Open Source Project6ffae012009-03-18 17:39:43 -070046 raise errors.AbortError
47 return root_path
Nicolas Cataniaff096c12009-05-01 11:55:36 -070048
49
50def GetHostOsArch():
51 """Identify the host os and arch.
52
53 Returns:
54 The triple (HOST_OS, HOST_ARCH, HOST_OS-HOST_ARCH).
55
56 Raises:
57 AbortError: If the os and/or arch could not be found.
58 """
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()
62
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))
72
73
74def GetHostBin():
75 """Compute the full pathname to the host binary directory.
76
77 Typically $ANDROID_BUILD_TOP/out/host/linux-x86/bin.
78
79 Assumes build environment has been properly configured by envsetup &
80 lunch/choosecombo.
81
82 Returns:
83 The absolute file path of the Android host binary directory.
84
85 Raises:
86 AbortError: if Android host binary directory could not be found.
87 """
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
93 return path
94
95
96def GetProductOut():
97 """Returns the full pathname to the target/product directory.
98
99 Typically the value of the env variable $ANDROID_PRODUCT_OUT.
100
101 Assumes build environment has been properly configured by envsetup &
102 lunch/choosecombo.
103
104 Returns:
105 The absolute file path of the Android product directory.
106
107 Raises:
108 AbortError: if Android product directory could not be found.
109 """
110 path = os.getenv("ANDROID_PRODUCT_OUT")
111 if path is None:
112 logger.Log("Error: ANDROID_PRODUCT_OUT not defined. Please run envsetup.sh")
113 raise errors.AbortError
114 return path
115
116
117def GetTargetSystemBin():
118 """Returns the full pathname to the target/product system/bin directory.
119
120 Typically the value of the env variable $ANDROID_PRODUCT_OUT/system/bin
121
122 Assumes build environment has been properly configured by envsetup &
123 lunch/choosecombo.
124
125 Returns:
126 The absolute file path of the Android target system bin directory.
127
128 Raises:
129 AbortError: if Android target system bin directory could not be found.
130 """
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
135 return path
Brett Chabot764d3fa2009-06-25 17:57:31 -0700136
137def GetHostLibraryPath():
138 """Returns the full pathname to the host java library output directory.
139
140 Typically $ANDROID_BUILD_TOP/out/host/<host_os>/framework.
141
142 Assumes build environment has been properly configured by envsetup &
143 lunch/choosecombo.
144
145 Returns:
146 The absolute file path of the Android host java library directory.
147
148 Raises:
149 AbortError: if Android host java library directory could not be found.
150 """
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
156 return path
157
158def GetTestAppPath():
159 """Returns the full pathname to the test app build output directory.
160
161 Typically $ANDROID_PRODUCT_OUT/data/app
162
163 Assumes build environment has been properly configured by envsetup &
164 lunch/choosecombo.
165
166 Returns:
167 The absolute file path of the Android test app build directory.
Brett Chabot764d3fa2009-06-25 17:57:31 -0700168 """
Brett Chabote0bf8162009-06-29 13:55:30 -0700169 return os.path.join(GetProductOut(), "data", "app")