Skip to content

Instantly share code, notes, and snippets.

@gedankenexperimenter
Last active March 5, 2022 21:58
Show Gist options
  • Save gedankenexperimenter/b465125c6853759f758f28cfcf984455 to your computer and use it in GitHub Desktop.
Save gedankenexperimenter/b465125c6853759f758f28cfcf984455 to your computer and use it in GitHub Desktop.
Sync libs for running docker simulator tests for Kaleidoscope
#!/bin/bash
# Synchronize the copy of a library used for building Kaleidoscope
# (i.e. KeyboardioHID) that will be used inside the Docker container with the
# one that is being used for normal builds. We do this by getting the git
# revision of the repo on the host, adding that repo as a remote for the docker
# version, and checking out the same revision there.
sync_docker_lib () {
LIB="$1"
if [[ -z ${LIB} ]]; then
echo "No lib specified to sync!" 1>&2
return 1
fi
if [[ -z ${KALEIDOSCOPE_LOCAL_LIB_DIR} ]]; then
echo "KALEIDOSCOPE_LOCAL_LIB_DIR was not defined." 1>&2
return 1
fi
if [[ ! -d ${KALEIDOSCOPE_LOCAL_LIB_DIR} ]]; then
echo "KALEIDOSCOPE_LOCAL_LIB_DIR ${KALEIDOSCOPE_LOCAL_LIB_DIR} not found." 1>&2
return 1
fi
SOURCE_REPO="${KALEIDOSCOPE_LOCAL_LIB_DIR}/${LIB}"
if [[ ! -d ${SOURCE_REPO} ]]; then
echo "Couldn't find lib dir: ${SOURCE_REPO}." 1>&2
return 1
fi
# Get hash of revision checked out in host repo.
REV=$(cd "${SOURCE_REPO}" && git rev-parse HEAD)
# Change dir to the repo used in Docker builds.
DEST_REPO="${KALEIDOSCOPE_DIR}/.arduino/user/hardware/keyboardio/virtual/libraries/${LIB}"
if [[ ! -d ${DEST_REPO} ]]; then
echo "Couldn't find dest lib dir: ${DEST_REPO}"
return 1
fi
cd "${DEST_REPO}"
# If the remote already exists, remove it. This seems to prevent some
# errors, but ought to be unnecessary.
(git remote | grep -q '^host_sync$') && \
git remote remove "host_sync"
# Add the host repo as a remote so we can sync to it.
git remote add "host_sync" "${SOURCE_REPO}"
git fetch "host_sync"
# Check out the current revision from the host repo.
git checkout ${REV}
}
for LIB in $(find "${KALEIDOSCOPE_LOCAL_LIB_DIR}" -type d -depth 1 -exec basename '{}' ';'); do
sync_docker_lib "${LIB}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment