Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ldpl committed Sep 27, 2021
2 parents 02a1224 + 407b10e commit 239ff97
Show file tree
Hide file tree
Showing 173 changed files with 31,042 additions and 9,412 deletions.
37 changes: 37 additions & 0 deletions .changelog
@@ -1,3 +1,40 @@
12.0-RC1 (2021-09-25)
------------------------------------------------------------------------
Feature: Display icon/text whether vehicle is lost in vehicle (list) window (#9543)
Feature: [MacOS] Add selected toolbar buttons to MacBook Pro Touch Bar (#9511)
Feature: Button to open order window from vehicle shared orders window (#9325)
Feature: Ctrl-Clicking shared order vehicle list opens order window (#9325)
Feature: Multiple rotating views on title screen (#8980)
Feature: Hide block signals in GUI by default (#8688)
Add: [Script] Allow GameScripts to build neutral objects (#9568)
Add: [Network] Allow sending chat messages via admin port (#9563)
Add: [AI/GS] Missing water related functions and objects (#8390)
Fix: Industry funding window did not update when changing funding method (#9572)
Fix #9562: [NewGRF] Handle case of invalid Action2 with zero results (#9564)
Fix: Incorrect error messages when placing water in scenario editor (#9560)
Fix #9484: Update locale currencies settings config map (#9559)
Fix: Prevent train reversing when entirely inside a train depot (#9557)
Fix: [Network] Add back 'Spectate' option to company toolbar menu (#9556)
Fix #9463: [Win32] Work around XAudio2 crashes (#9549)
Fix #8603: Don't give focus to text filter when opening Object GUI (#9547)
Fix #9241: Grove and forest tree brushes did not also create rainforest terrain (#9542)
Fix: [Network] Several crashes in our network code (#9534, #9456)
Fix #9527: Crash when trying to place multi-tile objects at map edge (#9529)
Fix: [Network] SendCmdNames only sent one name per packet (#9528)
Fix #9407: Desync when founding a town nearby a station (#9526)
Fix #9521: Don't load at just removed docks that were part of a multi-dock station (#9524)
Fix: Ships always tried to avoid docking tiles when pathfinding (even if nothing was on them) (#9522)
Fix: [Network] Convert server_advertise to server_game_type in config file (#9515)
Fix #9490: [Network] A full server couldn't be queried (#9508)
Fix: [Network] Don't show GameScript " (v0)" for old servers (#9507)
Fix: [Network] Show query errors in the server listing instead of error popup (#9506)
Fix: [Network] Crash when last-joined server was no longer available (#9503)
Fix #9501: [Network] Crash when more than one game-info query was pending (#9502)
Fix: Wrong error message when building canals over ship depots / locks (#9410)
Fix: Reduce cost of building canals over objects on sea (#9410)
Change: [Linkgraph] Delete links only served by vehicles stopped in depot (#9499)


12.0-beta2 (2021-08-19)
------------------------------------------------------------------------
Feature: [Linkgraph] Prioritize faster routes for passengers, mail and express cargo (#9457)
Expand Down
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Expand Up @@ -39,6 +39,7 @@ Describe here

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.
* The bug fix is important enough to be backported? (label: 'backport requested')
* 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.
Expand Down
221 changes: 221 additions & 0 deletions .github/unused-strings.py
@@ -0,0 +1,221 @@
"""
Script to scan the OpenTTD source-tree for STR_ entries that are defined but
no longer used.
This is not completely trivial, as OpenTTD references a lot of strings in
relation to another string. The most obvious example of this is a list. OpenTTD
only references the first entry in the list, and does "+ <var>" to get to the
correct string.
There are other ways OpenTTD does use relative values. This script tries to
account for all of them, to give the best approximation we have for "this
string is unused".
"""

import glob
import os
import re
import subprocess
import sys

from enum import Enum

LENGTH_NAME_LOOKUP = {
"VEHICLE_TYPES": 4,
}


class SkipType(Enum):
NONE = 1
LENGTH = 2
EXTERNAL = 3
ZERO_IS_SPECIAL = 4
EXPECT_NEWLINE = 5


def read_language_file(filename, strings_found, errors):
strings_defined = []

skip = SkipType.NONE
length = 0
common_prefix = ""
last_tiny_string = ""

with open(filename) as fp:
for line in fp.readlines():
if not line.strip():
if skip == SkipType.EXPECT_NEWLINE:
skip = SkipType.NONE
continue

line = line.strip()

if skip == SkipType.EXPECT_NEWLINE:
# The only thing allowed after a list, is this next marker, or a newline.
if line == "###next-name-looks-similar":
# "###next-name-looks-similar"
# Indicates the common prefix of the last list has a very
# similar name to the next entry, but isn't part of the
# list. So do not emit a warning about them looking very
# similar.

if length != 0:
errors.append(f"ERROR: list around {name} is shorted than indicated by ###length")

common_prefix = ""
else:
errors.append(f"ERROR: expected a newline after a list, but didn't find any around {name}. Did you add an entry to the list without increasing the length?")

skip = SkipType.NONE

if line[0] == "#":
if line.startswith("###length "):
# "###length <count>"
# Indicates the next few entries are part of a list. Only
# the first entry is possibly referenced, and the rest are
# indirectly.

if length != 0:
errors.append(f"ERROR: list around {name} is shorted than indicated by ###length")

length = line.split(" ")[1].strip()

if length.isnumeric():
length = int(length)
else:
length = LENGTH_NAME_LOOKUP[length]

skip = SkipType.LENGTH
elif line.startswith("###external "):
# "###external <count>"
# Indicates the next few entries are used outside the
# source and will not be referenced.

if length != 0:
errors.append(f"ERROR: list around {name} is shorted than indicated by ###length")

length = line.split(" ")[1].strip()
length = int(length)

skip = SkipType.EXTERNAL
elif line.startswith("###setting-zero-is-special"):
# "###setting-zero-is-special"
# Indicates the next entry is part of the "zero is special"
# flag of settings. These entries are not referenced
# directly in the code.

if length != 0:
errors.append(f"ERROR: list around {name} is shorted than indicated by ###length")

skip = SkipType.ZERO_IS_SPECIAL

continue

name = line.split(":")[0].strip()
strings_defined.append(name)

# If a string ends on _TINY or _SMALL, it can be the {TINY} variant.
# Check for this by some fuzzy matching.
if name.endswith(("_SMALL", "_TINY")):
last_tiny_string = name
elif last_tiny_string:
matching_name = "_".join(last_tiny_string.split("_")[:-1])
if name == matching_name:
strings_found.add(last_tiny_string)
else:
last_tiny_string = ""

if skip == SkipType.EXTERNAL:
strings_found.add(name)
skip = SkipType.LENGTH

if skip == SkipType.LENGTH:
skip = SkipType.NONE
length -= 1
common_prefix = name
elif skip == SkipType.ZERO_IS_SPECIAL:
strings_found.add(name)
elif length > 0:
strings_found.add(name)
length -= 1

# Find the common prefix of these strings
for i in range(len(common_prefix)):
if common_prefix[0 : i + 1] != name[0 : i + 1]:
common_prefix = common_prefix[0:i]
break

if length == 0:
skip = SkipType.EXPECT_NEWLINE

if len(common_prefix) < 6:
errors.append(f"ERROR: common prefix of block including {name} was reduced to {common_prefix}. This means the names in the list are not consistent.")
elif common_prefix:
if name.startswith(common_prefix):
errors.append(f"ERROR: {name} looks a lot like block above with prefix {common_prefix}. This mostly means that the list length was too short. Use '###next-name-looks-similar' if it is not.")
common_prefix = ""

return strings_defined


def scan_source_files(path, strings_found):
for new_path in glob.glob(f"{path}/*"):
if os.path.isdir(new_path):
scan_source_files(new_path, strings_found)
continue

if not new_path.endswith((".c", ".h", ".cpp", ".hpp", ".ini")):
continue

# Most files we can just open, but some use magic, that requires the
# G++ preprocessor before we can make sense out of it.
if new_path == "src/table/cargo_const.h":
p = subprocess.run(["g++", "-E", new_path], stdout=subprocess.PIPE)
output = p.stdout.decode()
else:
with open(new_path) as fp:
output = fp.read()

# Find all the string references.
matches = re.findall(r"[^A-Z_](STR_[A-Z0-9_]*)", output)
strings_found.update(matches)


def main():
strings_found = set()
errors = []

scan_source_files("src", strings_found)
strings_defined = read_language_file("src/lang/english.txt", strings_found, errors)

# STR_LAST_STRINGID is special, and not really a string.
strings_found.remove("STR_LAST_STRINGID")
# These are mentioned in comments, not really a string.
strings_found.remove("STR_XXX")
strings_found.remove("STR_NEWS")
strings_found.remove("STR_CONTENT_TYPE_")

# This string is added for completion, but never used.
strings_defined.remove("STR_JUST_DATE_SHORT")

strings_defined = sorted(strings_defined)
strings_found = sorted(list(strings_found))

for string in strings_found:
if string not in strings_defined:
errors.append(f"ERROR: {string} found but never defined.")

for string in strings_defined:
if string not in strings_found:
errors.append(f"ERROR: {string} is (possibly) no longer needed.")

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


if __name__ == "__main__":
main()
18 changes: 18 additions & 0 deletions .github/workflows/unused-strings.yml
@@ -0,0 +1,18 @@
name: Unused strings

on:
pull_request:

jobs:
unused-strings:
name: Unused strings
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Check for unused strings
run: |
set -ex
python3 .github/unused-strings.py
2 changes: 1 addition & 1 deletion .ottdrev
@@ -1 +1 @@
12.0-beta2 20210819 0 778e196b55265c40191186c273b008356136e20d 1 0 2021
12.0-RC1 20210925 0 79dc634d41d04f4b48e8e284f2986a9cdb288946 1 0 2021
2 changes: 1 addition & 1 deletion .release_date
@@ -1 +1 @@
2021-08-19 19:24 UTC
2021-09-25 14:00 UTC
2 changes: 1 addition & 1 deletion .version
@@ -1 +1 @@
12.0-beta2
12.0-RC1
37 changes: 37 additions & 0 deletions changelog.txt
@@ -1,3 +1,40 @@
12.0-RC1 (2021-09-25)
------------------------------------------------------------------------
Feature: Display icon/text whether vehicle is lost in vehicle (list) window (#9543)
Feature: [MacOS] Add selected toolbar buttons to MacBook Pro Touch Bar (#9511)
Feature: Button to open order window from vehicle shared orders window (#9325)
Feature: Ctrl-Clicking shared order vehicle list opens order window (#9325)
Feature: Multiple rotating views on title screen (#8980)
Feature: Hide block signals in GUI by default (#8688)
Add: [Script] Allow GameScripts to build neutral objects (#9568)
Add: [Network] Allow sending chat messages via admin port (#9563)
Add: [AI/GS] Missing water related functions and objects (#8390)
Fix: Industry funding window did not update when changing funding method (#9572)
Fix #9562: [NewGRF] Handle case of invalid Action2 with zero results (#9564)
Fix: Incorrect error messages when placing water in scenario editor (#9560)
Fix #9484: Update locale currencies settings config map (#9559)
Fix: Prevent train reversing when entirely inside a train depot (#9557)
Fix: [Network] Add back 'Spectate' option to company toolbar menu (#9556)
Fix #9463: [Win32] Work around XAudio2 crashes (#9549)
Fix #8603: Don't give focus to text filter when opening Object GUI (#9547)
Fix #9241: Grove and forest tree brushes did not also create rainforest terrain (#9542)
Fix: [Network] Several crashes in our network code (#9534, #9456)
Fix #9527: Crash when trying to place multi-tile objects at map edge (#9529)
Fix: [Network] SendCmdNames only sent one name per packet (#9528)
Fix #9407: Desync when founding a town nearby a station (#9526)
Fix #9521: Don't load at just removed docks that were part of a multi-dock station (#9524)
Fix: Ships always tried to avoid docking tiles when pathfinding (even if nothing was on them) (#9522)
Fix: [Network] Convert server_advertise to server_game_type in config file (#9515)
Fix #9490: [Network] A full server couldn't be queried (#9508)
Fix: [Network] Don't show GameScript " (v0)" for old servers (#9507)
Fix: [Network] Show query errors in the server listing instead of error popup (#9506)
Fix: [Network] Crash when last-joined server was no longer available (#9503)
Fix #9501: [Network] Crash when more than one game-info query was pending (#9502)
Fix: Wrong error message when building canals over ship depots / locks (#9410)
Fix: Reduce cost of building canals over objects on sea (#9410)
Change: [Linkgraph] Delete links only served by vehicles stopped in depot (#9499)


12.0-beta2 (2021-08-19)
------------------------------------------------------------------------
Feature: [Linkgraph] Prioritize faster routes for passengers, mail and express cargo (#9457)
Expand Down

0 comments on commit 239ff97

Please sign in to comment.