Browse Source

wscript: now waf builds extras archive by itself, using Python standard library's zipfile

pull/2/head
Alibek Omarov 2 years ago
parent
commit
686a966ff7
  1. 53
      scripts/waifulib/zip.py
  2. 1
      wscript

53
scripts/waifulib/zip.py

@ -0,0 +1,53 @@ @@ -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)

1
wscript

@ -39,6 +39,7 @@ SUBDIRS = [ @@ -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),

Loading…
Cancel
Save