Skip to content

Commit

Permalink
chore: Sync vendor script with duckdb (#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored Jan 2, 2025
1 parent 80b70a6 commit 277e589
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@
^man/dot-extract_constructor_and_modifiers\.Rd$
^man/dot-apply_modifiers\.Rd$
^man/handle_vertex_type_arg\.Rd$
^vendor\.sh$
^vendor-one\.sh$
2 changes: 1 addition & 1 deletion tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
In the shell:

```sh
tools/update-cigraph.sh <path-to-cigraph-working-copy>
vendor.sh <path-to-cigraph-working-copy>
```

There is a CI/CD workflow that runs this very frequently.
Expand Down
56 changes: 0 additions & 56 deletions tools/update-cigraph.sh

This file was deleted.

94 changes: 94 additions & 0 deletions vendor-one.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash
# https://unix.stackexchange.com/a/654932/19205
# Using bash for -o pipefail

set -e
set -x
set -o pipefail

cd `dirname $0`

project=igraph
vendor_base_dir=src/vendor
vendor_dir=${vendor_base_dir}/cigraph
repo_org=${project}
repo_name=${project}


if [ -z "$1" ]; then
upstream_basedir=../../${project}
else
upstream_basedir="$1"
fi

upstream_dir=.git/${project}

if [ "$upstream_basedir" != "$upstream_dir" ]; then
git clone "$upstream_basedir" "$upstream_dir"
fi

if [ -n "$(git status --porcelain)" ]; then
echo "Error: working directory not clean"
exit 1
fi

if [ -n "$(git -C "$upstream_dir" status --porcelain)" ]; then
echo "Warning: working directory $upstream_dir not clean"
fi

base=$(git log -n 3 --format="%s" -- ${vendor_dir} | tee /dev/stderr | sed -nr '/^.*'${repo_org}.${repo_name}'@([0-9a-f]+)( .*)?$/{s//\1/;p;}' | head -n 1)

original=$(git -C "$upstream_dir" log --first-parent --reverse --format="%H" ${base}..HEAD)

message=
is_tag=

for commit in $original; do
echo "Importing commit $commit"

git -C "$upstream_dir" checkout "$commit"

rm -rf ${vendor_dir}
mkdir -p ${vendor_dir}

git clone "$upstream_dir" ${vendor_dir}

cmake -S${vendor_dir} -B${vendor_dir}/build

mv ${vendor_dir}/build/include/igraph_version.h src/vendor/

rm -rf ${vendor_dir}/.git ${vendor_dir}/.github ${vendor_dir}/doc ${vendor_dir}/examples ${vendor_dir}/fuzzing ${vendor_dir}/tests ${vendor_dir}/tools ${vendor_dir}/build

make -f Makefile-cigraph

R -q -e 'cpp11::cpp_register()'

# Always vendor tags
if [ $(git -C "$upstream_dir" describe --tags "$commit" | grep -c -- -) -eq 0 ]; then
message="vendor: Update vendored sources (tag $(git -C "$upstream_dir" describe --tags "$commit")) to ${repo_org}/${repo_name}@$commit"
is_tag=true
break
fi

if [ $(git status --porcelain -- ${vendor_base_dir} | wc -l) -gt 1 ]; then
message="vendor: Update vendored sources to ${repo_org}/${repo_name}@$commit"
break
fi
done

if [ "$message" = "" ]; then
echo "No changes."
git checkout -- ${vendor_base_dir}
rm -rf "$upstream_dir"
exit 0
fi

git add .

(
echo "$message"
echo
git -C "$upstream_dir" log --first-parent --format="%s" ${base}..${commit} | tee /dev/stderr | sed -r 's%(#[0-9]+)%'${repo_org}/${repo_name}'\1%g'
) | git commit --file /dev/stdin

rm -rf "$upstream_dir"
92 changes: 92 additions & 0 deletions vendor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash
# https://unix.stackexchange.com/a/654932/19205
# Using bash for -o pipefail

set -e
set -x
set -o pipefail

cd `dirname $0`

project=igraph
vendor_base_dir=src/vendor
vendor_dir=${vendor_base_dir}/cigraph
repo_org=${project}
repo_name=${project}


if [ -z "$1" ]; then
upstream_basedir=../../${project}
else
upstream_basedir="$1"
fi

upstream_dir=.git/${project}

if [ "$upstream_basedir" != "$upstream_dir" ]; then
git clone "$upstream_basedir" "$upstream_dir"
fi

if [ -n "$(git status --porcelain)" ]; then
echo "Error: working directory not clean"
exit 1
fi

if [ -n "$(git -C "$upstream_dir" status --porcelain)" ]; then
echo "Warning: working directory $upstream_dir not clean"
fi

base=$(git log -n 3 --format="%s" -- ${vendor_dir} | tee /dev/stderr | sed -nr '/^.*'${repo_org}.${repo_name}'@([0-9a-f]+)( .*)?$/{s//\1/;p;}' | head -n 1)

original=$(git -C "$upstream_dir" rev-parse --verify HEAD)

message=
is_tag=

for commit in $original; do
echo "Importing commit $commit"

rm -rf ${vendor_dir}
mkdir -p ${vendor_dir}

git clone "$upstream_dir" ${vendor_dir}

cmake -S${vendor_dir} -B${vendor_dir}/build

mv ${vendor_dir}/build/include/igraph_version.h src/vendor/

rm -rf ${vendor_dir}/.git ${vendor_dir}/.github ${vendor_dir}/doc ${vendor_dir}/examples ${vendor_dir}/fuzzing ${vendor_dir}/tests ${vendor_dir}/tools ${vendor_dir}/build

make -f Makefile-cigraph

R -q -e 'cpp11::cpp_register()'

# Always vendor tags
if [ $(git -C "$upstream_dir" describe --tags "$commit" | grep -c -- -) -eq 0 ]; then
message="vendor: Update vendored sources (tag $(git -C "$upstream_dir" describe --tags "$commit")) to ${repo_org}/${repo_name}@$commit"
is_tag=true
break
fi

if [ $(git status --porcelain -- ${vendor_base_dir} | wc -l) -gt 1 ]; then
message="vendor: Update vendored sources to ${repo_org}/${repo_name}@$commit"
break
fi
done

if [ "$message" = "" ]; then
echo "No changes."
git checkout -- ${vendor_base_dir}
rm -rf "$upstream_dir"
exit 0
fi

git add .

(
echo "$message"
echo
git -C "$upstream_dir" log --first-parent --format="%s" ${base}..${commit} | tee /dev/stderr | sed -r 's%(#[0-9]+)%'${repo_org}/${repo_name}'\1%g'
) | git commit --file /dev/stdin

rm -rf "$upstream_dir"

0 comments on commit 277e589

Please sign in to comment.