MixedRealityToolkit-Unity icon indicating copy to clipboard operation
MixedRealityToolkit-Unity copied to clipboard

DEVELOPMENT_BUILD Symbol injection

Open Maesla opened this issue 2 years ago • 0 comments

Describe the bug

DEVEMOPMENT_BUILD is set in buildinfo but not used in the compilation

To reproduce

Create any code inside the bock

#If DEVELOPMENT_BUILD Debug.Log("Hello world"); //any functionality #endif

Steps to reproduce the behavior:

  1. Go to 'Build Window'
  2. Click on 'Appx Build Options'
  3. Scroll down to 'Build Configuration'
  4. Select 'Release'
  5. Create the vsprojet
  6. Launch the appx on the hololens2
  7. See error: 'You don't see the code inside #If DEVELOPMENT_BUILD #endIf

Expected behavior

I expect to see the effect of the code inside the block

Screenshots

image

If applicable, add screenshots to help explain your problem.

Your setup (please complete the following information)

  • Unity Version 2020.3.41
  • MRTK Version 2.7.3

Target platform (please complete the following information)

  • HoloLens 2

Additional context

I am trying to add some development code inside #If DEVELOPMENT_BUILD #endif

I've seen that MRTK uses it's own buildpipelne, so EditorUserBuildSettings.development is not used in this custom buildpipeline.

The main class is this UnityPlayerBuildTools https://github.com/microsoft/MixedRealityToolkit-Unity/blob/main/Assets/MRTK/Core/Utilities/BuildAndDeploy/UnityPlayerBuildTools.cs

In this class, you define different symbols and settings.

Regarding DEVELOPMENT_BUILD, you have two blocks that might affect the symbol

            if (buildInfo.HasAnySymbols(BuildSymbolDebug))
            {
                buildInfo.BuildOptions |= BuildOptions.Development | BuildOptions.AllowDebugging;
            }

This first one works perfectly. If the buildconfiguration is selected as "debug", DEVELOPMENT_BUILD is defined

The second block is the following:

            if (buildInfo.HasAnySymbols(BuildSymbolRelease))
            {
                // Unity automatically adds the DEBUG symbol if the BuildOptions.Development flag is
                // specified. In order to have debug symbols and the RELEASE symbols we have to
                // inject the symbol Unity relies on to enable the /debug+ flag of csc.exe which is "DEVELOPMENT_BUILD"
                buildInfo.AppendSymbols("DEVELOPMENT_BUILD");
            }

So, if the build configuration is "release", you inject manually "DEVELOPMENT_BUILD"

But when I create the project on "release", actually "DEVELOPMENT_BUILD" is not defined.

My guessing is that buildInfo.AppendSymbols("DEVELOPMENT_BUILD"); is done on line 76, but PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, buildInfo.BuildSymbols) is done before, in line 57

https://github.com/microsoft/MixedRealityToolkit-Unity/blob/476b77438442c4aff25d3a569d3c9fe90c0c6ce9/Assets/MRTK/Core/Utilities/BuildAndDeploy/UnityPlayerBuildTools.cs#L76

https://github.com/microsoft/MixedRealityToolkit-Unity/blob/476b77438442c4aff25d3a569d3c9fe90c0c6ce9/Assets/MRTK/Core/Utilities/BuildAndDeploy/UnityPlayerBuildTools.cs#L57

UnityPlayerBuildTools has changed in 2.8.2 and 3.0 but I don't see any major differences regarding this

So my questions are:

  1. Should DEVELOPMENT_BUILD be defined on the application on release configuration, taking into account line 76? Maybe PlayerSettings.SetScriptingDefineSymbolsForGroup should be moved after all symbols have been added to buildinfo
  2. If it is not an error and buildInfo.AppendSymbols("DEVELOPMENT_BUILD") is deliberately added after SetScriptingDefineSymbolsForGroup , what is that line for? I don't see any use in any part of the code after adding it
  3. What would be the recommended approach for defining that symbol? Debug configuration enables other things, like the "attach to debugger" window

Thank you

Maesla avatar Nov 25 '22 11:11 Maesla