message: Provide an unique dir for each compiling action to avoid conflicts.
diff: @@ -28,6 +28,7 @@ import subprocess
  import re
  import sys
  import pipes
  +import tempfile
  # Template values set by cuda_autoconf.
  CPU_COMPILER = ('%{cpu_compiler}')
  @@ -145,15 +146,17 @@ def InvokeNvcc(argv, log=False):
  nvccopts += m_options
  nvccopts += ['--compiler-options="' + " ".join(host_compiler_options) + '"']
  nvccopts += ['-x', 'cu'] + opt + includes + out + ['-c'] + src_files
  - # If we don't specify --keep-dir, nvcc will generate intermediate files under TEMP
  - # Put them under NVCC_TEMP_DIR instead, then Bazel can ignore files under NVCC_TEMP_DIR during dependency check
  + # Specify an unique temp directory for nvcc to generate intermediate files,
  + # then Bazel can ignore files under NVCC_TEMP_DIR during dependency check
  # http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#options-for-guiding-compiler-driver
  # Different actions are sharing NVCC_TEMP_DIR, so we cannot remove it if the directory already exists.
  if os.path.isfile(NVCC_TEMP_DIR):
  os.remove(NVCC_TEMP_DIR)
  if not os.path.exists(NVCC_TEMP_DIR):
  os.makedirs(NVCC_TEMP_DIR)
  - nvccopts += ['--keep', '--keep-dir', NVCC_TEMP_DIR]
  + # Provide an unique dir for each compiling action to avoid conflicts.
  + tempdir = tempfile.mkdtemp(dir = NVCC_TEMP_DIR)
  + nvccopts += ['--keep', '--keep-dir', tempdir]
  cmd = [NVCC_PATH] + nvccopts
  if log:
  Log(cmd)
  