From 2853b2724e0d310f034e443fdd253a0a52f84b7f Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 29 Jun 2023 08:48:32 +0200 Subject: [PATCH 1/3] [bgen] Use a response file when compiling code. This way we don't run into limitations on the command-line length. --- src/bgen/BindingTouch.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/bgen/BindingTouch.cs b/src/bgen/BindingTouch.cs index 547b4890cb89..ac7ecf480fcf 100644 --- a/src/bgen/BindingTouch.cs +++ b/src/bgen/BindingTouch.cs @@ -582,7 +582,7 @@ int Main3 (string [] args) AddNFloatUsing (cargs, tmpdir); - Compile (cargs, 1000); + Compile (cargs, 1000, tmpdir); } finally { if (delete_temp) Directory.Delete (tmpdir, true); @@ -627,7 +627,7 @@ string GetCompiledApiBindingsAssembly (string tmpdir, IEnumerable refs, AddNFloatUsing (cargs, tmpdir); - Compile (cargs, 2); + Compile (cargs, 2, tmpdir); return tmpass; } @@ -643,8 +643,16 @@ void AddNFloatUsing (List cargs, string tmpdir) #endif } - void Compile (List arguments, int errorCode) + void Compile (List arguments, int errorCode, string tmpdir) { + var responseFile = Path.Combine (tmpdir, $"compile-{errorCode}.rsp"); + // The /noconfig argument is not allowed in a response file, so don't put it there. + var responseFileArguments = arguments.Where (arg => !string.Equals (arg, "/noconfig", StringComparison.OrdinalIgnoreCase) && !string.Equals (arg, "-noconfig", StringComparison.OrdinalIgnoreCase)); + File.WriteAllLines (responseFile, responseFileArguments); + // We create a new list here on purpose to not modify the input argument. + arguments = arguments.Where (arg => !responseFileArguments.Contains (arg)).ToList (); + arguments.Add ($"@{responseFile}"); + if (compile_command is null || compile_command.Length == 0) { #if !NET if (string.IsNullOrEmpty (compiler)) From b85bd727795d28023bae4aea2f4080e293cb059a Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 29 Jun 2023 17:29:36 +0200 Subject: [PATCH 2/3] Add debug spew. --- src/bgen/BindingTouch.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bgen/BindingTouch.cs b/src/bgen/BindingTouch.cs index ac7ecf480fcf..e81575a2d92a 100644 --- a/src/bgen/BindingTouch.cs +++ b/src/bgen/BindingTouch.cs @@ -667,8 +667,11 @@ void Compile (List arguments, int errorCode, string tmpdir) arguments.Insert (i - 1, compile_command [i]); } - if (Driver.RunCommand (compile_command [0], arguments, null, out var compile_output, true, Driver.Verbosity) != 0) + if (Driver.RunCommand (compile_command [0], arguments, null, out var compile_output, true, Driver.Verbosity) != 0) { + Console.WriteLine ("Response file:"); + Console.WriteLine (File.ReadAllText (responseFile)); throw ErrorHelper.CreateError (errorCode, $"{compiler} {StringUtils.FormatArguments (arguments)}\n{compile_output}".Replace ("\n", "\n\t")); + } var output = string.Join (Environment.NewLine, compile_output.ToString ().Split (new char [] { '\n' }, StringSplitOptions.RemoveEmptyEntries)); if (!string.IsNullOrEmpty (output)) Console.WriteLine (output); From 4f5d1f342b9330f31c7303996a87447e8086d363 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 30 Jun 2023 11:05:03 +0200 Subject: [PATCH 3/3] Quote arguments in the response file. --- src/bgen/BindingTouch.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/bgen/BindingTouch.cs b/src/bgen/BindingTouch.cs index e81575a2d92a..3172763d49d8 100644 --- a/src/bgen/BindingTouch.cs +++ b/src/bgen/BindingTouch.cs @@ -647,8 +647,10 @@ void Compile (List arguments, int errorCode, string tmpdir) { var responseFile = Path.Combine (tmpdir, $"compile-{errorCode}.rsp"); // The /noconfig argument is not allowed in a response file, so don't put it there. - var responseFileArguments = arguments.Where (arg => !string.Equals (arg, "/noconfig", StringComparison.OrdinalIgnoreCase) && !string.Equals (arg, "-noconfig", StringComparison.OrdinalIgnoreCase)); - File.WriteAllLines (responseFile, responseFileArguments); + var responseFileArguments = arguments + .Where (arg => !string.Equals (arg, "/noconfig", StringComparison.OrdinalIgnoreCase) && !string.Equals (arg, "-noconfig", StringComparison.OrdinalIgnoreCase)) + .ToArray (); // StringUtils.QuoteForProcess only accepts IList, not IEnumerable + File.WriteAllLines (responseFile, StringUtils.QuoteForProcess (responseFileArguments)); // We create a new list here on purpose to not modify the input argument. arguments = arguments.Where (arg => !responseFileArguments.Contains (arg)).ToList (); arguments.Add ($"@{responseFile}"); @@ -667,11 +669,8 @@ void Compile (List arguments, int errorCode, string tmpdir) arguments.Insert (i - 1, compile_command [i]); } - if (Driver.RunCommand (compile_command [0], arguments, null, out var compile_output, true, Driver.Verbosity) != 0) { - Console.WriteLine ("Response file:"); - Console.WriteLine (File.ReadAllText (responseFile)); + if (Driver.RunCommand (compile_command [0], arguments, null, out var compile_output, true, Driver.Verbosity) != 0) throw ErrorHelper.CreateError (errorCode, $"{compiler} {StringUtils.FormatArguments (arguments)}\n{compile_output}".Replace ("\n", "\n\t")); - } var output = string.Join (Environment.NewLine, compile_output.ToString ().Split (new char [] { '\n' }, StringSplitOptions.RemoveEmptyEntries)); if (!string.IsNullOrEmpty (output)) Console.WriteLine (output);