rust-marker / marker

An experimental linting interface for Rust. Let's make custom lints a reality
https://rust-marker.github.io/marker/
Other
144 stars 11 forks source link

[Bug]: `marker_uitest` doesn't work in a workspace with rust-toolchain.toml file that uses `1.71` #298

Open Veetaha opened 1 year ago

Veetaha commented 1 year ago

Summary

I've been integrating marker into my work project. It's been quite seamless so far, but when I started testing my lints I found that a simple cargo test -p lint-crate doesn't work. The workspace I have the lint crate defined in uses 1.71 stable rust toolchain in rust-toolchain file.

Here is the error that I'm getting

Details ``` cargo test -p elastio-lints Compiling elastio-lints v0.28.43-dev (/home/veetaha/work/elastio/common/elastio-lints) Finished test [unoptimized] target(s) in 0.81s Running unittests src/lib.rs (target/debug/deps/elastio_lints-ca81c15328620075) running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s Running tests/uitest.rs (target/debug/deps/uitest-3b6f89e9813dc3ab) /home/veetaha/.rustup/toolchains/nightly-2023-08-24-x86_64-unknown-linux-gnu/bin/marker_rustc_driver: error while loading shared libraries: librustc_driver-00c03654e9ecf095.so: cannot open shared object file: No such file or directory thread 'main' panicked at ' =========================================================== Error: Unable to start Marker's driver UI tests need to be executed with the nightly version of the driver * Try setting the version in a `rust-toolchain.toml` file, like this: ``` [toolchain] channel = "nightly-2023-08-24" ``` * Try setting the channel when invoking the tests, like this: ``` cargo +nightly-2023-08-24 test" ``` =========================================================== ', /home/veetaha/.cargo/registry/src/index.crates.io-6f17d22bba15001f/marker_uitest-0.3.0/src/lib.rs:257:9 stack backtrace: 0: 0x55a7b8d32a81 - std::backtrace_rs::backtrace::libunwind::trace::h6aeaf83abc038fe6 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x55a7b8d32a81 - std::backtrace_rs::backtrace::trace_unsynchronized::h4f9875212db0ad97 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x55a7b8d32a81 - std::sys_common::backtrace::_print_fmt::h3f820027e9c39d3b at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:65:5 3: 0x55a7b8d32a81 - ::fmt::hded4932df41373b3 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:44:22 4: 0x55a7b8d5c72f - core::fmt::rt::Argument::fmt::hc8ead7746b2406d6 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/fmt/rt.rs:138:9 5: 0x55a7b8d5c72f - core::fmt::write::hb1cb56105a082ad9 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/fmt/mod.rs:1094:21 6: 0x55a7b8d2eff1 - std::io::Write::write_fmt::h797fda7085c97e57 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/io/mod.rs:1713:15 7: 0x55a7b8d32895 - std::sys_common::backtrace::_print::h492d3c92d7400346 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:47:5 8: 0x55a7b8d32895 - std::sys_common::backtrace::print::hf74aa2eef05af215 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:34:9 9: 0x55a7b8d347b7 - std::panicking::default_hook::{{closure}}::h8cad394227ea3de8 10: 0x55a7b8d345a4 - std::panicking::default_hook::h249cc184fec99a8a at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:288:9 11: 0x55a7b8d34cdc - std::panicking::rust_panic_with_hook::h82ebcd5d5ed2fad4 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:705:13 12: 0x55a7b8d34bd7 - std::panicking::begin_panic_handler::{{closure}}::h810bed8ecbe66f1a at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:597:13 13: 0x55a7b8d32eb6 - std::sys_common::backtrace::__rust_end_short_backtrace::h1410008071796261 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:151:18 14: 0x55a7b8d34922 - rust_begin_unwind at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:593:5 15: 0x55a7b8d5a103 - core::panicking::panic_fmt::ha0a42a25e0cf258d at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:67:14 16: 0x55a7b89942f5 - core::panicking::panic_display::h59aedf1a58ab8206 17: 0x55a7b899005d - marker_uitest::verify_driver::h59bc9ad5a43a5df5 18: 0x55a7b898e196 - marker_uitest::create_ui_test_config::ha499303f3a921a17 19: 0x55a7b8984be4 - uitest::main::hb45b62ded66aaa8d 20: 0x55a7b8987b23 - core::ops::function::FnOnce::call_once::h867139df5e8dcac0 21: 0x55a7b8984f66 - std::sys_common::backtrace::__rust_begin_short_backtrace::h7aa1576e7aea9372 22: 0x55a7b8987989 - std::rt::lang_start::{{closure}}::h83d40923d1ff81b9 23: 0x55a7b8d28185 - core::ops::function::impls:: for &F>::call_once::h5ce27e764c284c0a at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/ops/function.rs:284:13 24: 0x55a7b8d28185 - std::panicking::try::do_call::h4c1fc390ae241991 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:500:40 25: 0x55a7b8d28185 - std::panicking::try::h4d36e7eaed86af72 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:464:19 26: 0x55a7b8d28185 - std::panic::catch_unwind::h41cfb4dd65282b1e at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panic.rs:142:14 27: 0x55a7b8d28185 - std::rt::lang_start_internal::{{closure}}::hfed411c1c5fdb925 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/rt.rs:148:48 28: 0x55a7b8d28185 - std::panicking::try::do_call::h6893f6f32a464342 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:500:40 29: 0x55a7b8d28185 - std::panicking::try::h52b7102f469a0567 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:464:19 30: 0x55a7b8d28185 - std::panic::catch_unwind::h62120054677916b5 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panic.rs:142:14 31: 0x55a7b8d28185 - std::rt::lang_start_internal::hd66bf6b7da144005 at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/rt.rs:148:20 32: 0x55a7b8987967 - std::rt::lang_start::hb44b6dea8d65c1f8 33: 0x55a7b8984f45 - main 34: 0x7f84418c1d90 - __libc_start_call_main at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16 35: 0x7f84418c1e40 - __libc_start_main_impl at ./csu/../csu/libc-start.c:392:3 36: 0x55a7b89807e5 - _start 37: 0x0 - error: test failed, to rerun pass `-p elastio-lints --test uitest` ```

Cause

The problem occurs because the test process is invoked with both the RUSTUP_TOOLCHAIN and LD_LIBRARY_PATH that point to the 1.71.0 toolchain in this case. The marker_uitest needs to make sure to ignore these variables by invoking the driver via rustup run {marker-nightly-toolchain} marker_rustc_driver command.

Workaround

I've come up with a workaround for this issue, but I'd like this to be fixed in marker_uitest.

use marker_uitest::ui_test;
use std::env;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // FIXME: The toolchain juggling is the workaround for https://github.com/rust-marker/marker/issues/298
    let toolchain = "nightly-2023-08-24";
    std::env::set_var("RUSTUP_TOOLCHAIN", toolchain);

    let output = std::process::Command::new("rustup")
        .args(&["run", toolchain, "rustc", "--print", "sysroot"])
        .output()?;

    let sysroot = String::from_utf8(output.stdout).unwrap();
    let sysroot = sysroot.trim();

    if !output.status.success() {
        let stderr = String::from_utf8(output.stderr).unwrap();
        panic!(
            "Failed to get sysroot for marker rustc driver.\n\
            -- stdout --\n\
            {sysroot}\n\
            -- stderr --\n\
            {stderr}",
        );
    }

    env::set_var(
        "LD_LIBRARY_PATH",
        format!(
            "{sysroot}/lib:{}",
            env::var("LD_LIBRARY_PATH").unwrap_or_default()
        ),
    );

    let config = marker_uitest::simple_ui_test_config!()?;

    ui_test::run_tests_generic(
        vec![config],
        ui_test::default_file_filter,
        ui_test::default_per_file_config,
        ui_test::status_emitter::Text::quiet(),
    )?;

    Ok(())
}

Reproducer

Create a file rust-toolchain with 1.71.0 inside of it.

Initialize an dummy lint crate inside of the workspace.

Use the following code for the sample lint crate in tests/uitest.rs file:

use marker_uitest::ui_test;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = marker_uitest::simple_ui_test_config!()?;

    ui_test::run_tests_generic(
        vec![config],
        ui_test::default_file_filter,
        ui_test::default_per_file_config,
        ui_test::status_emitter::Text::quiet(),
    )?;

    Ok(())
}

Run cargo test

Version

cargo-marker 0.3.0
xFrednet commented 1 year ago

Yep, this is sadly a limitation rn. We might want to ask ui_test if they want to support setting the toolchain, before we hack around it in Marker's wrapper.