Fixed ./configure on Windows (#4449)
* 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
This commit is contained in:
parent
d6031a17b1
commit
629c799660
@ -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");
|
||||
@ -30,6 +30,7 @@ from __future__ import print_function
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import shutil
|
||||
|
||||
|
||||
@ -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:
|
||||
@ -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())
|
||||
@ -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)
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user