• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# Copyright 2024 The Pigweed Authors
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# the License at
8#
9#     https://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16
17# See:
18# - https://bazel.build/docs/user-manual#workspace-status-command
19# - https://github.com/bazelbuild/bazel/blob/a95f37bb038f/tools/buildstamp/get_workspace_status
20
21# This script will be run bazel when building process starts to
22# generate key-value information that represents the status of the
23# workspace. The output should be like
24#
25# KEY1 VALUE1
26# KEY2 VALUE2
27#
28# If the script exits with non-zero code, it's considered as a failure
29# and the output will be discarded.
30#
31# Note that keys starting with "STABLE_" are part of the stable set, which if
32# changed, invalidate any stampted targets. Keys which do not start with
33# "STABLE_" are part of the volatile set, which will be used but do not
34# invalidate stamped targets.
35
36# If we're in a CoG workspace, Git operations are not supported.
37# TODO: https://pwbug.dev/381305105 - This may be supported some day.
38if [[ "$PWD" == /google/cog/* ]];
39then
40    echo "STABLE_GIT_COMMIT UNKNOWN_COG_WORKSPACE"
41    echo "STABLE_GIT_TREE_DIRTY 1"
42    exit 0;
43fi
44
45# Current git commit
46git_rev=$(git rev-parse HEAD) || exit 1
47echo "STABLE_GIT_COMMIT ${git_rev}"
48
49# Check whether there are any uncommitted changes
50git diff-index --quiet HEAD --; diff_rc=$?
51case $diff_rc in
52    0) dirty=0 ;;
53    1) dirty=1 ;;
54    *) exit 1 ;;
55esac
56echo "STABLE_GIT_TREE_DIRTY ${dirty}"
57