amirrajan / rubymotion-applied

RubyMotion documentation provided by the community. Submit a pull request to the docs for a free one year indie subscription.
Apache License 2.0
49 stars 10 forks source link

Cyclical dependencies warning #105

Closed caramdache closed 5 years ago

caramdache commented 5 years ago

It's been a while since I compiled one of my projects and it suddenly raises warnings for possible cyclical dependencies. A while later, CoreData complains that some dynamic accessors cannot be resolved.

Build ./build/iPhoneSimulator-12.0-Development
WARNING! Possible cyclical dependency between ./app/about_controller.rb and ./app/events_controller.rb's class hierarchy. Consider revision if runtime exceptions occur around undefined symbols.
WARNING! Possible cyclical dependency between ./../lib/UITableViewTextFieldCell.rb and ./app/events_controller.rb's class hierarchy. Consider revision if runtime exceptions occur around undefined symbols.
WARNING! Possible cyclical dependency between ./app/event_controller.rb and ./app/events_controller.rb's class hierarchy. Consider revision if runtime exceptions occur around undefined symbols.
Compile ./../lib/UIColor_extensions.rb
Compile ...
Simulate /Users/home/Source/Events/build/iPhoneSimulator-12.0-Development/Events.app
(main)> CoreData: warning: dynamic accessors failed to find @property implementation for 'date' for entity 'Event' while resolving selector 'date' on class 'Event'.  Did you remember to declare it @dynamic or @synthesized in the @implementation ?

Intriguing, because these issues were never raised before by earlier version of RM. All the more intriguing that another project that follows a similar template (same class structure, same use of core data, use of the same RM lib, etc.) compiles and runs just fine.

Could this be a bug in RM 5.14 ?

amirrajan commented 5 years ago

The cyclical dependency warning was added last as part of the build process to bring attention to them. Your project may have always had them (or gems you depended on), this just brings them to light and become more important if you end up monkey patching classes that have cyclical dependencies.

caramdache commented 5 years ago

I've been trying to understand the error message and so I've included the code that you published earlier at: https://github.com/rubymotion/motion-support/issues/38#issuecomment-366676898.

However, in cyclic?, only file paths are available. Is there any way to find out the class(es) that trigger the cyclic dependency?

Besides, when I use defined?, RM print a duplicate warning for that file. Is this not supposed to turn the warning/issue off instead?

amirrajan commented 5 years ago

Applying the following patch will give you the full graph: https://github.com/infinitered/ProMotion/issues/810

There is also this gem that will let you visualize your dependencies: https://github.com/emad-elsaid/rubrowser

caramdache commented 5 years ago

Thanks for the pointers. https://github.com/infinitered/ProMotion/issues/810 only displays dependencies between files, NOT classes, as far as I can see.

rubrowser is excellent, thanks! However, it does not show any dependency between EventsController and AboutController. However, RM points out a circular dependency between ./app/events_controller.rb and ./app/about_controller.rb. Doesn't this look like a possible bug? capture d ecran 2018-09-25 a 11 16 33

caramdache commented 5 years ago

run seems like a more appropriate place to display the warning, as there can be multiple classes per file. Here is a suggested patch:

if cyclic?(dependency, def_path, ref_path)
    App.warn("Possible cyclical dependency for #{const} between #{def_path} and #{ref_path}'s. Consider revision if runtime exceptions occur around undefined 
    # remove cyclic 
    next
end
amirrajan commented 5 years ago

@caramdache are you monkey patching any gems you depend on?

Make sure you are including files in both app and lib

caramdache commented 5 years ago

No, but I'm monkey patching quite a few UIKit classes by myself. This is what the lib directory is for.

amirrajan commented 5 years ago

Are any of the libraries that you depend on also monkepatching the same UIKit libraries?

I don't think it'll be an issue given that it's all UIKit related. If you want you can email me at ar@amirrajan.net or DM on the Slack and I can help with your private repo.