nim-sds/nix/patches/nim-2.2.8-extra-mangling.patch
2026-04-06 12:41:55 +05:30

49 lines
1.4 KiB
Diff

--- a/compiler/modulegraphs.nim
+++ b/compiler/modulegraphs.nim
@@ -506,7 +506,11 @@
for i in 0..<trunc:
let c = rel[i]
case c
- of 'a'..'z', '0'..'9':
+ of 'a'..'m':
+ result.add char(c.uint8 + 13)
+ of 'n'..'z':
+ result.add char(c.uint8 - 13)
+ of '0'..'9':
result.add c
of {os.DirSep, os.AltSep}:
result.add 'Z' # because it looks a bit like '/'
--- a/compiler/modulepaths.nim
+++ b/compiler/modulepaths.nim
@@ -79,6 +79,17 @@
else:
result = fileInfoIdx(conf, fullPath)
+proc rot13(result: var string) =
+ # don't mangle .nim
+ let finalIdx =
+ if result.endsWith(".nim"): result.len - 4
+ else: result.len
+ for i, c in result[0..<finalIdx]:
+ case c
+ of 'a'..'m', 'A'..'M': result[i] = char(c.uint8 + 13)
+ of 'n'..'z', 'N'..'Z': result[i] = char(c.uint8 - 13)
+ else: discard
+
type
SelectedBase = enum
FromProject, FromSearchPath, FromNimblePath
@@ -109,9 +120,11 @@
of FromSearchPath: "@p"
of FromNimblePath: "@n"
- prefix & best.multiReplace(
+ result = prefix & best.multiReplace(
{$os.DirSep: "@s", $os.AltSep: "@s", "#": "@h", "@": "@@", ":": "@c"})
+ rot13(result)
proc demangleModuleName*(path: string): string =
## Demangle a relative module path.
result = path.multiReplace({"@@": "@", "@h": "#", "@s": "/", "@m": "", "@p": "", "@n": "", "@c": ":"})
+ rot13(result)