-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat: add warning for package in a workspace not listed as member #7123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
khayss
wants to merge
4
commits into
FuelLabs:master
Choose a base branch
from
khayss:feat/warn-for-non-workspace-member
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
baa3a8a
feat: add warning for package in a workspace not listed as member
khayss afaed4d
feat: add warning for package in a workspace not listed as member
khayss 6891429
Merge branch 'master' into feat/warn-for-non-workspace-member
khayss 78ce0b4
feat: add warning for package in a workspace not listed as member
khayss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,2 +1,3 @@ | ||
| pub mod defaults; | ||
| pub mod program_type; | ||
| pub mod workspace; |
This file contains hidden or 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,149 @@ | ||
| use std::{ | ||
| env, | ||
| ffi::OsStr, | ||
| path::{Component, Path, PathBuf}, | ||
| }; | ||
|
|
||
| pub fn check_workspace_membership(path: &str, name: &str) {} | ||
|
|
||
| pub fn root_manifest(manifest_path: Option<&Path>, cwd: &Path) -> Result<PathBuf, anyhow::Error> { | ||
| if let Some(manifest_path) = manifest_path { | ||
| let path = cwd.join(manifest_path); | ||
| // In general, we try to avoid normalizing paths in Cargo, | ||
| // but in this particular case we need it to fix #3586. | ||
| let path = normalize_path(&path); | ||
| if !path.ends_with("Cargo.toml") && !is_embedded(&path) { | ||
khayss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| anyhow::bail!("the manifest-path must be a path to a Cargo.toml file") | ||
khayss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| if !path.exists() { | ||
| anyhow::bail!("manifest path `{}` does not exist", manifest_path.display()) | ||
| } | ||
| if path.is_dir() { | ||
| anyhow::bail!( | ||
| "manifest path `{}` is a directory but expected a file", | ||
| manifest_path.display() | ||
| ) | ||
| } | ||
| if is_embedded(&path) { | ||
| anyhow::bail!("embedded manifest `{}` requires `-Zscript`", path.display()) | ||
| } | ||
| Ok(path) | ||
| } else { | ||
| find_root_manifest_for_wd(cwd) | ||
| } | ||
| } | ||
|
|
||
| pub fn find_root_manifest_for_wd(cwd: &Path) -> Result<PathBuf, anyhow::Error> { | ||
khayss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let valid_forc_toml_file_name = "Forc.toml"; | ||
| let invalid_forc_toml_file_name = "forc.toml"; | ||
| let mut invalid_cargo_toml_path_exists = false; | ||
|
|
||
| for current in ancestors(cwd, None) { | ||
| let manifest = current.join(valid_forc_toml_file_name); | ||
| if manifest.exists() { | ||
| return Ok(manifest); | ||
| } | ||
| if current.join(invalid_forc_toml_file_name).exists() { | ||
| invalid_cargo_toml_path_exists = true; | ||
| } | ||
| } | ||
|
|
||
| if invalid_cargo_toml_path_exists { | ||
| anyhow::bail!( | ||
| "could not find `{}` in `{}` or any parent directory, but found cargo.toml please try to rename it to Cargo.toml", | ||
khayss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| valid_forc_toml_file_name, | ||
| cwd.display() | ||
| ) | ||
| } else { | ||
| anyhow::bail!( | ||
| "could not find `{}` in `{}` or any parent directory", | ||
| valid_forc_toml_file_name, | ||
| cwd.display() | ||
| ) | ||
| } | ||
| } | ||
| pub fn normalize_path(path: &Path) -> PathBuf { | ||
| let mut components = path.components().peekable(); | ||
| let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { | ||
| components.next(); | ||
| PathBuf::from(c.as_os_str()) | ||
| } else { | ||
| PathBuf::new() | ||
| }; | ||
|
|
||
| for component in components { | ||
| match component { | ||
| Component::Prefix(..) => unreachable!(), | ||
| Component::RootDir => { | ||
| ret.push(Component::RootDir); | ||
| } | ||
| Component::CurDir => {} | ||
| Component::ParentDir => { | ||
| if ret.ends_with(Component::ParentDir) { | ||
| ret.push(Component::ParentDir); | ||
| } else { | ||
| let popped = ret.pop(); | ||
| if !popped && !ret.has_root() { | ||
| ret.push(Component::ParentDir); | ||
| } | ||
| } | ||
| } | ||
| Component::Normal(c) => { | ||
| ret.push(c); | ||
| } | ||
| } | ||
| } | ||
| ret | ||
| } | ||
|
|
||
| pub fn is_embedded(path: &Path) -> bool { | ||
| let ext = path.extension(); | ||
| (ext == Some(OsStr::new("rs")) || | ||
| // Provide better errors by not considering directories to be embedded manifests | ||
| ext.is_none()) | ||
| && path.is_file() | ||
| } | ||
|
|
||
| pub fn ancestors<'a>(path: &'a Path, stop_root_at: Option<&Path>) -> PathAncestors<'a> { | ||
| PathAncestors::new(path, stop_root_at) | ||
| } | ||
|
|
||
| pub struct PathAncestors<'a> { | ||
| current: Option<&'a Path>, | ||
| stop_at: Option<PathBuf>, | ||
| } | ||
|
|
||
| impl<'a> PathAncestors<'a> { | ||
| fn new(path: &'a Path, stop_root_at: Option<&Path>) -> PathAncestors<'a> { | ||
| // FIXME: This should be checked | ||
| let stop_at = env::var("") | ||
| .ok() | ||
| .map(PathBuf::from) | ||
| .or_else(|| stop_root_at.map(|p| p.to_path_buf())); | ||
| PathAncestors { | ||
| current: Some(path), | ||
| //HACK: avoid reading `~/.cargo/config` when testing Cargo itself. | ||
| stop_at, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<'a> Iterator for PathAncestors<'a> { | ||
| type Item = &'a Path; | ||
|
|
||
| fn next(&mut self) -> Option<&'a Path> { | ||
| if let Some(path) = self.current { | ||
| self.current = path.parent(); | ||
|
|
||
| if let Some(ref stop_at) = self.stop_at { | ||
| if path == stop_at { | ||
| self.current = None; | ||
| } | ||
| } | ||
|
|
||
| Some(path) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.