Commit Graph

291 Commits

Author SHA1 Message Date
Pietro Albini ded21affaf
fix formatting 2022-09-14 16:13:31 +02:00
Weihang Lo 2bbc8a043e
CVE-2022-36113: add tests 2022-09-14 10:54:33 +02: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