oli-obk / ui_test

A test framework for testing rustc diagnostics output
24 stars 24 forks source link

aux build nothing #249

Closed yu532758082 closed 1 month ago

yu532758082 commented 1 month ago

I'm writing a static detection tool like Clippy

I use compile-test to build ui tests ---- Imitate Clippy

I used //@ aux-build: test.rs when testing, and it said buiding aux file ok, but rlib did not appear in the corresponding traget directory

Building aux file tests/ui//auxiliary/xxxxx.rs ... ok

But if you compile manually using rustc, it will succeed

I added pirntln in run_ui func, show:

config: Config { host: None, target: None, root_dir: "tests/ui", program: CommandBuilder { program: "userdeifne_driver", args: ["--error-format=json", "--emit=metadata", "-Aunused", "-Ainternal_features", "-Zui-testing", "-Zdeduplicate-diagnostics=no", "-Dwarnings", "-Lxxxxxxx.rib(Desensitization)"], out_dir_flag: Some("--out-dir"), input_file_flag: None, envs: [], cfg_flag: Some("--print=cfg") }, output_conflict_handling: Bless, bless_command: Some("cargo uibless"), dependencies_crate_manifest_path: None, dependency_builder: CommandBuilder { program: "xxxx/.rustup/toolchains/nightly-2024-03-07-aarch64-apple-darwin/bin/cargo", args: ["build"], out_dir_flag: Some("--target-dir"), input_file_flag: Some("--manifest-path"), envs: [], cfg_flag: None }, out_dir: "target/ui_test", skip_files: [], filter_files: ["xxxxtest_name"], threads: None, list: false, run_only_ignored: false, filter_exact: false, comment_defaults: Comments { revisions: None, revisioned: {[]: Revisioned { span: DUMMY_SPAN, ignore: [], only: [], stderr_per_bitwidth: false, compile_flags: [], env_vars: [], normalize_stderr: [(PathBackslash, [47])], normalize_stdout: [(PathBackslash, [47])], error_in_other_files: [], error_matches: [], require_annotations_for_level: OptWithLine(None), aux_builds: [], edition: OptWithLine(Some(DUMMY_SPAN: "2021")), mode: OptWithLine(Some(DUMMY_SPAN: Fail { require_patterns: false, rustfix: Everything })), needs_asm_support: false, no_rustfix: OptWithLine(None), diagnostic_code_prefix: OptWithLine(Some(DUMMY_SPAN: "xxxxlinter::")) }} } } args: Args { filters: ["wildcard_import"], check: false, bless: true, exact: false, ignored: false, list: false, format: Pretty, threads: None, skip: [] }

Is there anything I could have gone wrong with? I look forward to your reply, thanks.

oli-obk commented 1 month ago

The aux files are built in different directories them normal. Is your test unable to use the aux built lib?

Can you paste the error you're getting from the test that uses the //@aux-build flag?

yu532758082 commented 1 month ago

When I compile and use the aux-built crate via extern, ui test says that it cannot find rlib in the corresponding target directory.

Finished `test` profile [unoptimized + debuginfo] target(s) in 0.22s
 Running tests/compile-test.rs (target/debug/deps/compile_test-a22223c5f813a8fc)

Building dependencies ... ok Building aux file tests/ui/xxxx/auxiliary/wildcard_imports_helper.rs ... ok tests/ui/xxx/wildcard_import.rs ... FAILED

error: there were 1 unmatched diagnostics --> tests/ui/xxxxxx/wildcard_import.rs:6:1 6 extern crate wildcard_import_helper; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Error[E0463]: can't find crate for wildcard_import_helper
oli-obk commented 1 month ago

there should a full invocation of the wildard_import.rs driver getting dumped on the command line. Does it contain any reference to the helper library?

oh... does your library contain fn main? We have some heuristic to turn those into binaries, but we should probably avoid doing that for aux builds 😆

yu532758082 commented 1 month ago

"command line" do you means this

"wildcard_imports_helper=target/ui_test/tests/ui/xxxxx/auxiliary/libwildcard_imports_helper.rlib" "-L" "target/ui_test/tests/ui/xxxxx/auxiliary" .stderr file shows this:

` error: extern location for wildcard_imports_helper does not exist: target/ui_test/tests/ui/xxxxx/auxiliary/libwildcard_imports_helper.rlib --> tests/ui/xxxxx/wildcard_import.rs:6:1 | LL | extern crate wildcard_imports_helper; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

`

I'm not sure if this is a bug, I have a similar compile-test structure to the clippy crate, it is ok on clippy crate

My compile-test file contains a mean function. If there is a way to circumvent the existing problem, please let me know.

oli-obk commented 1 month ago

you can use //@compile-flags: --crate-types=lib (in the aux file) to force a library crate type, even if you have a fn main

yu532758082 commented 1 month ago

I added //@compile-flags: --crate-type=lib to the aux file in the axuiliary folder But there was no change, no rlib file was generated under target

Is there any more information I can provide to help you locate it?

oli-obk commented 1 month ago

Can you create repo where your issue reproduces? I don't think I can debug your issue otherwise

yu532758082 commented 1 month ago

I will start building my repo and communicate with you when it is built.

yu532758082 commented 1 month ago

Hello, I found the cause of the problem when reproducing the minimum scenario

The reason is that when implementing rustc_driver::Callbacks, fn after_analysis<'tcx> is overloaded to return rustc_driver::Compilation::Stop causing the rlib generated by aux-build to not be generated as expected

Thank you for your answer