#!/bin/bash
set -euox pipefail

name="pybind11_repo"
#build_file = "//build:pybind11.bazel",
commit="5c7a290d374b8b6cc3bb3d1d6f1316547ba118f2"
remote="https://github.com/pybind/pybind11.git"

name=${1:-$name}
version=${2:-v.unknown}
remote=${3:-$remote}
commit=${4:-$commit}

tar_path=$name-$version-$commit.tar.gz


touch uploads
rm -rf uploads
mkdir -p uploads
cd uploads

#git archive --output=$tar_path $commit

mkdir $name
git clone $remote $name
cd $name
git archive --output=../$tar_path $commit
cd ../..
sha256=`sha256sum uploads/$tar_path | cut -f 1 -d ' '`

cat << EOF
third_party_archive(
    name = "$name",
    file_name = "$tar_path",
    sha256 = "$sha256",
)
EOF

echo scripts/build/upload-to-third-party.sh uploads/$tar_path
#
#
#commit=$(cd ~/protobuf && git rev-parse HEAD)
#(cd ~/protobuf && git archive --format=tar.gz -o /tmp/protobuf-${commit}.tgz HEAD)
#
#sha256=$(cd ~/driving && scripts/build/upload-to-third-party.sh /tmp/protobuf-${commit}.tgz | sed -n 's/^SHA256: \(.*\)/\1/p')

