regen-gapic.sh: fix microregen for macos

Fixes https://github.com/googleapis/gapic-generator-go/issues/228

Change-Id: I41c06111ae44a2e5ea392224c8a0373a2346ed92
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/46673
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jean de Klerk <deklerk@google.com>
diff --git a/regen-gapic.sh b/regen-gapic.sh
index 9ea015d..fadf6c9 100755
--- a/regen-gapic.sh
+++ b/regen-gapic.sh
@@ -19,6 +19,13 @@
 set -ex
 
 GOCLOUD_DIR="$(dirname "$0")"
+HOST_MOUNT="$PWD"
+
+# need to mount the /var/folders properly for macos
+# https://stackoverflow.com/questions/45122459/docker-mounts-denied-the-paths-are-not-shared-from-os-x-and-are-not-known/45123074
+if [[ "$OSTYPE" == "darwin"* ]] && [[ "$HOST_MOUNT" == "/var/folders"* ]]; then
+  HOST_MOUNT=/private$HOST_MOUNT
+fi
 
 microgen() {
   input=$1
@@ -27,8 +34,8 @@
   # see https://github.com/googleapis/gapic-generator-go/blob/master/README.md#docker-wrapper for details
   docker run \
     --user $UID \
-    --mount type=bind,source=$PWD,destination=/conf,readonly \
-    --mount type=bind,source=$PWD/$input,destination=/in/$input,readonly \
+    --mount type=bind,source=$HOST_MOUNT,destination=/conf,readonly \
+    --mount type=bind,source=$HOST_MOUNT/$input,destination=/in/$input,readonly \
     --mount type=bind,source=/tmp,destination=/out \
     --rm \
     gcr.io/gapic-images/gapic-generator-go:0.8.1 \