Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bf2291f
update
psfinaki Aug 23, 2022
538ddd8
Update
psfinaki Aug 23, 2022
56872bc
basic test
psfinaki Aug 23, 2022
ffc5fd2
Update
psfinaki Aug 23, 2022
744b5e7
Update
psfinaki Aug 23, 2022
d2cf45a
Update
psfinaki Aug 23, 2022
6191fe5
Update ConsoleOnlyOptionsTests.fs
psfinaki Aug 23, 2022
47b734b
Update
psfinaki Aug 23, 2022
3051560
Update
psfinaki Aug 23, 2022
210c424
Update
psfinaki Aug 23, 2022
681a4b4
Update
psfinaki Aug 23, 2022
0d28dd8
Update
psfinaki Aug 23, 2022
c50a87f
works
psfinaki Aug 23, 2022
6bec617
Update
psfinaki Aug 23, 2022
48188af
Update
psfinaki Aug 23, 2022
292e59b
Update
psfinaki Aug 23, 2022
f5c0620
Update
psfinaki Aug 23, 2022
f3f3a74
Update
psfinaki Aug 23, 2022
e8dd34c
Update ConsoleOnlyOptionsTests.fs
psfinaki Aug 23, 2022
0e5bfbb
Merge branch 'main' into psfinaki/13748
psfinaki Aug 23, 2022
0e18d25
Update
psfinaki Aug 24, 2022
feb030c
Fantomas
psfinaki Aug 24, 2022
a642270
Update
psfinaki Aug 24, 2022
4459daf
Update CompilerOptions.fs
psfinaki Aug 24, 2022
19dc57f
Update
psfinaki Aug 24, 2022
ebf1e2b
Update
psfinaki Aug 24, 2022
6a845fb
Update
psfinaki Aug 24, 2022
ef9080f
Merge branch 'psfinaki/13748' of https://github.com/dotnet/fsharp int…
psfinaki Aug 24, 2022
3f8bb8b
Update CompilerOptions.fs
psfinaki Aug 24, 2022
76a3a70
Update
psfinaki Aug 24, 2022
0e76306
Update
psfinaki Aug 24, 2022
43a09aa
update
psfinaki Aug 24, 2022
4a391b0
Update
psfinaki Aug 24, 2022
357f39d
update
psfinaki Aug 24, 2022
d41514f
Update
psfinaki Aug 24, 2022
51bfe7b
Update CompilerOptions.fs
psfinaki Aug 24, 2022
59a46d8
Update
psfinaki Aug 24, 2022
acea454
Update
psfinaki Aug 24, 2022
a4790bc
Update CompilerOptions.fs
psfinaki Aug 24, 2022
fe633fc
Update CompilerOptions.fs
psfinaki Aug 24, 2022
5945c45
Update
psfinaki Aug 24, 2022
b8b63c1
Update
psfinaki Aug 24, 2022
0348630
Update TestHelpers.fs
psfinaki Aug 24, 2022
b434bc6
Update
psfinaki Aug 24, 2022
d971f28
Update FSharp.Compiler.Service.Tests.fsproj
psfinaki Aug 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 58 additions & 28 deletions src/Compiler/Driver/CompilerOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ open FSharp.Compiler.TypedTreeOps
open FSharp.Compiler.DiagnosticsLogger

open Internal.Utilities
open System.Text

module Attributes =
open System.Runtime.CompilerServices
Expand Down Expand Up @@ -111,7 +112,11 @@ 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 nl = Environment.NewLine

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

Expand All @@ -130,18 +135,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)
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
printfn "" (* newline *)
printf "%-40s %s" "" (*<--flags*) word
let _ = sb.Append $"{nl}"
let _ = sb.Append $"{String.Empty, -40} {word}"
flagWidth + 1 + word.Length
else
printf " %s" word
let _ = sb.Append $" {word}"
column + 1 + word.Length

let words =
Expand All @@ -150,16 +155,19 @@ let PrintCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOp
| Some s -> s.Split [| ' ' |]

let _finalColumn = Array.fold printWord flagWidth words
printfn "" (* newline *)
let _ = sb.Append $"{nl}"
sb.ToString()

let PrintPublicOptions (heading, opts) =
let getPublicOptions (heading, opts) =
if not (isNil opts) then
printfn ""
printfn ""
printfn "\t\t%s" heading
List.iter PrintCompilerOption opts
$"{nl}{nl}\t\t{heading}{nl}"
+ (opts |> List.map getCompilerOption |> String.concat "")
else
""

let GetCompilerOptionBlocks blocks =
let sb = new StringBuilder()

let PrintCompilerOptionBlocks blocks =
let publicBlocks =
blocks
|> List.choose (function
Expand All @@ -173,10 +181,11 @@ let PrintCompilerOptionBlocks blocks =
let headingOptions =
publicBlocks |> List.filter (fun (h2, _) -> heading = h2) |> List.collect snd

PrintPublicOptions(heading, headingOptions)
let _ = sb.Append(getPublicOptions (heading, headingOptions))
Set.add heading doneHeadings

List.fold consider Set.empty publicBlocks |> ignore<Set<string>>
sb.ToString()

(* For QA *)
let dumpCompilerOption prefix (CompilerOption (str, _, spec, _, _)) =
Expand Down Expand Up @@ -1972,31 +1981,46 @@ let deprecatedFlagsFsc tcConfigB =
// OptionBlock: Miscellaneous options
//-----------------------------------

let DisplayBannerText tcConfigB =
let GetBannerText tcConfigB =
if tcConfigB.showBanner then
(printfn "%s" tcConfigB.productNameForBannerText
printfn "%s" (FSComp.SR.optsCopyright ()))
$"{tcConfigB.productNameForBannerText}{nl}"
+ $"{FSComp.SR.optsCopyright ()}{nl}"
else
""

/// FSC only help. (FSI has it's own help function).
let displayHelpFsc tcConfigB (blocks: CompilerOptionBlock list) =
DisplayBannerText tcConfigB
PrintCompilerOptionBlocks blocks
exit 0
let GetHelpFsc tcConfigB (blocks: CompilerOptionBlock list) =
GetBannerText tcConfigB + GetCompilerOptionBlocks blocks

let displayVersion tcConfigB =
printfn "%s" tcConfigB.productNameForBannerText
exit 0
let GetVersion tcConfigB =
$"{tcConfigB.productNameForBannerText}{nl}"

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 _ ->
Console.Write(GetVersion tcConfigB)
exit 0),
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 ->
Console.Write(GetHelpFsc tcConfigB blocks)
exit 0),
None,
Some(FSComp.SR.optsHelp ())
)
CompilerOption("@<file>", tagNone, OptionUnit ignore, None, Some(FSComp.SR.optsResponseFile ()))
]

Expand Down Expand Up @@ -2052,23 +2076,29 @@ let abbreviatedFlagsFsc tcConfigB =
CompilerOption(
"?",
tagNone,
OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks),
OptionConsoleOnly(fun blocks ->
Console.Write(GetHelpFsc tcConfigB blocks)
exit 0),
None,
Some(FSComp.SR.optsShortFormOf ("--help"))
)

CompilerOption(
"help",
tagNone,
OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks),
OptionConsoleOnly(fun blocks ->
Console.Write(GetHelpFsc tcConfigB blocks)
exit 0),
None,
Some(FSComp.SR.optsShortFormOf ("--help"))
)

CompilerOption(
"full-help",
tagNone,
OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks),
OptionConsoleOnly(fun blocks ->
Console.Write(GetHelpFsc tcConfigB blocks)
exit 0),
None,
Some(FSComp.SR.optsShortFormOf ("--help"))
)
Expand Down
8 changes: 6 additions & 2 deletions src/Compiler/Driver/CompilerOptions.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ and CompilerOptionBlock =
| PublicOptions of heading: string * options: CompilerOption list
| PrivateOptions of options: CompilerOption list

val PrintCompilerOptionBlocks: CompilerOptionBlock list -> unit // for printing usage
val GetCompilerOptionBlocks: CompilerOptionBlock list -> string

val DumpCompilerOptionBlocks: CompilerOptionBlock list -> unit // for QA

Expand All @@ -52,7 +52,11 @@ 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 GetBannerText: tcConfigB: TcConfigBuilder -> string

val GetHelpFsc: tcConfigB: TcConfigBuilder -> blocks: CompilerOptionBlock list -> string

val GetVersion: tcConfigB: TcConfigBuilder -> string

val GetCoreFscCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ let main1

// Display the banner text, if necessary
if not bannerAlreadyPrinted then
DisplayBannerText tcConfigB
Console.Write(GetBannerText tcConfigB)

// Create tcGlobals and frameworkTcImports
let outfile, pdbfile, assemblyName =
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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.Write (GetBannerText tcConfigB)
fprintfn fsiConsoleOutput.Out ""
fprintfn fsiConsoleOutput.Out "%s" (FSIstrings.SR.fsiUsage(executableFileNameWithoutExtension.Value))
PrintCompilerOptionBlocks blocks
Console.Write (GetCompilerOptionBlocks blocks)
exit 0

// option tags
Expand Down
31 changes: 31 additions & 0 deletions tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

module FSharp.Compiler.Service.Tests.ConsoleOnlyOptionsTests

open System
open System.IO
open FSharp.Compiler.CompilerOptions
open NUnit.Framework
open TestDoubles

[<Test>]
let ``Help is displayed correctly`` () =
let builder = getArbitraryTcConfigBuilder()
let blocks = GetCoreFscCompilerOptions builder
let expectedHelp = File.ReadAllText $"{__SOURCE_DIRECTORY__}/expected-help-output.txt"

let help = GetHelpFsc builder blocks

// 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.Replace("\r\n", Environment.NewLine))

[<Test>]
let ``Version is displayed correctly`` () =
let builder = getArbitraryTcConfigBuilder()
let expectedVersionPattern = @"Microsoft \(R\) F# Compiler version \d+\.\d+\.\d+\.\d+ for F# \d+\.\d+"

let version = GetVersion builder

Assert.That(version, Does.Match expectedVersionPattern)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
</PropertyGroup>

<ItemGroup>
<Content Include="expected-help-output.txt">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<Compile Include="..\fsharp\TestHelpers.fs" Link="TestHelpers.fs" />
<Compile Include="LibraryTestFx.fs" />
<Compile Include="SurfaceArea.netstandard.fs" />
Expand All @@ -38,6 +41,8 @@
<Compile Include="..\service\Symbols.fs">
<Link>Symbols.fs</Link>
</Compile>
<Compile Include="TestDoubles.fs" />
<Compile Include="ConsoleOnlyOptionsTests.fs" />
<Compile Include="VisualStudioVersusConsoleContextTests.fs" />
<Compile Include="..\service\SyntaxTreeTests\TypeTests.fs">
<Link>SyntaxTree\TypeTests.fs</Link>
Expand Down
23 changes: 23 additions & 0 deletions tests/FSharp.Compiler.Service.Tests/TestDoubles.fs
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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 TestDoubles

// copypasted from the CompilerOptions code,
// not worth changing that code's accessibility just for this test
Expand All @@ -23,17 +19,7 @@ let private getOptionsFromOptionBlocks blocks =
[<Test>] // 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
Expand Down
Loading