-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): remove zksync home (#2022)
## What ❔ <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`. - [ ] Spellcheck has been run via `zk spellcheck`. --------- Signed-off-by: Danil <deniallugo@gmail.com> Co-authored-by: Alex Ostrovski <aov@matterlabs.dev>
- Loading branch information
1 parent
fcbc089
commit d08fe81
Showing
18 changed files
with
198 additions
and
145 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::{ | ||
path::{Path, PathBuf}, | ||
str, | ||
}; | ||
|
||
use anyhow::Context as _; | ||
use once_cell::sync::OnceCell; | ||
|
||
static WORKSPACE: OnceCell<Option<PathBuf>> = OnceCell::new(); | ||
|
||
fn locate_workspace_inner() -> anyhow::Result<PathBuf> { | ||
let output = std::process::Command::new( | ||
std::env::var("CARGO") | ||
.ok() | ||
.unwrap_or_else(|| "cargo".to_string()), | ||
) | ||
.arg("locate-project") | ||
.arg("--workspace") | ||
.output() | ||
.context("Can't find Cargo workspace location")?; | ||
|
||
let output = | ||
serde_json::from_slice::<serde_json::Value>(&output.stdout).with_context(|| { | ||
format!( | ||
"Error parsing `cargo locate-project` output {}", | ||
str::from_utf8(&output.stdout).unwrap_or("(non-utf8 output)") | ||
) | ||
})?; | ||
let root = output.get("root").with_context(|| { | ||
format!("root doesn't exist in output from `cargo locate-project` {output:?}") | ||
})?; | ||
|
||
let serde_json::Value::String(root) = root else { | ||
return Err(anyhow::anyhow!("`root` is not a string: {root:?}")); | ||
}; | ||
let root_path = PathBuf::from(root); | ||
Ok(root_path | ||
.parent() | ||
.with_context(|| format!("`root` path doesn't have a parent: {}", root_path.display()))? | ||
.to_path_buf()) | ||
} | ||
|
||
/// Find the location of the current workspace, if this code works in workspace | ||
/// then it will return the correct folder if, it's binary e.g. in docker container | ||
/// you have to use fallback to another directory | ||
/// The code has been inspired by `insta` | ||
/// `https://github.com/mitsuhiko/insta/blob/master/insta/src/env.rs` | ||
pub fn locate_workspace() -> Option<&'static Path> { | ||
// Since `locate_workspace_inner()` should be deterministic, it makes little sense to call | ||
// `OnceCell::get_or_try_init()` here; the repeated calls are just as unlikely to succeed as the initial call. | ||
// Instead, we store `None` in the `OnceCell` if initialization failed. | ||
WORKSPACE | ||
.get_or_init(|| { | ||
let result = locate_workspace_inner(); | ||
if let Err(err) = &result { | ||
// `get_or_init()` is guaranteed to call the provided closure once per `OnceCell`; | ||
// i.e., we won't spam logs here. | ||
tracing::warn!("locate_workspace() failed: {err:?}"); | ||
} | ||
result.ok() | ||
}) | ||
.as_deref() | ||
} | ||
|
||
/// Returns [`locate_workspace()`] output with the "." fallback. | ||
pub fn workspace_dir_or_current_dir() -> &'static Path { | ||
locate_workspace().unwrap_or_else(|| Path::new(".")) | ||
} |
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
Oops, something went wrong.