forked from 0ad/0ad
Make checkrefs and called scripts return an error
This commit is contained in:
parent
2a06eea08a
commit
eeb0f1cce6
@ -37,6 +37,7 @@ class CheckRefs:
|
|||||||
self.supportedAudioFormats = ('ogg')
|
self.supportedAudioFormats = ('ogg')
|
||||||
self.mods = []
|
self.mods = []
|
||||||
self.__init_logger
|
self.__init_logger
|
||||||
|
self.inError = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __init_logger(self):
|
def __init_logger(self):
|
||||||
@ -103,12 +104,16 @@ class CheckRefs:
|
|||||||
sys.path.append("../xmlvalidator/")
|
sys.path.append("../xmlvalidator/")
|
||||||
from validate_grammar import RelaxNGValidator
|
from validate_grammar import RelaxNGValidator
|
||||||
validate = RelaxNGValidator(self.vfs_root, self.mods)
|
validate = RelaxNGValidator(self.vfs_root, self.mods)
|
||||||
validate.run()
|
if not validate.run():
|
||||||
|
self.inError = True
|
||||||
if args.validate_actors:
|
if args.validate_actors:
|
||||||
sys.path.append("../xmlvalidator/")
|
sys.path.append("../xmlvalidator/")
|
||||||
from validator import Validator
|
from validator import Validator
|
||||||
validator = Validator(self.vfs_root, self.mods)
|
validator = Validator(self.vfs_root, self.mods)
|
||||||
validator.run()
|
if not validator.run():
|
||||||
|
self.inError = True
|
||||||
|
|
||||||
|
return self.inError
|
||||||
|
|
||||||
def get_mod_dependencies(self, *mods):
|
def get_mod_dependencies(self, *mods):
|
||||||
modjsondeps = []
|
modjsondeps = []
|
||||||
@ -171,7 +176,8 @@ class CheckRefs:
|
|||||||
# ignore terrains.xml
|
# ignore terrains.xml
|
||||||
if name != 'terrains':
|
if name != 'terrains':
|
||||||
if name in terrains:
|
if name in terrains:
|
||||||
self.logger.warning(f"Duplicate terrain name '{name}' (from '{terrains[name]}' and '{ffp}')")
|
self.inError = True
|
||||||
|
self.logger.error(f"Duplicate terrain name '{name}' (from '{terrains[name]}' and '{ffp}')")
|
||||||
terrains[name] = str(fp)
|
terrains[name] = str(fp)
|
||||||
mapfiles = self.find_files('maps/scenarios', 'pmp')
|
mapfiles = self.find_files('maps/scenarios', 'pmp')
|
||||||
mapfiles.extend(self.find_files('maps/skirmishes', 'pmp'))
|
mapfiles.extend(self.find_files('maps/skirmishes', 'pmp'))
|
||||||
@ -411,7 +417,7 @@ class CheckRefs:
|
|||||||
material_elem = ElementTree.parse(ffp).getroot()
|
material_elem = ElementTree.parse(ffp).getroot()
|
||||||
for alternative in material_elem.findall('alternative'):
|
for alternative in material_elem.findall('alternative'):
|
||||||
material = alternative.get('material')
|
material = alternative.get('material')
|
||||||
if material:
|
if material is not None:
|
||||||
self.deps.append((str(fp), f'art/materials/{material}'))
|
self.deps.append((str(fp), f'art/materials/{material}'))
|
||||||
|
|
||||||
def add_particles(self):
|
def add_particles(self):
|
||||||
@ -642,7 +648,8 @@ class CheckRefs:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
callers = [str(self.vfs_to_relative_to_mods(ref)) for ref in reverse_deps[dep]]
|
callers = [str(self.vfs_to_relative_to_mods(ref)) for ref in reverse_deps[dep]]
|
||||||
self.logger.warning(f"Missing file '{dep}' referenced by: {', '.join(sorted(callers))}")
|
self.logger.error(f"Missing file '{dep}' referenced by: {', '.join(sorted(callers))}")
|
||||||
|
self.inError = True
|
||||||
if dep.lower() in lower_case_files:
|
if dep.lower() in lower_case_files:
|
||||||
self.logger.warning(f"### Case-insensitive match (found '{lower_case_files[dep.lower()]}')")
|
self.logger.warning(f"### Case-insensitive match (found '{lower_case_files[dep.lower()]}')")
|
||||||
|
|
||||||
@ -684,4 +691,5 @@ class CheckRefs:
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
check_ref = CheckRefs()
|
check_ref = CheckRefs()
|
||||||
check_ref.main()
|
if not check_ref.main():
|
||||||
|
sys.exit(1)
|
||||||
|
@ -47,6 +47,7 @@ class RelaxNGValidator:
|
|||||||
errorch.setFormatter(Formatter('%(levelname)s - %(message)s'))
|
errorch.setFormatter(Formatter('%(levelname)s - %(message)s'))
|
||||||
logger.addHandler(errorch)
|
logger.addHandler(errorch)
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
|
self.inError = False
|
||||||
|
|
||||||
def run (self):
|
def run (self):
|
||||||
self.validate_actors()
|
self.validate_actors()
|
||||||
@ -59,13 +60,14 @@ class RelaxNGValidator:
|
|||||||
self.validate_soundgroups()
|
self.validate_soundgroups()
|
||||||
self.validate_terrains()
|
self.validate_terrains()
|
||||||
self.validate_textures()
|
self.validate_textures()
|
||||||
|
return self.inError
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
""" Program entry point, parses command line arguments and launches the validation """
|
""" Program entry point, parses command line arguments and launches the validation """
|
||||||
# ordered uniq mods (dict maintains ordered keys from python 3.6)
|
# ordered uniq mods (dict maintains ordered keys from python 3.6)
|
||||||
self.logger.info(f"Checking {'|'.join(self.mods)}'s integrity.")
|
self.logger.info(f"Checking {'|'.join(self.mods)}'s integrity.")
|
||||||
self.logger.info(f"The following mods will be loaded: {'|'.join(self.mods)}.")
|
self.logger.info(f"The following mods will be loaded: {'|'.join(self.mods)}.")
|
||||||
self.run()
|
return self.run()
|
||||||
|
|
||||||
def find_files(self, vfs_root, mods, vfs_path, *ext_list):
|
def find_files(self, vfs_root, mods, vfs_path, *ext_list):
|
||||||
"""
|
"""
|
||||||
@ -177,6 +179,7 @@ class RelaxNGValidator:
|
|||||||
self.logger.info(f"{error_count} {name} validation errors")
|
self.logger.info(f"{error_count} {name} validation errors")
|
||||||
elif error_count > 0:
|
elif error_count > 0:
|
||||||
self.logger.error(f"{error_count} {name} validation errors")
|
self.logger.error(f"{error_count} {name} validation errors")
|
||||||
|
self.inError = True
|
||||||
|
|
||||||
|
|
||||||
def get_mod_dependencies(vfs_root, *mods):
|
def get_mod_dependencies(vfs_root, *mods):
|
||||||
@ -204,4 +207,5 @@ if __name__ == '__main__':
|
|||||||
args = ap.parse_args()
|
args = ap.parse_args()
|
||||||
mods = list(dict.fromkeys([*args.mods, *get_mod_dependencies(args.root, *args.mods), 'mod']).keys())
|
mods = list(dict.fromkeys([*args.mods, *get_mod_dependencies(args.root, *args.mods), 'mod']).keys())
|
||||||
relax_ng_validator = RelaxNGValidator(args.root, mods=mods, verbose=args.verbose)
|
relax_ng_validator = RelaxNGValidator(args.root, mods=mods, verbose=args.verbose)
|
||||||
relax_ng_validator.main()
|
if not relax_ng_validator.main():
|
||||||
|
sys.exit(1)
|
||||||
|
@ -111,6 +111,7 @@ class Validator:
|
|||||||
errorch.setFormatter(Formatter('%(levelname)s - %(message)s'))
|
errorch.setFormatter(Formatter('%(levelname)s - %(message)s'))
|
||||||
logger.addHandler(errorch)
|
logger.addHandler(errorch)
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
|
self.inError = False
|
||||||
|
|
||||||
def get_mod_path(self, mod_name, vfs_path):
|
def get_mod_path(self, mod_name, vfs_path):
|
||||||
return os.path.join(mod_name, vfs_path)
|
return os.path.join(mod_name, vfs_path)
|
||||||
@ -178,6 +179,7 @@ class Validator:
|
|||||||
self.get_mod_path(actor.mod_name, actor.vfs_path),
|
self.get_mod_path(actor.mod_name, actor.vfs_path),
|
||||||
actor.material
|
actor.material
|
||||||
))
|
))
|
||||||
|
self.inError = True
|
||||||
if actor.material not in self.materials:
|
if actor.material not in self.materials:
|
||||||
continue
|
continue
|
||||||
material = self.materials[actor.material]
|
material = self.materials[actor.material]
|
||||||
@ -189,6 +191,7 @@ class Validator:
|
|||||||
missing_textures,
|
missing_textures,
|
||||||
material.name
|
material.name
|
||||||
))
|
))
|
||||||
|
self.inError = True
|
||||||
|
|
||||||
extra_textures = ', '.join(set([extra_texture for extra_texture in actor.textures if extra_texture not in material.required_textures]))
|
extra_textures = ', '.join(set([extra_texture for extra_texture in actor.textures if extra_texture not in material.required_textures]))
|
||||||
if len(extra_textures) > 0:
|
if len(extra_textures) > 0:
|
||||||
@ -197,6 +200,9 @@ class Validator:
|
|||||||
extra_textures,
|
extra_textures,
|
||||||
material.name
|
material.name
|
||||||
))
|
))
|
||||||
|
self.inError = True
|
||||||
|
|
||||||
|
return self.inError
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
@ -206,4 +212,5 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('-m', '--mods', action='store', dest='mods', default='mod,public')
|
parser.add_argument('-m', '--mods', action='store', dest='mods', default='mod,public')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
validator = Validator(args.root, args.mods.split(','))
|
validator = Validator(args.root, args.mods.split(','))
|
||||||
validator.run()
|
if not validator.run():
|
||||||
|
sys.exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user