From 0ace3d43511d0c729ed037952b013df1122639ca Mon Sep 17 00:00:00 2001 From: Contrabang <91113370+Contrabang@users.noreply.github.com> Date: Mon, 6 May 2024 15:29:19 -0400 Subject: [PATCH] Adds CI to remove duplicate definitions (#25218) * the purge * yes * incorrect comment * send it --- .github/workflows/ci.yml | 1 + code/game/area/areas/ruins/lavaland_areas.dm | 2 +- .../client/preference/preferences_toggles.dm | 2 +- tools/ci/no_duplicate_definitions.py | 59 +++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tools/ci/no_duplicate_definitions.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31e4675cccb..cd7f7667f24 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,7 @@ jobs: python tools/ci/define_sanity.py python tools/ci/restrict_file_types.py python tools/ci/verify_sql_version.py + python tools/ci/no_duplicate_definitions.py python -m tools.ci.check_icon_conflicts python -m tools.ci.check_icon_dupenames python -m tools.maplint.source --github diff --git a/code/game/area/areas/ruins/lavaland_areas.dm b/code/game/area/areas/ruins/lavaland_areas.dm index 0fc875a8c4a..6bf480d9d4e 100644 --- a/code/game/area/areas/ruins/lavaland_areas.dm +++ b/code/game/area/areas/ruins/lavaland_areas.dm @@ -18,7 +18,7 @@ icon_state = "yellow" /area/ruin/powered/golem_ship - name = "Free Golem Landing" + name = "Free Golem Ship" icon_state = "yellow" /area/ruin/powered/greed diff --git a/code/modules/client/preference/preferences_toggles.dm b/code/modules/client/preference/preferences_toggles.dm index 31cfd405f5c..541e55faba3 100644 --- a/code/modules/client/preference/preferences_toggles.dm +++ b/code/modules/client/preference/preferences_toggles.dm @@ -301,7 +301,7 @@ disable_message = "You will no longer see runechat." blackbox_message = "Toggle Runechat" -/datum/preference_toggle/toggle_runechat +/datum/preference_toggle/toggle_ghost_death_notifs name = "Toggle Ghost Death Notifications" description = "Toggle a notification when a player dies" preftoggle_bitflag = PREFTOGGLE_2_DEATHMESSAGE diff --git a/tools/ci/no_duplicate_definitions.py b/tools/ci/no_duplicate_definitions.py new file mode 100644 index 00000000000..7d4f829fcc6 --- /dev/null +++ b/tools/ci/no_duplicate_definitions.py @@ -0,0 +1,59 @@ +import glob +import os +import re +import sys +import time +from collections import namedtuple, defaultdict + +Failure = namedtuple("Failure", ["filename", "lineno", "message"]) +Location = namedtuple("Location", ["filename", "lineno"]) + +RED = "\033[0;31m" +GREEN = "\033[0;32m" +BLUE = "\033[0;34m" +NC = "\033[0m" # No Color + +def print_error(message: str, filename: str, line_number: int): + if os.getenv("GITHUB_ACTIONS") == "true": # We're on github, output in a special format. + print(f"::error file={filename},line={line_number},title=Restricted Type in File::{filename}:{line_number}: {RED}{message}{NC}") + else: + print(f"{filename}:{line_number}: {RED}{message}{NC}") + +if __name__ == "__main__": + print("no_duplicate_definitions started") + + exit_code = 0 + start = time.time() + + dm_files = glob.glob("**/*.dm", recursive=True) + + if len(sys.argv) > 1: + dm_files = sys.argv[1:] + + all_failures = [] + + all_types = defaultdict(list) + + for code_filepath in dm_files: + with open(code_filepath, encoding="UTF-8") as code: + filename = code_filepath.split(os.path.sep)[-1] + + definition_matcher = re.compile(r'^(\/[\w][\w/]*?)(?: *\/[/*].*)?$') + for idx, line in enumerate(code): + if(rematch_result := re.search(definition_matcher, line)): + typepath = rematch_result.group(1) + if(not typepath): + print_error("Failed to find a type, despite matching regex. If this happens, this CI is probably broken.", code_filepath, idx + 1) + continue + all_types[typepath].append(Location(code_filepath, idx + 1)) + + for key, value_list in all_types.items(): + if len(value_list) > 1: + for location in value_list: + print_error(f"Found a duplicate definition of {key}.", location.filename, location.lineno) + exit_code = 1 + + end = time.time() + print(f"no_duplicate_definitions tests completed in {end - start:.2f}s\n") + + sys.exit(exit_code)