diff options
author | Rob Mensching <rob@firegiant.com> | 2022-03-31 16:50:07 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2022-03-31 18:01:06 -0700 |
commit | 88b472e81aae5bcd68255469c5f54e9e35a41ec3 (patch) | |
tree | 0dcb158829f2ba89699cbe21c4c747d78944c964 | |
parent | 47582b162368e8edf7a3b11c13b8e9dabc5f0a26 (diff) | |
download | wix-88b472e81aae5bcd68255469c5f54e9e35a41ec3.tar.gz wix-88b472e81aae5bcd68255469c5f54e9e35a41ec3.tar.bz2 wix-88b472e81aae5bcd68255469c5f54e9e35a41ec3.zip |
Support using response file for long command-lines in MakeSfxCA
Fixes wixtoolset/issues#4688
-rw-r--r-- | src/dtf/WixToolset.Dtf.CustomAction/WixToolset.Dtf.CustomAction.targets | 22 | ||||
-rw-r--r-- | src/dtf/WixToolset.Dtf.MakeSfxCA/MakeSfxCA.cs | 80 |
2 files changed, 81 insertions, 21 deletions
diff --git a/src/dtf/WixToolset.Dtf.CustomAction/WixToolset.Dtf.CustomAction.targets b/src/dtf/WixToolset.Dtf.CustomAction/WixToolset.Dtf.CustomAction.targets index 127bb29d..9d63f24c 100644 --- a/src/dtf/WixToolset.Dtf.CustomAction/WixToolset.Dtf.CustomAction.targets +++ b/src/dtf/WixToolset.Dtf.CustomAction/WixToolset.Dtf.CustomAction.targets | |||
@@ -29,7 +29,7 @@ | |||
29 | @(IntermediateAssembly) - Managed custom action assembly. | 29 | @(IntermediateAssembly) - Managed custom action assembly. |
30 | @(Content) - Project items of type Content will be included in the package. | 30 | @(Content) - Project items of type Content will be included in the package. |
31 | $(CustomActionContents) - Optional space-delimited list of additional files to include. | 31 | $(CustomActionContents) - Optional space-delimited list of additional files to include. |
32 | 32 | ||
33 | [OUT] | 33 | [OUT] |
34 | $(IntermediateOutputPath)$(TargetCAFileName) - Managed custom action package with unmanaged stub. | 34 | $(IntermediateOutputPath)$(TargetCAFileName) - Managed custom action package with unmanaged stub. |
35 | ================================================================================================== | 35 | ================================================================================================== |
@@ -44,7 +44,7 @@ | |||
44 | Condition=" '%(Extension)' == '.dll' or '%(Extension)' == '.exe' " /> | 44 | Condition=" '%(Extension)' == '.dll' or '%(Extension)' == '.exe' " /> |
45 | <CustomActionReferenceContents Include="@(ReferenceComWrappersToCopyLocal)" | 45 | <CustomActionReferenceContents Include="@(ReferenceComWrappersToCopyLocal)" |
46 | Condition=" '%(Extension)' == '.dll' or '%(Extension)' == '.exe' " /> | 46 | Condition=" '%(Extension)' == '.dll' or '%(Extension)' == '.exe' " /> |
47 | 47 | ||
48 | <!-- include PDBs for Debug only --> | 48 | <!-- include PDBs for Debug only --> |
49 | <CustomActionReferenceContents Include="@(IntermediateAssembly->'%(RootDir)%(Directory)%(Filename).pdb')" | 49 | <CustomActionReferenceContents Include="@(IntermediateAssembly->'%(RootDir)%(Directory)%(Filename).pdb')" |
50 | Condition=" Exists('%(RootDir)%(Directory)%(Filename).pdb') and '$(Configuration)' == 'Debug' " /> | 50 | Condition=" Exists('%(RootDir)%(Directory)%(Filename).pdb') and '$(Configuration)' == 'Debug' " /> |
@@ -60,17 +60,27 @@ | |||
60 | - Project items of type Content | 60 | - Project items of type Content |
61 | - Additional items in the CustomActionContents property | 61 | - Additional items in the CustomActionContents property |
62 | --> | 62 | --> |
63 | <ItemGroup> | ||
64 | <CustomActionContents Include="@(CustomActionReferenceContents);@(Content->'%(FullPath)');$(CustomActionContents)" /> | ||
65 | |||
66 | <IntermediateCAResponseFile TaskParameter="Value" PropertyName="IntermediateCAResponseFile" /> | ||
67 | <IntermediateCAAssembly Include="@(IntermediateAssembly->'%(FullPath)')" /> | ||
68 | <IntermediateCAPackage Include="@(IntermediateAssembly->'%(RootDir)%(Directory)$(TargetCAFileName)')" /> | ||
69 | </ItemGroup> | ||
70 | |||
71 | <!-- Use a response file to pass the potentially very long contents to MakeSfxCA.exe --> | ||
63 | <PropertyGroup> | 72 | <PropertyGroup> |
64 | <CustomActionContents>@(CustomActionReferenceContents);@(Content->'%(FullPath)');$(CustomActionContents)</CustomActionContents> | 73 | <IntermediateCAResponseFile>@(IntermediateCAPackage->'%(RootDir)%(Directory)%(Filename).rsp')</IntermediateCAResponseFile> |
65 | </PropertyGroup> | 74 | </PropertyGroup> |
66 | 75 | ||
76 | <WriteLinesToFile File="$(IntermediateCAResponseFile)" Lines="@(CustomActionContents->'"%(Identity)"')" Overwrite="true" /> | ||
77 | |||
67 | <ItemGroup> | 78 | <ItemGroup> |
68 | <IntermediateCAAssembly Include="@(IntermediateAssembly->'%(FullPath)')" /> | 79 | <FileWrites Include="$(IntermediateCAResponseFile)" /> |
69 | <IntermediateCAPackage Include="@(IntermediateAssembly->'%(RootDir)%(Directory)$(TargetCAFileName)')" /> | ||
70 | </ItemGroup> | 80 | </ItemGroup> |
71 | 81 | ||
72 | <!-- Run the MakeSfxCA.exe CA packaging tool. --> | 82 | <!-- Run the MakeSfxCA.exe CA packaging tool. --> |
73 | <Exec Command='"$(MakeSfxCA)" "@(IntermediateCAPackage)" "$(SfxCADll)" "@(IntermediateCAAssembly)" "$(CustomActionContents)"' | 83 | <Exec Command='"$(MakeSfxCA)" "@(IntermediateCAPackage)" "$(SfxCADll)" "@(IntermediateCAAssembly)" "@$(IntermediateCAResponseFile)"' |
74 | WorkingDirectory="$(ProjectDir)" /> | 84 | WorkingDirectory="$(ProjectDir)" /> |
75 | 85 | ||
76 | <!-- Add modules to be copied to output dir. --> | 86 | <!-- Add modules to be copied to output dir. --> |
diff --git a/src/dtf/WixToolset.Dtf.MakeSfxCA/MakeSfxCA.cs b/src/dtf/WixToolset.Dtf.MakeSfxCA/MakeSfxCA.cs index d701da20..d9239f10 100644 --- a/src/dtf/WixToolset.Dtf.MakeSfxCA/MakeSfxCA.cs +++ b/src/dtf/WixToolset.Dtf.MakeSfxCA/MakeSfxCA.cs | |||
@@ -3,11 +3,12 @@ | |||
3 | namespace WixToolset.Dtf.MakeSfxCA | 3 | namespace WixToolset.Dtf.MakeSfxCA |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.IO; | ||
7 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
7 | using System.IO; | ||
8 | using System.Linq; | ||
9 | using System.Reflection; | ||
8 | using System.Security; | 10 | using System.Security; |
9 | using System.Text; | 11 | using System.Text; |
10 | using System.Reflection; | ||
11 | using WixToolset.Dtf.Compression; | 12 | using WixToolset.Dtf.Compression; |
12 | using WixToolset.Dtf.Compression.Cab; | 13 | using WixToolset.Dtf.Compression.Cab; |
13 | using WixToolset.Dtf.Resources; | 14 | using WixToolset.Dtf.Resources; |
@@ -28,12 +29,12 @@ namespace WixToolset.Dtf.MakeSfxCA | |||
28 | /// Prints usage text for the tool. | 29 | /// Prints usage text for the tool. |
29 | /// </summary> | 30 | /// </summary> |
30 | /// <param name="w">Console text writer.</param> | 31 | /// <param name="w">Console text writer.</param> |
31 | public static void Usage(TextWriter w) | 32 | private static void Usage(TextWriter w) |
32 | { | 33 | { |
33 | w.WriteLine("WiX Toolset custom action packager version {0}", Assembly.GetExecutingAssembly().GetName().Version); | 34 | w.WriteLine("WiX Toolset custom action packager version {0}", Assembly.GetExecutingAssembly().GetName().Version); |
34 | w.WriteLine("Copyright (C) .NET Foundation and contributors. All rights reserved."); | 35 | w.WriteLine("Copyright (C) .NET Foundation and contributors. All rights reserved."); |
35 | w.WriteLine(); | 36 | w.WriteLine(); |
36 | w.WriteLine("Usage: WixToolset.Dtf.MakeSfxCA <outputca.dll> SfxCA.dll <inputca.dll> [support files ...]"); | 37 | w.WriteLine("Usage: WixToolset.Dtf.MakeSfxCA [-v] <outputca.dll> SfxCA.dll <inputca.dll> [support files ...]"); |
37 | w.WriteLine(); | 38 | w.WriteLine(); |
38 | w.WriteLine("Makes a self-extracting managed MSI CA or UI DLL package."); | 39 | w.WriteLine("Makes a self-extracting managed MSI CA or UI DLL package."); |
39 | w.WriteLine("Support files must include " + MakeSfxCA.REQUIRED_WI_ASSEMBLY); | 40 | w.WriteLine("Support files must include " + MakeSfxCA.REQUIRED_WI_ASSEMBLY); |
@@ -47,20 +48,42 @@ namespace WixToolset.Dtf.MakeSfxCA | |||
47 | /// <returns>0 on success, nonzero on failure.</returns> | 48 | /// <returns>0 on success, nonzero on failure.</returns> |
48 | public static int Main(string[] args) | 49 | public static int Main(string[] args) |
49 | { | 50 | { |
50 | if (args.Length < 3) | 51 | var logger = TextWriter.Null; |
52 | var output = String.Empty; | ||
53 | var sfxDll = String.Empty; | ||
54 | var inputs = new List<string>(); | ||
55 | |||
56 | var expandedArgs = ExpandArguments(args); | ||
57 | |||
58 | foreach (var arg in expandedArgs) | ||
59 | { | ||
60 | if (arg == "-v") | ||
61 | { | ||
62 | logger = Console.Out; | ||
63 | } | ||
64 | else if (String.IsNullOrEmpty(output)) | ||
65 | { | ||
66 | output = arg; | ||
67 | } | ||
68 | else if (String.IsNullOrEmpty(sfxDll)) | ||
69 | { | ||
70 | sfxDll = arg; | ||
71 | } | ||
72 | else | ||
73 | { | ||
74 | inputs.Add(arg); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | if (inputs.Count == 0) | ||
51 | { | 79 | { |
52 | Usage(Console.Out); | 80 | Usage(Console.Out); |
53 | return 1; | 81 | return 1; |
54 | } | 82 | } |
55 | 83 | ||
56 | var output = args[0]; | ||
57 | var sfxDll = args[1]; | ||
58 | var inputs = new string[args.Length - 2]; | ||
59 | Array.Copy(args, 2, inputs, 0, inputs.Length); | ||
60 | |||
61 | try | 84 | try |
62 | { | 85 | { |
63 | Build(output, sfxDll, inputs, Console.Out); | 86 | Build(output, sfxDll, inputs, logger); |
64 | return 0; | 87 | return 0; |
65 | } | 88 | } |
66 | catch (ArgumentException ex) | 89 | catch (ArgumentException ex) |
@@ -81,11 +104,38 @@ namespace WixToolset.Dtf.MakeSfxCA | |||
81 | } | 104 | } |
82 | 105 | ||
83 | /// <summary> | 106 | /// <summary> |
107 | /// Read the arguments include parsing response files. | ||
108 | /// </summary> | ||
109 | /// <param name="args">Arguments to expand</param> | ||
110 | /// <returns>Expanded list of arguments</returns> | ||
111 | private static List<string> ExpandArguments(string[] args) | ||
112 | { | ||
113 | var result = new List<string>(args.Length); | ||
114 | foreach (var arg in args) | ||
115 | { | ||
116 | if (String.IsNullOrWhiteSpace(arg)) | ||
117 | { | ||
118 | } | ||
119 | else if (arg.StartsWith("@")) | ||
120 | { | ||
121 | var parsed = File.ReadAllLines(arg.Substring(1)); | ||
122 | result.AddRange(parsed.Select(p => p.Trim('"')).Where(p => !String.IsNullOrWhiteSpace(p))); | ||
123 | } | ||
124 | else | ||
125 | { | ||
126 | result.Add(arg); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | return result; | ||
131 | } | ||
132 | |||
133 | /// <summary> | ||
84 | /// Packages up all the inputs to the output location. | 134 | /// Packages up all the inputs to the output location. |
85 | /// </summary> | 135 | /// </summary> |
86 | /// <exception cref="Exception">Various exceptions are thrown | 136 | /// <exception cref="Exception">Various exceptions are thrown |
87 | /// if things go wrong.</exception> | 137 | /// if things go wrong.</exception> |
88 | public static void Build(string output, string sfxDll, IList<string> inputs, TextWriter log) | 138 | private static void Build(string output, string sfxDll, IList<string> inputs, TextWriter log) |
89 | { | 139 | { |
90 | MakeSfxCA.log = log; | 140 | MakeSfxCA.log = log; |
91 | 141 | ||
@@ -205,7 +255,7 @@ namespace WixToolset.Dtf.MakeSfxCA | |||
205 | /// </remarks> | 255 | /// </remarks> |
206 | private static void ResolveDependentAssemblies(IDictionary<string, string> inputFiles, string inputDir) | 256 | private static void ResolveDependentAssemblies(IDictionary<string, string> inputFiles, string inputDir) |
207 | { | 257 | { |
208 | AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += delegate(object sender, ResolveEventArgs args) | 258 | AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += delegate (object sender, ResolveEventArgs args) |
209 | { | 259 | { |
210 | AssemblyName resolveName = new AssemblyName(args.Name); | 260 | AssemblyName resolveName = new AssemblyName(args.Name); |
211 | Assembly assembly = null; | 261 | Assembly assembly = null; |
@@ -416,7 +466,7 @@ namespace WixToolset.Dtf.MakeSfxCA | |||
416 | foreach (var argument in attribute.ConstructorArguments) | 466 | foreach (var argument in attribute.ConstructorArguments) |
417 | { | 467 | { |
418 | // The entry point name is the first positional argument, if specified. | 468 | // The entry point name is the first positional argument, if specified. |
419 | entryPointName = (string) argument.Value; | 469 | entryPointName = (string)argument.Value; |
420 | break; | 470 | break; |
421 | } | 471 | } |
422 | 472 | ||
@@ -472,7 +522,7 @@ namespace WixToolset.Dtf.MakeSfxCA | |||
472 | byte[] fileBytes; | 522 | byte[] fileBytes; |
473 | using (var readStream = File.OpenRead(sfxDll)) | 523 | using (var readStream = File.OpenRead(sfxDll)) |
474 | { | 524 | { |
475 | fileBytes = new byte[(int) readStream.Length]; | 525 | fileBytes = new byte[(int)readStream.Length]; |
476 | readStream.Read(fileBytes, 0, fileBytes.Length); | 526 | readStream.Read(fileBytes, 0, fileBytes.Length); |
477 | } | 527 | } |
478 | 528 | ||