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

Conventions #4259

Merged
merged 33 commits into from
Jul 11, 2017
Merged

Conventions #4259

merged 33 commits into from
Jul 11, 2017

Conversation

matklad
Copy link
Member

@matklad matklad commented Jul 8, 2017

r? @alexcrichton

I'd love to refactor our handing of inferring targets by convention, because it is super difficult to understand, and quite probably contains a couple of unintended/undocumented conventions (like src/foo.rs being a binary foo if there's no library in the package).

As a first step, I've just moved all the logic (600 loc) to a separate file from the toml.rs file, which used to be just huge (we even use in in IntelliJ Rust for performance testing :) ), and now it is "only" just above 1kloc :)

@matklad matklad requested review from alexcrichton and removed request for alexcrichton July 8, 2017 18:57
@matklad
Copy link
Member Author

matklad commented Jul 8, 2017

Ok, the next bunch of commits does some refactorings and deduplication. The main achievement so far is that we've got rid of normalize function which used a ton of impenetrable high order closure.

Also, some error messages are cleaned up a bit.

@matklad
Copy link
Member Author

matklad commented Jul 9, 2017

And the next bunch of commits actually makes some algorithmic changes:

  • we no longer use different algorithms for inferring whole targets and for inferring a path for the target, of which only the name is know.

  • we now warn about some conventions, which presumably shouldn't be conventions at all, but slipped due to the usage of two different algortithms from the previous bullet. This actually caused some churn in tests, because they used old conventions.

matklad added 3 commits July 9, 2017 16:18
While `/` do work on windows, the resulting path will have literal `/`
in its display.
@alexcrichton
Copy link
Member

This is looking great to me, thanks so much @matklad! Mind detailing the deprecation warnings here as well? (just in a comment). I've tagged this relnotes now but just want to make sure we know what to put in the release notes!

@alexcrichton alexcrichton added the relnotes Release-note worthy label Jul 10, 2017
@matklad
Copy link
Member Author

matklad commented Jul 10, 2017

Mind detailing the deprecation warnings here as well? (just in a comment)

Sure! There are several cases, which I think are "accidental" and are deprecated here

  • if you have a [lib] name = "foo" in your Cargo.toml, we treated src/foo.rs as a crate root. The fix is either to set path or to rename src/foo.rs to src/lib.rs

  • if you don't have a library, but you have [bin] name = "foo", we treated src/foo.rs as a (binary) crate root. The fix is to add path or to move to src/bin/foo.rs.

  • if you have a [bin] name = "bar", but your package's name is foo, we still treated src/main.rs or src/bin/main.rs as a bar's crate root, and now we warn. If binary names is the same as the package itself, then the behavior stays the same.

At least, these are all cases I intended to warn about, there maybe some unexpected stuff though!

However, almost all the changes to tests were to silence the warnings (eg, they compiled OK, but failed in with_stderr).

There was a single edge case where there is a genuine regression (and I really should have written about it before). In the tests, there was [lib] name = "foo" pattern, but src/foo.rs was generated by the build script from src/foo.rs.in. This happens because in "legacy mode" we check that file actually exists, before producing a warning, to avoid false positives. And in this case it's not really there, because the build script was not run yet. I ... don't know how to fix this neatly, but imo this is a really edgy edge case, and it was intended to be deprecated long ago:

// this is testing that src/<pkg-name>.rs still works (for now)
:-)

@alexcrichton
Copy link
Member

Ok that all sounds good to me and this seems like a great refactoring, so let's...

@bors: r+

@bors
Copy link
Contributor

bors commented Jul 11, 2017

📌 Commit 71e6629 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jul 11, 2017

⌛ Testing commit 71e6629 with merge 1566c92...

bors added a commit that referenced this pull request Jul 11, 2017
Conventions

r? @alexcrichton

I'd love to refactor our handing of inferring targets by convention, because it is super difficult to understand, and quite probably contains a couple of unintended/undocumented conventions (like `src/foo.rs` being a binary `foo` if there's no library in the package).

As a first step, I've just moved all the logic (600 loc) to a separate file from the `toml.rs` file, which used to be just **huge** (we even use in in IntelliJ Rust for performance testing :) ), and now it is "only" just above 1kloc :)
@bors
Copy link
Contributor

bors commented Jul 11, 2017

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

@bors bors merged commit 71e6629 into rust-lang:master Jul 11, 2017
danburkert added a commit to tokio-rs/prost that referenced this pull request Jul 16, 2017
This follows Cargo conventions. Cargo recently began warning when the
convention is not followed: rust-lang/cargo#4259.
@matklad matklad deleted the conventions branch September 14, 2017 23:22
@ehuss ehuss added this to the 1.20.0 milestone Feb 6, 2022
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.

4 participants