diff --git a/src/Paket.Core/Dependencies/NuGetV2.fs b/src/Paket.Core/Dependencies/NuGetV2.fs index 78071dba27..b6a6d4e586 100644 --- a/src/Paket.Core/Dependencies/NuGetV2.fs +++ b/src/Paket.Core/Dependencies/NuGetV2.fs @@ -210,12 +210,14 @@ let private handleODataEntry nugetURL packageName version entry = |> Seq.map (fun (_,_,pp) -> pp) |> Seq.distinctBy (fun pp -> pp.Platforms |> List.sort) |> Seq.toList + let cleanedPackages = rawPackages |> Seq.filter (fun (n,_,_) -> System.String.IsNullOrEmpty (n.ToString()) |> not) |> Seq.toList - let dependencies, warnings = - addFrameworkRestrictionsToDependencies cleanedPackages frameworks + + let dependencies, warnings = addFrameworkRestrictionsToDependencies cleanedPackages frameworks + for warning in warnings do let message = warning.Format officialName version Logging.traceWarnIfNotBefore message "%s" message diff --git a/src/Paket.Core/Dependencies/NuGetV3.fs b/src/Paket.Core/Dependencies/NuGetV3.fs index 2cbcb7cbb8..06868120dd 100644 --- a/src/Paket.Core/Dependencies/NuGetV3.fs +++ b/src/Paket.Core/Dependencies/NuGetV3.fs @@ -883,8 +883,8 @@ let getPackageDetails (source:NuGetV3Source) (packageName:PackageName) (version: else false - let optimized, warnings = - addFrameworkRestrictionsToDependencies dependencies dependencyGroups + let optimized, warnings = addFrameworkRestrictionsToDependencies dependencies dependencyGroups + for warning in warnings do let message = warning.Format packageName version Logging.traceWarnIfNotBefore message "%s" message diff --git a/src/Paket.Core/Dependencies/Nuspec.fs b/src/Paket.Core/Dependencies/Nuspec.fs index df38e026ae..952cba375c 100644 --- a/src/Paket.Core/Dependencies/Nuspec.fs +++ b/src/Paket.Core/Dependencies/Nuspec.fs @@ -52,6 +52,7 @@ module internal NuSpecParserHelper = | Some name, Some targetFrameworks -> targetFrameworks.Split([|','; ' '|],System.StringSplitOptions.RemoveEmptyEntries) |> Array.choose FrameworkDetection.Extract + |> Array.filter (fun x -> match x with Unsupported _ -> false | _ -> true) |> Array.map (fun fw -> { AssemblyName = name FrameworkRestrictions = ExplicitRestriction (FrameworkRestriction.Exactly fw) }) @@ -74,7 +75,7 @@ type Nuspec = static member private Load(fileName:string, doc:XmlDocument) = let frameworks = doc - |> getDescendants "group" + |> getDescendants "group" |> List.choose (fun node -> match node |> getAttribute "targetFramework" with | Some framework -> diff --git a/src/Paket.Core/Installation/RestoreProcess.fs b/src/Paket.Core/Installation/RestoreProcess.fs index 82d02a23bc..3cd8837aea 100644 --- a/src/Paket.Core/Installation/RestoreProcess.fs +++ b/src/Paket.Core/Installation/RestoreProcess.fs @@ -612,7 +612,8 @@ let Restore(dependenciesFileName,projectFile,force,group,referencesFileNames,ign |> Option.map (fun s -> s.Split([|';'|], StringSplitOptions.RemoveEmptyEntries) |> Array.map (fun s -> s.Trim()) - |> Array.choose FrameworkDetection.Extract) + |> Array.choose FrameworkDetection.Extract + |> Array.filter (fun x -> match x with Unsupported _ -> false | _ -> true)) let dependenciesFile = DependenciesFile.ReadFromFile(dependenciesFileName) diff --git a/src/Paket.Core/Installation/ScriptGeneration.fs b/src/Paket.Core/Installation/ScriptGeneration.fs index d201bc0fb0..9b4f7d8d8d 100644 --- a/src/Paket.Core/Installation/ScriptGeneration.fs +++ b/src/Paket.Core/Installation/ScriptGeneration.fs @@ -304,7 +304,8 @@ module ScriptGeneration = // specified frameworks are never considered default let targetFrameworkList = providedFrameworks - |> List.choose FrameworkDetection.Extract + |> List.choose FrameworkDetection.Extract + |> List.filter (fun x -> match x with Unsupported _ -> false | _ -> true) |> List.map (fun f -> f, false) failOnMismatch providedFrameworks targetFrameworkList FrameworkDetection.Extract "Unrecognized Framework(s)" diff --git a/src/Paket.Core/PaketConfigFiles/ProjectFile.fs b/src/Paket.Core/PaketConfigFiles/ProjectFile.fs index 3a1f4ad50b..19126cae1d 100644 --- a/src/Paket.Core/PaketConfigFiles/ProjectFile.fs +++ b/src/Paket.Core/PaketConfigFiles/ProjectFile.fs @@ -1116,7 +1116,7 @@ module ProjectFile = | Some x -> [prefix() + (x.Replace("v",""))] - match frameworks |> List.choose (fun s -> FrameworkDetection.Extract s |> Option.map TargetProfile.SinglePlatform) with + match frameworks |> List.choose (fun s -> FrameworkDetection.Extract s |> Option.map TargetProfile.SinglePlatform) |> List.filter (fun x -> match x with TargetProfile.SinglePlatform(Unsupported _) -> false | _ -> true) with | [] -> [TargetProfile.SinglePlatform (DotNetFramework FrameworkVersion.V4)] | xs -> xs diff --git a/src/Paket.Core/PaketConfigFiles/RuntimeGraph.fs b/src/Paket.Core/PaketConfigFiles/RuntimeGraph.fs index fbcdc8bb6c..aa92b699ca 100644 --- a/src/Paket.Core/PaketConfigFiles/RuntimeGraph.fs +++ b/src/Paket.Core/PaketConfigFiles/RuntimeGraph.fs @@ -60,6 +60,7 @@ module RuntimeGraphParser = Supported = [ for s in t.Value :?> JObject :> IEnumerable> do match FrameworkDetection.Extract s.Key with + | Some (Unsupported _ ) -> () | Some fid -> yield fid, match s.Value with diff --git a/src/Paket.Core/PublicAPI.fs b/src/Paket.Core/PublicAPI.fs index 7663a1c62d..1a53b9484e 100644 --- a/src/Paket.Core/PublicAPI.fs +++ b/src/Paket.Core/PublicAPI.fs @@ -904,6 +904,7 @@ module PublicAPI = | XamarinMac | DotNetCoreApp _ | DotNetStandard _ + | Unsupported _ | Tizen _ -> false | _ -> true) if fws.Length > 0 then SupportCalculation.findPortable false fws |> ignore) diff --git a/src/Paket.Core/Versioning/FrameworkHandling.fs b/src/Paket.Core/Versioning/FrameworkHandling.fs index 1327b5c36c..170717539f 100644 --- a/src/Paket.Core/Versioning/FrameworkHandling.fs +++ b/src/Paket.Core/Versioning/FrameworkHandling.fs @@ -531,6 +531,7 @@ type FrameworkIdentifier = | WindowsPhoneApp of WindowsPhoneAppVersion | Silverlight of SilverlightVersion | Tizen of TizenVersion + | Unsupported of string override x.ToString() = match x with @@ -553,6 +554,7 @@ type FrameworkIdentifier = | WindowsPhoneApp v -> "wpa" + v.ShortString() | Silverlight v -> "sl" + v.ShortString() | Tizen v -> "tizen" + v.ShortString() + | Unsupported s -> failwithf "Framework \"%s\" is unsupported" s member internal x.RawSupportedPlatformsTransitive = @@ -659,6 +661,7 @@ type FrameworkIdentifier = | WindowsPhone WindowsPhoneVersion.V8_1 -> [ WindowsPhone WindowsPhoneVersion.V8 ] | Tizen TizenVersion.V3 -> [ DotNetStandard DotNetStandardVersion.V1_6 ] | Tizen TizenVersion.V4 -> [ DotNetStandard DotNetStandardVersion.V1_6 ] + | Unsupported _ -> [] module FrameworkDetection = @@ -798,10 +801,10 @@ module FrameworkDetection = // "netcore" is for backwards compat (2017-08-20), we wrote this incorrectly into the lockfile. | MatchTfms ["netcoreapp";"netcore"] (Bind DotNetCoreAppVersion.TryParse) fm -> Some (DotNetCoreApp fm) // "dnxcore" and "dotnet" is for backwards compat (2019-03-26), we wrote this into the lockfile. - | MatchTfm "dnx" (allowVersions ["";"4.5.1"]) () -> Some (DotNetCoreApp DotNetCoreAppVersion.V1_0) + | MatchTfm "dnx" (allowVersions ["";"4.5.1"]) () -> Some (Unsupported path) | MatchTfms ["dnxcore";"netplatform";"netcore";"aspnetcore";"aspnet";"dotnet"] (Bind (allowVersions ["";"5"])) - () -> Some (DotNetCoreApp DotNetCoreAppVersion.V1_0) - | v when v.StartsWith "dotnet" -> Some (DotNetCoreApp DotNetCoreAppVersion.V1_0) + () -> Some (Unsupported path) + | v when v.StartsWith "dotnet" -> Some (Unsupported path) | MatchTfm "tizen" TizenVersion.TryParse fm -> Some (Tizen fm) // Default is full framework, for example "35" | MatchTfm "" FrameworkVersion.TryParse fm -> Some (DotNetFramework fm) @@ -1058,21 +1061,25 @@ type PortableProfileType = | Profile328 -> "portable-net40+sl5+win8+wp8+wpa81" | Profile336 -> "portable-net403+sl5+win8+wp8+wpa81" | Profile344 -> "portable-net45+sl5+win8+wp8+wpa81" - | UnsupportedProfile fws -> + | UnsupportedProfile _ -> "portable-" + String.Join ("+", x.Frameworks |> List.sort |> List.map (fun fw -> fw.ToString())) + type TargetProfileRaw = | SinglePlatformP of FrameworkIdentifier | PortableProfileP of PortableProfileType + override this.ToString() = match this with | SinglePlatformP x -> x.ToString() | PortableProfileP p -> p.FolderName + member x.IsUnsupportedPortable = match x with + | SinglePlatformP (Unsupported _ ) -> true | PortableProfileP p -> p.IsUnsupprted | _ -> false @@ -1337,6 +1344,11 @@ module KnownTargetProfiles = Native(Release,X64) Native(Release,Arm)] + let isSupportedProfile profile = + match profile with + | FrameworkIdentifier.Unsupported _ -> false + | _ -> true + let AllProfiles = (AllNativeProfiles |> List.map TargetProfile.SinglePlatform) @ AllDotNetStandardAndCoreProfiles @ @@ -1470,6 +1482,7 @@ module SupportCalculation = | XamarinWatch | DotNetCoreApp _ | DotNetStandard _ + | Unsupported _ | XamarinMac -> false | Tizen _ -> failwithf "Unexpected framework while trying to resolve PCL Profile" | _ -> true) diff --git a/src/Paket.Core/Versioning/PlatformMatching.fs b/src/Paket.Core/Versioning/PlatformMatching.fs index a7ec881237..d04765cee0 100644 --- a/src/Paket.Core/Versioning/PlatformMatching.fs +++ b/src/Paket.Core/Versioning/PlatformMatching.fs @@ -51,7 +51,7 @@ let extractPlatforms warn path = if warn && not (path.StartsWith("_")) then Logging.traceWarnIfNotBefore ("extractPlatforms", path) "Could not detect any platforms from '%s', please tell the package authors" path None - | Some s -> Some s + | Some s -> Some { s with Platforms = s.Platforms |> List.filter (fun fw -> match fw with Unsupported _ -> false | _ -> true) } let forceExtractPlatforms path = match extractPlatforms false path with @@ -119,6 +119,7 @@ let getPathPenalty = match path.Platforms with | _ when String.IsNullOrWhiteSpace path.Name -> handleEmpty() | [] -> MaxPenalty // Ignore this path as it contains no platforms, but the folder apparently has a name -> we failed to detect the framework and ignore it + | [ Unsupported _ ] -> MaxPenalty // Ignore this path as it contains no platforms, but the folder apparently has a name -> we failed to detect the framework and ignore it | [ h ] -> let additionalPen = if path.Name.EndsWith "-client" then Penalty_Client else 0 additionalPen + getPlatformPenalty(platform,TargetProfile.SinglePlatform h) @@ -183,8 +184,9 @@ let platformsSupport = let findBestMatch = - let rec findBestMatch (paths : ParsedPlatformPath list, targetProfile : TargetProfile) = + let rec findBestMatch (paths : ParsedPlatformPath list, targetProfile : TargetProfile) = paths + |> List.map (fun path -> { path with Platforms = path.Platforms |> List.filter (fun x -> match x with Unsupported _ -> false | _ -> true)}) |> List.map (fun path -> path, (getPathPenalty (path, targetProfile))) |> List.filter (fun (_, penalty) -> penalty < MaxPenalty) |> List.sortWith comparePaths @@ -239,6 +241,7 @@ let getTargetCondition (target:TargetProfile) = | Native(NoBuildMode,bits) -> (sprintf "'$(Platform)'=='%s'" bits.AsString), "" | Native(profile,bits) -> (sprintf "'$(Configuration)|$(Platform)'=='%s|%s'" profile.AsString bits.AsString), "" | Tizen version ->"$(TargetFrameworkIdentifier) == 'Tizen'", sprintf "$(TargetFrameworkVersion) == '%O'" version + | Unsupported s -> "", "" | TargetProfile.PortableProfile p -> sprintf "$(TargetFrameworkProfile) == '%O'" p.ProfileName,"" let getCondition (referenceCondition:string option) (allTargets: TargetProfile Set list) (targets : TargetProfile Set) = diff --git a/src/Paket.Core/Versioning/Requirements.fs b/src/Paket.Core/Versioning/Requirements.fs index a0defc5847..2e351cae4d 100644 --- a/src/Paket.Core/Versioning/Requirements.fs +++ b/src/Paket.Core/Versioning/Requirements.fs @@ -637,8 +637,6 @@ let parseRestrictionsLegacy failImmediatly (text:string) = else problems.Add p - let extractFw = FrameworkDetection.Extract - let extractProfile framework = PlatformMatching.extractPlatforms false framework |> Option.bind (fun pp -> let prof = pp.ToTargetProfile false @@ -683,13 +681,13 @@ let parseRestrictionsLegacy failImmediatly (text:string) = match fw2 with | None -> let handlers = - [ extractFw >> Option.map FrameworkRestriction.AtLeast + [ FrameworkDetection.Extract >> Option.map FrameworkRestriction.AtLeast extractProfile >> Option.map FrameworkRestriction.AtLeastPlatform ] tryParseFramework handlers fw1 | Some fw2 -> - let tryParse = tryParseFramework [extractFw] + let tryParse = tryParseFramework [FrameworkDetection.Extract] match tryParse fw1, tryParse fw2 with | Some x, Some y -> Some (FrameworkRestriction.Between (x, y)) @@ -701,7 +699,7 @@ let parseRestrictionsLegacy failImmediatly (text:string) = let fw, remaining = frameworkToken (x.Substring 1) let handlers = - [ extractFw >> Option.map FrameworkRestriction.Exactly ] + [ FrameworkDetection.Extract >> Option.map FrameworkRestriction.Exactly ] tryParseFramework handlers fw, remaining @@ -710,7 +708,7 @@ let parseRestrictionsLegacy failImmediatly (text:string) = let fw, remaining = frameworkToken (x.Substring 2) let handlers = - [ extractFw >> Option.map FrameworkRestriction.Exactly ] + [ FrameworkDetection.Extract >> Option.map FrameworkRestriction.Exactly ] tryParseFramework handlers fw, remaining @@ -718,7 +716,7 @@ let parseRestrictionsLegacy failImmediatly (text:string) = let fw, remaining = frameworkToken x let handlers = - [ extractFw >> Option.map FrameworkRestriction.Exactly + [ FrameworkDetection.Extract >> Option.map FrameworkRestriction.Exactly extractProfile >> Option.map FrameworkRestriction.AtLeastPlatform ] tryParseFramework handlers fw, remaining @@ -775,12 +773,24 @@ let private parseRestrictionsRaw skipSimplify (text:string) = else idx let rawOperator = restTrimmed.Substring(0, endOperator) let operator = rawOperator.TrimEnd([|')'|]) - match PlatformMatching.extractPlatforms false operator |> Option.bind (fun (pp:PlatformMatching.ParsedPlatformPath) -> - let prof = pp.ToTargetProfile false - if prof.IsSome && prof.Value.IsUnsupportedPortable then - handleError (RestrictionParseProblem.UnsupportedPortable operator) - prof) with - | None -> failwithf "invalid parameter '%s' after >= or < in '%s'" operator text + + let extractedPlatform = PlatformMatching.extractPlatforms false operator + let platFormPath = + extractedPlatform + |> Option.bind (fun (pp:PlatformMatching.ParsedPlatformPath) -> + let prof = pp.ToTargetProfile false + if prof.IsSome && prof.Value.IsUnsupportedPortable then + handleError (RestrictionParseProblem.UnsupportedPortable operator) + prof) + + match platFormPath with + | None -> + match extractedPlatform with + | Some pp when pp.Platforms = [] -> + let operatorIndex = text.IndexOf operator + FrameworkRestriction.NoRestriction, text.Substring(operatorIndex + operator.Length) + | _ -> + failwithf "invalid parameter '%s' after >= or < in '%s'" operator text | Some plat -> let f = if isSmaller then FrameworkRestriction.NotAtLeastPlatform @@ -1261,6 +1271,10 @@ let addFrameworkRestrictionsToDependencies rawDependencies (frameworkGroups:Pars handleProblem (UnknownPortableProfile v) | _ -> () prof) + |> Seq.filter (fun frameworkGroup -> + match frameworkGroup with + | TargetProfile.SinglePlatform sp -> KnownTargetProfiles.isSupportedProfile sp + | _ -> true) // TODO: Check if this is needed (I think the logic below is a general version of this subset logic) |> Seq.filter (fun frameworkGroup -> // filter all restrictions which would render this group to nothing (ie smaller restrictions) diff --git a/tests/Paket.Tests/Nuspec/NuspecSpecs.fs b/tests/Paket.Tests/Nuspec/NuspecSpecs.fs index f42c0ac2d2..2a2df674d1 100644 --- a/tests/Paket.Tests/Nuspec/NuspecSpecs.fs +++ b/tests/Paket.Tests/Nuspec/NuspecSpecs.fs @@ -273,8 +273,7 @@ let ``can detect framework assemblies for Microsoft.Framework.Logging``() = nuspec.FrameworkAssemblyReferences.[0].FrameworkRestrictions |> shouldEqual (makeOrList - [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5)) - FrameworkRestriction.Exactly(DotNetCoreApp(DotNetCoreAppVersion.V1_0))]) + [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5))]) let name,_,_restrictions = nuspec.Dependencies.Value.[0] name |> shouldEqual (PackageName "Microsoft.Framework.DependencyInjection.Interfaces")