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

fix(embedded): Align package name sanitization with cargo-new #12255

Merged
merged 5 commits into from
Jun 17, 2023

Conversation

epage
Copy link
Contributor

@epage epage commented Jun 12, 2023

What does this PR try to resolve?

This is a follow up to #12245 which is working to resolve the tracking issue #12207

This first aligns sanitization of package names with the central package name validation logic, putting the code next to each other so they can more easily stay in sync.

Oddly enough, cargo-new is stricter than our normal package-name validation. I went ahead and sanitized along with that as well.

In working on this, I was bothered by

  • the mix of - and _ in file names because of sanitization, so I made it more consistent by detecting which the user is using
  • -using _ in bins, so I switched the default to -

How should we test and review this PR?

One existing test covers a variety of sanitization needs

Another existing test hit one of the other cases (test being reserved)

Additional information

For implementation convenience, I changed the directory we write the manifest to. The impact of this should be minimal since

  • We reuse the full file name, so if it worked for the user it should work for us
  • We should be moving away from the temp manifest in future commits

@rustbot
Copy link
Collaborator

rustbot commented Jun 12, 2023

r? @weihanglo

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

@rustbot rustbot added Command-new S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 12, 2023
@epage epage marked this pull request as draft June 12, 2023 20:39
@epage epage force-pushed the sanitize branch 2 times, most recently from 697edc0 to 570c5df Compare June 13, 2023 01:34
@epage epage marked this pull request as ready for review June 13, 2023 01:34
@epage epage marked this pull request as draft June 13, 2023 13:22
@epage epage mentioned this pull request Jun 13, 2023
@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. Command-run labels Jun 13, 2023
bors added a commit that referenced this pull request Jun 13, 2023
refactor(embedded)

### What does this PR try to resolve?

This is trying to make it easier to have multiple active PRs touching `embedded.rs` by separating out the parts of the code that will be touched in each PR.  This is done by making the code roughly follow how the future code will be structured.

e.g. see #12255

### How should we test and review this PR?

Commit at a time.  This is just a refactor, so no tests are changed.
@epage epage marked this pull request as ready for review June 13, 2023 16:54
@bors
Copy link
Contributor

bors commented Jun 14, 2023

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

@epage epage marked this pull request as draft June 15, 2023 17:00
@epage epage marked this pull request as ready for review June 16, 2023 00:15
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Just some minor issues. Thanks you!

src/cargo/util/toml/embedded.rs Outdated Show resolved Hide resolved
src/cargo/util/toml/embedded.rs Outdated Show resolved Hide resolved
@weihanglo
Copy link
Member

Oddly enough, cargo-add is stricter than our normal package-name validation. I went ahead and sanitized along with that as well.

BTW, I guess you meant cargo new?

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Thanks!

@weihanglo weihanglo changed the title fix(embedded): Align package name sanitization with cargo-add fix(embedded): Align package name sanitization with cargo-new Jun 17, 2023
@weihanglo
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 17, 2023

📌 Commit 667ff78 has been approved by weihanglo

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 17, 2023
@bors
Copy link
Contributor

bors commented Jun 17, 2023

⌛ Testing commit 667ff78 with merge 3b5fac5...

@bors
Copy link
Contributor

bors commented Jun 17, 2023

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing 3b5fac5 to master...

1 similar comment
@bors
Copy link
Contributor

bors commented Jun 17, 2023

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing 3b5fac5 to master...

@bors
Copy link
Contributor

bors commented Jun 17, 2023

👀 Test was successful, but fast-forwarding failed: 422 Changes must be made through a pull request.

@bors bors merged commit 3b5fac5 into rust-lang:master Jun 17, 2023
@epage epage deleted the sanitize branch June 17, 2023 02:03
bors added a commit that referenced this pull request Jun 17, 2023
fix(embedded): Don't create an intermediate manifest

### What does this PR try to resolve?

More immediately, this is to unblock rust-lang/rust#112601

More generally, this gets us away from hackily writing out an out-of-line manifest from an embedded manifest.  To parse the manifest, we have to write it out so our regular manifest
loading code could handle it.  This updates the manifest parsing code to
handle it.

This doesn't mean this will work everywhere in all cases though.  For
example, ephemeral workspaces parses a manifest from the SourceId and
these won't have valid SourceIds.

As a consequence, `Cargo.lock` and `CARGO_TARGET_DIR` are changing from being next to
the temp manifest to being next to the script.  This still isn't the
desired behavior but stepping stones.

### How should we test and review this PR?

A Commit at a time

### Additional information

In production code, this does not conflict with #12255 (due to #12262) but in test code, it does.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 20, 2023
Update cargo

12 commits in 0c14026aa84ee2ec4c67460c0a18abc8519ca6b2..dead4b8740c4b6a8ed5211e37c99cf81d01c3b1c
2023-06-14 18:43:05 +0000 to 2023-06-20 20:07:17 +0000
- Convert valid feature name warning to an error. (rust-lang/cargo#12291)
- fix(embedded): Don't pollute script dir with lockfile (rust-lang/cargo#12284)
- fix: remove `-Zjobserver-per-rustc` again (rust-lang/cargo#12285)
- docs: some tweaks around `cargo test` (rust-lang/cargo#12288)
- Enable `doctest-in-workspace` by default (rust-lang/cargo#12221)
- fix(embedded): Don't auto-discover build.rs files (rust-lang/cargo#12283)
- fix(embeded): Don't pollute the scripts dir with `target/` (rust-lang/cargo#12282)
- feat: prepare for the next lockfile bump (rust-lang/cargo#12279)
- fix(embedded): Don't create an intermediate manifest (rust-lang/cargo#12268)
- refactor(embedded): Switch to `syn` for parsing doc comments (rust-lang/cargo#12258)
- fix(embedded): Align package name sanitization with cargo-new (rust-lang/cargo#12255)
- Clarify the default behavior of cargo-install. (rust-lang/cargo#12276)

r? `@ghost`
@ehuss ehuss added this to the 1.72.0 milestone Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. Command-new Command-run S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants