|
1 |
| -cargo-dot [](https://travis-ci.org/maxsnew/cargo-dot) |
2 |
| -===================== |
| 1 | +# cargo-graph |
3 | 2 |
|
4 |
| -A tool to graph transitive dependencies for Rust projects using Cargo |
| 3 | +Linux: [](https://travis-ci.org/kbknapp/cargo-graph) |
| 4 | + |
| 5 | +A `cargo` subcommand for building GraphViz DOT files of dependency graphs. This subcommand was originally based off and inspired by the project [cargo-dot](https://github.com/maxsnew/cargo-dot) by [Max New](https://github.com/maxsnew) |
| 6 | + |
| 7 | + |
| 8 | +## Demo |
| 9 | + |
| 10 | +Let's say we wanted to build a dependency graph of [cargo-count](https://github.com/kbknapp/cargo-count) but we wanted optional dependencies to use red dashed lines and black boxes, and regular (aka "build") dependencies to use orange lines to green diamons, one would run the following. |
| 11 | + |
| 12 | +**NOTE:** GraphViz `dot` needs to be installed to produce the .PNG from the dotfile |
5 | 13 |
|
6 |
| -Installation |
7 |
| ------------- |
8 |
| -In this project's directory, build the project and then add the binary to your `PATH`. |
9 |
| -```sh |
10 |
| -cargo build |
11 |
| -export PATH=$PATH:`pwd`/target/debug |
12 | 14 | ```
|
| 15 | +$ cargo graph --optional-line-style dashed --optional-line-color red --optional-shape box --build-shape diamond --build-color green --build-line-color orange > cargo-count.dot |
| 16 | +$ dot -Tpng > rainbow-graph.png cargo-count.dot |
| 17 | +``` |
| 18 | + |
| 19 | +**NOTE:** It's also possible to run `cargo graph [options] | dot [options] > [file]` instead of individual commands |
| 20 | + |
| 21 | +The above commands would produce the following graph: |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +Now, *why* someone would do that to a graph is a different story...but it's possible :) |
| 26 | + |
| 27 | +## Installing |
| 28 | + |
| 29 | +`cargo-graph` can be installed with `cargo install` |
| 30 | + |
| 31 | +``` |
| 32 | +$ cargo install cargo-graph |
| 33 | +``` |
| 34 | + |
| 35 | +This may require a nightly version of `cargo` if you get an error about the `install` command not being found. You may also compile and install the traditional way by followin the instructions below. |
| 36 | + |
| 37 | + |
| 38 | +## Compiling |
| 39 | + |
| 40 | +Follow these instructions to compile `cargo-count`, then skip down to Installation. |
| 41 | + |
| 42 | + 1. Ensure you have current version of `cargo` and [Rust](https://www.rust-lang.org) installed |
| 43 | + 2. Clone the project `$ git clone https://github.com/kbknapp/cargo-graph && cd cargo-graph` |
| 44 | + 3. Build the project `$ cargo build --release` (**NOTE:** There is a large performance differnce when compiling without optimizations, so I recommend alwasy using `--release` to enable to them) |
| 45 | + 4. Once complete, the binary will be located at `target/release/cargo-graph` |
| 46 | + |
| 47 | +## Installation and Usage |
| 48 | + |
| 49 | +All you need to do is place `cargo-graph` somewhere in your `$PATH`. Then run `cargo graph` anywhere in your project directory. For full details see below. |
| 50 | + |
| 51 | +### Linux / OS X |
| 52 | + |
| 53 | +You have two options, place `cargo-graph` into a directory that is already located in your `$PATH` variable (To see which directories those are, open a terminal and type `echo "${PATH//:/\n}"`, the quotation marks are important), or you can add a custom directory to your `$PATH` |
| 54 | + |
| 55 | +**Option 1** |
| 56 | +If you have write permission to a directory listed in your `$PATH` or you have root permission (or via `sudo`), simply copy the `cargo-graph` to that directory `# sudo cp cargo-graph/usr/local/bin` |
| 57 | + |
| 58 | +**Option 2** |
| 59 | +If you do not have root, `sudo`, or write permission to any directory already in `$PATH` you can create a directory inside your home directory, and add that. Many people use `$HOME/.bin` to keep it hidden (and not clutter your home directory), or `$HOME/bin` if you want it to be always visible. Here is an example to make the directory, add it to `$PATH`, and copy `cargo-graph` there. |
| 60 | + |
| 61 | +Simply change `bin` to whatever you'd like to name the directory, and `.bashrc` to whatever your shell startup file is (usually `.bashrc`, `.bash_profile`, or `.zshrc`) |
13 | 62 |
|
14 |
| -This will likely fail when used with the latest Rust nightly. If so, try |
15 | 63 | ```sh
|
16 |
| -cargo update |
| 64 | +$ mkdir ~/bin |
| 65 | +$ echo "export PATH=$PATH:$HOME/bin" >> ~/.bashrc |
| 66 | +$ cp cargo-graph~/bin |
| 67 | +$ source ~/.bashrc |
17 | 68 | ```
|
18 | 69 |
|
19 |
| -and then repeat the above steps. If it then succeeds, please submit a |
20 |
| -pull request with the new `Cargo.lock`. If it still fails, it is |
21 |
| -likely because Cargo is not updated to the latest nightly, which is |
22 |
| -common. |
| 70 | +### Windows |
23 | 71 |
|
24 |
| -Hopefully this will not be a problem once the beta starts and the |
25 |
| -nightlies are no longer the recommended installation method. See |
26 |
| -[here](http://blog.rust-lang.org/2015/02/13/Final-1.0-timeline.html) |
27 |
| -for details on the official timeline. |
| 72 | +On Windows 7/8 you can add directory to the `PATH` variable by opening a command line as an administrator and running |
28 | 73 |
|
29 |
| -Usage |
30 |
| ------ |
31 |
| -In a Rust project using Cargo, run the following commands (assuming |
32 |
| -cargo-dot is on your PATH) |
33 | 74 | ```sh
|
34 |
| -cargo build # If you don't have a Cargo.lock file |
35 |
| -cargo dot | dot -Tsvg > Cargo.svg |
| 75 | +C:\> setx path "%path%;C:\path\to\cargo-graph\binary" |
| 76 | +``` |
| 77 | + |
| 78 | +Otherwise, ensure you have the `cargo-graph` binary in the directory which you operating in the command line from, because Windows automatically adds your current directory to PATH (i.e. if you open a command line to `C:\my_project\` to use `cargo-graph` ensure `cargo-graph.exe` is inside that directory as well). |
| 79 | + |
| 80 | + |
| 81 | +### Options |
| 82 | + |
| 83 | +There are a few options for using `cargo-graph` which should be somewhat self explanitory. |
| 84 | + |
| 85 | +``` |
| 86 | +USAGE: |
| 87 | + cargo [FLAGS] [OPTIONS] [--] [ARGS] |
| 88 | +
|
| 89 | +FLAGS: |
| 90 | + -S, --follow-symlinks Follows symlinks and counts source files it finds |
| 91 | + (Defaults to false when omitted) |
| 92 | + -h, --help Prints help information |
| 93 | + --unsafe-statistics Displays lines and percentages of "unsafe" code |
| 94 | + -V, --version Prints version information |
| 95 | + -v, --verbose Print verbose output |
| 96 | +
|
| 97 | +OPTIONS: |
| 98 | + -l, --language <exts>... Only count these languges (by source code extension) |
| 99 | + (i.e. '-l js py cpp') |
| 100 | + -e, --exclude <paths>... Files or directories to exclude (automatically includes '.git') |
| 101 | + --utf8-rule <rule> Sets the UTF-8 parsing rule (Defaults to 'strict') |
| 102 | + [values: ignore lossy strict] |
| 103 | + -s, --separator <sep> Set the thousands separator for pretty printing |
| 104 | +
|
| 105 | +ARGS: |
| 106 | + to_count... The files or directories (including children) to count |
| 107 | + (defaults to current working directory when omitted) |
| 108 | +
|
| 109 | +When using '--exclude <path>' the path given can either be relative to the current |
| 110 | +directory, or absolute. When '<path>' is a file, it must be relative to the current |
| 111 | +directory or it will not be found. Example, if the current directory has a child |
| 112 | +directory named 'target' with a child fild 'test.rs' and you use `--exclude target/test.rs' |
| 113 | +
|
| 114 | +Globs are also supported. For example, to eclude 'test.rs' files from all child directories |
| 115 | +of the current directory you could do '--exclude */test.rs'. |
36 | 116 | ```
|
37 | 117 |
|
38 |
| -Examples |
39 |
| --------- |
40 |
| -This project's dependencies |
41 |
| - |
| 118 | +## License |
| 119 | + |
| 120 | +`cargo-graph` is released under the terms of the MIT. See the LICENSE-MIT file for the details. |
42 | 121 |
|
43 |
| -Servo's dependencies |
44 |
| - |
| 122 | +## Dependencies Tree |
| 123 | + |
0 commit comments