Skip to content

Support glob syntax in workspace members#3979

Merged
bors merged 6 commits into
rust-lang:masterfrom
hjr3:issue-3911
May 16, 2017
Merged

Support glob syntax in workspace members#3979
bors merged 6 commits into
rust-lang:masterfrom
hjr3:issue-3911

Conversation

@hjr3

@hjr3 hjr3 commented Apr 29, 2017

Copy link
Copy Markdown
Contributor

Fixes #3911

@rust-highfive

Copy link
Copy Markdown

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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@hjr3

hjr3 commented May 2, 2017

Copy link
Copy Markdown
Contributor Author

@alexcrichton sure, i can update the docs too!

@nipunn1313

Copy link
Copy Markdown
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

hjr3 commented May 7, 2017

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

hjr3 commented May 9, 2017

Copy link
Copy Markdown
Contributor Author

@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?

Comment thread src/cargo/core/workspace.rs Outdated
}

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread src/cargo/core/workspace.rs Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
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>.

Comment thread src/cargo/core/workspace.rs Outdated
human(format!("could not parse pattern `{}`: {}", &path, e))
})?;
res.map(|p| {
p.or_else(|e| {

Copy link
Copy Markdown
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
Copy Markdown
Member

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

@alexcrichton

Copy link
Copy Markdown
Member

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

@alexcrichton

Copy link
Copy Markdown
Member

@bors: r+

@bors

bors commented May 16, 2017

Copy link
Copy Markdown
Contributor

📌 Commit f00c223 has been approved by alexcrichton

@hjr3

hjr3 commented May 16, 2017

Copy link
Copy Markdown
Contributor Author

@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

bors commented May 16, 2017

Copy link
Copy Markdown
Contributor

⌛ 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
Copy Markdown
Member

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

@bors

bors commented May 16, 2017

Copy link
Copy Markdown
Contributor

☀️ 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
@diogovalada

Copy link
Copy Markdown

How to use?

[workspace]

members = [
    "./*"
]

gives an error

@0xPoe

0xPoe commented Feb 17, 2024

Copy link
Copy Markdown
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.

@diogovalada

diogovalada commented Feb 17, 2024

Copy link
Copy Markdown

@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
Copy Markdown
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