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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Specify which files should *not* trigger a `cargo` rebuild.
//!
//! In normal operation, `cargo` rebuilds a project when any potentially relevant file changes. One
//! can use the
//! [`rerun-if-changed`](https://doc.rust-lang.org/cargo/reference/build-scripts.html#change-detection)
//! instruction to tell `cargo` to only rebuild if certain files are changed. However, it is easy
//! to forget to add new files when using `rerun-if-changed`, causing `cargo` not to rebuild a
//! project when it should.
//!
//! `rerun_except` inverts this logic, causing `cargo` to rebuild a project when a file changes
//! *unless you explicitly ignored that file*. This is safer than `rerun-if-changed` because if you
//! forget to explicitly ignore files, then `cargo` will still rebuild your project.
//!
//! `rerun_except` uses the [`ignore`](https://crates.io/crates/ignore) library to specify which
//! files to ignore in `gitignore` format. Note that explicit ignore files in your project (e.g.
//! `.gitignore`) are implicitly added to the list of ignored files.
//!
//! For example if you have the following file layout:
//!
//! ```text
//! proj/
//! .gitignore
//! Cargo.toml
//! src/
//! lib.rs
//! lang_tests/
//! run.rs
//! test1.lang
//! test2.lang
//! target/
//! ...
//! ```
//!
//! and you do not want the two `.lang` files to trigger a rebuild then you would tell
//! `rerun_except` to exclude `lang_tests/*.lang`. Assuming, as is common, that your `.gitignore`
//! file also the `target/` directory, then `rerun_except` will also ignore the `target`
//! directory.
//!
//! Adding a new file such as `lang_tests/test3.lang` will not trigger a rebuild (since it is
//! covered by the ignore glob `lang_tests/*.lang`), but adding a new file such as `build.rs` will
//! trigger a rebuild (since it is not covered by an ignore glob).
//!
//! To use `rerun_except` in this manner you simply need to call `rerun_except::rerun_except` with
//! an array of ignore globs in [`gitignore` format](https://git-scm.com/docs/gitignore) as part of
//! your `build.rs` file:
//!
//! ```rust,ignore
//! use rerun_except::rerun_except;
//!
//! fn main() {
//! rerun_except(&["lang_tests/*.lang"]).unwrap();
//! }
//! ```
use env;
use Error;
use ;
/// Specify which files should not cause `cargo` to rebuild a project. `globs` is an array of
/// ignore globs. Each entry must be in [`gitignore` format](https://git-scm.com/docs/gitignore)
/// with the minor exception that entries must not begin with a `!`.