Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Targets need to be path namespaced to avoid conflicts #354
Right now we add every target's lib directory to the Ruby path. This introduces issues if multiple targets try to require the same file name because the first target will "win" and only its file will be used.
The solution would be to require code outside the target to specify the target name in the require path: require 'INST/lib/my_conversion'. However, this is a major breaking change that probably needs COSMOS 4.0.0.
Whatever the solution, we should ensure the REQUIRE keyword in target.txt still works locally. Other code inside a target lib should perhaps use require_relative to ensure it can be moved. Solution should consider how renaming the target directory could potentially break things.
Its in 4.0.0 though not documented well, or with good examples.
The primary change was to top_level.rb#require_class. It now allows you to pass a ClassName instead of filename in the cosmos config files for things, such as interfaces, that in the past just accepted a filename for the interface class. This allows the class name to include namespacing. So instead of tcpip_client_interface.rb you could pass MyTarget::TcpipClientInterface.
Also, inside of target.txt you should use the REQUIRE keyword to require everything needed by the target. This REQUIRE will always try to load the file from the targets lib folder first, before searching the entire system path. This guarantees that if a target defines a file, it will be required from that target even if a same named file is in a different targets lib folder.
Sorry this isn't more clear, but it is implemented, and there is a solution now.