1#!/bin/bash
2
3# SPDX-License-Identifier: MIT
4#
5# Copyright (c) 2021 Rangi
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the "Software"), to deal
9# in the Software without restriction, including without limitation the rights
10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in all
15# copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23# SOFTWARE.
24
25declare -A FILES
26while read -r -d '' file; do
27	FILES["$file"]="true"
28done < <(git diff --name-only -z $1 HEAD)
29
30edited () {
31	${FILES["$1"]:-"false"}
32}
33
34dependency () {
35	if edited "$1" && ! edited "$2"; then
36		echo "'$1' was modified, but not '$2'! $3" | xargs
37	fi
38}
39
40# Pull requests that edit the first file without the second may be correct,
41# but are suspicious enough to require review.
42
43dependency include/linkdefs.h    src/rgbds.5 \
44           "Was the object file format changed?"
45
46dependency src/asm/parser.y      src/asm/rgbasm.5 \
47           "Was the rgbasm grammar changed?"
48
49dependency include/asm/warning.h src/asm/rgbasm.1 \
50           "Were the rgbasm warnings changed?"
51
52dependency src/asm/object.c      include/linkdefs.h \
53           "Should the object file revision be bumped?"
54dependency src/link/object.c     include/linkdefs.h \
55           "Should the object file revision be bumped?"
56
57dependency Makefile              CMakeLists.txt \
58           "Did the build process change?"
59dependency Makefile              src/CMakeLists.txt \
60           "Did the build process change?"
61
62dependency src/asm/main.c        src/asm/rgbasm.1 \
63           "Did the rgbasm CLI change?"
64dependency src/asm/main.c        contrib/zsh_compl/_rgbasm \
65           "Did the rgbasm CLI change?"
66dependency src/asm/main.c        contrib/bash_compl/_rgbasm.bash \
67           "Did the rgbasm CLI change?"
68dependency src/link/main.c       src/link/rgblink.1 \
69           "Did the rgblink CLI change?"
70dependency src/link/main.c       contrib/zsh_compl/_rgblink \
71           "Did the rgblink CLI change?"
72dependency src/link/main.c        contrib/bash_compl/_rgblink.bash \
73           "Did the rgblink CLI change?"
74dependency src/fix/main.c        src/fix/rgbfix.1 \
75           "Did the rgbfix CLI change?"
76dependency src/fix/main.c        contrib/zsh_compl/_rgbfix \
77           "Did the rgbfix CLI change?"
78dependency src/fix/main.c        contrib/bash_compl/_rgbfix.bash \
79           "Did the rgbfix CLI change?"
80dependency src/gfx/main.c        src/gfx/rgbgfx.1 \
81           "Did the rgbgfx CLI change?"
82dependency src/gfx/main.c        contrib/zsh_compl/_rgbgfx \
83           "Did the rgbgfx CLI change?"
84dependency src/gfx/main.c        contrib/bash_compl/_rgbgfx.bash \
85           "Did the rgbgfx CLI change?"
86