The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 1 | #!/usr/bin/python2.4 |
| 2 | # |
| 3 | # |
| 4 | # Copyright 2008, The Android Open Source Project |
| 5 | # |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 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 |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 9 | # |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 11 | # |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 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 |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 16 | # limitations under the License. |
| 17 | |
| 18 | """Contains utility functions for interacting with the Android build system.""" |
| 19 | |
| 20 | # Python imports |
| 21 | import os |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 22 | import re |
| 23 | import subprocess |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 24 | |
| 25 | # local imports |
| 26 | import errors |
| 27 | import logger |
| 28 | |
| 29 | |
| 30 | def 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 Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 43 | root_path = os.getenv("ANDROID_BUILD_TOP") |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 44 | if root_path is None: |
Michael Wright | 5177da5 | 2012-05-25 15:58:33 -0700 | [diff] [blame] | 45 | logger.Log("Error: ANDROID_BUILD_TOP not defined. Please run " |
| 46 | "envsetup.sh and lunch/choosecombo") |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 47 | raise errors.AbortError |
| 48 | return root_path |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 49 | |
| 50 | |
JP Abgrall | f38107c | 2013-07-11 17:39:16 -0700 | [diff] [blame] | 51 | def 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 Abgrall | f38107c | 2013-07-11 17:39:16 -0700 | [diff] [blame] | 70 | def 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 Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 85 | def GetHostBin(): |
| 86 | """Compute the full pathname to the host binary directory. |
| 87 | |
JP Abgrall | f38107c | 2013-07-11 17:39:16 -0700 | [diff] [blame] | 88 | Typically $ANDROID_HOST_OUT/bin. |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 89 | |
| 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 Abgrall | f38107c | 2013-07-11 17:39:16 -0700 | [diff] [blame] | 99 | path = os.path.join(GetHostOutDir(), "bin") |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 100 | 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 | |
| 106 | def 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 Wright | 5177da5 | 2012-05-25 15:58:33 -0700 | [diff] [blame] | 122 | logger.Log("Error: ANDROID_PRODUCT_OUT not defined. Please run " |
| 123 | "envsetup.sh and lunch/choosecombo") |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 124 | raise errors.AbortError |
| 125 | return path |
| 126 | |
| 127 | |
Tsu Chiang Chuang | c137f5f | 2014-02-25 17:25:10 -0800 | [diff] [blame] | 128 | def 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 Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 147 | def 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 Chabot | 764d3fa | 2009-06-25 17:57:31 -0700 | [diff] [blame] | 166 | |
| 167 | def GetHostLibraryPath(): |
| 168 | """Returns the full pathname to the host java library output directory. |
| 169 | |
JP Abgrall | f38107c | 2013-07-11 17:39:16 -0700 | [diff] [blame] | 170 | Typically $ANDROID_HOST_OUT/framework. |
Brett Chabot | 764d3fa | 2009-06-25 17:57:31 -0700 | [diff] [blame] | 171 | |
| 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 Abgrall | f38107c | 2013-07-11 17:39:16 -0700 | [diff] [blame] | 181 | path = os.path.join(GetHostOutDir(), "framework") |
Brett Chabot | 764d3fa | 2009-06-25 17:57:31 -0700 | [diff] [blame] | 182 | 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 | |
| 187 | def 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 Chabot | 764d3fa | 2009-06-25 17:57:31 -0700 | [diff] [blame] | 197 | """ |
Brett Chabot | e0bf816 | 2009-06-29 13:55:30 -0700 | [diff] [blame] | 198 | return os.path.join(GetProductOut(), "data", "app") |