From 0e4a0da6d19792aaab5213985488f3d37ef2bf67 Mon Sep 17 00:00:00 2001 From: "Denis Kuzmin (github/3F)" Date: Tue, 17 Dec 2024 20:44:21 +0300 Subject: [PATCH] Pre-Proc: fixed edit Exec raw command & +Log option for IlMerge --- src/DllExport/Wizard/Gears/PostProcGear.cs | 17 ++++-------- src/DllExport/Wizard/Gears/PreProcGear.cs | 22 +++++++++------- src/DllExport/Wizard/PostProc.cs | 20 ++++---------- src/DllExport/Wizard/PreProc.cs | 16 +++++------- .../UI/Controls/PreProcControl.Designer.cs | 15 +++++++++++ .../Wizard/UI/Controls/PreProcControl.cs | 26 +++++++++---------- src/DllExport/Wizard/UserConfig.cs | 13 +++++++--- 7 files changed, 67 insertions(+), 62 deletions(-) diff --git a/src/DllExport/Wizard/Gears/PostProcGear.cs b/src/DllExport/Wizard/Gears/PostProcGear.cs index cdb8ede..a5d2ca4 100644 --- a/src/DllExport/Wizard/Gears/PostProcGear.cs +++ b/src/DllExport/Wizard/Gears/PostProcGear.cs @@ -13,15 +13,13 @@ namespace net.r_eg.DllExport.Wizard.Gears { - internal sealed class PostProcGear: IProjectGear + internal sealed class PostProcGear(IProjectSvc prj): IProjectGear { - private readonly IProjectSvc prj; + private readonly IProjectSvc prj = prj ?? throw new ArgumentNullException(nameof(prj)); private IUserConfig Config => prj.Config; private ISender Log => Config.Log; - private string Id => $"{Project.METALIB_PK_TOKEN}:PostProc"; - public void Install() { CfgPostProc(Config.PostProc.Type); @@ -33,11 +31,6 @@ public void Uninstall(bool hardReset) RemovePostProcTarget(); } - public PostProcGear(IProjectSvc prj) - { - this.prj = prj ?? throw new ArgumentNullException(nameof(prj)); - } - private void CfgPostProc(CmdType type) { prj.SetProperty(MSBuildProperties.DXP_POST_PROC_TYPE, (long)type); @@ -51,7 +44,7 @@ private void CfgPostProc(CmdType type) Log.send(this, $"Proc-Env: {Config.PostProc.ProcEnv}"); var target = prj.AddTarget(MSBuildTargets.DXP_POST_PROC); - target.Label = Id; + target.Label = ID; if((type & CmdType.Custom) == CmdType.Custom) { @@ -89,7 +82,7 @@ private ProjectTargetElement AddRecursiveDependentsFor(string id, CmdType type) var target = AllocateDerivativeTarget("For" + id); target.AfterTargets = MSBuildTargets.DXP_POST_PROC; - target.Label = Id; + target.Label = ID; target.Outputs = $"%({GetDependentsTargetDir(type)}.Identity)"; return target; @@ -136,7 +129,7 @@ private void RemoveDerivativeTargets() { foreach(var target in prj.XProject.Project.Xml.Targets) { - if((target.Label != Id && target.Label != Project.METALIB_PK_TOKEN) // METALIB_PK_TOKEN was for 1.7.3 or less + if((target.Label != ID && target.Label != Project.METALIB_PK_TOKEN) // METALIB_PK_TOKEN was for 1.7.3 or less || target.Name == MSBuildTargets.DXP_POST_PROC || !target.Name.StartsWith(GetDerivativeTargetName(null))) { diff --git a/src/DllExport/Wizard/Gears/PreProcGear.cs b/src/DllExport/Wizard/Gears/PreProcGear.cs index 5d44b11..8afe955 100644 --- a/src/DllExport/Wizard/Gears/PreProcGear.cs +++ b/src/DllExport/Wizard/Gears/PreProcGear.cs @@ -25,8 +25,6 @@ internal sealed class PreProcGear(IProjectSvc prj): IProjectGear private readonly IProjectSvc prj = prj ?? throw new ArgumentNullException(nameof(prj)); - private string Id => $"{Project.METALIB_PK_TOKEN}:PreProc"; - private IUserConfig Config => prj.Config; private IXProject XProject => prj.XProject; private ISender Log => Config.Log; @@ -42,7 +40,7 @@ public void Install() public void Uninstall(bool hardReset) { RemovePreProcTarget(hardReset); - XProject.RemovePropertyGroups(p => p.Label == Id); + XProject.RemovePropertyGroups(p => p.Label == ID); prj.RemovePackageReferences("Conari") .RemovePackageReferences("ilmerge"); @@ -98,7 +96,7 @@ private void AddPreProcTarget(string fxCmd, string corCmd, CmdType type) var target = prj.AddTarget(MSBuildTargets.DXP_PRE_PROC); target.BeforeTargets = MSBuildTargets.DXP_MAIN; - target.Label = Id; + target.Label = ID; target.AddPropertyGroup().SetProperty ( @@ -119,7 +117,7 @@ private void AddPreProcTarget(string fxCmd, string corCmd, CmdType type) AddILMergeWrapper(target, ignoreErr, _=> { - if(corCmd != fxCmd) + if((type & CmdType.ILMerge) == CmdType.ILMerge) { AddExecTask(target, fxCmd, "'$(IsNetCoreBased)'!='true'", ignoreErr); AddExecTask(target, corCmd, "'$(IsNetCoreBased)'=='true'", ignoreErr); @@ -185,8 +183,14 @@ private string FormatPreProcCmd(CmdType type, StringBuilder sb) if((type & CmdType.ILMerge) == CmdType.ILMerge) { - return $"$(ILMergeConsolePath) {cmd} {ILMERGE_TMP}\\$(TargetName).dll /out:$(TargetFileName)" - + (((type & CmdType.DebugInfo) == 0) ? " /ndebug" : string.Empty); + StringBuilder ilm = new(100); + ilm.Append("$(ILMergeConsolePath) "); + ilm.Append(cmd); + ilm.Append(" " + ILMERGE_TMP); + ilm.Append("\\$(TargetName).dll /out:$(TargetFileName)"); + if((type & CmdType.DebugInfo) == 0) ilm.Append(" /ndebug"); + if((type & CmdType.Log) == CmdType.Log) ilm.Append(" /log:$(TargetFileName).ILMerge.log"); + return ilm.ToString(); } return cmd; } @@ -203,7 +207,7 @@ private bool RemoveLabeledProperty(string name) ProjectPropertyElement _Get() => XProject.Project.Xml.Properties .FirstOrDefault(p => p.Name == name - && (p.Label == Id || p.Label == Project.METALIB_PK_TOKEN) + && (p.Label == ID || p.Label == Project.METALIB_PK_TOKEN) ); // METALIB_PK_TOKEN was for 1.7.3 or less var pp = _Get(); @@ -235,7 +239,7 @@ private sealed class _FxCorArgBuilder(int capacity) public StringBuilder AppendCor(string value) => Cor.Append(GetArg(value)); - private string GetArg(string value) => value + " "; + private string GetArg(string value) => string.IsNullOrWhiteSpace(value) ? string.Empty : value + " "; } } } diff --git a/src/DllExport/Wizard/PostProc.cs b/src/DllExport/Wizard/PostProc.cs index 978b246..2635cf3 100644 --- a/src/DllExport/Wizard/PostProc.cs +++ b/src/DllExport/Wizard/PostProc.cs @@ -15,6 +15,8 @@ namespace net.r_eg.DllExport.Wizard /// public sealed class PostProc { + internal const string ID = Project.METALIB_PK_TOKEN + ":" + nameof(PostProc); + private const string ENV_SLN = "$(" + MSBuildProperties.SLN_PATH + ")"; private const string ENV_PRJ = "$(" + MSBuildProperties.MSB_THIS_FULL_FPATH + ")"; @@ -37,26 +39,14 @@ public enum CmdType: long /// /// Never null environment. /// - public IList ProcEnv - { - get; - private set; - } + public IList ProcEnv { get; private set; } /// /// Never null command. /// - public string Cmd - { - get; - private set; - } + public string Cmd { get; private set; } - public CmdType Type - { - get; - private set; - } + public CmdType Type { get; private set; } public PostProc Configure(CmdType type = CmdType.None, string env = null, string cmd = null) { diff --git a/src/DllExport/Wizard/PreProc.cs b/src/DllExport/Wizard/PreProc.cs index c0e08f1..90211b4 100644 --- a/src/DllExport/Wizard/PreProc.cs +++ b/src/DllExport/Wizard/PreProc.cs @@ -12,20 +12,14 @@ namespace net.r_eg.DllExport.Wizard /// public sealed class PreProc { + internal const string ID = Project.METALIB_PK_TOKEN + ":" + nameof(PreProc); + /// /// Never null command. /// - public string Cmd - { - get; - private set; - } + public string Cmd { get; private set; } - public CmdType Type - { - get; - private set; - } + public CmdType Type { get; private set; } [System.Flags] public enum CmdType: long @@ -41,6 +35,8 @@ public enum CmdType: long DebugInfo = 0x8, IgnoreErr = 0x10, + + Log = 0x20, } public PreProc Configure(CmdType type = CmdType.None, string cmd = null) diff --git a/src/DllExport/Wizard/UI/Controls/PreProcControl.Designer.cs b/src/DllExport/Wizard/UI/Controls/PreProcControl.Designer.cs index c5c4393..7fdbbf2 100644 --- a/src/DllExport/Wizard/UI/Controls/PreProcControl.Designer.cs +++ b/src/DllExport/Wizard/UI/Controls/PreProcControl.Designer.cs @@ -39,6 +39,7 @@ private void InitializeComponent() this.chkIgnoreErrors = new System.Windows.Forms.CheckBox(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.chkGenDebugInfo = new System.Windows.Forms.CheckBox(); + this.chkLog = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // radioPreProcDisabled @@ -159,10 +160,23 @@ private void InitializeComponent() this.chkGenDebugInfo.Text = "Generate debug info"; this.chkGenDebugInfo.UseVisualStyleBackColor = true; // + // chkLog + // + this.chkLog.AutoSize = true; + this.chkLog.Enabled = false; + this.chkLog.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.chkLog.Location = new System.Drawing.Point(186, 5); + this.chkLog.Name = "chkLog"; + this.chkLog.Size = new System.Drawing.Size(41, 17); + this.chkLog.TabIndex = 29; + this.chkLog.Text = "Log"; + this.chkLog.UseVisualStyleBackColor = true; + // // PreProcControl // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.Controls.Add(this.chkLog); this.Controls.Add(this.chkGenDebugInfo); this.Controls.Add(this.chkIgnoreErrors); this.Controls.Add(this.radioPreProcDisabled); @@ -192,5 +206,6 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox chkIgnoreErrors; private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.CheckBox chkGenDebugInfo; + private System.Windows.Forms.CheckBox chkLog; } } diff --git a/src/DllExport/Wizard/UI/Controls/PreProcControl.cs b/src/DllExport/Wizard/UI/Controls/PreProcControl.cs index dd3f9b5..30b6a15 100644 --- a/src/DllExport/Wizard/UI/Controls/PreProcControl.cs +++ b/src/DllExport/Wizard/UI/Controls/PreProcControl.cs @@ -21,9 +21,7 @@ internal partial class PreProcControl: UserControl public void Render(PreProc instance) { - if(instance == null) { - throw new ArgumentNullException(nameof(instance)); - } + if(instance == null) throw new ArgumentNullException(nameof(instance)); SetCmdType(instance.Type); txtPreProc.Text = instance.Cmd; @@ -36,18 +34,15 @@ public PreProc Export(PreProc obj) private void SetCmdType(CmdType type) { - if(type == CmdType.None) - { - radioPreProcDisabled.Checked = true; - return; - } + if(type == CmdType.None) { radioPreProcDisabled.Checked = true; return; } if((type & CmdType.ILMerge) == CmdType.ILMerge) { radioILMerge.Checked = true; } if((type & CmdType.Exec) == CmdType.Exec) { radioRawExec.Checked = true; } - chkMergeConari.Checked = ((type & CmdType.Conari) == CmdType.Conari); - chkIgnoreErrors.Checked = ((type & CmdType.IgnoreErr) == CmdType.IgnoreErr); - chkGenDebugInfo.Checked = ((type & CmdType.DebugInfo) == CmdType.DebugInfo); + chkMergeConari.Checked = (type & CmdType.Conari) == CmdType.Conari; + chkIgnoreErrors.Checked = (type & CmdType.IgnoreErr) == CmdType.IgnoreErr; + chkGenDebugInfo.Checked = (type & CmdType.DebugInfo) == CmdType.DebugInfo; + chkLog.Checked = (type & CmdType.Log) == CmdType.Log; } private CmdType GetCmdType() @@ -60,6 +55,7 @@ private CmdType GetCmdType() if(chkMergeConari.Checked) { ret |= CmdType.Conari; } if(chkIgnoreErrors.Checked) { ret |= CmdType.IgnoreErr; } if(chkGenDebugInfo.Checked) { ret |= CmdType.DebugInfo; } + if(chkLog.Checked) { ret |= CmdType.Log; } return ret; } @@ -72,7 +68,7 @@ private void SetUIMergeConari(bool disabled) private bool SetUIPreProcCmd(bool disabled) { txtPreProc.Enabled = !disabled; - txtPreProc.BackColor = (disabled) ? SystemColors.Control : SystemColors.Window; + txtPreProc.BackColor = disabled ? SystemColors.Control : SystemColors.Window; chkIgnoreErrors.Checked = chkIgnoreErrors.Enabled = !disabled; @@ -88,6 +84,10 @@ private void ChkMergeConari_CheckedChanged(object sender, EventArgs e) private void RadioRawExec_CheckedChanged(object sender, EventArgs e) => SetUIMergeConari(radioRawExec.Checked); private void LinkAboutConari_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) => "https://github.com/3F/DllExport/wiki/Quick-start#when-conari-can-help-you".OpenUrl(); private void LinkPreProc_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) => "https://github.com/3F/DllExport/issues/40".OpenUrl(); - private void RadioILMerge_CheckedChanged(object sender, EventArgs e) => chkGenDebugInfo.Checked = chkGenDebugInfo.Enabled = radioILMerge.Checked; + private void RadioILMerge_CheckedChanged(object sender, EventArgs e) + { + chkLog.Enabled = chkGenDebugInfo.Checked = chkGenDebugInfo.Enabled = radioILMerge.Checked; + if(!radioILMerge.Checked) chkLog.Checked = false; + } } } diff --git a/src/DllExport/Wizard/UserConfig.cs b/src/DllExport/Wizard/UserConfig.cs index f6cbf6b..db71e07 100644 --- a/src/DllExport/Wizard/UserConfig.cs +++ b/src/DllExport/Wizard/UserConfig.cs @@ -177,9 +177,16 @@ protected string GetPreProcCmd(PreProcType type, IXProject xp) if((type & PreProcType.Exec) == PreProcType.Exec) { var tExec = xp?.Project.Xml?.Targets - .FirstOrDefault(t => t.Name == MSBuildTargets.DXP_PRE_PROC && t.Label == Project.METALIB_PK_TOKEN)? - .Tasks - .FirstOrDefault(t => t.Name == "Exec"); + .FirstOrDefault + (t => + t.Name == MSBuildTargets.DXP_PRE_PROC + && + ( + t.Label == PreProc.ID + || t.Label == Project.METALIB_PK_TOKEN // for 1.7.3 or less + ) + )? + .Tasks.FirstOrDefault(t => t.Name == "Exec"); if(tExec != null) {