Skip to content

Commit

Permalink
Merge branch 'openttd'
Browse files Browse the repository at this point in the history
  • Loading branch information
ldpl committed Feb 3, 2024
2 parents 77ed90f + 33ef333 commit 7a1afa5
Show file tree
Hide file tree
Showing 1,325 changed files with 137,807 additions and 70,337 deletions.
285 changes: 279 additions & 6 deletions .changelog

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .dorpsgek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ notifications:
only:
- master
only-by:
- DorpsGek
- eints-sync\[bot\]
commit-comment:
discussion:
pull-request:
Expand Down
468 changes: 468 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Some things are not automated, and forgotten often. This list is a reminder for
* This PR touches english.txt or translations? Check the [guidelines](https://github.com/OpenTTD/OpenTTD/blob/master/docs/eints.md)
* This PR affects the save game format? (label 'savegame upgrade')
* This PR affects the GS/AI API? (label 'needs review: Script API')
* ai_changelog.hpp, gs_changelog.hpp need updating.
* ai_changelog.hpp, game_changelog.hpp need updating.
* The compatibility wrappers (compat_*.nut) need updating.
* This PR affects the NewGRF API? (label 'needs review: NewGRF')
* newgrf_debug_data.h may need updating.
Expand Down
12 changes: 12 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: openttd
queries:
- uses: security-and-quality
query-filters:
- exclude:
id:
# Only feasible way is to move away from fopen; fopen_s is optional C11 and not implemented on most platforms.
- cpp/world-writable-file-creation
# Basically OpenTTD's coding style for adding things like ..._INVALID to enumerations
- cpp/irregular-enum-init
# Our GUI code tends to use switches for OnClick handlers, DrawWidget, and UpdateWidgetSize. Sometimes GUIs just don't have many elements, but we want to keep consistency.
- cpp/trivial-switch
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
groups:
actions:
patterns:
- "*"
71 changes: 71 additions & 0 deletions .github/script-missing-mode-enforcement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""
Script to scan the OpenTTD's script API for functions that miss checks for the
function being called from the right mode (deity or company mode).
When a function calls either ScriptObject::Command or ScriptObject::GetCompany
then the function is considered dangerous. When one of the mode enforcement
macros from script_error.hpp, i.e. EnforceDeityMode, EnforceCompanyModeValid or
EnforceDeityOrCompanyModeValid, are called in the function, then we consider
that the function has mode enforcement.
Any dangerous function for which no enforcement is found are emitted as errors.
"""

import glob
import re
import sys


def check_mode_enforcement(path):
errors = []
with open(path, "r") as reader:
mode_enforcement_found = False
dangerous_function = False
for line in reader:
# Line does not start with a tab and have <word>::<word>. That looks like the begin of a function, so reset the state.
if re.match(r"^[^\t].*\w::\w", line):
mode_enforcement_found = False
dangerous_function = False
currentFunction = line
continue

if re.match(
r"\t(EnforceDeityMode|EnforceCompanyModeValid|EnforceCompanyModeValid_Void|EnforceDeityOrCompanyModeValid|EnforceDeityOrCompanyModeValid_Void)\(",
line,
):
# Mode enforcement macro found
mode_enforcement_found = True
continue

if re.match(r".*(ScriptObject::Command|ScriptObject::GetCompany).*", line):
# Dangerous function found
dangerous_function = True
continue

# Line with only a closing bracket. That looks like the end of a function, so check for the dangerous function without mode enforcement
if re.match(r"^}$", line) and dangerous_function and not mode_enforcement_found:
function_name = currentFunction.rstrip("\n").replace("/* static */ ", "")
errors.append(f"{path}: {function_name}")

return errors


def main():
errors = []
for path in sorted(glob.glob("src/script/api/*.cpp")):
# Skip a number of files that yield only false positives
if path.endswith(("script_object.cpp", "script_companymode.cpp", "script_controller.cpp", "script_game.cpp")):
continue

errors.extend(check_mode_enforcement(path))

if errors:
print("Mode enforcement was expected in the following files/functions:")
print("\n".join(errors))
sys.exit(1)

print("OK")


if __name__ == "__main__":
main()
7 changes: 3 additions & 4 deletions .github/unused-strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,10 @@ def main():
errors.append(f"ERROR: {string} is (possibly) no longer needed.")

if errors:
for error in errors:
print(error)
print("\n".join(errors))
sys.exit(1)
else:
print("OK")

print("OK")


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 7a1afa5

Please sign in to comment.