1#!/bin/bash
2#
3# Copyright 2018, Haiku, Inc. All rights reserved.
4# Distributed under the terms of the MIT license.
5#
6
7if [ "$#" -lt 1 ]; then
8	echo "A tool to bump the revisions of all recipes that depend on another recipe."
9	echo "Usage: $0 <path/to/dependee/recipe>"
10	exit 1
11fi
12
13RECIPE=$1
14if [ ! -e "$1" ]; then
15	echo "$1 does not exist!"
16	exit 1
17fi
18
19# some stub functions so we don't get errors/warnings
20getPackagePrefix()
21{
22	:
23}
24defineDebugInfoPackage()
25{
26	:
27}
28
29# some utility functions
30processProvides()
31{
32	ret=""
33	for provide in $1; do
34		if [ "$provide" = "compat" ]; then
35			continue
36		fi
37		# grab only the provides that start with a letter (ignore >=, versions, etc.)
38		if [[ "$provide" =~ ^[A-Za-z].*$ ]]; then
39			ret="${ret} ${provide}"
40		fi
41	done
42	echo $ret
43}
44providesToGrep()
45{
46	ret=""
47	for provide in $1; do
48		ret="${ret}${provide}|"
49	done
50	echo ${ret::-1}
51}
52
53source $RECIPE
54GREP=$(providesToGrep "$(processProvides "$PROVIDES_devel")")
55FILES=$(git grep --name-only -E $GREP \
56	$(git rev-parse --show-toplevel))
57BUMPED=0
58for file in $FILES; do
59	source $file
60		# yes, this potentially overwrites global variables, but
61		# for now at least it's probably not an issue
62	echo $(processProvides "$BUILD_REQUIRES") | egrep $GREP >/dev/null
63	if [ $? -eq 0 ]; then
64		echo "bumping $file"
65		REVISION=$((REVISION+1))
66		sed -i "s/.*REVISION=.*/REVISION=\"$REVISION\"/" $file
67		# trim trailing space while we're at it
68		sed -i 's/[ \t]*$//' $file
69		BUMPED=$((BUMPED+1))
70	fi
71done
72echo ""
73echo "done; $BUMPED recipes bumped."
74