pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.33k stars 638 forks source link

depmap beautification #4860

Closed wisechengyi closed 7 years ago

wisechengyi commented 7 years ago

Problem

Currently the result of depmap looks unfriendly to human, especially with long list of dependencies

$ ./pants depmap examples/tests/java/org/pantsbuild/example/::

internal-examples.tests.java.org.pantsbuild.example.useproto.useproto
  internal-.junit_library
    junit-junit-4.12
  internal-3rdparty.junit
    *junit-junit-4.12
  internal-3rdparty.protobuf-java
    internal-3rdparty.protobuf-2.4.1
      com.google.protobuf-protobuf-java-2.4.1
  internal-examples.src.protobuf.org.pantsbuild.example.distance.distance
  *com.google.protobuf-protobuf-java-2.4.1
  *junit-junit-4.12
  *junit-junit-4.12
internal-examples.tests.java.org.pantsbuild.example.useprotoimports.useprotoimports
  internal-.junit_library
    junit-junit-4.12
  internal-3rdparty.junit
    *junit-junit-4.12
  internal-3rdparty.protobuf-java
    internal-3rdparty.protobuf-2.4.1
      com.google.protobuf-protobuf-java-2.4.1
  internal-examples.src.protobuf.org.pantsbuild.example.imports.imports
    internal-3rdparty.protobuf-test-import
      com.squareup.testing.protolib-protolib-test-1.0.1
    *com.squareup.testing.protolib-protolib-test-1.0.1
  *com.google.protobuf-protobuf-java-2.4.1
  *com.squareup.testing.protolib-protolib-test-1.0.1
  *junit-junit-4.12
  *junit-junit-4.12
internal-examples.tests.java.org.pantsbuild.example.useantlr.antlr4_test
  internal-.junit_library
    junit-junit-4.12
  internal-3rdparty.junit
    *junit-junit-4.12
  internal-examples.src.java.org.pantsbuild.example.antlr4.antlr4
    internal-examples.src.antlr.org.pantsbuild.example.exp.exp_antlr4
  *junit-junit-4.12
  *junit-junit-4.12
internal-examples.tests.java.org.pantsbuild.example.useantlr.antlr3_test
  internal-.junit_library
    junit-junit-4.12
  internal-3rdparty.junit
    *junit-junit-4.12
  internal-examples.src.java.org.pantsbuild.example.antlr3.antlr3
    internal-examples.src.antlr.org.pantsbuild.example.exp.exp_antlr3
  *junit-junit-4.12
  *junit-junit-4.12
internal-examples.tests.java.org.pantsbuild.example.usethrift.usethrift
  internal-.junit_library
    junit-junit-4.12
  internal-3rdparty.junit
    *junit-junit-4.12
  internal-3rdparty.thrift-0.9.2
    internal-3rdparty.libthrift-0.9.2
      org.apache.thrift-libthrift-0.9.2
  internal-examples.src.thrift.org.pantsbuild.example.distance.distance-java
  internal-examples.src.thrift.org.pantsbuild.example.precipitation.precipitation-java
    *internal-examples.src.thrift.org.pantsbuild.example.distance.distance-java
  *junit-junit-4.12
  *junit-junit-4.12
  *org.apache.thrift-libthrift-0.9.2
internal-examples.tests.java.org.pantsbuild.example.usejaxb.usejaxb
  internal-.junit_library
    junit-junit-4.12
  internal-3rdparty.junit
    *junit-junit-4.12
  internal-examples.src.java.org.pantsbuild.example.jaxb.reader.reader
    internal-examples.src.resources.org.pantsbuild.example.jaxb.jaxb
  *internal-examples.src.resources.org.pantsbuild.example.jaxb.jaxb
  *junit-junit-4.12
  *junit-junit-4.12
internal-examples.tests.java.org.pantsbuild.example.hello.greet.greet
  internal-.junit_library
    junit-junit-4.12
  internal-examples.src.java.org.pantsbuild.example.hello.greet.greet
  internal-examples.src.resources.org.pantsbuild.example.hello.hello
  *junit-junit-4.12
internal-examples.tests.java.org.pantsbuild.example.usewire.usewire
  internal-.junit_library
    junit-junit-4.12
  internal-3rdparty.junit
    *junit-junit-4.12
  internal-3rdparty.wire-runtime
    com.squareup.wire-wire-runtime-1.8.0
  internal-examples.src.wire.org.pantsbuild.example.temperature.temperature
  *com.squareup.wire-wire-runtime-1.8.0
  *junit-junit-4.12
  *junit-junit-4.12

Room for improvement

Ideally it should have:

  1. Real target names instead of the internal target ids. e.g. instead of internal-examples.tests.java.org.pantsbuild.example.usewire.usewire, it should be examples/tests/java/org/pantsbuild/example/usewire:usewire. Note that there is no internal- anymore, because I do not think that's necessary

  2. Have vertical lines to make it clear the dependency belongs to which branch, similar to the output of exa (https://the.exa.website/), e.g.

    $ exa -T src/python/pants/backend/
    src/python/pants/backend
    ├── README.md
    ├── __init__.py
    ├── __init__.pyc
    ├── codegen
    │  ├── BUILD
    │  ├── __init__.py
    │  ├── __init__.pyc
    │  ├── antlr
    │  │  ├── __init__.py
    │  │  ├── __init__.pyc
    │  │  ├── java
    │  │  │  ├── BUILD
    │  │  │  ├── __init__.py
    │  │  │  ├── __init__.pyc
    │  │  │  ├── antlr_java_gen.py
    │  │  │  ├── antlr_java_gen.pyc
    │  │  │  ├── java_antlr_library.py
    │  │  │  ├── java_antlr_library.pyc
    │  │  │  ├── register.py
    │  │  │  └── register.pyc
    │  │  └── python
    │  │     ├── BUILD
    │  │     ├── __init__.py
    │  │     ├── __init__.pyc
    │  │     ├── antlr_py_gen.py
    │  │     ├── antlr_py_gen.pyc
    │  │     ├── python_antlr_library.py
    │  │     ├── python_antlr_library.pyc
    │  │     ├── register.py
    │  │     └── register.pyc
    │  ├── jaxb
    │  │  ├── BUILD
    │  │  ├── __init__.py
    │  │  ├── __init__.pyc
    │  │  ├── jaxb_gen.py
    │  │  ├── jaxb_gen.pyc
    │  │  ├── jaxb_library.py
    │  │  ├── jaxb_library.pyc
    │  │  ├── register.py
    │  │  └── register.pyc
    │  ├── protobuf
    ...

    @baroquebobcat anything else you would like to add?

Where to start

https://github.com/pantsbuild/pants/blob/b7cd335efae0290caf4cafff4eac77aebfc9344a/src/python/pants/backend/project_info/tasks/depmap.py#L13

kwlzn commented 7 years ago

2 has been there for ~years via ./pants depmap --tree ...

but ./pants depmap --graph remains the most useful way to use depmap (even if just looking at the raw graphviz output) - so maybe we should focus on elevating graph-style output as the primary interface for depmap and kill the exhaustive text tree mode?

wisechengyi commented 7 years ago

Ah ok TIL --tree for depmap :) In that case that sounds more like an UX issue, closing this one.

kwlzn commented 7 years ago

I still like the 'real target names' idea tho - which would benefit depmap either way.

probably worth keeping this open to address that + the potential idea of elevating --graph as the primary interface?