1*9e94795aSAndroid Build Coastguard Worker# Copyright 2024, The Android Open Source Project 2*9e94795aSAndroid Build Coastguard Worker# 3*9e94795aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 4*9e94795aSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 5*9e94795aSAndroid Build Coastguard Worker# You may obtain a copy of the License at 6*9e94795aSAndroid Build Coastguard Worker# 7*9e94795aSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 8*9e94795aSAndroid Build Coastguard Worker# 9*9e94795aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*9e94795aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 11*9e94795aSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*9e94795aSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 13*9e94795aSAndroid Build Coastguard Worker# limitations under the License. 14*9e94795aSAndroid Build Coastguard Worker 15*9e94795aSAndroid Build Coastguard Worker"""Utilities for interacting with buildbot, with a simulation in a local environment""" 16*9e94795aSAndroid Build Coastguard Worker 17*9e94795aSAndroid Build Coastguard Workerimport os 18*9e94795aSAndroid Build Coastguard Workerimport sys 19*9e94795aSAndroid Build Coastguard Worker 20*9e94795aSAndroid Build Coastguard Worker# Check that the script is running from the root of the tree. Prevents subtle 21*9e94795aSAndroid Build Coastguard Worker# errors later, and CI always runs from the root of the tree. 22*9e94795aSAndroid Build Coastguard Workerif not os.path.exists("build/make/ci/buildbot.py"): 23*9e94795aSAndroid Build Coastguard Worker raise Exception("CI script must be run from the root of the tree instead of: " 24*9e94795aSAndroid Build Coastguard Worker + os.getcwd()) 25*9e94795aSAndroid Build Coastguard Worker 26*9e94795aSAndroid Build Coastguard Worker# Check that we are using the hermetic interpreter 27*9e94795aSAndroid Build Coastguard Workerif "prebuilts/build-tools/" not in sys.executable: 28*9e94795aSAndroid Build Coastguard Worker raise Exception("CI script must be run using the hermetic interpreter from " 29*9e94795aSAndroid Build Coastguard Worker + "prebuilts/build-tools instead of: " + sys.executable) 30*9e94795aSAndroid Build Coastguard Worker 31*9e94795aSAndroid Build Coastguard Worker 32*9e94795aSAndroid Build Coastguard Workerdef OutDir(): 33*9e94795aSAndroid Build Coastguard Worker "Get the out directory. Will create it if needed." 34*9e94795aSAndroid Build Coastguard Worker result = os.environ.get("OUT_DIR", "out") 35*9e94795aSAndroid Build Coastguard Worker os.makedirs(result, exist_ok=True) 36*9e94795aSAndroid Build Coastguard Worker return result 37*9e94795aSAndroid Build Coastguard Worker 38*9e94795aSAndroid Build Coastguard Workerdef DistDir(): 39*9e94795aSAndroid Build Coastguard Worker "Get the dist directory. Will create it if needed." 40*9e94795aSAndroid Build Coastguard Worker result = os.environ.get("DIST_DIR", os.path.join(OutDir(), "dist")) 41*9e94795aSAndroid Build Coastguard Worker os.makedirs(result, exist_ok=True) 42*9e94795aSAndroid Build Coastguard Worker return result 43*9e94795aSAndroid Build Coastguard Worker 44