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

tests fail when run from published crate with Cargo.toml.orig stripped #15

Closed
dkg opened this issue Nov 2, 2022 · 6 comments
Closed

Comments

@dkg
Copy link

dkg commented Nov 2, 2022

The process of publishing a crate appears to naturally strip the comments in Cargo.toml.

Consequently, when i try to build and run the code in this crate from the published crate, i end up with errors in the self-test.

The published crate (v0.2.6) has this Cargo.toml:

# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.

[package]
edition = "2018"
name = "document-features"
version = "0.2.6"
authors = ["Slint Developers <info@slint-ui.com>"]
description = "Extract documentation for the feature flags from comments in Cargo.toml"
homepage = "https://slint-ui.com"
readme = "README.md"
keywords = [
    "documentation",
    "features",
    "rustdoc",
    "macro",
]
categories = ["development-tools"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/slint-ui/document-features"

[lib]
path = "lib.rs"
proc-macro = true

[dependencies.litrs]
version = "0.2.3"
default-features = false

[features]
default = []
self-test = []

This of course results in:

error: Could not find documented features in Cargo.toml
 --> tests/self-doc.rs:3:5
  |
3 |     document_features::document_features!();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `document_features::document_features` (in Nightly builds, run with -Z macro-backtrace for more info)

This is a concern for me because i'm trying to package the document-features crate in debian, and the debian rust team is currently packaging based on the published crates.

@dkg
Copy link
Author

dkg commented Nov 2, 2022

I'm not sure what the right fix for this is. in debian, i'm patching the crate to reinstate the comment above the feature, but i welcome other suggestions for how to handle this better.

@ogoffart
Copy link
Member

ogoffart commented Nov 2, 2022

Normally, the original should be copied in a Cargo.toml.orig, and we do try to open that file as well:

document-features/lib.rs

Lines 262 to 265 in ba20128

if !cargo_toml.contains("\n##") && !cargo_toml.contains("\n#!") {
// On crates.io, Cargo.toml is usually "normalized" and stripped of all comments.
// The original Cargo.toml has been renamed Cargo.toml.orig
if let Ok(orig) = std::fs::read_to_string(Path::new(&path).join("Cargo.toml.orig")) {

@ogoffart
Copy link
Member

ogoffart commented Nov 3, 2022

I tried running the tests from the package published on crates.io, and they pass.
Maybe debian does some other transform to remove the Cargo.toml.orig?

@dkg
Copy link
Author

dkg commented Nov 3, 2022

Thank you for the prompt response! You've pointed me in the right direction.

Looks like this is indeed a debian-specific problem. dh_clean (the "clean" command for the debhelper packaging tool) defaults to removing any file with a name matching the *.orig glob (among others, see dh_clean(1) for the full list) before starting the build.

Looks like dh_clean can also be directed exclude some things, so in its most simple form we can just tell it to avoid killing Cargo.toml.orig. Since the rust packages are all built with the dh-cargo debhelper buildsystem extension, maybe we can use dh-cargo itself to avoid knocking out that file. I'll see what's possible.

@ogoffart
Copy link
Member

ogoffart commented Nov 3, 2022

I'll close this issue since this is not a bug in the crate.

Thanks for doing the debian packaging.

@ogoffart ogoffart closed this as not planned Won't fix, can't repro, duplicate, stale Nov 3, 2022
@dkg dkg changed the title tests fail when run from published crate tests fail when run from published crate with Cargo.toml.orig stripped Nov 3, 2022
@dkg
Copy link
Author

dkg commented Nov 3, 2022

For anyone who finds this and is interested in following up, i've put the discussion over at https://bugs.debian.org/1023413

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

No branches or pull requests

2 participants