How to remove private code before publishing?

eresonance

We have a medium-sized C codebase that provides an API for using our hardware products. We provide the source for this API so that customers can compile it into whatever environment they choose. It's important that the source is legible and easily navigated as many people do just that. We don't obfuscate it in any way.

In our code we have a number of functions and sections that are for internal testing only, stuff like wrapper methods, low level checks, etc. None of it is particularly interesting nor harmful in any respect but we don't really want people using them or getting confused about what they are. This has happened numerous times before despite having warnings in the code about using them.

Is there any tool or method by which we can filter out these sections before publishing the source?

Right now we use a custom method with comments, however it's hard to parse and maintain:

/* $if : INTERNAL : some comment */
debug_code();
/* $endif : INTERNAL */

I've looked at using #ifdef and the preprocessor but there doesn't seem to be a way to preprocess specific defines/macros and not the whole file at once. I would only want the specific blocks preprocessed (and therefore removed) and not all the defines and in the code.

EDIT: From my comment below, the stuff we would like to remove from the published code should not be located in separate files. Like wrappers, we prefer to keep those next to the functions they wrap to make it easy to find. Other times we have detailed comments about internal implementation that we want in the code for our reference but don't want others seeing it.

rici

One tool I've found useful for applications like this is coan, which is still actively maintained (although apparently it currently doesn't compile cleanly on Mac OS X, if that is a concern).

Coan is designed for code analysis and it can perform quite a few tasks which you probably don't need. As long as you don't explicitly #define the preprocessor macros which surround the code to be removed, you should be able to just -Define or -Undefine as appropriate.

Coan wants to keep the code consistent, and can evaluate preprocessor macros so as to correctly evaluate and possibly eliminate preprocessor conditionals. Even if you don't ask it to do the evaluation, it will normally interpret and simplify #ifdef blocks if the definition is visible. Even that behaviour can be altered with the --no-transients option, but it will emit a warning.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to remove private code before publishing?

From Dev

Do I need to remove testDevice code for AdView in android before publishing?

From Dev

How do I remove my personal details before publishing my .dotfiles repository to GitHub?

From Dev

How to prevent accidental publishing of a private pub package

From Dev

What changes are required in admob AdRequest code before publishing android app?

From Dev

Remove code before <html> tag

From Dev

How to test AdMob before publishing application to Google Play?

From Dev

Testing AdMob before publishing

From Dev

How to remove all hyperlinks from a LibreOffice writer document ready for publishing?

From Dev

How do you remove tags before and after a special tag in html code using Javascript?

From Dev

Error in Publishing a code in matlab

From Dev

Error in code publishing

From Dev

How to "insert" code before this(...) or super(...)?

From Dev

How to unit test this code with private implementation?

From Dev

How is private code accessed in nodejs modules?

From Dev

How is private code accessed in nodejs modules?

From Java

Authentication error on publishing to private NPM repository on Nexus

From Dev

How can I compress / gzip my mimified .js and .css files before publishing to AWS S3?

From Dev

How to test a Google Apps Script with multiple active users before publishing the addon?

From Dev

How to use Facebook deferred deep linking feature for new installs and to test the same before publishing iOS App to appStore?

From Dev

How to remove characters before and including an underscore?

From Dev

How to remove certain elements before taking screenshot?

From Dev

How to remove text before | character in notepad++

From Dev

how to remove the unwanted space before the image links

From Dev

how to remove everything before second occurance of underscore

From Dev

How to remove everything before a specific tag innerHTML

From Dev

How to remove a listener before an event takes place?

From Dev

How to remove text before | character in notepad++

From Dev

How to remove class before leaving a element in jQuery

Related Related

  1. 1

    How to remove private code before publishing?

  2. 2

    Do I need to remove testDevice code for AdView in android before publishing?

  3. 3

    How do I remove my personal details before publishing my .dotfiles repository to GitHub?

  4. 4

    How to prevent accidental publishing of a private pub package

  5. 5

    What changes are required in admob AdRequest code before publishing android app?

  6. 6

    Remove code before <html> tag

  7. 7

    How to test AdMob before publishing application to Google Play?

  8. 8

    Testing AdMob before publishing

  9. 9

    How to remove all hyperlinks from a LibreOffice writer document ready for publishing?

  10. 10

    How do you remove tags before and after a special tag in html code using Javascript?

  11. 11

    Error in Publishing a code in matlab

  12. 12

    Error in code publishing

  13. 13

    How to "insert" code before this(...) or super(...)?

  14. 14

    How to unit test this code with private implementation?

  15. 15

    How is private code accessed in nodejs modules?

  16. 16

    How is private code accessed in nodejs modules?

  17. 17

    Authentication error on publishing to private NPM repository on Nexus

  18. 18

    How can I compress / gzip my mimified .js and .css files before publishing to AWS S3?

  19. 19

    How to test a Google Apps Script with multiple active users before publishing the addon?

  20. 20

    How to use Facebook deferred deep linking feature for new installs and to test the same before publishing iOS App to appStore?

  21. 21

    How to remove characters before and including an underscore?

  22. 22

    How to remove certain elements before taking screenshot?

  23. 23

    How to remove text before | character in notepad++

  24. 24

    how to remove the unwanted space before the image links

  25. 25

    how to remove everything before second occurance of underscore

  26. 26

    How to remove everything before a specific tag innerHTML

  27. 27

    How to remove a listener before an event takes place?

  28. 28

    How to remove text before | character in notepad++

  29. 29

    How to remove class before leaving a element in jQuery

HotTag

Archive