Skip to content

Commit d5a0f96

Browse files
committed
chore: Rename CompileContext to BuildRunner
1 parent 94af7d5 commit d5a0f96

File tree

17 files changed

+498
-407
lines changed

17 files changed

+498
-407
lines changed

src/cargo/core/compiler/artifact.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Generate artifact information from unit dependencies for configuring the compiler environment.
22
33
use crate::core::compiler::unit_graph::UnitDep;
4-
use crate::core::compiler::{CompileContext, CrateType, FileFlavor, Unit};
4+
use crate::core::compiler::{BuildRunner, CrateType, FileFlavor, Unit};
55
use crate::core::dependency::ArtifactKind;
66
use crate::core::{Dependency, Target, TargetKind};
77
use crate::CargoResult;
@@ -11,12 +11,12 @@ use std::ffi::OsString;
1111
/// Return all environment variables for the given unit-dependencies
1212
/// if artifacts are present.
1313
pub fn get_env(
14-
cx: &CompileContext<'_, '_>,
14+
build_runner: &BuildRunner<'_, '_>,
1515
dependencies: &[UnitDep],
1616
) -> CargoResult<HashMap<String, OsString>> {
1717
let mut env = HashMap::new();
1818
for unit_dep in dependencies.iter().filter(|d| d.unit.artifact.is_true()) {
19-
for artifact_path in cx
19+
for artifact_path in build_runner
2020
.outputs(&unit_dep.unit)?
2121
.iter()
2222
.filter_map(|f| (f.flavor == FileFlavor::Normal).then(|| &f.path))

src/cargo/core/compiler/build_context/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use self::target_info::{
2020
/// before it gets started.
2121
///
2222
/// It is intended that this is mostly static information. Stuff that mutates
23-
/// during the build can be found in the parent [`Context`]. (I say mostly,
23+
/// during the build can be found in the parent [`BuildRunner`]. (I say mostly,
2424
/// because this has internal caching, but nothing that should be observable
2525
/// or require &mut.)
2626
///
@@ -39,9 +39,9 @@ pub use self::target_info::{
3939
/// since it is often too lower-level.
4040
/// Instead, [`ops::create_bcx`] is usually what you are looking for.
4141
///
42-
/// After a `BuildContext` is built, the next stage of building is handled in [`Context`].
42+
/// After a `BuildContext` is built, the next stage of building is handled in [`BuildRunner`].
4343
///
44-
/// [`Context`]: crate::core::compiler::CompileContext
44+
/// [`BuildRunner`]: crate::core::compiler::BuildRunner
4545
/// [`ops::create_bcx`]: crate::ops::create_bcx
4646
pub struct BuildContext<'a, 'gctx> {
4747
/// The workspace the build is for.

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
use crate::core::compiler::apply_env_config;
1111
use crate::core::compiler::{
12-
BuildOutput, CompileContext, CompileKind, CompileMode, CompileTarget, CrateType,
12+
BuildOutput, BuildRunner, CompileKind, CompileMode, CompileTarget, CrateType,
1313
};
1414
use crate::core::{Dependency, Package, Target, TargetKind, Workspace};
1515
use crate::util::config::{GlobalContext, StringList, TargetConfig};
@@ -1033,15 +1033,23 @@ impl RustDocFingerprint {
10331033
/// the rustdoc fingerprint info in order to guarantee that we won't end up with mixed
10341034
/// versions of the `js/html/css` files that `rustdoc` autogenerates which do not have
10351035
/// any versioning.
1036-
pub fn check_rustdoc_fingerprint(cx: &CompileContext<'_, '_>) -> CargoResult<()> {
1037-
if cx.bcx.gctx.cli_unstable().skip_rustdoc_fingerprint {
1036+
pub fn check_rustdoc_fingerprint(build_runner: &BuildRunner<'_, '_>) -> CargoResult<()> {
1037+
if build_runner
1038+
.bcx
1039+
.gctx
1040+
.cli_unstable()
1041+
.skip_rustdoc_fingerprint
1042+
{
10381043
return Ok(());
10391044
}
10401045
let actual_rustdoc_target_data = RustDocFingerprint {
1041-
rustc_vv: cx.bcx.rustc().verbose_version.clone(),
1046+
rustc_vv: build_runner.bcx.rustc().verbose_version.clone(),
10421047
};
10431048

1044-
let fingerprint_path = cx.files().host_root().join(".rustdoc_fingerprint.json");
1049+
let fingerprint_path = build_runner
1050+
.files()
1051+
.host_root()
1052+
.join(".rustdoc_fingerprint.json");
10451053
let write_fingerprint = || -> CargoResult<()> {
10461054
paths::write(
10471055
&fingerprint_path,
@@ -1076,10 +1084,11 @@ impl RustDocFingerprint {
10761084
"fingerprint {:?} mismatch, clearing doc directories",
10771085
fingerprint_path
10781086
);
1079-
cx.bcx
1087+
build_runner
1088+
.bcx
10801089
.all_kinds
10811090
.iter()
1082-
.map(|kind| cx.files().layout(*kind).doc())
1091+
.map(|kind| build_runner.files().layout(*kind).doc())
10831092
.filter(|path| path.exists())
10841093
.try_for_each(|path| clean_doc(path))?;
10851094
write_fingerprint()?;

src/cargo/core/compiler/build_plan.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use std::path::{Path, PathBuf};
1111

1212
use serde::Serialize;
1313

14-
use super::context::OutputFile;
15-
use super::{CompileContext, CompileKind, CompileMode, Unit};
14+
use super::build_runner::OutputFile;
15+
use super::{BuildRunner, CompileKind, CompileMode, Unit};
1616
use crate::core::TargetKind;
1717
use crate::util::{internal, CargoResult, GlobalContext};
1818
use cargo_util::ProcessBuilder;
@@ -107,10 +107,10 @@ impl BuildPlan {
107107
}
108108
}
109109

110-
pub fn add(&mut self, cx: &CompileContext<'_, '_>, unit: &Unit) -> CargoResult<()> {
110+
pub fn add(&mut self, build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult<()> {
111111
let id = self.plan.invocations.len();
112112
self.invocation_map.insert(unit.buildkey(), id);
113-
let deps = cx
113+
let deps = build_runner
114114
.unit_deps(unit)
115115
.iter()
116116
.map(|dep| self.invocation_map[&dep.unit.buildkey()])

src/cargo/core/compiler/context/compilation_files.rs renamed to src/cargo/core/compiler/build_runner/compilation_files.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::sync::Arc;
99
use lazycell::LazyCell;
1010
use tracing::debug;
1111

12-
use super::{BuildContext, CompileContext, CompileKind, FileFlavor, Layout};
12+
use super::{BuildContext, BuildRunner, CompileKind, FileFlavor, Layout};
1313
use crate::core::compiler::{CompileMode, CompileTarget, CrateType, FileType, Unit};
1414
use crate::core::{Target, TargetKind, Workspace};
1515
use crate::util::{self, CargoResult, StableHasher};
@@ -139,25 +139,25 @@ impl OutputFile {
139139

140140
impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
141141
pub(super) fn new(
142-
compile_ctx: &CompileContext<'a, 'gctx>,
142+
build_runner: &BuildRunner<'a, 'gctx>,
143143
host: Layout,
144144
target: HashMap<CompileTarget, Layout>,
145145
) -> CompilationFiles<'a, 'gctx> {
146146
let mut metas = HashMap::new();
147-
for unit in &compile_ctx.bcx.roots {
148-
metadata_of(unit, compile_ctx, &mut metas);
147+
for unit in &build_runner.bcx.roots {
148+
metadata_of(unit, build_runner, &mut metas);
149149
}
150150
let outputs = metas
151151
.keys()
152152
.cloned()
153153
.map(|unit| (unit, LazyCell::new()))
154154
.collect();
155155
CompilationFiles {
156-
ws: compile_ctx.bcx.ws,
156+
ws: build_runner.bcx.ws,
157157
host,
158158
target,
159-
export_dir: compile_ctx.bcx.build_config.export_dir.clone(),
160-
roots: compile_ctx.bcx.roots.clone(),
159+
export_dir: build_runner.bcx.build_config.export_dir.clone(),
160+
roots: build_runner.bcx.roots.clone(),
161161
metas,
162162
outputs,
163163
}
@@ -557,14 +557,14 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
557557
/// See [`compute_metadata`] for how a single metadata hash is computed.
558558
fn metadata_of<'a>(
559559
unit: &Unit,
560-
compile_ctx: &CompileContext<'_, '_>,
560+
build_runner: &BuildRunner<'_, '_>,
561561
metas: &'a mut HashMap<Unit, MetaInfo>,
562562
) -> &'a MetaInfo {
563563
if !metas.contains_key(unit) {
564-
let meta = compute_metadata(unit, compile_ctx, metas);
564+
let meta = compute_metadata(unit, build_runner, metas);
565565
metas.insert(unit.clone(), meta);
566-
for dep in compile_ctx.unit_deps(unit) {
567-
metadata_of(&dep.unit, compile_ctx, metas);
566+
for dep in build_runner.unit_deps(unit) {
567+
metadata_of(&dep.unit, build_runner, metas);
568568
}
569569
}
570570
&metas[unit]
@@ -573,10 +573,10 @@ fn metadata_of<'a>(
573573
/// Computes the metadata hash for the given [`Unit`].
574574
fn compute_metadata(
575575
unit: &Unit,
576-
compile_ctx: &CompileContext<'_, '_>,
576+
build_runner: &BuildRunner<'_, '_>,
577577
metas: &mut HashMap<Unit, MetaInfo>,
578578
) -> MetaInfo {
579-
let bcx = &compile_ctx.bcx;
579+
let bcx = &build_runner.bcx;
580580
let mut hasher = StableHasher::new();
581581

582582
METADATA_VERSION.hash(&mut hasher);
@@ -593,10 +593,10 @@ fn compute_metadata(
593593
unit.features.hash(&mut hasher);
594594

595595
// Mix in the target-metadata of all the dependencies of this target.
596-
let mut deps_metadata = compile_ctx
596+
let mut deps_metadata = build_runner
597597
.unit_deps(unit)
598598
.iter()
599-
.map(|dep| metadata_of(&dep.unit, compile_ctx, metas).meta_hash)
599+
.map(|dep| metadata_of(&dep.unit, build_runner, metas).meta_hash)
600600
.collect::<Vec<_>>();
601601
deps_metadata.sort();
602602
deps_metadata.hash(&mut hasher);
@@ -606,7 +606,7 @@ fn compute_metadata(
606606
// settings like debuginfo and whatnot.
607607
unit.profile.hash(&mut hasher);
608608
unit.mode.hash(&mut hasher);
609-
compile_ctx.lto[unit].hash(&mut hasher);
609+
build_runner.lto[unit].hash(&mut hasher);
610610

611611
// Artifacts compiled for the host should have a different
612612
// metadata piece than those compiled for the target, so make sure
@@ -622,17 +622,21 @@ fn compute_metadata(
622622

623623
hash_rustc_version(bcx, &mut hasher);
624624

625-
if compile_ctx.bcx.ws.is_member(&unit.pkg) {
625+
if build_runner.bcx.ws.is_member(&unit.pkg) {
626626
// This is primarily here for clippy. This ensures that the clippy
627627
// artifacts are separate from the `check` ones.
628-
if let Some(path) = &compile_ctx.bcx.rustc().workspace_wrapper {
628+
if let Some(path) = &build_runner.bcx.rustc().workspace_wrapper {
629629
path.hash(&mut hasher);
630630
}
631631
}
632632

633633
// Seed the contents of `__CARGO_DEFAULT_LIB_METADATA` to the hasher if present.
634634
// This should be the release channel, to get a different hash for each channel.
635-
if let Ok(ref channel) = compile_ctx.bcx.gctx.get_env("__CARGO_DEFAULT_LIB_METADATA") {
635+
if let Ok(ref channel) = build_runner
636+
.bcx
637+
.gctx
638+
.get_env("__CARGO_DEFAULT_LIB_METADATA")
639+
{
636640
channel.hash(&mut hasher);
637641
}
638642

src/cargo/core/compiler/context/mod.rs renamed to src/cargo/core/compiler/build_runner/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! [`CompileContext`] is the mutable state used during the build process.
1+
//! [`BuildRunner`] is the mutable state used during the build process.
22
33
use std::collections::{BTreeSet, HashMap, HashSet};
44
use std::path::{Path, PathBuf};
@@ -36,7 +36,7 @@ pub use self::compilation_files::{Metadata, OutputFile};
3636
/// throughout the entire build process. Everything is coordinated through this.
3737
///
3838
/// [`BuildContext`]: crate::core::compiler::BuildContext
39-
pub struct CompileContext<'a, 'gctx> {
39+
pub struct BuildRunner<'a, 'gctx> {
4040
/// Mostly static information about the build task.
4141
pub bcx: &'a BuildContext<'a, 'gctx>,
4242
/// A large collection of information about the result of the entire compilation.
@@ -88,7 +88,7 @@ pub struct CompileContext<'a, 'gctx> {
8888
pub failed_scrape_units: Arc<Mutex<HashSet<Metadata>>>,
8989
}
9090

91-
impl<'a, 'gctx> CompileContext<'a, 'gctx> {
91+
impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
9292
pub fn new(bcx: &'a BuildContext<'a, 'gctx>) -> CargoResult<Self> {
9393
// Load up the jobserver that we'll use to manage our parallelism. This
9494
// is the same as the GNU make implementation of a jobserver, and

src/cargo/core/compiler/compilation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<'gctx> Compilation<'gctx> {
166166
///
167167
/// `is_primary` is true if this is a "primary package", which means it
168168
/// was selected by the user on the command-line (such as with a `-p`
169-
/// flag), see [`crate::core::compiler::CompileContext::primary_packages`].
169+
/// flag), see [`crate::core::compiler::BuildRunner::primary_packages`].
170170
///
171171
/// `is_workspace` is true if this is a workspace member.
172172
pub fn rustc_process(

0 commit comments

Comments
 (0)