Skip to content

Commit

Permalink
Fixed ./configure on Windows (tensorflow#4449)
Browse files Browse the repository at this point in the history
* Fixed ./configure on Windows

Basically, symlink doesn't work on Windows

* Fixed shebang of gen_git_source.py

* gen_git_source.py: Replace os.popen with subprocess.check_output

os.popen doesn't work with Bazel properly on Windows, due to this error:
    RuntimeError: Cannot locate a COMSPEC environment variable to use as the shell
  • Loading branch information
meteorcloudy authored and mrry committed Sep 19, 2016
1 parent d6031a1 commit 629c799
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
15 changes: 9 additions & 6 deletions tensorflow/tools/git/gen_git_source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -30,6 +30,7 @@
import argparse
import json
import os
import subprocess
import shutil


Expand Down Expand Up @@ -111,7 +112,10 @@ def configure(src_base_path, debug=False):
if src is None:
open(os.path.join(gen_path, target), "w").write("")
else:
os.symlink(src, os.path.join(gen_path, target))
if hasattr(os, 'symlink'):
os.symlink(src, os.path.join(gen_path, target))
else:
shutil.copy2(src, os.path.join(gen_path, target))

json.dump(spec, open(os.path.join(gen_path, "spec.json"), "w"), indent=2)
if debug:
Expand Down Expand Up @@ -157,9 +161,8 @@ def generate(arglist):
raise RuntimeError(
"Run ./configure again, branch was '%s' but is now '%s'" %
(old_branch, new_branch))
strs["tf_git_version"] = os.popen(
"git -C \"%s\" describe --long --dirty --tags" %
(data["path"],)).read().strip()
strs["tf_git_version"] = subprocess.check_output(
["git", "-C", data["path"], "describe", "--long", "--dirty", "--tags"]).strip()
# TODO(aselle): Check for escaping
cpp_file = "\n".join("const char* %s() {return \"%s\";}" % (x, y)
for x, y in strs.items())
Expand All @@ -177,7 +180,7 @@ def raw_generate(output_file):
"""

strs = {"tf_compiler_version": "__VERSION__"}
version = os.popen("git describe --long --dirty --tags").read().strip()
version = subprocess.check_output(["git", "describe", "--long", "--dirty", "--tags"]).strip()
version = version if version else "unknown"
strs["tf_git_version"] = version
cpp_file = "\n".join("const char* %s() {return \"%s\";}" % (x, y)
Expand Down
18 changes: 16 additions & 2 deletions util/python/python_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ function setup_python {

for x in $EXPECTED_PATHS; do
if [ -e "$x" ]; then
rm "$x"
# This makes ./configure slow on Windows, but it works.
rm -rf "$x"
fi
done

# ln -sf is acutally implemented as copying in msys since creating symbolic links is privileged on Windows
# So we need -rf to remove them above.
ln -sf "${python_include}" util/python/python_include
ln -sf "${python_lib}" util/python/python_lib
ln -sf "${numpy_include}" third_party/py/numpy/numpy_include
Expand All @@ -159,13 +162,24 @@ function setup_python {
echo "export PYTHON_BIN_PATH=$PYTHON_BIN_PATH" > tools/python_bin_path.sh
}

PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
function is_windows() {
# On windows, the shell script is actually running in msys
if [[ "${PLATFORM}" =~ msys_nt* ]]; then
true
else
false
fi
}

function check_python {
for x in $EXPECTED_PATHS; do
if [ ! -e "$x" ]; then
echo -e "\n\nERROR: Cannot find '${x}'. Did you run configure?\n\n" 1>&2
exit 1
fi
if [ ! -L "${x}" ]; then
# Don't check symbolic link on Windows
if ! is_windows && [ ! -L "${x}" ]; then
echo -e "\n\nERROR: '${x}' is not a symbolic link. Internal error.\n\n" 1>&2
exit 1
fi
Expand Down

0 comments on commit 629c799

Please sign in to comment.