Skip to content

Commit 2002675

Browse files
authored
remove outputDirectory from compile-time search paths for scripts (#1606)
* remove outputDirectory from compile-time search paths for scripts * remove code duplication * code cleanup
1 parent 2e5143a commit 2002675

File tree

6 files changed

+163
-234
lines changed

6 files changed

+163
-234
lines changed

src/fsharp/CompileOps.fs

Lines changed: 72 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,7 +2796,7 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
27962796
(sourceFiles |> List.mapi (fun i _ -> (i = n-1)), tcConfig.target.IsExe)
27972797

27982798
// This call can fail if no CLR is found (this is the path to mscorlib)
2799-
member tcConfig.ClrRoot =
2799+
member tcConfig.TargetFrameworkDirectories =
28002800
use unwindBuildPhase = PushThreadBuildPhaseUntilUnwind (BuildPhase.Parameter)
28012801
match tcConfig.clrRoot with
28022802
| Some x ->
@@ -2853,15 +2853,15 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
28532853
member tcConfig.IsSystemAssembly (filename:string) =
28542854
try
28552855
FileSystem.SafeExists filename &&
2856-
((tcConfig.ClrRoot |> List.exists (fun clrRoot -> clrRoot = Path.GetDirectoryName filename)) ||
2856+
((tcConfig.TargetFrameworkDirectories |> List.exists (fun clrRoot -> clrRoot = Path.GetDirectoryName filename)) ||
28572857
(systemAssemblies |> List.exists (fun sysFile -> sysFile = fileNameWithoutExtension filename)))
28582858
with _ ->
28592859
false
28602860

28612861
// This is not the complete set of search paths, it is just the set
28622862
// that is special to F# (as compared to MSBuild resolution)
28632863
member tcConfig.SearchPathsForLibraryFiles =
2864-
[ yield! tcConfig.ClrRoot
2864+
[ yield! tcConfig.TargetFrameworkDirectories
28652865
yield! List.map (tcConfig.MakePathAbsolute) tcConfig.includes
28662866
yield tcConfig.implicitIncludeDir
28672867
yield tcConfig.fsharpBinariesDir ]
@@ -2986,13 +2986,16 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
29862986
assemblyName, highestPosition, assemblyGroup)
29872987
|> Array.ofSeq
29882988

2989-
let logmessage showMessages =
2989+
let logMessage showMessages =
29902990
if showMessages && tcConfig.showReferenceResolutions then (fun (message:string)->dprintf "%s\n" message)
29912991
else ignore
29922992

2993-
let logwarning showMessages =
2994-
(fun code message->
2993+
let logErrorOrWarning showMessages =
2994+
(fun isError code message->
29952995
if showMessages && mode = ReportErrors then
2996+
if isError then
2997+
errorR(MSBuildReferenceResolutionError(code,message,errorAndWarningRange))
2998+
else
29962999
match code with
29973000
// These are warnings that mean 'not resolved' for some assembly.
29983001
// Note that we don't get to know the name of the assembly that couldn't be resolved.
@@ -3001,15 +3004,10 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
30013004
| "MSB3106"
30023005
-> ()
30033006
| _ ->
3004-
(if code = "MSB3245" then errorR else warning)
3005-
(MSBuildReferenceResolutionWarning(code,message,errorAndWarningRange)))
3006-
3007-
let logerror showMessages =
3008-
(fun code message ->
3009-
if showMessages && mode = ReportErrors then
3010-
errorR(MSBuildReferenceResolutionError(code,message,errorAndWarningRange)))
3011-
3012-
let targetFrameworkVersion = tcConfig.targetFrameworkVersion
3007+
if code = "MSB3245" then
3008+
errorR(MSBuildReferenceResolutionWarning(code,message,errorAndWarningRange))
3009+
else
3010+
warning(MSBuildReferenceResolutionWarning(code,message,errorAndWarningRange)))
30133011

30143012
let targetProcessorArchitecture =
30153013
match tcConfig.platform with
@@ -3018,13 +3016,6 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
30183016
| Some(AMD64) -> "amd64"
30193017
| Some(IA64) -> "ia64"
30203018

3021-
let outputDirectory =
3022-
match tcConfig.outputFile with
3023-
| Some(outputFile) -> tcConfig.MakePathAbsolute outputFile
3024-
| None -> tcConfig.implicitIncludeDir
3025-
3026-
let targetFrameworkDirectories = tcConfig.ClrRoot
3027-
30283019
// First, try to resolve everything as a file using simple resolution
30293020
let resolvedAsFile =
30303021
groupedReferences
@@ -3040,14 +3031,13 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
30403031
tcConfig.referenceResolver.Resolve
30413032
(tcConfig.resolutionEnvironment,
30423033
references,
3043-
targetFrameworkVersion,
3044-
targetFrameworkDirectories,
3034+
tcConfig.targetFrameworkVersion,
3035+
tcConfig.TargetFrameworkDirectories,
30453036
targetProcessorArchitecture,
3046-
Path.GetDirectoryName(outputDirectory),
30473037
tcConfig.fsharpBinariesDir, // FSharp binaries directory
30483038
tcConfig.includes, // Explicit include directories
30493039
tcConfig.implicitIncludeDir, // Implicit include directory (likely the project directory)
3050-
logmessage showMessages, logwarning showMessages, logerror showMessages)
3040+
logMessage showMessages, logErrorOrWarning showMessages)
30513041
with
30523042
ReferenceResolver.ResolutionFailure -> error(Error(FSComp.SR.buildAssemblyResolutionFailed(),errorAndWarningRange))
30533043

@@ -4246,38 +4236,25 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
42464236
let invalidateCcu = new Event<_>()
42474237
#endif
42484238

4249-
// Adjust where the code for known F# libraries live relative to the installation of F#
4250-
let codeDir =
4251-
let dir = minfo.compileTimeWorkingDir
4252-
let knownLibraryLocation = @"src\fsharp\" // Help highlighting... "
4253-
let knownLibarySuffixes =
4254-
[ @"FSharp.Core"
4255-
@"FSharp.PowerPack"
4256-
@"FSharp.PowerPack.Linq"
4257-
@"FSharp.PowerPack.Metadata" ]
4258-
match knownLibarySuffixes |> List.tryFind (fun x -> dir.EndsWith(knownLibraryLocation + x,StringComparison.OrdinalIgnoreCase)) with
4259-
| None ->
4260-
dir
4261-
| Some libSuffix ->
4262-
// add "..\lib\FSharp.Core" to the F# binaries directory
4263-
Path.Combine(Path.Combine(tcConfig.fsharpBinariesDir,@"..\lib"),libSuffix)
4264-
4265-
let ccu =
4266-
CcuThunk.Create(ccuName, { ILScopeRef=ilScopeRef
4267-
Stamp = newStamp()
4268-
FileName = Some filename
4269-
QualifiedName= Some(ilScopeRef.QualifiedName)
4270-
SourceCodeDirectory = codeDir (* note: in some cases we fix up this information later *)
4271-
IsFSharp=true
4272-
Contents = mspec
4239+
let codeDir = minfo.compileTimeWorkingDir
4240+
let ccuData : CcuData =
4241+
{ ILScopeRef=ilScopeRef
4242+
Stamp = newStamp()
4243+
FileName = Some filename
4244+
QualifiedName= Some(ilScopeRef.QualifiedName)
4245+
SourceCodeDirectory = codeDir (* note: in some cases we fix up this information later *)
4246+
IsFSharp=true
4247+
Contents = mspec
42734248
#if EXTENSIONTYPING
4274-
InvalidateEvent=invalidateCcu.Publish
4275-
IsProviderGenerated = false
4276-
ImportProvidedType = (fun ty -> Import.ImportProvidedType (tcImports.GetImportMap()) m ty)
4249+
InvalidateEvent=invalidateCcu.Publish
4250+
IsProviderGenerated = false
4251+
ImportProvidedType = (fun ty -> Import.ImportProvidedType (tcImports.GetImportMap()) m ty)
42774252
#endif
4278-
UsesFSharp20PlusQuotations = minfo.usesQuotations
4279-
MemberSignatureEquality= (fun ty1 ty2 -> Tastops.typeEquivAux EraseAll (tcImports.GetTcGlobals()) ty1 ty2)
4280-
TypeForwarders = ImportILAssemblyTypeForwarders(tcImports.GetImportMap,m, ilModule.GetRawTypeForwarders()) })
4253+
UsesFSharp20PlusQuotations = minfo.usesQuotations
4254+
MemberSignatureEquality= (fun ty1 ty2 -> Tastops.typeEquivAux EraseAll (tcImports.GetTcGlobals()) ty1 ty2)
4255+
TypeForwarders = ImportILAssemblyTypeForwarders(tcImports.GetImportMap,m, ilModule.GetRawTypeForwarders()) }
4256+
4257+
let ccu = CcuThunk.Create(ccuName, ccuData)
42814258

42824259
let optdata =
42834260
lazy
@@ -4292,15 +4269,15 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
42924269
Some res)
42934270
let ilg = defaultArg ilGlobalsOpt EcmaILGlobals
42944271
let ccuinfo =
4295-
{ FSharpViewOfMetadata=ccu
4296-
AssemblyAutoOpenAttributes = ilModule.GetAutoOpenAttributes(ilg)
4297-
AssemblyInternalsVisibleToAttributes = ilModule.GetInternalsVisibleToAttributes(ilg)
4298-
FSharpOptimizationData=optdata
4272+
{ FSharpViewOfMetadata=ccu
4273+
AssemblyAutoOpenAttributes = ilModule.GetAutoOpenAttributes(ilg)
4274+
AssemblyInternalsVisibleToAttributes = ilModule.GetInternalsVisibleToAttributes(ilg)
4275+
FSharpOptimizationData=optdata
42994276
#if EXTENSIONTYPING
4300-
IsProviderGenerated = false
4301-
TypeProviders = []
4277+
IsProviderGenerated = false
4278+
TypeProviders = []
43024279
#endif
4303-
ILScopeRef = ilScopeRef }
4280+
ILScopeRef = ilScopeRef }
43044281
let phase2() =
43054282
#if EXTENSIONTYPING
43064283
match ilModule.TryGetRawILModule() with
@@ -4349,15 +4326,16 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
43494326
let phase2() = [tcImports.FindCcuInfo(m,ilShortAssemName,lookupOnly=true)]
43504327
dllinfo,phase2
43514328
else
4352-
let dllinfo = {RawMetadata=assemblyData
4353-
FileName=filename
4329+
let dllinfo =
4330+
{ RawMetadata=assemblyData
4331+
FileName=filename
43544332
#if EXTENSIONTYPING
4355-
ProviderGeneratedAssembly=None
4356-
IsProviderGenerated=false
4357-
ProviderGeneratedStaticLinkMap = None
4333+
ProviderGeneratedAssembly=None
4334+
IsProviderGenerated=false
4335+
ProviderGeneratedStaticLinkMap = None
43584336
#endif
4359-
ILScopeRef = ilScopeRef
4360-
ILAssemblyRefs = assemblyData.ILAssemblyRefs }
4337+
ILScopeRef = ilScopeRef
4338+
ILAssemblyRefs = assemblyData.ILAssemblyRefs }
43614339
tcImports.RegisterDll(dllinfo)
43624340
let ilg = defaultArg ilGlobalsOpt EcmaILGlobals
43634341
let phase2 =
@@ -5159,26 +5137,31 @@ type TcState =
51595137
tcsTcImplEnv = tcEnvAtEndOfLastInput }
51605138

51615139

5140+
/// Create the initial type checking state for compiling an assembly
51625141
let GetInitialTcState(m,ccuName,tcConfig:TcConfig,tcGlobals,tcImports:TcImports,niceNameGen,tcEnv0) =
51635142
ignore tcImports
5143+
51645144
// Create a ccu to hold all the results of compilation
51655145
let ccuType = NewCcuContents ILScopeRef.Local m ccuName (NewEmptyModuleOrNamespaceType Namespace)
5166-
let ccu =
5167-
CcuThunk.Create(ccuName,{IsFSharp=true
5168-
UsesFSharp20PlusQuotations=false
5146+
5147+
let ccuData : CcuData =
5148+
{ IsFSharp=true
5149+
UsesFSharp20PlusQuotations=false
51695150
#if EXTENSIONTYPING
5170-
InvalidateEvent=(new Event<_>()).Publish
5171-
IsProviderGenerated = false
5172-
ImportProvidedType = (fun ty -> Import.ImportProvidedType (tcImports.GetImportMap()) m ty)
5151+
InvalidateEvent=(new Event<_>()).Publish
5152+
IsProviderGenerated = false
5153+
ImportProvidedType = (fun ty -> Import.ImportProvidedType (tcImports.GetImportMap()) m ty)
51735154
#endif
5174-
FileName=None
5175-
Stamp = newStamp()
5176-
QualifiedName= None
5177-
SourceCodeDirectory = tcConfig.implicitIncludeDir
5178-
ILScopeRef=ILScopeRef.Local
5179-
Contents=ccuType
5180-
MemberSignatureEquality= (Tastops.typeEquivAux EraseAll tcGlobals)
5181-
TypeForwarders=Map.empty })
5155+
FileName=None
5156+
Stamp = newStamp()
5157+
QualifiedName= None
5158+
SourceCodeDirectory = tcConfig.implicitIncludeDir
5159+
ILScopeRef=ILScopeRef.Local
5160+
Contents=ccuType
5161+
MemberSignatureEquality= (Tastops.typeEquivAux EraseAll tcGlobals)
5162+
TypeForwarders=Map.empty }
5163+
5164+
let ccu = CcuThunk.Create(ccuName,ccuData)
51825165

51835166
// OK, is this is the FSharp.Core CCU then fix it up.
51845167
if tcConfig.compilingFslib then
@@ -5196,7 +5179,7 @@ let GetInitialTcState(m,ccuName,tcConfig:TcConfig,tcGlobals,tcImports:TcImports,
51965179
tcsRootSigsAndImpls = RootSigsAndImpls (rootSigs, rootImpls, allSigModulTyp, allImplementedSigModulTyp) }
51975180

51985181

5199-
/// Typecheck a single file or interactive entry into F# Interactive
5182+
/// Typecheck a single file (or interactive entry into F# Interactive)
52005183
let TypeCheckOneInputEventually
52015184
(checkForErrors , tcConfig:TcConfig, tcImports:TcImports,
52025185
tcGlobals, prefixPathOpt, tcSink, tcState: TcState, inp: ParsedInput) =
@@ -5307,12 +5290,14 @@ let TypeCheckOneInputEventually
53075290
return (tcState.TcEnvFromSignatures,EmptyTopAttrs,[]),tcState
53085291
}
53095292

5293+
/// Typecheck a single file (or interactive entry into F# Interactive)
53105294
let TypeCheckOneInput (checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt) tcState inp =
53115295
// 'use' ensures that the warning handler is restored at the end
53125296
use unwindEL = PushErrorLoggerPhaseUntilUnwind(fun oldLogger -> GetErrorLoggerFilteringByScopedPragmas(false,GetScopedPragmasForInput(inp),oldLogger) )
53135297
use unwindBP = PushThreadBuildPhaseUntilUnwind (BuildPhase.TypeCheck)
53145298
TypeCheckOneInputEventually (checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, TcResultsSink.NoSink, tcState, inp) |> Eventually.force
53155299

5300+
/// Finish checking multiple files (or one interactive entry into F# Interactive)
53165301
let TypeCheckMultipleInputsFinish(results,tcState: TcState) =
53175302
let tcEnvsAtEndFile,topAttrs,mimpls = List.unzip3 results
53185303

@@ -5323,11 +5308,12 @@ let TypeCheckMultipleInputsFinish(results,tcState: TcState) =
53235308

53245309
(tcEnvAtEndOfLastFile,topAttrs,mimpls),tcState
53255310

5311+
/// Check multiple files (or one interactive entry into F# Interactive)
53265312
let TypeCheckMultipleInputs (checkForErrors, tcConfig: TcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, inputs) =
53275313
let results,tcState = (tcState, inputs) ||> List.mapFold (TypeCheckOneInput (checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt))
53285314
TypeCheckMultipleInputsFinish(results,tcState)
53295315

5330-
let TypeCheckSingleInputAndFinishEventually(checkForErrors, tcConfig: TcConfig, tcImports, tcGlobals, prefixPathOpt, tcSink, tcState, input) =
5316+
let TypeCheckOneInputAndFinishEventually(checkForErrors, tcConfig: TcConfig, tcImports, tcGlobals, prefixPathOpt, tcSink, tcState, input) =
53315317
eventually {
53325318
let! results,tcState = TypeCheckOneInputEventually(checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcSink, tcState, input)
53335319
return TypeCheckMultipleInputsFinish([results],tcState)

src/fsharp/CompileOps.fsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ type TcConfig =
507507

508508

509509
member ComputeLightSyntaxInitialStatus : string -> bool
510-
member ClrRoot : string list
510+
member TargetFrameworkDirectories : string list
511511
512512
/// Get the loaded sources that exist and issue a warning for the ones that don't
513513
member GetAvailableLoadedSources : unit -> (range*string) list
@@ -728,7 +728,7 @@ val TypeCheckClosedInputSetFinish : TypedImplFile list * TcState -> TcState * Ty
728728
val TypeCheckClosedInputSet :(unit -> bool) * TcConfig * TcImports * TcGlobals * Ast.LongIdent option * TcState * Ast.ParsedInput list -> TcState * TopAttribs * TypedImplFile list * TcEnv
729729

730730
/// Check a single input and finish the checking
731-
val TypeCheckSingleInputAndFinishEventually :
731+
val TypeCheckOneInputAndFinishEventually :
732732
(unit -> bool) * TcConfig * TcImports * TcGlobals * Ast.LongIdent option * NameResolution.TcResultsSink * TcState * Ast.ParsedInput
733733
-> Eventually<(TcEnv * TopAttribs * TypedImplFile list) * TcState>
734734

0 commit comments

Comments
 (0)