1# Copyright (C) 2023 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import os 16import pathlib 17 18DEFAULT_REPORT_DIR = "benchmarks" 19 20def get_root(): 21 top_dir = os.environ.get("ANDROID_BUILD_TOP") 22 d = pathlib.Path.cwd() 23 # with cog, someone may have a new workspace and new source tree top, but 24 # not run lunch yet, resulting in a misleading ANDROID_BUILD_TOP value 25 if top_dir and d.is_relative_to(top_dir): 26 return pathlib.Path(top_dir).resolve() 27 while True: 28 if d.joinpath("build", "soong", "soong_ui.bash").exists(): 29 return d.resolve().absolute() 30 d = d.parent 31 if d == pathlib.Path("/"): 32 return None 33 34def get_dist_dir(): 35 dist_dir = os.getenv("DIST_DIR") 36 if dist_dir: 37 return pathlib.Path(dist_dir).resolve() 38 return get_out_dir().joinpath("dist") 39 40def get_out_dir(): 41 out_dir = os.getenv("OUT_DIR") 42 if not out_dir: 43 out_dir = "out" 44 return pathlib.Path(out_dir).resolve() 45