@@ -51,6 +51,8 @@ open FSharp.Compiler.Text
51
51
52
52
open FSharp.Compiler .DotNetFrameworkDependencies
53
53
54
+ open Interactive.DependencyManager
55
+
54
56
#if ! NO_ EXTENSIONTYPING
55
57
open FSharp.Compiler .ExtensionTyping
56
58
open Microsoft.FSharp .Core .CompilerServices
@@ -2235,8 +2237,8 @@ type TcConfigBuilder =
2235
2237
mutable shadowCopyReferences: bool
2236
2238
mutable useSdkRefs: bool
2237
2239
2238
- /// A function to call to try to get an object that acts as a snapshot of the metadata section of a .NET binary,
2239
- /// and from which we can read the metadata. Only used when metadataOnly=true.
2240
+ /// A function to call to try to get an object that acts as a snapshot of the metadata section of a .NET binary,
2241
+ /// and from which we can read the metadata. Only used when metadataOnly=true.
2240
2242
mutable tryGetMetadataSnapshot: ILReaderTryGetMetadataSnapshot
2241
2243
2242
2244
mutable internalTestSpanStackReferring: bool
@@ -2246,6 +2248,8 @@ type TcConfigBuilder =
2246
2248
mutable pathMap: PathMap
2247
2249
2248
2250
mutable langVersion: LanguageVersion
2251
+
2252
+ mutable dependencyProvider: DependencyProvider
2249
2253
}
2250
2254
2251
2255
static member Initial =
@@ -2386,6 +2390,7 @@ type TcConfigBuilder =
2386
2390
noConditionalErasure = false
2387
2391
pathMap = PathMap.empty
2388
2392
langVersion = LanguageVersion( " default" )
2393
+ dependencyProvider = new DependencyProvider()
2389
2394
}
2390
2395
2391
2396
static member CreateNew ( legacyReferenceResolver , defaultFSharpBinariesDir , reduceMemoryUsage , implicitIncludeDir ,
@@ -2495,7 +2500,6 @@ type TcConfigBuilder =
2495
2500
if not ( List.contains path ( List.map ( fun ( _ , _ , path ) -> path) tcConfigB.loadedSources)) then
2496
2501
tcConfigB.loadedSources <- tcConfigB.loadedSources ++ ( m, originalPath, path)
2497
2502
2498
-
2499
2503
member tcConfigB.AddEmbeddedSourceFile ( file ) =
2500
2504
tcConfigB.embedSourceList <- tcConfigB.embedSourceList ++ file
2501
2505
@@ -2515,8 +2519,8 @@ type TcConfigBuilder =
2515
2519
let projectReference = tcConfigB.projectReferences |> List.tryPick ( fun pr -> if pr.FileName = path then Some pr else None)
2516
2520
tcConfigB.referencedDLLs <- tcConfigB.referencedDLLs ++ AssemblyReference( m, path, projectReference)
2517
2521
2518
- member tcConfigB.AddDependencyManagerText ( packageManager : DependencyManagerIntegration. IDependencyManagerProvider, m , path : string ) =
2519
- let path = DependencyManagerIntegration.removeDependencyManagerKey packageManager.Key path
2522
+ member tcConfigB.AddDependencyManagerText ( packageManager : IDependencyManagerProvider , m , path : string ) =
2523
+ let path = tcConfigB.dependencyProvider.RemoveDependencyManagerKey ( packageManager.Key, path)
2520
2524
2521
2525
match tcConfigB.packageManagerLines |> Map.tryFind packageManager.Key with
2522
2526
| Some lines -> tcConfigB.packageManagerLines <- Map.add packageManager.Key ( lines ++ ( false , path, m)) tcConfigB.packageManagerLines
@@ -2842,6 +2846,9 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
2842
2846
TcConfig( builder, validate)
2843
2847
2844
2848
member x.legacyReferenceResolver = data.legacyReferenceResolver
2849
+
2850
+ member x.dependencyProvider = data.dependencyProvider
2851
+
2845
2852
member tcConfig.CloneOfOriginalBuilder =
2846
2853
{ data with conditionalCompilationDefines= data.conditionalCompilationDefines }
2847
2854
@@ -4924,7 +4931,7 @@ let RequireDLL (ctok, tcImports: TcImports, tcEnv, thisAssemblyName, m, file) =
4924
4931
let ProcessMetaCommandsFromInput
4925
4932
( nowarnF : 'state -> range * string -> 'state ,
4926
4933
dllRequireF : 'state -> range * string -> 'state ,
4927
- packageRequireF : 'state -> DependencyManagerIntegration. IDependencyManagerProvider * range * string -> 'state ,
4934
+ packageRequireF : 'state -> IDependencyManagerProvider * range * string -> 'state ,
4928
4935
loadSourceF : 'state -> range * string -> unit )
4929
4936
( tcConfig : TcConfigBuilder , inp , pathOfMetaCommandSource , state0 ) =
4930
4937
@@ -4944,7 +4951,7 @@ let ProcessMetaCommandsFromInput
4944
4951
errorR( HashIncludeNotAllowedInNonScript m)
4945
4952
match args with
4946
4953
| [ path] ->
4947
- matchedm<- m
4954
+ matchedm <- m
4948
4955
tcConfig.AddIncludePath( m, path, pathOfMetaCommandSource)
4949
4956
state
4950
4957
| _ ->
@@ -4954,27 +4961,35 @@ let ProcessMetaCommandsFromInput
4954
4961
List.fold ( fun state d -> nowarnF state ( m, d)) state numbers
4955
4962
4956
4963
| ParsedHashDirective(( " reference" | " r" ), args, m) ->
4957
- if not canHaveScriptMetaCommands then
4958
- errorR( HashReferenceNotAllowedInNonScript m)
4964
+ if not canHaveScriptMetaCommands then
4965
+ errorR( HashReferenceNotAllowedInNonScript m)
4966
+
4967
+ let reportError errorType error =
4968
+ match errorType with
4969
+ | ErrorReportType.Warning -> warning( Error( error, m))
4970
+ | ErrorReportType.Error -> errorR( Error( error, m))
4971
+
4972
+ match args with
4973
+ | [ path] ->
4974
+ matchedm <- m
4975
+ let output = tcConfig.outputDir |> Option.defaultValue " "
4976
+ let dm = tcConfig.dependencyProvider.TryFindDependencyManagerInPath( tcConfig.compilerToolPaths, output , reportError, path)
4977
+ match dm with
4978
+ | dllpath, null when String.IsNullOrWhiteSpace( dllpath) ->
4979
+ state // error already reported
4980
+
4981
+ | _, dependencyManager when not ( isNull dependencyManager) ->
4982
+ if tcConfig.langVersion.SupportsFeature( LanguageFeature.PackageManagement) then
4983
+ packageRequireF state ( dependencyManager, m, path)
4984
+ else
4985
+ errorR( Error( FSComp.SR.packageManagementRequiresVFive(), m))
4986
+ state
4959
4987
4960
- match args with
4961
- | [ path] ->
4962
- matchedm <- m
4963
- match DependencyManagerIntegration.tryFindDependencyManagerInPath tcConfig.compilerToolPaths tcConfig.outputDir m ( path: string) with
4964
- | DependencyManagerIntegration.ReferenceType.RegisteredDependencyManager packageManager ->
4965
- if tcConfig.langVersion.SupportsFeature( LanguageFeature.PackageManagement) then
4966
- packageRequireF state ( packageManager, m, path)
4967
- else
4968
- errorR( Error( FSComp.SR.packageManagementRequiresVFive(), m))
4969
- state
4970
-
4971
- // #r "Assembly"
4972
- | DependencyManagerIntegration.ReferenceType.Library path ->
4973
- dllRequireF state ( m, path)
4974
-
4975
- | DependencyManagerIntegration.ReferenceType.UnknownType ->
4976
- state // error already reported
4977
- | _ ->
4988
+ // #r "Assembly"
4989
+ | path, _ ->
4990
+ dllRequireF state ( m, path)
4991
+
4992
+ | _ ->
4978
4993
errorR( Error( FSComp.SR.buildInvalidHashrDirective(), m))
4979
4994
state
4980
4995
@@ -5227,10 +5242,10 @@ module ScriptPreprocessClosure =
5227
5242
// Recover by using a default TcConfig.
5228
5243
let tcConfigB = tcConfig.CloneOfOriginalBuilder
5229
5244
TcConfig.Create( tcConfigB, validate= false ), nowarns
5230
-
5245
+
5231
5246
let FindClosureFiles ( mainFile , _m , closureSources , origTcConfig : TcConfig , codeContext , lexResourceManager : Lexhelp.LexResourceManager ) =
5232
5247
let mutable tcConfig = origTcConfig
5233
-
5248
+
5234
5249
let observedSources = Observed()
5235
5250
let loadScripts = HashSet<_>()
5236
5251
@@ -5242,41 +5257,43 @@ module ScriptPreprocessClosure =
5242
5257
match packageManagerLines with
5243
5258
| [] -> ()
5244
5259
| (_, _, m)::_ ->
5260
+ let reportError errorType error =
5261
+ match errorType with
5262
+ | ErrorReportType.Warning -> warning( Error( error, m))
5263
+ | ErrorReportType.Error -> errorR( Error( error, m))
5264
+
5245
5265
match origTcConfig.packageManagerLines |> Map.tryFind packageManagerKey with
5246
5266
| Some oldDependencyManagerLines when oldDependencyManagerLines = packageManagerLines -> ()
5247
5267
| _ ->
5248
- match DependencyManagerIntegration.tryFindDependencyManagerByKey tcConfig.compilerToolPaths tcConfig.outputDir m packageManagerKey with
5249
- | None ->
5250
- errorR( DependencyManagerIntegration.createPackageManagerUnknownError tcConfig.compilerToolPaths tcConfig.outputDir packageManagerKey m)
5251
- | Some packageManager ->
5268
+ let outputDir = tcConfig.outputDir |> Option.defaultValue " "
5269
+ match tcConfig.dependencyProvider.TryFindDependencyManagerByKey( tcConfig.compilerToolPaths, outputDir, reportError, packageManagerKey) with
5270
+ | null ->
5271
+ errorR( Error( tcConfig.dependencyProvider.CreatePackageManagerUnknownError( tcConfig.compilerToolPaths, outputDir, packageManagerKey, reportError), m))
5272
+
5273
+ | dependencyManager ->
5252
5274
let inline snd3 ( _ , b , _ ) = b
5253
5275
let packageManagerTextLines = packageManagerLines |> List.map snd3
5254
-
5255
- match DependencyManagerIntegration.resolve packageManager tcConfig.implicitIncludeDir mainFile scriptName " .fsx" m packageManagerTextLines with
5256
- | None -> () // error already reported
5257
- | Some ( succeeded, generatedScripts, additionalIncludeFolders) ->
5258
- // This may incrementally update tcConfig too with new #r references
5259
- // New package text is ignored on this second phase
5260
- match succeeded with
5261
- | true ->
5262
- // Resolution produced no errors
5263
- if not ( isNil additionalIncludeFolders) then
5264
- let tcConfigB = tcConfig.CloneOfOriginalBuilder
5265
- for folder in additionalIncludeFolders do
5266
- tcConfigB.AddIncludePath( m, folder, " " )
5267
- tcConfigB.packageManagerLines <- tcConfigB.packageManagerLines |> Map.map( fun _ l -> l |> List.map( fun ( _ , p , m ) -> true , p, m))
5268
- tcConfig <- TcConfig.Create( tcConfigB, validate= false )
5269
- for script in generatedScripts do
5270
- let scriptText = File.ReadAllText script
5271
- loadScripts.Add script |> ignore
5272
- let iSourceText = SourceText.ofString scriptText
5273
- yield ! loop ( ClosureSource( script, m, iSourceText, true ))
5274
- | false ->
5275
- // Resolution produced errors update packagerManagerLines entries to note these failure
5276
- // failed resolutions will no longer be considered
5276
+ match tcConfig.dependencyProvider.Resolve( dependencyManager, tcConfig.implicitIncludeDir, mainFile, scriptName, " .fsx" , packageManagerTextLines, reportError, executionTfm) with
5277
+ | true , _ references, generatedScripts, additionalIncludeFolders ->
5278
+ // Resolution produced no errors
5279
+ if not ( Seq.isEmpty additionalIncludeFolders) then
5277
5280
let tcConfigB = tcConfig.CloneOfOriginalBuilder
5278
- tcConfigB.packageManagerLines <- tcConfigB.packageManagerLines |> Map.map( fun _ l -> l |> List.filter( fun ( tried , _ , _ ) -> tried))
5279
- tcConfig <- TcConfig.Create( tcConfigB, validate= false )]
5281
+ for folder in additionalIncludeFolders do
5282
+ tcConfigB.AddIncludePath( m, folder, " " )
5283
+ tcConfigB.packageManagerLines <- tcConfigB.packageManagerLines |> Map.map( fun _ l -> l |> List.map( fun ( _ , p , m ) -> true , p, m))
5284
+ tcConfig <- TcConfig.Create( tcConfigB, validate= false )
5285
+ for script in generatedScripts do
5286
+ let scriptText = File.ReadAllText script
5287
+ loadScripts.Add script |> ignore
5288
+ let iSourceText = SourceText.ofString scriptText
5289
+ yield ! loop ( ClosureSource( script, m, iSourceText, true ))
5290
+
5291
+ | false , _, _, _ ->
5292
+ // Resolution produced errors update packagerManagerLines entries to note these failure
5293
+ // failed resolutions will no longer be considered
5294
+ let tcConfigB = tcConfig.CloneOfOriginalBuilder
5295
+ tcConfigB.packageManagerLines <- tcConfigB.packageManagerLines |> Map.map( fun _ l -> l |> List.filter( fun ( tried , _ , _ ) -> tried))
5296
+ tcConfig <- TcConfig.Create( tcConfigB, validate= false )]
5280
5297
else []
5281
5298
5282
5299
and loop ( ClosureSource ( filename , m , sourceText , parseRequired )) =
0 commit comments