Skip to content

Commit 807f239

Browse files
committed
Fixing issue with directive references in F#
1 parent f7ead60 commit 807f239

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

src/WebJobs.Script/Description/DotNet/FSharp/FSharpCompilation.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ImmutableArray<Diagnostic> GetDiagnostics()
4747

4848
public FunctionSignature GetEntryPointSignature(IFunctionEntryPointResolver entryPointResolver)
4949
{
50-
EnsureAssemblyOption();
50+
EnsureAssemblyOption(false);
5151

5252
// Scrape the compiled assembly for entry points
5353
IList<MethodReference<MethodInfo>> methods =
@@ -87,18 +87,11 @@ public Assembly EmitAndLoad(CancellationToken cancellationToken)
8787
return _assemblyOption.Value;
8888
}
8989

90-
private void EnsureAssemblyOption()
90+
private void EnsureAssemblyOption(bool includeDiagnostics = true)
9191
{
9292
if (_assemblyOption == null)
9393
{
94-
var diagnostics = this.GetDiagnostics();
95-
var diagnosticsText = new System.Text.StringBuilder();
96-
foreach (var diagostic in diagnostics)
97-
{
98-
diagnosticsText.Append(diagostic.ToString());
99-
}
100-
101-
throw new CompilationErrorException("Script compilation failed. " + diagnosticsText, this.GetDiagnostics());
94+
throw new CompilationErrorException("Script compilation failed.", includeDiagnostics ? this.GetDiagnostics() : ImmutableArray<Diagnostic>.Empty);
10295
}
10396
}
10497
}

src/WebJobs.Script/Description/DotNet/FSharp/FSharpCompilationService.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,13 @@ public ICompilation GetFunctionCompilation(FunctionMetadata functionMetadata)
114114
// as dictated by the C# reference resolver, and F# doesn't like getting multiple references to those.
115115
otherFlags.Add("--noframework");
116116

117-
var references = script.Options.MetadataReferences
118-
.Cast<UnresolvedMetadataReference>()
119-
.Aggregate(new List<PortableExecutableReference>(), (a, r) =>
120-
{
121-
a.AddRange(_metadataResolver.ResolveReference(r.Reference, string.Empty, r.Properties));
122-
return a;
123-
});
117+
var references = script.GetCompilation().References
118+
.Where(m => !(m is UnresolvedMetadataReference))
119+
.Select(m => "-r:" + m.Display)
120+
.Distinct(new FileNameEqualityComparer());
124121

125122
// Add the references as reported by the metadata resolver.
126-
otherFlags.AddRange(references.Select(r => "-r:" + r.Display));
123+
otherFlags.AddRange(references);
127124

128125
if (_optimizationLevel == OptimizationLevel.Debug)
129126
{
@@ -201,5 +198,33 @@ private static string GetFunctionSource(FunctionMetadata functionMetadata)
201198

202199
return code ?? string.Empty;
203200
}
201+
202+
private class FileNameEqualityComparer : IEqualityComparer<string>
203+
{
204+
public bool Equals(string x, string y)
205+
{
206+
if (string.Equals(x, y))
207+
{
208+
return true;
209+
}
210+
211+
if (string.IsNullOrEmpty(x) || string.IsNullOrEmpty(y))
212+
{
213+
return false;
214+
}
215+
216+
return string.Equals(Path.GetFileName(x), Path.GetFileName(y));
217+
}
218+
219+
public int GetHashCode(string obj)
220+
{
221+
if (string.IsNullOrEmpty(obj))
222+
{
223+
return 0;
224+
}
225+
226+
return Path.GetFileName(obj).GetHashCode();
227+
}
228+
}
204229
}
205230
}

0 commit comments

Comments
 (0)