1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Build-time helper for [acta](https://crates.io/crates/acta).
//!
//! Call from your `build.rs` to compute a sensible default `path_width` for
//! `acta::Formatter` based on the longest source-file path in your project.
//!
//! # Example
//!
//! Add to your `Cargo.toml`:
//!
//! ```toml
//! [build-dependencies]
//! acta-build = "0.1"
//! ```
//!
//! In `build.rs`:
//!
//! ```no_run
//! # fn example() {
//! let width = acta_build::walk_src_max_width("src", "src/");
//! println!("cargo:rustc-env=ACTA_PATH_WIDTH={width}");
//! println!("cargo:rerun-if-changed=src");
//! # }
//! ```
//!
//! Then in your code:
//!
//! ```ignore
//! let width: usize = env!("ACTA_PATH_WIDTH").parse().unwrap_or(40);
//! let formatter = acta::Formatter::new().with_path_width(width);
//! ```
use Path;
use WalkDir;
/// Walk `dir` recursively, find every `.rs` file, and return
/// `max(path_len_after_stripping(strip_prefix)) + 4`.
///
/// Returns 40 if `dir` does not exist or contains no .rs files