|
| 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