Skip to content
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

Support glob syntax in workspace members #3979

Merged
merged 6 commits into from
May 16, 2017
Merged

Conversation

hjr3
Copy link
Contributor

@hjr3 hjr3 commented Apr 29, 2017

Fixes #3911

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

}

for path in expanded_list {
let manifest_path = path.join("Cargo.toml");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this error if there's a path without Cargo.toml matched by the glob? I would say that it's OK to bail in this case, but that just skipping that path would be probably more useful: I often have various assorted folders alongside the workspace packages.

In any case, I think a test case for this would be useful :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call out. I will get on it.

@alexcrichton
Copy link
Member

Thanks for the PR @hjr3! Looks good to me but I'd share the same concerns as @matklad, mayb ejust add a test to see what the error looks like?

@alexcrichton alexcrichton added the relnotes Release-note worthy label May 2, 2017
@alexcrichton
Copy link
Member

Also mind updating the workspace documentation to mention that globs may be used?

@hjr3
Copy link
Contributor Author

hjr3 commented May 2, 2017

@alexcrichton sure, i can update the docs too!

@nipunn1313
Copy link
Contributor

Thanks @hjr3! I'm looking forward to this one (we currently have a big setup with a script to autogenerate the workspace members).

@hjr3
Copy link
Contributor Author

hjr3 commented May 7, 2017

Apologies for taking so long to update this PR. I have updated the docs. Is it ok to reuse the globs URL like I did? It renders correctly with my testing.

I also added the test to shows what happens with a workspace path does not have a Cargo.toml file. As expected, it throws an error. I would expect that someone would add that to the exclude array though. Is that good enough? If it is, does the error message need to be improved? Should I mention that in the docs?

@alexcrichton
Copy link
Member

Looks good to me, but the tests seem to be failing? The new invalid_members test also seems to not have an error message :(

- fix glob missing members test to use proper expectations
- update code to handle case where glob does not match anything
@hjr3
Copy link
Contributor Author

hjr3 commented May 9, 2017

@alexcrichton ok i fixed glob_syntax_invalid_members to have the proper expectations. The invalid_members test was failing because that member path does not actually exist and the glob will ignore it. If expanded the member path returns an empty list, I default to the original (non-expanded) value. That could be weird in some cases though if someone specifies a pattern that does not match anything. It might be better to return an error if the pattern does not match anything?

@@ -527,6 +544,18 @@ impl<'cfg> Workspace<'cfg> {
}
}

fn expand_member_path(path: &Path) -> CargoResult<Vec<PathBuf>> {
let path = path.to_str().unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the None case be handled here instead of unwrap? (returning an empty Vec)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -527,6 +544,18 @@ impl<'cfg> Workspace<'cfg> {
}
}

fn expand_member_path(path: &Path) -> CargoResult<Vec<PathBuf>> {
let path = path.to_str().unwrap();
let res = glob(path).map_err(|e| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this use .chain_error instead of .map_err?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something here, but I don't see how .chain_error can be used with Result<glob::Paths, glob::PatternError>.

human(format!("could not parse pattern `{}`: {}", &path, e))
})?;
res.map(|p| {
p.or_else(|e| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, could this use chain_error?

@alexcrichton
Copy link
Member

Nah this seems like a reasonable interpretation to me I think, thanks!

@alexcrichton
Copy link
Member

@hjr3 mind updating to using chain_error instead of map_err in a few locations as well?

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Collaborator

bors commented May 16, 2017

📌 Commit f00c223 has been approved by alexcrichton

@hjr3
Copy link
Contributor Author

hjr3 commented May 16, 2017

@alexcrichton thanks, i was just about to push this same patch. it took me some time to figure out how to get the chain_error working for glob.

@bors
Copy link
Collaborator

bors commented May 16, 2017

⌛ Testing commit f00c223 with merge 828a9c5...

bors added a commit that referenced this pull request May 16, 2017
Support glob syntax in workspace members

Fixes #3911
@alexcrichton
Copy link
Member

Oh sorry about that! I was just going through old Cargo PRs and figured this could use a bit of a boost :)

@bors
Copy link
Collaborator

bors commented May 16, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 828a9c5 to master...

@bors bors merged commit f00c223 into rust-lang:master May 16, 2017
@Astlaan
Copy link

Astlaan commented Feb 16, 2024

How to use?

[workspace]

members = [
    "./*"
]

gives an error

@Rustin170506
Copy link
Member

@Astlaan What is the error? Could you please open a new issue instead of leaving a comment here, as this PR was closed 7 years ago.

If it is a usage issue, https://users.rust-lang.org/ may be a better place to ask this type of question.

@Astlaan
Copy link

Astlaan commented Feb 17, 2024

@Astlaan What is the error? Could you please open a new issue instead of leaving a comment here, as this PR was closed 7 years ago.

If it is a usage issue, https://users.rust-lang.org/ may be a better place to ask this type of question.

Sorry, this is what I wrote:

[workspace]

members = [
    "./*"
]

But apparently with fails with an error like:

cargo check
error: failed to load manifest for workspace member C:\Users\user\Documents\ProjectA\.\.git

Caused by:
  failed to read `C:\Users\user\Documents\ProjectA\ .git\Cargo.toml

It's it possible to have it not fail and simply add as members folders that do have a Cargo.toml?

@weihanglo
Copy link
Member

@Astlaan you can use workspace.exclude to exclude folder not intended to be a member.

See #11405 for tracking the workspace globbing issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Release-note worthy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cargo should support glob syntax in workspace members
10 participants