|
| 1 | +//! This module isolates the compiletest APIs used by the rustdoc-gui-test tool. |
| 2 | +//! |
| 3 | +//! Thanks to this isolation layer, changes to compiletest directive parsing |
| 4 | +//! might require changes to the items in this module, but shouldn't require |
| 5 | +//! changes to rustdoc-gui-test itself. |
| 6 | +//! |
| 7 | +//! The current relationship between compiletest and rustdoc-gui-test is |
| 8 | +//! awkward. Ideally, rustdoc-gui-test should either split off its own |
| 9 | +//! directive parser and become fully independent, or be incorporated into |
| 10 | +//! compiletest as another test mode. |
| 11 | +//! |
| 12 | +//! See <https://github.com/rust-lang/rust/issues/143827> for more context. |
| 13 | +
|
| 14 | +use std::path::Path; |
| 15 | + |
| 16 | +use camino::{Utf8Path, Utf8PathBuf}; |
| 17 | + |
| 18 | +use crate::common::{CodegenBackend, Config, TestMode, TestSuite}; |
| 19 | +use crate::directives::TestProps; |
| 20 | + |
| 21 | +/// Subset of compiletest directive values that are actually used by |
| 22 | +/// rustdoc-gui-test. |
| 23 | +#[derive(Debug)] |
| 24 | +pub struct RustdocGuiTestProps { |
| 25 | + pub compile_flags: Vec<String>, |
| 26 | + pub run_flags: Vec<String>, |
| 27 | +} |
| 28 | + |
| 29 | +impl RustdocGuiTestProps { |
| 30 | + pub fn from_file(test_file_path: &Path) -> Self { |
| 31 | + let test_file_path = Utf8Path::from_path(test_file_path).unwrap(); |
| 32 | + let config = incomplete_config_for_rustdoc_gui_test(); |
| 33 | + |
| 34 | + let props = TestProps::from_file(test_file_path, None, &config); |
| 35 | + |
| 36 | + let TestProps { compile_flags, run_flags, .. } = props; |
| 37 | + Self { compile_flags, run_flags } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +/// Incomplete config intended for `src/tools/rustdoc-gui-test` **only** as |
| 42 | +/// `src/tools/rustdoc-gui-test` wants to reuse `compiletest`'s directive -> test property |
| 43 | +/// handling for `//@ {compile,run}-flags`, do not use for any other purpose. |
| 44 | +/// |
| 45 | +/// FIXME(#143827): this setup feels very hacky. It so happens that `tests/rustdoc-gui/` |
| 46 | +/// **only** uses `//@ {compile,run}-flags` for now and not any directives that actually rely on |
| 47 | +/// info that is assumed available in a fully populated [`Config`]. |
| 48 | +fn incomplete_config_for_rustdoc_gui_test() -> Config { |
| 49 | + // FIXME(#143827): spelling this out intentionally, because this is questionable. |
| 50 | + // |
| 51 | + // For instance, `//@ ignore-stage1` will not work at all. |
| 52 | + Config { |
| 53 | + mode: TestMode::Rustdoc, |
| 54 | + // E.g. this has no sensible default tbh. |
| 55 | + suite: TestSuite::Ui, |
| 56 | + |
| 57 | + // Dummy values. |
| 58 | + edition: Default::default(), |
| 59 | + bless: Default::default(), |
| 60 | + fail_fast: Default::default(), |
| 61 | + compile_lib_path: Utf8PathBuf::default(), |
| 62 | + run_lib_path: Utf8PathBuf::default(), |
| 63 | + rustc_path: Utf8PathBuf::default(), |
| 64 | + cargo_path: Default::default(), |
| 65 | + stage0_rustc_path: Default::default(), |
| 66 | + query_rustc_path: Default::default(), |
| 67 | + rustdoc_path: Default::default(), |
| 68 | + coverage_dump_path: Default::default(), |
| 69 | + python: Default::default(), |
| 70 | + jsondocck_path: Default::default(), |
| 71 | + jsondoclint_path: Default::default(), |
| 72 | + llvm_filecheck: Default::default(), |
| 73 | + llvm_bin_dir: Default::default(), |
| 74 | + run_clang_based_tests_with: Default::default(), |
| 75 | + src_root: Utf8PathBuf::default(), |
| 76 | + src_test_suite_root: Utf8PathBuf::default(), |
| 77 | + build_root: Utf8PathBuf::default(), |
| 78 | + build_test_suite_root: Utf8PathBuf::default(), |
| 79 | + sysroot_base: Utf8PathBuf::default(), |
| 80 | + stage: Default::default(), |
| 81 | + stage_id: String::default(), |
| 82 | + debugger: Default::default(), |
| 83 | + run_ignored: Default::default(), |
| 84 | + with_rustc_debug_assertions: Default::default(), |
| 85 | + with_std_debug_assertions: Default::default(), |
| 86 | + filters: Default::default(), |
| 87 | + skip: Default::default(), |
| 88 | + filter_exact: Default::default(), |
| 89 | + force_pass_mode: Default::default(), |
| 90 | + run: Default::default(), |
| 91 | + runner: Default::default(), |
| 92 | + host_rustcflags: Default::default(), |
| 93 | + target_rustcflags: Default::default(), |
| 94 | + rust_randomized_layout: Default::default(), |
| 95 | + optimize_tests: Default::default(), |
| 96 | + target: Default::default(), |
| 97 | + host: Default::default(), |
| 98 | + cdb: Default::default(), |
| 99 | + cdb_version: Default::default(), |
| 100 | + gdb: Default::default(), |
| 101 | + gdb_version: Default::default(), |
| 102 | + lldb_version: Default::default(), |
| 103 | + llvm_version: Default::default(), |
| 104 | + system_llvm: Default::default(), |
| 105 | + android_cross_path: Default::default(), |
| 106 | + adb_path: Default::default(), |
| 107 | + adb_test_dir: Default::default(), |
| 108 | + adb_device_status: Default::default(), |
| 109 | + lldb_python_dir: Default::default(), |
| 110 | + verbose: Default::default(), |
| 111 | + color: Default::default(), |
| 112 | + remote_test_client: Default::default(), |
| 113 | + compare_mode: Default::default(), |
| 114 | + rustfix_coverage: Default::default(), |
| 115 | + has_html_tidy: Default::default(), |
| 116 | + has_enzyme: Default::default(), |
| 117 | + channel: Default::default(), |
| 118 | + git_hash: Default::default(), |
| 119 | + cc: Default::default(), |
| 120 | + cxx: Default::default(), |
| 121 | + cflags: Default::default(), |
| 122 | + cxxflags: Default::default(), |
| 123 | + ar: Default::default(), |
| 124 | + target_linker: Default::default(), |
| 125 | + host_linker: Default::default(), |
| 126 | + llvm_components: Default::default(), |
| 127 | + nodejs: Default::default(), |
| 128 | + npm: Default::default(), |
| 129 | + force_rerun: Default::default(), |
| 130 | + only_modified: Default::default(), |
| 131 | + target_cfgs: Default::default(), |
| 132 | + builtin_cfg_names: Default::default(), |
| 133 | + supported_crate_types: Default::default(), |
| 134 | + nocapture: Default::default(), |
| 135 | + nightly_branch: Default::default(), |
| 136 | + git_merge_commit_email: Default::default(), |
| 137 | + profiler_runtime: Default::default(), |
| 138 | + diff_command: Default::default(), |
| 139 | + minicore_path: Default::default(), |
| 140 | + default_codegen_backend: CodegenBackend::Llvm, |
| 141 | + override_codegen_backend: None, |
| 142 | + } |
| 143 | +} |
0 commit comments