-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify setup.py to build protos on Windows #723
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
from distutils.command.build import build | ||
from distutils.command.clean import clean | ||
from distutils.cmd import Command | ||
from distutils.spawn import find_executable | ||
from setuptools import find_packages | ||
from setuptools import setup | ||
from setuptools.command.test import test | ||
|
@@ -51,7 +52,6 @@ class BuildProtoCommand(Command): | |
('outdir=', 'o', 'Where to output .py files.')] | ||
|
||
def initialize_options(self): | ||
self.skip_proto = False | ||
try: | ||
prefix = subprocess.check_output( | ||
'pkg-config --variable prefix protobuf'.split()).strip().decode('utf-8') | ||
|
@@ -63,30 +63,29 @@ def initialize_options(self): | |
# Default to /usr/local for Homebrew | ||
prefix = '/usr/local' | ||
else: | ||
print('Warning: mfg-inspector output is not fully implemented for ' | ||
'Windows. OpenHTF will be installed without it.') | ||
self.skip_proto = True | ||
prefix = None | ||
|
||
maybe_protoc = os.path.join(prefix, 'bin', 'protoc') | ||
if os.path.isfile(maybe_protoc) and os.access(maybe_protoc, os.X_OK): | ||
self.protoc = None | ||
if prefix: | ||
maybe_protoc = os.path.join(prefix, 'bin', 'protoc') | ||
if os.path.isfile(maybe_protoc) and os.access(maybe_protoc, os.X_OK): | ||
self.protoc = maybe_protoc | ||
else: | ||
else: | ||
print('Warning: protoc not found at %s' % maybe_protoc) | ||
print('setup will attempt to run protoc with no prefix.') | ||
self.protoc = 'protoc' | ||
|
||
self.protodir = os.path.join(prefix, 'include') | ||
if not self.protoc: | ||
self.protoc = find_executable('protoc') | ||
pc_path = os.path.dirname(find_executable('protoc')) | ||
self.protodir = os.path.abspath(os.path.join(os.path.dirname(pc_path), os.path.pardir, 'lib')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not familiar with protos on Windows, but this looks a bit suspicious, in that you're going up two directory levels and assuming that If you expect If you actually want to go up two directories then this should be cleaned up as: self.protoc = find_executable('protoc')
self.protodir = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(self.protoc))), 'lib') |
||
else: | ||
self.protodir = os.path.join(prefix, 'include') | ||
self.indir = os.getcwd() | ||
self.outdir = os.getcwd() | ||
|
||
def finalize_options(self): | ||
pass | ||
|
||
def run(self): | ||
if self.skip_proto: | ||
print('Skipping building protocol buffers.') | ||
return | ||
|
||
# Build regular proto files. | ||
protos = glob.glob( | ||
os.path.join(self.indir, 'openhtf', 'output', 'proto', '*.proto')) | ||
|
@@ -109,6 +108,10 @@ def run(self): | |
'"protobuf-compiler" and "libprotobuf-dev" packages.') | ||
elif sys.platform == 'darwin': | ||
print('On Mac, protobuf is often installed via homebrew.') | ||
else: | ||
print('On Windows, protoc should be installed and added ' | ||
'to the path. Pre-built binaries can be found at ' | ||
'https://github.com/google/protobuf/releases') | ||
raise | ||
except subprocess.CalledProcessError: | ||
print('Could not build proto files.') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With these changes, Mac and Linux will fallback to using the Windows logic if
maybe_protoc
is not found. This doesn't seem right. For example, the proto dir should remain asos.path.join(prefix, 'include')
on Mac/Linux instead of using/usr/lib/
.It seems like the Mac/Linux logic should remain unchanged by this PR, so I suggest restructuring the flow control to something like: