Skip to content

Commit

Permalink
Merge pull request #223 from ZenVoich/optimize-moc-wrapper
Browse files Browse the repository at this point in the history
[cli] optimize `moc-wrapper`
  • Loading branch information
ZenVoich authored Apr 22, 2024
2 parents 1188cc1 + 7b8aa9e commit ab7d75f
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions cli/bin/moc-wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
#!/bin/bash
mocPath="$(mops toolchain bin moc --fallback)"
$mocPath "$@"

# set -e

findRootDir() {
dir="$(pwd)"
while [[ "$dir" != "" && ! -e "$dir/mops.toml" ]]; do
dir=${dir%/*}
done
echo "$dir"
}

rootDir=$(findRootDir)
mopsToml="$rootDir/mops.toml"

if [[ $rootDir == "" ]] || [[ ! -f $mopsToml ]]; then
echo "mops.toml not found in $rootDir or its parent directories"
exit 1;
fi;

if command -v openssl &> /dev/null; then
mopsTomlHash=$(openssl sha256 $mopsToml | awk -F'= ' '{print $2}')
else
mopsTomlHash=$(shasum $mopsToml -a 256 | awk -F' ' '{print $1}')
fi;

cached="$rootDir/.mops/moc-$mopsTomlHash"

if [ -f $cached ]; then
mocPath=$(cat $cached)
if [[ "$mocPath" != *"/moc" ]] ; then
mocPath="$(mops toolchain bin moc --fallback)"
echo -n $mocPath > "$cached"
fi;
else
mocPath="$(mops toolchain bin moc --fallback)"
echo -n $mocPath > "$cached"
fi;

$mocPath "$@"

0 comments on commit ab7d75f

Please sign in to comment.