forked from SEL4PROJ/AOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aos-make-project.sh
executable file
·147 lines (124 loc) · 2.97 KB
/
aos-make-project.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
#!/bin/sh
#
# Copyright 2020, Data61
# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
# ABN 41 687 119 230.
#
# This software may be distributed and modified according to the terms of
# the GNU General Public License version 2. Note that NO WARRANTY is provided.
# See "LICENSE_GPLv2.txt" for details.
#
# @TAG(DATA61_GPL)
#
# Script to extract the aos sources from a repo managed repository into
# a single dir, and maintaining the correct symbolic links. If no
# directory exists a git repository is initialised. All updates to the
# directory are then added and the user is then prompted for a commit
# message.
#
# usage ./aos-make-project.sh <AOS_REPO_CHECKOUT> <NEW_DIR>
#
set -e
if [ $# -eq 1 ]; then
DEST_REPO=$(realpath -m "$1"); shift
else
echo "Usage: $0 REPOSITORY_DESITNATION" >&2
exit 1
fi
SCRIPT_DIR=$(realpath -e "${0%/*}")
main () {
src_repo=$(find_repo)
cd "${src_repo}"
clean_repo "${src_repo}"
git_try_create "${DEST_REPO}"
copy_to_repo \
"${src_repo}" "${DEST_REPO}" "kernel/" \
--links
copy_to_repo \
"${src_repo}" "${DEST_REPO}" "libnfs/" \
--links --exclude ".gitignore"
copy_to_repo \
"${src_repo}" "${DEST_REPO}" "projects/" \
--copy-links --exclude "aos-make-project.sh"
copy_to_repo \
"${src_repo}" "${DEST_REPO}" "tools/" \
--links
cd "${DEST_REPO}"
ln \
-srf \
"projects/aos/reset.sh" \
"${DEST_REPO}/reset.sh"
ln \
-srf \
"projects/aos/odroid" \
"${DEST_REPO}/odroid"
ln \
-srf \
"projects/aos/init-build.sh" \
"${DEST_REPO}/init-build.sh"
ln \
-srf \
"projects/aos/.gitignore" \
"${DEST_REPO}/.gitignore"
ln \
-srf \
"projects/aos/settings.cmake" \
"${DEST_REPO}/settings.cmake"
ln \
-srf \
"tools/seL4/cmake-tool/default-CMakeLists.txt" \
"${DEST_REPO}/CMakeLists.txt"
git add .
git commit -e
echo "Repository updated in '${DEST_REPO}'"
}
# Find the root of the AOS repo.
find_repo () {
dir=$SCRIPT_DIR
while ! [ "${dir}" = "/" ] && ! [ -d "${dir}/.repo" ]; do
dir=$(dirname "${dir}")
done
if [ ! -d "${dir}/.repo" ]; then
echo "Failed to find root of AOS repo" >&2
exit 1
else
echo "${dir}"
fi
}
# Initialise the git repository if it doesn't exist
git_try_create () {
repo_dir=$1; shift
if [ -d "${repo_dir}/.git" ]; then
echo "Adding to existing git repository \"${repo_dir}\"..."
return
fi
echo "Creating new git repository in \"${repo_dir}\"..."
git init "${repo_dir}"
}
# Copy files into a git repository
copy_to_repo () {
src_dir=$1; shift
dest_dir=$1; shift
relative_path=$1; shift
echo "Copying ${src_dir}/${relative_path} to ${dest_dir}/${relative_path}"
rsync \
-r \
--exclude ".git" \
"$@" \
"${src_dir}/${relative_path}" \
"${dest_dir}/${relative_path}"
}
# clean repo projects
clean_repo () {
repo_dir=$1; shift
cd "${repo_dir}"
projects=$(repo list | cut -d ':' -f 1)
for project in ${projects}; do
echo "Cleaning '${repo_dir}/${project}'..."
cd "${repo_dir}/${project}"
git clean -fX
git clean -i
done
}
# Run the script
main