-
Notifications
You must be signed in to change notification settings - Fork 717
/
get-bitstream-strategy.sh
executable file
·65 lines (53 loc) · 2.11 KB
/
get-bitstream-strategy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
set -e
usage_string="
Usage: get-bitstream-strategy.sh <cached-bitstream-design> [pathspec]...
cached-bitstream-design The design name for the cached bitstream. This script
will retrieve the most recent image from a commit in
this branch's history.
pathspec A git pathspec (multiple instances permitted) indicating which files
trigger building the bitstream. Please use only exclude pathspecs
to cause new, unconsidered paths to trigger the build.
"
if [ $# -lt 1 ]; then
echo >&2 "ERROR: Unexpected number of arguments"
echo >&2 "${usage_string}"
exit 1
fi
. util/build_consts.sh
bitstream_design=${*:1:1}
if [ $# -gt 1 ]; then
excluded_files=( "${@:2}" )
else
excluded_files=( "." )
fi
# Retrieve the most recent bitstream at or before HEAD.
BITSTREAM="--refresh HEAD" ci/bazelisk.sh build @bitstreams//:manifest
# Find the bitstream commit from the manifest file.
manifest_file=$(ci/scripts/target-location.sh @bitstreams//:manifest)
bitstream_commit=$(ci/bazelisk.sh run //util/py/scripts:get_bitstream_build_id \
-- --manifest ${manifest_file} \
--schema ${REPO_TOP}/rules/scripts/bitstreams_manifest.schema.json \
--design ${bitstream_design})
if [ -z "${bitstream_commit}" ]; then
echo "Design ${bitstream_design} not found in the cache"
bitstream_strategy=build
else
echo "Checking for changes against pre-built bitstream from ${bitstream_commit}"
echo "Files changed:"
git diff --stat --name-only ${bitstream_commit}
echo
echo "Changed files after exclusions applied:"
# Use the cached bitstream if no changed files remain.
if git diff --exit-code --stat --name-only ${bitstream_commit} -- "${excluded_files[@]}"; then
bitstream_strategy=cached
else
bitstream_strategy=build
fi
fi
echo
echo "Bitstream strategy is ${bitstream_strategy}"
echo "##vso[task.setvariable variable=bitstreamStrategy]${bitstream_strategy}"