From 686a966ff7e532ec9b148aaedfc1d3b365c13d46 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 11 Sep 2022 01:39:29 +0300 Subject: [PATCH] wscript: now waf builds extras archive by itself, using Python standard library's zipfile --- scripts/waifulib/zip.py | 53 +++++++++++++++++++++++++++++++++++++++++ wscript | 1 + 2 files changed, 54 insertions(+) create mode 100644 scripts/waifulib/zip.py diff --git a/scripts/waifulib/zip.py b/scripts/waifulib/zip.py new file mode 100644 index 00000000..119f028b --- /dev/null +++ b/scripts/waifulib/zip.py @@ -0,0 +1,53 @@ +#! /usr/bin/env python +# encoding: utf-8 + +from waflib import TaskGen, Task, Logs +import zipfile + +class ziparchive(Task.Task): + color = 'YELLOW' + + def __str__(self): + tgt_str = ' '.join([a.path_from(a.ctx.launch_node()) for a in self.outputs]) + count = len(self.inputs) + return '%s: %d files -> %s' % (self.__class__.__name__, count, tgt_str) + + def keyword(self): + return 'Creating' + + def run(self): + outfile = self.outputs[0].path_from(self.outputs[0].ctx.launch_node()) + comp = zipfile.ZIP_STORED if self.compresslevel == 0 else zipfile.ZIP_DEFLATED + + with zipfile.ZipFile(outfile, mode='w', + compression=comp, compresslevel=self.compresslevel, + strict_timestamps=False) as zf: + + for src in self.inputs: + infile = src.path_from(src.ctx.launch_node()) + arcfile = src.path_from(self.relative_to) + + Logs.debug('%s: %s <- %s as %s', self.__class__.__name__, outfile, infile, arcfile) + zf.write(infile, arcfile) + +@TaskGen.feature('zip') +def create_zip_archive(self): + compresslevel = getattr(self, 'compresslevel', 6) # 6 is zip default + if compresslevel < 0 or compresslevel > 9: + self.fatal('Invalid compress level') + + files = getattr(self, 'files', None) + if not files: + self.fatal('No files to archive') + + relative_to = getattr(self, 'relative_to', None) + if not relative_to: + self.fatal('No relative directory supplied') + + self.path.get_bld().mkdir() + target = self.path.get_bld().make_node(self.name) + + tsk = self.create_task('ziparchive', files, target) + + setattr(tsk, 'compresslevel', compresslevel) + setattr(tsk, 'relative_to', relative_to) diff --git a/wscript b/wscript index dfda447a..b8916809 100644 --- a/wscript +++ b/wscript @@ -39,6 +39,7 @@ SUBDIRS = [ Subproject('dllemu'), # disable only by engine feature, makes no sense to even parse subprojects in dedicated mode + Subproject('3rdparty/extras', lambda x: not x.env.DEDICATED), Subproject('3rdparty/nanogl', lambda x: not x.env.DEDICATED and x.env.NANOGL), Subproject('3rdparty/gl-wes-v2', lambda x: not x.env.DEDICATED and x.env.GLWES), Subproject('3rdparty/gl4es', lambda x: not x.env.DEDICATED and x.env.GL4ES),