From afbe69d00dc7f3d50a5d19fd4b8c913445ac9950 Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Mon, 21 Aug 2017 18:41:29 +0200 Subject: [PATCH] allow paket to omit similar warnings (ie group warnings). --- src/Paket.Core/Common/Logging.fs | 21 +++++++++++++++++++ src/Paket.Core/Common/Logging.fsi | 4 ++++ src/Paket.Core/Dependencies/NuGetCache.fs | 2 ++ src/Paket.Core/Dependencies/NuGetV2.fs | 2 +- src/Paket.Core/Dependencies/NuGetV3.fs | 2 +- src/Paket.Core/Dependencies/Nuspec.fs | 4 ++-- .../PackageManagement/NugetConvert.fs | 2 +- .../PaketConfigFiles/InstallModel.fs | 2 +- src/Paket.Core/Versioning/PlatformMatching.fs | 2 +- src/Paket/Paket.fsproj | 4 ++-- src/Paket/Program.fs | 3 +++ 11 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/Paket.Core/Common/Logging.fs b/src/Paket.Core/Common/Logging.fs index 945b9ed0f8..b584ea0d89 100644 --- a/src/Paket.Core/Common/Logging.fs +++ b/src/Paket.Core/Common/Logging.fs @@ -3,6 +3,8 @@ open System open System.IO open System.Diagnostics +open System.Collections.Concurrent +open System.Threading /// [omit] let mutable verbose = false @@ -49,6 +51,25 @@ let traceErrorfn fmt = Printf.ksprintf traceError fmt /// [omit] let traceWarnfn fmt = Printf.ksprintf traceWarn fmt +let private omittedWarnings = ref 0 +let private warnings = ConcurrentDictionary() +let traceIfNotBefore tracer key fmt = + let printer = + if verbose then tracer + else + let g = Guid.NewGuid() + if g = warnings.GetOrAdd(key, fun _ -> g) then + tracer + else + Interlocked.Increment(omittedWarnings) |> ignore + ignore + + Printf.ksprintf printer fmt + +let getOmittedWarningCount () = omittedWarnings.Value + +let traceWarnIfNotBefore key fmt = traceIfNotBefore traceWarn key fmt +let traceErrorIfNotBefore key fmt = traceIfNotBefore traceError key fmt // Console Trace diff --git a/src/Paket.Core/Common/Logging.fsi b/src/Paket.Core/Common/Logging.fsi index 40b7869454..a286388a34 100644 --- a/src/Paket.Core/Common/Logging.fsi +++ b/src/Paket.Core/Common/Logging.fsi @@ -26,6 +26,10 @@ val traceErrorfn : Printf.StringFormat<'a,unit> -> 'a val traceWarnfn : Printf.StringFormat<'a,unit> -> 'a +val traceWarnIfNotBefore : 'a -> Printf.StringFormat<'b,unit> -> 'b +val traceErrorIfNotBefore : 'a -> Printf.StringFormat<'b,unit> -> 'b + +val getOmittedWarningCount : unit -> int type Trace = { Level: TraceLevel diff --git a/src/Paket.Core/Dependencies/NuGetCache.fs b/src/Paket.Core/Dependencies/NuGetCache.fs index 01c2ce0f54..1f3e794cf2 100644 --- a/src/Paket.Core/Dependencies/NuGetCache.fs +++ b/src/Paket.Core/Dependencies/NuGetCache.fs @@ -79,6 +79,8 @@ type NuGetRequestGetVersions = type UnparsedPackageFile = { FullPath : string PathWithinPackage : string } + member x.BasePath = + x.FullPath.Substring(0, x.FullPath.Length - (x.PathWithinPackage.Length + 1)) module NuGetConfig = open System.Text diff --git a/src/Paket.Core/Dependencies/NuGetV2.fs b/src/Paket.Core/Dependencies/NuGetV2.fs index d4f04c78e5..eae835fc1f 100644 --- a/src/Paket.Core/Dependencies/NuGetV2.fs +++ b/src/Paket.Core/Dependencies/NuGetV2.fs @@ -190,7 +190,7 @@ let private handleODataEntry nugetURL packageName version entry = match PlatformMatching.extractPlatforms false restriction with | Some p -> Some p | None -> - Logging.traceWarnfn "Could not detect any platforms from '%s' in package %O %O" restriction packageName version + Logging.traceWarnIfNotBefore ("Package", restriction, packageName, version) "Could not detect any platforms from '%s' in package %O %O, please tell the package authors" restriction packageName version None else Some PlatformMatching.ParsedPlatformPath.Empty) |> Option.map (fun pp -> name, version, pp) diff --git a/src/Paket.Core/Dependencies/NuGetV3.fs b/src/Paket.Core/Dependencies/NuGetV3.fs index 1f52b3c55c..84c983b764 100644 --- a/src/Paket.Core/Dependencies/NuGetV3.fs +++ b/src/Paket.Core/Dependencies/NuGetV3.fs @@ -256,7 +256,7 @@ let getPackageDetails (source:NugetV3Source) (packageName:PackageName) (version: | x -> let restrictions, problems = Requirements.parseRestrictionsLegacy false x for problem in problems do - Logging.traceErrorfn "Could not detect any platforms from '%s' in %O %O" problem.Framework packageName version + Logging.traceErrorIfNotBefore ("Package", problem.Framework, packageName, version) "Could not detect any platforms from '%s' in %O %O, please tell the package authors" problem.Framework packageName version restrictions (PackageName dep.Id), (VersionRequirement.Parse dep.Range), targetFramework) |> Seq.toList diff --git a/src/Paket.Core/Dependencies/Nuspec.fs b/src/Paket.Core/Dependencies/Nuspec.fs index 1ebcf5dd8a..8d375780db 100644 --- a/src/Paket.Core/Dependencies/Nuspec.fs +++ b/src/Paket.Core/Dependencies/Nuspec.fs @@ -36,7 +36,7 @@ module internal NuSpecParserHelper = match PlatformMatching.extractPlatforms false framework with | Some pp -> Some (name, version, pp) | None -> - Logging.traceWarnfn "Could not detect any platforms from '%s' in '%s'" framework fileName + Logging.traceWarnIfNotBefore ("NuSpecFile", framework, fileName) "Could not detect any platforms from '%s' in '%s', please tell the package authors" framework fileName None | _ -> Some(name,version, PlatformMatching.ParsedPlatformPath.Empty) @@ -84,7 +84,7 @@ type Nuspec = match PlatformMatching.extractPlatforms false framework with | Some p -> Some p | None -> - Logging.traceWarnfn "Could not detect any platforms from '%s' in '%s'" framework fileName + Logging.traceWarnIfNotBefore ("NuSpecFile", framework, fileName) "Could not detect any platforms from '%s' in '%s', please tell the package authors" framework fileName None | _ -> Some PlatformMatching.ParsedPlatformPath.Empty) diff --git a/src/Paket.Core/PackageManagement/NugetConvert.fs b/src/Paket.Core/PackageManagement/NugetConvert.fs index 3cc661d262..dab78413c2 100644 --- a/src/Paket.Core/PackageManagement/NugetConvert.fs +++ b/src/Paket.Core/PackageManagement/NugetConvert.fs @@ -286,7 +286,7 @@ let createDependenciesFileR (rootDirectory : DirectoryInfo) nugetEnv mode = |> List.map (fun fw -> let restrictions, problems = Requirements.parseRestrictionsLegacy false fw for problem in problems do - Logging.traceErrorfn "Could not detect any platforms from '%s' in %O %O" problem.Framework name version + Logging.traceErrorfn "Could not detect any platforms from '%s' in %O %O, please tell the package authors" problem.Framework name version restrictions) | _ -> [] let restrictions = diff --git a/src/Paket.Core/PaketConfigFiles/InstallModel.fs b/src/Paket.Core/PaketConfigFiles/InstallModel.fs index c6c45a67bb..c392cd9594 100644 --- a/src/Paket.Core/PaketConfigFiles/InstallModel.fs +++ b/src/Paket.Core/PaketConfigFiles/InstallModel.fs @@ -367,7 +367,7 @@ module InstallModel = (FolderScanner.choose "invalid tfm" (fun plats -> let parsed = PlatformMatching.extractPlatforms false plats if parsed.IsNone then - traceWarnfn "Could not detect any platforms from '%s' in '%s'" plats upf.FullPath + traceWarnIfNotBefore ("File", plats, upf.BasePath) "Could not detect any platforms from '%s' in '%s', please tell the package authors" plats upf.FullPath parsed)) >> FolderScanner.ParseResult.box) } { FolderScanner.AdvancedScanner.Name = "rid"; FolderScanner.AdvancedScanner.Parser = diff --git a/src/Paket.Core/Versioning/PlatformMatching.fs b/src/Paket.Core/Versioning/PlatformMatching.fs index 4635a45636..949d2fd20c 100644 --- a/src/Paket.Core/Versioning/PlatformMatching.fs +++ b/src/Paket.Core/Versioning/PlatformMatching.fs @@ -44,7 +44,7 @@ let extractPlatforms warn path = match extractPlatformsPriv path with | None -> if warn then - traceWarnfn "Could not detect any platforms from '%s'" path + Logging.traceWarnIfNotBefore ("extractPlatforms", path) "Could not detect any platforms from '%s', please tell the package authors" path None | Some s -> Some s diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index 5f63e85c28..33dc78b6cc 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -31,8 +31,8 @@ Project paket.exe Project - restore - C:\temp\perf\ + update + C:\proj\testing\testpaketfailure\ true diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index b72b177828..36d8a40427 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -100,6 +100,9 @@ let processWithValidation silent validateF commandF (result : ParseResults<'T>) ) tracefn " - Runtime: %s" (Utils.TimeSpanToReadableString realTime) + let omitted = Logging.getOmittedWarningCount() + if not verbose && omitted > 0 then + traceWarnfn "Paket omitted '%d' warnings similar to the ones above. You can see them in verbose mode" omitted let processCommand silent commandF result = processWithValidation silent (fun _ -> true) commandF result