Add a option to kiwix-build.py to clean intermediate directories.

Travis fails if we try to build a lot of targets in the same job because
of quota limit. By removing intermediate build files, we limit our disk
usage.
This commit is contained in:
Matthieu Gautier 2017-04-24 15:26:28 +02:00
parent 86c1547f88
commit 3beb6d81f2
1 changed files with 18 additions and 0 deletions

View File

@ -213,6 +213,16 @@ class BuildEnv:
self.libprefix = options.libprefix or self._detect_libdir() self.libprefix = options.libprefix or self._detect_libdir()
self.targetsDict = targetsDict self.targetsDict = targetsDict
def clean_intermediate_directories(self):
for subdir in os.listdir(self.build_dir):
subpath = pj(self.build_dir, subdir)
if subpath == self.install_dir:
continue
if os.path.isdir(subpath):
shutil.rmtree(subpath)
else:
os.remove(subpath)
def detect_platform(self): def detect_platform(self):
_platform = platform.system() _platform = platform.system()
self.distname = _platform self.distname = _platform
@ -837,6 +847,12 @@ class Builder:
self.prepare_sources() self.prepare_sources()
print("[BUILD]") print("[BUILD]")
self.build() self.build()
# No error, clean intermediate file at end of build if needed.
print("[CLEAN]")
if self.buildEnv.options.clean_at_end:
self.buildEnv.clean_intermediate_directories()
else:
print("SKIP")
except StopBuild: except StopBuild:
sys.exit("Stopping build due to errors") sys.exit("Stopping build due to errors")
@ -857,6 +873,8 @@ def parse_args():
help="Skip the source download part") help="Skip the source download part")
parser.add_argument('--build-deps-only', action='store_true', parser.add_argument('--build-deps-only', action='store_true',
help=("Build only the dependencies of the specified targets.")) help=("Build only the dependencies of the specified targets."))
parser.add_argument('--clean-at-end', action='store_true',
help="Clean all intermediate files after the (successfull) build")
return parser.parse_args() return parser.parse_args()