Commit graph

161 commits

Author SHA1 Message Date
hi-rustin 7cbc858b71 Add some tests 2023-08-28 09:29:17 +08:00
hi-rustin 4bdeb53cb5 Bail out an error when using cargo:: in custom build script
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-07-27 23:00:52 +08:00
Arpad Borsos 18e290c0e4
Enable doctest-in-workspace by default
This stabilizes and enables the `-Z doctest-in-workspace` flag by default.

Also adds another testcase to make sure that the `include!()` and `file!()` macros interact well together.
2023-06-17 19:34:34 +02:00
Weihang Lo 64a1f204f3
refactor: only when -C debuginfo > 0 will spilt-debuginfo be passed
It was unnecessary to pass `spilt-debuginfo` if there is no debuginfo.
Tests are touched here only for matching rustflags invocation stderr
in the original test suite.
2023-05-31 20:43:57 +01:00
Eric Huss 16ac6fae11 Re-enable code_generation test on Windows 2023-05-29 12:01:02 -07:00
Adrián Ortiz db457d950f Fixing issue https://github.com/rust-lang/cargo/issues/10834:
- Adding display of which target failed to compile
- Consistent messages for warnings/errors.
- Fixing assertions on related tests.
2023-03-07 06:45:26 +01:00
Scott Schafer 9708e6f62d refactor: Make two tests stderr not match their test name 2023-02-20 11:09:05 -06:00
Rémy Rakic 7ccda69f70 do not display message to enable debuginfo when it's already enabled 2023-01-31 22:36:20 +00:00
Rémy Rakic 9d9b7fef2d improve debuginfo error message when build script fails 2023-01-31 22:36:20 +00:00
Rémy Rakic 3be6c93a22 update optional_build_dep_and_required_normal_dep test expectations
This test dynamically enables a shared build/runtime dependency, and
therefore doesn't trigger the build/runtime sharing reuse optimization,
as the build dep is initially built without debuginfo for optimization
purposes.
2023-01-31 22:36:20 +00:00
Rémy Rakic 7dfabdc681 add build script failure test when requesting backtraces
it displays an additional message on how to improve these backtraces, now that
debuginfo is turned off most of the time in `dev.build-override`.
2023-01-31 20:12:52 +00:00
Rémy Rakic 6848006cbe update tests for build deps debuginfo optimization 2023-01-31 20:12:52 +00:00
arriven 9e01c8bbcf skip mtime checks for paths in $CARGO_HOME 2023-01-24 08:27:33 +00:00
Dinu Blanovschi 0beb5fe93d Simple explanations for why cargo rebuilds crates 2022-12-28 16:27:50 +01: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
Arlo Siemsen d51ed05324 Fix deadlock when build scripts are waiting for input on stdin 2022-10-12 11:46:51 -05:00
Scott Schafer ab18bd40d5 refactor(testsuite): Replace [project] with [package] 2022-09-26 09:51:16 -06:00
Eric Huss 7eb007ddbf Add reasons to all ignored tests. 2022-08-02 12:24:00 -07:00
Scott Schafer c239e407e7 add a reason to masquerade_as_nightly_cargo so it is searchable 2022-07-15 21:32:23 -05:00
bors 39ad1039d9 Auto merge of #10600 - tmfink:doc-build-script-link-order, r=ehuss
doc: discuss build script instruction order

### What does this PR try to resolve?

It is currently not documented that the order of build script `cargo:` instructions may be relevant to linking.

This has caused issues such as: https://github.com/rust-lang/rust/issues/96328

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

Build/view documentation.

### Additional information

- Cargo maintainers should fact check my wording.
- We may need to discuss if this should also be documented for `rustc`
- Maintainers should ensure that this change does not prevent a change in what is currently unspecified behavior. Perhaps `cargo` will want to rearrange link arguments itself to resolve issues in the future?
2022-05-25 00:50:02 +00:00
Travis Finkenauer 43ce1e7a98 Test that link argument order is maintained
Patch provided by @ehuss
2022-05-24 12:45:20 -07:00
bors 9fa2bba679 Auto merge of #10281 - Gnurfos:depinfo_relative, r=ehuss
Fix use of .. in dep-info-basedir

### Summary

This allows setting, in .cargo/config's dep-info-basedir, some relative path that goes above the crate's directory.

### Motivation

In a setup like this:

```
repo_root
├── Makefile
├── some_c_things
│   └── foo.c
└── rust_things
    ├── Cargo.toml
    └─── src
        └── lib.rs
```

If you want the generated .d files to be includable directly in the Makefile (without post-processing), you need them to mention paths relative to the root, like:

rust_things/target/....: rust_things/src/lib.rs

### Implementation

For this you need to have relative paths with parent directories (in this case ..) in dep-info-basedir, which does not work without the change in this PR (due to render_filename doing only strip_prefix, while the basedir still contains literal ..s).

Let me know if this change is acceptable. Another implementation could be to canonicalize in ConfigRelativePath::resolve_path instead, especially since that struct outputs absolute paths. But that would have it access the filesystem, while it currently doesn't.
2022-05-07 19:49:54 +00:00
Jon Gjengset f23894d93f Make rustflags logic more linear 2022-02-23 16:36:14 -08:00
Jon Gjengset 745329c3b1 Remove env_var from test names that don't use env 2022-02-23 16:35:41 -08:00
Jon Gjengset 4f41727106 Enable propagating rustflags to build scripts
This patch implements more complete logic for applying rustflags to
build scripts and other host artifacts. In the default configuration, it
only makes build scripts (and plugins and whatnot) pick up on
`rustflags` from `[host]`, which fixes #10206 but otherwise preserves
existing behavior in all its inconsistent glory. The same is the case if
`target-applies-to-host` is explicitly set to `false`.

When `target-applies-to-host` is explicitly set to `true`, rustflags
will start to be applied in the same way that `linker` and `runner` are
today -- namely they'll be applied from `[target.<host triple>]` and
from `RUSTFLAGS`/`build.rustflags` if `--target <host triple>` is given.
2022-02-18 10:50:08 -08:00
Jon Gjengset 040f0d10a6 Simplify unused build scripts in tests
The tests in question all tail to even build the build script, so the
contents of `main` don't matter, and make the tests seem more complex
than they really are.
2022-02-17 10:33:23 -08:00
Jon Gjengset 90a61d183f Run target-applies-to-host tests on stable 2022-02-17 10:31:10 -08:00
Seb E e5ff81b0e7 Fix use of .. in dep-info-basedir config 2022-01-12 10:37:32 +01:00
Weihang Lo d92dceaeba
Test IO error resilience while walking directories
Remove `build_script::build_script_scan_eacces`  test case because cargo
ignores it and returns its path during a `cargo build`. The caller still
has a chance to hit the IO error if they does access it.
2022-01-05 14:29:59 +08:00
Weihang Lo 6fa0f01d87
Test filesystem loop during traversal
Use unordered since order of warning differs on each platform.
2021-12-15 09:42:14 +08:00
Weihang Lo 760ff62f36
Improve I/O error message for fingerprint of build script
It is a bit rough but I don't think there is a network I/O error
in `pkg_fingerprint`. Checking only `io::Error` type should be fine.
2021-12-11 08:31:24 +08:00
Weihang Lo d22623466d
Show original version_req for locked dependency
When encounter resolver error with locked dependency, we now show
original version req along with the exact locked version.
2021-09-20 11:31:59 +08:00
Eric Huss c4e92ac69a Improve "wrong output" error. 2021-09-11 16:34:09 -07:00
Weihang Lo a5f8bc94f5
Improve resolver message for validate_links 2021-08-24 00:39:38 +08:00
Weihang Lo 0afd40b4de
Update tests to display dep-req info for dep-chain 2021-08-24 00:39:38 +08:00
bors adde602238 Auto merge of #9601 - jonhoo:fix-9600, r=ehuss
Inform build scripts of rustc compiler context

Fixes #9600.
2021-07-20 21:27:35 +00:00
Jon Gjengset 1cbce47051 Remove RUSTC_VERSION envvar 2021-07-15 17:53:21 -07:00
Jon Gjengset d0c751bc8f Test when RUSTC_WORKSPACE_WRAPPER is not set 2021-07-12 09:34:39 -07:00
Joshua Nelson 9c7cc545d7 Combine rustc and cargo's diagnostic summaries
This works by introspecting rustc's error output, using the JSON format
to determine whether it's a warning or error, then skipping it
altogether if it's a summary of the diagnostics printed.

Before:

```
src/main.rs:1:10: warning: trait objects without an explicit `dyn` are deprecated
src/main.rs:1:1: error[E0601]: `main` function not found in crate `wrong`
src/main.rs:1:9: error[E0038]: the trait `Clone` cannot be made into an object
error: aborting due to 2 previous errors; 1 warning emitted
error: could not compile `wrong`

```

After:

```
$ cargo check --message-format short
src/main.rs:1:10: warning: trait objects without an explicit `dyn` are deprecated
src/main.rs:1:1: error[E0601]: `main` function not found in crate `wrong`
src/main.rs:1:9: error[E0038]: the trait `Clone` cannot be made into an object
error: could not compile `wrong` due to 2 previous errors; 1 warning emitted
```
2021-07-06 19:46:27 -04:00
Jon Gjengset d6b4a06274 Also set RUSTC_WORKSPACE_WRAPPER for build.rs 2021-07-06 09:46:02 -07:00
Jon Gjengset fa7c5b196f Use a more standard linker flag 2021-06-29 12:26:50 -07:00
Jon Gjengset fb0d41fcc5 Adopt CARGO_ENCODED_RUSTFLAGS 2021-06-29 12:08:50 -07:00
Jon Gjengset c16b9d4c55 Remove CARGO_VERSION* env vars
Cargo and Rustc are co-versioned at the moment anyway.
2021-06-25 11:01:23 -07:00
Jon Gjengset 49d33c4ec4 Expose cargo and rustc version envvars 2021-06-24 09:56:14 -07:00
Jon Gjengset 1e407453c2 Remove CARGO_ prefix for new build script envvars 2021-06-24 09:56:00 -07:00
Jon Gjengset 8012d328ee Avoid coercing path to string for windows 2021-06-18 12:40:29 -07:00
Jon Gjengset 719eb593c8 Add tests for rustc context build script env vars 2021-06-18 12:15:03 -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 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
hi-rustin 724cf0f0eb More information for links conflicting 2021-06-10 15:12:19 +08:00