Skip to content

Commit 28e1652

Browse files
committed
utils/index: Add west projects to Zephyr repo on fetch
1 parent fc8106d commit 28e1652

File tree

5 files changed

+142
-1
lines changed

5 files changed

+142
-1
lines changed

docker/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ RUN \
3434
libapache2-mod-wsgi-py3 \
3535
libjansson4 \
3636
libyaml-0-2 \
37-
wget
37+
wget \
38+
yq
3839

3940
COPY ./requirements.txt /usr/local/elixir/
4041

projects/zephyr.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
# Enable DT bindings compatible strings support
44
dts_comp_support=1
55

6+
version_dir()
7+
{
8+
grep "^elixir-" |
9+
sed -e 's/elixir-//';
10+
}
11+
12+
version_rev()
13+
{
14+
sed -e 's/^/elixir-/';
15+
}
16+
617
list_tags()
718
{
819
echo "$tags" |
@@ -21,3 +32,7 @@ get_latest_tags()
2132
{
2233
git tag | grep -v '^zephyr-v' | version_dir | grep -v '\-rc' | sort -Vr
2334
}
35+
36+
fetch_hook() {
37+
$script_dir/utils/zephyr-converter.sh $opt1
38+
}

script.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ script_dir=`pwd`
3232
cd "$cur_dir"
3333
dts_comp_support=0 # DT bindings compatible strings support (disable by default)
3434

35+
# Converts git repository tag to name visible in Elixir
3536
version_dir()
3637
{
3738
cat;
3839
}
3940

41+
# Converts tag name visible in Elixir to git repository tag
4042
version_rev()
4143
{
4244
cat;
@@ -214,6 +216,11 @@ dts_comp()
214216
echo $dts_comp_support
215217
}
216218

219+
# Ran from utils/index to allow projects modify the repository after fetch
220+
fetch_hook() {
221+
return;
222+
}
223+
217224
project=$(basename `dirname $LXR_REPO_DIR`)
218225

219226
plugin=$script_dir/projects/$project.sh
@@ -291,6 +298,10 @@ case $cmd in
291298
dts_comp
292299
;;
293300

301+
fetch-hook)
302+
fetch_hook
303+
;;
304+
294305
help)
295306
echo "Usage: $0 subcommand [args]..."
296307
exit 1

utils/index

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ project_fetch() {
4646

4747
$git fetch --all --tags -j4
4848

49+
LXR_REPO_DIR=$1/repo LXR_DATA_DIR=$1/data \
50+
./script.sh fetch-hook "$(realpath $1)"
51+
4952
# A gc.log file implies a garbage collect failed in the past.
5053
# Also, create a hidden flag which could be useful to trigger GCs manually.
5154
if test -e $1/repo/gc.log -o "$ELIXIR_GC"; then

utils/zephyr-converter.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
clean_git_worktree() {
6+
find $1 -mindepth 1 -maxdepth 1 -type d -not -path "$1/.git*" -exec rm -r {} \; || true
7+
find $1 -mindepth 1 -maxdepth 1 -type f -not -path "$1/.git*" -exec rm -r {} \; || true
8+
}
9+
10+
copy_git_worktree() {
11+
rsync -q -av $1 --exclude .git $2
12+
}
13+
14+
resolve_path() {
15+
project_path_resolved=`readlink -m $1`
16+
echo ./`realpath -m --relative-to=$(pwd) $project_path_resolved`
17+
}
18+
19+
print_readme() {
20+
echo "This directory contains projects specified in west.yaml."
21+
echo "It was generated automatically and is not a part of the upstream $PROJECT_NAME repository."
22+
echo "You can report bugs (ex. missing west.yaml projects) at https://github.com/bootlin/elixir"
23+
}
24+
25+
if [[ "$#" -ne 1 ]]; then
26+
echo "usage: $0 west-project-dir"
27+
exit 1
28+
fi
29+
30+
if ! command -v west 2>&1 >/dev/null; then
31+
echo "west command is not available"
32+
exit 1
33+
fi
34+
35+
cd $1
36+
37+
PROJECT_NAME=zephyr
38+
TOP_DIR=./west-topdir
39+
REPO_DIR=./repo
40+
TMP_DIR=./tmp
41+
MAIN_BRANCH=main
42+
export ZEPHYR_BASE=$TOP_DIR
43+
44+
if [[ ! -d $REPO_DIR ]]; then
45+
echo "$REPO_DIR does not exist. Please clone project repository to $REPO first."
46+
exit 1
47+
fi
48+
49+
git -C $REPO_DIR config user.email [email protected]
50+
git -C $REPO_DIR config user.name "west repository converter for $PROJECT_NAME"
51+
52+
if [[ ! -f $TOP_DIR/$PROJECT_NAME/.git ]]; then
53+
git -C $REPO_DIR worktree add -f ../$TOP_DIR/$PROJECT_NAME $MAIN_BRANCH
54+
fi
55+
56+
if [[ ! -f $TMP_DIR/.git ]]; then
57+
git -C $REPO_DIR worktree add -f ../$TMP_DIR $MAIN_BRANCH
58+
git -C $TMP_DIR checkout --orphan elixir
59+
git -C $TMP_DIR commit --allow-empty -m "initial commit"
60+
fi
61+
62+
if [[ ! -d $TOP_DIR/.west ]]; then
63+
west init $TOP_DIR/zephyr -l
64+
fi
65+
66+
project_tags=`git -C $REPO_DIR tag | grep -v "^elixir" | grep -v "^$PROJECT_NAME"`
67+
local_tags=`git -C $REPO_DIR tag | { grep "^elixir" || true; } | sed 's/^elixir-//'`
68+
new_tags=`echo $project_tags $local_tags | tr ' ' '\n' | sort -n | uniq -u`
69+
70+
for tag in $new_tags; do
71+
echo "found missing tag $tag"
72+
git -C $TOP_DIR/$PROJECT_NAME checkout -f $tag
73+
clean_git_worktree $TMP_DIR
74+
75+
west_manifest=$TOP_DIR/$PROJECT_NAME/west.yml
76+
if [[ -f $west_manifest ]]; then
77+
# Find disabled groups
78+
extra_group_names=`cat west-topdir/$PROJECT_NAME/west.yml | yq -r '(.manifest."group-filter" // [])[]'`
79+
# Take only disabled groups (start with '-'), enable them (replace - with +),
80+
# concatenate lines to group-a,group-b,...
81+
extra_groups=`echo $extra_group_names | tr ' ' '\n' | grep '^-' | sed 's/^-/+/' | paste -s -d,`
82+
west update $([[ ! -z $extra_groups ]] && echo --group-filter "$extra_groups")
83+
# Get module paths to copy
84+
module_paths=`cat $west_manifest | yq -r '.manifest.projects | map(.path)[] | select(. != null)'`
85+
86+
mkdir -p $TMP_DIR/west_projects
87+
for top_path in $module_paths; do
88+
# Check if project_path does not traverse outside west_projects
89+
project_path=`resolve_path $TMP_DIR/west_projects/$top_path`
90+
if [[ $project_path =~ ^$TMP_DIR/west_projects/.* ]]; then
91+
echo "copying $top_path project directory"
92+
mkdir -p $project_path
93+
copy_git_worktree $TOP_DIR/$top_path/ $project_path
94+
else
95+
echo "found suspicious path $project_path, not copying"
96+
fi
97+
done
98+
99+
print_readme > $TMP_DIR/west_projects/README.txt
100+
fi
101+
102+
echo "copying $PROJECT_NAME directory"
103+
git -C $TMP_DIR checkout -q elixir
104+
copy_git_worktree $TOP_DIR/$PROJECT_NAME/ $TMP_DIR
105+
106+
echo "commiting $tag"
107+
git -C $TMP_DIR add '*'
108+
git -C $TMP_DIR commit -q -a -m $tag
109+
git -C $TMP_DIR tag elixir-$tag
110+
done
111+

0 commit comments

Comments
 (0)