OxygeneCodeProvider and optimize parameter

I have a question regarding the OxygeneCodeProvider and the CompilerOptions.

Depending on an Optimize flag, I set the CompilerOptions with the “-O” or without the “-O” flag

CompilerOptions = "-allowglobals:yes -allowlegacywith:yes -delphicompatibility:yes -allowimplicitout:yes -delphidivide:yes" + (options.HasFlag(PascalOptions.Optimize) ? " -O" : string.Empty),

But it seems like regardless of the “-O” or not, the OxygeneCodeProvider produces (almost - beside time and path dependent differences) exactly the same DLL.

Is this correct or do I not specify the parameter properly? Is there a way to tell from the DLL if it’s compiled with debug or not or if it’s optimized? When I look at the file info, Debug Version always seems to be false (but I have to say, I do not set this part in the assembly info)

(Usually I also set IncludeDebugInformation, when I omit the “-O” and that’s properly honored)

There’s an assembly level attribute:

This is debug:
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations)]

Release would NOT have DisableOptimizations.

Thanx Carlo.

Argl, I generate my own Assembly Info using GenerateCodeFromCompileUnit but do not include the DisableOptimizations info :frowning: sorry, my fault.

The compiler should create that attribute. You can see what it generates in say ilspy. (Unless you provide it yourself of course)

I looked at the DLL and the attribute is there:

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.None)]

I looked at several DLLs, some compiled with -O some without and it’s always DebuggingModes.None.

hrmm that is weird. I checked the code and -O/Optimize IS hooked up.

I’m playing around a bit with the CodeDom. So I kind of converted my DCL PASCAL command from C# to an Oxygene command line program and added some code generation. It’s not for any use, a playground and … and … :slight_smile:

CodeDomOptimizeTest.exe --help
-f, --Files Files to be compiled, delimited by coma.
-b, --Binary Filename of the DLL.
-o, --Optimize (Default: False) Specifies optimize or not.
-d, --Debug (Default: False) Specifies debug mode or not.
-w, --WarningLevel (Default: 4) Specifies the warning level.
-a, --Attributes Specifies a list of assembly attributes separated by coma, ex: Company=AXA.
–createdummy (Default: False) Creates a dummy source file.
–help Display this help screen.

So, when I compile a dummy file (–createdummy creates a pas file with a class containing two fields) and produce an AssemblyInfo.pas with AssemblyCompany set to axa, then I get (as expected) a DLL containing the compiled dummy file and the assembly info.

Now, I can compile with debug or not and with optimize or not, the Assembly Info always looks the same (ILSpy):

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.None)]
[assembly: AssemblyCompany("axa")]

When I analyze the DLL header, it sais:

File Version Information : 

Version language : German (Switzerland)
      ProductVersion	: 1.0
      FileVersion	: 1.0.0.0
      CompanyName	: axa

Creation Date	: 21/11/2017  17:39:21 
Last Modif. Date	: 21/11/2017  17:41:09 
Last Access Date	: 21/11/2017  17:39:21 
FileSize	: 2560 bytes ( 2.500 KB,  0.002 MB ) 
FileVersionInfoSize	: 708 bytes  
File type	: Dynamic Link Library (0x2) 
Target OS	: Win32 (0x4) 
File/Product version	: 1.0.0.0 / 1.0.0.0
Language 	: German (Switzerland) (0x0) 
Character Set	: Not referenced (0x0) 

Build Information : 
Debug Version	: no 
Patched Version	: no 
Prerelease Version	: no 
Private Version	: no 
Special Build	: no 

Same result for:

  • CodeDomOptimizeTest --createdummy -a"namespace=aa,company=axa" -O
  • CodeDomOptimizeTest --createdummy -a"namespace=aa,company=axa" -debug
  • CodeDomOptimizeTest --createdummy -a"namespace=aa,company=axa"

I also double checked (and it works as expected):

  • by debugger that the CompilerOptions contains the -O:

parameters.CompilerOptions := “-allowglobals:yes -allowlegacywith:yes -delphicompatibility:yes -allowimplicitout:yes -delphidivide:yes” + if optimize then " -O" else String.Empty;

  • and that the mdb and pdb files are created when I compile with -debug.

I might look at it again tomorrow, but so far I have no idea.

CodeDomOptimizeTest.zip (36.1 KB)

P.S. You have to first restore the nuget package to compile it.

Thanks, logged as bugs://79072

bugs://79072 got closed with status nochangereq.

Oke I think I got it. Turns out the default for Optimize is true.
So you want to change your code to:

parameters.CompilerOptions := "-allowglobals:yes -allowlegacywith:yes -delphicompatibility:yes -allowimplicitout:yes -delphidivide:yes" + if optimize then " -O" else ' -O-';

This gets me:
Optimize:
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.None)]
non Optimize:

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations)]

Ok, thanx, I’ll try it.