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

Handle overlapping members and exclude keys #4297

Closed
wants to merge 1 commit into from

Conversation

alexcrichton
Copy link
Member

The longest key takes precedence if there's more than one that matches.

Closes #4089

@rust-highfive
Copy link

r? @matklad

(rust_highfive has picked a reviewer for you, use r? to override)

Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

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

Hm, we support globs in members, don't we? And looks like this is_excluded function does not handle this at all?

});
let mut excludes = exclude.iter()
.map(|p| root_path.join(p))
.filter(|p| manifest_path.starts_with(p));
Copy link
Member

Choose a reason for hiding this comment

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

I think this'll look a tiny bit neater if we add .max_by_key(|p| p.as_os_str().len()) bit here, and then do match (explicit_member, exclude) { ... } simultaneously.

The longest key takes precedence if there's more than one that matches.

Closes rust-lang#4089
@alexcrichton
Copy link
Member Author

Excellent point about globs! I fixed using exclude and globs by using Gitignore, although the glob crate is still used to expand members directives, so I added a comment on the issue to switch to gitignore.

@matklad
Copy link
Member

matklad commented Jul 19, 2017

Let's add a test with globs! :)

I think the scenario which does not work with old is_excluded is this:

Workspace root includes a member foo via glob. Then, if we execute cargo build inside foo, cargo won't detect that it is a member of the workspace.

manifest_path.starts_with(root_path.join(mem))
})
members.iter()
.filter(|p| manifest_path.starts_with(root_path.join(p)))
Copy link
Member

Choose a reason for hiding this comment

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

I think that members can contain globs. That is, p might be like foo/* here, and so this starts_with will fail.

@matklad
Copy link
Member

matklad commented Jul 19, 2017

I think the scenario which does not work with old is_excluded is this:

I though wrong :) Nevertheless, I think this test will be interesting:

~/trash/ws master*
λ tree .
.
├── Cargo.toml
└── foo
    └── baz
        └── bar
            ├── Cargo.toml
            └── src
                └── lib.rs

4 directories, 3 files

~/trash/ws master*
λ cat Cargo.toml
[workspace]
members = ["foo/baz/*"]
exclude = ["foo/"]

Looks like foo/bar/baz should be a member of the workspace.

@behnam
Copy link
Contributor

behnam commented Jul 20, 2017

@alexcrichton, should I take over this one and fix #4089 along the migration to gitignore-matching everywhere?

@behnam
Copy link
Contributor

behnam commented Jul 20, 2017

Also, another difference between workspace.member/exclude vs package.include/exclude is that the package configs are exclusive (if include is set, exclude is ignored silently), but in workspace, turns out both configs can exist at the same time.

I think whatever solution we take here better be aligned with the future of package configs, since I'm hopping we can make those non-exclusive, too.

Here's my suggestion for workspace configs (which we can implement earlier and later expand it to package configs):

  • Treat member and exclude configs as rows of one gitignore, with list in member being added with a ! prefix.

  • Error on negated patterns (patterns starting with !) in any of the configs. (Only allow escaped, literal exclamation mark: \!.)

What do you think?

@alexcrichton
Copy link
Member Author

Sorry yeah @behnam if you wouldn't mind taking this over, that'd be great! I'm quickly losing steam on this :(

I'm also sorry that there's not really a great design here, it's all sort of ad-hoc. My main motivation for this was to remove these lines in the rust-lang/rust repo. Beyond that I've just been attempting to rationalize gitignore/glob pattern, but I get the feeling that it's just becoming more of a mess.

@behnam
Copy link
Contributor

behnam commented Jul 26, 2017

No worries, @alexcrichton. I can get back to this when I get back from the trip next week.

@alexcrichton
Copy link
Member Author

ping @behnam, was just curious if you had a chance to take a look at this again! If you're busy then of course no worries!

@bors
Copy link
Contributor

bors commented Sep 9, 2017

☔ The latest upstream changes (presumably #4469) made this pull request unmergeable. Please resolve the merge conflicts.

bors added a commit that referenced this pull request Oct 10, 2017
[core/workspace] Create WorkspaceRootConfig

Create `WorkspaceRootConfig`, which knows its `root_dir` and lists of
`members` and `excludes`, to answer queries on which paths are a member
and which are not.

----

This is the first step of the fix, that's only a codemod to put together the relevant parts : `workspace.members`, `workspace.excludes`, and the `root_dir` (where `members` and `excludes` are relative to). There's no logic change in this PR to keep review easier.

The added tests are commented out, because they fail with the current logic. The next step to get these steps to pass.

Tracker: <#4089>
Old PR: <#4297>
@alexcrichton
Copy link
Member Author

This never quite panned out, so closing.

@bors
Copy link
Contributor

bors commented Aug 19, 2018

☔ The latest upstream changes (presumably #5907) made this pull request unmergeable. Please resolve the merge conflicts.

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

Successfully merging this pull request may close these issues.

5 participants