Skip to content

Commit

Permalink
Fix python support problems caused by building script errors.
Browse files Browse the repository at this point in the history
Summary:
When trying to build caffe2 with python provided by homebrew, I find out there are some errors in the building scripts. The "get_python_cmake_flags.py" script is supposed to find out the correct python library and header file locations. However, due to these errors, this script does not function correctly. After building, caffe2 is linked against the default python library provided by Apple which causes a crash when trying to validate whether or not the installation is successful:
```shell
python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
```
The fix is as simple as follows:

- Add "shell" so that command substitution could work under Makefile.

- Add blank spaces between -D options so that they are treated as options not makefile targets.

- Print the "flags" variable without the newline character so that they could be utilized by command substitution correctly.
Closes facebookarchive/caffe2#391

Differential Revision: D4943212

Pulled By: Yangqing

fbshipit-source-id: 04d3595fa2d89fe57aed5b6a7a91a95114a82a1b
  • Loading branch information
yangyanzhan authored and facebook-github-bot committed Apr 25, 2017
1 parent 902409b commit 2994dd6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This makefile does nothing but delegating the actual building to cmake.

all:
@mkdir -p build && cd build && cmake .. $(python ./scripts/get_python_cmake_flags.py) && $(MAKE)
@mkdir -p build && cd build && cmake .. $(shell python ./scripts/get_python_cmake_flags.py) && $(MAKE)

local:
@./scripts/build_local.sh
Expand Down
6 changes: 4 additions & 2 deletions scripts/get_python_cmake_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
if sys.platform == "darwin":
lib = os.path.dirname(lib) + '/Python'
if os.path.isfile(lib):
flags += '-DPYTHON_LIBRARY={lib}'.format(lib=lib)
flags += '-DPYTHON_LIBRARY={lib} '.format(lib=lib)

if os.path.isfile(inc + '/Python.h'):
flags += '-DPYTHON_INCLUDE_DIR={inc}'.format(inc=inc)
flags += '-DPYTHON_INCLUDE_DIR={inc} '.format(inc=inc)

print(flags, end='')

0 comments on commit 2994dd6

Please sign in to comment.