Fix Error when run python setup.py install again on Windows (#59689)

Summary:
Fix https://github.com/pytorch/pytorch/issues/59688

So far, .build.ninja should be removed before building the source code on Windows at any time

Pull Request resolved: https://github.com/pytorch/pytorch/pull/59689

Reviewed By: bdhirsh

Differential Revision: D29032960

Pulled By: walterddr

fbshipit-source-id: 2b8162cd119820d3b6d8715745ec29b9c381e01f
This commit is contained in:
Yi Zhang 2021-06-10 12:19:13 -07:00 committed by Facebook GitHub Bot
parent 1fc3576d97
commit cc32dcadd9

View File

@ -178,17 +178,19 @@ class CMake:
if rerun and os.path.isfile(self._cmake_cache_file):
os.remove(self._cmake_cache_file)
ninja_build_file = os.path.join(self.build_dir, 'build.ninja')
if os.path.exists(self._cmake_cache_file) and not (
USE_NINJA and not os.path.exists(ninja_build_file)):
# Everything's in place. Do not rerun.
return
ninja_deps_file = os.path.join(self.build_dir, '.ninja_deps')
if IS_WINDOWS and USE_NINJA and os.path.exists(ninja_deps_file):
# Cannot rerun ninja on Windows due to a ninja bug.
# The workaround is to remove `.ninja_deps`.
os.remove(ninja_deps_file)
ninja_build_file = os.path.join(self.build_dir, 'build.ninja')
if os.path.exists(self._cmake_cache_file) and not (
USE_NINJA and not os.path.exists(ninja_build_file)):
# Everything's in place. Do not rerun.
return
args = []
if USE_NINJA:
# Avoid conflicts in '-G' and the `CMAKE_GENERATOR`