Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore code marked as such by the preprocessor / Swift Active Compilation Conditions #500

Open
tcldr opened this issue Jan 23, 2018 · 3 comments

Comments

@tcldr
Copy link

tcldr commented Jan 23, 2018

Many projects use swift preprocessor directives / active compilation conditions to enable conditional compilation. (e.g. lines surrounded by an if/ifdef/ifndef directive that should only compile when their condition – usually an environment variable – evaluates to true.)

As far as I can tell, Sourcery appears not to be aware of these markers and therefore blocks of code marked to be ignored are still processed by Sourcery – leading to compilation errors.

Searching the source code I see that the Source Kitten dependency may expose those lines of code which should be ignored so this may be something that could be added relatively simply?

@ilyapuchka
Copy link
Collaborator

@tcldr that's a really good suggestion.
If that's the issue we can maybe add special annotation to surround such blocks. But need to check what is the actual behaviour in this case and is there a way to solve it with SourceKitten.
But this might become more complicated if we would want Sourcery to parse source code depending on if conditions in such #ifdef are met or not, i.e. depending on the platform, swift version or compiler flag.

@tcldr
Copy link
Author

tcldr commented Jan 23, 2018

Great – fingers-crossed it's an easy win!

A special annotation could work, skippedByCompiler or something.

But if it's simpler, maybe skipping those blocks entirely and simply leveraging the preprocessor?

I guess it depends on whether there is a use-case for knowing which code the compiler has skipped during a Sourcery pass – but I imagine if you have marked code to be skipped during the preprocessor phase, you'd likely want it ignored by Sourcery too.

@art-divin
Copy link
Collaborator

#1145 is related, but does not resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants