Trouble getting a detailed view of modules
EdmundsEcho opened this issue · 2 comments
First, thank you for this plugin; an important component of the rust-tool-chain.
I'm having trouble getting the expected output. The documentation suggests I should see more than what I am. As of now, it's only reporting what is in my main.rs
.
> cargo modules generate tree --with-types --verbose --package oauth --bin oauth
crate
└── package: oauth
└── target: oauth
crate oauth
├── fn main: pub(crate)
├── fn run: pub(crate)
├── fn set_env: pub(crate)
└── fn start_server: pub(crate)
However, while not in my cargo, main depends on the following (referenced using oauth
prefix):
use async_redis_session::RedisSessionStore;
use axum::extract::Extension;
use axum::http::header::{HeaderValue, USER_AGENT};
use axum::{
handler::Handler, http::StatusCode, response::IntoResponse, routing::get, AddExtensionLayer,
Router,
};
use secrecy::ExposeSecret;
use tokio::sync::mpsc;
use tower::ServiceBuilder;
use tower_http::set_header::SetRequestHeaderLayer;
use tower_http::trace::TraceLayer;
#[path = "constants.rs"]
mod constants;
#[path = "handlers/mod.rs"]
mod handlers;
#[path = "models/mod.rs"]
mod models;
#[path = "middleware/mod.rs"]
mod middleware;
#[path = "errors.rs"]
mod errors;
#[path = "state.rs"]
mod state;
#[path = "config.rs"]
pub mod config;
use crate::config::config_get;
use crate::errors::{AuthError, Result};
use crate::handlers::*;
use crate::models::drive_clients;
use crate::models::oauth_clients;
pub fn app() -> Result<Router> {...}
// see https://kubernetes.io/docs/reference/using-api/health-checks/
async fn health_check() -> impl IntoResponse {...}
// global fallback
async fn handler_404() -> impl IntoResponse {...}
// for dev purposes; reload the config files
async fn reload(Extension(shutdown_handle): Extension<mpsc::Sender<()>>) -> impl IntoResponse {...}
Cargo for the project within the workspace:
[package]
name = "oauth"
version = "0.1.0"
edition = "2021"
rust-version = "1.57"
# minimize exe size
[profile.release]
lto = true
codegen-units = 1
[[bin]]
name = "oauth"
path = "src/main.rs"
It would be great to get a better understanding of what output to expect from modules
.
So, once I add a [lib]
entry in cargo, it punches out what I would expect:
> cargo modules generate tree --package oauth --lib
crate oauth
├── mod config: pub
├── mod constants: pub(crate)
├── mod errors: pub(crate)
├── mod handlers: pub(crate)
│ ├── mod authenticate: pub
│ ├── mod authorize: pub
│ ├── mod drive_authorized: pub
│ ├── mod favicon: pub
│ ├── mod filesystem: pub
│ ├── mod login_authorized: pub
│ ├── mod logout: pub
│ └── mod shared: pub(self)
├── mod middleware: pub(crate)
│ └── mod print_response: pub
├── mod models: pub(crate)
│ ├── mod auth_failed_redirect: pub
│ ├── mod auth_redirect: pub
│ ├── mod auth_return: pub
│ ├── mod drive_clients: pub
│ ├── mod drive_provider: pub
│ ├── mod drive_token: pub
│ ├── mod files: pub
│ ├── mod message: pub
│ ├── mod oauth_clients: pub
│ ├── mod oauth_provider: pub
│ ├── mod project_id: pub
│ ├── mod user: pub
│ └── mod user_registration: pub
└── mod state: pub(crate)
I wonder if this output should not be what we see without the lib entry given main.rs
clearly has access to these modules. If not, some sort of warning/FYI?
Hi @EdmundsEcho, thanks for the detailed feedback, it is much appreciated!
Since (if I understand your project correctly) the modules are strictly speaking part of the oauth
library, rather than the oauth
binary (and only pulled in via an implicit dependency between bin and lib).
As such when running generate tree
they are not considered at all (due to being "extern"), and when running generate graph
only when running with --with-externs
.
The generate tree
command only traverses owns
relationships (as compared to depends on
, which generate graph
also supports), as otherwise the traversal might end up with cycles and thus not be a tree anymore.