Commit graph

1897 commits

Author SHA1 Message Date
Alex Crichton aca5261718 Revert "fix failures on linux"
This reverts commit e729880f56.
2020-12-18 08:06:38 -08:00
bors fde8ee3ba0 Auto merge of #8984 - ehuss:reject-ambiguous-git, r=Eh2406
Reject ambiguous git dependency declaration.

This rejects a git dependency that specifies more than one of `branch`, `tag`, or `rev`. Cargo does not handle this case very well, and this warning has been in place for 4 years (since #2940).

Fixes #7841
2020-12-16 21:37:20 +00:00
Eric Huss d65a714493 Reject ambiguous git dependency declaration. 2020-12-16 13:10:11 -08:00
Eric Huss 0ac41f0051 Fix tests not working with a different CARGO_TARGET_DIR. 2020-12-16 11:19:32 -08:00
bors a3c2627fbc Auto merge of #8973 - ehuss:rerun-if-directory, r=alexcrichton
Check if rerun-if-changed points to a directory.

This changes it so that if a build script emits `cargo:rerun-if-changed` pointing to a directory, then Cargo will scan the entire directory for changes (instead of just looking at the mtime of the directory itself).  I think this is more useful, as otherwise build scripts have to recreate this logic.

I've tried to make it semi-intelligent in the face of symbolic links.  It checks the mtime of the link and its target, and follows the link if it points to a directory.

There are a few other edge cases. For example, if it doesn't have permission for a directory, it will skip it.  I think this is relatively reasonable, though it's hard to say for sure.
2020-12-14 17:21:26 +00:00
bors 8917837fb6 Auto merge of #8934 - ehuss:token-process, r=alexcrichton
Implement external credential process. (RFC 2730)

This adds a config setting for an external process to run to fetch the token for a registry. See `unstable.md` for more details.

As part of this, it adds a new `logout` command. This is currently gated on nightly with the appropriate `-Z` flag.

I have included four sample wrappers that integrate with the macOS Keychain, Windows Credential Manager, GNOME libsecret, and 1password. I'm not sure if we'll ultimately ship these, but I would like to. Primarily this provided a proof-of-concept to see if the design works.

**Patch Walkthrough**

This is a brief overview of the changes:

- Adds the `logout` command. With `cargo logout -Z unstable-options`, this allows removing the `token` from `.cargo/credentials`.  With `cargo logout -Z credential-process`, this launches the process with the `erase` argument to remove the token from storage.
- Credential-process handling is in the `ops/registry/auth.rs` module. I think it is pretty straightforward, it just launches the process with the appropriate store/get/erase argument.
- `ops::registry::registry()` now returns the `RegistryConfig` to make it easier to pass the config information around.
- `crates/credential/cargo-credential` is a helper crate for writing credential processes.
- A special shorthand of the `cargo:` prefix for a credential process will launch the named process from the `libexec` directory in the sysroot (or, more specifically, the `libexec` directory next to the `cargo` process). For example `credential-process = "cargo:macos-keychain"`. My intent is to bundle these in the pre-built rust-lang distributions, and this should "just work" when used with rustup. I'm not sure how that will work with other Rust distributions, but I'm guessing they can figure it out. This should make it much easier for users to get started, but does add some integration complexity.

**Questions**

- I'm on the fence about the name `credential-process` vs `credentials-process`, which sounds more natural? (Or something else?)
- I'm uneasy about the behavior when both `token` and `credential-process` is specified (see `warn_both_token_and_process` test). Currently it issues a warning and uses `token`. Does that make sense? What about the case where you have `registries.foo.token` for a specific registry, but then have a general `registry.credential-process` for the default (it currently warns and uses the token, maybe it should not warn?)?
- I am still pretty uneasy with writing FFI wrappers, so maybe those could get a little extra scrutiny? They seem to work, but I have not extensively tested them (I tried login, publish, and logout). I have not previously used these APIs, so I am not familiar with them.
- Testing the wrappers I think will be quite difficult, because some require TTY interaction (and 1password requires an online account). Or, for example in the macOS case, it has GUI dialog box where I can use my fingerprint scanner. Right now, I just build them in CI to make sure they compile.
- 1password is a little weird in that it passes the token on the command-line, which is not very secure on some systems (other processes can see these sometimes). The only alternative I can think of is to not support `cargo login` and require the user to manually enter the token in the 1password GUI. I don't think the concern is too large (1password themselves seem to think it is acceptable). Should this be OK?
- I'm a little uneasy with the design of `cargo login`, where it passes the token in stdin. If the wrapper requires stdin for user interaction (such as entering a password to unlock), this is quite awkward. There is a hack in the 1password example that demonstrates using `/dev/tty` and `CONIN$`, which *seems* to work, but I'm worried is fragile. I'm not very comfortable passing the token in environment variables, because those can be visible to other processes (like CLI args), but in some situations that shouldn't be too risky. Another option is to use a separate file descriptor/handle to pass the token in. Implementing that in Rust in a cross-platform way is not terribly easy, so I wanted to open this up for discussion first.
2020-12-14 16:22:53 +00:00
Eric Huss cee088b0db Check if rerun-if-changed points to a directory. 2020-12-12 14:14:54 -08:00
bors c68c6220b6 Auto merge of #8968 - alexcrichton:revert-8834, r=ehuss
Revert recent build-std vendoring changes

This reverts #8834 to address https://github.com/rust-lang/cargo/issues/8962 and https://github.com/rust-lang/cargo/issues/8963

cc `@Gankra`
2020-12-12 18:07:59 +00:00
Alex Crichton 4761ada30f Fix the unit dependency graph with dev-dependency links
This commit fixes #8966 by updating the unit generation logic to avoid
generating an erroneous circular dependency between the execution of two
build scripts. This has been present for Cargo in a long time since #5651
(an accidental regression), but the situation appears rare enough that
we didn't get to it until now!

Closes #8966
2020-12-11 09:59:33 -08:00
Alex Crichton 049b2727b1 Fix a test 2020-12-11 08:43:27 -08:00
Alex Crichton 602f6b64de Revert "Check if rust-src contains a vendor dir, and patch it in"
This reverts commit eadb4fc86c.
2020-12-11 07:45:27 -08:00
Eric Huss 395edf2f8f Change behavior when both token and credential-process is specified.
Change it so that if both are specified, it is an error just to be safer
for now.

If token is specified for a registry, ignore the global
credential-process.

I'm still uncertain if this is the best behavior, but I think we can
tweak it later if needed.
2020-12-08 08:36:49 -08:00
Arpad Borsos e729880f56 fix failures on linux 2020-12-07 09:25:49 +01:00
Arpad Borsos 2cc2ae8c96 Run rustdoc doctests relative to the workspace
By doing so, rustdoc will also emit workspace-relative filenames for
the doctests.

fixes #8097
2020-12-06 23:21:06 +01:00
Eric Huss bdbc8da5b4 Validate that the credential process only outputs a single line (token). 2020-12-06 11:41:12 -08:00
Eric Huss 6b472c90e1 Fix panic with -Zbuild-std and no roots. 2020-12-04 13:34:34 -08:00
bors 78beb3784f Auto merge of #8912 - aniljava:master, r=alexcrichton
Fixes #8783 , cargo new fails without a author name or email

If user can not be obtained from git or env variables $USER, new command defaults to empty author in generated Cargo.toml

Could not edit old PR(#8910 8783) as the original clone was deleted.
2020-12-03 15:14:39 +00:00
Anil P a006347b2d Removed debug println! 2020-12-02 23:04:00 -06:00
Anil P 4787dd3acf rustfmt 2020-12-02 23:02:55 -06:00
Anil P 4eeadfb38c Explicitly removed USER env variables. 2020-12-02 22:59:40 -06:00
Eric Huss cc6df1d7a5 Implement credential-process. 2020-12-02 19:09:54 -08:00
bors c7939aeb1f Auto merge of #8929 - ehuss:fix-git-config-author, r=Eh2406
Fix test escaping __CARGO_TEST_ROOT

#8886 added a test which unsets `__CARGO_TEST_ROOT`, but that environment variable is there for a reason. This causes problems as it causes that test to load the `.cargo/config` from the real home directory, which if it contains a `[cargo-new]` section, causes the test to fail.

The fix here is to change `find_tests_git_config` so that it behaves more like the real git config loader, but avoids escaping the test sandbox.  There are some subtle issues here, like #7469, which I believe should still work correctly.
2020-12-02 22:12:37 +00:00
Anil P 65f2a87c40 Merge remote-tracking branch 'upstream/master' 2020-12-02 12:43:30 -06:00
Anil P fad16813a3 Removed debug println from earlier commit. 2020-12-02 12:39:29 -06:00
Eric Huss ea1a73a121 Add period to allowed feature name characters. 2020-12-02 07:56:44 -08:00
Anil P 38694d4a2c Merge remote-tracking branch 'upstream/master'
Remote
2020-12-02 01:00:30 -06:00
asdf c3e01b8fe3 Fix test escaping __CARGO_TEST_ROOT 2020-12-01 21:58:32 -08:00
Anil P 917fc99fd5 Test cargo new with missing authors
- test case for missing name and email (author_without_user_or_email)
- test case for handling email only (finds_author_email_only)
2020-12-01 23:46:16 -06:00
bors 63d0fe4344 Auto merge of #8725 - chaaz:master, r=ehuss
Add "--workspace" to update command

My `--bin` project has CI which updates the version number in `Cargo.toml`, which it then commits. However, this means that any further cargo command (`build`, `test`, etc) will update the existing `Cargo.lock` file (updating the root version), causing some frustration for users. Furthermore, it breaks the `publish` command, which requires the repo to be current.

I've added a `sync-lockfile` command to simply update the root version in the `Cargo.lock` file to match the `Cargo.toml` in the same way that simple commands like `fetch` do. If no `Cargo.lock` file is present, and new one is generated based on the index.

This is a demo PR for Pre-RFC conversation at https://internals.rust-lang.org/t/pre-rfc-cargo-command-to-just-sync-lockfile/13119, but may become a real PR if it gets approval.
2020-12-02 01:44:30 +00:00
bors 6de98d13af Auto merge of #8877 - jyn514:rustdoc-map, r=alexcrichton
Set docs.rs as the default extern-map for crates.io

Helps address https://github.com/rust-lang/cargo/issues/8296, specifically the bit needed for https://github.com/rust-lang/docs.rs/issues/1177.
r? `@ehuss`
2020-12-01 15:34:20 +00:00
Eric Huss 8d230f958a Fix custom_target_dependency test. 2020-11-27 06:50:08 -08:00
bors 4e32fba575 Auto merge of #8886 - justfortherec:fix/8882/gitconfig-includeif, r=alexcrichton
Start searching git config at new path

This lets `cargo new` follow `includeIf` blocks inside .gitignore.

Fixes #8882

I am not sure if removing the `__CARGO_TEST_ROOT` environment variable has any bad side effects. My quick grep of the repository didn't highlight anything in particular.
2020-11-24 15:35:39 +00:00
bors 1cd7e38619 Auto merge of #8894 - ehuss:version-bump, r=Eh2406
Bump to 0.51.0, update changelog
2020-11-24 03:04:53 +00:00
Eric Huss 9b590d0dd4 Bump to 0.51.0 2020-11-23 17:34:18 -08:00
bors 774c64cfea Auto merge of #8869 - ayazhafiz:e/metadata-doc, r=ehuss
Publish target's "doc" setting when emitting metadata

Prior to this commit `cargo metadata` would not emit the value of a
target's "doc" setting, used by `cargo doc` to determine whether
documentation should be generated. However, this information is useful
for machine programs interested in such targets, and the information is
already made available on the internal representation of a target, so
this commit just exposes that during target serialization for emit.

cf https://github.com/deadlinks/cargo-deadlinks/issues/99
2020-11-24 00:27:46 +00:00
Franz-Xaver Geiger 35b029c2ce Start searching git config at path of the new project
This lets `cargo new` follow `includeIf` blocks inside .gitignore.

Fixes #8882
2020-11-23 20:43:57 +01:00
Jakob Schikowski 62ddaf343e Relaxes expectation of cargo test tests to accept test execution time 2020-11-23 00:25:46 +01:00
Joshua Nelson d85fd93329 Fix inconsistency with quoting
Locally, the output looks like `'bar=...'`, but in CI the quotes are
missing. Allow either.
2020-11-21 22:51:30 -05:00
Joshua Nelson d9f63cd684 Set docs.rs as the default extern-map for crates.io 2020-11-21 22:05:19 -05:00
bors 905134577c Auto merge of #8441 - reitermarkus:linkarg, r=alexcrichton
Finish implementation of `-Zextra-link-arg`.

This is a continuation of https://github.com/rust-lang/cargo/pull/7811, which adds tests and a warning if the `-Zextra-link-arg` flag is not specified. Also moved the documentation into `unstable.md`.
2020-11-18 21:44:17 +00:00
bors 668a6c6292 Auto merge of #8864 - bk2204:reproducible-crates, r=alexcrichton
Reproducible crate builds

This series introduces reproducible crate builds.  Since crates are essentially gzipped tar archives, we canonicalize the fields such that they don't contain extraneous and potentially privacy-leaking data such as user and group names and IDs, device major and minor, and system timestamps.  Outside of the timestamps, the user probably did not intend to share information about their user or system, so this also improves developer privacy somewhat.

The individual commit messages include copious details about the individual changes involved and the rationale for this change, but roughly, the idea is that by setting the environment variable `SOURCE_DATE_EPOCH`, which is [the preferred way to specify a fixed timestamp by the Reproducible Builds project](https://reproducible-builds.org/docs/source-date-epoch/), we will produce a fully reproducible archive.  In any event, we will now produce consistent timestamps throughout the archive and avoid looking up the system time repeatedly.

If desired, I could hash the produced crate in the tests, but I feel that would be a little overkill, especially since it's possible that one of our dependencies (e.g., flate2) might change and result in us producing an equivalent but different archive.  Since reproducible builds use a consistent toolchain, that's not a problem here.

Fixes #8612
2020-11-18 15:21:38 +00:00
ayazhafiz e831dd12a8 Publish target's "doc" setting when emitting metadata
Prior to this commit `cargo metadata` would not emit the value of a
target's "doc" setting, used by `cargo doc` to determine whether
documentation should be generated. However, this information is useful
for machine programs interested in such targets, and the information is
already made available on the internal representation of a target, so
this commit just exposes that during target serialization for emit.

cf https://github.com/deadlinks/cargo-deadlinks/issues/99
2020-11-17 19:54:17 -06:00
brian m. carlson 449ead05db
package: canonicalize tar headers for crate packages
Currently, when reading a file from disk, we include several pieces of
data from the on-disk file, including the user and group names and IDs,
the device major and minor, the mode, and the timestamp.  This means
that our archives differ between systems, sometimes in unhelpful ways.

In addition, most users probably did not intend to share information
about their user and group settings, operating system and disk type, and
umask.  While these aren't huge privacy leaks, cargo doesn't use them
when extracting archives, so there's no value to including them.

Since using consistent data means that our archives are reproducible and
don't leak user data, both of which are desirable features, let's
canonicalize the header to strip out identifying information.

Omit the inclusion of the timestamp for generated files and tell the tar
crate to copy deterministic data.  That will omit all of the data we
don't care about and also canonicalize the mode properly.

Our tests don't check the specifics of certain fields because they
differ between the generated files and the files that are archived from
the disk format.  They are still canonicalized correctly for each type,
however.
2020-11-18 00:07:50 +00:00
brian m. carlson e46ca84b6c
package: canonicalize tar headers for crate packages
Currently, when reading a file from disk, we include several pieces of
data from the on-disk file, including the user and group names and IDs,
the device major and minor, the mode, and the timestamp.  This means
that our archives differ between systems, sometimes in unhelpful ways.

In addition, most users probably did not intend to share information
about their user and group settings, operating system and disk type, and
umask.  While these aren't huge privacy leaks, cargo doesn't use them
when extracting archives, so there's no value to including them.

Since using consistent data means that our archives are reproducible and
don't leak user data, both of which are desirable features, let's
canonicalize the header to strip out identifying information.

We set the user and group information to 0 and root, since that's the
only user that's typically consistent among Unix systems.  Setting
these values doesn't create a security risk since tar can't change the
ownership of files when it's running as a normal unprivileged user.

Similarly, we set the device major and minor to 0.  There is no useful
value here that's portable across systems, and it does not affect
extraction in any way.

We also set the timestamp to the same one that we use for generated
files.  This is probably the biggest loss of relevant data, but
considering that cargo doesn't otherwise use it and honoring it makes
the archives unreproducible, we canonicalize it as well.

Finally, we canonicalize the mode of an item we're storing by looking at
the executable bit and using mode 755 if it's set and mode 644 if it's
not.  We already use 644 as the default for generated files, and this is
the same algorithm that Git uses to determine whether a file should be
considered executable.  The tests don't test this case because there's
no portable way to create executable files on Windows.
2020-11-16 01:46:10 +00:00
Eric Huss b1029b7d16 Allow resolver="1" to explicitly use the old resolver behavior. 2020-11-13 12:03:15 -08:00
Eric Huss 2a07061b38 Fix publishing with optional dependencies. 2020-11-12 10:44:10 -08:00
bors 8662ab427a Auto merge of #8834 - Gankra:rust-src-vendor, r=ehuss
Check if rust-src contains a vendor dir, and patch it in

This is the cargo side of https://github.com/rust-lang/wg-cargo-std-aware/issues/23

Note that this design naively assumes there is only one version of each package. It does not robustly verify this, and will presumably just cryptically fail to resolve dependencies.

See https://github.com/rust-lang/rust/pull/78790 for the other half of this change.
2020-11-12 03:47:53 +00:00
Alexis Beingessner eadb4fc86c Check if rust-src contains a vendor dir, and patch it in
This is the cargo side of https://github.com/rust-lang/wg-cargo-std-aware/issues/23
2020-11-10 11:47:32 -05:00
Igor Matuszewski aab416f6e6 Use u32/64::to/from_le_bytes instead of bit fiddling 2020-11-09 23:32:39 +01:00
Markus Reiter 9fca62483f Rename rustc-bin-link-arg to rustc-link-arg-bins. 2020-11-09 15:16:32 +01:00