-
Notifications
You must be signed in to change notification settings - Fork 27
/
repo.sh
executable file
·149 lines (131 loc) · 4.61 KB
/
repo.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
set -e
shopt -s nullglob
source config.sh
recipes=""
for arg in "${@:1}"
do
if [ "$arg" == "--debug" ]
then
DEBUG=--debug
elif [ "$arg" == "--nonstop" ]
then
set +e
else
recipes+=" $arg"
fi
done
if [ "$recipes" == "" ]
then
recipes="$(target/release/list_recipes)"
fi
for recipe in $recipes
do
recipe_path=`target/release/find_recipe $recipe`
COOKBOOK_RECIPE="$recipe_path"
TARGET_DIR="${COOKBOOK_RECIPE}/target/${TARGET}"
COOKBOOK_BUILD="${TARGET_DIR}/build"
COOKBOOK_STAGE="${TARGET_DIR}/stage"
COOKBOOK_SOURCE="${COOKBOOK_RECIPE}/source"
COOKBOOK_SYSROOT="${TARGET_DIR}/sysroot"
if [ -e "${COOKBOOK_RECIPE}/recipe.toml" ]
then
target/release/cook "$recipe"
if [ ! -f "${COOKBOOK_STAGE}.tar.gz" ]
then
echo -e "\033[01;38;5;155mrepo - legacy packaging $recipe\033[0m" >&2
./cook.sh "$recipe" tar $DEBUG
else
TIME_PKG="$($STAT -c "%Y" "${COOKBOOK_STAGE}.pkgar")"
TIME_STAGE="$($STAT -c "%Y" "${COOKBOOK_STAGE}.tar.gz")"
if [ "$TIME_PKG" -gt "$TIME_STAGE" ]
then
echo -e "\033[01;38;5;155mrepo - legacy repackaging $recipe\033[0m" >&2
./cook.sh "$recipe" untar tar $DEBUG
fi
fi
# Match pkgar and tar time
touch -c -r "${COOKBOOK_STAGE}.tar.gz" "${COOKBOOK_STAGE}.pkgar"
continue
fi
if [ ! -d "${COOKBOOK_SOURCE}" ]
then
echo -e "\033[01;38;5;155mrepo - fetching $recipe\033[0m" >&2
./cook.sh "$recipe" fetch
fi
if [ ! -d "${COOKBOOK_BUILD}" ]
then
echo -e "\033[01;38;5;155mrepo - preparing $recipe\033[0m" >&2
./cook.sh "$recipe" prepare
elif [ ! -d "${COOKBOOK_SYSROOT}" ]
then
echo -e "\033[01;38;5;155mrepo - repreparing $recipe\033[0m" >&2
./cook.sh "$recipe" unprepare prepare
else
TIME_SOURCE="$($FIND "${COOKBOOK_SOURCE}" -type f -not -path '*/.git*' -printf "%Ts\n" | sort -nr | head -n 1)"
TIME_BUILD="$($FIND "${COOKBOOK_BUILD}" -type f -not -path '*/.git*' -printf "%Ts\n" | sort -nr | head -n 1)"
if [ "$TIME_SOURCE" -gt "$TIME_BUILD" ]
then
echo -e "\033[01;38;5;155mrepo - repreparing $recipe\033[0m" >&2
./cook.sh "$recipe" unprepare prepare
fi
fi
if [ ! -f "${COOKBOOK_STAGE}.tar.gz" ]
then
echo -e "\033[01;38;5;155mrepo - building $recipe\033[0m" >&2
./cook.sh "$recipe" build stage tar $DEBUG
else
TIME_BUILD="$($FIND "${COOKBOOK_BUILD}" -type f -not -path '*/.git*' -printf "%Ts\n" | sort -nr | head -n 1)"
TIME_STAGE="$($STAT -c "%Y" "${COOKBOOK_STAGE}.tar.gz")"
TIME_RECIPE="$($FIND "${COOKBOOK_RECIPE}"/{recipe.sh,*.patch} -printf '%Ts\n' | sort -nr | head -n 1)"
if [ "$TIME_BUILD" -gt "$TIME_STAGE" -o "$TIME_RECIPE" -gt "$TIME_STAGE" ]
then
echo -e "\033[01;38;5;155mrepo - rebuilding $recipe\033[0m" >&2
./cook.sh "$recipe" untar unstage build stage tar $DEBUG
else
echo -e "\033[01;38;5;155mrepo - $recipe up to date\033[0m" >&2
fi
fi
if [ ! -f "${COOKBOOK_STAGE}.pkgar" ]
then
echo -e "\033[01;38;5;155mrepo - packaging $recipe\033[0m" >&2
./cook.sh "$recipe" pkg $DEBUG
else
TIME_STAGE="$($STAT -c "%Y" "${COOKBOOK_STAGE}.tar.gz")"
TIME_PKG="$($STAT -c "%Y" "${COOKBOOK_STAGE}.pkgar")"
if [ "$TIME_STAGE" -gt "$TIME_PKG" ]
then
echo -e "\033[01;38;5;155mrepo - repackaging $recipe\033[0m" >&2
./cook.sh "$recipe" unpkg pkg $DEBUG
fi
fi
done
mkdir -p "$REPO"
for recipe in $recipes
do
recipe_path=`target/release/find_recipe $recipe`
COOKBOOK_RECIPE="$recipe_path"
TARGET_DIR="${COOKBOOK_RECIPE}/target/${TARGET}"
COOKBOOK_STAGE="${TARGET_DIR}/stage"
if [ "${COOKBOOK_STAGE}.tar.gz" -nt "$REPO/$recipe.tar.gz" ]
then
echo -e "\033[01;38;5;155mrepo - publishing $recipe\033[0m" >&2
./cook.sh $recipe publish
fi
if [ "${COOKBOOK_STAGE}.pkgar" -nt "$REPO/$recipe.pkgar" ]
then
echo -e "\033[01;38;5;155mrepo - publishing $recipe\033[0m" >&2
cp -v "${COOKBOOK_STAGE}.pkgar" "$REPO/$recipe.pkgar"
fi
done
echo -e "\033[01;38;5;155mrepo - generating repo.toml\033[0m" >&2
echo "[packages]" > "$REPO/repo.toml"
for toml in "$REPO/"*".toml"
do
package="$(basename "$toml" .toml)"
if [ "$package" != "repo" ]
then
version="$(grep version "$toml" | cut -d '=' -f2-)"
echo "$package =$version" >> "$REPO/repo.toml"
fi
done