Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not parse DNX stuff as dotnetcoreapp - fixes #3544 #3545

Merged
merged 1 commit into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Paket.Core/Dependencies/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Paket.Core/Dependencies/NuGetV3.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Paket.Core/Dependencies/Nuspec.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
Expand All @@ -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 ->
Expand Down
3 changes: 2 additions & 1 deletion src/Paket.Core/Installation/RestoreProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/Paket.Core/Installation/ScriptGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/PaketConfigFiles/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/Paket.Core/PaketConfigFiles/RuntimeGraph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module RuntimeGraphParser =
Supported =
[ for s in t.Value :?> JObject :> IEnumerable<KeyValuePair<string, JToken>> do
match FrameworkDetection.Extract s.Key with
| Some (Unsupported _ ) -> ()
| Some fid ->
yield fid,
match s.Value with
Expand Down
1 change: 1 addition & 0 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ module PublicAPI =
| XamarinMac
| DotNetCoreApp _
| DotNetStandard _
| Unsupported _
| Tizen _ -> false
| _ -> true)
if fws.Length > 0 then SupportCalculation.findPortable false fws |> ignore)
Expand Down
21 changes: 17 additions & 4 deletions src/Paket.Core/Versioning/FrameworkHandling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ type FrameworkIdentifier =
| WindowsPhoneApp of WindowsPhoneAppVersion
| Silverlight of SilverlightVersion
| Tizen of TizenVersion
| Unsupported of string

override x.ToString() =
match x with
Expand All @@ -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 =
Expand Down Expand Up @@ -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 =

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 @
Expand Down Expand Up @@ -1470,6 +1482,7 @@ module SupportCalculation =
| XamarinWatch
| DotNetCoreApp _
| DotNetStandard _
| Unsupported _
| XamarinMac -> false
| Tizen _ -> failwithf "Unexpected framework while trying to resolve PCL Profile"
| _ -> true)
Expand Down
7 changes: 5 additions & 2 deletions src/Paket.Core/Versioning/PlatformMatching.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) =
Expand Down
40 changes: 27 additions & 13 deletions src/Paket.Core/Versioning/Requirements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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

Expand All @@ -710,15 +708,15 @@ 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

| x ->
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions tests/Paket.Tests/Nuspec/NuspecSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down