Skip to content

Commit 3c1af40

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

File tree

5 files changed

+140
-1
lines changed

5 files changed

+140
-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+
cat;
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: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
export ZEPHYR_BASE=$TOP_DIR
42+
43+
if [[ ! -d $REPO_DIR ]]; then
44+
echo "$REPO_DIR does not exist. Please clone project repository to $REPO first."
45+
exit 1
46+
fi
47+
48+
git -C $REPO_DIR config user.email [email protected]
49+
git -C $REPO_DIR config user.name "west repository converter for $PROJECT_NAME"
50+
51+
if [[ ! -f $TOP_DIR/$PROJECT_NAME/.git ]]; then
52+
git -C $REPO_DIR worktree add ../$TOP_DIR/$PROJECT_NAME main
53+
fi
54+
55+
if [[ ! -f $TMP_DIR/.git ]]; then
56+
git -C $REPO_DIR worktree add -b elixir --orphan ../$TMP_DIR
57+
git -C $TMP_DIR commit --allow-empty -m "initial commit"
58+
fi
59+
60+
if [[ ! -d $TOP_DIR/.west ]]; then
61+
west init $TOP_DIR/zephyr -l
62+
fi
63+
64+
project_tags=`git -C $REPO_DIR tag | grep -v "^elixir" | grep -v "^$PROJECT_NAME"`
65+
local_tags=`git -C $REPO_DIR tag | { grep "^elixir" || true; } | sed 's/^elixir-//'`
66+
new_tags= #`echo $project_tags $local_tags | tr ' ' '\n' | sort -n | uniq -u | grep v4.0.0`
67+
68+
for tag in $new_tags; do
69+
echo "found missing tag $tag"
70+
git -C $TOP_DIR/$PROJECT_NAME checkout -f $tag
71+
clean_git_worktree $TMP_DIR
72+
73+
west_manifest=$TOP_DIR/$PROJECT_NAME/west.yml
74+
if [[ -f $west_manifest ]]; then
75+
# Find disabled groups
76+
extra_group_names=`cat west-topdir/$PROJECT_NAME/west.yml | yq -r '(.manifest."group-filter" // [])[]'`
77+
# Take only disabled groups (start with '-'), enable them (replace - with +),
78+
# concatenate lines to group-a,group-b,...
79+
extra_groups=`echo $extra_group_names | tr ' ' '\n' | grep '^-' | sed 's/^-/+/' | paste -s -d,`
80+
west update $([[ ! -z $extra_groups ]] && echo --group-filter "$extra_groups")
81+
# Get module paths to copy
82+
module_paths=`cat $west_manifest | yq -r '.manifest.projects | map(.path)[] | select(. != null)'`
83+
84+
mkdir -p $TMP_DIR/west_projects
85+
for top_path in $module_paths; do
86+
# Check if project_path does not traverse outside west_projects
87+
project_path=`resolve_path $TMP_DIR/west_projects/$top_path`
88+
if [[ $project_path =~ ^$TMP_DIR/west_projects/.* ]]; then
89+
echo "copying $top_path project directory"
90+
mkdir -p $project_path
91+
copy_git_worktree $TOP_DIR/$top_path/ $project_path
92+
else
93+
echo "found suspicious path $project_path, not copying"
94+
fi
95+
done
96+
97+
print_readme > $TMP_DIR/west_projects/README.txt
98+
fi
99+
100+
echo "copying $PROJECT_NAME directory"
101+
git -C $TMP_DIR checkout -q elixir
102+
copy_git_worktree $TOP_DIR/$PROJECT_NAME/ $TMP_DIR
103+
104+
echo "commiting $tag"
105+
git -C $TMP_DIR add '*'
106+
git -C $TMP_DIR commit -q -a -m $tag
107+
git -C $TMP_DIR tag elixir-$tag
108+
done
109+

0 commit comments

Comments
 (0)