Skip to content

Commit af648f3

Browse files
KevinRansombaronfel
authored andcommitted
Merge pull request #8441 from dotnet/merges/master-to-feature/and-bang
Merge master to feature/and-bang
2 parents 5c9ba21 + de0637f commit af648f3

8 files changed

+248
-128
lines changed

src/fsharp/CompileOps.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5152,7 +5152,7 @@ module ScriptPreprocessClosure =
51525152
let tcConfigB = tcConfig.CloneOfOriginalBuilder
51535153
TcConfig.Create(tcConfigB, validate=false), nowarns
51545154

5155-
let FindClosureFiles(mainFile, _m, closureSources, origTcConfig:TcConfig, codeContext, lexResourceManager: Lexhelp.LexResourceManager) =
5155+
let FindClosureFiles(_mainFile, _m, closureSources, origTcConfig:TcConfig, codeContext, lexResourceManager: Lexhelp.LexResourceManager) =
51565156
let mutable tcConfig = origTcConfig
51575157

51585158
let observedSources = Observed()
@@ -5176,7 +5176,7 @@ module ScriptPreprocessClosure =
51765176
let inline snd3 (_, b, _) = b
51775177
let packageManagerTextLines = packageManagerLines |> List.map snd3
51785178

5179-
match DependencyManagerIntegration.resolve packageManager tcConfig.implicitIncludeDir mainFile scriptName m packageManagerTextLines with
5179+
match DependencyManagerIntegration.resolve packageManager ".fsx" m packageManagerTextLines with
51805180
| None -> () // error already reported
51815181
| Some (succeeded, generatedScripts, additionalIncludeFolders) -> //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
51825182
// This may incrementally update tcConfig too with new #r references

src/fsharp/DependencyManager.Integration.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module ReflectionHelper =
6262
type internal IDependencyManagerProvider =
6363
abstract Name: string
6464
abstract Key: string
65-
abstract ResolveDependencies: scriptDir: string * mainScriptName: string * scriptName: string * packageManagerTextLines: string seq * tfm: string -> bool * string list * string list
65+
abstract ResolveDependencies: scriptExt: string * packageManagerTextLines: string seq * tfm: string -> bool * string list * string list
6666
abstract DependencyAdding: IEvent<string * string>
6767
abstract DependencyAdded: IEvent<string * string>
6868
abstract DependencyFailed: IEvent<string * string>
@@ -86,7 +86,7 @@ type ReflectionDependencyManagerProvider(theType: Type, nameProperty: PropertyIn
8686
match ReflectionHelper.getAttributeNamed theType dependencyManagerAttributeName,
8787
ReflectionHelper.getInstanceProperty<string> theType namePropertyName,
8888
ReflectionHelper.getInstanceProperty<string> theType keyPropertyName,
89-
ReflectionHelper.getInstanceMethod<bool * string list * string list> theType [| typeof<string>; typeof<string>; typeof<string>; typeof<string seq>; typeof<string> |] resolveDependenciesMethodName
89+
ReflectionHelper.getInstanceMethod<bool * string list * string list> theType [| typeof<string>; typeof<string seq>; typeof<string> |] resolveDependenciesMethodName
9090
with
9191
| None, _, _, _ -> None
9292
| _, None, _, _ -> None
@@ -98,13 +98,13 @@ type ReflectionDependencyManagerProvider(theType: Type, nameProperty: PropertyIn
9898
interface IDependencyManagerProvider with
9999
member __.Name = instance |> nameProperty
100100
member __.Key = instance |> keyProperty
101-
member this.ResolveDependencies(scriptDir, mainScriptName, scriptName, packageManagerTextLines, tfm) =
101+
member this.ResolveDependencies(scriptDir, packageManagerTextLines, tfm) =
102102
let key = (this :> IDependencyManagerProvider).Key
103103
let triggerEvent (evt: Event<string * string>) =
104104
for prLine in packageManagerTextLines do
105105
evt.Trigger(key, prLine)
106106
triggerEvent dependencyAddingEvent
107-
let arguments = [| box scriptDir; box mainScriptName; box scriptName; box packageManagerTextLines; box tfm |]
107+
let arguments = [| box scriptDir; box packageManagerTextLines; box tfm |]
108108
let succeeded, generatedScripts, additionalIncludeFolders = resolveDeps.Invoke(instance, arguments) :?> _
109109
if succeeded then triggerEvent dependencyAddedEvent
110110
else triggerEvent dependencyFailedEvent
@@ -191,9 +191,9 @@ let tryFindDependencyManagerByKey (compilerTools: string list) (outputDir:string
191191
errorR(Error(FSComp.SR.packageManagerError(e.Message), m))
192192
None
193193

194-
let resolve (packageManager:IDependencyManagerProvider) implicitIncludeDir mainScriptName fileName m packageManagerTextLines =
194+
let resolve (packageManager:IDependencyManagerProvider) scriptExt m packageManagerTextLines =
195195
try
196-
Some(packageManager.ResolveDependencies(implicitIncludeDir, mainScriptName, fileName, packageManagerTextLines, executionTfm))
196+
Some(packageManager.ResolveDependencies(scriptExt, packageManagerTextLines, executionTfm))
197197
with e ->
198198
let e = ReflectionHelper.stripTieWrapper e
199199
errorR(Error(FSComp.SR.packageManagerError(e.Message), m))

src/fsharp/DependencyManager.Integration.fsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open FSharp.Compiler.Range
88
type IDependencyManagerProvider =
99
abstract Name: string
1010
abstract Key: string
11-
abstract ResolveDependencies: scriptDir: string * mainScriptName: string * scriptName: string * packageManagerTextLines: string seq * tfm: string -> bool * string list * string list
11+
abstract ResolveDependencies: scriptExt: string * packageManagerTextLines: string seq * tfm: string -> bool * string list * string list
1212
abstract DependencyAdding: IEvent<string * string>
1313
abstract DependencyAdded: IEvent<string * string>
1414
abstract DependencyFailed: IEvent<string * string>
@@ -23,4 +23,4 @@ val tryFindDependencyManagerInPath: string list -> string option -> range -> str
2323
val tryFindDependencyManagerByKey: string list -> string option -> range -> string -> IDependencyManagerProvider option
2424
val removeDependencyManagerKey: string -> string -> string
2525
val createPackageManagerUnknownError: string list -> string option -> string -> range -> exn
26-
val resolve: IDependencyManagerProvider -> string -> string -> string -> range -> string seq -> (bool * string list * string list) option
26+
val resolve: IDependencyManagerProvider -> string -> range -> string seq -> (bool * string list * string list) option
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
namespace FSharp.DependencyManager
3+
4+
open System
5+
open System.Collections
6+
open System.Collections.Generic
7+
open System.Diagnostics
8+
open System.IO
9+
open System.Reflection
10+
open System.Runtime.CompilerServices
11+
open System.Runtime.Versioning
12+
13+
open Internal.Utilities.FSharpEnvironment
14+
15+
// Package reference information
16+
type PackageReference = {
17+
Include:string
18+
Version:string
19+
RestoreSources:string
20+
Script:string }
21+
22+
23+
// Resolved assembly information
24+
type Resolution = {
25+
NugetPackageId : string
26+
NugetPackageVersion : string
27+
PackageRoot : string
28+
FullPath : string
29+
IsNotImplementationReference: string
30+
NativePath : string
31+
AppHostRuntimeIdentifier : string
32+
InitializeSourcePath : string }
33+
34+
35+
module ProjectFile =
36+
37+
let findLoadsFromResolutions (resolutions:Resolution array) =
38+
resolutions
39+
|> Array.filter(fun r -> not(String.IsNullOrEmpty(r.NugetPackageId) ||
40+
String.IsNullOrEmpty(r.InitializeSourcePath)) &&
41+
File.Exists(r.InitializeSourcePath))
42+
|> Array.map(fun r -> r.InitializeSourcePath)
43+
|> Array.distinct
44+
45+
let findIncludesFromResolutions (resolutions:Resolution array) =
46+
let managedRoots =
47+
resolutions
48+
|> Array.filter(fun r -> not(String.IsNullOrEmpty(r.NugetPackageId) ||
49+
String.IsNullOrEmpty(r.PackageRoot)) &&
50+
Directory.Exists(r.PackageRoot))
51+
|> Array.map(fun r -> r.PackageRoot)
52+
|> Array.distinct
53+
54+
let nativeRoots =
55+
resolutions
56+
|> Array.filter(fun r -> not(String.IsNullOrEmpty(r.NugetPackageId) ||
57+
String.IsNullOrEmpty(r.NativePath)) &&
58+
Directory.Exists(r.NativePath))
59+
|> Array.map(fun r -> r.NativePath)
60+
|> Array.distinct
61+
62+
Array.concat [|managedRoots; nativeRoots|]
63+
64+
let getResolutionsFromFile resolutionsFile =
65+
66+
let lines =
67+
try
68+
File.ReadAllText(resolutionsFile).Split([| '\r'; '\n'|], StringSplitOptions.None)
69+
|> Array.filter(fun line -> not(String.IsNullOrEmpty(line)))
70+
with
71+
| _ -> [||]
72+
73+
[| for line in lines do
74+
let fields = line.Split(',')
75+
if fields.Length < 8 then raise (new System.InvalidOperationException(sprintf "Internal error - Invalid resolutions file format '%s'" line))
76+
else {
77+
NugetPackageId = fields.[0]
78+
NugetPackageVersion = fields.[1]
79+
PackageRoot = fields.[2]
80+
FullPath = fields.[3]
81+
IsNotImplementationReference = fields.[4]
82+
InitializeSourcePath = fields.[5]
83+
NativePath = fields.[6]
84+
AppHostRuntimeIdentifier = fields.[7]
85+
}
86+
|]
87+
88+
let makeScriptFromResolutions (resolutions:Resolution array) poundRprefix =
89+
let expandReferences =
90+
resolutions
91+
|> Array.filter(fun r -> not(String.IsNullOrEmpty(r.NugetPackageId) ||
92+
String.IsNullOrEmpty(r.FullPath)) &&
93+
String.Compare(r.IsNotImplementationReference, "true", StringComparison.InvariantCultureIgnoreCase) <> 0 &&
94+
File.Exists(r.FullPath))
95+
|> Array.fold(fun acc r -> acc + poundRprefix + r.FullPath + "\"" + Environment.NewLine) ""
96+
97+
let projectTemplate ="""
98+
// Generated from #r "nuget:Package References"
99+
// ============================================
100+
//
101+
// DOTNET_HOST_PATH:(C:\Program Files\dotnet\dotnet.exe)
102+
// MSBuildSDKsPath:(C:\Program Files\dotnet\sdk\3.1.200-preview-014883\Sdks)
103+
// MSBuildExtensionsPath:(C:\Program Files\dotnet\sdk\3.1.200-preview-014883\)
104+
//
105+
// References
106+
//
107+
$(POUND_R)
108+
109+
"""
110+
projectTemplate.Replace("$(POUND_R)", expandReferences)
111+
112+
let generateProjectBody = """
113+
<Project Sdk='Microsoft.NET.Sdk'>
114+
115+
<PropertyGroup>
116+
<TargetFramework>$(TARGETFRAMEWORK)</TargetFramework>
117+
<IsPackable>false</IsPackable>
118+
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
119+
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
120+
121+
<!-- Temporary fix some sdks, shipped internally with broken parameterization -->
122+
<FSharpCoreImplicitPackageVersion Condition="'$(FSharpCoreImplicitPackageVersion)' == '{{FSharpCoreShippedPackageVersion}}'">4.7.0</FSharpCoreImplicitPackageVersion>
123+
<FSharpCoreImplicitPackageVersion Condition="'$(FSharpCoreImplicitPackageVersion)' == '{{FSharpCorePreviewPackageVersion}}'">4.7.1-*</FSharpCoreImplicitPackageVersion>
124+
</PropertyGroup>
125+
126+
$(PACKAGEREFERENCES)
127+
128+
<Target Name="ComputePackageRootsForInteractivePackageManagement"
129+
DependsOnTargets="ResolveReferences;ResolveSdkReferences;ResolveTargetingPackAssets;ResolveSDKReferences;GenerateBuildDependencyFile">
130+
131+
<ItemGroup>
132+
<__InteractiveReferencedAssemblies Include = "@(ReferencePath)" />
133+
<__InteractiveReferencedAssembliesCopyLocal Include = "@(RuntimeCopyLocalItems)" Condition="'$(TargetFrameworkIdentifier)'!='.NETFramework'" />
134+
<__InteractiveReferencedAssembliesCopyLocal Include = "@(ReferenceCopyLocalPaths)" Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'" />
135+
<__ConflictsList Include="%(_ConflictPackageFiles.ConflictItemType)=%(_ConflictPackageFiles.Filename)%(_ConflictPackageFiles.Extension)" />
136+
</ItemGroup>
137+
138+
<PropertyGroup>
139+
<__Conflicts>@(__ConflictsList, ';');</__Conflicts>
140+
</PropertyGroup>
141+
142+
<ItemGroup>
143+
<InteractiveResolvedFile Include="@(__InteractiveReferencedAssemblies)"
144+
Condition="$([System.String]::new($(__Conflicts)).Contains($([System.String]::new('Reference=%(__InteractiveReferencedAssemblies.Filename)%(__InteractiveReferencedAssemblies.Extension);'))))"
145+
KeepDuplicates="false">
146+
<NormalizedIdentity Condition="'%(Identity)'!=''">$([System.String]::Copy('%(Identity)').Replace('\', '/'))</NormalizedIdentity>
147+
<NormalizedPathInPackage Condition="'%(__InteractiveReferencedAssemblies.PathInPackage)'!=''">$([System.String]::Copy('%(__InteractiveReferencedAssemblies.PathInPackage)').Replace('\', '/'))</NormalizedPathInPackage>
148+
<PositionPathInPackage Condition="'%(InteractiveResolvedFile.NormalizedPathInPackage)'!=''">$([System.String]::Copy('%(InteractiveResolvedFile.NormalizedIdentity)').IndexOf('%(InteractiveResolvedFile.NormalizedPathInPackage)'))</PositionPathInPackage>
149+
<PackageRoot Condition="'%(InteractiveResolvedFile.NormalizedPathInPackage)'!='' and '%(InteractiveResolvedFile.PositionPathInPackage)'!='-1'">$([System.String]::Copy('%(InteractiveResolvedFile.NormalizedIdentity)').Substring(0, %(InteractiveResolvedFile.PositionPathInPackage)))</PackageRoot>
150+
<InitializeSourcePath>%(InteractiveResolvedFile.PackageRoot)content\%(__InteractiveReferencedAssemblies.FileName)%(__InteractiveReferencedAssemblies.Extension)$(SCRIPTEXTENSION)</InitializeSourcePath>
151+
<IsNotImplementationReference>$([System.String]::Copy('%(__InteractiveReferencedAssemblies.PathInPackage)').StartsWith('ref/'))</IsNotImplementationReference>
152+
<NuGetPackageId>%(__InteractiveReferencedAssemblies.NuGetPackageId)</NuGetPackageId>
153+
<NuGetPackageVersion>%(__InteractiveReferencedAssemblies.NuGetPackageVersion)</NuGetPackageVersion>
154+
</InteractiveResolvedFile>
155+
156+
<InteractiveResolvedFile Include="@(__InteractiveReferencedAssembliesCopyLocal)" KeepDuplicates="false">
157+
<NormalizedIdentity Condition="'%(Identity)'!=''">$([System.String]::Copy('%(Identity)').Replace('\', '/'))</NormalizedIdentity>
158+
<NormalizedPathInPackage Condition="'%(__InteractiveReferencedAssembliesCopyLocal.PathInPackage)'!=''">$([System.String]::Copy('%(__InteractiveReferencedAssembliesCopyLocal.PathInPackage)').Replace('\', '/'))</NormalizedPathInPackage>
159+
<PositionPathInPackage Condition="'%(InteractiveResolvedFile.NormalizedPathInPackage)'!=''">$([System.String]::Copy('%(InteractiveResolvedFile.NormalizedIdentity)').IndexOf('%(InteractiveResolvedFile.NormalizedPathInPackage)'))</PositionPathInPackage>
160+
<PackageRoot Condition="'%(InteractiveResolvedFile.NormalizedPathInPackage)'!='' and '%(InteractiveResolvedFile.PositionPathInPackage)'!='-1'">$([System.String]::Copy('%(InteractiveResolvedFile.NormalizedIdentity)').Substring(0, %(InteractiveResolvedFile.PositionPathInPackage)))</PackageRoot>
161+
<InitializeSourcePath>%(InteractiveResolvedFile.PackageRoot)content\%(__InteractiveReferencedAssembliesCopyLocal.FileName)%(__InteractiveReferencedAssembliesCopyLocal.Extension)$(SCRIPTEXTENSION)</InitializeSourcePath>
162+
<IsNotImplementationReference>$([System.String]::Copy('%(__InteractiveReferencedAssembliesCopyLocal.PathInPackage)').StartsWith('ref/'))</IsNotImplementationReference>
163+
<NuGetPackageId>%(__InteractiveReferencedAssembliesCopyLocal.NuGetPackageId)</NuGetPackageId>
164+
<NuGetPackageVersion>%(__InteractiveReferencedAssembliesCopyLocal.NuGetPackageVersion)</NuGetPackageVersion>
165+
</InteractiveResolvedFile>
166+
167+
<NativeIncludeRoots
168+
Include="@(RuntimeTargetsCopyLocalItems)"
169+
Condition="'%(RuntimeTargetsCopyLocalItems.AssetType)' == 'native'">
170+
<Path>$([MSBuild]::EnsureTrailingSlash('$([System.String]::Copy('%(FullPath)').Substring(0, $([System.String]::Copy('%(FullPath)').LastIndexOf('runtimes'))))'))</Path>
171+
</NativeIncludeRoots>
172+
</ItemGroup>
173+
</Target>
174+
175+
<Target Name="InteractivePackageManagement"
176+
DependsOnTargets="ComputePackageRootsForInteractivePackageManagement"
177+
BeforeTargets="CoreCompile"
178+
AfterTargets="PrepareForBuild">
179+
180+
<ItemGroup>
181+
<ResolvedReferenceLines Remove='*' />
182+
<ResolvedReferenceLines Include='%(InteractiveResolvedFile.NugetPackageId),%(InteractiveResolvedFile.NugetPackageVersion),%(InteractiveResolvedFile.PackageRoot),%(InteractiveResolvedFile.FullPath),%(InteractiveResolvedFile.IsNotImplementationReference),%(InteractiveResolvedFile.InitializeSourcePath),%(NativeIncludeRoots.Path),$(AppHostRuntimeIdentifier)' KeepDuplicates="false" />
183+
</ItemGroup>
184+
185+
<WriteLinesToFile Lines='@(ResolvedReferenceLines)'
186+
File='$(MSBuildProjectFullPath).resolvedReferences.paths'
187+
Overwrite='True' WriteOnlyWhenDifferent='True' />
188+
</Target>
189+
190+
</Project>"""

0 commit comments

Comments
 (0)