blob: 1ee93e5dc3cb7a8f5aae5d90500958490bb92827 [file] [log] [blame]
Alexander Williams8365ac42022-08-17 17:07:28 -07001#!/bin/bash
2# Copyright lowRISC contributors.
3# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4# SPDX-License-Identifier: Apache-2.0
5
6set -e
7
8usage_string="
9Usage: get-bitstream-strategy.sh <cached-bitstream-target> [pathspec]...
10
11 cached-bitsream-target The bazel target for the cached bitstream. This script
12 will retrieve the most recent image from a commit in this
13 this branch's history.
14 pathspec A git pathspec (multiple instances permitted) indicating which files
15 trigger building the bitstream. Please use only exclude pathspecs
16 to cause new, unconsidered paths to trigger the build.
17"
18
19if [ $# -lt 1 ]; then
20 echo >&2 "ERROR: Unexpected number of arguments"
21 echo >&2 "${usage_string}"
22 exit 1
23fi
24
25. util/build_consts.sh
26
27bitstream_target=${*:1:1}
28
29if [ $# -gt 1 ]; then
30 excluded_files=( "${@:2}" )
31else
32 excluded_files=( "." )
33fi
34
35# Retrieve the most recent bitstream at or before HEAD.
36BITSTREAM="--refresh HEAD" ./bazelisk.sh build ${bitstream_target}
37
38# The directory containing the bitstream is named after the git hash.
39bitstream_file=$(ci/scripts/target-location.sh ${bitstream_target})
40bitstream_commit=$(basename "$(dirname ${bitstream_file})")
41
42echo "Checking for changes against pre-built bitstream from ${bitstream_commit}"
43echo "Files changed:"
44git diff --stat --name-only ${bitstream_commit}
45echo
46echo "Changed files after exclusions applied:"
47# Use the cached bitstream if no changed files remain.
48if git diff --exit-code --stat --name-only ${bitstream_commit} -- "${excluded_files[@]}"; then
49 bitstream_strategy=cached
50else
51 bitstream_strategy=build
52fi
53
54echo
55echo "Bitstream strategy is ${bitstream_strategy}"
56echo "##vso[task.setvariable variable=bitstreamStrategy]${bitstream_strategy}"