theos / logos

Preprocessor that simplifies Objective-C hooking.
https://theos.dev/docs/logos
Other
206 stars 34 forks source link

[Fix 72] generator config is not case-sensitive consistent #87

Open uroboro opened 2 years ago

uroboro commented 2 years ago

What does this implement/fix? Explain your changes.

Perl's can_load is case-insensitive which means that the system can find case variations of generator names but Thunk later cannot properly load the module.

For now, it detects the typo on the generator name but only warns the user instead of assuming which one they intended, to prevent allowing variations of the names to be used in source code.

Does this close any currently open issues?

72

uroboro commented 11 months ago

As Ethan explained in the issue thread, you can get the errors with just the %config line as the source code:

➤ for f in *; bat --pager none $f; logos.pl $f; end
───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: generator.x
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ %config(generator=internal)
   2   │ 
───────┴───────────────────────────────────────────────────────────────────────────────────────
#line 1 "generator.x"

───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: generator_bad_case.x
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ %config(generator=Internal)
   2   │ 
───────┴───────────────────────────────────────────────────────────────────────────────────────
Goto undefined subroutine &main:: at /Users/uroboro/theos/vendor/logos/bin/lib/Logos/Generator/Thunk.pm line 33.
───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: generator_inexistent.x
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ %config(generator=Internals)
   2   │ 
───────┴───────────────────────────────────────────────────────────────────────────────────────
Could not find or check module 'Logos::Generator::Internals::Generator' [THIS MAY BE A PROBLEM!] at /Users/uroboro/theos/vendor/logos/bin/lib/Logos/Generator.pm line 45.
generator_inexistent.x: error: I can't find the 'Internals' Generator!

It is possible that I'm seeing this issue with a case insensitive filesystem because I'm using MacOS (with changes in this PR):

➤ for f in *; bat --pager none $f; logos.pl $f; end
───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: generator.x
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ %config(generator=internal)
   2   │ 
───────┴───────────────────────────────────────────────────────────────────────────────────────
#line 1 "generator.x"

───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: generator_bad_case.x
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ %config(generator=Internal)
   2   │ 
───────┴───────────────────────────────────────────────────────────────────────────────────────
generator_bad_case.x: error: I can't find the 'Internal' Generator, did you mean 'internal'?
───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: generator_inexistent.x
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ %config(generator=Internals)
   2   │ 
───────┴───────────────────────────────────────────────────────────────────────────────────────
Could not find or check module 'Logos::Generator::Internals::Generator' [THIS MAY BE A PROBLEM!] at /Users/uroboro/theos/vendor/logos/bin/lib/Logos/Generator.pm line 45.
generator_inexistent.x: error: I can't find the 'Internals' Generator!

Regarding the check logic, can_load fails if it cannot find the module (according to case sensitive rules of the file system). On a case sensitive system, it won't find an 'Internal' module because it's called 'internal', but on a case insensitive it will.

Somewhere in between this and Thunk, the loading of the module does not happen in case insensitive systems and logos shows that "Goto undefined subroutine &main:: at" message. I'll simplify the logic to just make my additions as just an extra piece of code (leave lines 43-45 as they were originally).

BTW, the $Module::Load::Conditional::VERBOSE = 1; at the top might be unnecessary since we always show "....x: error: I can't find the 'Internals' Generator!" message.

L1ghtmann commented 1 week ago

Think this is pretty much ready to go. Did we want to adjust per the comment above or stick to what's pr'd?