11// SPDX-License-Identifier: GPL-3.0-or-later
22
3+ //! This module defines the configuration of the application.
4+ //!
5+ //! The configuration is either loaded from a file or used with the default
6+ //! values, which are defined in the code. The configuration exposes the main
7+ //! logical steps that the application will follow.
8+ //!
9+ //! The configuration file syntax is based on the YAML format.
10+ //! The default configuration file name is `bear.yml`.
11+ //!
12+ //! The configuration file location is searched in the following order:
13+ //! - The current working directory.
14+ //! - The local configuration directory of the user.
15+ //! - The configuration directory of the user.
16+ //! - The local configuration directory of the application.
17+ //! - The configuration directory of the application.
18+ //!
19+ //! The configuration file content is validated against the schema version,
20+ //! syntax and semantic constraints. If the configuration file is invalid,
21+ //! the application will exit with an error message explaining the issue.
22+ //!
23+ //! ```yaml
24+ //! schema: 4.0
25+ //!
26+ //! intercept:
27+ //! mode: wrapper
28+ //! directory: /tmp
29+ //! executables:
30+ //! - /usr/bin/cc
31+ //! - /usr/bin/c++
32+ //! output:
33+ //! specification: clang
34+ //! compilers:
35+ //! - path: /usr/local/bin/cc
36+ //! ignore: always
37+ //! - path: /usr/local/bin/c++
38+ //! ignore: conditional
39+ //! arguments:
40+ //! match:
41+ //! - -###
42+ //! - path: /usr/local/bin/clang
43+ //! ignore: never
44+ //! arguments:
45+ //! add:
46+ //! - -DDEBUG
47+ //! remove:
48+ //! - -Wall
49+ //! - path: /usr/local/bin/clang++
50+ //! arguments:
51+ //! remove:
52+ //! - -Wall
53+ //! filter:
54+ //! source:
55+ //! include_only_existing_files: true
56+ //! paths_to_include:
57+ //! - sources
58+ //! paths_to_exclude:
59+ //! - tests
60+ //! duplicates:
61+ //! by_fields:
62+ //! - file
63+ //! - directory
64+ //! format:
65+ //! command_as_array: true
66+ //! drop_output_field: false
67+ //! ```
68+ //!
69+ //! ```yaml
70+ //! schema: 4.0
71+ //!
72+ //! intercept:
73+ //! mode: preload
74+ //! output:
75+ //! specification: bear
76+ //! ```
77+
378use std:: collections:: HashSet ;
479use std:: fs:: OpenOptions ;
580use std:: path:: { Path , PathBuf } ;
@@ -14,61 +89,6 @@ const PRELOAD_LIBRARY_PATH: &str = env!("PRELOAD_LIBRARY_PATH");
1489const WRAPPER_EXECUTABLE_PATH : & str = env ! ( "WRAPPER_EXECUTABLE_PATH" ) ;
1590
1691/// Represents the application configuration.
17- ///
18- /// ```yaml
19- /// schema: 4.0
20- ///
21- /// intercept:
22- /// mode: wrapper
23- /// directory: /tmp
24- /// executables:
25- /// - /usr/bin/cc
26- /// - /usr/bin/c++
27- /// output:
28- /// specification: clang
29- /// compilers:
30- /// - path: /usr/local/bin/cc
31- /// ignore: always
32- /// - path: /usr/local/bin/c++
33- /// ignore: conditional
34- /// arguments:
35- /// match:
36- /// - -###
37- /// - path: /usr/local/bin/clang
38- /// ignore: never
39- /// arguments:
40- /// add:
41- /// - -DDEBUG
42- /// remove:
43- /// - -Wall
44- /// - path: /usr/local/bin/clang++
45- /// arguments:
46- /// remove:
47- /// - -Wall
48- /// filter:
49- /// source:
50- /// include_only_existing_files: true
51- /// paths_to_include:
52- /// - sources
53- /// paths_to_exclude:
54- /// - tests
55- /// duplicates:
56- /// by_fields:
57- /// - file
58- /// - directory
59- /// format:
60- /// command_as_array: true
61- /// drop_output_field: false
62- /// ```
63- ///
64- /// ```yaml
65- /// schema: 4.0
66- ///
67- /// intercept:
68- /// mode: preload
69- /// output:
70- /// specification: bear
71- /// ```
7292#[ derive( Debug , PartialEq , Deserialize , Serialize ) ]
7393pub struct Main {
7494 #[ serde( deserialize_with = "validate_schema_version" ) ]
0 commit comments