slint-ui / document-features

Extract documentation for the feature flags from comments in Cargo.toml
Apache License 2.0
171 stars 11 forks source link

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

Closed dkg closed 1 year ago

dkg commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Normally, the original should be copied in a Cargo.toml.orig, and we do try to open that file as well: https://github.com/slint-ui/document-features/blob/ba20128b81382fdb40cfbf7aff2c6408a066c236/lib.rs#L262-L265

ogoffart commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

Thanks for doing the debian packaging.

dkg commented 1 year ago

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