Skip to content

Commit 78c788f

Browse files
committed
Some random comments and docstrings.
1 parent b505e8a commit 78c788f

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

src/cargo/core/compiler/context/compilation_files.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ impl fmt::Display for Metadata {
5050
}
5151
}
5252

53+
/// Collection of information about the files emitted by the compiler, and the
54+
/// output directory structure.
5355
pub struct CompilationFiles<'a, 'cfg> {
5456
/// The target directory layout for the host (and target if it is the same as host).
5557
pub(super) host: Layout,
@@ -66,6 +68,7 @@ pub struct CompilationFiles<'a, 'cfg> {
6668
outputs: HashMap<Unit<'a>, LazyCell<Arc<Vec<OutputFile>>>>,
6769
}
6870

71+
/// Info about a single file emitted by the compiler.
6972
#[derive(Debug)]
7073
pub struct OutputFile {
7174
/// Absolute path to the file that will be produced by the build process.
@@ -227,6 +230,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
227230
}
228231
}
229232

233+
/// Returns the filenames that the given unit will generate.
230234
pub(super) fn outputs(
231235
&self,
232236
unit: &Unit<'a>,

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
163163
plan.output_plan();
164164
}
165165

166+
// Collect the result of the build into `self.compilation`.
166167
for unit in units.iter() {
168+
// Collect tests and executables.
167169
for output in self.outputs(unit)?.iter() {
168170
if output.flavor == FileFlavor::DebugInfo || output.flavor == FileFlavor::Auxiliary
169171
{
@@ -183,6 +185,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
183185
}
184186
}
185187

188+
// If the unit has a build script, add `OUT_DIR` to the
189+
// environment variables.
186190
for dep in self.dep_targets(unit).iter() {
187191
if !unit.target.is_lib() {
188192
continue;
@@ -198,6 +202,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
198202
}
199203
}
200204

205+
// Collect information for `rustdoc --test`.
201206
if unit.mode.is_doc_test() {
202207
// Note that we can *only* doc-test rlib outputs here. A
203208
// staticlib output cannot be linked by the compiler (it just
@@ -231,6 +236,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
231236
});
232237
}
233238

239+
// Collect the enabled features.
234240
let feats = &unit.features;
235241
if !feats.is_empty() {
236242
self.compilation
@@ -243,6 +249,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
243249
.collect()
244250
});
245251
}
252+
253+
// Collect rustdocflags.
246254
let rustdocflags = self.bcx.rustdocflags_args(unit);
247255
if !rustdocflags.is_empty() {
248256
self.compilation

src/cargo/core/compiler/fingerprint.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ pub fn prepare_target<'a, 'cfg>(
313313
}
314314

315315
/// Dependency edge information for fingerprints. This is generated for each
316-
/// unit in `dep_targets` and is stored in a `Fingerprint` below.
316+
/// dependency and is stored in a `Fingerprint` below.
317317
#[derive(Clone)]
318318
struct DepFingerprint {
319319
/// The hash of the package id that this dependency points to
@@ -1626,6 +1626,10 @@ pub fn translate_dep_info(
16261626
Ok(())
16271627
}
16281628

1629+
/// Parse the `.d` dep-info file generated by rustc.
1630+
///
1631+
/// Result is a Vec of `(target, prerequisites)` tuples where `target` is the
1632+
/// rule name, and `prerequisites` is a list of files that it depends on.
16291633
pub fn parse_rustc_dep_info(rustc_dep_info: &Path) -> CargoResult<Vec<(String, Vec<String>)>> {
16301634
let contents = paths::read(rustc_dep_info)?;
16311635
contents

src/cargo/core/compiler/output_depinfo.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
//! Module for generating dep-info files.
2+
//!
3+
//! `rustc` generates a dep-info file with a `.d` extension at the same
4+
//! location of the output artifacts as a result of using `--emit=dep-info`.
5+
//! This dep-info file is a Makefile-like syntax that indicates the
6+
//! dependencies needed to build the artifact. Example:
7+
//!
8+
//! ```makefile
9+
//! /path/to/target/debug/deps/cargo-b6219d178925203d: src/bin/main.rs src/bin/cargo/cli.rs # … etc.
10+
//! ```
11+
//!
12+
//! The fingerprint module has code to parse these files, and stores them as
13+
//! binary format in the fingerprint directory. These are used to quickly scan
14+
//! for any changed files.
15+
//!
16+
//! On top of all this, Cargo emits its own dep-info files in the output
17+
//! directory. This is done for every "uplifted" artifact. These are intended
18+
//! to be used with external build systems so that they can detect if Cargo
19+
//! needs to be re-executed. It includes all the entries from the `rustc`
20+
//! dep-info file, and extends it with any `rerun-if-changed` entries from
21+
//! build scripts. It also includes sources from any path dependencies. Registry
22+
//! dependencies are not included under the assumption that changes to them can
23+
//! be detected via changes to `Cargo.lock`.
24+
125
use std::collections::{BTreeSet, HashSet};
226
use std::fs::File;
327
use std::io::{BufWriter, Write};
@@ -75,6 +99,9 @@ fn add_deps_for_unit<'a, 'b>(
7599
Ok(())
76100
}
77101

102+
/// Save a `.d` dep-info file for the given unit.
103+
///
104+
/// This only saves files for uplifted artifacts.
78105
pub fn output_depinfo<'a, 'b>(cx: &mut Context<'a, 'b>, unit: &Unit<'a>) -> CargoResult<()> {
79106
let bcx = cx.bcx;
80107
let mut deps = BTreeSet::new();

0 commit comments

Comments
 (0)