Commit 0571cb2e authored by dylan grafmyre's avatar dylan grafmyre
Browse files

fix supervisor to work with bspzip

parent c08c81c3
......@@ -16,8 +16,8 @@ VIS_FLAGS?=$(VBIN_FLAGS) -fast
RAD_BIN?=$(SUPERVISE_V_BIN) $(VBIN_DIR)vrad.exe
RAD_FLAGS?=$(VBIN_FLAGS) -StaticPropLighting -bounce 2 -noextra
# -StaticPropSampleScale 0.25
BSPZIP_BIN?=$(VBIN_DIR)bspzip.exe
BSPZIP_FLAGS?=
BSPZIP_BIN?=$(SUPERVISE_V_BIN) $(VBIN_DIR)bspzip.exe
BSPZIP_FLAGS?=$(VBIN_FLAGS)
# my take on compiling
# vbsp: writes bsp
......@@ -37,7 +37,8 @@ BSPZIP_FLAGS?=
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) $(basename $@).bsp
%_p.bsp: %.bsp
$(BSPZIP_BIN) $(BSPZIP_FLAGS) -addlist $^ $(basename $^).bspzip-addlist $@
$(BSPZIP_BIN) -addlist $^ $(basename $^).bspzip-addlist $@ $(BSPZIP_FLAGS)
cp $@ $(MOUNT_DIR)maps\\$(notdir $@)
all: ttt_terrorcon_v2.bsp ttt_terrorcon_v2.lint ttt_terrorcon_v2.game
......
......@@ -12,6 +12,18 @@ import hashlib
import subprocess
import logging
import collections
import copy
BELOW_NORMAL_PRIORITY_CLASS = 0x00004000
def execve_low(execve, *args, **kwargs):
logging.info('execve: %r', execve)
return subprocess.run(
execve,
*args,
creationflags=BELOW_NORMAL_PRIORITY_CLASS,
**kwargs,
)
def hashfile(file_, bufsize=None, hashfunc=hashlib.sha1):
if bufsize is None:
......@@ -50,67 +62,115 @@ class FileFingerprint:
return other.hash.digest() == self.hash.digest()
class Argset:
vmf_hash = None
bsp_hash = None
def __init__(self, argv=None):
if argv is None:
argv = sys.argv
self.prog = os.path.basename(argv[0])
self.bin = argv[1]
self.file = argv[-1]
self.vargs = argv[2:-1]
self.has_vmf = os.path.isfile(self.vmf)
self.has_bsp = os.path.isfile(self.bsp)
bin_ = None
@classmethod
def new_from_argv(cls, argv):
prog = os.path.basename(argv[0])
bin_ = argv[1]
bin_basename = os.path.basename(bin_)
bin_name = os.path.splitext(bin_basename)[0]
BINMAP = {
'bspzip': BspzipArgset,
'vbsp': BspCompileArgset,
'vvis': BspCompileArgset,
'vrad': BspCompileArgset,
}
if bin_name not in BINMAP:
raise NotImplementedError('no argset supervisor for bin %r'.format(bin_name))
logging.info('Argset for %r', bin_name)
return BINMAP[bin_name](argv)
def supervise(self):
raise NotImplementedError
@property
def name(self):
return os.path.basename(self.bin_)
def __repr__(self):
return '<{s.__class__.__name__} {t}>'.format(
s=self,
t=self.__dict__
)
class BspzipArgset(Argset):
def __init__(self, argv):
self.bin_ = argv[1]
self.mode = argv[2]
self.ibsp = argv[3]
self.addlist = argv[4]
self.obsp = argv[5]
self.vargs = argv[6:]
assert self.mode == '-addlist'
def supervise(self):
logging.info('%s', self)
if not os.path.isfile(self.ibsp):
logging.info('ENOENT no ibsp %r', self.ibsp)
return 2
if not os.path.isfile(self.addlist):
logging.info('ENOENT no addlist %r', self.addlist)
return 2
ifp = FileFingerprint(self.ibsp)
execve_low([
self.bin_,
self.mode,
self.ibsp,
self.addlist,
self.obsp,
] + self.vargs + [
])
if not os.path.isfile(self.obsp):
logging.info('ENOENT no obsp %r', self.obsp)
return 2
ofp = FileFingerprint(self.obsp)
bsp_changed = (ifp == ofp)
return bsp_changed
class BspCompileArgset(Argset):
def __init__(self, argv):
self.prog = os.path.basename(argv[0])
self.bin_ = argv[1]
self.file_ = argv[-1]
self.vargs = argv[2:-1]
self.has_vmf = os.path.isfile(self.vmf)
self.has_bsp = os.path.isfile(self.bsp)
@property
def vmf(self):
return '{}.vmf'.format(self.file)
return '{}.vmf'.format(self.file_)
@property
def bsp(self):
return '{}.bsp'.format(self.file)
return '{}.bsp'.format(self.file_)
@property
def name(self):
return os.path.basename(self.bin)
def supervise(self):
ifp = None
if self.has_bsp:
ifp = FileFingerprint(self.bsp)
else:
logging.info('no bsp file %r', self.bsp)
BELOW_NORMAL_PRIORITY_CLASS = 0x00004000
def main():
logging.basicConfig(level=logging.INFO)
argset = Argset(sys.argv)
execve_low(
[self.bin_] + self.vargs + [self.file_]
)
fp = collections.defaultdict(lambda:[None, None])
#if argset.has_vmf:
# fp['vmf'][0] = FileFingerprint(argset.vmf)
if argset.has_bsp:
fp['bsp'][0] = FileFingerprint(argset.bsp)
else:
logging.info('no bsp file %r', argset.bsp)
if not os.path.isfile(self.bsp):
logging.info('no bsp file %r', self.bsp)
return 2
execve = [argset.bin] + argset.vargs + [argset.file]
logging.info('execve: %r', execve)
popen = subprocess.run(
execve,
creationflags=BELOW_NORMAL_PRIORITY_CLASS
)
ofp = FileFingerprint(self.bsp)
#if argset.has_vmf:
# fp['vmf'][1] = FileFingerprint(argset.vmf)
if os.path.isfile(argset.bsp):
fp['bsp'][1] = FileFingerprint(argset.bsp)
else:
logging.info('no bsp file %r', argset.bsp)
exit(2)
bsp_changed = (fp['bsp'][0] == fp['bsp'][1])
exit(bsp_changed)
bsp_changed = (ifp == ofp)
return bsp_changed
def main():
logging.basicConfig(level=logging.INFO)
argset = Argset.new_from_argv(sys.argv)
exit(argset.supervise())
if __name__ == '__main__':
main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment