mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
rename rustc_cfg::Config
to rustc_cfg::RustcCfgConfig
and import
This commit is contained in:
parent
553152e2d5
commit
fad3823a20
2 changed files with 14 additions and 14 deletions
|
@ -7,7 +7,7 @@ use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use crate::{cfg_flag::CfgFlag, utf8_stdout, ManifestPath, Sysroot};
|
use crate::{cfg_flag::CfgFlag, utf8_stdout, ManifestPath, Sysroot};
|
||||||
|
|
||||||
pub(crate) enum Config<'a> {
|
pub(crate) enum RustcCfgConfig<'a> {
|
||||||
Cargo(&'a ManifestPath),
|
Cargo(&'a ManifestPath),
|
||||||
Explicit(&'a Sysroot),
|
Explicit(&'a Sysroot),
|
||||||
Discover,
|
Discover,
|
||||||
|
@ -16,7 +16,7 @@ pub(crate) enum Config<'a> {
|
||||||
pub(crate) fn get(
|
pub(crate) fn get(
|
||||||
target: Option<&str>,
|
target: Option<&str>,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, String>,
|
||||||
config: Config<'_>,
|
config: RustcCfgConfig<'_>,
|
||||||
) -> Vec<CfgFlag> {
|
) -> Vec<CfgFlag> {
|
||||||
let _p = profile::span("rustc_cfg::get");
|
let _p = profile::span("rustc_cfg::get");
|
||||||
let mut res = Vec::with_capacity(6 * 2 + 1);
|
let mut res = Vec::with_capacity(6 * 2 + 1);
|
||||||
|
@ -61,10 +61,10 @@ pub(crate) fn get(
|
||||||
fn get_rust_cfgs(
|
fn get_rust_cfgs(
|
||||||
target: Option<&str>,
|
target: Option<&str>,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, String>,
|
||||||
config: Config<'_>,
|
config: RustcCfgConfig<'_>,
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
let mut cmd = match config {
|
let mut cmd = match config {
|
||||||
Config::Cargo(cargo_toml) => {
|
RustcCfgConfig::Cargo(cargo_toml) => {
|
||||||
let mut cmd = Command::new(toolchain::cargo());
|
let mut cmd = Command::new(toolchain::cargo());
|
||||||
cmd.envs(extra_env);
|
cmd.envs(extra_env);
|
||||||
cmd.current_dir(cargo_toml.parent())
|
cmd.current_dir(cargo_toml.parent())
|
||||||
|
@ -76,12 +76,12 @@ fn get_rust_cfgs(
|
||||||
|
|
||||||
return utf8_stdout(cmd).context("Unable to run `cargo rustc`");
|
return utf8_stdout(cmd).context("Unable to run `cargo rustc`");
|
||||||
}
|
}
|
||||||
Config::Explicit(sysroot) => {
|
RustcCfgConfig::Explicit(sysroot) => {
|
||||||
let rustc: std::path::PathBuf = sysroot.discover_rustc()?.into();
|
let rustc: std::path::PathBuf = sysroot.discover_rustc()?.into();
|
||||||
tracing::debug!(?rustc, "using explicit rustc from sysroot");
|
tracing::debug!(?rustc, "using explicit rustc from sysroot");
|
||||||
Command::new(rustc)
|
Command::new(rustc)
|
||||||
}
|
}
|
||||||
Config::Discover => {
|
RustcCfgConfig::Discover => {
|
||||||
let rustc = toolchain::rustc();
|
let rustc = toolchain::rustc();
|
||||||
tracing::debug!(?rustc, "using rustc from env");
|
tracing::debug!(?rustc, "using rustc from env");
|
||||||
Command::new(rustc)
|
Command::new(rustc)
|
||||||
|
|
|
@ -21,7 +21,7 @@ use crate::{
|
||||||
cargo_workspace::{DepKind, PackageData, RustLibSource},
|
cargo_workspace::{DepKind, PackageData, RustLibSource},
|
||||||
cfg_flag::CfgFlag,
|
cfg_flag::CfgFlag,
|
||||||
project_json::Crate,
|
project_json::Crate,
|
||||||
rustc_cfg,
|
rustc_cfg::{self, RustcCfgConfig},
|
||||||
sysroot::SysrootCrate,
|
sysroot::SysrootCrate,
|
||||||
target_data_layout, utf8_stdout, CargoConfig, CargoWorkspace, InvocationStrategy, ManifestPath,
|
target_data_layout, utf8_stdout, CargoConfig, CargoWorkspace, InvocationStrategy, ManifestPath,
|
||||||
Package, ProjectJson, ProjectManifest, Sysroot, TargetData, TargetKind, WorkspaceBuildScripts,
|
Package, ProjectJson, ProjectManifest, Sysroot, TargetData, TargetKind, WorkspaceBuildScripts,
|
||||||
|
@ -282,7 +282,7 @@ impl ProjectWorkspace {
|
||||||
let rustc_cfg = rustc_cfg::get(
|
let rustc_cfg = rustc_cfg::get(
|
||||||
config.target.as_deref(),
|
config.target.as_deref(),
|
||||||
&config.extra_env,
|
&config.extra_env,
|
||||||
rustc_cfg::Config::Cargo(cargo_toml),
|
RustcCfgConfig::Cargo(cargo_toml),
|
||||||
);
|
);
|
||||||
|
|
||||||
let cfg_overrides = config.cfg_overrides.clone();
|
let cfg_overrides = config.cfg_overrides.clone();
|
||||||
|
@ -337,11 +337,11 @@ impl ProjectWorkspace {
|
||||||
let config = match &sysroot {
|
let config = match &sysroot {
|
||||||
Ok(sysroot) => {
|
Ok(sysroot) => {
|
||||||
tracing::debug!(src_root = %sysroot.src_root(), root = %sysroot.root(), "Using sysroot");
|
tracing::debug!(src_root = %sysroot.src_root(), root = %sysroot.root(), "Using sysroot");
|
||||||
rustc_cfg::Config::Explicit(sysroot)
|
RustcCfgConfig::Explicit(sysroot)
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
tracing::debug!("discovering sysroot");
|
tracing::debug!("discovering sysroot");
|
||||||
rustc_cfg::Config::Discover
|
RustcCfgConfig::Discover
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -370,11 +370,11 @@ impl ProjectWorkspace {
|
||||||
let rustc_config = match &sysroot {
|
let rustc_config = match &sysroot {
|
||||||
Ok(sysroot) => {
|
Ok(sysroot) => {
|
||||||
tracing::info!(src_root = %sysroot.src_root(), root = %sysroot.root(), "Using sysroot");
|
tracing::info!(src_root = %sysroot.src_root(), root = %sysroot.root(), "Using sysroot");
|
||||||
rustc_cfg::Config::Explicit(sysroot)
|
RustcCfgConfig::Explicit(sysroot)
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
tracing::info!("discovering sysroot");
|
tracing::info!("discovering sysroot");
|
||||||
rustc_cfg::Config::Discover
|
RustcCfgConfig::Discover
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -774,8 +774,8 @@ fn project_json_to_crate_graph(
|
||||||
let target_cfgs = match target.as_deref() {
|
let target_cfgs = match target.as_deref() {
|
||||||
Some(target) => cfg_cache.entry(target).or_insert_with(|| {
|
Some(target) => cfg_cache.entry(target).or_insert_with(|| {
|
||||||
let rustc_cfg = match sysroot {
|
let rustc_cfg = match sysroot {
|
||||||
Some(sysroot) => rustc_cfg::Config::Explicit(sysroot),
|
Some(sysroot) => RustcCfgConfig::Explicit(sysroot),
|
||||||
None => rustc_cfg::Config::Discover,
|
None => RustcCfgConfig::Discover,
|
||||||
};
|
};
|
||||||
|
|
||||||
rustc_cfg::get(Some(target), extra_env, rustc_cfg)
|
rustc_cfg::get(Some(target), extra_env, rustc_cfg)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue