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

Changed how Cargo.toml of baseline is being built, added all features to baseline's manifest #173

Merged
merged 12 commits into from
Nov 10, 2022

Conversation

tonowak
Copy link
Collaborator

@tonowak tonowak commented Nov 8, 2022

Fixes #147
Tested on the repo from this issue - seems to work. (Should I write some tests besides manually checking?)

In the issue you mentioned deleting the baseline's Cargo.lock. Is it also needed here? I don't really understand why this step is necessary.

Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

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

Excited to merge this, it looks good! Just a few small points worth discussing before we merge.

src/baseline.rs Outdated
Comment on lines 304 to 305
toml::to_string(&manifest)?.replace("edition = \"2021\"", ""),
// tonowak to obi1kenobi: do you know why this replace is necessary?
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure, why did you need to add it? :) Would it cause any harm to leave the edition key in the TOML?

Also, consider making these comments as GitHub comments on the PR itself for future PRs? That way we can't miss them either in terms of discussing them or in terms of remembering to remove them later when they've been sorted out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure, why did you need to add it? :) Would it cause any harm to leave the edition key in the TOML?

I had an error without removing the edition, I'll try to reproduce the error and paste it here when I'll have some time.

Also, consider making these comments as GitHub comments on the PR itself for future PRs? That way we can't miss them either in terms of discussing them or in terms of remembering to remove them later when they've been sorted out.

Sounds reasonable, but then I could forget to comment something after creating the PR...

Copy link
Owner

Choose a reason for hiding this comment

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

Sounds reasonable, but then I could forget to comment something after creating the PR...

You could perhaps keep these notes in a personal local file, and then turn them into comments as you open the PR? That way they aren't in the source code but they are written down before opening the PR.

I usually keep a notes file like this for myself to keep track of everything that's in progress, and I'd recommend it as a process in general.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had an error without removing the edition, I'll try to reproduce the error and paste it here when I'll have some time.

Error: Failed when running cargo-doc on ../rust-libp2p/target/semver-checks/registry-libp2p_core-0_37_0/Cargo.toml: error: cannot specify features for packages outside of workspace

Copy link
Owner

Choose a reason for hiding this comment

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

Is it perhaps getting confused about the fact that the target dir is inside the workspace of the other Cargo.toml? Here's what I'd suggest:

  • Try reproducing the error with a manual call to cargo from the terminal.
  • Then try moving the target directory somewhere else, outside of the workspace of libp2p, and try reproducing the error again with the same call.

I'm a bit worried about the edition removal because it feels like there might be a deeper issue here and the edition is just a symptom rather than the cause.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The smallest breaking Cargo.toml seems to be

[package]
name = "rustdoc"
edition = "2021"
version = "0.0.0"

[workspace]

[dependencies]
libp2p = "0.37.0"

[lib]
path = "lib.rs"

with an empty lib.rs.

Copy link
Owner

Choose a reason for hiding this comment

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

Re-reading the error message one more time, I think the issue is about attempting to combine --all-features with --package libp2p-core. The libp2p-core package is a dependency of the project and as such its features are specified in the Cargo.toml, so we can't run --all-features on it because what if the Cargo.toml entry for it specifies some other set of features? In other words, --all-features only makes sense in the context of commands applied to the source code corresponding to the Cargo.toml, and does not make sense for dependency packages where features are specified elsewhere.

I think the answer is to not include --all-features in the "make fake project + get rustdoc of the dependency" branch of cargo-semver-checks.

Copy link
Owner

Choose a reason for hiding this comment

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

I think this is the only remaining item for this PR, otherwise it's ready to merge.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, I'll do it in 2-3h

Copy link
Owner

Choose a reason for hiding this comment

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

No rush, whenever you have a moment is fine.

Cargo.toml Show resolved Hide resolved
src/baseline.rs Outdated Show resolved Hide resolved
@obi1kenobi
Copy link
Owner

obi1kenobi commented Nov 9, 2022

Fixes #147 Tested on the repo from this issue - seems to work. (Should I write some tests besides manually checking?)

It would be great to have a test, since this is a tricky issue that would be a pain to debug again if we had a regression.

What do you think would be the best and easiest way to test this? It's a little bit tricky since the issue only happens when using a baseline from crates.io.

In the issue you mentioned deleting the baseline's Cargo.lock. Is it also needed here? I don't really understand why this step is necessary.

Since we'd be emitting a brand new Cargo.toml in the baseline directory, it's probably a good idea to ensure the baseline directory is empty and freshly created, for example by deleting it completely if it already existed.

I'm not sure why I had a problem with Cargo.lock, but the easiest way to not have the problem is to not have any files (including the lockfile) in the baseline directory when writing the new Cargo.toml.

This is another case of "it's better to not have to debug this later." :)

@tonowak
Copy link
Collaborator Author

tonowak commented Nov 9, 2022

What do you think would be the best and easiest way to test this? It's a little bit tricky since the issue only happens when using a baseline from crates.io.

It is tempting to add a test that checks for this problem from a selected crate from crates.io, but that would require internet connection. From one side, it seems weird to require access to crates.io during testing, but from the other side, cargo-semver-checks requires it when running the tool. What is your opinion?

@obi1kenobi
Copy link
Owner

It is tempting to add a test that checks for this problem from a selected crate from crates.io, but that would require internet connection. From one side, it seems weird to require access to crates.io during testing, but from the other side, cargo-semver-checks requires it when running the tool. What is your opinion?

I agree we probably don't want to trigger this at cargo test time, for the reasons you laid out.

How about a test script that gets run on GitHub Actions, as a sort of integration test? For example, it could clone the specific repo and commit where we found this problem, and assert that the false-positive is gone i.e. that running cargo-semver-checks with the appropriate flags exits cleanly.

@tonowak
Copy link
Collaborator Author

tonowak commented Nov 9, 2022

So then I would need to edit https://github.com/obi1kenobi/cargo-semver-check/blob/main/.github/workflows/ci.yml right?
I guess the test would clone the rust-libp2p repo with a given relative path and rev and then it would run cargo run on it?

@obi1kenobi
Copy link
Owner

So then I would need to edit https://github.com/obi1kenobi/cargo-semver-check/blob/main/.github/workflows/ci.yml right? I guess the test would clone the rust-libp2p repo with a given relative path and rev and then it would run cargo run on it?

Yeah, that was what I had imagined, but I'm not tied to that idea or approach. If you have an alternative idea on how to add a regression test for this, I'd love to know about it!

@tonowak
Copy link
Collaborator Author

tonowak commented Nov 9, 2022

That idea seems good enough for me. I don't really see another way to test this specific problem without connecting to crates.io during cargo test. And this approach would also potentially find other bugs (connection to crates.io is needed for the tool to work and it is good to check on an example that it works)

@tonowak
Copy link
Collaborator Author

tonowak commented Nov 9, 2022

I think I'll add an issue and try to write a new PR for the GitHub Action integration tests and leave this PR without any tests. It seems that those tests would be beneficial not only to this particular PR. What do you think?

@obi1kenobi
Copy link
Owner

That sounds good. We should just avoid making new releases before those tests are in, which should be okay.

src/baseline.rs Outdated Show resolved Hide resolved
src/baseline.rs Show resolved Hide resolved
src/baseline.rs Outdated Show resolved Hide resolved
src/baseline.rs Outdated Show resolved Hide resolved
src/dump.rs Show resolved Hide resolved
src/baseline.rs Outdated Show resolved Hide resolved
@obi1kenobi obi1kenobi enabled auto-merge (squash) November 10, 2022 23:49
@obi1kenobi obi1kenobi merged commit b015efd into obi1kenobi:main Nov 10, 2022
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.

False positive: baseline rustdoc built from registry version only includes default features
2 participants