Commit graph

580 commits

Author SHA1 Message Date
Jacob Finkelman 29ff25f6d9 cleanups round 1 2022-12-13 23:49:07 +00:00
Jacob Finkelman 2ac15086fb end-to-end tests 2022-12-12 21:50:08 +00:00
Jacob Finkelman 6d1c07bcc5 Send asymmetric tokens with mutations 2022-12-12 20:11:26 +00:00
Lucio Franco ac9da4b193 home: Remove github ci, link license, remove others 2022-12-12 13:52:23 -05:00
Lucio Franco 6a1a9edd40 Merge branch 'homemerge' into lucio/home-crate 2022-12-12 13:46:59 -05:00
Lucio Franco dbb8dada19 Add crate 2022-12-12 13:46:41 -05:00
Ed Page 48895b1681 fix: Move off atty to resolve soundness issue
There is a soundness issue with atty when building on Windows with a
custom allocator.

This PR switches direct dependencies on atty to is-terminal.  New semver
compatible versions of clap and snapbox remove atty. #11417 upgrades
env_logger to remove it from there.

Fixes #11415
2022-11-25 06:28:01 -06:00
bors de56c1251b Auto merge of #10343 - willcrichton:example-analyzer, r=weihanglo
Change rustdoc-scrape-examples to be a target-level configuration

This PR addresses issues raised in rust-lang/cargo#9525. Specifically:
1. It enables examples to be scraped from `#[test]` functions, by passing additional flags to Rustdoc to ensure that these functions aren't ignored by rustc.
2. It moves the `arg` from `-Z rustdoc-scrape-examples={arg}` into a target-level configuration that can be added to Cargo.toml.

The added test `scrape_examples_configure_target` shows a concrete example. In short, examples will be default scraped from Example and Lib targets. Then the user can enable or disable scraping like so:

```toml
[lib]
doc-scrape-examples = false

[[test]]
name = "my_test"
doc-scrape-examples = true
```
2022-11-25 06:58:20 +00:00
Expyron bb837662d8 chore: Upgrade miow 2022-11-18 14:08:46 +01:00
Arlo Siemsen 9827412fee Implement RFC 3139: alternative registry authentication support 2022-11-16 14:36:19 -06:00
Will Crichton 39e6737de7 Change rustdoc-scrape-examples to be a target-level configuration 2022-11-16 09:18:33 -08:00
Weihang Lo 054a19ba2f
Bump crate crates-io to 0.35.0 2022-11-13 10:55:15 +00:00
Weihang Lo 851492c788
Bump crate cargo-util to 0.2.3 2022-11-13 10:55:10 +00:00
RyanAD eb8d3e2932 simplify join_paths error message and add test 2022-11-12 18:44:22 -07:00
RyanAD 730e8ca46d make call to paths::join_paths and warn if path contains invalid chars 2022-11-12 18:43:46 -07:00
RyanAD 23c1a51ad0 Improve error message in join_paths when env contains a path separator 2022-11-12 18:43:37 -07:00
hi-rustin 6de9ed11be Fix not a hyperlink warnings
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-11-10 08:52:32 +08:00
Arlo Siemsen 90c6b5854d Fix waiting for publishing to complete when publishing to a sparse registry 2022-11-08 18:14:52 -06:00
bors 9286a1beba Auto merge of #11328 - epage:upgrade, r=weihanglo
chore: Upgrade dependencies

This upgrades several dependencies to the latest "major" release.  The original intent was just to get onto the latest snapbox but I noticed several others that could be updated and thought "why not".

- `snapbox` broke compatibility on less used APIs
- Its unclear from the docs if `miow` or `remove_dir_all` even broke compatibility

I did not touch `mdman` as that has several large, stale deps
2022-11-04 06:41:49 +00:00
Ed Page 8d6a828c18 chore: Upgrade miow 2022-11-03 19:59:25 -05:00
Eric Huss fa8375b3c9 Remove remove_dir_all 2022-11-03 16:51:48 -07:00
Ed Page 25f838bfb7 chore: Upgrade snapbox 2022-11-02 23:15:48 -05:00
bors 352175f810 Auto merge of #11285 - jonhoo:cargo-env, r=weihanglo
Make cargo forward pre-existing CARGO if set

Currently, Cargo will always set `$CARGO` to point to what it detects its own path to be (using `std::env::current_exe`). Unfortunately, this runs into trouble when Cargo is used as a library, or when `current_exe` is not actually the binary itself (e.g., when invoked through Valgrind or `ld.so`), since `$CARGO` will not point at something that can be used as `cargo`. This, in turn, means that users can't currently rely on `$CARGO` to do the right thing, and will sometimes have to invoke `cargo` directly from `$PATH` instead, which may not reflect the `cargo` that's currently in use.

This patch makes Cargo re-use the existing value of `$CARGO` if it's already set in the environment. For Cargo subcommands, this will mean that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`, and then Cargo-as-a-library inside of `cargo-foo` will inherit that (correct) value instead of overwriting it with the incorrect value `cargo-foo`. For other execution environments that do not have `cargo` in their call stack, it gives them the opportunity to set a working value for `$CARGO`.

One note about the implementation of this is that the test suite now needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does not interfere with the contents of the tests. It _could_ remove `$CARGO` instead, but overriding it seemed less error-prone.

Fixes #10119.
Fixes #10113.
2022-11-02 12:38:30 +00:00
Anton Lazarev d70a4ee93c
update stderr in tests for unrelated functionality 2022-10-28 17:13:25 -07:00
Rageking8 61813d9d72 fix dupe word typos 2022-10-26 12:15:45 +08:00
Jon Gjengset 724a1977ce Make cargo forward pre-existing CARGO if set
Currently, Cargo will always set `$CARGO` to point to what it detects
its own path to be (using `std::env::current_exe`). Unfortunately, this
runs into trouble when Cargo is used as a library, or when `current_exe`
is not actually the binary itself (e.g., when invoked through Valgrind
or `ld.so`), since `$CARGO` will not point at something that can be used
as `cargo`. This, in turn, means that users can't currently rely on
`$CARGO` to do the right thing, and will sometimes have to invoke
`cargo` directly from `$PATH` instead, which may not reflect the `cargo`
that's currently in use.

This patch makes Cargo re-use the existing value of `$CARGO` if it's
already set in the environment. For Cargo subcommands, this will mean
that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`,
and then Cargo-as-a-library inside of `cargo-foo` will inherit that
(correct) value instead of overwriting it with the incorrect value
`cargo-foo`. For other execution environments that do not have `cargo`
in their call stack, it gives them the opportunity to set a working
value for `$CARGO`.

One note about the implementation of this is that the test suite now
needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does
not interfere with the contents of the tests. It _could_ remove `$CARGO`
instead, but overriding it seemed less error-prone.

Fixes #10119.
Fixes #10113.
2022-10-25 13:51:27 -07:00
Ed Page a9f704aaaa fix: Remove leading newline in vendor output
This supersedes #11271
2022-10-21 12:27:21 -05:00
Ed Page 04d836fa71 feat(publish): Support 'publish.timeout' config behind '-Zpublish-timeout'
Originally, crates.io would block on publish requests until the publish
was complete, giving `cargo publish` this behavior by extension.  When
crates.io switched to asynchronous publishing, this intermittently broke
people's workflows when publishing multiple crates.  I say interittent
because it usually works until it doesn't and it is unclear why to the
end user because it will be published by the time they check.  In the
end, callers tend to either put in timeouts (and pray), poll the
server's API, or use `crates-index` crate to poll the index.

This isn't sufficient because
- For any new interested party, this is a pit of failure they'll fall
  into
- crates-index has re-implemented index support incorrectly in the past,
  currently doesn't handle auth, doesn't support `git-cli`, etc.
- None of these previous options work if we were to implement
  workspace-publish support (#1169)
- The new sparse registry might increase the publish times, making the
  delay easier to hit manually
- The new sparse registry goes through CDNs so checking the server's API
  might not be sufficient
- Once the sparse registry is available, crates-index users will find
  out when the package is ready in git but it might not be ready through
  the sparse registry because of CDNs

This introduces unstable support for blocking by setting
`publish.timeout` to non-zero value.

A step towards #9507
2022-10-13 08:53:36 -05:00
Arlo Siemsen d51ed05324 Fix deadlock when build scripts are waiting for input on stdin 2022-10-12 11:46:51 -05:00
Arlo Siemsen dd5134c7a5 Implement RFC 3289: source replacement ambiguity 2022-10-07 22:30:59 -05:00
Arlo Siemsen dcc512b317 Add retry support to sparse registries 2022-10-07 12:00:24 -05:00
Scott Schafer 251a2c7915 cargo-test-support: Make publish http api write to file system 2022-09-22 10:00:49 -06:00
Scott Schafer 0ba6224a70 cargo-test-support: allow processing of the body of a request for test http registries 2022-09-21 10:07:09 -06:00
Pietro Albini 0bf436d0d2
fix formatting 2022-09-14 16:14:11 +02:00
Weihang Lo dafe4a7ea0
CVE-2022-36113: add tests 2022-09-14 10:54:47 +02:00
bors e5ec3a8ff9 Auto merge of #11004 - jonhoo:bump-git2, r=weihanglo
Bump git2 to 0.15 and libgit2-sys to 0.14

This will allow cargo to avoid vendored builds of git2 in up-to-date
environments going forward, and brings in the [libgit2 1.4.4 CVE fix].

[libgit2 1.4.4 CVE fix]: https://github.com/libgit2/libgit2/releases/tag/v1.4.4
2022-08-27 09:22:12 +00:00
Jon Gjengset ed78e6b747 Bump snapbox to 0.3
0.3 has a small number of [breaking changes], but makes diffs much
easier to visually parse by eliding large sections of unchanged content.

[breaking changes]: https://github.com/assert-rs/trycmd/blob/main/crates/snapbox/CHANGELOG.md#030---2022-08-01
2022-08-17 22:07:20 +00:00
Jon Gjengset 30fe22b260 Bump git2 to 0.15 and libgit2-sys to 0.14
This will allow cargo to avoid vendored builds of git2 in up-to-date
environments going forward, and brings in the [libgit2 1.4.4 CVE fix].

[libgit2 1.4.4 CVE fix]: https://github.com/libgit2/libgit2/releases/tag/v1.4.4
2022-08-17 22:02:28 +00:00
Wim Looman 61c4b11eae
Ensure rustc-echo-wrapper works with an overridden build.target-dir 2022-08-10 17:37:40 +02:00
Eric Holk 8de9adfb0d Use old Windows path handling on CI 2022-08-03 16:09:06 -07:00
Eric Holk e9c7544c19 Move Windows path test function to test code 2022-08-03 15:59:59 -07:00
bors 333478d0aa Auto merge of #10929 - ehuss:ignore-reason, r=weihanglo
Add reasons to all ignored tests.

This adds a reason string to all `#[ignore]` attributes. This will be displayed when running the test (since 1.61), which can help quickly see and identify why tests are being ignored. It looks roughly like:

```
test basic ... ignored, requires nightly, CARGO_RUN_BUILD_STD_TESTS must be set
test build::simple_terminal_width ... ignored, --diagnostic-width is stabilized in 1.64
test check_cfg::features_with_cargo_check ... ignored, --check-cfg is unstable
test plugins::panic_abort_plugins ... ignored, requires rustc_private
```
2022-08-03 03:54:05 +00:00
Eric Huss a8e285aa18 Always allow hg to be missing on CI. 2022-08-02 15:18:16 -07:00
Eric Huss 7eb007ddbf Add reasons to all ignored tests. 2022-08-02 12:24:00 -07:00
Eric Huss 7858bebb0e Remove needless is_not_nightly closure. 2022-07-31 15:28:31 -07:00
Eric Huss 9d43ffc02a Remove CARGO_TEST_DISABLE_GIT_CLI
This appears to no longer be necessary since we have migrated to
GitHub Actions.
2022-07-30 19:36:58 -07:00
Eric Huss 1c3640e05c Add requirements to cargo_test. 2022-07-30 19:36:58 -07:00
Ed Page a645c4fef0 refactor(source): Replace bool with enum 2022-07-21 09:27:01 -05:00
Ed Page 6a62d35458 refactor(registry): Move query out-param to be last 2022-07-20 12:54:16 -05:00
Scott Schafer c239e407e7 add a reason to masquerade_as_nightly_cargo so it is searchable 2022-07-15 21:32:23 -05:00
Eric Huss 41ac6078aa Bump cargo-util version. 2022-06-30 14:25:28 -07:00
Ed Page cbd4edb266 refactor(test): Clarify asserts are for UI
In writing the contrib documentation for functional vs ui tests, I
realized that as we work to make snapbox work for the functional tests,
we'll need distinct `Assert` objects since we'll want to elide a lot
more content in functional tests.  I'm making room for this by
qualifying the existing asserts as being for "ui".
2022-06-21 14:59:54 -05:00
Arlo Siemsen 24dac452c5 Improve testing framework for http registries
Improve integration of the http server introduced by the http-registry feature.
Now the same HTTP server is used for serving downloads, the index, and
the API.

This makes it easier to write tests that deal with authentication and
http registries.
2022-06-10 16:51:35 -05:00
Jakub Sitnicki 26031b9069 Respect submodule update=none strategy in .gitmodules
Git lets users define the default update/checkout strategy for a submodule
by setting the `submodule.<name>.update` key in `.gitmodules` file.

If the update strategy is `none`, the submodule will be skipped during
update. It will not be fetched and checked out:

1. *foo* is a big git repo

```
/tmp $ git init foo
Initialized empty Git repository in /tmp/foo/.git/
/tmp $ dd if=/dev/zero of=foo/big bs=1000M count=1
1+0 records in
1+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 0.482087 s, 2.2 GB/s
/tmp $ git -C foo add big
/tmp $ git -C foo commit -m 'I am big'
[main (root-commit) 84fb533] I am big
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 big
```

2. *bar* is a repo with a big submodule with `update=none`

```
/tmp $ git init bar
Initialized empty Git repository in /tmp/bar/.git/
/tmp $ git -C bar submodule add file:///tmp/foo foo
Cloning into '/tmp/bar/foo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 1 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), 995.50 KiB | 338.00 KiB/s, done.
/tmp $ git -C bar config --file .gitmodules submodule.foo.update none
/tmp $ cat bar/.gitmodules
[submodule "foo"]
        path = foo
        url = file:///tmp/foo
        update = none
/tmp $ git -C bar commit --all -m 'I have a big submodule with update=none'
[main (root-commit) 6c355ea] I have a big submodule not updated by default
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 foo
```

3. *baz* is a clone of *bar*, notice *foo* submodule gets skipped

```
/tmp $ git clone --recurse-submodules file:///tmp/bar baz
Cloning into 'baz'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Submodule 'foo' (file:///tmp/foo) registered for path 'foo'
Skipping submodule 'foo'
/tmp $ git -C baz submodule update --init
Skipping submodule 'foo'
/tmp $
```

Cargo, on the other hand, ignores the submodule update strategy set in
`.gitmodules` properties when updating dependencies. Such behavior can
be considered against the wish of the crate publisher.

4. *bar* is now a lib with a big submodule with update disabled

```
/tmp $ cargo init --lib bar
     Created library package
/tmp $ git -C bar add .
/tmp $ git -C bar commit -m 'I am a lib with a big submodule but update=none'
[main eb07cf7] I am a lib with a big submodule but update=none
 3 files changed, 18 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 Cargo.toml
 create mode 100644 src/lib.rs
/tmp $
```

5. *qux* depends on *bar*, notice *bar*'s submodules are fetched

```
/tmp $ cargo init qux && cd qux
     Created binary (application) package
/tmp/qux $ echo -e '[dependencies.bar]\ngit = "file:///tmp/bar"' >> Cargo.toml
/tmp/qux $ time cargo update
    Updating git repository `file:///tmp/bar`
    Updating git submodule `file:///tmp/foo`

real    0m22.182s
user    0m20.402s
sys     0m1.714s
/tmp/qux $
```

Fix it by checking if a Git repository submodule should be updated when
cargo processes dependencies.

6. With the change applied, submodules with `update=none` are skipped

```
/tmp/qux $ cargo cache -a > /dev/null
/tmp/qux $ time ~/src/cargo/target/debug/cargo update
    Updating git repository `file:///tmp/bar`
    Skipping git submodule `file:///tmp/foo`

real    0m0.029s
user    0m0.021s
sys     0m0.008s
/tmp/qux $
```

Fixes #4247.

Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
2022-06-07 14:52:02 +02:00
Yuki Okushi 819f7a5cff
Enforce to use tar v0.4.38 2022-06-01 19:17:15 +09:00
Ed Page dde4a1c381 test: Make curr_dir work in/out of workspace
When running tests in the `rust-lang/cargo` repo, `file!` is relative to
the crate root and tests are run relative to the crate root and
everything is fine.

When running tests in the `rust-lang/rust` repo, `file!` is relative to
the workspace root and tests are run relative to the crate root and
there is much sadness.

If we are compiling relative to the crate root, we could make the path
absolute and everything would be dandy but this needs to happen at
compile time.  Didn't see a way to do this.

We could stop using `curr_dir` but that makes the tests a bit noisier
with more overhead for creating a new tests from an existing case.

Since we can reasonly know what all roots will be used for `file!`, we
can just hard code-in support for those two roots.  Much happiness
ensues as everything works with this surgical hack.
2022-05-12 03:28:27 -05:00
Scott Schafer cab6d30c1d fix typos found by the typos-cli crate 2022-05-10 16:47:28 -05:00
Koichi ITO 1626762fe4 Use the traits added to the Rust 2021 Edition prelude
Follow up https://github.com/rust-lang/rust/pull/96861.

This PR uses the traits added to the Rust 2021 Edition prelude.

> The `TryInto`, `TryFrom` and `FromIterator` traits are now part of the prelude.

https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html
2022-05-10 21:46:45 +09:00
Scott Schafer 92fbc4e344 move all snapshot/cargo_add/ tests to testsuite/cargo_add/ 2022-05-06 20:51:29 -05:00
klensy 867a580f29 dedupe toml_edit crate, followup #10603 2022-05-02 03:10:38 +03:00
Ed Page d6e912ca32 feat(test-support): Make multi-argument strings avaialble to snapbox
This is something the existing test infrastructure supports, so I
figured I'd make it mirror it for snapbox.  I'm mixed.
- It reads more like what a user would type, making it easier to run a
  test locally or take a manual test case and automate it
- It can make it harder to parse the arguments when scanning tests
- Without using a crate like `shlex`, the syntax support is unclear
2022-04-27 20:57:19 -05:00
Ed Page 83d444040c feat(test-support): Make it easy to launch cargo 2022-04-27 20:57:17 -05:00
Ed Page 9a3d99b6c5 fix(test-support): Default the current_dir for snapbox 2022-04-27 20:57:03 -05:00
Ed Page c9e82ec197 feat(test-support): Expose test-env setup 2022-04-27 20:57:03 -05:00
Ed Page 79ef00c60b feat(test-support): Expose masquerade_as_nightly_cargo to snapbox users 2022-04-27 20:56:20 -05:00
Ed Page 0d135a0b43 feat(test-support): Share Project::from_template with all cargo tests
This was written for `cargo_add.rs`, based on `snapbox`.  This allows
creating a test from a known reproduction case or easily debugging on an
existing test case.
2022-04-27 20:53:25 -05:00
Ed Page 30451d2ffc feat(test-support): Allow reusing snapbox assertions 2022-04-27 20:45:36 -05:00
Ed Page 5eaec4fa2f refactor(test-support): Use snapbox to look up binaries 2022-04-27 20:45:36 -05:00
bors 7a3b56b486 Auto merge of #10553 - sourcefrog:cachedir, r=weihanglo
Mark .cargo/git and .cargo/registry as cache dirs

Fixes #10457

### What does this PR try to resolve?

As we previously discussed in #10457 this marks `~/.cargo/git` and `~/.cargo/registry` as not to be included in backups, and not subject to content indexing. These directories can be fairly large and frequently changed, and should only contain content that can be re-downloaded if necessary.

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

I did two manual tests:

1. Using the binary built from this tree, run `cargo update` in a source tree that has a git dependency, and observe that afterwards, there is a `CACHEDIR.TAG` in `~/.cargo/git`.
2. Similarly, run `cargo update` and observe that there's a `CACHEDIR.TAG` in `~/.cargo/registry`.

(I ran this on Linux. This code should also trigger OS-specific behavior on macOS and Windows that's the same as is currently applied to `target/`.)

I added some test assertions.
2022-04-27 08:55:00 +00:00
Martin Pool ae5fd5e2e1 exclude_from_backups_and_indexing can't fail
Ignore errors creating the registry directory
2022-04-25 18:29:13 -07:00
Martin Pool ce9a6ab648 Mark .cargo/git and .cargo/registry as cache dirs
Fixes #10457 (but still needs tests)
2022-04-10 16:19:21 -07:00
Weihang Lo d813739c76
test: make tests compatible when force using argfile 2022-04-10 22:23:20 +08:00
Weihang Lo 7146111afe
Close tempfile explicitly after the command to exist 2022-04-10 22:23:20 +08:00
Weihang Lo 5e8827f26e
Debug assertion for rustc argfile invocations 2022-04-10 22:23:19 +08:00
Weihang Lo 3f749f615b
Ensure non-UTF8 compatibility of argfile arg 2022-04-10 21:46:43 +08:00
Weihang Lo 9155c0062b
Ensure that temporary argfile lives longer them command execution 2022-04-10 21:46:43 +08:00
Weihang Lo 877c0add35
State that arg in argfile must not contain newlines 2022-04-10 21:46:42 +08:00
Weihang Lo 4f6a2ec28b
Bump cargo-util to 0.1.3 2022-04-08 15:39:36 +08:00
Weihang Lo b788e52246
Retry with argfile if hitting "command line too big" error
- Add `ProcessBuilder::output` and ProcessBuilder::status`, which are
  unopinionated version of `exec_*` (won't error out when exitcode > 0)
- Add `ProcessBuilder::retry_with_argfile` to enable trying with argfile
  when hitting the "command line too big" error.
2022-04-08 15:39:36 +08:00
Weihang Lo c9d443a063
Separate command wrappers from command arguments 2022-04-08 13:38:14 +08:00
Arlo Siemsen 412b633914 HTTP registry implementation 2022-03-20 18:02:09 -07:00
Weihang Lo 0e044546f8
Bump git2@0.14.2 and libgit2-sys@0.13.2
The previous libgit2-sys release forgot to include the fix of libgit2 1.4.2.
https://github.com/rust-lang/git2-rs/pull/820#issuecomment-1064284814
That might cause problems when people don't have "Git for Windows"
installed on their machines.
2022-03-15 07:26:45 +08:00
bors a77ed9ba87 Auto merge of #10064 - arlosi:poll, r=Eh2406
Registry functions return Poll to enable parallel fetching of index data

Adds `Poll` as a return type for several registry functions to enable parallel fetching of crate metadata with a future http-based registry.

Work is scheduled by calling the `query` and related functions, then waited on with `block_until_ready`.

This PR is based on the draft PR started by eh2406 here [#8985](https://github.com/rust-lang/cargo/pull/8985).

r? `@Eh2406`
cc `@alexcrichton`
cc `@jonhoo`
2022-03-09 19:30:19 +00:00
Lucas Kent fab44ff971 Remove warn(clippy::*) 2022-03-09 10:33:39 +11:00
Loïc BRANSTETT dd701a17f3 Update git2 to 0.14.1 and git2-curl to 0.15.0 and libgit2-sys to 0.13.1 2022-03-01 18:39:22 +01:00
Arlo Siemsen 82093ad9dc Registry functions return task::Poll to enable parallel fetching of index data. 2022-02-28 12:22:11 -08:00
Jacob Finkelman 96dc595eaf HashMap::from not into 2022-02-24 18:24:33 +00:00
Jacob Finkelman 4bfed40178 don't need mut 2022-02-23 22:48:47 +00:00
bors 5aad9b302a Auto merge of #9992 - Byron:rfc-3028, r=ehuss
Implement "artifact dependencies" (RFC-3028)

Tracking issue: #9096

#### Tasks

* [x] -Z unstable option called `bindeps`
*  **(config)** allow parsing of newly introduced 'artifact' fields
   * [x] into `TomlManifest`
   * [x] into `Manifest`
      - [x] ~~abort~~ warn if artifacts are used on stable
*  **resolver** : assure artifact dependencies are part of the resolution process and unified into the dependency tree
* 🔬**compiler**: make it understand 'artifact' dependencies and pass new environment variables to the crate being build
  * [x] `lib=false` should not be considered a rust library for the dependent, in unit and possibly resolve graph
  * [x] assure profile settings are applied correctly
  * [x] target overrides work
      * [x] `target = "target"` in build deps
      * [x] other targets on build deps
      * [x] other targets on non-build deps
      * [x] 'no-cross doc tests' seems like a constraint we should apply as well maybe
  * [x] more confidence with `resolver = "2"`
  * [x] assure artifact placement is correct (bin and various forms of lib)
*  **serialization**: rewriting manifests (i.e. for publishing) does not discard artifact information
   * [x] publishing keeps `artifact` and `lib` values
* **Other cargo subcommands**
   * [x] `cargo metadata`
        * leave unchanged
   * [x] artifacts work with `cargo check`
   * [x] artifacts work with rustdoc, such that it doesn't document them unless `lib=true`
   * [x] `cargo tree` maybe?
   * [x] `cargo clean` should clean artifacts - even though it's more complex, ultimately it deletes the `target` directory.
   * [x] artifacts work with `cargo test` (and dev-dependencies)
       * [x] doctests
       * [x] try `reproducible` repository as well.
* 🧪 **tests** for more subtle RFC constraints
   - [x] build scripts cannot access artifact environment variables at compile time, only at runtime)
   - [x] assure 'examples' which also support crate-type fields like [[lib]] won't become artifacts themselves.
   - [x] assure `--out-dir` does not leak artifacts - tested manually, it seemed to niche to add a test.
   - [x] try `target="foo"` in artifact and assure it sees a decent error message
   - [x] Assure RFC 3176 _doesn't_ work
* 🧹cleanup and finalization
    - [x] assure no `TODO(ST)` markers are left in code
    - [x] assure no tests are ignored
    - [x] use `resolver = "1"` once to assert everything also works with the previous resolver, but leave it on "2".

#### Implementation and review notes

- artifacts and unstable options are only checked when transforming them from `TomlManifest` to `Manifest`, discarding artifact information if the unstable flag is not set. Nowhere else in code will the CLI options be checked again.
- `If no binaries are specified, all the binaries in the package will be built and made available.` - this should only refer to `[[bin]]` targets, not examples for instance.
- artifact binaries won't be uplifted, hence won't be present outside of their output directory
- ️We don't know how [package links](00e925f61f/src/cargo/core/compiler/unit_dependencies.rs (L380)) will affect artifacts for build dependencies. Should probably be thought through.
- ️The location of artifacts is only tested roughly to avoid having to deal with different output names on the four platforms that seem to matter (gnu, macos, windows msvc, windows gnu).
- `cargo tree` doesn't handle artifacts specifically, and it might be interesting to make clear if an artifact is only an artifact, or both artifact and dependency.
- Most error and warning messages can probably be more cargo-matic.

#### Questions

* Does `cargo` without the feature enabled have to complain about the "artifact" field in a dependency, like it does right now?  It doesn't look like machinery for that exists in `do_read_manifest()`.
   - ✔️It warns now
*  Should parsing of artifact values, like "bin" be case sensitive?
   - ✔️ It's case sensitive now, which should help with serde roundtripping.

#### Review Progress

* [x] address Josh's review notes one by one
   * [x] introduce `IsArtifact` (see [this answer](https://github.com/rust-lang/cargo/pull/9992#discussion_r774928102)) (76cd48a2d62d74e043a1a482199c5bb920f50311)
   * [x] prefer uplifting artifact deps that were written into the `deps` directory, but prefer to do that in [this PR instead](https://github.com/rust-lang/cargo/pull/9992)
   * [x] add extra-tests as described in Josh's comment: " features get unified between a Rust library and a binary, and one that confirms features don't get unified between a Rust library and a binary for a different target?"
   * [x] Make target-based artifact splitting work by porting parts of RFC-3176
       * [x] test-support/cross-compile
       * [x] namespace separation
* [x] re-create RFC-3176 what's not in RFC-3028, namely multidep support and all related tests
* [x] Address Eh2406 's review comments
* [x] Address Eric's comments
   * [x] Unstable features need to be documented in unstable.md.
   * [x] sort out [`target_data`](https://github.com/rust-lang/cargo/pull/9992#discussion_r787316229)
   * [x] figure out [cargo metadata](https://github.com/rust-lang/cargo/pull/9992#discussion_r787320923)
   * [x] See if target-data can work without an [index format update](https://github.com/rust-lang/cargo/pull/9992#issuecomment-1021697124).
   * [x] truncate comments at 80-90 lines and remove unused methods, remove -Z unstable-options, use `cfg!(target_env = "msvc")`
   * [x] add missing doc comments to newly added methods and funtions
   * [x] simplify method parameters and inline some functions
   * [x] add test and extend test to show additional issues
* [x] assure current set of tests works consistently, also on windows

Sponsored by [Profian](https://www.profian.com)
2022-02-22 03:56:46 +00:00
Sebastian Thiel 7248f4b70d
add support for artifact dependencies (#9096)
Tracking issue: https://github.com/rust-lang/cargo/issues/9096
Original PR: https://github.com/rust-lang/cargo/pull/9992

Add 'bindeps' -Z flag for later use

A test to validate artifact dependencies aren't currently parsed.

Parse 'artifact' and 'lib' fields.

Note that this isn't behind a feature toggle so 'unused' messages will
disappear.

Transfer artifact dependencies from toml- into manifest-dependencies

There are a few premises governing the operation.

- if unstable features are not set, warn when 'artifact' or 'lib' is
  encountered.
- bail if 'lib' is encountered alone, but warn that this WOULD happen
  with nightly.
- artifact parsing checks for all invariants, but some aren't tested.

Assure serialization of 'artifact' and 'lib' fields produces suitable values during publishing

This should be the only place were these fields matter and where a cargo
manifest is actually produced. These are only for internal use, no user
is typically going to see or edit them.

Place all artifact dependency tests inta their own module

This facilitates deduplication later and possibly redistribution into
other modules if there is a better fit.

Represent artifacts that are rust libraries as another ArtifactKind

This is more consistent and probably simpler for later use.
No need to reflect the TOML data structure.

Add tests to assure only 'lib = true' artifact deps are documented

RFC-3028 doesn't talk about documentation, but for lib=true it's clear
what the desired behaviour should be.
If an artifact isn't a library though, then for now, it's transparent,
maybe.

Many more tests, more documentation, mild `Artifact` refactor

The latter seems to be a better fit for what being an artifact
really means within cargo, as it literally turns being a library
on or off, and thus only optionally becoming a normal library.

refactor to prepare for artifact related checks

Don't show a no-lib warning for artifact dependencies (with lib = false)

Tests for more artifact dependency invariants

These are merely a proof of concept to show that we are not in
a position to actually figure out everything about artifacts
right after resolution.

However, the error message looks more like a fatal error and less
like something that can happen with a more elaborate error message
with causes.

This might show that these kind of checks might be better done later
right before trying to use the information for create compile units.

Validate that artifact deps with lib=true still trigger no-lib warnings

This triggers the same warning as before, for now without any
customization to indicate it's an artifact dependency.

Use warnings instead of errors
------------------------------

This avoids the kind of harsh end of compilation in favor of something
that can be recovered from. Since warnings are annoying, users will
probably avoid re-declaring artifact dependencies.

Hook in artifact dependencies into build script runs

Even though we would still have to see what happens if they have a lib
as well. Is it built twice?

Also
----

- fly-by refactor: fix typo; use ? in method returning option
- Propagate artifact information into Units; put artifacts into place

  This means artifacts now have their own place in the 'artifact'
  directory and uplifts won't happen for them.

- refactor and fix cippy suggestion
- fix build after rebasing onto master

Create directories when executing the job, and not when preparing it.

also: Get CI to work on windows the easy way, for now.

Set directories for artifact dependencies in build script runtimes

Test remaining kinds of build-script runtime environment variables

Also
----
- Fix windows tests, the quick way.
- Try to fix windows assertions, and generalize them
- Fix second test for windows, hopefully

test for available library dependency in build scripts with lib = true

probably generally exclude all artifact dependencies with lib=false.

Pass renamed dep names along with unit deps to allow proper artifact env names

Test for selective bin:<name> syntax, as well as binaries with dashes

Test to assure dependency names are transformed correctly

assure advertised binaries and directories are actually present

This wouldn't be the case if dependencies are not setup correctly,
for instance.

Also
----
 - make it easier to see actual values even on failure

   This should help figure out why on CI something fails that works
   locally no matter what.
   Turns out this is a race condition, with my machine being on the good
   side of it so it doesn't show in testing. Fortunately it still can be
   reproduced and easily tested for.

 - refactor test; the race condition is still present though

 - Force CI to pass here by avoiding checks triggering race.

 - Fix windows build, maybe?

More tolerant is_file() checks to account for delay on CI

This _should_ help CI to test for the presence which is better than
not testing at all.

This appears to be needed as the output file isn't ready/present in time
for some reason.

The root cause of this issue is unknown, but it's definitely a race
as it rarely happens locally. When it happened, the file was always
present after the run.
Now we will learn if it is truly not present, ever, or if it's maybe
something very else.

Validate libs also don't see artifact dependencies as libraries with lib=false

Also
----

 - Add prelimiary test for validating build-time artifacts
 - Try to fix CI on gnu windows

   Which apparently generates paths similar to linux, but with .exe suffix.
   The current linux patterns should match that.

 - refactor

   Help sharing code across modules

allow rustc to use artifact dep environment variables, but…

…it needs some adjustments to actually setup the unit dependency graph
with artifacts as well.
Right now it will only setup dependencies for artifacts that are libs,
but not the artifacts themselves, completely ignoring them when they
are not libs.

Make artifact dependencies available in main loop

This is the commit message #2:
------------------------------

rough cut of support for artifact dependencies at build time…

…which unfortunately already shows that the binary it is supposed to
include is reproducibly not ready in time even though the path is
correct and it's present right after the run.

Could it be related to rmeta?

This is the commit message #3:
------------------------------

Fix test expectations as failure is typical than the warning we had before…

…and add some tolerance to existing test to avoid occasional failures.

This doesn't change the issue that it also doens't work at all for
libraries, which is nicely reproducable and hopefully helps to fix
this issue.

This is the commit message #4:
------------------------------

Probably the fix for the dependency issue in the scheduler

This means that bin() targets are now properly added to the job graph
to cause proper syncing, whereas previously apparently it would
still schedule binaries, but somehow consider them rmeta and thus
start their dependents too early, leading to races.

This is the commit message #5:
------------------------------

Don't accidentally include non-gnu windows tests in gnu windows.

Support cargo doc and cargo check

The major changes here are…

- always compile artifacts in build mode, as we literally want the
  build output, always, which the dependent might rely on being present.
- share code between the rather similar looking paths for rustdoc and
  rustc.

Make artifact messages appear more in line with cargo by using backticks

Also: Add first test for static lib support in build scripts

build-scripts with support for cdylib and staticlib

 - Fix windows msvc build

   No need to speculate why the staticlib has hashes in the name even
   though nothing else.

staticlib and cdylib support for libraries

test staticlib and cdylibs for rustdoc as well.

Also catch a seemingly untested special case/warning about the lack
of linkable items, which probably shouldn't be an issue for artifacts
as they are not linkable in the traditional sense.

more useful test for 'cargo check'

`cargo check` isn't used very consistently in tests, so when we use it
we should be sure to actually try to use an artifact based feature
to gain some coverage.

verify that multiple versions are allowed for artifact deps as well.

also: remove redundant test

This is the commit message #2:
------------------------------

Properly choose which dependencies take part in artifact handling

Previously it would include them very generously without considering
the compatible dependency types.

This is the commit message #3:
------------------------------

a more complex test which includes dev-dependencies

It also shows that doc-tests don't yet work as rustdoc is run outside of
the system into which we integrate right now.

It should be possible to write our environment variable configuration
in terms of this 'finished compilation' though, hopefully with
most code reused.

This is the commit message #4:
------------------------------

A first stab at storing artifact environment variables for packages…

…however, it seems like the key for this isn't necessarily correct
under all circumstances. Maybe it should be something more specific,
don't know.

This is the commit message #5:
------------------------------

Adjust key for identifying units to Metadata

This one is actually unique and feels much better.

This is the commit message #6:
------------------------------

Attempt to make use of artifact environment information…

…but fail as the metadata won't match as the doctest unit is, of course,
its separate unit. Now I wonder if its possible to find the artifact
units in question that have the metadata.

Properly use metadata to use artifact environment variables in doctests

This is the commit message #2:
------------------------------

Add test for resolver = "2" and build dependencies

Interestingly the 'host-features' flag must be set (as is seemingly
documented in the flags documentation as well), even though I am not
quite sure if this is the 100% correct solution. Should it rather
have an entry with this flag being false in its map? Probably not…
but I am not quite certain.

This is the commit message #3:
------------------------------

set most if not all tests to use resolver = "2"

This allows to keep it working with the most recent version while
allowing to quickly test with "1" as well (which thus far was working
fine).

All tests I could imagine (excluding target and profiles) are working now

Crossplatform tests now run on architecture aarm64 as well.

More stringent negative testing

Fix incorrect handling of dependency directory computation

Previously it would just 'hack' the deps-dir to become something very
different for artifacts.

This could easily be fixed by putting the logic for artifact output
directories into the right spot.

A test for cargo-tree to indicate artifacts aren't handled specifically

Assure build-scripts can't access artifacts at build time

Actual doc-tests with access to artifact env vars

All relevant parsing of `target = [..]`

Next step is to actually take it into consideration.

A failing test for adjusting the target for build script artifacts using --target

Check for unknown artifact target triple in a place that exists for a year

The first test showing that `target="target"` deps seemingly work

For now only tested for build scripts, but it won't be much different
for non-build dependencies.

build scripts accept custom targets unconditionally

Support target setting for non-build dependencies

This is the commit message #2:
------------------------------

Add doc-test cross compile related test

Even though there is no artifact code specific to doc testing, it's
worth to try testing it with different target settings to validate
it still works despite doc tests having some special caseing around
target settings.

This is the commit message #3:
------------------------------

A test to validate profiles work as expected for build-deps and non-build deps

No change is required to make this work and artifact dependencies 'just work'
based on the typical rules of their non-artifact counterarts.

This is the commit message #4:
------------------------------

Adjust `cargo metadata` to deal with artifact dependencies

This commit was squashed and there is probably more that changed.

This is the commit message #5:
------------------------------

Show bin-only artifacts in "resolve" of metadata as well.

This is the commit message #6:
------------------------------

minor refactoring during research for RFC-3176

This will soon need to return multiple extern-name/dep-name pairs.

This is the commit message #7:
------------------------------

See if opt-level 3 works on win-msvc in basic profile test for artifacts

This is the same value as is used in the other test of the same name,
which certainly runs on windows.

This is the commit message #8:
------------------------------

refactor

Assure the type for targets reflect that they cannot be the host target,
which removes a few unreachable!() expressions.

Put `root_unit_compile_kind` into `UnitFor`

Previously that wasn't done because of the unused `all_values()`
method which has now been deleted as its not being used anyomre.

This allows for the root unit compile kind to be passed as originally
intended, instead of working around the previous lack of extendability
of UnitFor due to ::all_values().

This is also the basis for better/correct feature handling once
feature resolution can be depending on the artifact target as well,
resulting in another extension to UnitFor for that matter.

Also
----

 - Fix ordering

   Previously the re-created target_mode was used due to the reordering
   in code, and who knows what kind of effects that might have
   (despite the test suite being OK with it).

   Let's put it back in place.

 - Deactivate test with filename collision on MSVC until RFC-3176 lands

Avoid clashes with binaries called 'artifact' by putting 'artifact/' into './deps/'

This commit addresses review comment https://github.com/rust-lang/cargo/pull/9992#discussion_r772939834

Don't rely on operator precedence for boolean operations

Now it should be clear that no matter what the first term is,
if the unit is an artifact, we should enqueue it.

Replace boolean and `/*artifact*/ <bool>` with `IsArtifact::(Yes/No)`

fix `doc::doc_lib_false()` test

It broke due to major breakage in the way dependencies are calculated.

Now we differentiate between deps computation for docs and for building.

Avoid testing for doctest cross-compilation message

It seems to be present on my machine, but isn't on linux and it's
probably better to leave it out entirely and focus on the portions
of consecutive output that we want to see at least.

A test to validate features are unified across libraries and those in artifact deps in the same target

Allow aarch64 MacOS to crosscompile to an easily executable alternative target

That way more tests can run locally.

Support for feature resolution per target

The implementation is taken directly from RFC-3176 and notably lacks
the 'multidep' part.

Doing this definitely has the benefit of making entirely clear
'what is what' and helps to greatly reduce the scope of RFC-3176
when it's rebuilt based on the latest RF-3028, what we are implementing
right now.

Also
----
- A test which prooves that artifact deps with different target don't have a feature namespace yet

- Add a test to validate features are namespaced by target

  Previously it didn't work because it relies on resolver = "2".

- 'cargo metadata' test to see how artifact-deps are presented

- Missed an opportunity for using the newly introduced `PackageFeaturesKey`

- Use a HashMap to store name->value relations for artifact environment variables

  This is semantically closer to what's intended.

  also: Remove a by now misleading comment

Prevent resolver crash if `target = "target"` is encountered in non-build dependencies

A warning was emitted before, now we also apply a fix.

Previously the test didn't fail as it accidentally used the old
resolver, which now has been removed.

Abort in parsing stage if nightly flag is not set and 'artifact' is used

There is no good reason to delay errors to a later stage when code
tries to use artifacts via environment variables which are not present.

Change wording of warning message into what's expected for an error message

remove unnecessary `Result` in `collect()` call

Improve logic to warn if dependencie are ignored due to missing libraries

The improvement here is to trigger correctly if any dependency of a
crate is potentially a library, without having an actual library target
as part of the package specification.

Due to artifact dependencies it's also possible to have a dependency
to the same crate of the same version, hence the package name
isn't necessarily a unique name anymore. Now the name of the actual
dependency in the toml file is used to alleviate this.

Various small changes for readability and consistency

A failing test to validate artifacts work in published crates as well

Originally this should have been a test to see target acquisition works
but this more pressing issue surfaced instead.

Make artifacts known to the registry data (backwards compatible)

Now artifacts are serialized into the registry on publish (at least
if this code is actually used in the real crates-io registry) which
allows the resolve stage to contain artifact information.

This seems to be in line with the idea to provide cargo with all
information it needs to do package resolution without downloading
the actual manifest.

Pick up all artifact targets into target info once resolve data is available

Even though this works in the test at hand, it clearly shows there
is a cyclic dependency between the resolve and the target data.

In theory, one would have to repeat resolution until it settles
while avoiding cycles.

Maybe there is a better way.

Add `bindeps`/artifact dependencies to `unstsable.md` with examples

Fix tests

Various small improvements

Greatly simplify artifact environment propagation to commands

Remove all adjustments to cargo-metadata, but leave tests

The tests are to record the status quo with the current code
when artifact dependencies are present and assure the information
is not entirely non-sensical.

Revert "Make artifacts known to the registry data (backwards compatible)"

This reverts commit adc5f8ad04840af9fd06c964cfcdffb8c30769b0.

Ideally we are able to make it work without altering the registry
storage format. This could work if information from the package
set is added to the resolve information.

Enrich resolves information with additional information from downloaded manifests

Resolve information comes from the registry, and it's only as rich as
needed to know which packages take part in the build.

Artifacts, however, don't influence dependency resolution, hence it
shouldn't be part of it.

For artifact information being present nonetheless when it matters,
we port it back to the resolve graph where it will be needed later.

Collect 'forced-target' information from non-workspace members as well

This is needed as these targets aren't present in the registry and
thus can't be picked up by traversing non-workspce members.

The mechanism used to pick up artifact targets can also be used
to pick up these targets.

Remove unnecessary adjustment of doc test

refactor `State::deps()` to have filter; re-enable accidentally disabled test

The initial rebasing started out with a separted `deps_filtered()`
method to retain the original capabilities while minimizing the chance
for surprises. It turned out that the all changes combined in this PR
make heavy use of filtering capabilities to the point where
`deps(<without filter>)` was unused. This suggested that it's required
to keep it as is without a way to inline portions of it.

For the original change that triggered this rebase, see

bd45ac81ba

The fix originally made was reapplied by allowing to re-use the
required filter, but without inlining it.

Always error on invalid artifact setup, with or without enabled bindeps feature

Clarify how critical resolver code around artifact is working

Remove workaround in favor of deferring a proper implementation

See https://github.com/rust-lang/cargo/pull/9992#issuecomment-1033394197
for reference and the TODO in the ignored test for more information.

truncate comments at 80-90c; cleanup

- remove unused method
- remove '-Z unstable-options'
- improve error message
- improve the way MSVC special cases are targetted in tests
- improve how executables are found on non MSVC

Avoid depending on output of rustc

There is cyclic dependency between rustc and cargo which makes it
impossible to adjust cargo's expectations on rustc without leaving
broken commits in rustc and cargo.

Add missing documentation

fix incorrect removal of non-artifact libs

This is also the first step towards cleaning up the filtering logic
which is still making some logic harder to understand than needs be.

The goal is to get it to be closer to what's currently on master.

Another test was added to have more safety regarding the overall
library inclusion logic.

inline `build_artifact_requirements_to_units()`

Simplify filtering

This adds a default filter to `state.deps(…)` making it similar to
what's currently in master, while creating another version of it
to allow setting a custom filter. This is needed as the default filter
won't allow build dependencies, which we need in this particular case.

`calc_artifact_deps(…)` now hard-codes the default filter which is
needed due to the use of `any` here:
c0e6abe384/src/cargo/core/compiler/unit_dependencies.rs (L1119)
.

Simplify filtering.
2022-02-22 08:08:42 +08:00
bors 46c9b51957 Auto merge of #10346 - yerke:yerke/no-run-test-executable-path, r=ehuss
Print executable name on cargo test --no-run #2

Closes #9957

This is a continuation of https://github.com/rust-lang/cargo/pull/9959.
2022-02-20 15:47:58 +00:00
Yerkebulan Tulibergenov eca63cfd4e Merge branch 'master' into yerke/no-run-test-executable-path 2022-01-30 23:13:35 -08:00
Eric Huss 54e7f684a8 Sync toml_edit versions 2022-01-25 14:33:32 -08:00
bors bb96b3a3e8 Auto merge of #10086 - epage:toml, r=ehuss
Port cargo from toml-rs to toml_edit

Benefits:
- A TOML 1.0 compliant parser
- Unblock future work
  - Have `cargo init` add the current crate to the workspace, rather
    than error
  - #5586: Upstream `cargo-add`

TODO
- [x] Analyze performance and address regressions
- [x] Identify and resolve incompatibiies
- [x] Resolve remaining test failures, see
      https://github.com/ordian/toml_edit/labels/cargo
- [x] ~~Switch the code from https://github.com/rust-lang/cargo/pull/10176 to only parse once~~ (this PR is being merged first)
2022-01-20 03:56:18 +00:00
maxwase 2623af0c43 Use is_symlink() method 2022-01-14 00:36:24 +03:00
Ed Page 320c279f43 Port cargo from toml-rs to toml_edit
Benefits:
- A TOML 1.0 compliant parser
- Unblock future work
  - Have `cargo init` add the current crate to the workspace, rather
    than error
  - #5586: Upstream `cargo-add`
2022-01-13 09:27:27 -06:00
Eric Huss 43a063c80a Stabilize namespaced and weak dependency features. 2022-01-06 15:56:56 -08:00
bors 180f599f60 Auto merge of #10196 - charlesroussel:master, r=alexcrichton
Add workaround for sporadic kills when building on Macos

This is the workaround for the issue https://github.com/rust-lang/cargo/issues/10060
2021-12-16 16:36:36 +00:00
Charles Roussel c9c67c0a93 Add workaround for sporadic kills when building on Macos 2021-12-16 16:59:57 +01:00
bors c689f55b8c Auto merge of #10193 - sstangl:help-alias-10138, r=alexcrichton
Display alias target on 'cargo help <alias>`

```
Previously, `cargo help <alias>` resolved the alias and displayed the
help for the targeted subcommand. For example, if `br` were aliased to
`build --release`, `cargo help br` would display the manpage for
cargo-build.

With this patch, it will print "'br' is aliased to 'build --release'".
```

Addresses issue #10138.

This is my first patch to Cargo. I attempted to follow the style of the surrounding code. Please let me know if any changes are required: happy to make them. In particular, I wasn't sure if any tests exist for this path.
2021-12-14 17:50:46 +00:00
Sean Stangl 4c66d18361 fix panic if an alias is defined to "" 2021-12-12 13:30:31 -07:00
Eric Huss 06bffb59a7 Bump versions of local deps. 2021-12-03 11:05:03 -08:00
Russ Weas effc72042b Implement glob escaping for clean -p
Implement glob escaping for clean -p

Add pattern escape for glob matching cargo clean files

Implement correct solution for #10068

Removed superfluous formatting changes

Update rm_rf_glob()'s error handling

Remove dir_glob reference for non-glob function

Added test

Satisfy clippy

Add MSVC support for test
2021-11-16 16:55:23 -06:00
bors dc6a1d5304 Auto merge of #10000 - alexcrichton:upgrade-edition, r=Eh2406
Upgrade Cargo to the 2021 edition

While I was poking around in the manifests I also went ahead and removed the `authors` entries since at least the one for Cargo itself is quite outdated and Cargo otherwise doesn't use these any more.
2021-10-23 18:08:27 +00:00
Sebastian Thiel cf8e464d6f
Do not canonicalize the exe-candidate at all
And here is why: https://github.com/rust-lang/cargo/pull/9991#issuecomment-949727679
2021-10-23 15:29:47 +08:00
Alex Crichton cab1e3566b Fix CI testing 2021-10-22 13:30:46 -07:00
Alex Crichton c687d83ada Remove authors directives from Cargo crates
Most of these are pretty dated and Cargo defaults nowadays to not
emitting an `authors` field so this commit also removes them from the
manifests.
2021-10-22 10:27:20 -07:00
Alex Crichton cabe1cca0a Upgrade Cargo to the 2021 edition
This didn't actually result in any code changes yet, for now this simply
flips the edition flag for all of our crates and documentation.
2021-10-22 10:25:52 -07:00
Sebastian Thiel 4906ef2364
Assure the binary name won't change after canonicalization, and keep looking if it does. 2021-10-21 18:21:18 +08:00
Sebastian Thiel 0d06193bf1
Only canonicalize executable path if it has relative directories
Otherwise symbolic links may also accidentally be resolved which may
lead to unexpected results in the case of 'coreutils', a binary
that depends on the executable name being a symbolic link.

This means a path like /bin/echo being canonicalized to /bin/coreutils
will loose all information about the desired functionality.

Test failures will occur if 'echo' is resolved that way and it's
not trivial to find the cause of it in the provided error messages.
2021-10-21 17:03:58 +08:00
Vaibhav bef4d79ff2 Print executable name on cargo test --no-run.
Closes #9957

Signed-off-by: Vaibhav <vrongmeal@gmail.com>
2021-10-05 23:47:38 +05:30
Eric Huss 422d5b030c Enable some tests on windows. 2021-09-08 23:34:37 -07:00
Weihang Lo 0afd40b4de
Update tests to display dep-req info for dep-chain 2021-08-24 00:39:38 +08:00
Nipunn Koorapati 5a56cf2e5b Refactor echo cargo subcommand test helper into cargo-test-support 2021-08-14 22:37:54 -07:00
Nipunn Koorapati dde290e6ff Refactor fake_file() away from cargo_command tests
There are already similar preexisting test helpers which
also work on windows. Port over the executable-creation
helper into the file() helper and things appear to pass.
2021-08-05 19:09:58 -07:00
Erick Tryzelaar f71b231aea Update cargo-platform to 0.1.2
This preps cargo-platform for a release. The only substantial change is that
this should include the license files into the archive that is uploaded to
crates.io.

Closes #9758
2021-08-04 16:13:04 -07:00
Eric Huss 70a607eaa7 Remove nbsp characters. 2021-07-30 15:40:37 -07:00
Eric Huss 4fbf61da10 Bump cargo-util version. 2021-07-29 09:23:23 -07:00
Alik Aslanyan 8ee76f6082
Weather is not nice today.. 2021-07-23 17:15:14 +04:00
Dustin J. Mitchell 76a079cbd9 Factor version preferences into a struct
This concentrates all of the "prefer this version" logic previously
handled with `try_to_use` and `prefer_patch_deps` parameters into a
struct that hides both the reason a package version might be preferred
and the form that preference took (Dependency or PackageId).  Besides
simplifying `RegistryQuerier::query` slightly, this invites further
refinements to version preferences to support new cargo features.
2021-07-18 21:05:16 +00:00
bors f8ba1cbfcb Auto merge of #9639 - djmitche:issue9535, r=Eh2406
Prefer patched versions of dependencies

When selecting among several versions of a paackage, prefer versions
from `[patch]` sections over other versions, similar to how locked
versions are preferred.

Patches come in the form of a Dependency and not a PackageId, so this
preference is expressed with `prefer_patch_deps`, distinct from
`try_to_use`.

Fixes #9535
2021-07-14 19:14:22 +00:00
Eric Huss b67454c660 Make it easier to run testsuite with a custom toolchain. 2021-07-11 14:02:47 -07:00
Dustin J. Mitchell bd4a353e98 Prefer patched versions of dependencies
When selecting among several versions of a paackage, prefer versions
from `[patch]` sections over other versions, similar to how locked
versions are preferred.

Patches come in the form of a Dependency and not a PackageId, so this
preference is expressed with `prefer_patch_deps`, distinct from
`try_to_use`.
2021-07-09 18:23:21 +00:00
Eric Huss 28c3bef71a Include the linker in the fingerprint. 2021-07-01 20:33:48 -07:00
Toothbrush c973a6d0af
rustfmt 2021-06-29 18:18:28 +01:00
Toothbrush 684391e444
Change if cfg!(..) { } to #[cfg!(..)] { }
This fixes builds on non-Windows platforms.
2021-06-29 17:19:14 +01:00
Toothbrush f1c8e56909
Format exclude_from_content_indexing 2021-06-28 21:45:59 +01:00
Toothbrush 9d96a88961
Exclude target from content-indexing on Windows
This has a noticeable performance improvement for most projects, especially when the storage device is a hard drive.

Closes #8694
2021-06-28 20:12:44 +01:00
Eric Huss c0dca04f49 Disambiguate is_symlink. 2021-06-19 11:27:14 -07:00
Tomasz Miąsko 8df771f381 Avoid quadratic complexity when splitting output into lines
When searching for newlines in a process output keep track which part of
buffer was already examined to avoid processing the same data again and
again.
2021-06-18 20:00:55 +02:00
Tomasz Miąsko 9f60fcacaf Simplify line splitting code in exec_with_streaming NFC 2021-06-18 20:00:55 +02:00
Eric Huss 16b5402fd7 testsuite: Switch to colored diffs with Myers diff. 2021-06-16 15:43:29 -07:00
Eric Huss 205148e645 Only normalize paths on windows.
I don't trust that all these transformations won't have unintended
consequences on other platforms. It is nice to verify there aren't any
backslash shenanigans on other platforms.
2021-06-16 10:35:26 -07:00
Eric Huss aea5ca3ca0 Remove the double-backslash escape for matching.
Using `with_json` is safer since it knows what JSON escaping is.
2021-06-16 09:44:29 -07:00
Eric Huss b73e3d4fa5 Don't export lines_match.
Use better high-level interfaces to achieve the same thing.
2021-06-16 09:44:29 -07:00
Eric Huss 24b8936c20 Remove normalized_lines_match, it is not needed. 2021-06-16 09:44:29 -07:00
Eric Huss 6dff99781d Remove with_either_contains.
It isn't needed anymore, and I would prefer to not keep around unused code.
It can always be added back if ever needed again.
2021-06-16 09:44:29 -07:00
Eric Huss e132bb53ab Move comparison and diffing code to a new module.
This includes various minor refactorings to try to clean things up
and provide better error messages.
2021-06-16 09:44:29 -07:00
Eric Huss 0f5deb64f9 testsuite: Support anyhow error chains in error messages.
This is intended to help with adding more usage of anyhow in the
testsuite, which can help show context for errors.

This also includes some small improvements to the error messages to
provide more information.
2021-06-16 09:44:28 -07:00
Eric Huss 2021865d88 Remove some unused code. 2021-06-15 15:38:02 -07:00
Eric Huss 393077f968 Add run_json to Execs.
This is a helper to run the process and return a JSON object.
2021-06-11 16:07:20 -07:00
Eric Huss 3be34cb834 Remove "Expected: execs" from testsuite error.
That message was not helpful.
2021-06-11 15:25:50 -07:00
Eric Huss 0f304ca450 Fix verify_checks_output.
This was accidentally broken in
cc5e9df64a
causing it to not check in the error case (which is the only case that mattered).
2021-06-11 13:12:30 -07:00
Eric Huss 5d1b0f9c43 Switch cargo-test-support to anyhow. 2021-06-11 12:37:27 -07:00
Eric Huss 7b229bbe39 Move the rustc-echo-wrapper to be shared across tests.
This helps avoid rebuilding the same project several times.
2021-06-09 17:13:33 -07:00
Weihang Lo df82a44f9e
refactor: extract common make_dep_path to cargo_util 2021-06-01 11:14:53 +08:00
David Tolnay 396bdd3a89
Remove parsing of broken version syntax from 5 years ago 2021-05-26 14:37:39 -07:00
bors 070e459c2d Auto merge of #9468 - PaulDance:fix-rustdoc-warnings, r=ehuss
Fix rustdoc warnings

Change some small parts of the unit documentation in order to resolve warnings emitted when running `cargo doc` from the root of this project. It should help reduce the noise when checking that new or updated documentation builds correctly.

See the commit messages for details about the modifications themselves, although they should be rather simple.

Cheers,
Paul.
2021-05-11 18:12:23 +00:00
Paul Mabileau a5b4b4710a
Bump url to 2.2.2 where Into<String> for Url is used
The base package, `cargo-test-support` and `mdman`.

Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>
2021-05-10 22:20:11 +02:00
Paul Mabileau c021ba9acf
Fix Url::into_string deprecation warning
`url::Url::into_string` is deprecated. The `Into<String>` implementation
is now used.

Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>
2021-05-10 22:19:00 +02:00
Paul Mabileau 9ea1cbdeda
Fix doc warnings for cargo-util::paths
Add parentheses to disambiguate from `write!`.

Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>
2021-05-09 19:47:08 +02:00
Vojtech Kral 53343bc398 Use CARGO_TARGET_TMPDIR in integration tests if available 2021-05-07 00:03:01 +02:00
Léo Gaspard 731d881a60 handle review comments 2021-04-24 19:12:52 +02:00
Léo Gaspard 5e11afc1ab Expose build.target .cargo/config setting as packages.target in Cargo.toml 2021-04-24 19:12:52 +02:00
Eric Huss 10eb56f2c4 Update clippy lint allow set. 2021-04-13 09:02:07 -07:00
bors 7204d3989d Auto merge of #9302 - ehuss:cargo-config, r=alexcrichton
Add `cargo config` subcommand.

This adds an initial version of the `cargo config` command as discussed in #2362.

Closes #2362
2021-03-30 19:07:19 +00:00
Alex Crichton a4f0988ef8 Default macOS targets to unpacked debuginfo
This commit continues the work from #9112 to enable `unpacked` split
debuginfo on macOS targets by default. This has been discussed on [internals]
for awhile now and no breakage has emerged while significant speedups
have. This is expected to be a compile-time and `target`-directory size
win for almost all macOS Rust projects.

While breakage is possible it's possible to mitigate this with
project-local or global cargo configuration of the `dev` and `test` profiles.

[internals]: https://internals.rust-lang.org/t/help-test-faster-incremental-debug-macos-builds-on-nightly/14016/9
2021-03-26 07:38:17 -07:00
Eric Huss 96a5642217 Add cargo config subcommand. 2021-03-25 13:52:31 -07:00
bors fb45eb132e Auto merge of #9292 - ehuss:cargo-util, r=alexcrichton
Split out cargo-util package for cargo-test-support.

This splits out code from `cargo` that was being used by `cargo-test-support` in order to remove the dev-dependency cycle on the `cargo` crate. The intent here is to improve development build times. On my system, `touch src/cargo/lib.rs ; cargo check --profile=test` goes from 6.4 seconds to 3.5. I suspect more substantial changes (more than just `touch`) should exhibit even more improvements.

This has a substantial downside that it is another package to manage publishing, particularly with making sure the version is updated correctly for crates.io. I'm uncertain if on balance it is worth it, but I lean towards moving forward with it.
2021-03-22 14:11:51 +00:00
Eric Huss 378b086f2c Fix redundant_semicolons warning in resolver-tests. 2021-03-20 17:44:08 -07:00
Eric Huss c840160a6d Remove the dev-dependency cycle on cargo. 2021-03-20 17:42:42 -07:00
Eric Huss 0fb35e3129 Remove cargo:: link. 2021-03-20 17:42:42 -07:00
Eric Huss 565591f6e9 Remove use of CRATES_IO_INDEX in cargo-test-support.
Unfortunate duplication of the string, but I think it is unlikely
to have any consequences.
2021-03-20 17:42:41 -07:00
Eric Huss 0ad3fb1b57 Remove CargoResult from cargo-test-support. 2021-03-20 17:42:41 -07:00
Eric Huss 10224938bf Remove use of Rustc from cargo-test-support.
cargo-test-support wasn't using any of the caching or other logic from
Rustc, so this just swaps with a very basic implementation in order to
remove the dependency on `cargo`.
2021-03-20 17:42:41 -07:00
Eric Huss 4aa1ec2419 Move Sha256 to cargo-util. 2021-03-20 17:42:41 -07:00
Eric Huss 1dae5acb7d Move paths to cargo-util. 2021-03-20 17:42:41 -07:00
Eric Huss dbfdd49559 Move is_ci to cargo-util. 2021-03-20 17:42:32 -07:00
Eric Huss 888100352a Move ProcessBuilder to cargo-util. 2021-03-20 15:19:03 -07:00
Eric Huss 669340333a Split util code into a separate package. 2021-03-20 15:15:54 -07:00
Kornel 3f7f0942cd track_caller on custom assert functions 2021-03-03 17:17:07 +00:00
bors b219f0eb7a Auto merge of #9181 - jyn514:computer-says-no, r=ehuss
Forbid setting `RUSTC_BOOTSTRAP` from a build script on stable

Instead, recommend `RUSTC_BOOTSTRAP=crate_name`. If cargo is using a nightly toolchain, or if RUSTC_BOOTSTRAP was set in *cargo*'s build environment, the error is downgraded to a warning, since the variable won't affect the build.

This is mostly the same as suggested in https://github.com/rust-lang/cargo/issues/7088#issuecomment-713867773, except that `RUSTC_BOOTSTRAP=` values other than 1 are treated the same as `RUSTC_BOOTSTRAP=1`. My reasoning was that https://github.com/rust-lang/rust/pull/77802 is now on 1.50 stable, so some crates may have started using it, and I would still prefer not to give hard errors when there's no workaround.

Closes https://github.com/rust-lang/cargo/issues/7088.

r? `@joshtriplett`
2021-03-03 03:19:33 +00:00
Eric Huss c9bd6e12e1 Minor update to registry API error messages. 2021-02-27 12:38:17 -08:00
bors 6780fbd22a Auto merge of #9207 - ehuss:testsuite-splitdebug, r=Eh2406
testsuite: Use split debuginfo on macos.

This switches the testsuite to use "unpacked" debuginfo on macos, which is a substantial performance boost. On my system, the testsuite runs 1.55 times faster with this change.  Along with #9206, total testsuite time is 3.1 times faster.
2021-02-25 19:06:49 +00:00
Eric Huss c73765f9c3 testsuite: Improve performance when using rustup. 2021-02-25 09:07:48 -08:00
Eric Huss 0f78dbd38e testsuite: Use split debuginfo on macos. 2021-02-25 09:06:11 -08:00
Joshua Nelson a5720117fe Make nightly_features_allowed a field instead of a function
`nightly_features_allowed()` is no longer doing any work, so it can be
accessed directly. This also renames the `enable_nightly_features` field
to `nightly_features_allowed`.
2021-02-24 15:11:31 -05:00
Joshua Nelson 4b096beaed Fix masquerade_as_nightly_cargo in work threads
Previously, since `ENABLE_NIGHTLY_FEATURES` and
`NIGHTLY_FEATURES_ENABLED` were thread locals, reading them in any other
thread would always say nightly features were disabled. Now, they are
tied to the `Context` itself, so it is both more clear how the variables
are being set and fixes the behavior within work threads.

Note that `Context` is not thread-safe, so this passes a boolean through
to `BuildOutput::parse`.
2021-02-24 14:43:00 -05:00
bors 8eb0e9a855 Auto merge of #9184 - ehuss:fix-next-edition, r=alexcrichton
Updates to edition handling.

This introduces some updates for edition handling (split into commits for review).  In short:

* `cargo-features = ["edition2021"]` can be used to opt-in to 2021 support without needing to pass around `-Z unstable-options`. I tried to emphasize in the docs that this is only for testing and experimentation.
* Make `"2"` the default resolver for 2021 edition.
* Make `cargo fix --edition` mean the "next" edition from the present one, and support 2021. Also, if already at the latest edition, generate a warning instead an error.
* I decided to allow `cargo fix --edition` from 2018 to 2021 on the nightly channel without an explicit opt-in. It's tricky to implement with an opt-in (see comment in diff).

Partial for #9048.
Fixes #9047.
2021-02-23 21:35:42 +00:00
Eric Huss 3f2f7e30ff Add a migrating message for cargo fix --edition.
This helps indicate which edition you are moving from and to.
2021-02-17 21:36:28 -08:00
Eric Huss 820537c706 Change Fixing to Fixed, and add a verbose "Fixing".
What was previously "Fixing" was a message for after the fixes had
been applied. I think it would be clearer if it said "Fixed",
to indicate that the fixes had actually finished.

The new "Fixing" is posted just before it starts. This is verbose-only
since it is a little noisy.
2021-02-17 20:41:38 -08:00
Eric Huss be28b58b45 Add features2 to the index. 2021-02-10 11:15:19 -08:00
Eric Huss 196673bb1e Add a schema version to the index. 2021-02-10 10:58:07 -08:00
bjorn3 f5a3d55983 Fix warnings of the new non_fmt_panic lint 2021-02-06 19:10:42 +01:00
Eric Huss 33f648ab3b Fix permission issue with cargo vendor. 2021-02-03 17:37:00 -08:00
bors aaaf296ab7 Auto merge of #9112 - alexcrichton:split-debuginfo, r=ehuss
Add split-debuginfo profile option

This commit adds a new `split-debuginfo` option to Cargo compilation
profiles which gets forwarded to the `-Csplit-debuginfo` codegen option
in rustc. This commit also sets the default, only on macOS, to be
`-Csplit-debuginfo=unpacked`. The purpose of this change is to leverage
rust-lang/rust#79570 to avoid running `dsymutil` on incremental builds
while also preserving a pleasant debugging experience by default. This
should lead to much faster incremental build times on macOS since
`dsymutil` isn't exactly the speediest tool in the world.

This is technically a breaking change in Cargo because we're no longer
by-default producing the `*.dSYM` folders on macOS. If those are still
desired, however, authors can always run `dsymutil` themselves or
otherwise configure `split-debuginfo = 'packed'` in their
manifest/profile configuration.
2021-02-03 22:50:15 +00:00
Eric Huss 06b8d1cac1 Add a ResponseError for registry API interaction.
The intent here is to make it easier to work with API errors.

This also includes some new tests for checking network errors.
2021-02-02 17:44:57 -08:00
Eric Huss 340656e29d Add RegistryBuilder to help initializing test registries.
The intent here is to make it more flexible to create different registry
setups, and to reuse code a little more easily.
2021-02-02 15:48:48 -08:00
Alex Crichton cc5e9df64a Cache failures in the rustc info cache
This commit updates the rustc info cache to cache failures to execute
rustc as well as successes. This fixes a weird issue where if you're
probing for flags the `rustc_info_cache` test fails on channels which
don't have the flag since previously a failure to execute rustc resulted
in never caching the result.
2021-02-01 11:29:25 -08:00
Alex Crichton ed4568e108 Add split-debuginfo profile option
This commit adds a new `split-debuginfo` option to Cargo compilation
profiles which gets forwarded to the `-Csplit-debuginfo` codegen option
in rustc. This commit also sets the default, only on macOS, to be
`-Csplit-debuginfo=unpacked`. The purpose of this change is to leverage
rust-lang/rust#79570 to avoid running `dsymutil` on incremental builds
while also preserving a pleasant debugging experience by default. This
should lead to much faster incremental build times on macOS since
`dsymutil` isn't exactly the speediest tool in the world.

This is technically a breaking change in Cargo because we're no longer
by-default producing the `*.dSYM` folders on macOS. If those are still
desired, however, authors can always run `dsymutil` themselves or
otherwise configure `split-debuginfo = 'packed'` in their
manifest/profile configuration.
2021-02-01 09:21:36 -08:00
klensy dcc9587160 trivial char range check 2021-01-29 01:27:16 +03:00
Eric Huss eaa5896405 Remove Registry::new. 2021-01-22 11:06:51 -08:00
bors 638f33d036 Auto merge of #9035 - weihanglo:fix/git-init-search-path, r=alexcrichton
Fix: set default git config search path for tests

Fixes https://github.com/rust-lang/cargo/issues/8863 by setting the default config search path.

Just wait https://github.com/rust-lang/git2-rs/pull/656 being merged and update Cargo.toml the new release of git2-rs 😄
2021-01-22 15:29:39 +00:00
Weihang Lo 06d65a48f8
chore: bump versions of git2 and libgit2-sys 2021-01-22 23:27:44 +08:00
Weihang Lo 02b49de61c
fix: set search path before init repos 2021-01-21 14:55:30 +08:00
Dirkjan Ochtman c221fec911 Implement support for rust-version field in project metadata 2021-01-20 11:40:41 +01:00
Matthias Krüger 8e3f97f02d reduce nesting of if x { } else { if y {} else {} } expressions by concerting to if x {} else if y {} else {} (clippy::collapsible_else_if) 2021-01-06 13:59:17 +01:00
Eric Huss 382b2519b4 Add version to credential dependencies.
I forgot to add the version in the dependency declaration for cargo-credential.
2020-12-16 12:25:59 -08: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 69c5af8591 Add some credential manifest metadata and READMEs. 2020-12-06 11:41:12 -08:00
Eric Huss 37e9c77a33 Add docs on how cargo-credential finds the action argument. 2020-12-06 11:41:12 -08:00
Eric Huss 8ac04d1e63 Check for nul in Windows utf-16 wide-string. 2020-12-06 11:40:53 -08:00
Eric Huss eb081ed301 Workaround fs issue in cargo publish. 2020-12-05 14:10:29 -08:00
Eric Huss cc6df1d7a5 Implement credential-process. 2020-12-02 19:09:54 -08:00
Igor Matuszewski aab416f6e6 Use u32/64::to/from_le_bytes instead of bit fiddling 2020-11-09 23:32:39 +01:00
Aaron Hill 939b5ff766
Bump anyhow dependency to 1.0.34 in crates-io crate
This will keep `crates-io` compiling if https://github.com/rust-lang/rust/issues/33953
is fixed. See https://github.com/dtolnay/anyhow/pull/120
2020-11-02 18:45:18 -05:00
Eric Huss b731190daa Add a future-compatibility warning on allowed feature name characters. 2020-10-27 14:23:35 -07:00
Eric Huss bcfdf9fbad New namespaced features implementation. 2020-10-23 16:04:41 -07:00
Weihang Lo d613cd66c7
Merge branch 'master' into feat/glob-pattern 2020-10-18 08:48:30 +08:00
Eric Huss 1a86f232c5 Fix man page links inside option blocks. 2020-10-17 12:15:12 -07:00
Ivan Tham a90984924d
Add help to substitute macros 2020-10-14 10:01:12 +08:00
Weihang Lo be31989a43
test: minimal shell quote supoort for cargo-test-support 2020-10-04 22:55:50 +08:00
bors 1ffdfb70eb Auto merge of #8715 - ehuss:contrib, r=alexcrichton
Add contributor guide.

This consolidates and extends the contributor information in a single place. This is an mdbook project, along with a CI job which will build and deploy it to GitHub Pages at <https://rust-lang.github.io/cargo/contrib/>.

You can view a rendered version here: <https://ehuss.github.io/cargo/contrib/>

I don't know if this will actually be helpful to anyone, but I figured it's worth a shot.

NOTE: The CI deploy is designed to preserve the existing gh-pages content.  However, it will **delete the history** on that branch. I think that should be fine, there doesn't seem to be too much interesting stuff there.  I do have a backup in my fork, though. Some extra scrutiny on the code might be wise.  The reason it deletes the history is because deploying mdbook on every push would balloon the repository size.
2020-09-27 07:06:34 +00:00
bors c369b8c8d8 Auto merge of #8165 - mchernyavsky:force-progress, r=ehuss
Add a term option to configure the progress bar

Closes https://github.com/rust-lang/cargo/issues/7587.
2020-09-23 21:28:14 +00:00
Eric Huss 4d40ef4ef4 Add contributor guide. 2020-09-18 14:01:51 -07:00
mchernyavsky d649c66191 Add a term option to configure the progress bar 2020-09-16 22:32:31 +03:00
Mukund Lakshman 8d610e1d28 Display formatted output for JSON diffing in tests. 2020-09-12 17:24:53 +01:00
Alex Crichton bf10871c32 Fix flakiness in close_output test
It looks like stdout/stderr can race as to which gets printed first, but
both are valid for this test.

Closes #8665
2020-08-31 13:15:30 -07:00
bors 964a16a28e Auto merge of #8575 - matthiaskrgr:clippy_v16, r=ehuss
clippy fixes, use matches! macro in more places
2020-08-04 03:47:51 +00:00
Matthias Krüger f23b91190c use sort_by_key() instead of comparing by keys manually
replace format!() macro by String::from()
use eprintln() instead of manually writing to std::io::stderr
2020-08-03 22:52:01 +02:00
Eric Huss 566706e863 Fix some Windows newline behavior. 2020-08-01 12:22:14 -07:00
Eric Huss 8b878f38cd Add mdman for generating man pages. 2020-08-01 11:13:52 -07:00
Alex Crichton dc4b695f41 Build host dependencies with opt-level 0 by default
This commit updates Cargo's build of host dependencies to build them
with optimization level 0 by default instead of matching the profile of
the final binary.

Since Cargo's inception build dependencies have, by default, been built
in a profile that largely matches the profile of the final target
artifact. Build dependencies, however, rarely actually need to be
optimized and are often executing very small tasks, which means that
optimizing them often wastes a lot of build time. A great example of
this is procedural macros where `syn` and friends are pretty heavyweight
to optimize, and the amount of Rust code they're parsing is typically
quite small, so the time spent optimizing rarely comes as a benefit.

The goal of this PR is to improve build times on average in the
community by not spending time optimizing build dependencies (build
scripts, procedural macros, and their transitive dependencies). The PR
will not be a universal win for everyone, however. There's some
situations where your build time may actually increase:

* In some cases build scripts and procedural macros can take quite a
  long time to run!
* Cargo may not build dependencies more than once if they're shared with
  the main build. This only applies to builds without `--target` where
  the same crate is used in the final binary as in a build script.

In these cases, however, the `build-override` profile has existed for
some time know and allows giving a knob to tweak this behavior. For
example to get back the previous build behavior of Cargo you would
specify, in `Cargo.toml`:

    [profile.release.build-override]
    opt-level = 3

or you can configure this via the environment:

    export CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_OPT_LEVEL=3

There are two notable features we would like to add in the future which
would make the impact of a change like this smaller, but they're not
implemented at this time (nor do we have concrete plans to implement
them). First we would like crates to have a way of specifying they
should be optimized by default, despite default profile options. Often
crates, like lalrpop historically, have abysmal performance in debug
mode and almost always (even in debug builds) want to be built in
release mode. The second feature is that ideally crate authors would be
able to tell Cargo to minimize the number of crates built, unifying
profiles where possible to avoid double-compiling crates.

At this time though the Cargo team feels that the benefit of changing
the defaults is well worth this change. Neither today nor directly after
this change will be a perfect world, but it's hoped that this change
makes things less bad!
2020-07-17 12:39:41 -07:00
Arlo Siemsen 58869e5ce6 Stop ignoring Array ordering Json comparison tests. Update tests to have sorted order. 2020-07-15 16:32:19 -07:00
bors 2f4097aa6b Auto merge of #8416 - est31:remove_derive, r=alexcrichton
Remove unused serde_derive dependency from the crates.io crate
2020-06-26 16:33:12 +00:00
est31 65591e8144 Remove unused serde_derive dependency 2020-06-26 17:29:09 +02:00
CrLF0710 ad0940c9ad Add missing license field. 2020-06-20 10:03:25 +08:00
Matthias Krüger 6eefe3c236 fix clippy warnings 2020-06-04 00:55:45 +02:00
bors 5847787fef Auto merge of #8274 - Eh2406:8249-repro, r=alexcrichton
reset lockfile information between resolutions

#8249 pointed out that some kind of lockfile data was leaking between calls to the resolver. @ehuss made a reproducing test case. This PR resets the `LockedMap` data structure when calling `register_previous_locks`.

lets see if CI likes it.
fix #8249
2020-06-01 16:01:10 +00:00
Eric Huss 80e55c774b Fix tests with enoent error message on non-english systems. 2020-05-29 12:34:17 -07:00
Eh2406 8ce0d02971 confirm that it is not a bug at resolver level 2020-05-28 15:43:30 -04:00
Daniel Wagner-Hall 556c236f9a Bump to semver 0.10 for VersionReq::is_exact
This stops using `to_string` as a proxy for this now-provided precise API.

This reverts commit b71927224f and bupms the
dependency version in Cargo.toml.
2020-05-25 11:11:45 +01:00
Eric Huss 771b2bca76 Repro 2020-05-24 17:31:30 -04:00
Matthias Krüger 6694fdb677 clippy fixes 2020-05-01 01:16:30 +02:00
bors 90931d9b31 Auto merge of #8077 - faern:use-assoc-int-consts, r=ehuss
Use associated constants directly on primitive types instead of modules

This PR is in no way critical. It's more of a code cleanup. It comes as a result of me making https://github.com/rust-lang/rust/pull/70857 and search-and-replacing all usage of the soft-deprecated ways of reaching primitive type constants.

It makes the code slightly shorter, that's basically it. And showcases the recommended way of reaching these consts on new code :)
2020-04-28 01:56:59 +00:00
Dylan MacKenzie cf57ce1574 Clear RUSTDOCFLAGS for all tests 2020-04-27 14:31:44 -07:00
bors 97d39aeaac Auto merge of #8139 - mati865:patch-1, r=ehuss
Add windows-gnu CI and fix tests

One remaining failure:
```
---- features::feature_off_dylib stdout ----
running `d:\a\1\s\target\debug\cargo.exe build --features f1`
running `d:\a\1\s\target\debug\cargo.exe run -p bar`
thread 'features::feature_off_dylib' panicked at '
Expected: execs
    but: exited with exit code: 101
--- stdout

--- stderr
   Compiling foo v0.0.1 (D:\a\1\s\target\cit\t663\foo)
   Compiling bar v0.0.1 (D:\a\1\s\target\cit\t663\foo\bar)
    Finished dev [unoptimized + debuginfo] target(s) in 0.69s
     Running `target\debug\bar.exe`
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"f1"`,
 right: `"no f1"`', bar\src\main.rs:5:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\bar.exe` (exit code: 101)
', crates\cargo-test-support\src\lib.rs:833:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    features::feature_off_dylib
```

I disassembled the dylibs and `cargo run -p bar` correctly rebuilt it inside `target/debug/deps/` but did not copy it to `target/debug`. To further confirm, calling `cp target/debug/deps/foo.dll target/debug/` manually solved the issue.
Any idea?

----

I left `FIXME` in places where import lib should be added with https://github.com/rust-lang/cargo/pull/6875.

`TOOLCHAIN: nightly-x86_64-pc-windows-gnu` can be replaced with beta on Thursday.
2020-04-21 17:03:56 +00:00
Mateusz Mikuła 9f742466f1 Update tests for windows-gnu 2020-04-21 17:25:25 +02:00
bors 9d84c0c734 Auto merge of #7973 - ehuss:index-updates, r=alexcrichton
Several updates to token/index handling.

This attempts to tighten up the usage of token/index handling, to prevent accidental leakage of the crates.io token.

* Make `registry.index` config a hard error. This was deprecated 4 years ago in #2857, and removing it helps simplify things.
* Don't allow both `--index` and `--registry` to be specified at the same time. Otherwise `--index` was being silently ignored.
* `registry.token` is not allowed to be used with the `--index` flag. The intent here is to avoid possibly leaking a crates.io token to another host.
* Added a warning if source replacement is used and the token is loaded from `registry.token`.

Closes #6545
2020-04-20 19:50:40 +00:00
Eric Huss 65274ea7d5 Add a warning when using registry.token with source replacement. 2020-04-19 09:25:32 -07:00
Eric Huss 787e75b797 Add resolver opt-in for new feature resolver. 2020-04-19 08:45:18 -07:00
Eric Huss 4ae79d2ffd Use fs helpers instead of File functions. 2020-04-17 07:56:16 -07:00
Eric Huss 4367ec4d11 Use Path methods instead of fs::metadata. 2020-04-16 22:00:22 -07:00
Linus Färnstrand c428c0ef41 Use associated constants directly on primitive types instead of modules 2020-04-06 23:37:06 +02:00
Alex Crichton bac300bda0 Add support for -Cembed-bitcode=no
This commit is the Cargo half of support necessary for
rust-lang/rust#70458. Today the compiler emits embedded bytecode in
rlibs by default, but compresses it. This is both extraneous disk space
and wasted build time for almost all builds, so the PR in question there
is changing rustc to have a `-Cembed-bitcode` flag which, when enabled,
places the bitcode in the object file rather than an auxiliary file (no
extra compression), but also enables `-Cembed-bitcode=no` to disable
bitcode emission entirely.

This Cargo support changes Cargo to pass `-Cembed-bitcode=no` for almost
all compilations. Cargo will keep `lto = true` and such working by not
passing this flag (and thus allowing bitcode to get embedded), but by
default `cargo build` and `cargo build --release` will no longer have
any bitcode in rlibs which should result in speedier builds!

Most of the changes here were around the test suite and various
assertions about the `rustc` command lines we spit out. One test was
hard-disabled until we can get `-Cembed-bitcode=no` into nightly, and
then we can make it a nightly-only test. The test will then be stable
again once `-Cembed-bitcode=no` hits stable.

Note that this is intended to land before the upstream `-Cembed-bitcode`
change. The thinking is that we'll land everything in rust-lang/rust all
at once so there's no build time regressions for anyone. If we were to
land the `-Cembed-bitcode` PR first then there would be a build time
regression until we land Cargo changes because rustc would be emitting
uncompressed bitcode by default and Cargo wouldn't be turning it off.
2020-04-01 14:31:06 -07:00
bors 8a0d4d9c9a Auto merge of #8028 - ehuss:new-proc-macro-decouple, r=alexcrichton
Re-implement proc-macro feature decoupling.

This is essentially a rewrite of #8003. Instead of adding proc-macro to the index, it uses a strategy of downloading all packages before doing feature resolution. Then the package can be inspected for the proc-macro field.

This is a fairly major change. A brief overview:
- `PackageSet` now has a `download_accessible` method which tries to download a minimal set of every accessible package. This isn't very smart right now, and errs on downloading too much. In most cases it should be the same (or nearly the same) as before. It downloads extra in the following cases:
    - The check for `[target]` dependencies checks both host and target for every dependency. I could tighten that up a little so build dependencies only check for the host, but it would add some complexity and I wanted to get feedback first.
    - Optional dependencies disabled by the new feature resolver will get downloaded.
- Removed the loop in computing unit dependencies where downloading used to reside.
- When downloading starts, it should now show a more accurate count of how many crates are to be downloaded. Previously the count would fluctuate while the graph is being built.
2020-03-24 17:57:04 +00:00
Alex Tokarev 38aa4a2353 Remove unused transitive dependencies: miniz_oxide, adler32
Fixes #8019
2020-03-23 19:19:29 +03:00
Eric Huss 944f5049f1 Re-implement proc-macro feature decoupling. 2020-03-22 15:08:02 -07:00
bors 92d0ce8069 Auto merge of #8003 - ehuss:proc-macro-index, r=alexcrichton
Add proc-macro to index, and new feature resolver.

This adds the "pm" field to the index so that Cargo can detect which packages contain a proc-macro without downloading the package.

The second commit builds on that to support proc-macros in the new "de-unification" of the new feature resolver. This prevents dependencies shared between proc-macros and other dependency kinds from having features unified.

cc #7915
2020-03-18 14:00:07 +00:00
Eric Huss d47a9545db Use Option::as_deref 2020-03-15 18:51:38 -07:00
Eric Huss 0b115f57aa -Zfeatures=host_dep: Support decoupling proc-macro features. 2020-03-15 15:59:42 -07:00
Eric Huss 5a1862cd36 Add proc-macro to the index. 2020-03-15 10:10:25 -07:00
bors 7302186d7b Auto merge of #7533 - yaahc:clippy-banishment, r=ehuss
Close the front door for clippy but open the back
2020-03-14 20:50:15 +00:00
Jane Lusby d02f476804 rustfmt 2020-03-13 15:02:55 -07:00
Jane Lusby 76797b5c2a switch from bash script to rust program 2020-03-13 14:59:41 -07:00
Alex Crichton 82239d7a10 Bump libgit2 dependencies
Brings in rust-lang/git2-rs#527

Closes #7466
Closes #7988
2020-03-13 12:26:46 -07:00
Jane Lusby b0351e4d87 Close the front door for clippy but open the back 2020-03-12 19:27:48 -07:00
Alex Crichton 5b6e7397ed Update libgit2 dependency
Brings in a few CVE fixes and such for libgit2, bringing libgit to
0.99.0
2020-02-26 09:39:05 -08:00
Matthias Krüger 1d912002e9 fix most remaining clippy findings (mostly redundant imports) 2020-02-21 12:15:16 +01:00
Alex Tokarev 2b1dc3e518 Run through nightly clippy 2020-02-21 01:27:18 +03:00
Alex Tokarev 45ad3f9986 Remove unused imports 2020-02-20 23:58:10 +03:00
Eric Huss 457c4bc4c8 Work-around macOS 10.15 Gatekeeper issue. 2020-02-19 16:46:35 -08:00
Eric Huss 0a2f691381 Switch azure to macOS 10.15. 2020-02-19 16:46:29 -08:00
Eric Huss 0d44a8267b Rework internal errors. 2020-02-17 19:03:57 -08:00
Josh Stone 9c8b4dcd3e Link the licenses into crates/cargo-platform
The licenses should be included in the package published on crates.io
2020-02-14 15:54:22 -08:00
Kinrany bc4c65c5d3 Do not run formats_source if rustfmt is not available
Generalized `clippy_is_available` and renamed as `command_is_available`.

No checks in `ignores_failure_to_format_source`, it's not supposed to
use `rustfmt` even if it's available
2020-02-05 10:09:43 +03:00
Eric Huss 0279e8e63a Fix using global options before an alias. 2020-01-31 13:56:06 -08:00
Matthias Krüger a6a395c690 fix some clippy warnings 2020-01-17 12:20:11 +01:00
Eric Huss 0b653a43ba Rename Kind 2020-01-11 11:04:13 -08:00
bors c95f396b4c Auto merge of #7778 - ehuss:bump-crates-io, r=alexcrichton
Bump crates-io

Needed for #7776.
2020-01-08 18:26:02 +00:00
Eric Huss b688f7da56 Bump crates-io 2020-01-08 10:05:35 -08:00
Alex Crichton d0430dd2b1 Run rustfmt 2020-01-07 20:01:34 -08:00
Alex Crichton 3a18c89a55 Migrate from the failure crate to anyhow
The `anyhow` crate interoperates with the `std::error::Error` trait
rather than a custom `Fail` trait, and this is the general trend of
error handling in Rust as well.

Note that this is mostly mechanical (sed) and intended to get the test
suite passing. As usual there's still more idiomatic cleanup that can
happen, but that's left to later commits.
2020-01-07 16:50:09 -08:00
Takayuki Nakata f37b9bd77a Update the reference link in a message
Follow up dc81356ef.
2020-01-07 09:05:49 +09:00
Matthias Krüger 8245e02924 bump git2 dependencies 2019-12-19 23:29:41 +01:00
Eric Huss 00a47302dd Fixes for some test errors on Windows. 2019-12-19 09:44:02 -08:00
Eric Huss 91015d52ce Add --config CLI option. 2019-12-19 09:44:02 -08:00
Eric Huss 381251aa1f Config refactoring. 2019-12-19 09:44:01 -08:00
Takayuki Nakata b7bc069fbb Refactoring of creating registry 2019-12-17 14:12:27 +09:00
Takayuki Nakata 3613999aca Refactoring to call new generate_* functions instead of duplicating codes 2019-12-17 12:31:01 +09:00
Takayuki Nakata 2a4d1dc40a Append registries to config 2019-12-17 09:59:45 +09:00
Takayuki Nakata a718ed61d6 Refactoring 2019-12-14 23:16:45 +09:00
Takayuki Nakata 6cbde6e2bf Fix overwriting alternate registry token
When executing `cargo login`, 2nd alternate registry token overwrites
1st alternate registry token.

Fixes #7701.
2019-12-13 22:42:49 +09:00
Eric Huss fd65cbd816 Bump cargo-platform version. 2019-12-10 11:59:06 -08:00
Benedikt Werner aa93f61f21
Warn instead of error 2019-12-07 09:10:06 +01:00
Benedikt Werner a572f0f274
Use blacklist instead of whitelist 2019-12-05 11:53:26 +01:00
Benedikt Werner bee13d604d
Fix test formatting 2019-12-04 09:33:58 +01:00
Benedikt Werner 552ecc9438
Emit error on [target.cfg(debug_assertions).dependencies] 2019-12-04 09:08:43 +01:00
Eric Huss 83571aee56 Minor testsuite organization. 2019-11-24 18:42:45 -08:00
Igor Makarov 2a49ac94d0 suppress clippy lint inefficient_to_string - according to reviewers' preference 2019-11-12 10:57:13 +02:00
Igor Makarov 1c5861c8b4 implement clippy suggestion to remove redundant clone 2019-11-12 10:56:27 +02:00
Igor Makarov 6d21f9e08c silence several clippy lints in tests 2019-11-12 10:54:59 +02:00
Igor Makarov b590183d87 suppress clippy lint needless_doctest_main 2019-11-12 10:49:04 +02:00
Igor Makarov b3fe6b7d27 implement clippy suggestion to remove redundant to_string 2019-11-12 10:21:21 +02:00
Igor Makarov 37ec84d09a implement clippy suggestion to remove needless return 2019-11-12 10:21:21 +02:00
Eric Huss 1df81ee07e Bump to 0.42.0, Update changelog 2019-11-07 11:19:48 -08:00
Eric Huss a8f645a9ca Remove some needless parentheses now reported on nightly. 2019-11-07 11:19:07 -08:00
Alex Crichton a92fd48fb4 Improve error message for cyclic dependencies
First reported in rust-lang/rust#65014 it looks like our error message
on cyclic dependencies may be confusing at times. It looks like this is
an issue because there are multiple paths through a graph for a
dependency, so using the generic `path_to_top` function isn't producing
the most useful path for this purpose.

We're already walking the graph though, so this commit adds an extra
parameter which collects the list of packages we've visited so far to
produce a hopefully always-accurate error message showing the chain of
dependencies end-to-end for what depends on what.
2019-10-07 16:50:42 -07:00
Eh2406 0750caffe8 add a test to show the new performance 2019-09-27 17:31:02 -04:00
Eric Huss 8ad031b54f Bump to 0.41.0, Update changelog 2019-09-27 09:02:13 -07:00