mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-26 17:54:14 +00:00
chore: drop dead winapi_stubs.h includes across minecraft
This commit is contained in:
parent
83b89eea3e
commit
0f98d6beec
114
scripts/sweep_winapi_stubs_includes.py
Normal file
114
scripts/sweep_winapi_stubs_includes.py
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Conservative sweep: remove dead app/linux/Stubs/winapi_stubs.h includes.
|
||||
|
||||
winapi_stubs.h provides Windows API typedefs and constants for Linux
|
||||
(LARGE_INTEGER, FILETIME, ERROR_*, etc.). Many minecraft/ files include
|
||||
it as transitive leftovers and never actually reference any of those
|
||||
symbols.
|
||||
|
||||
Usage:
|
||||
python3 scripts/sweep_winapi_stubs_includes.py [--apply]
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
MINECRAFT_ROOT = REPO_ROOT / "targets" / "minecraft"
|
||||
|
||||
INCLUDE_RE = re.compile(
|
||||
r'^[ \t]*#[ \t]*include[ \t]*"app/linux/Stubs/winapi_stubs\.h"[ \t]*\n',
|
||||
re.MULTILINE,
|
||||
)
|
||||
|
||||
# Symbols defined by winapi_stubs.h. If any appear in the consumer, the
|
||||
# include is needed.
|
||||
USAGE_PATTERNS = [
|
||||
re.compile(r'\bLARGE_INTEGER\b'),
|
||||
re.compile(r'\bULARGE_INTEGER\b'),
|
||||
re.compile(r'\bFILETIME\b'),
|
||||
re.compile(r'\bSYSTEMTIME\b'),
|
||||
re.compile(r'\bERROR_SUCCESS\b'),
|
||||
re.compile(r'\bERROR_IO_PENDING\b'),
|
||||
re.compile(r'\bERROR_CANCELLED\b'),
|
||||
re.compile(r'\bMEM_COMMIT\b'),
|
||||
re.compile(r'\bMEM_RESERVE\b'),
|
||||
re.compile(r'\bMEM_DECOMMIT\b'),
|
||||
re.compile(r'\bPAGE_READWRITE\b'),
|
||||
re.compile(r'\bDWORD\b'),
|
||||
re.compile(r'\bBYTE\b'),
|
||||
re.compile(r'\bWORD\b'),
|
||||
re.compile(r'\bHANDLE\b'),
|
||||
re.compile(r'\bHRESULT\b'),
|
||||
re.compile(r'\bGetLastError\b'),
|
||||
re.compile(r'\bGetFileSize\b'),
|
||||
re.compile(r'\bGetSystemTime\b'),
|
||||
re.compile(r'\bSystemTimeToFileTime\b'),
|
||||
re.compile(r'\bMakeAbsoluteSD\b'),
|
||||
re.compile(r'\bSetFilePointer\b'),
|
||||
re.compile(r'\bReadFile\b'),
|
||||
re.compile(r'\bWriteFile\b'),
|
||||
re.compile(r'\bCloseHandle\b'),
|
||||
re.compile(r'\bCreateFile\b'),
|
||||
re.compile(r'\bVirtualAlloc\b'),
|
||||
re.compile(r'\bVirtualFree\b'),
|
||||
re.compile(r'\bSleep\s*\('),
|
||||
re.compile(r'\bWaitForSingleObject\b'),
|
||||
re.compile(r'\bSetEvent\b'),
|
||||
re.compile(r'\bResetEvent\b'),
|
||||
re.compile(r'\bInterlocked'),
|
||||
re.compile(r'\bOutputDebugString\b'),
|
||||
re.compile(r'\bMessageBox\b'),
|
||||
]
|
||||
|
||||
|
||||
def needs_winapi(text: str) -> bool:
|
||||
scan = INCLUDE_RE.sub("", text)
|
||||
return any(p.search(scan) for p in USAGE_PATTERNS)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--apply", action="store_true",
|
||||
help="Actually remove the dead includes")
|
||||
args = parser.parse_args()
|
||||
|
||||
candidates: list[Path] = []
|
||||
for dirpath, _dirnames, filenames in os.walk(MINECRAFT_ROOT):
|
||||
for name in filenames:
|
||||
if not name.endswith((".cpp", ".c", ".h", ".hpp")):
|
||||
continue
|
||||
path = Path(dirpath) / name
|
||||
try:
|
||||
text = path.read_text(encoding="utf-8", errors="surrogateescape")
|
||||
except OSError:
|
||||
continue
|
||||
if not INCLUDE_RE.search(text):
|
||||
continue
|
||||
if needs_winapi(text):
|
||||
continue
|
||||
candidates.append(path)
|
||||
|
||||
candidates.sort()
|
||||
for path in candidates:
|
||||
print(path.relative_to(REPO_ROOT))
|
||||
|
||||
print(f"\n{len(candidates)} files have a dead winapi_stubs.h include")
|
||||
|
||||
if args.apply:
|
||||
for path in candidates:
|
||||
text = path.read_text(encoding="utf-8", errors="surrogateescape")
|
||||
new_text = INCLUDE_RE.sub("", text)
|
||||
path.write_text(new_text, encoding="utf-8", errors="surrogateescape")
|
||||
print(f"Removed from {len(candidates)} files")
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <cmath>
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "java/JavaMath.h"
|
||||
#include "java/Random.h"
|
||||
#include "minecraft/SharedConstants.h"
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@
|
|||
#include "app/common/Tutorial/TutorialMode.h"
|
||||
#include "app/common/UI/All Platforms/UIEnums.h"
|
||||
#include "app/linux/Linux_UIController.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "PlatformTypes.h"
|
||||
#include "Pos.h"
|
||||
#include "minecraft/SharedConstants.h"
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include "platform/renderer/renderer.h"
|
||||
#include "LevelRenderer.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "util/FrameProfiler.h"
|
||||
#include "TileRenderer.h"
|
||||
#include "minecraft/client/renderer/Tesselator.h"
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
#include "minecraft/GameEnums.h"
|
||||
#include "platform/ShutdownManager.h"
|
||||
#include "app/common/Colours/ColourTable.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "minecraft/client/BufferedImage.h"
|
||||
#include "util/FrameProfiler.h"
|
||||
#include "platform/stubs.h"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include <format>
|
||||
#include <utility>
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "minecraft/client/BufferedImage.h"
|
||||
#include "SimpleIcon.h"
|
||||
#include "StitchedTexture.h"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "StitchSlot.h"
|
||||
#include "Texture.h"
|
||||
#include "TextureHolder.h"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include <format>
|
||||
#include <utility>
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "minecraft/client/BufferedImage.h"
|
||||
#include "StitchSlot.h"
|
||||
#include "StitchedTexture.h"
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
#include "app/common/Colours/ColourTable.h"
|
||||
#include "minecraft/IGameServices.h"
|
||||
#include "app/linux/Linux_UIController.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "minecraft/client/BufferedImage.h"
|
||||
#include "util/StringHelpers.h"
|
||||
#include "java/File.h"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include <string>
|
||||
|
||||
#include "app/common/Network/Socket.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "platform/C4JThread.h"
|
||||
#include "java/InputOutputStream/DataInputStream.h"
|
||||
#include "java/InputOutputStream/DataOutputStream.h"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <limits>
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "PacketListener.h"
|
||||
#include "java/InputOutputStream/DataInputStream.h"
|
||||
#include "java/InputOutputStream/DataOutputStream.h"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <limits>
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "PacketListener.h"
|
||||
#include "java/InputOutputStream/DataInputStream.h"
|
||||
#include "java/InputOutputStream/DataOutputStream.h"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "PacketListener.h"
|
||||
#include "java/InputOutputStream/DataInputStream.h"
|
||||
#include "java/InputOutputStream/DataOutputStream.h"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "PacketListener.h"
|
||||
#include "java/InputOutputStream/DataInputStream.h"
|
||||
#include "java/InputOutputStream/DataOutputStream.h"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include "app/common/BuildVer/BuildVer.h"
|
||||
#include "platform/IPlatformNetwork.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "PacketListener.h"
|
||||
#include "java/InputOutputStream/DataInputStream.h"
|
||||
#include "java/InputOutputStream/DataOutputStream.h"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <unordered_set>
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "PacketListener.h"
|
||||
#include "java/InputOutputStream/DataInputStream.h"
|
||||
#include "java/InputOutputStream/DataOutputStream.h"
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
#include "app/common/Network/Socket.h"
|
||||
#include "app/common/Tutorial/Tutorial.h"
|
||||
#include "app/common/Tutorial/TutorialEnum.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "platform/NetTypes.h"
|
||||
#include "MinecraftServer.h"
|
||||
#include "Settings.h"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include <vector>
|
||||
|
||||
#include "app/common/Network/NetworkPlayerInterface.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "ServerLevel.h"
|
||||
#include "ServerPlayer.h"
|
||||
#include "TrackedEntity.h"
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
#include "app/common/BuildVer/BuildVer.h"
|
||||
#include "app/common/Network/NetworkPlayerInterface.h"
|
||||
#include "platform/IPlatformNetwork.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "platform/NetTypes.h"
|
||||
#include "PlayerConnection.h"
|
||||
#include "ServerConnection.h"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "java/Random.h"
|
||||
|
||||
int WeighedRandom::getTotalWeight(std::vector<WeighedRandomItem*>* items) {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
#include "EntityPos.h"
|
||||
#include "SyncedEntityData.h"
|
||||
#include "minecraft/GameEnums.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "java/Class.h"
|
||||
#include "java/Random.h"
|
||||
#include "minecraft/Direction.h"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include <vector>
|
||||
|
||||
#include "app/common/Colours/ColourTable.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "java/Class.h"
|
||||
#include "minecraft/client/Minecraft.h"
|
||||
#include "minecraft/core/BehaviorRegistry.h"
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
#include "app/common/Colours/ColourTable.h"
|
||||
#include "app/common/Console_Debug_enum.h"
|
||||
#include "app/common/Network/GameNetworkManager.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "util/FrameProfiler.h"
|
||||
#include "java/Random.h"
|
||||
#include "minecraft/Direction.h"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "minecraft/world/level/biome/BiomeDecorator.h"
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "java/Random.h"
|
||||
#include "minecraft/world/level/Level.h"
|
||||
#include "minecraft/world/level/biome/Biome.h"
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
#include "minecraft/world/level/biome/Biome.h"
|
||||
#include "minecraft/world/level/chunk/ChunkSource.h"
|
||||
#if defined(__linux__)
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#endif
|
||||
#include "java/Random.h"
|
||||
#include "minecraft/world/entity/MobCategory.h"
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
#include "minecraft/GameEnums.h"
|
||||
#include "app/common/GameRules/LevelGeneration/LevelGenerationOptions.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "StrongholdPieces.h"
|
||||
#include "java/JavaMath.h"
|
||||
#include "java/Random.h"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#include "platform/fs/fs.h"
|
||||
#include "minecraft/world/level/newbiome/layer/Layer.h"
|
||||
#if defined(__linux__)
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#endif
|
||||
#include "minecraft/world/level/biome/Biome.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
#include "LevelData.h"
|
||||
#include "app/common/Console_Debug_enum.h"
|
||||
#include "app/common/GameRules/GameRuleManager.h"
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "util/StringHelpers.h"
|
||||
#include "java/File.h"
|
||||
#include "java/InputOutputStream/ByteArrayInputStream.h"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "java/InputOutputStream/DataInputStream.h"
|
||||
#include "java/InputOutputStream/DataOutputStream.h"
|
||||
#include "minecraft/world/entity/ai/village/Villages.h"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "app/linux/Stubs/winapi_stubs.h"
|
||||
#include "minecraft/world/entity/Entity.h"
|
||||
#include "minecraft/world/entity/LivingEntity.h"
|
||||
#include "minecraft/world/entity/player/Player.h"
|
||||
|
|
|
|||
Loading…
Reference in a new issue