Skip to content

Commit

Permalink
refactor extended tarball generaton to use the new ensure_if_default
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Jul 23, 2021
1 parent 2cfac3f commit c15e248
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 38 deletions.
44 changes: 37 additions & 7 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,8 @@ impl StepDescription {
}

fn maybe_run(&self, builder: &Builder<'_>, pathset: &PathSet) {
if builder.config.exclude.iter().any(|e| pathset.has(e)) {
eprintln!("Skipping {:?} because it is excluded", pathset);
if self.is_excluded(builder, pathset) {
return;
} else if !builder.config.exclude.is_empty() {
eprintln!(
"{:?} not skipped for {:?} -- not in {:?}",
pathset, self.name, builder.config.exclude
);
}

// Determine the targets participating in this rule.
Expand All @@ -182,6 +176,21 @@ impl StepDescription {
}
}

fn is_excluded(&self, builder: &Builder<'_>, pathset: &PathSet) -> bool {
if builder.config.exclude.iter().any(|e| pathset.has(e)) {
eprintln!("Skipping {:?} because it is excluded", pathset);
return true;
}

if !builder.config.exclude.is_empty() {
eprintln!(
"{:?} not skipped for {:?} -- not in {:?}",
pathset, self.name, builder.config.exclude
);
}
false
}

fn run(v: &[StepDescription], builder: &Builder<'_>, paths: &[PathBuf]) {
let should_runs =
v.iter().map(|desc| (desc.should_run)(ShouldRun::new(builder))).collect::<Vec<_>>();
Expand Down Expand Up @@ -1579,6 +1588,27 @@ impl<'a> Builder<'a> {
self.cache.put(step, out.clone());
out
}

/// Ensure that a given step is built *only if it's supposed to be built by default*, returning
/// its output. This will cache the step, so it's safe (and good!) to call this as often as
/// needed to ensure that all dependencies are build.
pub(crate) fn ensure_if_default<T, S: Step<Output = Option<T>>>(
&'a self,
step: S,
) -> S::Output {
let desc = StepDescription::from::<S>();
let should_run = (desc.should_run)(ShouldRun::new(self));

// Avoid running steps contained in --exclude
for pathset in &should_run.paths {
if desc.is_excluded(self, pathset) {
return None;
}
}

// Only execute if it's supposed to run as default
if desc.default && should_run.is_really_default() { self.ensure(step) } else { None }
}
}

#[cfg(test)]
Expand Down
47 changes: 17 additions & 30 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct Docs {
}

impl Step for Docs {
type Output = GeneratedTarball;
type Output = Option<GeneratedTarball>;
const DEFAULT: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand All @@ -72,7 +72,7 @@ impl Step for Docs {
}

/// Builds the `rust-docs` installer component.
fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
let host = self.host;
builder.default_doc(&[]);

Expand All @@ -82,7 +82,7 @@ impl Step for Docs {
tarball.set_product_name("Rust Documentation");
tarball.add_bulk_dir(&builder.doc_out(host), dest);
tarball.add_file(&builder.src.join("src/doc/robots.txt"), dest, 0o644);
tarball.generate()
Some(tarball.generate())
}
}

Expand Down Expand Up @@ -1359,13 +1359,11 @@ impl Step for Extended {

let mut tarballs = Vec::new();
let mut built_tools = HashSet::new();
macro_rules! add_tool {
macro_rules! add_component {
($name:expr => $step:expr) => {
if should_build_extended_tool(builder, $name) {
if let Some(tarball) = builder.ensure($step) {
tarballs.push(tarball);
built_tools.insert($name);
}
if let Some(tarball) = builder.ensure_if_default($step) {
tarballs.push(tarball);
built_tools.insert($name);
}
};
}
Expand All @@ -1377,31 +1375,20 @@ impl Step for Extended {
tarballs.push(builder.ensure(Rustc { compiler: builder.compiler(stage, target) }));
tarballs.push(builder.ensure(Std { compiler, target }).expect("missing std"));

if builder.config.docs {
tarballs.push(builder.ensure(Docs { host: target }));
}

if target.contains("windows-gnu") {
tarballs.push(builder.ensure(Mingw { host: target }).expect("missing mingw"));
}

if builder.config.profiler_enabled(target)
|| should_build_extended_tool(builder, "rust-demangler")
{
if let Some(tarball) = builder.ensure(RustDemangler { compiler, target }) {
tarballs.push(tarball);
built_tools.insert("rust-demangler");
}
}

add_tool!("cargo" => Cargo { compiler, target });
add_tool!("rustfmt" => Rustfmt { compiler, target });
add_tool!("rls" => Rls { compiler, target });
add_tool!("rust-analyzer" => RustAnalyzer { compiler, target });
add_tool!("llvm-tools" => LlvmTools { target });
add_tool!("clippy" => Clippy { compiler, target });
add_tool!("miri" => Miri { compiler, target });
add_tool!("analysis" => Analysis { compiler, target });
add_component!("rust-docs" => Docs { host: target });
add_component!("rust-demangler"=> RustDemangler { compiler, target });
add_component!("cargo" => Cargo { compiler, target });
add_component!("rustfmt" => Rustfmt { compiler, target });
add_component!("rls" => Rls { compiler, target });
add_component!("rust-analyzer" => RustAnalyzer { compiler, target });
add_component!("llvm-components" => LlvmTools { target });
add_component!("clippy" => Clippy { compiler, target });
add_component!("miri" => Miri { compiler, target });
add_component!("analysis" => Analysis { compiler, target });

let etc = builder.src.join("src/etc/installer");

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ macro_rules! install {

install!((self, builder, _config),
Docs, "src/doc", _config.docs, only_hosts: false, {
let tarball = builder.ensure(dist::Docs { host: self.target });
let tarball = builder.ensure(dist::Docs { host: self.target }).expect("missing docs");
install_sh(builder, "docs", self.compiler.stage, Some(self.target), &tarball);
};
Std, "library/std", true, only_hosts: false, {
Expand Down

0 comments on commit c15e248

Please sign in to comment.