blob: 2bbb8f608d393e05ea10fbad78191b91204f1edc [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:
Michael Wright5177da52012-05-25 15:58:33 -070045 logger.Log("Error: ANDROID_BUILD_TOP not defined. Please run "
46 "envsetup.sh and lunch/choosecombo")
The Android Open Source Project6ffae012009-03-18 17:39:43 -070047 raise errors.AbortError
48 return root_path
Nicolas Cataniaff096c12009-05-01 11:55:36 -070049
50
JP Abgrallf38107c2013-07-11 17:39:16 -070051def GetHostOutDir():
52 """Returns the full pathname of out/host/arch of the Android development tree.
53
54 Assumes build environment has been properly configured by envsetup &
55 lunch/choosecombo.
56
57 Returns:
58 the absolute file path of the Android host output directory.
59 Raises:
60 AbortError: if Android host output directory could not be found.
61 """
62 host_out_path = os.getenv("ANDROID_HOST_OUT")
63 if host_out_path is None:
64 logger.Log("Error: ANDROID_HOST_OUT not defined. Please run "
65 "envsetup.sh and lunch/choosecombo")
66 raise errors.AbortError
67 return host_out_path
68
69
JP Abgrallf38107c2013-07-11 17:39:16 -070070def GetOutDir():
71 """Returns the full pathname of the "out" of the Android development tree.
72
73 Assumes build environment has been properly configured by envsetup &
74 lunch/choosecombo.
75
76 Returns:
77 the absolute file path of the Android build output directory.
78 """
79 root_path = os.getenv("OUT_DIR")
80 if root_path is None:
81 root_path = os.path.join(GetTop(), "out")
82 return root_path
83
84
Nicolas Cataniaff096c12009-05-01 11:55:36 -070085def GetHostBin():
86 """Compute the full pathname to the host binary directory.
87
JP Abgrallf38107c2013-07-11 17:39:16 -070088 Typically $ANDROID_HOST_OUT/bin.
Nicolas Cataniaff096c12009-05-01 11:55:36 -070089
90 Assumes build environment has been properly configured by envsetup &
91 lunch/choosecombo.
92
93 Returns:
94 The absolute file path of the Android host binary directory.
95
96 Raises:
97 AbortError: if Android host binary directory could not be found.
98 """
JP Abgrallf38107c2013-07-11 17:39:16 -070099 path = os.path.join(GetHostOutDir(), "bin")
Nicolas Cataniaff096c12009-05-01 11:55:36 -0700100 if not os.path.exists(path):
101 logger.Log("Error: Host bin path could not be found %s" % path)
102 raise errors.AbortError
103 return path
104
105
106def GetProductOut():
107 """Returns the full pathname to the target/product directory.
108
109 Typically the value of the env variable $ANDROID_PRODUCT_OUT.
110
111 Assumes build environment has been properly configured by envsetup &
112 lunch/choosecombo.
113
114 Returns:
115 The absolute file path of the Android product directory.
116
117 Raises:
118 AbortError: if Android product directory could not be found.
119 """
120 path = os.getenv("ANDROID_PRODUCT_OUT")
121 if path is None:
Michael Wright5177da52012-05-25 15:58:33 -0700122 logger.Log("Error: ANDROID_PRODUCT_OUT not defined. Please run "
123 "envsetup.sh and lunch/choosecombo")
Nicolas Cataniaff096c12009-05-01 11:55:36 -0700124 raise errors.AbortError
125 return path
126
127
Tsu Chiang Chuangc137f5f2014-02-25 17:25:10 -0800128def GetTargetNativeTestPath():
129 """Returns the full pathname to target/product data/nativetest/ directory.
130
131 Assumes build environment has been properly configured by envsetup &
132 lunch/choosecombo.
133
134 Returns:
135 The absolute file path of the Android target native test directory.
136
137 Raises:
138 AbortError: if Android target native test directory could not be found.
139 """
140 path = os.path.join(GetProductOut(), "data", "nativetest")
141 if not os.path.exists(path):
142 logger.Log("Error: Target native test path could not be found")
143 raise errors.AbortError
144 return path
145
146
Nicolas Cataniaff096c12009-05-01 11:55:36 -0700147def GetTargetSystemBin():
148 """Returns the full pathname to the target/product system/bin directory.
149
150 Typically the value of the env variable $ANDROID_PRODUCT_OUT/system/bin
151
152 Assumes build environment has been properly configured by envsetup &
153 lunch/choosecombo.
154
155 Returns:
156 The absolute file path of the Android target system bin directory.
157
158 Raises:
159 AbortError: if Android target system bin directory could not be found.
160 """
161 path = os.path.join(GetProductOut(), "system", "bin")
162 if not os.path.exists(path):
163 logger.Log("Error: Target system bin path could not be found")
164 raise errors.AbortError
165 return path
Brett Chabot764d3fa2009-06-25 17:57:31 -0700166
167def GetHostLibraryPath():
168 """Returns the full pathname to the host java library output directory.
169
JP Abgrallf38107c2013-07-11 17:39:16 -0700170 Typically $ANDROID_HOST_OUT/framework.
Brett Chabot764d3fa2009-06-25 17:57:31 -0700171
172 Assumes build environment has been properly configured by envsetup &
173 lunch/choosecombo.
174
175 Returns:
176 The absolute file path of the Android host java library directory.
177
178 Raises:
179 AbortError: if Android host java library directory could not be found.
180 """
JP Abgrallf38107c2013-07-11 17:39:16 -0700181 path = os.path.join(GetHostOutDir(), "framework")
Brett Chabot764d3fa2009-06-25 17:57:31 -0700182 if not os.path.exists(path):
183 logger.Log("Error: Host library path could not be found %s" % path)
184 raise errors.AbortError
185 return path
186
187def GetTestAppPath():
188 """Returns the full pathname to the test app build output directory.
189
190 Typically $ANDROID_PRODUCT_OUT/data/app
191
192 Assumes build environment has been properly configured by envsetup &
193 lunch/choosecombo.
194
195 Returns:
196 The absolute file path of the Android test app build directory.
Brett Chabot764d3fa2009-06-25 17:57:31 -0700197 """
Brett Chabote0bf8162009-06-29 13:55:30 -0700198 return os.path.join(GetProductOut(), "data", "app")