Reputation: 2205
How can I get an access to the Bundle.main of the application inside the Macro? Basically I need to read the info.plist. Even more specifically, I have props there linked to my .xcconfig
props, and want to read and validate configs in compile time.
I have tried:
let bundle = Bundle.main
and getting the bundle of the Macro itself
I've tried also:
let bundle = Bundle(identifier: "com.myorg.AppName")
//"com.myorg.AppName" is the correct identifier of my app bundle, which I've double checked from the app itself
And getting nil
Any way to get the app's bundle/info.plist inside the Macro? We can't just pass the object to macro props, because it's pre-compile operation.
Upvotes: 0
Views: 395
Reputation: 2762
There are few cases to note when using macros here:
Macros run during compile time, while bundle is only available when you are running the final compiled app. So macros can't use bundles here as during compilation it is not available.
Your next option is accessing the file using current file system, but as of now macros don't have any access to file system but there is plan to add this in future:
The macro expansion operation is asynchronous, to account for potentially-asynchronous operations that will eventually be added to
MacroExpansionContext
. For example, operations that require additional communication with the compiler to get types of subexpressions, access files in the program, and so on.
So as of now your option is to use swift package plugins instead, create a build tool plugin that performs validation during build phase of the app. You can get more details on following resources on how to achieve what you want:
Upvotes: 0