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

Some improvements #3090

Merged
merged 13 commits into from
Feb 28, 2018
Merged
36 changes: 36 additions & 0 deletions docs/content/commands/restriction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# paket restriction

Determine how a restriction formula is interpreted by paket.

```sh
paket restriction <restriction formula>

RESTRICTION:

<restriction formula> A paket formula representing a restriction

OPTIONS:

--silent, -s suppress console output
--verbose, -v print detailed information to the console
--log-file <path> print output to a file
--from-bootstrapper call coming from the '--run' feature of the bootstrapper
--help display this list of options.
```

> Note if your formula contains spaces (which it will most likely) you need to escape with quotes

## Example

```
$ ./paket.exe restriction "|| (== netcoreapp2.0) (&& (== netstandard2.0) (>= netcoreapp2.0))"
Paket version 5.145.1
Restriction: || (== netcoreapp2.0) (&& (== netstandard2.0) (>= netcoreapp2.0))
Simplified: || (== netcoreapp2.0) (&& (== netstandard2.0) (>= netcoreapp2.0))
Frameworks: [
netcoreapp2.0
]
Performance:
- Runtime: 763 milliseconds
```

1 change: 1 addition & 0 deletions docs/tools/templates/template.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<li><a href="@Root/paket-show-installed-packages.html">paket show-installed-packages</a></li>
<li><a href="@Root/paket-update.html">paket update</a></li>
<li><a href="@Root/paket-why.html">paket why</a></li>
<li><a href="@Root/paket-restriction.html">paket restriction</a></li>
</ul>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ let assertNhibernateForFramework35IsThere scenario =
"iesi.collections.csx", ["Net35/Iesi.Collections.dll"]
"iesi.collections.fsx", ["Net35/Iesi.Collections.dll"]
"nhibernate.csx", ["Net35/NHibernate.dll";"#load \"iesi.collections.csx\""]
"nhibernate.fsx", ["Net35/NHibernate.dll";"#load @\"iesi.collections.fsx\""]
"nhibernate.fsx", ["Net35/NHibernate.dll";"#load \"iesi.collections.fsx\""]
]
let folder = getLoadScriptDefaultFolder scenario
let failures = getScriptContentsFailedExpectations folder expectations
Expand Down Expand Up @@ -202,7 +202,7 @@ let ``mscorlib excluded from f# script`` () =
Assert.False hasFilesWithMsCorlib

// Important to have the correct relative path
let expectedContent = "#load @\"Microsoft.Rest.ClientRuntime.Azure.fsx\""
let expectedContent = "#load \"Microsoft.Rest.ClientRuntime.Azure.fsx\""
let scriptPath = Path.Combine(scriptRootDir.FullName, "net46", "Microsoft.Azure.Management.ResourceManager.fsx")
let scriptContent = File.ReadAllText(scriptPath)
Assert.IsTrue(scriptContent.Contains expectedContent, sprintf "Should contain '%s' but script content was:\n%s" expectedContent scriptContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3')">
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3')">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this PR has to do with this change. but it looks correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes guess so

<ItemGroup>
<Reference Include="Microsoft.Diagnostics.Tracing.EventSource">
<HintPath>..\..\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist\lib\net40\Microsoft.Diagnostics.Tracing.EventSource.dll</HintPath>
Expand Down
14 changes: 7 additions & 7 deletions src/Paket.Core/Installation/ScriptGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ module ScriptGeneration =
else libFile.FullName

// create the approiate load string for the target resource
let refString (reference:ReferenceType) =
let refString (reference:ReferenceType) =
let escapeString (s:string) =
s.Replace("\\", "\\\\").Replace("\"", "\\\"")
match reference, self.Lang with
| Assembly file, _ ->
sprintf """#r "%s" """ (relativePath scriptFile file)
| LoadScript script, ScriptType.FSharp ->
sprintf """#load @"%s" """ (relativePath scriptFile ((baseDirectory.FullName </> script) |> FileInfo))
| LoadScript script, ScriptType.CSharp ->
sprintf """#load "%s" """ (relativePath scriptFile ((baseDirectory.FullName </> script) |> FileInfo))
sprintf """#r "%s" """ (relativePath scriptFile file |> escapeString)
| LoadScript script, _ ->
sprintf """#load "%s" """ (relativePath scriptFile ((baseDirectory.FullName </> script) |> FileInfo) |> escapeString)
| Framework name,_ ->
sprintf """#r "%s" """ name
sprintf """#r "%s" """ (escapeString name)

self.Input |> Seq.map refString |> Seq.distinct |> String.concat "\n"

Expand Down
16 changes: 12 additions & 4 deletions src/Paket.Core/PaketConfigFiles/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ module ProjectFile =
let private appendMap first second =
Map.fold (fun state key value -> Map.add key value state) first second

let inline getPackageIdAttribute (pf:ProjectFile) (node:XmlNode) =
let maybePackageId =
node
|> getAttribute "Include"
|> Option.orElseWith (fun _ -> node |> getAttribute "Update")
match maybePackageId with
| Some id -> id
| None -> failwithf "project file '%s' contains a reference without 'Include' or 'Update' attribute" pf.FileName

let private calculatePropertyMap (projectFile:ProjectFile) defaultProperties =
let defaultProperties = appendMap defaultProperties (getReservedProperties projectFile)

Expand Down Expand Up @@ -1460,10 +1469,10 @@ module ProjectFile =
|> List.filter (getDescendants "PrivateAssets" >>
List.exists (fun x -> x.InnerText = "All") >>
not)

let getPackageReferences project =
packageReferencesNoPrivateAssets project
|> List.map (getAttribute "Include" >> Option.get)
|> List.map (getPackageIdAttribute project)

let getCliReferences project =
cliToolsNoPrivateAssets project
Expand Down Expand Up @@ -1635,8 +1644,7 @@ module ProjectFile =
VersionRange.AtLeast (v.Replace("*","0"))
else
VersionRange.Exactly v

{ NugetPackage.Id = node |> getAttribute "Include" |> Option.get
{ NugetPackage.Id = getPackageIdAttribute projectFile node
VersionRange = versionRange
Kind = NugetPackageKind.Package
TargetFramework = None })
Expand Down
8 changes: 1 addition & 7 deletions src/Paket.Core/Versioning/ConfigFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,7 @@ let GetAuthenticationForUrl =
getSourceNodes credentialsNode source "credential" @ getSourceNodes credentialsNode source "token"

match sourceNodes with
| sourceNode :: _ ->
let auth = getAuthFromNode sourceNode
if checkCredentials (url, Some auth) then
Some auth
else
failwithf "Credentials from authentication store for %s are invalid" source
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this still fails, but a bit later and with one request less

None
| sourceNode :: _ -> Some (getAuthFromNode sourceNode)
| _ -> None)

/// Get the authentication from the authentication store for a specific source
Expand Down
10 changes: 10 additions & 0 deletions src/Paket/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,14 @@ with

| Details -> "display detailed information with all paths, versions and framework restrictions"

type RestrictionArgs =
| [<ExactlyOnce;MainCommand>] Restriction of restrictionRaw:string
with
interface IArgParserTemplate with
member this.Usage =
match this with
| Restriction(_) -> "The restriction to resolve"

type Command =
// global options
| Version
Expand Down Expand Up @@ -630,6 +638,7 @@ type Command =
| [<Hidden;CustomCommandLine("generate-include-scripts")>] GenerateIncludeScripts of ParseResults<GenerateLoadScriptsArgs>
| [<CustomCommandLine("generate-load-scripts")>] GenerateLoadScripts of ParseResults<GenerateLoadScriptsArgs>
| [<CustomCommandLine("why")>] Why of ParseResults<WhyArgs>
| [<CustomCommandLine("restriction")>] Restriction of ParseResults<RestrictionArgs>
| [<CustomCommandLine("info")>] Info of ParseResults<InfoArgs>
with
interface IArgParserTemplate with
Expand Down Expand Up @@ -660,6 +669,7 @@ with
| GenerateIncludeScripts _ -> "[obsolete]"
| GenerateLoadScripts _ -> "generate F# and C# include scripts that reference installed packages in a interactive environment like F# Interactive or ScriptCS"
| Why _ -> "determine why a dependency is required"
| Restriction _ -> "resolve a framework restriction and show details"
| Info _ -> "info"
| Log_File _ -> "print output to a file"
| Silent -> "suppress console output"
Expand Down
19 changes: 19 additions & 0 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ let findPackages silent (results : ParseResults<_>) =

#nowarn "44" // because FixNuspecs is deprecated and we have warnaserror

open Paket.Requirements

let fixNuspecs silent (results : ParseResults<_>) =
let nuspecFiles =
results.GetResult <@ FixNuspecsArgs.Files @>
Expand Down Expand Up @@ -741,6 +743,22 @@ let why (results: ParseResults<WhyArgs>) =

Why.ohWhy(packageName, directDeps, lockFile, groupName, results.Parser.PrintUsage(), options)

let restriction (results: ParseResults<RestrictionArgs>) =
let restrictionRaw = results.GetResult <@ RestrictionArgs.Restriction @>
let restriction, parseProblems = Requirements.parseRestrictions restrictionRaw

for problem in parseProblems |> Seq.map (fun x -> x.AsMessage) do
Logging.traceWarnfn "Problem: %s" problem

Logging.tracefn "Restriction: %s" restrictionRaw
Logging.tracefn "Simplified: %s" (restriction.ToString())
Logging.tracefn "Frameworks: [ "
for framework in restriction.RepresentedFrameworks do
Logging.tracefn " %s" framework.CompareString
Logging.tracefn "]"



let waitForDebugger () =
while not(System.Diagnostics.Debugger.IsAttached) do
System.Threading.Thread.Sleep(100)
Expand Down Expand Up @@ -776,6 +794,7 @@ let handleCommand silent command =
| GenerateLoadScripts r -> processCommand silent generateLoadScripts r
| GenerateNuspec r -> processCommand silent generateNuspec r
| Why r -> processCommand silent why r
| Restriction r -> processCommand silent restriction r
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@forki I can remove that from the PR if you don't like it, the rest are bug-fixes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it's fine, but needs docs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the question, I saw it more like a debug helper for us, but we can make it a feature (honestly I doubt if the regular user can do something with the output)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add some lines :)

| Info r -> processCommand silent info r
// global options; list here in order to maintain compiler warnings
// in case of new subcommands added
Expand Down