Skip to content

Commit 0f529ca

Browse files
dschnellertimvaillancourt
authored andcommitted
Fix building on macOS (#285)
* Ignore Intellij Project File * Make build.sh compatible with macOS There already was a switch in place for the Python executable, but both the readlink and cp commands use flags not present on the default macOS binaries. This commit adds a check upfront and aborts with a message about you needing the coreutils package from homebrew to get the GNU variants of both commands. * Related: Fix flake8: Make regex a raw string
1 parent eaad5d4 commit 0f529ca

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ build
33
tmp
44
*.pyc
55
.idea
6+
*.iml

mongodb_consistent_backup/Upload/Rsync/Rsync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def init(self):
5656
def rsync_info(self):
5757
if not self._rsync_info:
5858
output = check_output([self.rsync_binary, "--version"])
59-
search = re.search("^rsync\s+version\s([0-9.-]+)\s+protocol\sversion\s(\d+)", output)
59+
search = re.search(r"^rsync\s+version\s([0-9.-]+)\s+protocol\sversion\s(\d+)", output)
6060
self.rsync_version = search.group(1)
6161
self._rsync_info = {"version": self.rsync_version, "protocol_version": int(search.group(2))}
6262
return self._rsync_info

scripts/build.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22

33
set -x
44

5+
readlink_bin=readlink
6+
cp_bin=cp
7+
if [[ "`uname`" =~ "Darwin" ]]; then
8+
if [[ -x /usr/local/bin/gcp && -x /usr/local/bin/greadlink ]]; then
9+
readlink_bin=greadlink
10+
cp_bin=gcp
11+
else
12+
echo "To run this on macOS, please install coreutils via homebrew first."
13+
exit 1
14+
fi
15+
fi
16+
517
name=${BIN_NAME:-mongodb-consistent-backup}
618
mod_name=mongodb_consistent_backup
7-
rootdir=$(readlink -f $(dirname $0)/..)
19+
rootdir=$(${readlink_bin} -f $(dirname $0)/..)
820
srcdir=${rootdir}/${mod_name}
921
bindir=${rootdir}/bin
1022
builddir=${rootdir}/build
@@ -55,8 +67,8 @@ fi
5567
if [ -d ${srcdir} ]; then
5668
[ -e ${builddir} ] && rm -rf ${builddir}
5769
mkdir -p ${builddir}
58-
cp -dpR ${rootdir}/${mod_name} ${builddir}/${mod_name}
59-
cp -dp ${rootdir}/{setup.py,requirements.txt,README.rst,VERSION} ${builddir}
70+
${cp_bin} -dpR ${rootdir}/${mod_name} ${builddir}/${mod_name}
71+
${cp_bin} -dp ${rootdir}/{setup.py,requirements.txt,README.rst,VERSION} ${builddir}
6072
find ${builddir} -type f -name "*.pyc" -delete
6173

6274
# Replace version number in setup.py and mongodb_consistent_backup/__init__.py with number in VERSION:

0 commit comments

Comments
 (0)