Skip to content

Commit 1403751

Browse files
committed
CompilerTools switch initial implementation
1 parent d520c29 commit 1403751

File tree

13 files changed

+76
-30
lines changed

13 files changed

+76
-30
lines changed

src/fsharp/CompileOps.fs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,7 @@ type TcConfigBuilder =
20292029
mutable light: bool option
20302030
mutable conditionalCompilationDefines: string list
20312031
mutable loadedSources: (range * string) list
2032+
mutable compilerToolPaths: string list
20322033
mutable referencedDLLs: AssemblyReference list
20332034
mutable projectReferences: IProjectReference list
20342035
mutable knownUnresolvedReferences: UnresolvedAssemblyReference list
@@ -2193,6 +2194,7 @@ type TcConfigBuilder =
21932194
resolutionEnvironment = ResolutionEnvironment.EditingOrCompilation false
21942195
framework = true
21952196
implicitlyResolveAssemblies = true
2197+
compilerToolPaths = []
21962198
referencedDLLs = []
21972199
projectReferences = []
21982200
knownUnresolvedReferences = []
@@ -2424,6 +2426,13 @@ type TcConfigBuilder =
24242426
member tcConfigB.AddEmbeddedResource filename =
24252427
tcConfigB.embedResources <- tcConfigB.embedResources ++ filename
24262428

2429+
member tcConfigB.AddCompilerToolsByPath (m:range, path) =
2430+
if FileSystem.IsInvalidPathShim(path) then
2431+
warning(Error(FSComp.SR.buildInvalidAssemblyName(path), m))
2432+
elif not (tcConfigB.compilerToolPaths |> List.exists (fun text -> path = text)) then // NOTE: We keep same paths if range is different.
2433+
let compilerToolPath = tcConfigB.compilerToolPaths |> List.tryPick (fun text -> if text = path then Some text else None)
2434+
tcConfigB.compilerToolPaths <- tcConfigB.compilerToolPaths ++ (Option.defaultValue "" compilerToolPath) //AssemblyReference(m, path, projectReference)
2435+
24272436
member tcConfigB.AddReferencedAssemblyByPath (m, path) =
24282437
if FileSystem.IsInvalidPathShim path then
24292438
warning(Error(FSComp.SR.buildInvalidAssemblyName(path), m))
@@ -2682,6 +2691,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
26822691
member x.light = data.light
26832692
member x.conditionalCompilationDefines = data.conditionalCompilationDefines
26842693
member x.loadedSources = data.loadedSources
2694+
member x.compilerToolPaths = data.compilerToolPaths
26852695
member x.referencedDLLs = data.referencedDLLs
26862696
member x.knownUnresolvedReferences = data.knownUnresolvedReferences
26872697
member x.clrRoot = clrRootValue
@@ -4261,7 +4271,7 @@ and [<Sealed>] TcImports(tcConfigP: TcConfigProvider, initialResolutions: TcAsse
42614271
let providers =
42624272
[ for designTimeAssemblyName in designTimeAssemblyNames do
42634273
yield! ExtensionTyping.GetTypeProvidersOfAssembly(fileNameOfRuntimeAssembly, ilScopeRefOfRuntimeAssembly, designTimeAssemblyName, typeProviderEnvironment,
4264-
tcConfig.isInvalidationSupported, tcConfig.isInteractive, systemRuntimeContainsType, primaryAssemblyVersion, m) ]
4274+
tcConfig.isInvalidationSupported, tcConfig.isInteractive, systemRuntimeContainsType, primaryAssemblyVersion, tcConfig.compilerToolPaths, m) ]
42654275

42664276
// Note, type providers are disposable objects. The TcImports owns the provider objects - when/if it is disposed, the providers are disposed.
42674277
// We ignore all exceptions from provider disposal.
@@ -4545,7 +4555,6 @@ and [<Sealed>] TcImports(tcConfigP: TcConfigProvider, initialResolutions: TcAsse
45454555
member tcImports.RegisterAndImportReferencedAssemblies (ctok, nms: AssemblyResolution list) =
45464556
cancellable {
45474557
CheckDisposed()
4548-
45494558
let! results =
45504559
nms |> Cancellable.each (fun nm ->
45514560
cancellable {

src/fsharp/CompileOps.fsi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ type TcConfigBuilder =
272272
mutable conditionalCompilationDefines: string list
273273
/// Sources added into the build with #load
274274
mutable loadedSources: (range * string) list
275-
275+
mutable compilerToolPaths: string list
276276
mutable referencedDLLs: AssemblyReference list
277277
mutable projectReferences: IProjectReference list
278278
mutable knownUnresolvedReferences: UnresolvedAssemblyReference list
@@ -408,6 +408,7 @@ type TcConfigBuilder =
408408
member TurnWarningOff: range * string -> unit
409409
member TurnWarningOn: range * string -> unit
410410
member AddIncludePath: range * string * string -> unit
411+
member AddCompilerToolsByPath: range * string -> unit
411412
member AddReferencedAssemblyByPath: range * string -> unit
412413
member RemoveReferencedAssemblyByPath: range * string -> unit
413414
member AddEmbeddedSourceFile: string -> unit
@@ -441,6 +442,7 @@ type TcConfig =
441442
member conditionalCompilationDefines: string list
442443
member subsystemVersion: int * int
443444
member useHighEntropyVA: bool
445+
member compilerToolPaths: string list
444446
member referencedDLLs: AssemblyReference list
445447
member reduceMemoryUsage: ReduceMemoryFlag
446448
member inputCodePage: int option

src/fsharp/CompileOptions.fs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,18 @@ let PrintOptionInfo (tcConfigB:TcConfigBuilder) =
559559
// OptionBlock: Input files
560560
//-------------------------
561561

562-
let inputFileFlagsBoth (tcConfigB: TcConfigBuilder) =
562+
let inputFileFlagsBoth (tcConfigB : TcConfigBuilder) = [
563563
[ CompilerOption("reference", tagFile, OptionString (fun s -> tcConfigB.AddReferencedAssemblyByPath (rangeStartup, s)), None, Some (FSComp.SR.optsReference()))
564-
]
564+
CompilerOption("compilertool", tagFile, OptionString (fun s -> tcConfigB.AddCompilerToolsByPath (rangeStartup, s)), None, Some (FSComp.SR.optsCompilerTool()))
565+
566+
let referenceFlagAbbrev (tcConfigB : TcConfigBuilder) =
567+
CompilerOption("r", tagFile, OptionString (fun s -> tcConfigB.AddReferencedAssemblyByPath (rangeStartup, s)), None, Some(FSComp.SR.optsShortFormOf("--reference")))
568+
569+
let compilerToolFlagAbbrev (tcConfigB : TcConfigBuilder) =
570+
CompilerOption("t", tagFile, OptionString (fun s -> tcConfigB.AddCompilerToolsByPath (rangeStartup, s)), None, Some(FSComp.SR.optsShortFormOf("--compilertool")))
565571

566-
let inputFileFlagsFsc tcConfigB = inputFileFlagsBoth tcConfigB
572+
let inputFileFlagsFsi tcConfigB = inputFileFlagsBoth tcConfigB
573+
let inputFileFlagsFsc tcConfigB = inputFileFlagsBoth tcConfigB
567574

568575
let inputFileFlagsFsiBase (_tcConfigB: TcConfigBuilder) =
569576
#if NETSTANDARD

src/fsharp/CompileOptions.fsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ open FSharp.Compiler.TcGlobals
1212

1313
//----------------------------------------------------------------------------
1414
// Compiler Option Parser
15-
//--------------------------------------------------------------------------
15+
//----------------------------------------------------------------------------
1616

1717
// For command-line options that can be suffixed with +/-
1818
[<RequireQualifiedAccess>]
@@ -89,7 +89,7 @@ val NormalizeAssemblyRefs : CompilationThreadToken * TcImports -> (AbstractIL.IL
8989
// Miscellany
9090
val ignoreFailureOnMono1_1_16 : (unit -> unit) -> unit
9191
val mutable enableConsoleColoring : bool
92-
val DoWithColor : System.ConsoleColor -> (unit -> 'a) -> 'a
92+
val DoWithColor : ConsoleColor -> (unit -> 'a) -> 'a
9393
val DoWithErrorColor : bool -> (unit -> 'a) -> 'a
9494
val ReportTime : TcConfig -> string -> unit
9595
val GetAbbrevFlagSet : TcConfigBuilder -> bool -> Set<string>

src/fsharp/ExtensionTyping.fs

100755100644
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module internal ExtensionTyping =
6262

6363
/// Load a the design-time part of a type-provider into the host process, and look for types
6464
/// marked with the TypeProviderAttribute attribute.
65-
let GetTypeProviderImplementationTypes (runTimeAssemblyFileName, designTimeAssemblyNameString, m: range) =
65+
let GetTypeProviderImplementationTypes (runTimeAssemblyFileName, designTimeAssemblyNameString, m:range, compilerToolPaths:string list) =
6666

6767
// Report an error, blaming the particular type provider component
6868
let raiseError (e: exn) =
@@ -102,6 +102,17 @@ module internal ExtensionTyping =
102102

103103
let designTimeAssemblyOpt =
104104

105+
// If we've found a design-time assembly, look for the public types with TypeProviderAttribute
106+
107+
// ===========================================================================================
108+
// CompilerTools can also TypeProvider design time tools
109+
// TODO: Search xompilerToolPaths for designtime type provider
110+
// ===========================================================================================
111+
112+
ignore (compilerToolPaths)
113+
114+
// ===========================================================================================
115+
105116
if designTimeAssemblyNameString.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) then
106117
loadFromParentDirRelativeToRuntimeAssemblyLocation designTimeAssemblyNameString
107118
else
@@ -123,7 +134,6 @@ module internal ExtensionTyping =
123134
with e ->
124135
raiseError e
125136

126-
// If we've find a design-time assembly, look for the public types with TypeProviderAttribute
127137
match designTimeAssemblyOpt with
128138
| Some loadedDesignTimeAssembly ->
129139
try
@@ -194,7 +204,8 @@ module internal ExtensionTyping =
194204
isInteractive: bool,
195205
systemRuntimeContainsType : string -> bool,
196206
systemRuntimeAssemblyVersion : System.Version,
197-
m: range) =
207+
compilerToolPaths: string list,
208+
m:range) =
198209

199210
let providerSpecs =
200211
try
@@ -214,7 +225,7 @@ module internal ExtensionTyping =
214225
| Some designTimeAssemblyName, Some path when String.Compare(designTimeAssemblyName.Name, Path.GetFileNameWithoutExtension path, StringComparison.OrdinalIgnoreCase) = 0 ->
215226
()
216227
| Some _, _ ->
217-
for t in GetTypeProviderImplementationTypes (runTimeAssemblyFileName, designTimeAssemblyNameString, m) do
228+
for t in GetTypeProviderImplementationTypes (runTimeAssemblyFileName, designTimeAssemblyNameString, m, compilerToolPaths) do
218229
let resolver = CreateTypeProvider (t, runTimeAssemblyFileName, resolutionEnvironment, isInvalidationSupported, isInteractive, systemRuntimeContainsType, systemRuntimeAssemblyVersion, m)
219230
match box resolver with
220231
| null -> ()
@@ -223,7 +234,7 @@ module internal ExtensionTyping =
223234
() ]
224235

225236
with :? TypeProviderError as tpe ->
226-
tpe.Iter(fun e -> errorR(NumberedError((e.Number, e.ContextualErrorMessage), m)) )
237+
tpe.Iter(fun e -> errorR(NumberedError((e.Number, e.ContextualErrorMessage), m)) )
227238
[]
228239

229240
let providers = Tainted<_>.CreateAll providerSpecs

src/fsharp/ExtensionTyping.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ module internal ExtensionTyping =
5454
* isInteractive: bool
5555
* systemRuntimeContainsType : (string -> bool)
5656
* systemRuntimeAssemblyVersion : System.Version
57+
* compilerToolsPath : string list
5758
* range -> Tainted<ITypeProvider> list
5859

5960
/// Given an extension type resolver, supply a human-readable name suitable for error messages.

src/fsharp/FSComp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ optsNoOpt,"Only include optimization information essential for implementing inli
846846
optsNoInterface,"Don't add a resource to the generated assembly containing F#-specific metadata"
847847
optsSig,"Print the inferred interface of the assembly to a file"
848848
optsReference,"Reference an assembly (Short form: -r)"
849+
optsCompilerTool,"Reference an assembly or diretory containing a design time tool (Short form: -t)"
849850
optsWin32res,"Specify a Win32 resource file (.res)"
850851
optsWin32manifest,"Specify a Win32 manifest file"
851852
optsNowin32manifest,"Do not include the default Win32 manifest"

src/fsharp/FSharp.Build/Fsc.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type public Fsc () as this =
2727
let mutable checksumAlgorithm: string = null
2828
let mutable codePage : string = null
2929
let mutable commandLineArgs : ITaskItem list = []
30+
let mutable compilerTools: ITaskItem [] = [||]
3031
let mutable debugSymbols = false
3132
let mutable debugType : string = null
3233
let mutable defineConstants : ITaskItem[] = [||]
@@ -162,6 +163,12 @@ type public Fsc () as this =
162163

163164
// VersionFile
164165
builder.AppendSwitchIfNotNull("--versionfile:", versionFile)
166+
167+
// CompilerTools
168+
if compilerTools <> null then
169+
for item in compilerTools do
170+
builder.AppendSwitchIfNotNull("--compilertool:", item.ItemSpec)
171+
165172
// References
166173
if references <> null then
167174
for item in references do
@@ -276,6 +283,11 @@ type public Fsc () as this =
276283
with get() = codePage
277284
and set(s) = codePage <- s
278285

286+
// -r <string>: Reference an F# or .NET assembly.
287+
member fsc.CompilerTools
288+
with get() = compilerTools
289+
and set(a) = compilerTools <- a
290+
279291
// -g: Produce debug file. Disables optimizations if a -O flag is not given.
280292
member fsc.DebugSymbols
281293
with get() = debugSymbols

src/fsharp/FSharp.Build/Microsoft.FSharp.Targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ this file.
210210
@(CompileBefore);
211211
@(Compile);
212212
@(CompileAfter);
213+
@(CompilerToolsFscCompilerTools);
213214
@(_CoreCompileResourceInputs);
214215
@(ManifestNonResxWithNoCultureOnDisk);
215216
$(ApplicationIcon);
@@ -278,6 +279,7 @@ this file.
278279
BaseAddress="$(BaseAddress)"
279280
ChecksumAlgorithm="$(PdbChecksumAlgorithm)"
280281
CodePage="$(CodePage)"
282+
CompilerTools="$(FscCompilerTools)"
281283
DebugSymbols="$(DebugSymbols)"
282284
DebugType="$(DebugType)"
283285
DefineConstants="$(DefineConstants)"

tests/fsharpqa/Source/CompilerOptions/fsc/help/help40.437.1033.bsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ Copyright (c) Microsoft Corporation. All Rights Reserved.
4040

4141

4242
- INPUT FILES -
43-
--reference:<file> Reference an assembly (Short form:
44-
-r)
43+
--reference:<file> Reference an assembly (Short form: -r)
44+
--compilertool:<file> Reference an assembly or diretory containing a
45+
design time tool (Short form: -t)
4546

4647

4748
- RESOURCES -

0 commit comments

Comments
 (0)