nautilus_core/
paths.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Utility functions for resolving project and workspace directory paths.
17
18use std::path::PathBuf;
19
20/// Returns the workspace root directory path.
21#[must_use]
22pub fn get_workspace_root_path() -> PathBuf {
23    PathBuf::from(env!("CARGO_MANIFEST_DIR"))
24        .parent()
25        .expect("Failed to get project root")
26        .to_path_buf()
27}
28
29/// Returns the project root directory path.
30#[must_use]
31pub fn get_project_root_path() -> PathBuf {
32    get_workspace_root_path()
33        .parent()
34        .expect("Failed to get workspace root")
35        .to_path_buf()
36}
37
38/// Returns the tests root directory path.
39#[must_use]
40pub fn get_tests_root_path() -> PathBuf {
41    get_project_root_path().join("tests")
42}
43
44/// Returns the test data directory path.
45#[must_use]
46pub fn get_test_data_path() -> PathBuf {
47    if let Ok(test_data_root_path) = std::env::var("TEST_DATA_ROOT_PATH") {
48        get_project_root_path()
49            .join(test_data_root_path)
50            .join("test_data")
51    } else {
52        get_project_root_path().join("tests").join("test_data")
53    }
54}