Skip to content

Commit 620269f

Browse files
committed
Bump version to 5.0.0-alpha018
1 parent 22f2d97 commit 620269f

File tree

4 files changed

+71
-44
lines changed

4 files changed

+71
-44
lines changed

RELEASE_NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#### 5.0.0-alpha018 - 24.09.2017
2+
* BUGFIX: Cache loaded assemblies and redirect later calls.
3+
14
#### 5.0.0-alpha017 - 23.09.2017
25
* BUGFIX: try to fallback to load framework assemblies from the default AssemblyLoadContext.
36

build.fsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,15 @@ Target.Create "ReleaseDocs" (fun _ ->
883883
open Fake.Api
884884

885885
Target.Create "FastRelease" (fun _ ->
886+
887+
Git.Staging.StageAll ""
888+
Git.Commit.Commit "" (sprintf "Bump version to %s" release.NugetVersion)
889+
let branch = Git.Information.getBranchName ""
890+
Git.Branches.pushBranch "" "origin" branch
891+
892+
Git.Branches.tag "" release.NugetVersion
893+
Git.Branches.pushTag "" "origin" release.NugetVersion
894+
886895
let token =
887896
match Environment.environVarOrDefault "github_token" "" with
888897
| s when not (System.String.IsNullOrWhiteSpace s) -> s
@@ -900,14 +909,6 @@ Target.Create "FastRelease" (fun _ ->
900909
draftWithFiles
901910
|> GitHub.releaseDraft
902911
|> Async.RunSynchronously
903-
904-
Git.Staging.StageAll ""
905-
Git.Commit.Commit "" (sprintf "Bump version to %s" release.NugetVersion)
906-
let branch = Git.Information.getBranchName ""
907-
Git.Branches.pushBranch "" "origin" branch
908-
909-
Git.Branches.tag "" release.NugetVersion
910-
Git.Branches.pushTag "" "origin" release.NugetVersion
911912
)
912913

913914
open System

src/app/Fake.Core.Targets/Target.fs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ module Target =
219219
/// Represents build errors
220220
type BuildError = {
221221
Target : string
222-
Message : string }
222+
Error : exn }
223223

224224
//let mutable private errors = []
225225
let private errorsVar = "Fake.Core.Targets.errors"
@@ -240,7 +240,7 @@ module Target =
240240
//| BuildException(msg, errs) ->
241241
// let errMsgs = errs |> List.map(fun e -> { Target = targetName; Message = e })
242242
// { Target = targetName; Message = msg } :: (errMsgs @ errors)
243-
| _ -> { Target = targetName; Message = exn.ToString() } :: GetErrors())
243+
| _ -> { Target = targetName; Error = exn } :: GetErrors())
244244
let error e =
245245
match e with
246246
//| BuildException(msg, errs) -> msg + (if PrintStackTraceOnError then Environment.NewLine + e.StackTrace.ToString() else "")
@@ -291,7 +291,7 @@ module Target =
291291
|> Seq.map (fun kv -> kv.Key)
292292
|> Seq.iter (fun name ->
293293
try
294-
let watch = new System.Diagnostics.Stopwatch()
294+
let watch = System.Diagnostics.Stopwatch()
295295
watch.Start()
296296
Trace.tracefn "Starting BuildFailureTarget: %s" name
297297
let target = Get name
@@ -370,7 +370,7 @@ module Target =
370370
let internal WriteErrors () =
371371
Trace.traceLine()
372372
GetErrors()
373-
|> Seq.mapi(fun i e -> sprintf "%3d) %s" (i + 1) e.Message)
373+
|> Seq.mapi(fun i e -> sprintf "%3d) %s" (i + 1) e.Error.Message)
374374
|> Seq.iter Trace.traceError
375375

376376
/// <summary>Writes a build time report.</summary>
@@ -541,8 +541,13 @@ module Target =
541541

542542
match GetErrors() with
543543
| [] -> ()
544-
| errors -> failwithf "A target failed: %A" errors
545-
544+
| errors ->
545+
let targets = errors |> Seq.map (fun e -> e.Target) |> Seq.distinct
546+
let targetStr = String.Join(", ", targets)
547+
AggregateException(
548+
sprintf "Targets '%s' failed." targetStr,
549+
errors |> Seq.map (fun e -> e.Error))
550+
|> raise
546551
/// Registers a BuildFailureTarget (not activated).
547552
let BuildFailureTarget name body =
548553
Create name body

src/app/Fake.Runtime/CoreCache.fs

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ let loadAssembly (loadContext:AssemblyLoadContext) printDetails (assemInfo:Assem
199199
if printDetails then tracefn "Unable to find assembly %A. (Error: %O)" assemInfo ex
200200
None
201201

202+
202203
let findAndLoadInRuntimeDeps (loadContext:AssemblyLoadContext) (name:AssemblyName) printDetails (runtimeDependencies:AssemblyInfo list) =
203204
let strName = name.FullName
204205
if printDetails then tracefn "Trying to resolve: %s" strName
@@ -219,33 +220,43 @@ let findAndLoadInRuntimeDeps (loadContext:AssemblyLoadContext) (name:AssemblyNam
219220
| Some a ->
220221
a.FullName = strName, (Some (None, a))
221222
| None ->
222-
match runtimeDependencies |> List.tryFind (fun r -> r.FullName = strName) with
223-
| Some a ->
224-
true, loadAssembly loadContext printDetails a
225-
| _ ->
226-
let token = name.GetPublicKeyToken()
227-
match runtimeDependencies
228-
|> Seq.map (fun r -> AssemblyName(r.FullName), r)
229-
|> Seq.tryFind (fun (n, _) ->
230-
n.Name = name.Name &&
231-
(isNull token || // When null accept what we have.
232-
n.GetPublicKeyToken() = token)) with
233-
| Some (otherName, info) ->
234-
// Then the version matches and the public token is null we still accept this as perfect match
235-
(isNull token && otherName.Version = name.Version), loadAssembly loadContext printDetails info
236-
| _ ->
237223
#if NETSTANDARD1_6
238-
// One last option is to try and load from the default app-context...
239-
try let assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(name)
224+
// Check if we can resolve to a framework assembly.
225+
let result =
226+
try let assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(name)
227+
let isFramework =
228+
assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
229+
|> Seq.exists (fun m -> m.Key = ".NETFrameworkAssembly")
230+
if not isFramework then
231+
None
232+
else
240233
let location =
241234
try Some assembly.Location
242235
with e ->
243236
if printDetails then tracefn "Could not get Location from '%s': %O" strName e
244237
None
245-
true, Some (location, assembly)
246-
with e ->
247-
if printDetails then tracefn "Could not find assembly in the default load-context: %s" strName
238+
Some (location, assembly)
239+
with e -> None
240+
match result with
241+
| Some r -> true, Some r
242+
| None ->
248243
#endif
244+
if printDetails then tracefn "Could not find assembly in the default load-context: %s" strName
245+
match runtimeDependencies |> List.tryFind (fun r -> r.FullName = strName) with
246+
| Some a ->
247+
true, loadAssembly loadContext printDetails a
248+
| _ ->
249+
let token = name.GetPublicKeyToken()
250+
match runtimeDependencies
251+
|> Seq.map (fun r -> AssemblyName(r.FullName), r)
252+
|> Seq.tryFind (fun (n, _) ->
253+
n.Name = name.Name &&
254+
(isNull token || // When null accept what we have.
255+
n.GetPublicKeyToken() = token)) with
256+
| Some (otherName, info) ->
257+
// Then the version matches and the public token is null we still accept this as perfect match
258+
(isNull token && otherName.Version = name.Version), loadAssembly loadContext printDetails info
259+
| _ ->
249260
false, None
250261
match result with
251262
| Some (location, a) ->
@@ -260,22 +271,29 @@ let findAndLoadInRuntimeDeps (loadContext:AssemblyLoadContext) (name:AssemblyNam
260271
if printDetails then tracefn "Could not resolve: %s" strName
261272
null
262273

274+
let findAndLoadInRuntimeDepsCached =
275+
let assemblyCache = System.Collections.Concurrent.ConcurrentDictionary<_,Assembly>()
276+
fun (loadContext:AssemblyLoadContext) (name:AssemblyName) printDetails (runtimeDependencies:AssemblyInfo list) ->
277+
let mutable wasCalled = false
278+
let result = assemblyCache.GetOrAdd(name.Name, (fun _ ->
279+
wasCalled <- true
280+
findAndLoadInRuntimeDeps loadContext name printDetails runtimeDependencies))
281+
if not wasCalled then
282+
let loadedName = result.GetName()
283+
let isPerfectMatch = loadedName.Name = name.Name && loadedName.Version = name.Version
284+
if not isPerfectMatch then
285+
traceFAKE "Redirect assembly from '%A' to previous loaded assembly '%A'" name loadedName
286+
else
287+
if printDetails then tracefn "Redirect assembly load to previously loaded assembly: %A" loadedName
288+
result
289+
263290
#if NETSTANDARD1_6
264291
// See https://github.com/dotnet/coreclr/issues/6411
265292
type FakeLoadContext (printDetails:bool, dependencies:AssemblyInfo list) =
266293
inherit AssemblyLoadContext()
267-
//let basePath = System.AppContext.BaseDirectory
268-
//let references =
269-
// System.IO.Directory.GetFiles(basePath, "*.dll")
270-
// |> Seq.filter (fun r -> not (System.IO.Path.GetFileName(r).ToLowerInvariant().StartsWith("api-ms")))
271-
// |> Seq.choose (fun r ->
272-
// try Some (AssemblyInfo.ofLocation r)
273-
// with e -> None)
274-
// |> Seq.toList
275-
//let allReferences = references @ dependencies
276294
let allReferences = dependencies
277295
override x.Load(assem:AssemblyName) =
278-
findAndLoadInRuntimeDeps x assem printDetails allReferences
296+
findAndLoadInRuntimeDepsCached x assem printDetails allReferences
279297
#endif
280298

281299
let fakeDirectoryName = ".fake"

0 commit comments

Comments
 (0)