1#!/bin/bash -e 2# Copyright (C) 2022 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# Script used as --workspace_status_command. 17# Must execute at the root of workspace. 18# https://docs.bazel.build/versions/main/command-line-reference.html#flag--workspace_status_command 19 20# Common script utilities 21source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../../make/shell_utils.sh 22require_top 23 24 25if [[ ! -f "WORKSPACE" ]]; then 26 echo "ERROR: gen_build_number.sh must be executed at the root of Bazel workspace." >&2 27 exit 1 28fi 29 30 31# TODO(b/228463719): figure out how to get the path properly. 32BUILD_NUMBER_FILE=$(getoutdir)/soong/build_number.txt 33if [[ -f ${BUILD_NUMBER_FILE} ]]; then 34 BUILD_NUMBER=$(cat ${BUILD_NUMBER_FILE}) 35else 36 BUILD_NUMBER=eng.${USER:0:6}.$(date '+%Y%m%d.%H%M%S') 37fi 38 39echo "BUILD_NUMBER ${BUILD_NUMBER}" 40