Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Strip lines from source code files prior to build process.

Discussion in 'Testing & Automation' started by fwalkerCirca, Mar 19, 2019.

  1. fwalkerCirca

    fwalkerCirca

    Joined:
    Apr 10, 2017
    Posts:
    57
    Hello, I am looking for some confirmation on what might be the best way to approach this task.
    The task is: I want to be able to strip some code prior to a build.
    My initial idea would be to copy the entire project file structure to a temp directory, then process/rewrite/strip the code files and finally point the projectPath for the build process to this new directory.
    But I keep thinking that there has to be a cleaner way. A way to perhaps handle/copy only the script files to a temp directory? and have the build process use the code files to build from the new directory?
    Maybe there is a way to inject the stripping prior to generating the object files?
    Any thoughts are appreciated.
     
  2. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,194
    I think a bit more context would help. Is it really necessary to strip the code prior to the build, or do you just want to make sure it isn't present in the build output (e.g. using [Conditional] or #if/#endif blocks)?
     
  3. fwalkerCirca

    fwalkerCirca

    Joined:
    Apr 10, 2017
    Posts:
    57
    Sure. So the answered would be that I would like to make sure the code isn't present on the build output, however, I would like to do it without using #if blocks ! :)
     
  4. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,194
    Why don't you want to use #if blocks?
     
  5. fwalkerCirca

    fwalkerCirca

    Joined:
    Apr 10, 2017
    Posts:
    57
    Just our preferences... There would be lots of these blocks and they would make source code hard to read. Plus there would be no way to enforce for devs to add the #if blocks.
     
    Last edited: Mar 20, 2019
  6. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,254
    There are 2 ways i can think of: [Conditional] attribute as @superpig suggested, which works out of the box, but is limited by a few simple "rules", or coming up with your own C# assembly rewriter (probably based on Mono.Cecil) that will strip some stuff from the compiled assemblies.

    Option number 2 is more complex (but probably cooler to implement hahaha).
     
  7. arielsan

    arielsan

    Joined:
    Dec 3, 2013
    Posts:
    28
    Can't you use different assemblies marked as editor only or something like that?, to avoid them to be included during the build.