-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(infra): share get_absolute_path infra util with snapi test utils
- Loading branch information
1 parent
eb4e92e
commit ca5efcc
Showing
14 changed files
with
31 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
use std::env; | ||
use std::path::PathBuf; | ||
use std::path::{Path, PathBuf}; | ||
use std::sync::LazyLock; | ||
|
||
static PATH_TO_CARGO_MANIFEST_DIR: LazyLock<Option<PathBuf>> = | ||
LazyLock::new(|| env::var("CARGO_MANIFEST_DIR").ok().map(|dir| Path::new(&dir).into())); | ||
|
||
pub fn cargo_manifest_dir() -> Option<PathBuf> { | ||
PATH_TO_CARGO_MANIFEST_DIR.clone() | ||
} | ||
|
||
// TODO(Tsabary/ Arni): consolidate with other get_absolute_path functions. | ||
/// Returns the absolute path from the project root. | ||
pub fn get_absolute_path(relative_path: &str) -> PathBuf { | ||
let base_dir = env::var("CARGO_MANIFEST_DIR") | ||
let base_dir = cargo_manifest_dir() | ||
// Attempt to get the `CARGO_MANIFEST_DIR` environment variable and convert it to `PathBuf`. | ||
// Ascend two directories ("../..") to get to the project root. | ||
.map(|dir| PathBuf::from(dir).join("../..")) | ||
.map(|dir| dir.join("../..")) | ||
// If `CARGO_MANIFEST_DIR` isn't set, fall back to the current working directory | ||
.unwrap_or_else(|_| env::current_dir().expect("Failed to get current directory")); | ||
.unwrap_or(env::current_dir().expect("Failed to get current directory")); | ||
base_dir.join(relative_path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters