提交 93ef10bc authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #4773 from ruslanagit/master

Add support for spaces in paths
...@@ -439,6 +439,9 @@ if param != "": ...@@ -439,6 +439,9 @@ if param != "":
del newp del newp
del distutils del distutils
# to support path that includes spaces, we need to wrap it with double quotes on Windows
if param and os.name == 'nt':
param = '"%s"' % param
AddConfigVar('cxx', AddConfigVar('cxx',
"The C++ compiler to use. Currently only g++ is" "The C++ compiler to use. Currently only g++ is"
" supported, but supporting additional compilers should not be " " supported, but supporting additional compilers should not be "
...@@ -1177,7 +1180,7 @@ def default_blas_ldflags(): ...@@ -1177,7 +1180,7 @@ def default_blas_ldflags():
use_unix_epd = True use_unix_epd = True
if sys.platform == 'win32': if sys.platform == 'win32':
return ' '.join( return ' '.join(
['-L%s' % os.path.join(sys.prefix, "Scripts")] + ['-L"%s"' % os.path.join(sys.prefix, "Scripts")] +
# Why on Windows, the library used are not the # Why on Windows, the library used are not the
# same as what is in # same as what is in
# blas_info['libraries']? # blas_info['libraries']?
...@@ -1247,7 +1250,7 @@ def default_blas_ldflags(): ...@@ -1247,7 +1250,7 @@ def default_blas_ldflags():
['-l%s' % l for l in blas_info['libraries']]) ['-l%s' % l for l in blas_info['libraries']])
elif sys.platform == 'win32': elif sys.platform == 'win32':
return ' '.join( return ' '.join(
['-L%s' % lib_path] + ['-L"%s"' % lib_path] +
# Why on Windows, the library used are not the # Why on Windows, the library used are not the
# same as what is in blas_info['libraries']? # same as what is in blas_info['libraries']?
['-l%s' % l for l in ["mk2_core", "mk2_intel_thread", ['-l%s' % l for l in ["mk2_core", "mk2_intel_thread",
...@@ -1268,7 +1271,7 @@ def default_blas_ldflags(): ...@@ -1268,7 +1271,7 @@ def default_blas_ldflags():
else: else:
# This branch is executed if no exception was raised # This branch is executed if no exception was raised
lib_path = os.path.join(sys.prefix, 'DLLs') lib_path = os.path.join(sys.prefix, 'DLLs')
flags = ['-L%s' % lib_path] flags = ['-L"%s"' % lib_path]
flags += ['-l%s' % l for l in ["mkl_core", flags += ['-l%s' % l for l in ["mkl_core",
"mkl_intel_thread", "mkl_intel_thread",
"mkl_rt"]] "mkl_rt"]]
...@@ -1276,13 +1279,15 @@ def default_blas_ldflags(): ...@@ -1276,13 +1279,15 @@ def default_blas_ldflags():
if res: if res:
return res return res
# to support path that includes spaces, we need to wrap it with double quotes on Windows
path_wrapper = "\"" if os.name == 'nt' else ""
ret = ( ret = (
# TODO: the Gemm op below should separate the # TODO: the Gemm op below should separate the
# -L and -l arguments into the two callbacks # -L and -l arguments into the two callbacks
# that CLinker uses for that stuff. for now, # that CLinker uses for that stuff. for now,
# we just pass the whole ldflags as the -l # we just pass the whole ldflags as the -l
# options part. # options part.
['-L%s' % l for l in blas_info.get('library_dirs', [])] + ['-L%s%s%s' % (path_wrapper, l, path_wrapper) for l in blas_info.get('library_dirs', [])] +
['-l%s' % l for l in blas_info.get('libraries', [])] + ['-l%s' % l for l in blas_info.get('libraries', [])] +
blas_info.get('extra_link_args', [])) blas_info.get('extra_link_args', []))
# For some very strange reason, we need to specify -lm twice # For some very strange reason, we need to specify -lm twice
...@@ -1343,7 +1348,11 @@ def try_blas_flag(flags): ...@@ -1343,7 +1348,11 @@ def try_blas_flag(flags):
return 0; return 0;
} }
""") """)
cflags = flags + ['-L' + d for d in theano.gof.cmodule.std_lib_dirs()] cflags = flags
# to support path that includes spaces, we need to wrap it with double quotes on Windows
path_wrapper = "\"" if os.name == 'nt' else ""
cflags.extend(['-L%s%s%s' % (path_wrapper, d, path_wrapper) for d in theano.gof.cmodule.std_lib_dirs()])
res = GCC_compiler.try_compile_tmp( res = GCC_compiler.try_compile_tmp(
test_code, tmp_prefix='try_blas_', test_code, tmp_prefix='try_blas_',
flags=cflags, try_run=True) flags=cflags, try_run=True)
......
...@@ -2251,7 +2251,10 @@ class GCC_compiler(Compiler): ...@@ -2251,7 +2251,10 @@ class GCC_compiler(Compiler):
cmd.extend(p for p in preargs if not p.startswith('-O')) cmd.extend(p for p in preargs if not p.startswith('-O'))
else: else:
cmd.extend(preargs) cmd.extend(preargs)
cmd.extend('-I%s' % idir for idir in include_dirs) # to support path that includes spaces, we need to wrap it with double quotes on Windows
path_wrapper = "\"" if os.name == 'nt' else ""
cmd.extend(['-I%s%s%s' % (path_wrapper, idir, path_wrapper) for idir in include_dirs])
cmd.extend(['-L%s%s%s' % (path_wrapper, ldir, path_wrapper) for ldir in lib_dirs])
if hide_symbols and sys.platform != 'win32': if hide_symbols and sys.platform != 'win32':
# This has been available since gcc 4.0 so we suppose it # This has been available since gcc 4.0 so we suppose it
# is always available. We pass it here since it # is always available. We pass it here since it
...@@ -2262,7 +2265,6 @@ class GCC_compiler(Compiler): ...@@ -2262,7 +2265,6 @@ class GCC_compiler(Compiler):
cmd.append('-fvisibility=hidden') cmd.append('-fvisibility=hidden')
cmd.extend(['-o', lib_filename]) cmd.extend(['-o', lib_filename])
cmd.append(cppfilename) cmd.append(cppfilename)
cmd.extend(['-L%s' % ldir for ldir in lib_dirs])
cmd.extend(['-l%s' % l for l in libs]) cmd.extend(['-l%s' % l for l in libs])
# print >> sys.stderr, 'COMPILING W CMD', cmd # print >> sys.stderr, 'COMPILING W CMD', cmd
_logger.debug('Running cmd: %s', ' '.join(cmd)) _logger.debug('Running cmd: %s', ' '.join(cmd))
......
...@@ -24,6 +24,12 @@ def subprocess_Popen(command, **params): ...@@ -24,6 +24,12 @@ def subprocess_Popen(command, **params):
# execute "g++" without extensions. # execute "g++" without extensions.
# (Executing "g++.bat" explicitly would also work.) # (Executing "g++.bat" explicitly would also work.)
params['shell'] = True params['shell'] = True
# "If shell is True, it is recommended to pass args as a string rather than as a sequence." (cite taken from https://docs.python.org/2/library/subprocess.html#frequently-used-arguments)
# In case when command arguments have spaces, passing a command as a list will result in incorrect arguments break down, and consequently
# in "The filename, directory name, or volume label syntax is incorrect" error message.
# Passing the command as a single string solves this problem.
if isinstance(command, list):
command = ' '.join(command)
# Using the dummy file descriptors below is a workaround for a # Using the dummy file descriptors below is a workaround for a
# crash experienced in an unusual Python 2.4.4 Windows environment # crash experienced in an unusual Python 2.4.4 Windows environment
......
...@@ -299,11 +299,14 @@ def dnn_available(): ...@@ -299,11 +299,14 @@ def dnn_available():
return 1; return 1;
} }
""") """)
params = ["-l", "cudnn", "-I" + os.path.dirname(__file__)] # to support path that includes spaces, we need to wrap it with double quotes on Windows
path_wrapper = "\"" if os.name =='nt' else ""
params = ["-l", "cudnn"]
params.extend(['-I%s%s%s' % (path_wrapper, os.path.dirname(__file__), path_wrapper)])
if config.dnn.include_path: if config.dnn.include_path:
params.append("-I" + config.dnn.include_path) params.extend(['-I%s%s%s' % (path_wrapper, config.dnn.include_path, path_wrapper)])
if config.dnn.library_path: if config.dnn.library_path:
params.append("-L" + config.dnn.library_path) params.extend(['-L%s%s%s' % (path_wrapper, config.dnn.library_path, path_wrapper)])
if config.nvcc.compiler_bindir: if config.nvcc.compiler_bindir:
params.extend(['--compiler-bindir', params.extend(['--compiler-bindir',
config.nvcc.compiler_bindir]) config.nvcc.compiler_bindir])
......
...@@ -321,10 +321,12 @@ class NVCC_compiler(Compiler): ...@@ -321,10 +321,12 @@ class NVCC_compiler(Compiler):
# the -rpath option is not understood by the Microsoft linker # the -rpath option is not understood by the Microsoft linker
for rpath in rpaths: for rpath in rpaths:
cmd.extend(['-Xlinker', ','.join(['-rpath', rpath])]) cmd.extend(['-Xlinker', ','.join(['-rpath', rpath])])
cmd.extend('-I%s' % idir for idir in include_dirs) # to support path that includes spaces, we need to wrap it with double quotes on Windows
path_wrapper = "\"" if os.name == 'nt' else ""
cmd.extend(['-I%s%s%s' % (path_wrapper, idir, path_wrapper) for idir in include_dirs])
cmd.extend(['-L%s%s%s' % (path_wrapper, ldir, path_wrapper) for ldir in lib_dirs])
cmd.extend(['-o', lib_filename]) cmd.extend(['-o', lib_filename])
cmd.append(os.path.split(cppfilename)[-1]) cmd.append(os.path.split(cppfilename)[-1])
cmd.extend(['-L%s' % ldir for ldir in lib_dirs])
cmd.extend(['-l%s' % l for l in libs]) cmd.extend(['-l%s' % l for l in libs])
if sys.platform == 'darwin': if sys.platform == 'darwin':
# This tells the compiler to use the already-loaded python # This tells the compiler to use the already-loaded python
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论