From bf2291f98161faeb248a3a48090f8cce9ecdae66 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 14:16:06 +0200 Subject: [PATCH 01/43] update --- src/Compiler/Driver/CompilerOptions.fs | 8 ++++---- src/Compiler/Driver/CompilerOptions.fsi | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 7bbecb8916b..ee77a58f3e1 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -1972,14 +1972,14 @@ let deprecatedFlagsFsc tcConfigB = // OptionBlock: Miscellaneous options //----------------------------------- -let DisplayBannerText tcConfigB = +let DisplayBannerText (tcConfigB: TcConfigBuilder) (print: Printf.TextWriterFormat unit> -> string -> unit) : unit = if tcConfigB.showBanner then - (printfn "%s" tcConfigB.productNameForBannerText - printfn "%s" (FSComp.SR.optsCopyright ())) + (print "%s" tcConfigB.productNameForBannerText + print "%s" (FSComp.SR.optsCopyright ())) /// FSC only help. (FSI has it's own help function). let displayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) = - DisplayBannerText tcConfigB + DisplayBannerText tcConfigB printfn PrintCompilerOptionBlocks blocks exit 0 diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 983a38f5182..6e8b16f8048 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -52,7 +52,7 @@ val FilterCompilerOptionBlock: (CompilerOption -> bool) -> CompilerOptionBlock - /// Parse and process a set of compiler options val ParseCompilerOptions: (string -> unit) * CompilerOptionBlock list * string list -> unit -val DisplayBannerText: TcConfigBuilder -> unit +val DisplayBannerText: TcConfigBuilder -> (Printf.TextWriterFormat unit> -> string -> unit) -> unit val GetCoreFscCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list From 538ddd8887224cf9c7a80a29d1d40ffd4af04513 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 14:20:49 +0200 Subject: [PATCH 02/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index ee77a58f3e1..1e9150aa284 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -1972,7 +1972,7 @@ let deprecatedFlagsFsc tcConfigB = // OptionBlock: Miscellaneous options //----------------------------------- -let DisplayBannerText (tcConfigB: TcConfigBuilder) (print: Printf.TextWriterFormat unit> -> string -> unit) : unit = +let DisplayBannerText tcConfigB (print: Printf.TextWriterFormat unit> -> string -> unit) = if tcConfigB.showBanner then (print "%s" tcConfigB.productNameForBannerText print "%s" (FSComp.SR.optsCopyright ())) From 56872bcf4cf2b786aaa5cbf1d09f5d01da8fd595 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 14:36:36 +0200 Subject: [PATCH 03/43] basic test --- src/Compiler/Driver/CompilerOptions.fsi | 4 +++ src/Compiler/Driver/fsc.fs | 2 +- src/Compiler/Interactive/fsi.fs | 2 +- .../ConsoleOnlyOptionsTests.fs | 32 +++++++++++++++++++ .../FSharp.Compiler.Service.Tests.fsproj | 1 + 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 6e8b16f8048..3bc09fab5d3 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -54,6 +54,10 @@ val ParseCompilerOptions: (string -> unit) * CompilerOptionBlock list * string l val DisplayBannerText: TcConfigBuilder -> (Printf.TextWriterFormat unit> -> string -> unit) -> unit +val displayHelpFsc: TcConfigBuilder -> CompilerOptionBlock list -> 'a + +val displayVersion: TcConfigBuilder -> 'a + val GetCoreFscCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list val GetCoreFsiCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list diff --git a/src/Compiler/Driver/fsc.fs b/src/Compiler/Driver/fsc.fs index 654c0a8bda2..861d46bbf9e 100644 --- a/src/Compiler/Driver/fsc.fs +++ b/src/Compiler/Driver/fsc.fs @@ -544,7 +544,7 @@ let main1 // Display the banner text, if necessary if not bannerAlreadyPrinted then - DisplayBannerText tcConfigB + DisplayBannerText tcConfigB printfn // Create tcGlobals and frameworkTcImports let outfile, pdbfile, assemblyName = diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 32a8ad40592..9f888db322f 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -882,7 +882,7 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig, // In the "--help", these options can be printed either before (fsiUsagePrefix) or after (fsiUsageSuffix) the core options. let displayHelpFsi tcConfigB (blocks:CompilerOptionBlock list) = - DisplayBannerText tcConfigB; + DisplayBannerText tcConfigB printfn; fprintfn fsiConsoleOutput.Out "" fprintfn fsiConsoleOutput.Out "%s" (FSIstrings.SR.fsiUsage(executableFileNameWithoutExtension.Value)) PrintCompilerOptionBlocks blocks diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs new file mode 100644 index 00000000000..440c52ae3cf --- /dev/null +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +module FSharp.Compiler.Service.Tests.ConsoleOnlyOptionsTests + +open FSharp.Compiler.Text +open NUnit.Framework +open System.IO +open FSharp.Compiler.CompilerConfig +open FSharp.Compiler.CompilerOptions +open Internal.Utilities +open FSharp.Compiler.AbstractIL.ILBinaryReader + +[] +let ``Blah1`` () = + // just a random thing to make things work + let builder = TcConfigBuilder.CreateNew( + null, + FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value, + ReduceMemoryFlag.Yes, + Directory.GetCurrentDirectory(), + false, + false, + CopyFSharpCoreFlag.No, + (fun _ -> None), + None, + Range.Zero) + + let blocks = GetCoreServiceCompilerOptions builder + + let result = displayHelpFsc builder blocks + () + diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj index 491a5e9afa0..e4d94dfe891 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj @@ -38,6 +38,7 @@ Symbols.fs + SyntaxTree\TypeTests.fs From ffc5fd240cb133502999c019ea4721664ad8587d Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 14:39:56 +0200 Subject: [PATCH 04/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 12 ++++++------ src/Compiler/Driver/CompilerOptions.fsi | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 1e9150aa284..90f666edd02 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -1978,8 +1978,8 @@ let DisplayBannerText tcConfigB (print: Printf.TextWriterFormat unit> print "%s" (FSComp.SR.optsCopyright ())) /// FSC only help. (FSI has it's own help function). -let displayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) = - DisplayBannerText tcConfigB printfn +let displayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) print = + DisplayBannerText tcConfigB print PrintCompilerOptionBlocks blocks exit 0 @@ -1996,7 +1996,7 @@ let miscFlagsBoth tcConfigB = let miscFlagsFsc tcConfigB = miscFlagsBoth tcConfigB @ [ - CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), None, Some(FSComp.SR.optsHelp ())) + CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn), None, Some(FSComp.SR.optsHelp ())) CompilerOption("@", tagNone, OptionUnit ignore, None, Some(FSComp.SR.optsResponseFile ())) ] @@ -2052,7 +2052,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "?", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2060,7 +2060,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2068,7 +2068,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "full-help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 3bc09fab5d3..d67f113e6c6 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -54,7 +54,7 @@ val ParseCompilerOptions: (string -> unit) * CompilerOptionBlock list * string l val DisplayBannerText: TcConfigBuilder -> (Printf.TextWriterFormat unit> -> string -> unit) -> unit -val displayHelpFsc: TcConfigBuilder -> CompilerOptionBlock list -> 'a +val displayHelpFsc: TcConfigBuilder -> CompilerOptionBlock list -> (Printf.TextWriterFormat unit> -> string -> unit) -> 'a val displayVersion: TcConfigBuilder -> 'a From 744b5e7adb9774a2a0bbd8237be739a8b4cad977 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 14:46:11 +0200 Subject: [PATCH 05/43] Update --- src/Compiler/Driver/CompilerOptions.fsi | 13 ++++++++++--- .../ConsoleOnlyOptionsTests.fs | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index d67f113e6c6..8ee306f7d7b 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -52,9 +52,16 @@ val FilterCompilerOptionBlock: (CompilerOption -> bool) -> CompilerOptionBlock - /// Parse and process a set of compiler options val ParseCompilerOptions: (string -> unit) * CompilerOptionBlock list * string list -> unit -val DisplayBannerText: TcConfigBuilder -> (Printf.TextWriterFormat unit> -> string -> unit) -> unit - -val displayHelpFsc: TcConfigBuilder -> CompilerOptionBlock list -> (Printf.TextWriterFormat unit> -> string -> unit) -> 'a +val DisplayBannerText: + tcConfigB: TcConfigBuilder + -> print: (Printf.TextWriterFormat unit> -> string -> unit) + -> unit + +val displayHelpFsc: + tcConfigB: TcConfigBuilder + -> blocks: CompilerOptionBlock list + -> print: (Printf.TextWriterFormat unit> -> string -> unit) + -> 'a val displayVersion: TcConfigBuilder -> 'a diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 440c52ae3cf..ef7e0f30d4a 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -27,6 +27,6 @@ let ``Blah1`` () = let blocks = GetCoreServiceCompilerOptions builder - let result = displayHelpFsc builder blocks + let result = displayHelpFsc builder blocks printfn () From d2cf45af934e10f7394bbd19f950f8221f3a1da1 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 15:03:47 +0200 Subject: [PATCH 06/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 12 ++++++------ src/Compiler/Driver/CompilerOptions.fsi | 1 + .../ConsoleOnlyOptionsTests.fs | 6 +++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 90f666edd02..e63f5857954 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -1978,10 +1978,10 @@ let DisplayBannerText tcConfigB (print: Printf.TextWriterFormat unit> print "%s" (FSComp.SR.optsCopyright ())) /// FSC only help. (FSI has it's own help function). -let displayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) print = +let displayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) print exit = DisplayBannerText tcConfigB print PrintCompilerOptionBlocks blocks - exit 0 + exit() let displayVersion tcConfigB = printfn "%s" tcConfigB.productNameForBannerText @@ -1996,7 +1996,7 @@ let miscFlagsBoth tcConfigB = let miscFlagsFsc tcConfigB = miscFlagsBoth tcConfigB @ [ - CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn), None, Some(FSComp.SR.optsHelp ())) + CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn (exit 0)), None, Some(FSComp.SR.optsHelp ())) CompilerOption("@", tagNone, OptionUnit ignore, None, Some(FSComp.SR.optsResponseFile ())) ] @@ -2052,7 +2052,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "?", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn (exit 0)), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2060,7 +2060,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn (exit 0)), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2068,7 +2068,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "full-help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn (exit 0)), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 8ee306f7d7b..2627453a734 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -61,6 +61,7 @@ val displayHelpFsc: tcConfigB: TcConfigBuilder -> blocks: CompilerOptionBlock list -> print: (Printf.TextWriterFormat unit> -> string -> unit) + -> exit: (unit -> 'a) -> 'a val displayVersion: TcConfigBuilder -> 'a diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index ef7e0f30d4a..25b5c568181 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -27,6 +27,10 @@ let ``Blah1`` () = let blocks = GetCoreServiceCompilerOptions builder - let result = displayHelpFsc builder blocks printfn + use sw = new StreamWriter(@"C:\code\text.txt") + let print = fprintfn sw + let exit() = () + let result = displayHelpFsc builder blocks print exit + sw.Close() () From 6191fe5b1b1b3d98c8ac0ac8f10fcf7cdcf0c73c Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 15:16:10 +0200 Subject: [PATCH 07/43] Update ConsoleOnlyOptionsTests.fs --- .../ConsoleOnlyOptionsTests.fs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 25b5c568181..107baf33706 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -25,12 +25,14 @@ let ``Blah1`` () = None, Range.Zero) - let blocks = GetCoreServiceCompilerOptions builder + let blocks = GetCoreFscCompilerOptions builder - use sw = new StreamWriter(@"C:\code\text.txt") - let print = fprintfn sw + use writer = new StreamWriter @"C:\code\text.txt" + let print = fprintfn writer let exit() = () - let result = displayHelpFsc builder blocks print exit - sw.Close() + + displayHelpFsc builder blocks print exit + + writer.Close() () From 47b734bbaabc33191556cde8c1524eac400302f1 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 16:20:54 +0200 Subject: [PATCH 08/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 24 +++++++++---------- src/Compiler/Driver/CompilerOptions.fsi | 4 ++-- src/Compiler/Driver/fsc.fs | 2 +- src/Compiler/Interactive/fsi.fs | 2 +- .../ConsoleOnlyOptionsTests.fs | 4 +--- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index e63f5857954..d103543c5f3 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -152,11 +152,11 @@ let PrintCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOp let _finalColumn = Array.fold printWord flagWidth words printfn "" (* newline *) -let PrintPublicOptions (heading, opts) = +let PrintPublicOptions (heading, opts) print = if not (isNil opts) then - printfn "" - printfn "" - printfn "\t\t%s" heading + print "" + print "" + print $"\t\t{heading}" List.iter PrintCompilerOption opts let PrintCompilerOptionBlocks blocks = @@ -173,7 +173,7 @@ let PrintCompilerOptionBlocks blocks = let headingOptions = publicBlocks |> List.filter (fun (h2, _) -> heading = h2) |> List.collect snd - PrintPublicOptions(heading, headingOptions) + PrintPublicOptions(heading, headingOptions) Console.WriteLine Set.add heading doneHeadings List.fold consider Set.empty publicBlocks |> ignore> @@ -1972,10 +1972,10 @@ let deprecatedFlagsFsc tcConfigB = // OptionBlock: Miscellaneous options //----------------------------------- -let DisplayBannerText tcConfigB (print: Printf.TextWriterFormat unit> -> string -> unit) = +let DisplayBannerText tcConfigB (print: string -> unit) = if tcConfigB.showBanner then - (print "%s" tcConfigB.productNameForBannerText - print "%s" (FSComp.SR.optsCopyright ())) + (print tcConfigB.productNameForBannerText + print (FSComp.SR.optsCopyright ())) /// FSC only help. (FSI has it's own help function). let displayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) print exit = @@ -1996,7 +1996,7 @@ let miscFlagsBoth tcConfigB = let miscFlagsFsc tcConfigB = miscFlagsBoth tcConfigB @ [ - CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn (exit 0)), None, Some(FSComp.SR.optsHelp ())) + CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.WriteLine (exit 0)), None, Some(FSComp.SR.optsHelp ())) CompilerOption("@", tagNone, OptionUnit ignore, None, Some(FSComp.SR.optsResponseFile ())) ] @@ -2052,7 +2052,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "?", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn (exit 0)), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.WriteLine (exit 0)), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2060,7 +2060,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn (exit 0)), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.WriteLine (exit 0)), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2068,7 +2068,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "full-help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks printfn (exit 0)), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.WriteLine (exit 0)), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 2627453a734..530fb7b526f 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -54,13 +54,13 @@ val ParseCompilerOptions: (string -> unit) * CompilerOptionBlock list * string l val DisplayBannerText: tcConfigB: TcConfigBuilder - -> print: (Printf.TextWriterFormat unit> -> string -> unit) + -> print: (string -> unit) -> unit val displayHelpFsc: tcConfigB: TcConfigBuilder -> blocks: CompilerOptionBlock list - -> print: (Printf.TextWriterFormat unit> -> string -> unit) + -> print: (string -> unit) -> exit: (unit -> 'a) -> 'a diff --git a/src/Compiler/Driver/fsc.fs b/src/Compiler/Driver/fsc.fs index 861d46bbf9e..08d64396520 100644 --- a/src/Compiler/Driver/fsc.fs +++ b/src/Compiler/Driver/fsc.fs @@ -544,7 +544,7 @@ let main1 // Display the banner text, if necessary if not bannerAlreadyPrinted then - DisplayBannerText tcConfigB printfn + DisplayBannerText tcConfigB Console.WriteLine // Create tcGlobals and frameworkTcImports let outfile, pdbfile, assemblyName = diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 9f888db322f..3aed450dff5 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -882,7 +882,7 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig, // In the "--help", these options can be printed either before (fsiUsagePrefix) or after (fsiUsageSuffix) the core options. let displayHelpFsi tcConfigB (blocks:CompilerOptionBlock list) = - DisplayBannerText tcConfigB printfn; + DisplayBannerText tcConfigB Console.WriteLine; fprintfn fsiConsoleOutput.Out "" fprintfn fsiConsoleOutput.Out "%s" (FSIstrings.SR.fsiUsage(executableFileNameWithoutExtension.Value)) PrintCompilerOptionBlocks blocks diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 107baf33706..7dd3e8ba5de 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -27,12 +27,10 @@ let ``Blah1`` () = let blocks = GetCoreFscCompilerOptions builder - use writer = new StreamWriter @"C:\code\text.txt" - let print = fprintfn writer + let print line = File.AppendAllLines(@"C:\code\text.txt", [line]) let exit() = () displayHelpFsc builder blocks print exit - writer.Close() () From 30515605db8e6f852ee98e67cf389f41454b669b Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 16:26:49 +0200 Subject: [PATCH 09/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 6 +++--- src/Compiler/Driver/CompilerOptions.fsi | 5 ++++- src/Compiler/Interactive/fsi.fs | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index d103543c5f3..2416f71afe8 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -159,7 +159,7 @@ let PrintPublicOptions (heading, opts) print = print $"\t\t{heading}" List.iter PrintCompilerOption opts -let PrintCompilerOptionBlocks blocks = +let PrintCompilerOptionBlocks blocks print = let publicBlocks = blocks |> List.choose (function @@ -173,7 +173,7 @@ let PrintCompilerOptionBlocks blocks = let headingOptions = publicBlocks |> List.filter (fun (h2, _) -> heading = h2) |> List.collect snd - PrintPublicOptions(heading, headingOptions) Console.WriteLine + PrintPublicOptions(heading, headingOptions) print Set.add heading doneHeadings List.fold consider Set.empty publicBlocks |> ignore> @@ -1980,7 +1980,7 @@ let DisplayBannerText tcConfigB (print: string -> unit) = /// FSC only help. (FSI has it's own help function). let displayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) print exit = DisplayBannerText tcConfigB print - PrintCompilerOptionBlocks blocks + PrintCompilerOptionBlocks blocks print exit() let displayVersion tcConfigB = diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 530fb7b526f..141c04c7736 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -43,7 +43,10 @@ and CompilerOptionBlock = | PublicOptions of heading: string * options: CompilerOption list | PrivateOptions of options: CompilerOption list -val PrintCompilerOptionBlocks: CompilerOptionBlock list -> unit // for printing usage +val PrintCompilerOptionBlocks: + CompilerOptionBlock list + -> print: (string -> unit) + -> unit // for printing usage val DumpCompilerOptionBlocks: CompilerOptionBlock list -> unit // for QA diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 3aed450dff5..1325a184822 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -885,7 +885,7 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig, DisplayBannerText tcConfigB Console.WriteLine; fprintfn fsiConsoleOutput.Out "" fprintfn fsiConsoleOutput.Out "%s" (FSIstrings.SR.fsiUsage(executableFileNameWithoutExtension.Value)) - PrintCompilerOptionBlocks blocks + PrintCompilerOptionBlocks blocks Console.WriteLine exit 0 // option tags From 210c42443a0c00a6228b9389c6fb78c67323b530 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 16:57:27 +0200 Subject: [PATCH 10/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 20 +++++++++---------- src/Compiler/Driver/fsc.fs | 2 +- src/Compiler/Interactive/fsi.fs | 4 ++-- .../ConsoleOnlyOptionsTests.fs | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 2416f71afe8..14d22186993 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -154,9 +154,9 @@ let PrintCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOp let PrintPublicOptions (heading, opts) print = if not (isNil opts) then - print "" - print "" - print $"\t\t{heading}" + print "\n" + print "\n" + print $"\n\t\t{heading}" List.iter PrintCompilerOption opts let PrintCompilerOptionBlocks blocks print = @@ -1972,10 +1972,10 @@ let deprecatedFlagsFsc tcConfigB = // OptionBlock: Miscellaneous options //----------------------------------- -let DisplayBannerText tcConfigB (print: string -> unit) = +let DisplayBannerText tcConfigB print = if tcConfigB.showBanner then - (print tcConfigB.productNameForBannerText - print (FSComp.SR.optsCopyright ())) + (print $"\n{tcConfigB.productNameForBannerText}" + print $"\n{FSComp.SR.optsCopyright ()}") /// FSC only help. (FSI has it's own help function). let displayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) print exit = @@ -1996,7 +1996,7 @@ let miscFlagsBoth tcConfigB = let miscFlagsFsc tcConfigB = miscFlagsBoth tcConfigB @ [ - CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.WriteLine (exit 0)), None, Some(FSComp.SR.optsHelp ())) + CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.Write (exit 0)), None, Some(FSComp.SR.optsHelp ())) CompilerOption("@", tagNone, OptionUnit ignore, None, Some(FSComp.SR.optsResponseFile ())) ] @@ -2052,7 +2052,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "?", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.WriteLine (exit 0)), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.Write (exit 0)), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2060,7 +2060,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.WriteLine (exit 0)), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.Write (exit 0)), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2068,7 +2068,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "full-help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.WriteLine (exit 0)), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.Write (exit 0)), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) diff --git a/src/Compiler/Driver/fsc.fs b/src/Compiler/Driver/fsc.fs index 08d64396520..d2880ba146c 100644 --- a/src/Compiler/Driver/fsc.fs +++ b/src/Compiler/Driver/fsc.fs @@ -544,7 +544,7 @@ let main1 // Display the banner text, if necessary if not bannerAlreadyPrinted then - DisplayBannerText tcConfigB Console.WriteLine + DisplayBannerText tcConfigB Console.Write // Create tcGlobals and frameworkTcImports let outfile, pdbfile, assemblyName = diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 1325a184822..bfdf9f7b1ec 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -882,10 +882,10 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig, // In the "--help", these options can be printed either before (fsiUsagePrefix) or after (fsiUsageSuffix) the core options. let displayHelpFsi tcConfigB (blocks:CompilerOptionBlock list) = - DisplayBannerText tcConfigB Console.WriteLine; + DisplayBannerText tcConfigB Console.Write; fprintfn fsiConsoleOutput.Out "" fprintfn fsiConsoleOutput.Out "%s" (FSIstrings.SR.fsiUsage(executableFileNameWithoutExtension.Value)) - PrintCompilerOptionBlocks blocks Console.WriteLine + PrintCompilerOptionBlocks blocks Console.Write exit 0 // option tags diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 7dd3e8ba5de..c97b481fbaf 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -27,7 +27,7 @@ let ``Blah1`` () = let blocks = GetCoreFscCompilerOptions builder - let print line = File.AppendAllLines(@"C:\code\text.txt", [line]) + let print text = File.AppendAllText(@"C:\code\text.txt", text) let exit() = () displayHelpFsc builder blocks print exit From 681a4b4d2147213126b8bde59f38f4fea0886fb9 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 17:05:44 +0200 Subject: [PATCH 11/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 14d22186993..d5a48dd04d8 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -156,7 +156,7 @@ let PrintPublicOptions (heading, opts) print = if not (isNil opts) then print "\n" print "\n" - print $"\n\t\t{heading}" + print $"\t\t{heading}\n" List.iter PrintCompilerOption opts let PrintCompilerOptionBlocks blocks print = @@ -1974,8 +1974,8 @@ let deprecatedFlagsFsc tcConfigB = let DisplayBannerText tcConfigB print = if tcConfigB.showBanner then - (print $"\n{tcConfigB.productNameForBannerText}" - print $"\n{FSComp.SR.optsCopyright ()}") + (print $"{tcConfigB.productNameForBannerText}\n" + print $"{FSComp.SR.optsCopyright ()}\n") /// FSC only help. (FSI has it's own help function). let displayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) print exit = From 0d28dd8a8c0b98462f2265173227bf4639ee4eec Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 17:41:12 +0200 Subject: [PATCH 12/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index d5a48dd04d8..ab6332dcd82 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -90,7 +90,6 @@ let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) = "" else s (* s="flag" for "--flag" options. s="--" for "--" option. Adjust printing here for "--" case. *) - match spec with | OptionUnit _ | OptionSet _ @@ -111,7 +110,8 @@ let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) = else sprintf "%s:%s" s tag (* still being decided *) -let PrintCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOption) = + +let PrintCompilerOption print (CompilerOption (_s, _tag, _spec, _, help) as compilerOption) = let flagWidth = 42 // fixed width for printing of flags, e.g. --debug:{full|pdbonly|portable|embedded} let defaultLineWidth = 80 // the fallback width @@ -130,18 +130,18 @@ let PrintCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOp // flagWidth chars - for flags description or padding on continuation lines. // single space - space. // description - words upto but excluding the final character of the line. - printf "%-40s" (compilerOptionUsage compilerOption) + print $"{compilerOptionUsage compilerOption, 40}" let printWord column (word: string) = // Have printed upto column. // Now print the next word including any preceding whitespace. // Returns the column printed to (suited to folding). if column + 1 (*space*) + word.Length >= lineWidth then // NOTE: "equality" ensures final character of the line is never printed - printfn "" (* newline *) - printf "%-40s %s" "" (*<--flags*) word + print "\n" + print $"{word, -40}" flagWidth + 1 + word.Length else - printf " %s" word + print $" {word}" column + 1 + word.Length let words = @@ -150,14 +150,14 @@ let PrintCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOp | Some s -> s.Split [| ' ' |] let _finalColumn = Array.fold printWord flagWidth words - printfn "" (* newline *) + print "\n" let PrintPublicOptions (heading, opts) print = if not (isNil opts) then print "\n" print "\n" print $"\t\t{heading}\n" - List.iter PrintCompilerOption opts + List.iter (PrintCompilerOption print) opts let PrintCompilerOptionBlocks blocks print = let publicBlocks = From c50a87fbc035a7c383c9aa5c0298eec1dc4591c6 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 18:05:40 +0200 Subject: [PATCH 13/43] works --- src/Compiler/Driver/CompilerOptions.fs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index ab6332dcd82..729bd4e6e8f 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -90,6 +90,7 @@ let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) = "" else s (* s="flag" for "--flag" options. s="--" for "--" option. Adjust printing here for "--" case. *) + match spec with | OptionUnit _ | OptionSet _ @@ -130,7 +131,7 @@ let PrintCompilerOption print (CompilerOption (_s, _tag, _spec, _, help) as comp // flagWidth chars - for flags description or padding on continuation lines. // single space - space. // description - words upto but excluding the final character of the line. - print $"{compilerOptionUsage compilerOption, 40}" + print $"{compilerOptionUsage compilerOption, -40}" let printWord column (word: string) = // Have printed upto column. @@ -138,7 +139,7 @@ let PrintCompilerOption print (CompilerOption (_s, _tag, _spec, _, help) as comp // Returns the column printed to (suited to folding). if column + 1 (*space*) + word.Length >= lineWidth then // NOTE: "equality" ensures final character of the line is never printed print "\n" - print $"{word, -40}" + print $"{String.Empty, -40} {word}" flagWidth + 1 + word.Length else print $" {word}" From 6bec617be7f9c2b0aa993edad97d586c0a5ebd79 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 18:35:37 +0200 Subject: [PATCH 14/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 8 +++---- src/Compiler/Driver/CompilerOptions.fsi | 6 ++++- .../ConsoleOnlyOptionsTests.fs | 23 ++++++++++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 729bd4e6e8f..d13fa3a1392 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -1984,14 +1984,14 @@ let displayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) print exit = PrintCompilerOptionBlocks blocks print exit() -let displayVersion tcConfigB = - printfn "%s" tcConfigB.productNameForBannerText - exit 0 +let displayVersion tcConfigB print exit = + print $"{tcConfigB.productNameForBannerText}\n" + exit() let miscFlagsBoth tcConfigB = [ CompilerOption("nologo", tagNone, OptionUnit(fun () -> tcConfigB.showBanner <- false), None, Some(FSComp.SR.optsNologo ())) - CompilerOption("version", tagNone, OptionConsoleOnly(fun _ -> displayVersion tcConfigB), None, Some(FSComp.SR.optsVersion ())) + CompilerOption("version", tagNone, OptionConsoleOnly(fun _ -> displayVersion tcConfigB Console.Write (exit 0)), None, Some(FSComp.SR.optsVersion ())) ] let miscFlagsFsc tcConfigB = diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 141c04c7736..18ac3ff73b8 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -67,7 +67,11 @@ val displayHelpFsc: -> exit: (unit -> 'a) -> 'a -val displayVersion: TcConfigBuilder -> 'a +val displayVersion: + tcConfigB: TcConfigBuilder + -> print: (string -> unit) + -> exit: (unit -> 'a) + -> 'a val GetCoreFscCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index c97b481fbaf..effdb3a1aad 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -9,11 +9,11 @@ open FSharp.Compiler.CompilerConfig open FSharp.Compiler.CompilerOptions open Internal.Utilities open FSharp.Compiler.AbstractIL.ILBinaryReader +open System -[] -let ``Blah1`` () = +let private getBuilder() = // just a random thing to make things work - let builder = TcConfigBuilder.CreateNew( + TcConfigBuilder.CreateNew( null, FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value, ReduceMemoryFlag.Yes, @@ -25,6 +25,9 @@ let ``Blah1`` () = None, Range.Zero) +[] +let ``Blah1`` () = + let builder = getBuilder() let blocks = GetCoreFscCompilerOptions builder let print text = File.AppendAllText(@"C:\code\text.txt", text) @@ -34,3 +37,17 @@ let ``Blah1`` () = () +[] +let ``Blah2`` () = + let builder = getBuilder() + + let fileName = $"{Guid.NewGuid()}" + let print text = File.AppendAllText(fileName, text) + let exit() = () + + displayVersion builder print exit + + let output = File.ReadAllText fileName + + () + From 48188af17e31ba21e4bc9b25c97e5ad977f3d3c3 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 18:47:58 +0200 Subject: [PATCH 15/43] Update --- .../ConsoleOnlyOptionsTests.fs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index effdb3a1aad..08c99f246d0 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -26,7 +26,7 @@ let private getBuilder() = Range.Zero) [] -let ``Blah1`` () = +let ``Help is displayed correctly`` () = let builder = getBuilder() let blocks = GetCoreFscCompilerOptions builder @@ -38,7 +38,7 @@ let ``Blah1`` () = () [] -let ``Blah2`` () = +let ``Version is displayed correctly`` () = let builder = getBuilder() let fileName = $"{Guid.NewGuid()}" @@ -49,5 +49,8 @@ let ``Blah2`` () = let output = File.ReadAllText fileName - () + Assert.That( + output, + Does.Match(@"Microsoft \(R\) F# Compiler version \d+\.\d+\.\d+\.\d+ for F# \d+\.\d+")) + () From 292e59b9d788e63590e449e8ebdd16aae34c00f3 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 19:18:08 +0200 Subject: [PATCH 16/43] Update --- .../ConsoleOnlyOptionsTests.fs | 21 +-- .../FSharp.Compiler.Service.Tests.fsproj | 5 + .../expected-help-output.txt | 172 ++++++++++++++++++ 3 files changed, 187 insertions(+), 11 deletions(-) create mode 100644 tests/FSharp.Compiler.Service.Tests/expected-help-output.txt diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 08c99f246d0..92e83463568 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -29,28 +29,27 @@ let private getBuilder() = let ``Help is displayed correctly`` () = let builder = getBuilder() let blocks = GetCoreFscCompilerOptions builder + let fileName = $"{Guid.NewGuid()}" + let expectedHelp = File.ReadAllText $"{__SOURCE_DIRECTORY__}/expected-help-output.txt" - let print text = File.AppendAllText(@"C:\code\text.txt", text) + let print text = File.AppendAllText(fileName, text) let exit() = () - displayHelpFsc builder blocks print exit + let help = File.ReadAllText fileName + Assert.AreEqual(expectedHelp, help) + () [] let ``Version is displayed correctly`` () = let builder = getBuilder() - let fileName = $"{Guid.NewGuid()}" + let expectedVersionPattern = @"Microsoft \(R\) F# Compiler version \d+\.\d+\.\d+\.\d+ for F# \d+\.\d+" + let print text = File.AppendAllText(fileName, text) let exit() = () - displayVersion builder print exit - let output = File.ReadAllText fileName - - Assert.That( - output, - Does.Match(@"Microsoft \(R\) F# Compiler version \d+\.\d+\.\d+\.\d+ for F# \d+\.\d+")) - - () + let version = File.ReadAllText fileName + Assert.That(version, Does.Match expectedVersionPattern) diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj index e4d94dfe891..5daea43b6c6 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj @@ -20,6 +20,9 @@ + + Never + @@ -168,6 +171,8 @@ + + diff --git a/tests/FSharp.Compiler.Service.Tests/expected-help-output.txt b/tests/FSharp.Compiler.Service.Tests/expected-help-output.txt new file mode 100644 index 00000000000..f2873df8725 --- /dev/null +++ b/tests/FSharp.Compiler.Service.Tests/expected-help-output.txt @@ -0,0 +1,172 @@ +Microsoft (R) F# Compiler version 12.0.4.0 for F# 6.0 +Copyright (c) Microsoft Corporation. All Rights Reserved. + + + - OUTPUT FILES - +--out: Name of the output file (Short form: + -o) +--target:exe Build a console executable +--target:winexe Build a Windows executable +--target:library Build a library (Short form: -a) +--target:module Build a module that can be added to + another assembly +--delaysign[+|-] Delay-sign the assembly using only + the public portion of the strong + name key +--publicsign[+|-] Public-sign the assembly using only + the public portion of the strong + name key, and mark the assembly as + signed +--doc: Write the xmldoc of the assembly to + the given file +--keyfile: Specify a strong name key file +--platform: Limit which platforms this code can + run on: x86, x64, Arm, Arm64, + Itanium, anycpu32bitpreferred, or + anycpu. The default is anycpu. +--nooptimizationdata Only include optimization + information essential for + implementing inlined constructs. + Inhibits cross-module inlining but + improves binary compatibility. +--nointerfacedata Don't add a resource to the + generated assembly containing + F#-specific metadata +--sig: Print the inferred interface of the + assembly to a file +--allsigs Print the inferred interfaces of all + compilation files to associated + signature files +--nocopyfsharpcore Don't copy FSharp.Core.dll along the + produced binaries +--refonly[+|-] Produce a reference assembly, + instead of a full assembly, as the + primary output +--refout: Produce a reference assembly with + the specified file path. + + + - INPUT FILES - +--reference: Reference an assembly (Short form: + -r) +--compilertool: Reference an assembly or directory + containing a design time tool (Short + form: -t) + + + - RESOURCES - +--win32icon: Specify a Win32 icon file (.ico) +--win32res: Specify a Win32 resource file (.res) +--win32manifest: Specify a Win32 manifest file +--nowin32manifest Do not include the default Win32 + manifest +--resource: Embed the specified managed resource +--linkresource: Link the specified resource to this + assembly where the resinfo format is + [,[,public|private]] + + + - CODE GENERATION - +--debug[+|-] Emit debug information (Short form: + -g) +--debug:{full|pdbonly|portable|embedded} Specify debugging type: full, + portable, embedded, pdbonly. ('full' + is the default if no debuggging type + specified and enables attaching a + debugger to a running program, + 'portable' is a cross-platform + format, 'embedded' is a + cross-platform format embedded into + the output file). +--embed[+|-] Embed all source files in the + portable PDB file +--embed: Embed specific source files in the + portable PDB file +--sourcelink: Source link information file to + embed in the portable PDB file +--optimize[+|-] Enable optimizations (Short form: + -O) +--tailcalls[+|-] Enable or disable tailcalls +--deterministic[+|-] Produce a deterministic assembly + (including module version GUID and + timestamp) +--pathmap: Maps physical paths to source path + names output by the compiler +--crossoptimize[+|-] Enable or disable cross-module + optimizations +--reflectionfree Disable implicit generation of + constructs using reflection + + + - ERRORS AND WARNINGS - +--warnaserror[+|-] Report all warnings as errors +--warnaserror[+|-]: Report specific warnings as errors +--warn: Set a warning level (0-5) +--nowarn: Disable specific warning messages +--warnon: Enable specific warnings that may be + off by default +--consolecolors[+|-] Output warning and error messages in + color + + + - LANGUAGE - +--langversion:{?|version|latest|preview} Display the allowed values for + language version, specify language + version such as 'latest' or + 'preview' +--checked[+|-] Generate overflow checks +--define: Define conditional compilation + symbols (Short form: -d) +--mlcompatibility Ignore ML compatibility warnings + + + - MISCELLANEOUS - +--nologo Suppress compiler copyright message +--version Display compiler version banner and + exit +--help Display this usage message (Short + form: -?) +--@ Read response file for more options + + + - ADVANCED - +--codepage: Specify the codepage used to read + source files +--utf8output Output messages in UTF-8 encoding +--preferreduilang: Specify the preferred output + language culture name (e.g. es-ES, + ja-JP) +--fullpaths Output messages with fully qualified + paths +--lib: Specify a directory for the include + path which is used to resolve source + files and assemblies (Short form: + -I) +--simpleresolution Resolve assembly references using + directory-based rules rather than + MSBuild resolution +--targetprofile: Specify target framework profile of + this assembly. Valid values are + mscorlib, netcore or netstandard. + Default - mscorlib +--baseaddress:
Base address for the library to be + built +--checksumalgorithm:{SHA1|SHA256} Specify algorithm for calculating + source file checksum stored in PDB. + Supported values are: SHA1 or SHA256 + (default) +--noframework Do not reference the default CLI + assemblies by default +--standalone Statically link the F# library and + all referenced DLLs that depend on + it into the assembly being generated +--staticlink: Statically link the given assembly + and all referenced DLLs that depend + on this assembly. Use an assembly + name e.g. mylib, not a DLL name. +--pdb: Name the output debug file +--highentropyva[+|-] Enable high-entropy ASLR +--subsystemversion: Specify subsystem version of this + assembly +--quotations-debug[+|-] Emit debug information in quotations From f5c062005cbf05b45a00cf49ec925d941c87fc70 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 19:23:14 +0200 Subject: [PATCH 17/43] Update --- .../ConsoleOnlyOptionsTests.fs | 17 +++++++++-------- .../expected-help-output.txt | 3 +-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 92e83463568..10cc08b92a2 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -2,17 +2,17 @@ module FSharp.Compiler.Service.Tests.ConsoleOnlyOptionsTests -open FSharp.Compiler.Text -open NUnit.Framework +open System open System.IO +open FSharp.Compiler.Text +open FSharp.Compiler.AbstractIL.ILBinaryReader open FSharp.Compiler.CompilerConfig open FSharp.Compiler.CompilerOptions open Internal.Utilities -open FSharp.Compiler.AbstractIL.ILBinaryReader -open System +open NUnit.Framework +// just a random thing to make things work let private getBuilder() = - // just a random thing to make things work TcConfigBuilder.CreateNew( null, FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value, @@ -37,9 +37,10 @@ let ``Help is displayed correctly`` () = displayHelpFsc builder blocks print exit let help = File.ReadAllText fileName - Assert.AreEqual(expectedHelp, help) - - () + // contains instead of equal + // as we don't control the 1st line of the output (the version) + // it's tested separately + StringAssert.Contains(expectedHelp, help) [] let ``Version is displayed correctly`` () = diff --git a/tests/FSharp.Compiler.Service.Tests/expected-help-output.txt b/tests/FSharp.Compiler.Service.Tests/expected-help-output.txt index f2873df8725..7d787f6ceb4 100644 --- a/tests/FSharp.Compiler.Service.Tests/expected-help-output.txt +++ b/tests/FSharp.Compiler.Service.Tests/expected-help-output.txt @@ -1,5 +1,4 @@ -Microsoft (R) F# Compiler version 12.0.4.0 for F# 6.0 -Copyright (c) Microsoft Corporation. All Rights Reserved. +Copyright (c) Microsoft Corporation. All Rights Reserved. - OUTPUT FILES - From f3f3a74eda1f378cade1c8e4960f8efcc9c46a36 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 19:29:09 +0200 Subject: [PATCH 18/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 15 +++++++-------- src/Compiler/Driver/CompilerOptions.fsi | 6 +++--- .../ConsoleOnlyOptionsTests.fs | 2 +- .../FSharp.Compiler.Service.Tests.fsproj | 2 -- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index d13fa3a1392..b094fe0e6b3 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -111,7 +111,6 @@ let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) = else sprintf "%s:%s" s tag (* still being decided *) - let PrintCompilerOption print (CompilerOption (_s, _tag, _spec, _, help) as compilerOption) = let flagWidth = 42 // fixed width for printing of flags, e.g. --debug:{full|pdbonly|portable|embedded} let defaultLineWidth = 80 // the fallback width @@ -1979,25 +1978,25 @@ let DisplayBannerText tcConfigB print = print $"{FSComp.SR.optsCopyright ()}\n") /// FSC only help. (FSI has it's own help function). -let displayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) print exit = +let DisplayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) print exit = DisplayBannerText tcConfigB print PrintCompilerOptionBlocks blocks print exit() -let displayVersion tcConfigB print exit = +let DisplayVersion tcConfigB print exit = print $"{tcConfigB.productNameForBannerText}\n" exit() let miscFlagsBoth tcConfigB = [ CompilerOption("nologo", tagNone, OptionUnit(fun () -> tcConfigB.showBanner <- false), None, Some(FSComp.SR.optsNologo ())) - CompilerOption("version", tagNone, OptionConsoleOnly(fun _ -> displayVersion tcConfigB Console.Write (exit 0)), None, Some(FSComp.SR.optsVersion ())) + CompilerOption("version", tagNone, OptionConsoleOnly(fun _ -> DisplayVersion tcConfigB Console.Write (exit 0)), None, Some(FSComp.SR.optsVersion ())) ] let miscFlagsFsc tcConfigB = miscFlagsBoth tcConfigB @ [ - CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.Write (exit 0)), None, Some(FSComp.SR.optsHelp ())) + CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> DisplayHelpFsc tcConfigB blocks Console.Write (exit 0)), None, Some(FSComp.SR.optsHelp ())) CompilerOption("@", tagNone, OptionUnit ignore, None, Some(FSComp.SR.optsResponseFile ())) ] @@ -2053,7 +2052,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "?", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.Write (exit 0)), + OptionConsoleOnly(fun blocks -> DisplayHelpFsc tcConfigB blocks Console.Write (exit 0)), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2061,7 +2060,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.Write (exit 0)), + OptionConsoleOnly(fun blocks -> DisplayHelpFsc tcConfigB blocks Console.Write (exit 0)), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2069,7 +2068,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "full-help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks Console.Write (exit 0)), + OptionConsoleOnly(fun blocks -> DisplayHelpFsc tcConfigB blocks Console.Write (exit 0)), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 18ac3ff73b8..e414df5239e 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -46,7 +46,7 @@ and CompilerOptionBlock = val PrintCompilerOptionBlocks: CompilerOptionBlock list -> print: (string -> unit) - -> unit // for printing usage + -> unit val DumpCompilerOptionBlocks: CompilerOptionBlock list -> unit // for QA @@ -60,14 +60,14 @@ val DisplayBannerText: -> print: (string -> unit) -> unit -val displayHelpFsc: +val DisplayHelpFsc: tcConfigB: TcConfigBuilder -> blocks: CompilerOptionBlock list -> print: (string -> unit) -> exit: (unit -> 'a) -> 'a -val displayVersion: +val DisplayVersion: tcConfigB: TcConfigBuilder -> print: (string -> unit) -> exit: (unit -> 'a) diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 10cc08b92a2..6a447c7c86d 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -37,7 +37,7 @@ let ``Help is displayed correctly`` () = displayHelpFsc builder blocks print exit let help = File.ReadAllText fileName - // contains instead of equal + // contains instead of equals // as we don't control the 1st line of the output (the version) // it's tested separately StringAssert.Contains(expectedHelp, help) diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj index 5daea43b6c6..76417737cf5 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj @@ -171,8 +171,6 @@ - - From e8dd34c25f5b1fe888b1ae052a302742991d1d37 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 23 Aug 2022 19:46:07 +0200 Subject: [PATCH 19/43] Update ConsoleOnlyOptionsTests.fs --- .../ConsoleOnlyOptionsTests.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 6a447c7c86d..415e7cf5292 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -31,10 +31,10 @@ let ``Help is displayed correctly`` () = let blocks = GetCoreFscCompilerOptions builder let fileName = $"{Guid.NewGuid()}" let expectedHelp = File.ReadAllText $"{__SOURCE_DIRECTORY__}/expected-help-output.txt" - let print text = File.AppendAllText(fileName, text) let exit() = () - displayHelpFsc builder blocks print exit + + DisplayHelpFsc builder blocks print exit let help = File.ReadAllText fileName // contains instead of equals @@ -47,10 +47,10 @@ let ``Version is displayed correctly`` () = let builder = getBuilder() let fileName = $"{Guid.NewGuid()}" let expectedVersionPattern = @"Microsoft \(R\) F# Compiler version \d+\.\d+\.\d+\.\d+ for F# \d+\.\d+" - let print text = File.AppendAllText(fileName, text) let exit() = () - displayVersion builder print exit + + DisplayVersion builder print exit let version = File.ReadAllText fileName Assert.That(version, Does.Match expectedVersionPattern) From 0e18d2524cdedb41f4e23eb0257a3ef179016233 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 13:44:54 +0200 Subject: [PATCH 20/43] Update --- src/Compiler/Driver/CompilerOptions.fsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index e414df5239e..65a6523974b 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -64,14 +64,14 @@ val DisplayHelpFsc: tcConfigB: TcConfigBuilder -> blocks: CompilerOptionBlock list -> print: (string -> unit) - -> exit: (unit -> 'a) - -> 'a + -> exit: (unit -> 'T) + -> 'T val DisplayVersion: tcConfigB: TcConfigBuilder -> print: (string -> unit) - -> exit: (unit -> 'a) - -> 'a + -> exit: (unit -> 'T) + -> 'T val GetCoreFscCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list From feb030c1a0e7985f225d67cb2198697a526c2087 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 13:47:18 +0200 Subject: [PATCH 21/43] Fantomas --- src/Compiler/Driver/CompilerOptions.fs | 22 +++++++++++++---- src/Compiler/Driver/CompilerOptions.fsi | 32 +++++++++---------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index b094fe0e6b3..0e7c362c836 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -173,7 +173,7 @@ let PrintCompilerOptionBlocks blocks print = let headingOptions = publicBlocks |> List.filter (fun (h2, _) -> heading = h2) |> List.collect snd - PrintPublicOptions(heading, headingOptions) print + PrintPublicOptions (heading, headingOptions) print Set.add heading doneHeadings List.fold consider Set.empty publicBlocks |> ignore> @@ -1981,22 +1981,34 @@ let DisplayBannerText tcConfigB print = let DisplayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) print exit = DisplayBannerText tcConfigB print PrintCompilerOptionBlocks blocks print - exit() + exit () let DisplayVersion tcConfigB print exit = print $"{tcConfigB.productNameForBannerText}\n" - exit() + exit () let miscFlagsBoth tcConfigB = [ CompilerOption("nologo", tagNone, OptionUnit(fun () -> tcConfigB.showBanner <- false), None, Some(FSComp.SR.optsNologo ())) - CompilerOption("version", tagNone, OptionConsoleOnly(fun _ -> DisplayVersion tcConfigB Console.Write (exit 0)), None, Some(FSComp.SR.optsVersion ())) + CompilerOption( + "version", + tagNone, + OptionConsoleOnly(fun _ -> DisplayVersion tcConfigB Console.Write (exit 0)), + None, + Some(FSComp.SR.optsVersion ()) + ) ] let miscFlagsFsc tcConfigB = miscFlagsBoth tcConfigB @ [ - CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> DisplayHelpFsc tcConfigB blocks Console.Write (exit 0)), None, Some(FSComp.SR.optsHelp ())) + CompilerOption( + "help", + tagNone, + OptionConsoleOnly(fun blocks -> DisplayHelpFsc tcConfigB blocks Console.Write (exit 0)), + None, + Some(FSComp.SR.optsHelp ()) + ) CompilerOption("@", tagNone, OptionUnit ignore, None, Some(FSComp.SR.optsResponseFile ())) ] diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 65a6523974b..2504ef51c30 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -43,10 +43,7 @@ and CompilerOptionBlock = | PublicOptions of heading: string * options: CompilerOption list | PrivateOptions of options: CompilerOption list -val PrintCompilerOptionBlocks: - CompilerOptionBlock list - -> print: (string -> unit) - -> unit +val PrintCompilerOptionBlocks: CompilerOptionBlock list -> print: (string -> unit) -> unit val DumpCompilerOptionBlocks: CompilerOptionBlock list -> unit // for QA @@ -55,23 +52,16 @@ val FilterCompilerOptionBlock: (CompilerOption -> bool) -> CompilerOptionBlock - /// Parse and process a set of compiler options val ParseCompilerOptions: (string -> unit) * CompilerOptionBlock list * string list -> unit -val DisplayBannerText: - tcConfigB: TcConfigBuilder - -> print: (string -> unit) - -> unit - -val DisplayHelpFsc: - tcConfigB: TcConfigBuilder - -> blocks: CompilerOptionBlock list - -> print: (string -> unit) - -> exit: (unit -> 'T) - -> 'T - -val DisplayVersion: - tcConfigB: TcConfigBuilder - -> print: (string -> unit) - -> exit: (unit -> 'T) - -> 'T +val DisplayBannerText: tcConfigB: TcConfigBuilder -> print: (string -> unit) -> unit + +val DisplayHelpFsc: + tcConfigB: TcConfigBuilder -> + blocks: CompilerOptionBlock list -> + print: (string -> unit) -> + exit: (unit -> 'T) -> + 'T + +val DisplayVersion: tcConfigB: TcConfigBuilder -> print: (string -> unit) -> exit: (unit -> 'T) -> 'T val GetCoreFscCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list From a642270032636aa9aad0b2704dd6b3cc7b880c78 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 14:11:01 +0200 Subject: [PATCH 22/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 18 +++++++++++------- src/Compiler/Driver/CompilerOptions.fsi | 6 +++--- .../ConsoleOnlyOptionsTests.fs | 4 ++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 0e7c362c836..b2941e1ab77 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -1978,22 +1978,26 @@ let DisplayBannerText tcConfigB print = print $"{FSComp.SR.optsCopyright ()}\n") /// FSC only help. (FSI has it's own help function). -let DisplayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) print exit = +let DisplayHelpFsc print exit tcConfigB (blocks: CompilerOptionBlock list) = DisplayBannerText tcConfigB print PrintCompilerOptionBlocks blocks print exit () -let DisplayVersion tcConfigB print exit = +let DisplayVersion print exit tcConfigB = print $"{tcConfigB.productNameForBannerText}\n" exit () +let displayHelpFsc = DisplayHelpFsc Console.Write (fun () -> exit 0) + +let displayVersion = DisplayVersion Console.Write (fun () -> exit 0) + let miscFlagsBoth tcConfigB = [ CompilerOption("nologo", tagNone, OptionUnit(fun () -> tcConfigB.showBanner <- false), None, Some(FSComp.SR.optsNologo ())) CompilerOption( "version", tagNone, - OptionConsoleOnly(fun _ -> DisplayVersion tcConfigB Console.Write (exit 0)), + OptionConsoleOnly(fun _ -> displayVersion tcConfigB), None, Some(FSComp.SR.optsVersion ()) ) @@ -2005,7 +2009,7 @@ let miscFlagsFsc tcConfigB = CompilerOption( "help", tagNone, - OptionConsoleOnly(fun blocks -> DisplayHelpFsc tcConfigB blocks Console.Write (exit 0)), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), None, Some(FSComp.SR.optsHelp ()) ) @@ -2064,7 +2068,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "?", tagNone, - OptionConsoleOnly(fun blocks -> DisplayHelpFsc tcConfigB blocks Console.Write (exit 0)), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2072,7 +2076,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "help", tagNone, - OptionConsoleOnly(fun blocks -> DisplayHelpFsc tcConfigB blocks Console.Write (exit 0)), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2080,7 +2084,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "full-help", tagNone, - OptionConsoleOnly(fun blocks -> DisplayHelpFsc tcConfigB blocks Console.Write (exit 0)), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 2504ef51c30..d05b322b338 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -55,13 +55,13 @@ val ParseCompilerOptions: (string -> unit) * CompilerOptionBlock list * string l val DisplayBannerText: tcConfigB: TcConfigBuilder -> print: (string -> unit) -> unit val DisplayHelpFsc: - tcConfigB: TcConfigBuilder -> - blocks: CompilerOptionBlock list -> print: (string -> unit) -> exit: (unit -> 'T) -> + tcConfigB: TcConfigBuilder -> + blocks: CompilerOptionBlock list -> 'T -val DisplayVersion: tcConfigB: TcConfigBuilder -> print: (string -> unit) -> exit: (unit -> 'T) -> 'T +val DisplayVersion: print: (string -> unit) -> exit: (unit -> 'T) -> tcConfigB: TcConfigBuilder -> 'T val GetCoreFscCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 415e7cf5292..558d3883ab9 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -34,7 +34,7 @@ let ``Help is displayed correctly`` () = let print text = File.AppendAllText(fileName, text) let exit() = () - DisplayHelpFsc builder blocks print exit + DisplayHelpFsc print exit builder blocks let help = File.ReadAllText fileName // contains instead of equals @@ -50,7 +50,7 @@ let ``Version is displayed correctly`` () = let print text = File.AppendAllText(fileName, text) let exit() = () - DisplayVersion builder print exit + DisplayVersion print exit builder let version = File.ReadAllText fileName Assert.That(version, Does.Match expectedVersionPattern) From 4459daf675fa21eeee4a26b504f6da7da0f6a7bf Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 14:26:44 +0200 Subject: [PATCH 23/43] Update CompilerOptions.fs --- src/Compiler/Driver/CompilerOptions.fs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index b2941e1ab77..3cc85c2ee8b 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -1994,25 +1994,13 @@ let displayVersion = DisplayVersion Console.Write (fun () -> exit 0) let miscFlagsBoth tcConfigB = [ CompilerOption("nologo", tagNone, OptionUnit(fun () -> tcConfigB.showBanner <- false), None, Some(FSComp.SR.optsNologo ())) - CompilerOption( - "version", - tagNone, - OptionConsoleOnly(fun _ -> displayVersion tcConfigB), - None, - Some(FSComp.SR.optsVersion ()) - ) + CompilerOption("version", tagNone, OptionConsoleOnly(fun _ -> displayVersion tcConfigB), None, Some(FSComp.SR.optsVersion ())) ] let miscFlagsFsc tcConfigB = miscFlagsBoth tcConfigB @ [ - CompilerOption( - "help", - tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), - None, - Some(FSComp.SR.optsHelp ()) - ) + CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), None, Some(FSComp.SR.optsHelp ())) CompilerOption("@", tagNone, OptionUnit ignore, None, Some(FSComp.SR.optsResponseFile ())) ] From 19dc57f1465beedf9e95ad29511b7505bbe8a223 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 14:28:22 +0200 Subject: [PATCH 24/43] Update --- src/Compiler/Interactive/fsi.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index bfdf9f7b1ec..ea1e99f55e5 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -882,7 +882,7 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig, // In the "--help", these options can be printed either before (fsiUsagePrefix) or after (fsiUsageSuffix) the core options. let displayHelpFsi tcConfigB (blocks:CompilerOptionBlock list) = - DisplayBannerText tcConfigB Console.Write; + DisplayBannerText tcConfigB Console.Write fprintfn fsiConsoleOutput.Out "" fprintfn fsiConsoleOutput.Out "%s" (FSIstrings.SR.fsiUsage(executableFileNameWithoutExtension.Value)) PrintCompilerOptionBlocks blocks Console.Write From ebf1e2b2f239128bad90582465f6995af8ea26db Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 14:30:43 +0200 Subject: [PATCH 25/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 22 +++++++++---------- src/Compiler/Driver/CompilerOptions.fsi | 10 ++++----- .../ConsoleOnlyOptionsTests.fs | 12 +++++----- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 3cc85c2ee8b..184b93419a1 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -1972,20 +1972,20 @@ let deprecatedFlagsFsc tcConfigB = // OptionBlock: Miscellaneous options //----------------------------------- -let DisplayBannerText tcConfigB print = +let DisplayBannerText tcConfigB printer = if tcConfigB.showBanner then - (print $"{tcConfigB.productNameForBannerText}\n" - print $"{FSComp.SR.optsCopyright ()}\n") + (printer $"{tcConfigB.productNameForBannerText}\n" + printer $"{FSComp.SR.optsCopyright ()}\n") /// FSC only help. (FSI has it's own help function). -let DisplayHelpFsc print exit tcConfigB (blocks: CompilerOptionBlock list) = - DisplayBannerText tcConfigB print - PrintCompilerOptionBlocks blocks print - exit () - -let DisplayVersion print exit tcConfigB = - print $"{tcConfigB.productNameForBannerText}\n" - exit () +let DisplayHelpFsc printer exiter tcConfigB (blocks: CompilerOptionBlock list) = + DisplayBannerText tcConfigB printer + PrintCompilerOptionBlocks blocks printer + exiter () + +let DisplayVersion printer exiter tcConfigB = + printer $"{tcConfigB.productNameForBannerText}\n" + exiter () let displayHelpFsc = DisplayHelpFsc Console.Write (fun () -> exit 0) diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index d05b322b338..53d9c876360 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -43,7 +43,7 @@ and CompilerOptionBlock = | PublicOptions of heading: string * options: CompilerOption list | PrivateOptions of options: CompilerOption list -val PrintCompilerOptionBlocks: CompilerOptionBlock list -> print: (string -> unit) -> unit +val PrintCompilerOptionBlocks: CompilerOptionBlock list -> printer: (string -> unit) -> unit val DumpCompilerOptionBlocks: CompilerOptionBlock list -> unit // for QA @@ -52,16 +52,16 @@ val FilterCompilerOptionBlock: (CompilerOption -> bool) -> CompilerOptionBlock - /// Parse and process a set of compiler options val ParseCompilerOptions: (string -> unit) * CompilerOptionBlock list * string list -> unit -val DisplayBannerText: tcConfigB: TcConfigBuilder -> print: (string -> unit) -> unit +val DisplayBannerText: tcConfigB: TcConfigBuilder -> printer: (string -> unit) -> unit val DisplayHelpFsc: - print: (string -> unit) -> - exit: (unit -> 'T) -> + printer: (string -> unit) -> + exiter: (unit -> 'T) -> tcConfigB: TcConfigBuilder -> blocks: CompilerOptionBlock list -> 'T -val DisplayVersion: print: (string -> unit) -> exit: (unit -> 'T) -> tcConfigB: TcConfigBuilder -> 'T +val DisplayVersion: printer: (string -> unit) -> exiter: (unit -> 'T) -> tcConfigB: TcConfigBuilder -> 'T val GetCoreFscCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 558d3883ab9..8df0721233c 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -31,10 +31,10 @@ let ``Help is displayed correctly`` () = let blocks = GetCoreFscCompilerOptions builder let fileName = $"{Guid.NewGuid()}" let expectedHelp = File.ReadAllText $"{__SOURCE_DIRECTORY__}/expected-help-output.txt" - let print text = File.AppendAllText(fileName, text) - let exit() = () + let printer text = File.AppendAllText(fileName, text) + let exiter () = () - DisplayHelpFsc print exit builder blocks + DisplayHelpFsc printer exiter builder blocks let help = File.ReadAllText fileName // contains instead of equals @@ -47,10 +47,10 @@ let ``Version is displayed correctly`` () = let builder = getBuilder() let fileName = $"{Guid.NewGuid()}" let expectedVersionPattern = @"Microsoft \(R\) F# Compiler version \d+\.\d+\.\d+\.\d+ for F# \d+\.\d+" - let print text = File.AppendAllText(fileName, text) - let exit() = () + let printer text = File.AppendAllText(fileName, text) + let exiter () = () - DisplayVersion print exit builder + DisplayVersion printer exiter builder let version = File.ReadAllText fileName Assert.That(version, Does.Match expectedVersionPattern) From 6a845fb1e7f46527f09ad0cf09de0df6b2b7f8bb Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 14:36:07 +0200 Subject: [PATCH 26/43] Update --- .../ConsoleOnlyOptionsTests.fs | 23 +++---------------- .../VisualStudioVersusConsoleContextTests.fs | 18 ++------------- tests/fsharp/TestHelpers.fs | 21 ++++++++++++++++- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 8df0721233c..0c781d258e6 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -4,30 +4,13 @@ module FSharp.Compiler.Service.Tests.ConsoleOnlyOptionsTests open System open System.IO -open FSharp.Compiler.Text -open FSharp.Compiler.AbstractIL.ILBinaryReader -open FSharp.Compiler.CompilerConfig open FSharp.Compiler.CompilerOptions -open Internal.Utilities open NUnit.Framework - -// just a random thing to make things work -let private getBuilder() = - TcConfigBuilder.CreateNew( - null, - FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value, - ReduceMemoryFlag.Yes, - Directory.GetCurrentDirectory(), - false, - false, - CopyFSharpCoreFlag.No, - (fun _ -> None), - None, - Range.Zero) +open Tests.TestHelpers [] let ``Help is displayed correctly`` () = - let builder = getBuilder() + let builder = getArbitraryTcConfigBuilder() let blocks = GetCoreFscCompilerOptions builder let fileName = $"{Guid.NewGuid()}" let expectedHelp = File.ReadAllText $"{__SOURCE_DIRECTORY__}/expected-help-output.txt" @@ -44,7 +27,7 @@ let ``Help is displayed correctly`` () = [] let ``Version is displayed correctly`` () = - let builder = getBuilder() + let builder = getArbitraryTcConfigBuilder() let fileName = $"{Guid.NewGuid()}" let expectedVersionPattern = @"Microsoft \(R\) F# Compiler version \d+\.\d+\.\d+\.\d+ for F# \d+\.\d+" let printer text = File.AppendAllText(fileName, text) diff --git a/tests/FSharp.Compiler.Service.Tests/VisualStudioVersusConsoleContextTests.fs b/tests/FSharp.Compiler.Service.Tests/VisualStudioVersusConsoleContextTests.fs index 9d37644e892..c43d3d860b7 100644 --- a/tests/FSharp.Compiler.Service.Tests/VisualStudioVersusConsoleContextTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/VisualStudioVersusConsoleContextTests.fs @@ -2,13 +2,9 @@ module FSharp.Compiler.Service.Tests.VisualStudioVersusConsoleContextTests -open FSharp.Compiler.Text open NUnit.Framework -open System.IO -open FSharp.Compiler.CompilerConfig open FSharp.Compiler.CompilerOptions -open Internal.Utilities -open FSharp.Compiler.AbstractIL.ILBinaryReader +open Tests.TestHelpers // copypasted from the CompilerOptions code, // not worth changing that code's accessibility just for this test @@ -23,17 +19,7 @@ let private getOptionsFromOptionBlocks blocks = [] // controls https://github.com/dotnet/fsharp/issues/13549 let ``Console-only options are filtered out for fsc in the VS context`` () = // just a random thing to make things work - let builder = TcConfigBuilder.CreateNew( - null, - FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value, - ReduceMemoryFlag.Yes, - Directory.GetCurrentDirectory(), - false, - false, - CopyFSharpCoreFlag.No, - (fun _ -> None), - None, - Range.Zero) + let builder = getArbitraryTcConfigBuilder() let blocks = GetCoreServiceCompilerOptions builder let options = getOptionsFromOptionBlocks blocks diff --git a/tests/fsharp/TestHelpers.fs b/tests/fsharp/TestHelpers.fs index f6b17da6c06..59124544da0 100644 --- a/tests/fsharp/TestHelpers.fs +++ b/tests/fsharp/TestHelpers.fs @@ -1,5 +1,10 @@ module Tests.TestHelpers + open System.IO +open FSharp.Compiler.Text +open FSharp.Compiler.AbstractIL.ILBinaryReader +open FSharp.Compiler.CompilerConfig +open Internal.Utilities let assembleDiffMessage actual expected = @@ -44,4 +49,18 @@ let assembleDiffMessage actual expected = newLine sb sb.ToString () - Some msg \ No newline at end of file + Some msg + +// just a random thing to make things work +let internal getArbitraryTcConfigBuilder() = + TcConfigBuilder.CreateNew( + null, + FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value, + ReduceMemoryFlag.Yes, + Directory.GetCurrentDirectory(), + false, + false, + CopyFSharpCoreFlag.No, + (fun _ -> None), + None, + Range.Zero) From 3f8bb8b94b3637b573c7737a9d092701c2f6b982 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 14:46:43 +0200 Subject: [PATCH 27/43] Update CompilerOptions.fs --- src/Compiler/Driver/CompilerOptions.fs | 34 ++++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 184b93419a1..1fee6b8597e 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -111,7 +111,9 @@ let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) = else sprintf "%s:%s" s tag (* still being decided *) -let PrintCompilerOption print (CompilerOption (_s, _tag, _spec, _, help) as compilerOption) = +let nl = Environment.NewLine + +let PrintCompilerOption printer (CompilerOption (_s, _tag, _spec, _, help) as compilerOption) = let flagWidth = 42 // fixed width for printing of flags, e.g. --debug:{full|pdbonly|portable|embedded} let defaultLineWidth = 80 // the fallback width @@ -130,18 +132,18 @@ let PrintCompilerOption print (CompilerOption (_s, _tag, _spec, _, help) as comp // flagWidth chars - for flags description or padding on continuation lines. // single space - space. // description - words upto but excluding the final character of the line. - print $"{compilerOptionUsage compilerOption, -40}" + printer $"{compilerOptionUsage compilerOption, -40}" let printWord column (word: string) = // Have printed upto column. // Now print the next word including any preceding whitespace. // Returns the column printed to (suited to folding). if column + 1 (*space*) + word.Length >= lineWidth then // NOTE: "equality" ensures final character of the line is never printed - print "\n" - print $"{String.Empty, -40} {word}" + printer $"{nl}" + printer $"{String.Empty, -40} {word}" flagWidth + 1 + word.Length else - print $" {word}" + printer $" {word}" column + 1 + word.Length let words = @@ -150,16 +152,16 @@ let PrintCompilerOption print (CompilerOption (_s, _tag, _spec, _, help) as comp | Some s -> s.Split [| ' ' |] let _finalColumn = Array.fold printWord flagWidth words - print "\n" + printer $"{nl}" -let PrintPublicOptions (heading, opts) print = +let PrintPublicOptions (heading, opts) printer = if not (isNil opts) then - print "\n" - print "\n" - print $"\t\t{heading}\n" - List.iter (PrintCompilerOption print) opts + printer $"{nl}" + printer $"{nl}" + printer $"\t\t{heading}{nl}" + List.iter (PrintCompilerOption printer) opts -let PrintCompilerOptionBlocks blocks print = +let PrintCompilerOptionBlocks blocks printer = let publicBlocks = blocks |> List.choose (function @@ -173,7 +175,7 @@ let PrintCompilerOptionBlocks blocks print = let headingOptions = publicBlocks |> List.filter (fun (h2, _) -> heading = h2) |> List.collect snd - PrintPublicOptions (heading, headingOptions) print + PrintPublicOptions (heading, headingOptions) printer Set.add heading doneHeadings List.fold consider Set.empty publicBlocks |> ignore> @@ -1974,8 +1976,8 @@ let deprecatedFlagsFsc tcConfigB = let DisplayBannerText tcConfigB printer = if tcConfigB.showBanner then - (printer $"{tcConfigB.productNameForBannerText}\n" - printer $"{FSComp.SR.optsCopyright ()}\n") + (printer $"{tcConfigB.productNameForBannerText}{nl}" + printer $"{FSComp.SR.optsCopyright ()}{nl}") /// FSC only help. (FSI has it's own help function). let DisplayHelpFsc printer exiter tcConfigB (blocks: CompilerOptionBlock list) = @@ -1984,7 +1986,7 @@ let DisplayHelpFsc printer exiter tcConfigB (blocks: CompilerOptionBlock list) = exiter () let DisplayVersion printer exiter tcConfigB = - printer $"{tcConfigB.productNameForBannerText}\n" + printer $"{tcConfigB.productNameForBannerText}{nl}" exiter () let displayHelpFsc = DisplayHelpFsc Console.Write (fun () -> exit 0) From 76a3a702c38b815e2813c4eaef24d9d1ab45c09d Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 15:37:50 +0200 Subject: [PATCH 28/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 18 +++++++++--------- src/Compiler/Driver/CompilerOptions.fsi | 4 ++-- src/Compiler/Driver/fsc.fs | 2 +- src/Compiler/Interactive/fsi.fs | 2 +- .../ConsoleOnlyOptionsTests.fs | 6 +----- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 1fee6b8597e..ce1220ecab0 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -1974,29 +1974,29 @@ let deprecatedFlagsFsc tcConfigB = // OptionBlock: Miscellaneous options //----------------------------------- -let DisplayBannerText tcConfigB printer = +let GetBannerText tcConfigB = if tcConfigB.showBanner then - (printer $"{tcConfigB.productNameForBannerText}{nl}" - printer $"{FSComp.SR.optsCopyright ()}{nl}") + $"{tcConfigB.productNameForBannerText}{nl}" + + $"{FSComp.SR.optsCopyright ()}{nl}" + else "" /// FSC only help. (FSI has it's own help function). let DisplayHelpFsc printer exiter tcConfigB (blocks: CompilerOptionBlock list) = - DisplayBannerText tcConfigB printer + printer (GetBannerText tcConfigB) PrintCompilerOptionBlocks blocks printer exiter () -let DisplayVersion printer exiter tcConfigB = - printer $"{tcConfigB.productNameForBannerText}{nl}" - exiter () +let GetVersion tcConfigB = + $"{tcConfigB.productNameForBannerText}{nl}" let displayHelpFsc = DisplayHelpFsc Console.Write (fun () -> exit 0) -let displayVersion = DisplayVersion Console.Write (fun () -> exit 0) +let displayVersion = GetVersion >> Console.Write let miscFlagsBoth tcConfigB = [ CompilerOption("nologo", tagNone, OptionUnit(fun () -> tcConfigB.showBanner <- false), None, Some(FSComp.SR.optsNologo ())) - CompilerOption("version", tagNone, OptionConsoleOnly(fun _ -> displayVersion tcConfigB), None, Some(FSComp.SR.optsVersion ())) + CompilerOption("version", tagNone, OptionConsoleOnly(fun _ -> displayVersion tcConfigB; exit 0), None, Some(FSComp.SR.optsVersion ())) ] let miscFlagsFsc tcConfigB = diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 53d9c876360..eb709a76265 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -52,7 +52,7 @@ val FilterCompilerOptionBlock: (CompilerOption -> bool) -> CompilerOptionBlock - /// Parse and process a set of compiler options val ParseCompilerOptions: (string -> unit) * CompilerOptionBlock list * string list -> unit -val DisplayBannerText: tcConfigB: TcConfigBuilder -> printer: (string -> unit) -> unit +val GetBannerText: tcConfigB: TcConfigBuilder -> string val DisplayHelpFsc: printer: (string -> unit) -> @@ -61,7 +61,7 @@ val DisplayHelpFsc: blocks: CompilerOptionBlock list -> 'T -val DisplayVersion: printer: (string -> unit) -> exiter: (unit -> 'T) -> tcConfigB: TcConfigBuilder -> 'T +val GetVersion: tcConfigB: TcConfigBuilder -> string val GetCoreFscCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list diff --git a/src/Compiler/Driver/fsc.fs b/src/Compiler/Driver/fsc.fs index d2880ba146c..ea2eca95518 100644 --- a/src/Compiler/Driver/fsc.fs +++ b/src/Compiler/Driver/fsc.fs @@ -544,7 +544,7 @@ let main1 // Display the banner text, if necessary if not bannerAlreadyPrinted then - DisplayBannerText tcConfigB Console.Write + Console.Write (GetBannerText tcConfigB) // Create tcGlobals and frameworkTcImports let outfile, pdbfile, assemblyName = diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index ea1e99f55e5..14d395a25a7 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -882,7 +882,7 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig, // In the "--help", these options can be printed either before (fsiUsagePrefix) or after (fsiUsageSuffix) the core options. let displayHelpFsi tcConfigB (blocks:CompilerOptionBlock list) = - DisplayBannerText tcConfigB Console.Write + Console.Write (GetBannerText tcConfigB) fprintfn fsiConsoleOutput.Out "" fprintfn fsiConsoleOutput.Out "%s" (FSIstrings.SR.fsiUsage(executableFileNameWithoutExtension.Value)) PrintCompilerOptionBlocks blocks Console.Write diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 0c781d258e6..05b7abdced5 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -28,12 +28,8 @@ let ``Help is displayed correctly`` () = [] let ``Version is displayed correctly`` () = let builder = getArbitraryTcConfigBuilder() - let fileName = $"{Guid.NewGuid()}" let expectedVersionPattern = @"Microsoft \(R\) F# Compiler version \d+\.\d+\.\d+\.\d+ for F# \d+\.\d+" - let printer text = File.AppendAllText(fileName, text) - let exiter () = () - DisplayVersion printer exiter builder + let version = GetVersion builder - let version = File.ReadAllText fileName Assert.That(version, Does.Match expectedVersionPattern) From 0e76306650aa858aaa6bc2a64087b0c45f22dc1e Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 15:50:28 +0200 Subject: [PATCH 29/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index ce1220ecab0..612b257ac0e 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -22,6 +22,7 @@ open FSharp.Compiler.TypedTreeOps open FSharp.Compiler.DiagnosticsLogger open Internal.Utilities +open System.Text module Attributes = open System.Runtime.CompilerServices @@ -113,7 +114,9 @@ let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) = let nl = Environment.NewLine -let PrintCompilerOption printer (CompilerOption (_s, _tag, _spec, _, help) as compilerOption) = +let getCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOption) = + let sb = StringBuilder() + let flagWidth = 42 // fixed width for printing of flags, e.g. --debug:{full|pdbonly|portable|embedded} let defaultLineWidth = 80 // the fallback width @@ -132,18 +135,18 @@ let PrintCompilerOption printer (CompilerOption (_s, _tag, _spec, _, help) as co // flagWidth chars - for flags description or padding on continuation lines. // single space - space. // description - words upto but excluding the final character of the line. - printer $"{compilerOptionUsage compilerOption, -40}" + let _ = sb.Append $"{compilerOptionUsage compilerOption, -40}" let printWord column (word: string) = // Have printed upto column. // Now print the next word including any preceding whitespace. // Returns the column printed to (suited to folding). if column + 1 (*space*) + word.Length >= lineWidth then // NOTE: "equality" ensures final character of the line is never printed - printer $"{nl}" - printer $"{String.Empty, -40} {word}" + let _ = sb.Append $"{nl}" + let _ = sb.Append $"{String.Empty, -40} {word}" flagWidth + 1 + word.Length else - printer $" {word}" + let _ = sb.Append $" {word}" column + 1 + word.Length let words = @@ -152,14 +155,15 @@ let PrintCompilerOption printer (CompilerOption (_s, _tag, _spec, _, help) as co | Some s -> s.Split [| ' ' |] let _finalColumn = Array.fold printWord flagWidth words - printer $"{nl}" + let _ = sb.Append $"{nl}" + sb.ToString() let PrintPublicOptions (heading, opts) printer = if not (isNil opts) then printer $"{nl}" printer $"{nl}" printer $"\t\t{heading}{nl}" - List.iter (PrintCompilerOption printer) opts + List.iter (getCompilerOption >> printer) opts let PrintCompilerOptionBlocks blocks printer = let publicBlocks = From 43a09aaad6922cf43cd6982a037ef828d620bea6 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 15:58:44 +0200 Subject: [PATCH 30/43] update --- src/Compiler/Driver/CompilerOptions.fs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 612b257ac0e..40c2c165392 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -158,12 +158,15 @@ let getCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOpti let _ = sb.Append $"{nl}" sb.ToString() -let PrintPublicOptions (heading, opts) printer = +let GetPublicOptions (heading, opts) = + let sb = StringBuilder() if not (isNil opts) then - printer $"{nl}" - printer $"{nl}" - printer $"\t\t{heading}{nl}" - List.iter (getCompilerOption >> printer) opts + let _ = sb.Append $"{nl}" + let _ = sb.Append $"{nl}" + let _ = sb.Append $"\t\t{heading}{nl}" + opts |> List.map getCompilerOption |> List.iter (sb.Append >> ignore) + sb.ToString() + else "" let PrintCompilerOptionBlocks blocks printer = let publicBlocks = @@ -179,7 +182,7 @@ let PrintCompilerOptionBlocks blocks printer = let headingOptions = publicBlocks |> List.filter (fun (h2, _) -> heading = h2) |> List.collect snd - PrintPublicOptions (heading, headingOptions) printer + printer (GetPublicOptions (heading, headingOptions)) Set.add heading doneHeadings List.fold consider Set.empty publicBlocks |> ignore> From 4a391b0ff35b384ac252655a5cbbefae8c3af7cd Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 16:04:38 +0200 Subject: [PATCH 31/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 8 +++++--- src/Compiler/Driver/CompilerOptions.fsi | 2 +- src/Compiler/Interactive/fsi.fs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 40c2c165392..915d7461fc7 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -168,7 +168,8 @@ let GetPublicOptions (heading, opts) = sb.ToString() else "" -let PrintCompilerOptionBlocks blocks printer = +let PrintCompilerOptionBlocks blocks = + let sb = new StringBuilder() let publicBlocks = blocks |> List.choose (function @@ -182,10 +183,11 @@ let PrintCompilerOptionBlocks blocks printer = let headingOptions = publicBlocks |> List.filter (fun (h2, _) -> heading = h2) |> List.collect snd - printer (GetPublicOptions (heading, headingOptions)) + let _ = sb.Append (GetPublicOptions (heading, headingOptions)) Set.add heading doneHeadings List.fold consider Set.empty publicBlocks |> ignore> + sb.ToString() (* For QA *) let dumpCompilerOption prefix (CompilerOption (str, _, spec, _, _)) = @@ -1990,7 +1992,7 @@ let GetBannerText tcConfigB = /// FSC only help. (FSI has it's own help function). let DisplayHelpFsc printer exiter tcConfigB (blocks: CompilerOptionBlock list) = printer (GetBannerText tcConfigB) - PrintCompilerOptionBlocks blocks printer + printer (PrintCompilerOptionBlocks blocks) exiter () let GetVersion tcConfigB = diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index eb709a76265..e1ff045f4e5 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -43,7 +43,7 @@ and CompilerOptionBlock = | PublicOptions of heading: string * options: CompilerOption list | PrivateOptions of options: CompilerOption list -val PrintCompilerOptionBlocks: CompilerOptionBlock list -> printer: (string -> unit) -> unit +val PrintCompilerOptionBlocks: CompilerOptionBlock list -> string val DumpCompilerOptionBlocks: CompilerOptionBlock list -> unit // for QA diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 14d395a25a7..607f50f9306 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -885,7 +885,7 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig, Console.Write (GetBannerText tcConfigB) fprintfn fsiConsoleOutput.Out "" fprintfn fsiConsoleOutput.Out "%s" (FSIstrings.SR.fsiUsage(executableFileNameWithoutExtension.Value)) - PrintCompilerOptionBlocks blocks Console.Write + Console.Write (PrintCompilerOptionBlocks blocks) exit 0 // option tags From 357f39d6234a7f96d0147c2c9c37f56ab5d10d1c Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 16:12:33 +0200 Subject: [PATCH 32/43] update --- src/Compiler/Driver/CompilerOptions.fs | 19 +++++++++---------- src/Compiler/Driver/CompilerOptions.fsi | 8 +++----- src/Compiler/Interactive/fsi.fs | 2 +- .../ConsoleOnlyOptionsTests.fs | 7 +------ 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 915d7461fc7..55622d1b3e4 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -168,7 +168,7 @@ let GetPublicOptions (heading, opts) = sb.ToString() else "" -let PrintCompilerOptionBlocks blocks = +let GetCompilerOptionBlocks blocks = let sb = new StringBuilder() let publicBlocks = blocks @@ -1990,15 +1990,14 @@ let GetBannerText tcConfigB = else "" /// FSC only help. (FSI has it's own help function). -let DisplayHelpFsc printer exiter tcConfigB (blocks: CompilerOptionBlock list) = - printer (GetBannerText tcConfigB) - printer (PrintCompilerOptionBlocks blocks) - exiter () +let GetHelpFsc tcConfigB (blocks: CompilerOptionBlock list) = + GetBannerText tcConfigB + + GetCompilerOptionBlocks blocks let GetVersion tcConfigB = $"{tcConfigB.productNameForBannerText}{nl}" -let displayHelpFsc = DisplayHelpFsc Console.Write (fun () -> exit 0) +let displayHelpFsc config blocks = GetHelpFsc config blocks |> Console.Write let displayVersion = GetVersion >> Console.Write @@ -2011,7 +2010,7 @@ let miscFlagsBoth tcConfigB = let miscFlagsFsc tcConfigB = miscFlagsBoth tcConfigB @ [ - CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), None, Some(FSComp.SR.optsHelp ())) + CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks; exit 0), None, Some(FSComp.SR.optsHelp ())) CompilerOption("@", tagNone, OptionUnit ignore, None, Some(FSComp.SR.optsResponseFile ())) ] @@ -2067,7 +2066,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "?", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks; exit 0), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2075,7 +2074,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks; exit 0), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2083,7 +2082,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "full-help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), + OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks; exit 0), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index e1ff045f4e5..8d66b7728f8 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -43,7 +43,7 @@ and CompilerOptionBlock = | PublicOptions of heading: string * options: CompilerOption list | PrivateOptions of options: CompilerOption list -val PrintCompilerOptionBlocks: CompilerOptionBlock list -> string +val GetCompilerOptionBlocks: CompilerOptionBlock list -> string val DumpCompilerOptionBlocks: CompilerOptionBlock list -> unit // for QA @@ -54,12 +54,10 @@ val ParseCompilerOptions: (string -> unit) * CompilerOptionBlock list * string l val GetBannerText: tcConfigB: TcConfigBuilder -> string -val DisplayHelpFsc: - printer: (string -> unit) -> - exiter: (unit -> 'T) -> +val GetHelpFsc: tcConfigB: TcConfigBuilder -> blocks: CompilerOptionBlock list -> - 'T + string val GetVersion: tcConfigB: TcConfigBuilder -> string diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 607f50f9306..f44b7d5df46 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -885,7 +885,7 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig, Console.Write (GetBannerText tcConfigB) fprintfn fsiConsoleOutput.Out "" fprintfn fsiConsoleOutput.Out "%s" (FSIstrings.SR.fsiUsage(executableFileNameWithoutExtension.Value)) - Console.Write (PrintCompilerOptionBlocks blocks) + Console.Write (GetCompilerOptionBlocks blocks) exit 0 // option tags diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 05b7abdced5..bed2f983e1f 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -2,7 +2,6 @@ module FSharp.Compiler.Service.Tests.ConsoleOnlyOptionsTests -open System open System.IO open FSharp.Compiler.CompilerOptions open NUnit.Framework @@ -12,14 +11,10 @@ open Tests.TestHelpers let ``Help is displayed correctly`` () = let builder = getArbitraryTcConfigBuilder() let blocks = GetCoreFscCompilerOptions builder - let fileName = $"{Guid.NewGuid()}" let expectedHelp = File.ReadAllText $"{__SOURCE_DIRECTORY__}/expected-help-output.txt" - let printer text = File.AppendAllText(fileName, text) - let exiter () = () - DisplayHelpFsc printer exiter builder blocks + let help = GetHelpFsc builder blocks - let help = File.ReadAllText fileName // contains instead of equals // as we don't control the 1st line of the output (the version) // it's tested separately From d41514fa0fbb9ef1275a3a22f5698d3586c14b37 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 16:16:10 +0200 Subject: [PATCH 33/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 55622d1b3e4..b925f6c4323 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -1999,12 +1999,10 @@ let GetVersion tcConfigB = let displayHelpFsc config blocks = GetHelpFsc config blocks |> Console.Write -let displayVersion = GetVersion >> Console.Write - let miscFlagsBoth tcConfigB = [ CompilerOption("nologo", tagNone, OptionUnit(fun () -> tcConfigB.showBanner <- false), None, Some(FSComp.SR.optsNologo ())) - CompilerOption("version", tagNone, OptionConsoleOnly(fun _ -> displayVersion tcConfigB; exit 0), None, Some(FSComp.SR.optsVersion ())) + CompilerOption("version", tagNone, OptionConsoleOnly(fun _ -> Console.Write (GetVersion tcConfigB); exit 0), None, Some(FSComp.SR.optsVersion ())) ] let miscFlagsFsc tcConfigB = From 51bfe7b3f06e9a1568683bbf747b13fef4725b33 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 16:17:32 +0200 Subject: [PATCH 34/43] Update CompilerOptions.fs --- src/Compiler/Driver/CompilerOptions.fs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index b925f6c4323..c616b77ba16 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -1997,8 +1997,6 @@ let GetHelpFsc tcConfigB (blocks: CompilerOptionBlock list) = let GetVersion tcConfigB = $"{tcConfigB.productNameForBannerText}{nl}" -let displayHelpFsc config blocks = GetHelpFsc config blocks |> Console.Write - let miscFlagsBoth tcConfigB = [ CompilerOption("nologo", tagNone, OptionUnit(fun () -> tcConfigB.showBanner <- false), None, Some(FSComp.SR.optsNologo ())) @@ -2008,7 +2006,7 @@ let miscFlagsBoth tcConfigB = let miscFlagsFsc tcConfigB = miscFlagsBoth tcConfigB @ [ - CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks; exit 0), None, Some(FSComp.SR.optsHelp ())) + CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> Console.Write (GetHelpFsc tcConfigB blocks); exit 0), None, Some(FSComp.SR.optsHelp ())) CompilerOption("@", tagNone, OptionUnit ignore, None, Some(FSComp.SR.optsResponseFile ())) ] @@ -2064,7 +2062,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "?", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks; exit 0), + OptionConsoleOnly(fun blocks -> Console.Write (GetHelpFsc tcConfigB blocks); exit 0), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2072,7 +2070,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks; exit 0), + OptionConsoleOnly(fun blocks -> Console.Write (GetHelpFsc tcConfigB blocks); exit 0), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2080,7 +2078,7 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "full-help", tagNone, - OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks; exit 0), + OptionConsoleOnly(fun blocks -> Console.Write (GetHelpFsc tcConfigB blocks); exit 0), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) From 59a46d8bc1ed74a30710eb25afac04c7a3bc622b Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 16:28:19 +0200 Subject: [PATCH 35/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 51 ++++++++++++++++++------- src/Compiler/Driver/CompilerOptions.fsi | 5 +-- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index c616b77ba16..b93a2913ed0 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -158,18 +158,21 @@ let getCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOpti let _ = sb.Append $"{nl}" sb.ToString() -let GetPublicOptions (heading, opts) = +let getPublicOptions (heading, opts) = let sb = StringBuilder() + if not (isNil opts) then let _ = sb.Append $"{nl}" let _ = sb.Append $"{nl}" let _ = sb.Append $"\t\t{heading}{nl}" opts |> List.map getCompilerOption |> List.iter (sb.Append >> ignore) sb.ToString() - else "" + else + "" let GetCompilerOptionBlocks blocks = let sb = new StringBuilder() + let publicBlocks = blocks |> List.choose (function @@ -183,7 +186,7 @@ let GetCompilerOptionBlocks blocks = let headingOptions = publicBlocks |> List.filter (fun (h2, _) -> heading = h2) |> List.collect snd - let _ = sb.Append (GetPublicOptions (heading, headingOptions)) + let _ = sb.Append(getPublicOptions(heading, headingOptions)) Set.add heading doneHeadings List.fold consider Set.empty publicBlocks |> ignore> @@ -1985,14 +1988,14 @@ let deprecatedFlagsFsc tcConfigB = let GetBannerText tcConfigB = if tcConfigB.showBanner then - $"{tcConfigB.productNameForBannerText}{nl}" + - $"{FSComp.SR.optsCopyright ()}{nl}" - else "" + $"{tcConfigB.productNameForBannerText}{nl}" + + $"{FSComp.SR.optsCopyright ()}{nl}" + else + "" /// FSC only help. (FSI has it's own help function). let GetHelpFsc tcConfigB (blocks: CompilerOptionBlock list) = - GetBannerText tcConfigB + - GetCompilerOptionBlocks blocks + GetBannerText tcConfigB + GetCompilerOptionBlocks blocks let GetVersion tcConfigB = $"{tcConfigB.productNameForBannerText}{nl}" @@ -2000,13 +2003,29 @@ let GetVersion tcConfigB = let miscFlagsBoth tcConfigB = [ CompilerOption("nologo", tagNone, OptionUnit(fun () -> tcConfigB.showBanner <- false), None, Some(FSComp.SR.optsNologo ())) - CompilerOption("version", tagNone, OptionConsoleOnly(fun _ -> Console.Write (GetVersion tcConfigB); exit 0), None, Some(FSComp.SR.optsVersion ())) + CompilerOption( + "version", + tagNone, + OptionConsoleOnly(fun _ -> + Console.Write(GetVersion tcConfigB) + exit 0), + None, + Some(FSComp.SR.optsVersion ()) + ) ] let miscFlagsFsc tcConfigB = miscFlagsBoth tcConfigB @ [ - CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> Console.Write (GetHelpFsc tcConfigB blocks); exit 0), None, Some(FSComp.SR.optsHelp ())) + CompilerOption( + "help", + tagNone, + OptionConsoleOnly(fun blocks -> + Console.Write(GetHelpFsc tcConfigB blocks) + exit 0), + None, + Some(FSComp.SR.optsHelp ()) + ) CompilerOption("@", tagNone, OptionUnit ignore, None, Some(FSComp.SR.optsResponseFile ())) ] @@ -2062,7 +2081,9 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "?", tagNone, - OptionConsoleOnly(fun blocks -> Console.Write (GetHelpFsc tcConfigB blocks); exit 0), + OptionConsoleOnly(fun blocks -> + Console.Write(GetHelpFsc tcConfigB blocks) + exit 0), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2070,7 +2091,9 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "help", tagNone, - OptionConsoleOnly(fun blocks -> Console.Write (GetHelpFsc tcConfigB blocks); exit 0), + OptionConsoleOnly(fun blocks -> + Console.Write(GetHelpFsc tcConfigB blocks) + exit 0), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) @@ -2078,7 +2101,9 @@ let abbreviatedFlagsFsc tcConfigB = CompilerOption( "full-help", tagNone, - OptionConsoleOnly(fun blocks -> Console.Write (GetHelpFsc tcConfigB blocks); exit 0), + OptionConsoleOnly(fun blocks -> + Console.Write(GetHelpFsc tcConfigB blocks) + exit 0), None, Some(FSComp.SR.optsShortFormOf ("--help")) ) diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 8d66b7728f8..048bffb51e9 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -54,10 +54,7 @@ val ParseCompilerOptions: (string -> unit) * CompilerOptionBlock list * string l val GetBannerText: tcConfigB: TcConfigBuilder -> string -val GetHelpFsc: - tcConfigB: TcConfigBuilder -> - blocks: CompilerOptionBlock list -> - string +val GetHelpFsc: tcConfigB: TcConfigBuilder -> blocks: CompilerOptionBlock list -> string val GetVersion: tcConfigB: TcConfigBuilder -> string From acea4542a692365273d98f30f0ee711caf52eca5 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 16:41:35 +0200 Subject: [PATCH 36/43] Update --- tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index bed2f983e1f..196ca16cf85 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -2,6 +2,7 @@ module FSharp.Compiler.Service.Tests.ConsoleOnlyOptionsTests +open System open System.IO open FSharp.Compiler.CompilerOptions open NUnit.Framework @@ -18,7 +19,7 @@ let ``Help is displayed correctly`` () = // contains instead of equals // as we don't control the 1st line of the output (the version) // it's tested separately - StringAssert.Contains(expectedHelp, help) + StringAssert.Contains(expectedHelp, help.Replace("\r\n", Environment.NewLine)) [] let ``Version is displayed correctly`` () = From a4790bc7b114b693ab9a2c9cfa88f7c4231199bb Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 16:42:53 +0200 Subject: [PATCH 37/43] Update CompilerOptions.fs --- src/Compiler/Driver/CompilerOptions.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index b93a2913ed0..1de372ac6ca 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -186,7 +186,7 @@ let GetCompilerOptionBlocks blocks = let headingOptions = publicBlocks |> List.filter (fun (h2, _) -> heading = h2) |> List.collect snd - let _ = sb.Append(getPublicOptions(heading, headingOptions)) + let _ = sb.Append(getPublicOptions (heading, headingOptions)) Set.add heading doneHeadings List.fold consider Set.empty publicBlocks |> ignore> From fe633fc2a32f422dd97fe610cdfb8977079419d6 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 16:54:52 +0200 Subject: [PATCH 38/43] Update CompilerOptions.fs --- src/Compiler/Driver/CompilerOptions.fs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 1de372ac6ca..b771dac94e7 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -159,14 +159,9 @@ let getCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOpti sb.ToString() let getPublicOptions (heading, opts) = - let sb = StringBuilder() - if not (isNil opts) then - let _ = sb.Append $"{nl}" - let _ = sb.Append $"{nl}" - let _ = sb.Append $"\t\t{heading}{nl}" - opts |> List.map getCompilerOption |> List.iter (sb.Append >> ignore) - sb.ToString() + $"{nl}{nl}\t\t{heading}{nl}" + + (opts |> List.map getCompilerOption |> String.concat "") else "" From 5945c45c40a25b6de624d98e54dbacb00d36deca Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 17:04:12 +0200 Subject: [PATCH 39/43] Update --- src/Compiler/Driver/CompilerOptions.fs | 4 ++-- src/Compiler/Driver/fsc.fs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index b771dac94e7..40b001f4699 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -160,8 +160,8 @@ let getCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOpti let getPublicOptions (heading, opts) = if not (isNil opts) then - $"{nl}{nl}\t\t{heading}{nl}" + - (opts |> List.map getCompilerOption |> String.concat "") + $"{nl}{nl}\t\t{heading}{nl}" + + (opts |> List.map getCompilerOption |> String.concat "") else "" diff --git a/src/Compiler/Driver/fsc.fs b/src/Compiler/Driver/fsc.fs index ea2eca95518..28174489a61 100644 --- a/src/Compiler/Driver/fsc.fs +++ b/src/Compiler/Driver/fsc.fs @@ -544,7 +544,7 @@ let main1 // Display the banner text, if necessary if not bannerAlreadyPrinted then - Console.Write (GetBannerText tcConfigB) + Console.Write(GetBannerText tcConfigB) // Create tcGlobals and frameworkTcImports let outfile, pdbfile, assemblyName = From b8b63c1f90d10b6ef832105a8c633cd243ed1c90 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 18:55:14 +0200 Subject: [PATCH 40/43] Update --- .../TestDoubles.fs | 23 +++++++++++++++++++ tests/fsharp/TestHelpers.fs | 19 +-------------- 2 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 tests/FSharp.Compiler.Service.Tests/TestDoubles.fs diff --git a/tests/FSharp.Compiler.Service.Tests/TestDoubles.fs b/tests/FSharp.Compiler.Service.Tests/TestDoubles.fs new file mode 100644 index 00000000000..7af70f94c83 --- /dev/null +++ b/tests/FSharp.Compiler.Service.Tests/TestDoubles.fs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +module FSharp.Compiler.Service.Tests.TestDoubles + +open System.IO +open FSharp.Compiler.Text +open FSharp.Compiler.AbstractIL.ILBinaryReader +open FSharp.Compiler.CompilerConfig +open Internal.Utilities + +// just a random thing to make things work +let internal getArbitraryTcConfigBuilder() = + TcConfigBuilder.CreateNew( + null, + FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value, + ReduceMemoryFlag.Yes, + Directory.GetCurrentDirectory(), + false, + false, + CopyFSharpCoreFlag.No, + (fun _ -> None), + None, + Range.Zero) diff --git a/tests/fsharp/TestHelpers.fs b/tests/fsharp/TestHelpers.fs index 59124544da0..6a1ef2fab98 100644 --- a/tests/fsharp/TestHelpers.fs +++ b/tests/fsharp/TestHelpers.fs @@ -1,10 +1,7 @@ module Tests.TestHelpers open System.IO -open FSharp.Compiler.Text -open FSharp.Compiler.AbstractIL.ILBinaryReader -open FSharp.Compiler.CompilerConfig -open Internal.Utilities + let assembleDiffMessage actual expected = @@ -50,17 +47,3 @@ let assembleDiffMessage actual expected = sb.ToString () Some msg - -// just a random thing to make things work -let internal getArbitraryTcConfigBuilder() = - TcConfigBuilder.CreateNew( - null, - FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value, - ReduceMemoryFlag.Yes, - Directory.GetCurrentDirectory(), - false, - false, - CopyFSharpCoreFlag.No, - (fun _ -> None), - None, - Range.Zero) From 03486303e83fdf103564bc0f599fe39152de7b3c Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 18:55:50 +0200 Subject: [PATCH 41/43] Update TestHelpers.fs --- tests/fsharp/TestHelpers.fs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/fsharp/TestHelpers.fs b/tests/fsharp/TestHelpers.fs index 6a1ef2fab98..f6b17da6c06 100644 --- a/tests/fsharp/TestHelpers.fs +++ b/tests/fsharp/TestHelpers.fs @@ -1,8 +1,6 @@ module Tests.TestHelpers - open System.IO - let assembleDiffMessage actual expected = let getLines text = @@ -46,4 +44,4 @@ let assembleDiffMessage actual expected = newLine sb sb.ToString () - Some msg + Some msg \ No newline at end of file From b434bc64e56f55e03d06e60a57d56d9d72f33c2e Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 18:56:21 +0200 Subject: [PATCH 42/43] Update --- tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs | 2 +- .../VisualStudioVersusConsoleContextTests.fs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs index 196ca16cf85..7cab17439c4 100644 --- a/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs @@ -6,7 +6,7 @@ open System open System.IO open FSharp.Compiler.CompilerOptions open NUnit.Framework -open Tests.TestHelpers +open TestDoubles [] let ``Help is displayed correctly`` () = diff --git a/tests/FSharp.Compiler.Service.Tests/VisualStudioVersusConsoleContextTests.fs b/tests/FSharp.Compiler.Service.Tests/VisualStudioVersusConsoleContextTests.fs index c43d3d860b7..24dea808feb 100644 --- a/tests/FSharp.Compiler.Service.Tests/VisualStudioVersusConsoleContextTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/VisualStudioVersusConsoleContextTests.fs @@ -4,7 +4,7 @@ module FSharp.Compiler.Service.Tests.VisualStudioVersusConsoleContextTests open NUnit.Framework open FSharp.Compiler.CompilerOptions -open Tests.TestHelpers +open TestDoubles // copypasted from the CompilerOptions code, // not worth changing that code's accessibility just for this test From d971f2884b33331d0404657294b0dccaac85c0e7 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 24 Aug 2022 18:59:00 +0200 Subject: [PATCH 43/43] Update FSharp.Compiler.Service.Tests.fsproj --- .../FSharp.Compiler.Service.Tests.fsproj | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj index 7ca6bf13b15..81f470dcbcd 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj @@ -41,6 +41,7 @@ Symbols.fs +