From 4e687671a5047a26e95d0b22dd0f97d4581a5d9d Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Sun, 10 Feb 2019 14:25:20 -0800 Subject: [PATCH] Tweak python setup.py clean to properly clean the native build --- src/api/python/setup.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/api/python/setup.py b/src/api/python/setup.py index 9939f5962..2d5e5c75d 100644 --- a/src/api/python/setup.py +++ b/src/api/python/setup.py @@ -10,6 +10,7 @@ from distutils.util import get_platform from distutils.errors import LibError from distutils.command.build import build as _build from distutils.command.sdist import sdist as _sdist +from distutils.command.clean import clean as _clean from setuptools.command.develop import develop as _develop from setuptools.command.bdist_egg import bdist_egg as _bdist_egg @@ -37,13 +38,23 @@ else: LIBRARY_FILE = "libz3.so" EXECUTABLE_FILE = "z3" +def rmtree(tree): + if os.path.exists(tree): + shutil.rmtree(tree, ignore_errors=False) + def _clean_bins(): """ Clean up the binary files and headers that are installed along with the bindings """ - shutil.rmtree(LIBS_DIR, ignore_errors=True) - shutil.rmtree(BINS_DIR, ignore_errors=True) - shutil.rmtree(HEADERS_DIR, ignore_errors=True) + rmtree(LIBS_DIR) + rmtree(BINS_DIR) + rmtree(HEADERS_DIR) + +def _clean_native_build(): + """ + Clean the "build" directory in the z3 native root + """ + rmtree(BUILD_DIR) def _z3_version(): post = os.getenv('Z3_VERSION_SUFFIX', '') @@ -146,10 +157,16 @@ class bdist_egg(_bdist_egg): class sdist(_sdist): def run(self): - self.execute(_clean_bins, (), msg="Cleaning binary files") + self.execute(_clean_bins, (), msg="Cleaning binary files and headers") self.execute(_copy_sources, (), msg="Copying source files") _sdist.run(self) +class clean(_clean): + def run(self): + self.execute(_clean_bins, (), msg="Cleaning binary files and headers") + self.execute(_clean_native_build, (), msg="Cleaning native build") + _clean.run(self) + # the build directory needs to exist #try: os.makedirs(os.path.join(ROOT_DIR, 'build')) #except OSError: pass @@ -191,5 +208,5 @@ setup( 'z3': [os.path.join('lib', '*'), os.path.join('include', '*.h'), os.path.join('include', 'c++', '*.h')] }, data_files=[('bin',[os.path.join('bin',EXECUTABLE_FILE)])], - cmdclass={'build': build, 'develop': develop, 'sdist': sdist, 'bdist_egg': bdist_egg}, + cmdclass={'build': build, 'develop': develop, 'sdist': sdist, 'bdist_egg': bdist_egg, 'clean': clean}, )