Skip to content

Commit

Permalink
Install the required version of protoc on macOS
Browse files Browse the repository at this point in the history
Summary:
This change updates the mac setup so that the required version of protoc
is install from a zip archive on github. If a homebrew version of protoc
is installed that isn't the current version, we uninstall it first.

The installation of protoc is the same for linux and mac, so the code is
shared.

Test Plan:
Remove my manually installed version of protoc. Run `make` without these
changes to install the latest homebrew version. After the changes, run
`make` and verify that the homebrew version is uninstalled and the
custom version is installed instead. Run `make` one last time to verify
that "protoc already installed".

Reviewers: csilvers, adamgoforth, benkraft

Reviewed By: csilvers

Differential Revision: https://phabricator.khanacademy.org/D57167
  • Loading branch information
dnerdy committed Aug 29, 2019
1 parent 30f409f commit 0d64ca2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 37 deletions.
30 changes: 3 additions & 27 deletions linux-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,33 +199,9 @@ EOF
}

install_protoc() {
# We use protocol buffers in webapp's event log stream infrastructure. This
# installs the protocol buffer compiler (which generates python & java code
# from the protocol buffer definitions), as well as a go-based compiler
# plugin that allows us to generate bigquery schemas as well.

if ! which protoc >/dev/null || ! protoc --version | grep -q 3.4.0; then
# TODO(colin): I didn't see a good-looking ppa for the protbuf compiler.
# Look a bit harder to see if there's a better way to keep this up to date?
mkdir -p /tmp/protoc
wget -O/tmp/protoc/protoc-3.4.0.zip https://github.com/google/protobuf/releases/download/v3.4.0/protoc-3.4.0-linux-x86_64.zip
(
cd /tmp/protoc
unzip protoc-3.4.0.zip
# This puts the compiler itself into ./bin/protoc and several
# definitions into ./include/google/protobuf/**
# we move them both into /usr/local
sudo install -m755 ./bin/protoc /usr/local/bin
# Remove old versions of the includes, if they exist
sudo rm -rf /usr/local/include/google/protobuf || true
sudo mkdir -p /usr/local/include/google
sudo mv ./include/google/protobuf /usr/local/include/google/
sudo chmod -R a+rX /usr/local/include/google/protobuf
)
rm -fr /tmp/protoc
else
echo "protoc already installed"
fi
# The linux and mac installation process is the same aside from the
# platform-dependent zip archive.
install_protoc_common https://github.com/google/protobuf/releases/download/v3.4.0/protoc-3.4.0-linux-x86_64.zip
}

install_watchman() {
Expand Down
19 changes: 9 additions & 10 deletions mac-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,17 @@ install_helpful_tools() {
fi
}

# TODO(csilvers): make sure we have the right version of protoc, somehow
install_protoc() {
# We use protocol buffers in webapp's event log stream infrastructure. This
# installs the protocol buffer compiler (which generates python & java code
# from the protocol buffer definitions), as well as a go-based compiler
# plugin that allows us to generate bigquery schemas as well.
if ! brew ls protobuf >/dev/null 2>&1; then
info "Installing protoc\n"
brew install protobuf
else
success "protoc already installed"
# If the user has a homebrew version of protobuf installed, uninstall it so
# we can manually install our own version in /usr/local.
if brew list | grep -q '^protobuf$'; then
info "Uninstalling homebrew version of protobuf\n"
brew uninstall protobuf
fi

# The mac and linux installation process is the same from here on out aside
# from the platform-dependent zip archive.
install_protoc_common https://github.com/protocolbuffers/protobuf/releases/download/v3.4.0/protoc-3.4.0-osx-x86_64.zip
}

install_python_tools() {
Expand Down
42 changes: 42 additions & 0 deletions shared-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,48 @@ install_mac_java() {
fi
}

install_protoc_common() {
# Platform independent installation of protoc.
# usage: install_protoc_common <zip_url>

# The URL of the protoc zip file is passed as the first argument to this
# function. This file is platform dependent.
zip_url=$1

# We use protocol buffers in webapp's event log stream infrastructure. This
# installs the protocol buffer compiler (which generates python & java code
# from the protocol buffer definitions), as well as a go-based compiler
# plugin that allows us to generate bigquery schemas as well.

if ! which protoc >/dev/null || ! protoc --version | grep -q 3.4.0; then
echo "Installing protoc"
mkdir -p /tmp/protoc
wget -O /tmp/protoc/protoc-3.4.0.zip "$zip_url"
# Change directories within a subshell so that we don't have to worry
# about changing back to the current directory when done.
(
cd /tmp/protoc
# This puts the compiler itself into ./bin/protoc and several
# definitions into ./include/google/protobuf we move them both
# into /usr/local.
unzip -q protoc-3.4.0.zip
# Move the protoc binary to the final location and set the
# permissions as needed.
sudo install -m755 ./bin/protoc /usr/local/bin
# Remove old versions of the includes, if they exist
sudo rm -rf /usr/local/include/google/protobuf
sudo mkdir -p /usr/local/include/google
# Move the protoc include files to the final location and set the
# permissions as needed.
sudo mv ./include/google/protobuf /usr/local/include/google/
sudo chmod -R a+rX /usr/local/include/google/protobuf
)
rm -rf /tmp/protoc
else
echo "protoc already installed"
fi
}

# Evaluates to truthy if go is installed and >1.12 (we need module
# support). Evaluates to falsey else.
has_recent_go() {
Expand Down

0 comments on commit 0d64ca2

Please sign in to comment.