1# 2# Copyright 2020 - The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16"""Common functions shared between the scripts.""" 17 18import os 19 20 21def android_repository_root(): 22 """Returns the root of the tree.""" 23 if 'ANDROID_BUILD_TOP' not in os.environ: 24 raise Exception('Environment variable ANDROID_BUILD_TOP not set') 25 return os.environ['ANDROID_BUILD_TOP'] 26 27 28def printable_path(filename): 29 """Returns the filename relative to the current dir, if it's under it.""" 30 relative_path = os.path.relpath(filename) 31 if not relative_path.startswith('../'): 32 return relative_path 33 else: 34 return filename 35