blob: 27b20949e813c73560285f1f015ce394e56118d9 [file] [log] [blame]
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -08001#!/bin/bash
Vijay Vasudevana4806a32015-12-03 10:26:25 -08002# Copyright 2015 Google Inc. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15# ==============================================================================
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080016
17set -e -o errexit
18
19EXPECTED_PATHS="util/python/python_include util/python/python_lib third_party/py/numpy/numpy_include"
20
21function main {
22 argument="$1"
23 shift
24 case $argument in
25 --check)
26 check_python
27 exit 0
28 ;;
29 --setup)
30 setup_python "$1"
31 exit 0
32 ;;
33 esac
34}
35
36function setup_python {
37 PYTHON_BIN_PATH="$1";
38
39 if [ -z "$PYTHON_BIN_PATH" ]; then
40 echo "PYTHON_BIN_PATH was not provided. Did you run configure?"
41 exit 1
42 fi
43 if [ ! -x "$PYTHON_BIN_PATH" ] || [ -d "$PYTHON_BIN_PATH" ]; then
44 echo "PYTHON_BIN_PATH is not executable. Is it the python binary?"
45 exit 1
46 fi
47
48 local python_include=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; from distutils import sysconfig; print(sysconfig.get_python_inc());')
49 if [ "$python_include" == "" ]; then
50 echo -e "\n\nERROR: Problem getting python include path. Is distutils installed?"
51 exit 1
52 fi
53 local python_lib=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; from distutils import sysconfig; print(sysconfig.get_python_lib());')
54 if [ "$python_lib" == "" ]; then
55 echo -e "\n\nERROR: Problem getting python lib path. Is distutils installed?"
56 exit 1
57 fi
58 local numpy_include=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import numpy; print(numpy.get_include());')
59 if [ "$numpy_include" == "" ]; then
60 echo -e "\n\nERROR: Problem getting numpy include path. Is numpy installed?"
61 exit 1
62 fi
63
64 for x in $EXPECTED_PATHS; do
65 if [ -e "$x" ]; then
66 rm "$x"
67 fi
68 done
69
70 ln -s "${python_include}" util/python/python_include
71 ln -s "${python_lib}" util/python/python_lib
72 ln -s "${numpy_include}" third_party/py/numpy/numpy_include
73}
74
75function check_python {
76 for x in $EXPECTED_PATHS; do
77 if [ ! -e "$x" ]; then
78 echo -e "\n\nERROR: Cannot find '${x}'. Did you run configure?\n\n" 1>&2
79 exit 1
80 fi
81 if [ ! -L "${x}" ]; then
82 echo -e "\n\nERROR: '${x}' is not a symbolic link. Internal error.\n\n" 1>&2
83 exit 1
84 fi
85 true_path=$(readlink "${x}")
86 if [ ! -d "${true_path}" ]; then
87 echo -e "\n\nERROR: '${x}' does not refer to an existing directory: ${true_path}. Do you need to rerun configure?\n\n" 1>&2
88 exit 1
89 fi
90 done
91}
92
93main "$@"