From c3372fe929bf3765f95e6ce9270cf9c6a30a4c7d Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 20 Apr 2020 10:51:07 +0200 Subject: [PATCH 1/2] Move main into its own crate --- Cargo.lock | 16 ++++++++++++---- Cargo.toml | 14 ++++++-------- rust-code-analysis-cli/Cargo.toml | 14 ++++++++++++++ {src => rust-code-analysis-cli/src}/main.rs | 0 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 rust-code-analysis-cli/Cargo.toml rename {src => rust-code-analysis-cli/src}/main.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 4986f3e87..c764bb5f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1299,16 +1299,12 @@ dependencies = [ "aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "enum-iterator 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "globset 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "json 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-format 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "petgraph 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1318,6 +1314,18 @@ dependencies = [ "serde_json 1.0.51 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tree-sitter 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rust-code-analysis-cli" +version = "0.0.1" +dependencies = [ + "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "globset 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-code-analysis 0.0.11", + "serde_json 1.0.51 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 9054ca25a..51d4e2cd2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,32 +10,30 @@ cc = "^1.0" phf_codegen = "^0.8" [dependencies] -actix-web = "^2.0" actix-rt = "^1.0" +actix-web = "^2.0" aho-corasick = "^0.7" bytes = "^0.5" -clap = "^2.33" enum-iterator = "^0.6" futures = "^0.3" fxhash = "0.2" -globset = "^0.4" json = "^0.12" -tree-sitter = "^0.6" -termcolor = "^1.0" -crossbeam = "^0.7" lazy_static = "^1.3" -num_cpus = "^1.12" num-format = "^0.4" petgraph = "^0.5" phf = { version = "^0.8", features = ["macros"] } regex = "^1.1" serde = "^1.0" serde_json = "^1.0" -walkdir = "^2.2" +termcolor = "^1.0" +tree-sitter = "^0.6" [dev-dependencies] pretty_assertions = "^0.6" +[workspace] +members = ["rust-code-analysis-cli"] + [profile.release] opt-level = 3 debug = false diff --git a/rust-code-analysis-cli/Cargo.toml b/rust-code-analysis-cli/Cargo.toml new file mode 100644 index 000000000..384fe545e --- /dev/null +++ b/rust-code-analysis-cli/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "rust-code-analysis-cli" +version = "0.0.1" +authors = ["Calixte Denizet "] +edition = "2018" + +[dependencies] +clap = "^2.33" +crossbeam = "^0.7" +globset = "^0.4" +num_cpus = "^1.12" +rust-code-analysis = { path = ".." } +serde_json = "^1.0" +walkdir = "^2.2" diff --git a/src/main.rs b/rust-code-analysis-cli/src/main.rs similarity index 100% rename from src/main.rs rename to rust-code-analysis-cli/src/main.rs From 5cba368935d77020ad03115745edee33422f0cec Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Tue, 21 Apr 2020 15:26:48 +0200 Subject: [PATCH 2/2] Explain rust-code-analysis-cli in the README --- README.md | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 60a4dc4e9..c11c8e0a9 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Task Status](https://community-tc.services.mozilla.com/api/github/v1/repository/mozilla/rust-code-analysis/master/badge.svg)](https://community-tc.services.mozilla.com/api/github/v1/repository/mozilla/rust-code-analysis/master/latest) [![codecov](https://codecov.io/gh/mozilla/rust-code-analysis/branch/master/graph/badge.svg)](https://codecov.io/gh/mozilla/rust-code-analysis) -This project is a Rust crate (library) to analyse source code. This software is based on [Tree Sitter](https://github.com/tree-sitter/tree-sitter). +**rust-code-analysis** is a Rust library to analyze the source code of many different programming languages. It is based on a parser generator tool and an incremental parsing library called [Tree Sitter](https://github.com/tree-sitter/tree-sitter). ## Supported Languages @@ -33,18 +33,26 @@ control flow of a program. - NEXITS: it counts the number of possible exit points from a method/function. - NARGS: it counts the number of arguments of a function/method. -## How to get metrics +# rust-code-analysis-cli + +**rust-code-analysis-cli** is a command line tool thought to interact with +the functions available in the library. +It can print a series of information on your shell such as nodes and metrics. +It can also export metrics as a json file. +Below you can find a series of commands to use the software at best. + +### How to get metrics You can get metrics in your shell in this way ``` -rust-code-analysis --metrics --paths /your/path/to/a/file +rust-code-analysis-cli --metrics --paths /your/path/to/a/file ``` or as a `json` file ``` -rust-code-analysis --metrics --output your/path/to/the/output/directory --paths /your/path/to/a/file +rust-code-analysis-cli --metrics --output your/path/to/the/output/directory --paths /your/path/to/a/file ``` or you can run it as a `HTTP` service and use its `REST API` @@ -69,12 +77,15 @@ or through SSH git clone --recurse-submodules -j8 git@github.com:mozilla/rust-code-analysis.git ``` -Build and run `rust-code-analysis` +Build and run the software ```console -# Build with cargo +# Build rust-code-analysis with cargo cargo build +# Build rust-code-analysis-cli with cargo +cargo build --all + # Run through cargo cargo run -- -h cargo run -- --serve --port 8000 @@ -82,7 +93,7 @@ cargo run -- --serve --port 8000 ## How to run tests -After the build step, run the following command in order to verify if all tests pass +After the build step, run the following command to verify if all tests pass ``` cargo test --verbose