Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Add kpm list command #1029

Merged
merged 1 commit into from Jan 18, 2015
Merged

Add kpm list command #1029

merged 1 commit into from Jan 18, 2015

Conversation

troydai
Copy link
Contributor

@troydai troydai commented Jan 5, 2015

Add a new command to kpm: kpm list

The command lists the dependencies of given project. The command runs in two modes.

  1. In default mode, it lists all the packages on the feed.
  2. In local mode, it walk the dependencies against all local assembly files and list the full paths.

Under local mode a path to the runtime assemblies folder is allowed optionally. If provided, the command will try to use the assemblies under that folder to resolve the dependencies.

Usage examples:

Lists all the libraries dependencies in a flat mode. Following the packages, immediate dependents are listed.

kpm list

List dependencies for Microsoft.Framework.Runtime.Roslyn (C:\myk\KRuntime\src\Microsoft.Framework.Runtime.Roslyn\project.json)
[Target framework Asp.Net]
gac/Microsoft.CSharp 4.0.0.0
    -> Microsoft.Framework.Runtime 1.0.0, Microsoft.Framework.Runtime.Common 1.0.0, Microsoft.Framework.Runtime.Interfaces 1.0.0, Microsoft.Framework.Runtime.Loader 1.0.0, Microsoft.Framework.Runtime.Roslyn 1.0.0, Microsoft.Framework.Runtime.Roslyn.Common 1.0.0
gac/mscorlib 4.0.0.0
    -> Microsoft.Framework.Runtime 1.0.0, Microsoft.Framework.Runtime.Common 1.0.0, Microsoft.Framework.Runtime.Interfaces 1.0.0, Microsoft.Framework.Runtime.Loader 1.0.0, Microsoft.Framework.Runtime.Roslyn 1.0.0, Microsoft.Framework.Runtime.Roslyn.Common 1.0.0
gac/System 4.0.0.0
    -> Microsoft.Framework.Runtime 1.0.0, Microsoft.Framework.Runtime.Common 1.0.0, Microsoft.Framework.Runtime.Interfaces 1.0.0, Microsoft.Framework.Runtime.Loader 1.0.0, Microsoft.Framework.Runtime.Roslyn 1.0.0, Microsoft.Framework.Runtime.Roslyn.Common 1.0.0
gac/System.Collections 4.0.10.0
    -> Microsoft.Framework.Runtime 1.0.0
gac/System.Core 4.0.0.0
    -> Microsoft.Framework.Runtime 1.0.0, Microsoft.Framework.Runtime.Common 1.0.0, Microsoft.Framework.Runtime.Interfaces 1.0.0, Microsoft.Framework.Runtime.Loader 1.0.0, Microsoft.Framework.Runtime.Roslyn 1.0.0, Microsoft.Framework.Runtime.Roslyn.Common 1.0.0
gac/System.IO 4.0.0.0
    -> Microsoft.Framework.Runtime 1.0.0, Microsoft.Framework.Runtime.Roslyn 1.0.0
gac/System.IO.Compression 4.0.0.0
    -> Microsoft.Framework.Runtime 1.0.0
gac/System.IO.Compression.FileSystem 4.0.0.0
    -> Microsoft.Framework.Runtime 1.0.0
gac/System.Runtime 4.0.20.0
    -> Microsoft.Framework.Runtime 1.0.0, Microsoft.Framework.Runtime.Roslyn.Common 1.0.0
gac/System.Text.Encoding 4.0.0.0
    -> Microsoft.Framework.Runtime.Roslyn 1.0.0
gac/System.Threading.Tasks 4.0.10.0
    -> Microsoft.Framework.Runtime.Roslyn 1.0.0
gac/System.Xml 4.0.0.0
    -> Microsoft.Framework.Runtime 1.0.0, Microsoft.Framework.Runtime.Roslyn 1.0.0
gac/System.Xml.Linq 4.0.0.0
    -> Microsoft.Framework.Runtime 1.0.0, Microsoft.Framework.Runtime.Roslyn 1.0.0
Microsoft.CodeAnalysis.CSharp 1.0.0-rc1-*
    -> Microsoft.Framework.Runtime.Roslyn 1.0.0, Microsoft.Framework.Runtime.Roslyn.Common 1.0.0
Microsoft.Framework.Runtime 1.0.0
    -> Microsoft.Framework.Runtime.Roslyn 1.0.0
Microsoft.Framework.Runtime.Common 1.0.0
    -> Microsoft.Framework.Runtime 1.0.0, Microsoft.Framework.Runtime.Roslyn 1.0.0, Microsoft.Framework.Runtime.Roslyn.Common 1.0.0
Microsoft.Framework.Runtime.Interfaces 1.0.0
    -> Microsoft.Framework.Runtime 1.0.0, Microsoft.Framework.Runtime.Common 1.0.0, Microsoft.Framework.Runtime.Loader 1.0.0, Microsoft.Framework.Runtime.Roslyn 1.0.0, Microsoft.Framework.Runtime.Roslyn.Common 1.0.0
Microsoft.Framework.Runtime.Loader 1.0.0
    -> Microsoft.Framework.Runtime 1.0.0

List the full paths to the assemblies referenced by the project on local disk.

kpm list --local

List dependencies for Microsoft.Framework.Runtime.Roslyn (C:\myk\KRuntime\src\Microsoft.Framework.Runtime.Roslyn\project.json)
[Target framework Asp.Net]
C:\Users\trdai\.kpm\packages\Newtonsoft.Json\6.0.6\lib\net45\Newtonsoft.Json.dll
C:\Users\trdai\.kpm\packages\System.Collections.Immutable\1.1.32-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
C:\Users\trdai\.kpm\packages\System.Reflection.Metadata\1.0.17-beta\lib\portable-net45+win8\System.Reflection.Metadata.dll
[Target framework Asp.NetCore]
C:\Users\trdai\.kpm\packages\Newtonsoft.Json\6.0.6\lib\portable-net45+wp80+win8+wpa81+aspnetcore50\Newtonsoft.Json.dll
C:\Users\trdai\.kpm\packages\System.AppContext\4.0.0-beta-22513\lib\aspnetcore50\System.AppContext.dll
C:\Users\trdai\.kpm\packages\System.Collections.Concurrent\4.0.10-beta-22513\lib\aspnetcore50\System.Collections.Concurrent.dll
C:\Users\trdai\.kpm\packages\System.Collections.Immutable\1.1.32-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
C:\Users\trdai\.kpm\packages\System.Collections\4.0.10-beta-22513\lib\aspnetcore50\System.Collections.dll
C:\Users\trdai\.kpm\packages\System.ComponentModel\4.0.0-beta-22513\lib\aspnetcore50\System.ComponentModel.dll
C:\Users\trdai\.kpm\packages\System.Console\4.0.0-beta-22513\lib\aspnetcore50\System.Console.dll
C:\Users\trdai\.kpm\packages\System.Diagnostics.Debug\4.0.10-beta-22513\lib\aspnetcore50\System.Diagnostics.Debug.dll
C:\Users\trdai\.kpm\packages\System.Diagnostics.Tools\4.0.0-beta-22513\lib\aspnetcore50\System.Diagnostics.Tools.dll
C:\Users\trdai\.kpm\packages\System.Dynamic.Runtime\4.0.0-beta-22513\lib\aspnetcore50\System.Dynamic.Runtime.dll
C:\Users\trdai\.kpm\packages\System.Globalization\4.0.10-beta-22513\lib\aspnetcore50\System.Globalization.dll
C:\Users\trdai\.kpm\packages\System.IO.Compression\4.0.0-beta-22513\lib\aspnetcore50\System.IO.Compression.dll
C:\Users\trdai\.kpm\packages\System.IO.FileSystem.Primitives\4.0.0-beta-22513\lib\aspnetcore50\System.IO.FileSystem.Primitives.dll
C:\Users\trdai\.kpm\packages\System.IO.FileSystem.Watcher\4.0.0-beta-22513\lib\aspnetcore50\System.IO.FileSystem.Watcher.dll
C:\Users\trdai\.kpm\packages\System.IO.FileSystem\4.0.0-beta-22513\lib\aspnetcore50\System.IO.FileSystem.dll

List all the libraries dependencies in a tree mode. The tree is fully expanded.

kpm list --tree

List dependencies for Microsoft.Framework.Runtime.Roslyn (C:\myk\KRuntime\src\Microsoft.Framework.Runtime.Roslyn\project.json)
[Target framework Asp.Net]
└Microsoft.Framework.Runtime.Roslyn 1.0.0
  ├Microsoft.CodeAnalysis.CSharp 1.0.0-rc1-*
  ├Microsoft.Framework.Runtime 1.0.0
  │ ├System.Reflection.Metadata 1.0.17-beta
  │ │ └System.Collections.Immutable 1.1.32-beta
  │ ├Microsoft.Framework.Runtime.Loader 1.0.0
  │ │ ├Microsoft.Framework.Runtime.Interfaces 1.0.0
  │ │ │ ├gac/mscorlib 4.0.0.0
  │ │ │ ├gac/System 4.0.0.0
  │ │ │ ├gac/System.Core 4.0.0.0
  │ │ │ └gac/Microsoft.CSharp 4.0.0.0
  │ │ ├gac/mscorlib 4.0.0.0
  │ │ ├gac/System 4.0.0.0
  │ │ ├gac/System.Core 4.0.0.0
  │ │ └gac/Microsoft.CSharp 4.0.0.0
  │ ├Microsoft.Framework.Runtime.Common 1.0.0
  │ │ ├Microsoft.Framework.Runtime.Interfaces 1.0.0
  │ │ │ ├gac/mscorlib 4.0.0.0
  │ │ │ ├gac/System 4.0.0.0
  │ │ │ ├gac/System.Core 4.0.0.0
  │ │ │ └gac/Microsoft.CSharp 4.0.0.0
  │ │ ├gac/mscorlib 4.0.0.0
  │ │ ├gac/System 4.0.0.0
  │ │ ├gac/System.Core 4.0.0.0
  │ │ └gac/Microsoft.CSharp 4.0.0.0
  │ ├Microsoft.Framework.Runtime.Interfaces 1.0.0
  │ │ ├gac/mscorlib 4.0.0.0

List all the libraries dependencies in a tree mode, but the three will be collapsed under level 3.

kpm list --tree --tree-level 3

List dependencies for Microsoft.Framework.Runtime.Roslyn (C:\myk\KRuntime\src\Microsoft.Framework.Runtime.Roslyn\project.json)
[Target framework Asp.Net]
└Microsoft.Framework.Runtime.Roslyn 1.0.0
  ├Microsoft.CodeAnalysis.CSharp 1.0.0-rc1-*
  ├Microsoft.Framework.Runtime 1.0.0
  │ ├System.Reflection.Metadata 1.0.17-beta
  │ │ └System.Collections.Immutable 1.1.32-beta ()
  │ ├Microsoft.Framework.Runtime.Loader 1.0.0
  │ │ ├Microsoft.Framework.Runtime.Interfaces 1.0.0 (gac/Microsoft.CSharp 4.0.0.0,gac/mscorlib 4.0.0.0,gac/System 4.0.0.0,gac/System.Core 4.0.0.0)
  │ │ ├gac/mscorlib 4.0.0.0 ()
  │ │ ├gac/System 4.0.0.0 ()
  │ │ ├gac/System.Core 4.0.0.0 ()
  │ │ └gac/Microsoft.CSharp 4.0.0.0 ()
  │ ├Microsoft.Framework.Runtime.Common 1.0.0
  │ │ ├Microsoft.Framework.Runtime.Interfaces 1.0.0 (gac/Microsoft.CSharp 4.0.0.0,gac/mscorlib 4.0.0.0,gac/System 4.0.0.0,gac/System.Core 4.0.0.0)
  │ │ ├gac/mscorlib 4.0.0.0 ()
  │ │ ├gac/System 4.0.0.0 ()
  │ │ ├gac/System.Core 4.0.0.0 ()
  │ │ └gac/Microsoft.CSharp 4.0.0.0 ()
  │ ├Microsoft.Framework.Runtime.Interfaces 1.0.0
  │ │ ├gac/mscorlib 4.0.0.0 ()
  │ │ ├gac/System 4.0.0.0 ()
  │ │ ├gac/System.Core 4.0.0.0 ()
  │ │ └gac/Microsoft.CSharp 4.0.0.0 ()

app.Command("list", c =>
{
c.Description = "Print the dependencies of a given project.";
var coreclrRoot = c.Option("--coreclr",
Copy link
Member

Choose a reason for hiding this comment

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

Why is this --coreclr? and not --runtime?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

humm may need a better name. I'm a bit hesitated on "runtime". First of all it is not used in the case of CLR framework. Second, it is actually used to point the CoreCLR packages folder rather than the runtime folder. And also put "runtime" is a little bit ambiguous, in kvm it accepts a runtime version name.

Copy link
Member

Choose a reason for hiding this comment

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

It should totally be runtime. The flag in kvm is -r aka --runtime the flag in kpm pack is also --runtime. Of of the values of the -r flag on kvm is CoreCLR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a switch, it accept a path to the CoreCLR assemblies folder. The usage is different from the -r and --runtime.

@davidfowl
Copy link
Member

  1. In default mode, it lists all the packages on the feed.

I think this is insane 😄. We should look at what npm and other package manages do when listing remote packages. Maybe the default list command requires a search query and we can show results by feed.

kpm list System.AppContext

For --local, I think you want to treat this command like a command line version of the references node in visual studio. You use it to see what your project is referencing, and to see unresolved dependencies and other information like that.

Maybe if --runtime is specified, then we can walk past the package graph into the implementation, otherwise we don't show it by default.

@davidfowl
Copy link
Member

I would also mirror the output of pack and build when listing dependencies

@troydai
Copy link
Contributor Author

troydai commented Jan 5, 2015

Ah, it should be:

1) In default mode, it lists all the packages the project referenced.

@davidfowl
Copy link
Member

nit:

List dependencies for C:\myk\KRuntime\src\Microsoft.Framework.Runtime.Roslyn\project.json

It should be something like:

Listing dependencies for Microsoft.Framework.Runtime.Roslyn (C:\myk\KRuntime\src\Microsoft.Framework.Runtime.Roslyn\project.json)

@davidfowl
Copy link
Member

You may also want to consider showing an actual dependency tree.

@troydai
Copy link
Contributor Author

troydai commented Jan 5, 2015

How about a reversed dependency tree: each package follows by the chain of dependencies explaining why it is introduced?

@davidfowl
Copy link
Member

By default? Nope, it should be an option though. This command looks promising but I think what I said holds. Assume this is the command line equivalent of the references node. Try using it that way on some projects and see if it's actually useful.

@davidfowl
Copy link
Member

There also needs to be a --framework flag so you can specify which framework (of the ones specified in your project.json file) to show

@davidfowl
Copy link
Member

https://docs.npmjs.com/cli/ls

parseable

Default: false
Type: Boolean
Show parseable output instead of tree view.

{
foreach (var loadableAssembly in libraryInformation.LoadableAssemblies)
{
IEnumerable<string> dependencies;
Copy link
Contributor

Choose a reason for hiding this comment

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

minor : can this be var dependencies = ResolveLocalDependency(loadableAssembly.Name, assemblyName => missing.Add(assemblyName)); instead?

@troydai
Copy link
Contributor Author

troydai commented Jan 7, 2015

Rebase on the latest dev. I'll begin addressing the first round of feedbacks.

@troydai
Copy link
Contributor Author

troydai commented Jan 14, 2015

The command design is overhauled. The description will be updated.

@troydai
Copy link
Contributor Author

troydai commented Jan 14, 2015

@davidfowl

@troydai
Copy link
Contributor Author

troydai commented Jan 15, 2015

@davidfowl @muratg @loudej @Praburaj @ChengTian
Please help review this PR if we want to check it in on time.

@troydai
Copy link
Contributor Author

troydai commented Jan 15, 2015

Also @Eilon, I used the spelling check plugin this time. Hopefully it saved you some work.

/// <summary>
/// Walk the graph in depth-first post order
/// </summary>
public class DFPostOrderWalker<T, K>
Copy link
Member

Choose a reason for hiding this comment

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

T and K as generic args is not very descriptive. Normally it would be TFoo and TBar, though in this case it's not clear to me what the two args represent at all. Do you have better names for them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

T -> TNode, represents the type of the graph's node
K -> TState, represents the type of the result of the traversal, it is a state pass down in the recursive invocation.

Advice?

Copy link
Member

Choose a reason for hiding this comment

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

That's better than the old names, for sure 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Should the file name be DepthFirstPostOrderWalker.cs instead of DFPostOrderWalker.cs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought about that but the name appears a little bit long. So here's my thought, I'd like to have a set of common used algorithms and data structures place together. There name can follow the convention that DF stands for Depth First and BF stands for Breath First. It helps to shorten the name without hurt the readability to much.

Advice?

Copy link
Member

Choose a reason for hiding this comment

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

DF and BF are not commonly known acronyms so I recommend against using them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All right.


public void Draw(IGraphNode<Library> root)
{
var dict = Collect(root);
Copy link
Member

Choose a reason for hiding this comment

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

dict? Dictionary of what?

@troydai
Copy link
Contributor Author

troydai commented Jan 16, 2015

@Eilon thanks for the comments on names/comments/messages, all accept, I'll update.


if (set.Any())
{
line.AppendFormat(" ({0})", string.Join(",", set.Select(l => l.ToString()).OrderBy(s => s).ToArray()));
Copy link
Member

Choose a reason for hiding this comment

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

l? s?

@troydai
Copy link
Contributor Author

troydai commented Jan 16, 2015

My PR is trending (103 comments and growing) and more changes is coming. Discussed with @davidfowl, following changes will be made to simplified the codes.

  1. Tree mode will be removed. Doesn't bring in much value but requires a lot of code.
  2. Converting the two walkers into extension method.
IGraphNode<Library> root = GetRoot();
root.PreOrderWalk(
    visitNode => { ...  }, 
    getChildren => { ... }
)

@troydai
Copy link
Contributor Author

troydai commented Jan 17, 2015

@davidfowl

Func<TNode, IEnumerable<TNode>, bool> visitNode,
Func<TNode, IEnumerable<TNode>> getChildren)
{
if (visitNode == null)
Copy link
Member

Choose a reason for hiding this comment

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

Can we use [NotNull] here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. There is no NotNull in kpm project.

@troydai
Copy link
Contributor Author

troydai commented Jan 18, 2015

@Eilon @davidfowl

{
if (_framework != AspNetCore50)
{
var gacDesc = _gacResolver.GetDescription(new Library { Name = assembly, IsGacOrFrameworkReference = true }, _framework);
Copy link
Member

Choose a reason for hiding this comment

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

This was supposed to go into ResolveAssemblyFilePath

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, missed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now the GAC resolving is not actually needed since we ignore all the unresolved assemblies here. I'll remove the code.

Copy link
Member

Choose a reason for hiding this comment

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

Great!

@troydai
Copy link
Contributor Author

troydai commented Jan 18, 2015

@davidfowl

public void Render(IGraphNode<Library> root)
{
var dict = FindImmediateDependent(root);
foreach (var key in dict.Keys.OrderBy(library => library.ToString()))
Copy link
Member

Choose a reason for hiding this comment

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

library.Name? Instead of ToString()

Copy link
Member

Choose a reason for hiding this comment

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

For the order by

@davidfowl
Copy link
Member

:shipit: after that last change

_framework = framework;

_hostContext = CreateApplicationHostContext();
_gacResolver = new GacDependencyResolver();
Copy link
Member

Choose a reason for hiding this comment

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

Is this still required?

@troydai troydai merged commit 72f4be7 into dev Jan 18, 2015
@troydai troydai deleted the update.dpa branch January 18, 2015 22:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants