215 Commits

Author SHA1 Message Date
Ed Page
5e35e271bc feat(toml): Add autolib
PR #5335 added `autobins`, etc for #5330.  Nowhere in there is
discussion of `autolib`.

Cargo script disables support for additional build-targets by disabling
discovery.
Except we don't have a way to disable discovery of `autolib`, leading to #14476.
By adding `autolib`, we can continue in that direction.

This also allows us to bypass inferring of libs on published packages,
like all other build-targets which were handled in #13849.

As this seems fairly low controversy, this insta-stabilizes the field.
In prior versions of Cargo, users will get an "unused manifest key"
warning.
For packags where this is set by `cargo publish`, the warning will be suppressed and things will work as normal.
For `cargo vendor`, the same except there will be some churn in the
vendored source as this field will now be set.
For local development, it should be rare to set `autolib` so the lack of
error by discovering a file when this is set shouldn't be a problem.

Fixes #14476
2024-09-24 11:24:24 -05:00
Weihang Lo
5dfdd59009
feat: make lockfile v4 the default
This commit makes lockfile version 4 the default version when Cargo
tries to write to a lockfile.

The lockfile version 4 has been stabilized since 1.78.0,
and will become default in 1.83.0.
the length of transition period is pretty similar as before.

One caveat is that in other output from Cargo,
e.g., `cargo metatada`, status messages,
`SourceID` will display in the v4 URL encoded format.
This shouldn't affect the majority of Rust users,
as `SourceId` representation should be opaque to them,
unless comparing `SourceId` across different version of toolchains.
2024-09-24 20:43:02 -04:00
Ed Page
a6cf1be655 test: Switch from allow to expect deprecated
This caught a couple of lingering items.
2024-09-23 20:44:06 -05:00
Joe Neeman
4110b844fb Filter package specs while packaging 2024-08-30 10:10:46 +07:00
Joe Neeman
653025fdd5 Add test for package filtering with old edition 2024-08-30 10:10:46 +07:00
Joe Neeman
96d4d6f6cb Allow unpublishable crates to be packaged 2024-08-20 10:41:19 +07:00
Joe Neeman
a9987f0982 Use the shared source building in package
This changes the registry validation slightly, adding in a check
forbidding implicit source replacement. This affects the tests (which
configure a dummy registry for source replacement), so we also weaken
the checks by only erroring for registry issues when there are actually
local dependencies.
2024-08-20 10:41:09 +07:00
Joe Neeman
7919bda55f Add misbehaving test for packaging unpublishable workspace 2024-08-19 13:16:46 +07:00
bors
b66cad8038 Auto merge of #14359 - linyihai:issue-14354, r=weihanglo
Fix: `cargo package` failed on bare commit git repo.

### What does this PR try to resolve?
Fixes #14354

This approach chose to not generate a `.cargo_vcs_info.json` for bare commit git repo.

### How should we test and review this PR?
Compare the test changes before and after the two commits

### Additional information
2024-08-08 21:22:58 +00:00
Lin Yihai
37cda2d9a0 feat: don't generate .cargo_vcs_info.json if git repro has no commit 2024-08-08 09:57:39 +08:00
Lin Yihai
ab4ab66c60 fix: cargo package failed on bare commit git repo 2024-08-08 09:57:39 +08:00
Lin Yihai
a562387d2b test: Add test for issue-14354
This a test to reflect that `cargo package --allow-dirty` will fail on a bare commit git repo
2024-08-08 09:57:39 +08:00
Joe Neeman
275d3b6e54 Change registry inference rules when packaging multiple packages
Infer the package registry only if all packages have the same publish
field. If there is confusion, bail out instead of defaulting to
crates-io.
2024-08-07 21:55:11 +07:00
Joe Neeman
010db83cf5 Add misbehaving tests. 2024-08-07 21:53:56 +07:00
Joe Neeman
a2f0a9e7d6 Adds support for packaging workspaces.
Takes local dependencies into account when packaging a workspace. Builds
a temporary package registry to provide local dependencies, and overlays
it on the upstream registry.

This adds `--registry` and `--index` flags to `cargo package`. They act
much like the same arguments to `cargo publish`, except that of course
we are not actually publishing to the specified registry. Instead, these
arguments affect lock-file generation for intra-workspace dependencies:
when simultaneously packaging a crate and one of its dependencies, the
lock-file will be generated under the assumption that the dependency
will be published to the specified registry.

Co-Authored-By: Tor Hovland <55164+torhovland@users.noreply.github.com>
2024-07-24 16:36:30 +07:00
Joe Neeman
cbc836d4b0 Add tests showing incorrect workspace packaging.
Co-Authored-By: Tor Hovland <55164+torhovland@users.noreply.github.com>
2024-07-24 16:03:51 +07:00
Ed Page
d17322dccb fix(test): Move path2url to CargoPathExt::to_url
I was considering moving this into `paths` and noticed `CargoPathExt`.
I figured if we had any extension traits for `Path`, then this is a
reasonable one to add.
2024-07-18 15:41:26 -05:00
Ed Page
3a615ca9c8 feat(test): Add CargoPathExt to prelude 2024-07-18 15:22:29 -05:00
Ed Page
5b9799c6f4 refactor: Migrate from extern crate to test-support prelude
We now include the prelude in so many places, this simplifies how we can
present how `cargo-test-support` works.

Yes, this included some `use` clean ups but its already painful enough
walking through every test file, I didn't want to do it twice.
2024-07-12 15:57:00 -05:00
eth3lbert
5efed1bfdf
test: migrate package to snapbox 2024-06-27 12:55:34 +08:00
Tor Hovland
e7bfed103c Skip serializing the dirty flag if false. 2024-06-24 13:02:25 +02:00
Tor Hovland
1b636855a9 Add a dirty flag to the vcs_info file. 2024-06-24 13:02:25 +02:00
Tor Hovland
2a1299a878 fix: Include vcs_info even if workspace is dirty. 2024-06-24 13:02:25 +02:00
Tor Hovland
a6ad3a3ed5 test: Verify that the vcs_info file is not included in package when allowing dirty. 2024-06-24 13:02:25 +02:00
Joe Neeman
c0287bec8d Change verification order during packaging.
Once we support packaging workspaces with dependencies, dependency
packages need to be built before anything is verified. In addition to a
little refactoring, this commit reorders the console messages so that
package metadata (archive size, etc.) is reported before verification
results.

Co-Authored-By: Tor Hovland <55164+torhovland@users.noreply.github.com>
2024-06-14 15:15:03 -05:00
Ed Page
dc5ac62cab fix(test): Deprecate non-snapbox assertions
While this is noisy and hides other deprecations, I figured deprecations would
make it easier for people to discover what tasks remain and allow us to
divide and conquer this work rather than doing a heroic PR.
In theory, this will be short lived and we'll go back to seeing
deprecations in our tests.
2024-06-10 10:20:52 -05:00
bors
ab85225804 Auto merge of #13921 - heisen-li:licence_readme_warning, r=weihanglo
fix(toml): Convert warnings that `licence` and `readme` files do not exist into errors

### What does this PR try to resolve?

In this PR:
- Changed the warning to a hard error and modified the associated test function;
- Removed what should have been a redundant test function:`publish::publish_with_missing_readme`;
- Since `cargo publish` is preceded by the execution of `cargo package`, the error message in the test `function bad_license_file` needs to be modified.

issue: https://github.com/rust-lang/cargo/issues/13629#license-file-and-readme-pointing-to-a-non-existent-file.

### Additional information

It seems that this is not enough, the current situation is that `cargo package` warns if `package.readme` is an empty string or the wrong file location, but if I cancel `package.readme`, no warning is generated.

I'm wondering if I should judge `package.readme&licence` when executing `cargo package` and return an error if it doesn't exist?

As this has not been done before, your advice is sought.
2024-06-09 13:02:50 +00:00
heisen-li
193319c66c fix(toml): Convert warnings that license and readme files do not exist into errors 2024-06-04 12:32:18 +08:00
Ed Page
150461cdec fix(vendor): Ensure sort happens for vendor 2024-06-03 10:34:41 -05:00
Ed Page
81b1bb1580 test(package): Ensure order is consistent 2024-06-03 09:10:05 -05:00
Ed Page
06a57142f1 fix(toml): Warn, rather than fail publish, if targets are excluded
This could offer performance gains when parsing a published
manifest since the targets don't need to be discovered.
To see this, we'd first need to stop discovering potential targets even when it isn't
needed.
2024-04-29 12:25:56 -05:00
Ed Page
1e6047763d fix(toml): Warn, rather than fail publish, if build.rs is excluded
This could offer a minor performance gain when reading this manifest
since the target doesn't need to be discovered.
2024-04-29 12:25:19 -05:00
Ed Page
39f1a210b8 perf(toml): Avoid looking up readme on published packages
Not much of a performance gain;
this is mostly done to be consistent with the target work.
2024-04-29 12:25:19 -05:00
Ed Page
0cf29c5713 test(package): Show different crate discovery cases
I left off the explicit `path` cases because I hope that will become
moot
2024-04-29 12:25:19 -05:00
Ed Page
340050e0cb test(package): Show current case behavior 2024-04-29 12:25:19 -05:00
bors
7ac5d58f36 Auto merge of #13735 - linyihai:package-no-match, r=epage
`cargo package -p no-exist` emitt  error when the -p `package` not found

### What does this PR try to resolve?

Fixes #13719

If `-p` is used, and the spec doesn't match any member, we emit an error  like `cargo publish -p` does.

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

The first commit add a test to show the issue, the next commit add the check logic to fix it.

### Additional information
2024-04-12 16:27:02 +00:00
Lin Yihai
decbadb36f fix: cargo package -p includes all packages if no match is found 2024-04-12 10:57:58 +08:00
Lin Yihai
ac7bf6eb19 test(package): cargo package -p doesnt-exist will package all packages in workspace 2024-04-12 10:57:35 +08:00
Ed Page
8b593e5ba7 fix(package): Normalize path separators
A windows user could use `\` and no Linux or Mac user could use the
package.
This normalizes the separator to what works on all platforms.
2024-04-09 21:29:08 -05:00
Ed Page
5539293cf6 fix(package): Normalize paths in published Cargo.toml
For now, this is more for visual consistency.
However, this blocks #13713 as we need to be able to make these paths
comparable to what is included in the package.
2024-04-09 20:57:25 -05:00
Ed Page
4eea907733 test(package): Show behavior with backslashes 2024-04-09 13:44:25 -05:00
Ed Page
71e362fb17 test(package): Clean up a build.rs test 2024-04-05 13:12:41 -05:00
Arlo Siemsen
312e2aab7f Use strip_path_canonical for getting the relative path
This resolve an issue where the package path contains a symlink that's resolved by git
2024-04-03 12:59:49 -05:00
Arlo Siemsen
45c390a2a5 Switch to using gitoxide by default for listing files 2024-04-03 12:05:26 -05:00
Ed Page
cad9673785 refactor(package): Move preamble to Manifest 2024-03-28 13:29:24 -05:00
Sebastian Thiel
a710d459af
assure repositories are always walked into to avoid .git folders.
With a traditional walk, `.git` will be picked up, and so will be
ignored directories. This commit also doesn't give submodules special
treatment - instead it just tries to open directories as repositories,
or walks them if that fails.
2024-03-18 10:07:04 +01:00
Sebastian Thiel
9115545053
implement list_files_gix to be used when gitoxide is enabled. 2024-03-18 10:06:13 +01:00
Lin Yihai
cf45a5c186 test: Add test for packaging a public dependency 2024-03-01 20:19:41 +08:00
Ed Page
14646e6af6 test: Make edition explicit on packages 2024-02-22 11:37:03 -06:00
Ed Page
e7e8d8748a fix(compiler): Clarify we're showing a profile name 2024-02-08 14:01:39 -06:00