From c006de8f4404aaacd4d20a4a765db1635e95959e Mon Sep 17 00:00:00 2001 From: Kasper Ziemianek Date: Wed, 27 Sep 2023 23:01:21 +0200 Subject: [PATCH] filter logs only from local modules (#2162) --- tee-worker/Cargo.lock | 67 +++++++++++-- tee-worker/Cargo.toml | 1 + tee-worker/enclave-runtime/Cargo.lock | 136 ++++++++++++++++++-------- tee-worker/enclave-runtime/Cargo.toml | 1 + tee-worker/enclave-runtime/src/lib.rs | 14 ++- tee-worker/litentry/macros/Cargo.toml | 12 +++ tee-worker/litentry/macros/src/lib.rs | 59 +++++++++++ 7 files changed, 243 insertions(+), 47 deletions(-) create mode 100644 tee-worker/litentry/macros/Cargo.toml create mode 100644 tee-worker/litentry/macros/src/lib.rs diff --git a/tee-worker/Cargo.lock b/tee-worker/Cargo.lock index 8937225e00..88f8e1201c 100644 --- a/tee-worker/Cargo.lock +++ b/tee-worker/Cargo.lock @@ -1034,6 +1034,16 @@ dependencies = [ "thiserror 1.0.44", ] +[[package]] +name = "cargo_toml" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3f9629bc6c4388ea699781dc988c2b99766d7679b151c81990b4fa1208fafd3" +dependencies = [ + "serde 1.0.175", + "toml 0.8.0", +] + [[package]] name = "cc" version = "1.0.79" @@ -1384,7 +1394,7 @@ dependencies = [ "rust-ini", "serde 1.0.175", "serde_json 1.0.103", - "toml", + "toml 0.5.11", "yaml-rust 0.4.5", ] @@ -7054,6 +7064,14 @@ dependencies = [ "ws", ] +[[package]] +name = "litentry-macros" +version = "0.1.0" +dependencies = [ + "cargo_toml", + "quote", +] + [[package]] name = "litentry-primitives" version = "0.1.0" @@ -11304,7 +11322,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell 1.18.0", - "toml_edit", + "toml_edit 0.19.14", ] [[package]] @@ -11546,9 +11564,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.32" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -13918,6 +13936,15 @@ dependencies = [ "serde 1.0.175", ] +[[package]] +name = "serde_spanned" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +dependencies = [ + "serde 1.0.175", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -15457,7 +15484,7 @@ dependencies = [ "sp-maybe-compressed-blob", "strum 0.24.1", "tempfile", - "toml", + "toml 0.5.11", "walkdir", "wasm-opt", ] @@ -15938,11 +15965,26 @@ dependencies = [ "serde 1.0.175", ] +[[package]] +name = "toml" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c226a7bba6d859b63c92c4b4fe69c5b6b72d0cb897dbc8e6012298e6154cb56e" +dependencies = [ + "serde 1.0.175", + "serde_spanned", + "toml_datetime", + "toml_edit 0.20.0", +] + [[package]] name = "toml_datetime" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +dependencies = [ + "serde 1.0.175", +] [[package]] name = "toml_edit" @@ -15955,6 +15997,19 @@ dependencies = [ "winnow", ] +[[package]] +name = "toml_edit" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ff63e60a958cefbb518ae1fd6566af80d9d4be430a33f3723dfc47d1d411d95" +dependencies = [ + "indexmap 2.0.0", + "serde 1.0.175", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tower" version = "0.4.13" @@ -16885,7 +16940,7 @@ dependencies = [ "rustix 0.36.15", "serde 1.0.175", "sha2 0.10.7", - "toml", + "toml 0.5.11", "windows-sys 0.42.0", "zstd", ] diff --git a/tee-worker/Cargo.toml b/tee-worker/Cargo.toml index a6c3157862..dc3e2bc90b 100644 --- a/tee-worker/Cargo.toml +++ b/tee-worker/Cargo.toml @@ -69,6 +69,7 @@ members = [ "sidechain/state", "sidechain/validateer-fetch", "litentry/primitives", + "litentry/macros", "litentry/pallets/identity-management", "litentry/core/stf-task/sender", "litentry/core/stf-task/receiver", diff --git a/tee-worker/enclave-runtime/Cargo.lock b/tee-worker/enclave-runtime/Cargo.lock index 8ef10b954d..ae2be63a9e 100644 --- a/tee-worker/enclave-runtime/Cargo.lock +++ b/tee-worker/enclave-runtime/Cargo.lock @@ -189,7 +189,7 @@ checksum = "fee3da8ef1276b0bee5dd1c7258010d8fffd31801447323115a25560e1327b89" dependencies = [ "proc-macro-error", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -437,6 +437,16 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +[[package]] +name = "cargo_toml" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3f9629bc6c4388ea699781dc988c2b99766d7679b151c81990b4fa1208fafd3" +dependencies = [ + "serde 1.0.175", + "toml", +] + [[package]] name = "cc" version = "1.0.79" @@ -633,7 +643,7 @@ checksum = "8ef71ddb5b3a1f53dee24817c8f70dfa1cb29e804c18d88c228d4bc9c86ee3b9" dependencies = [ "proc-macro-error", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -644,7 +654,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -655,7 +665,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e79116f119dd1dba1abf1f3405f03b9b0e79a27a3883864bfebded8a3dc768cd" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -667,7 +677,7 @@ checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ "convert_case", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "rustc_version 0.4.0", "syn 1.0.109", ] @@ -811,6 +821,7 @@ dependencies = [ "lc-scheduled-enclave", "lc-stf-task-receiver", "lc-stf-task-sender", + "litentry-macros", "litentry-primitives", "log", "multibase", @@ -1138,7 +1149,7 @@ dependencies = [ "frame-support-procedural-tools", "itertools 0.10.5", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -1150,7 +1161,7 @@ dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -1160,7 +1171,7 @@ version = "3.0.0" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#8c4b84520cee2d7de53cc33cb67605ce4efefba8" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -1291,7 +1302,7 @@ source = "git+https://github.com/mesalock-linux/futures-rs-sgx#d54882f24ddf7d613 dependencies = [ "proc-macro-hack", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -1577,7 +1588,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -2959,6 +2970,14 @@ dependencies = [ "sgx_tstd", ] +[[package]] +name = "litentry-macros" +version = "0.1.0" +dependencies = [ + "cargo_toml", + "quote 1.0.33", +] + [[package]] name = "litentry-primitives" version = "0.1.0" @@ -3153,7 +3172,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -3535,7 +3554,7 @@ checksum = "2a296c3079b5fefbc499e1de58dc26c09b1b9a5952d26694ee89f04a43ebbb3e" dependencies = [ "proc-macro-crate", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -3615,7 +3634,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell 1.18.0", - "toml_edit", + "toml_edit 0.19.14", ] [[package]] @@ -3626,7 +3645,7 @@ checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", "version_check", ] @@ -3638,7 +3657,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "version_check", ] @@ -3679,7 +3698,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -3705,9 +3724,9 @@ checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" [[package]] name = "quote" -version = "1.0.32" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -3797,7 +3816,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dfaf0c85b766276c797f3791f5bc6d5bd116b41d53049af2789666b0c0bc9fa" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 2.0.27", ] @@ -3923,7 +3942,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a169f6bc5a81033e86ed39d0f4150e2608160b73d2b93c6e8e6a3efa873f14" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -3945,7 +3964,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e33d7b2abe0c340d8797fe2907d3f20d3b5ea5908683618bfe80df7f621f672a" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -4073,7 +4092,7 @@ checksum = "912e55f6d20e0e80d63733872b40e1227c0bce1e1ab81ba67d696339bfd7fd29" dependencies = [ "proc-macro-crate", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -4205,7 +4224,7 @@ version = "1.0.118" source = "git+https://github.com/mesalock-linux/serde-sgx#db0226f1d5d70fca6b96af2c285851502204e21c" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -4216,7 +4235,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b23f7ade6f110613c0d63858ddb8b94c1041f550eab58a16b371bdf2c9c80ab4" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 2.0.27", ] @@ -4254,6 +4273,15 @@ dependencies = [ "serde 1.0.175", ] +[[package]] +name = "serde_spanned" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +dependencies = [ + "serde 1.0.175", +] + [[package]] name = "sgx-verify" version = "0.1.4" @@ -4591,7 +4619,7 @@ dependencies = [ "blake2", "proc-macro-crate", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -4709,7 +4737,7 @@ version = "5.0.0" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#8c4b84520cee2d7de53cc33cb67605ce4efefba8" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "sp-core-hashing", "syn 1.0.109", ] @@ -4720,7 +4748,7 @@ version = "5.0.0" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#8c4b84520cee2d7de53cc33cb67605ce4efefba8" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -4840,7 +4868,7 @@ dependencies = [ "Inflector", "proc-macro-crate", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -4951,7 +4979,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.3 dependencies = [ "parity-scale-codec", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -5002,7 +5030,7 @@ checksum = "bfc443bad666016e012538782d9e3006213a7db43e9fb1dda91657dc06a6fa08" dependencies = [ "Inflector", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "serde 1.0.175", "serde_json 1.0.103", "unicode-xid 0.2.4", @@ -5028,7 +5056,7 @@ checksum = "ad8d03b598d3d0fff69bf533ee3ef19b8eeb342729596df84bcc7e1f96ec4059" dependencies = [ "heck", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "rustversion", "syn 2.0.27", ] @@ -5087,7 +5115,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "unicode-ident", ] @@ -5098,7 +5126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "unicode-ident", ] @@ -5162,7 +5190,7 @@ version = "1.0.9" source = "git+https://github.com/mesalock-linux/thiserror-sgx?tag=sgx_1.1.3#c2f806b88616e06aab0af770366a76885d974fdc" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -5173,7 +5201,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 2.0.27", ] @@ -5203,11 +5231,26 @@ dependencies = [ "crunchy", ] +[[package]] +name = "toml" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c226a7bba6d859b63c92c4b4fe69c5b6b72d0cb897dbc8e6012298e6154cb56e" +dependencies = [ + "serde 1.0.175", + "serde_spanned", + "toml_datetime", + "toml_edit 0.20.0", +] + [[package]] name = "toml_datetime" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +dependencies = [ + "serde 1.0.175", +] [[package]] name = "toml_edit" @@ -5220,6 +5263,19 @@ dependencies = [ "winnow", ] +[[package]] +name = "toml_edit" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ff63e60a958cefbb518ae1fd6566af80d9d4be430a33f3723dfc47d1d411d95" +dependencies = [ + "indexmap 2.0.0", + "serde 1.0.175", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tracing" version = "0.1.37" @@ -5435,7 +5491,7 @@ dependencies = [ "log", "once_cell 1.18.0", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 2.0.27", "wasm-bindgen-shared", ] @@ -5446,7 +5502,7 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" dependencies = [ - "quote 1.0.32", + "quote 1.0.33", "wasm-bindgen-macro-support", ] @@ -5457,7 +5513,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 2.0.27", "wasm-bindgen-backend", "wasm-bindgen-shared", @@ -5591,7 +5647,7 @@ source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.39#c22e dependencies = [ "Inflector", "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -5670,6 +5726,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 2.0.27", ] diff --git a/tee-worker/enclave-runtime/Cargo.toml b/tee-worker/enclave-runtime/Cargo.toml index a7cb07a9bd..50653733d2 100644 --- a/tee-worker/enclave-runtime/Cargo.toml +++ b/tee-worker/enclave-runtime/Cargo.toml @@ -137,6 +137,7 @@ lc-data-providers = { path = "../litentry/core/data-providers", default-features lc-scheduled-enclave = { path = "../litentry/core/scheduled-enclave", default-features = false, features = ["sgx"] } lc-stf-task-receiver = { path = "../litentry/core/stf-task/receiver", default-features = false, features = ["sgx"] } lc-stf-task-sender = { path = "../litentry/core/stf-task/sender", default-features = false, features = ["sgx"] } +litentry-macros = { path = "../litentry/macros" } litentry-primitives = { path = "../litentry/primitives", default-features = false, features = ["sgx"] } # substrate deps diff --git a/tee-worker/enclave-runtime/src/lib.rs b/tee-worker/enclave-runtime/src/lib.rs index c74c468c40..8cf5e5c830 100644 --- a/tee-worker/enclave-runtime/src/lib.rs +++ b/tee-worker/enclave-runtime/src/lib.rs @@ -127,7 +127,19 @@ pub unsafe extern "C" fn init( ) -> sgx_status_t { // Initialize the logging environment in the enclave. if_production_or!( - env_logger::Builder::new().filter(None, LevelFilter::Info).init(), + { + let module_names = litentry_macros::local_modules!(); + println!( + "Initializing logger to filter only following local modules: {:?}", + module_names + ); + let mut builder = env_logger::Builder::new(); + builder.filter(None, LevelFilter::Off); + module_names.into_iter().for_each(|module| { + builder.filter(Some(module), LevelFilter::Info); + }); + builder.init(); + }, env_logger::init() ); diff --git a/tee-worker/litentry/macros/Cargo.toml b/tee-worker/litentry/macros/Cargo.toml new file mode 100644 index 0000000000..c3039927e1 --- /dev/null +++ b/tee-worker/litentry/macros/Cargo.toml @@ -0,0 +1,12 @@ +[package] +authors = ["Trust Computing GmbH "] +name = "litentry-macros" +version = "0.1.0" +edition = "2021" + +[dependencies] +cargo_toml = "0.16.3" +quote = "1.0.33" + +[lib] +proc-macro = true diff --git a/tee-worker/litentry/macros/src/lib.rs b/tee-worker/litentry/macros/src/lib.rs new file mode 100644 index 0000000000..b57ac19473 --- /dev/null +++ b/tee-worker/litentry/macros/src/lib.rs @@ -0,0 +1,59 @@ +// Copyright 2020-2023 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +use cargo_toml::{Dependency, Manifest}; +use proc_macro::TokenStream; +use quote::quote; +use std::fs; + +#[proc_macro] +pub fn local_modules(_item: TokenStream) -> TokenStream { + let mut deps: Vec = vec![]; + read_module_names("", ".", &mut deps); + let output = quote! { + { + let deps: Vec<&str> = vec![ + #(#deps),* + ]; + deps + } + }; + output.into() +} + +fn read_module_names(path: &str, relative_to: &str, module_names: &mut Vec) { + let current_path = relative_to.to_string() + "/" + path; + let cargo_file = current_path.to_string() + "/Cargo.toml"; + let contents = fs::read_to_string(&cargo_file) + .unwrap_or_else(|_| panic!("Should have been able to read the file: {}", cargo_file)); + let manifest = Manifest::from_str(&contents) + .unwrap_or_else(|_| panic!("Could not parse manifest file locate at {}", cargo_file)); + if let Some(package) = manifest.package { + let module_name = package.name.replace('-', "_"); + // skip package if it is unnamed or it was already visited + if !package.name.is_empty() && !module_names.contains(&module_name) { + module_names.push(module_name); + // go through all dependencies and visit the ones that has `path`, which means they are local + manifest.dependencies.values().for_each(|dep| { + if let Dependency::Detailed(details) = dep { + if let Some(path) = &details.path { + read_module_names(path, ¤t_path, module_names) + } + } + }); + } + } +}