Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/hwsapibot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_call:

env:
INSTALL_PACKAGES: cmake make gcc g++ git doxygen perl libxml-simple-perl libxml-parser-perl bc curl python3-venv python3
INSTALL_PACKAGES: cmake make gcc g++ git doxygen bc curl python3-venv python3
BUILDSTATS_API_KEY: ${{ secrets.BUILDSTATS_API_KEY }}
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ jobs:
- name: check sql updates
run: |
python3 ./tools/checksql.py

- name: check tools syntax
run: |
find tools -name '*.py' -print0 | xargs -0 python3 -m py_compile
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ endif()

# Checks for external programs that may be needed in some targets/commands
find_program(DOXYGEN_FOUND doxygen)
find_program(PERL_FOUND perl)
find_program(PYTHON3_FOUND python3)

# Checks and creates the import conf directory
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ For a list of supported platforms, please refer to the [Supported Platforms](htt
- A build system like GNU make or Ninja (Ninja is preferred build system on windows, recommended for *Unix as well)
- MariaDB
- *Optional dependencies for development only*
- perl (required to rebuild the HPM Hooks and HPMDataCheck)
- requires the XML::Simple module, which in turn requires libexpat-dev
- Doxygen (required to rebuild the HPM Hooks and HPMDataCheck)

For a full list of prerequisites, please refer to the [Building](https://github.com/HerculesWS/Hercules/wiki/Building) wiki page.
Expand Down
12 changes: 6 additions & 6 deletions tools/HPMHookGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

set(API_SERVER_PATH "${CMAKE_SOURCE_DIR}/src/api")

if(DOXYGEN_FOUND AND PERL_FOUND AND PYTHON3_FOUND)
if(DOXYGEN_FOUND AND PYTHON3_FOUND)
add_custom_target(hooks
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND
Expand Down Expand Up @@ -47,14 +47,14 @@ if(DOXYGEN_FOUND AND PERL_FOUND AND PYTHON3_FOUND)
echo
"Regenerating HPM Hook definitions..."
COMMAND
perl
"HPMHookGen.pl"
python3
"HPMHookGen.py"
COMMAND
echo
"Regenerating HPM Data Check definitions..."
COMMAND
perl
"HPMDataCheckGen.pl"
python3
"HPMDataCheckGen.py"
BYPRODUCTS
"${CMAKE_CURRENT_SOURCE_DIR}/doxyoutput"
"${API_SERVER_PATH}/handlers.h.dox"
Expand All @@ -71,6 +71,6 @@ else()
add_custom_target(hooks
COMMAND
echo
"doxygen, perl and python3 are not found or disabled"
"doxygen and python3 are not found or disabled"
)
endif()
135 changes: 0 additions & 135 deletions tools/HPMHookGen/HPMDataCheckGen.pl

This file was deleted.

156 changes: 156 additions & 0 deletions tools/HPMHookGen/HPMDataCheckGen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/usr/bin/env python3
#
# This file is part of Hercules.
# http://herc.ws - http://github.com/HerculesWS/Hercules
#
# Copyright (C) 2014-2026 Hercules Dev Team
#
# Hercules is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Run from the tools/HPMHookGen/ directory, after `doxygen` has produced
# doxyoutput/xml/*.xml, to (re)generate ../../src/common/HPMDataCheck.h

import datetime
import glob
import os
import re
import xml.etree.ElementTree as ET

HPM_DATA_CHECK_API_VER = 1


def main():
# Perl's glob() sorts its results alphabetically by default; Python's
# glob.glob() does not, so the sort must be done explicitly to keep
# entries within each #ifdef guard group in a stable, matching order.
files = sorted(
f for f in glob.glob('doxyoutput/xml/struct*.xml')
if os.path.isfile(f) and re.search(r'[^h]\.xml$', f)
)

out = {}

for file in files:
try:
tree = ET.parse(file)
except ET.ParseError:
continue
root = tree.getroot()
compounddef = root.find('compounddef')
if compounddef is None:
continue

# means its a struct from a .c file, plugins cant access those so we don't care.
if compounddef.find('includes') is None:
continue

compoundname_el = compounddef.find('compoundname')
compoundname = compoundname_el.text if compoundname_el is not None and compoundname_el.text else ''
# its a duplicate with a :: name e.g. struct script_state {<...>} ay;
if '::' in compoundname:
continue

location = compounddef.find('location')
file_attr = location.get('file', '') if location is not None else ''
filepath = re.split(r'[/\\]', file_attr)
foldername = filepath[-2].upper() if len(filepath) >= 2 else ''

# Skip the HPM core, plugins don't need it
if filepath[-1] == "HPM.h":
continue

filename = filepath[-1].upper()
filename = re.sub(r'[.-]', '_', filename)
filename = re.sub(r'\.[^.]*$', '', filename)

plugintypes = 'SERVER_TYPE_UNKNOWN'
if foldername == 'COMMON':
if filename == 'MAPINDEX_H':
plugintypes = 'SERVER_TYPE_CHAR|SERVER_TYPE_MAP'
elif filename == 'GRFIO_H':
plugintypes = 'SERVER_TYPE_MAP'
else:
plugintypes = 'SERVER_TYPE_ALL'
elif re.match(r'^(LOGIN|CHAR|MAP)', foldername):
plugintypes = "SERVER_TYPE_%s" % foldername

symboldata = {
'name': compoundname,
'type': plugintypes,
}
name = "%s_%s" % (foldername, filename)
out.setdefault(name, []).append(symboldata)

fname = '../../src/common/HPMDataCheck.h'
year = datetime.date.today().year

with open(fname, 'w', newline='\n') as fh:
fh.write("""/**
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
* Copyright (C) 2014-%d Hercules Dev Team
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* NOTE: This file was auto-generated and should never be manually edited,
* as it will get overwritten.
*/

/* GENERATED FILE DO NOT EDIT */

#ifndef HPM_DATA_CHECK_H
#define HPM_DATA_CHECK_H

#if !defined(HPMHOOKGEN)
#include "common/HPMSymbols.inc.h"
#endif // ! HPMHOOKGEN
#ifdef HPM_SYMBOL
#undef HPM_SYMBOL
#endif // HPM_SYMBOL

HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
""" % year)

for key in sorted(out.keys()):
fh.write("\t#ifdef %s\n" % key)
for entry in out[key]:
fh.write("\t\t{ \"%s\", sizeof(struct %s), %s },\n" % (entry['name'], entry['name'], entry['type']))
fh.write("\t#else\n")
fh.write("\t\t#define %s\n" % key)
fh.write("\t#endif // %s\n" % key)

fh.write("""};
HPExport unsigned int HPMDataCheckLen = ARRAYLENGTH(HPMDataCheck);
HPExport int HPMDataCheckVer = %d;

#endif /* HPM_DATA_CHECK_H */
""" % HPM_DATA_CHECK_API_VER)


if __name__ == '__main__':
main()
Loading
Loading