Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/densemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl<K: Index, V> DenseMap<K, V> {
self.vec.push(val);
id
}

pub fn all_ids(&self) -> impl Iterator<Item = K> {
(0..self.vec.len()).map(|id| K::from(id))
}
}

impl<K: Index, V: Clone> DenseMap<K, V> {
Expand Down
136 changes: 85 additions & 51 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ use crate::{
densemap::{self, DenseMap},
hash::BuildHash,
};
use std::collections::{hash_map::Entry, HashMap};
use std::path::{Path, PathBuf};
use std::time::SystemTime;
use std::{
collections::{hash_map::Entry, HashMap},
ops::{Deref, DerefMut},
};

/// Id for File nodes in the Graph.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -39,7 +42,7 @@ impl From<usize> for BuildId {
}

/// A single file referenced as part of a build.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct File {
/// Canonical path to the file.
pub name: String,
Expand Down Expand Up @@ -74,6 +77,7 @@ pub struct RspFile {
}

/// Input files to a Build.
#[derive(Clone)]
pub struct BuildIns {
/// Internally we stuff explicit/implicit/order-only ins all into one Vec.
/// This is mostly to simplify some of the iteration and is a little more
Expand All @@ -88,6 +92,7 @@ pub struct BuildIns {
}

/// Output files from a Build.
#[derive(Clone)]
pub struct BuildOuts {
/// Similar to ins, we keep both explicit and implicit outs in one Vec.
pub ids: Vec<FileId>,
Expand Down Expand Up @@ -144,60 +149,19 @@ mod tests {
}
}

/// A single build action, generating File outputs from File inputs with a command.
pub struct Build {
/// Source location this Build was declared.
pub location: FileLoc,

/// User-provided description of the build step.
pub desc: Option<String>,

/// Command line to run. Absent for phony builds.
pub cmdline: Option<String>,

/// Path to generated `.d` file, if any.
pub depfile: Option<String>,

/// If true, extract "/showIncludes" lines from output.
pub parse_showincludes: bool,

// Struct that contains the path to the rsp file and its contents, if any.
pub rspfile: Option<RspFile>,

/// Pool to execute this build in, if any.
pub pool: Option<String>,

#[derive(Clone)]
pub struct BuildDependencies {
/// Input files.
pub ins: BuildIns,

/// Additional inputs discovered from a previous build.
discovered_ins: Vec<FileId>,

/// Output files.
pub outs: BuildOuts,

/// True if output of command should be hidden on successful completion.
pub hide_success: bool,
/// True if last line of output should not be shown in status.
pub hide_progress: bool,
}
impl Build {
pub fn new(loc: FileLoc, ins: BuildIns, outs: BuildOuts) -> Self {
Build {
location: loc,
desc: None,
cmdline: None,
depfile: None,
parse_showincludes: false,
rspfile: None,
pool: None,
ins,
discovered_ins: Vec::new(),
outs,
hide_success: false,
hide_progress: false,
}
}

impl BuildDependencies {
/// Input paths that appear in `$in`.
pub fn explicit_ins(&self) -> &[FileId] {
&self.ins.ids[0..self.ins.explicit]
Expand Down Expand Up @@ -245,6 +209,80 @@ impl Build {
}
}

/// A single build action, generating File outputs from File inputs with a command.
pub struct Build {
/// Source location this Build was declared.
pub location: FileLoc,

/// Inputs and outputs for this build.
pub dependencies: BuildDependencies,

/// User-provided description of the build step.
pub desc: Option<String>,

/// Command line to run. Absent for phony builds.
pub cmdline: Option<String>,

/// Controls how dependency information is processed after compilation.
pub deps: Option<String>,

/// Path to generated `.d` file, if any.
pub depfile: Option<String>,

// Struct that contains the path to the rsp file and its contents, if any.
pub rspfile: Option<RspFile>,

/// Pool to execute this build in, if any.
pub pool: Option<String>,

/// True if output of command should be hidden on successful completion.
pub hide_success: bool,
/// True if last line of output should not be shown in status.
pub hide_progress: bool,
}
impl Build {
pub fn new(loc: FileLoc, ins: BuildIns, outs: BuildOuts) -> Self {
Build {
location: loc,
dependencies: BuildDependencies {
ins,
discovered_ins: Vec::new(),
outs,
},
desc: None,
cmdline: None,
deps: None,
depfile: None,
rspfile: None,
pool: None,
hide_success: false,
hide_progress: false,
}
}

/// If true, extract "/showIncludes" lines from output.
pub fn parse_showincludes(&self) -> bool {
match self.deps.as_deref() {
Some("msvc") => true,
_ => false,
}
}
}

impl Deref for Build {
type Target = BuildDependencies;

fn deref(&self) -> &Self::Target {
&self.dependencies
}
}

impl DerefMut for Build {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.dependencies
}
}

/// The build graph: owns Files/Builds and maps FileIds/BuildIds to them.
#[derive(Default)]
pub struct Graph {
Expand Down Expand Up @@ -330,10 +368,6 @@ impl GraphFiles {
}
}
}

pub fn all_ids(&self) -> impl Iterator<Item = FileId> {
(0..self.by_id.next_id().0).map(|id| FileId(id))
}
}

/// MTime info gathered for a file. This also models "file is absent".
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod canon;
mod db;
mod densemap;
mod depfile;
pub mod densemap;
pub mod depfile;
mod eval;
mod graph;
pub mod graph;
mod hash;
pub mod load;
pub mod parse;
Expand Down
10 changes: 5 additions & 5 deletions src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ impl Loader {
let cmdline = lookup("command");
let desc = lookup("description");
let depfile = lookup("depfile");
let parse_showincludes = match lookup("deps").as_deref() {
None => false,
Some("gcc") => false,
Some("msvc") => true,
let deps = match lookup("deps").as_deref() {
None => None,
Some("gcc") => Some("gcc".to_string()),
Some("msvc") => Some("msvc".to_string()),
Some(other) => bail!("invalid deps attribute {:?}", other),
};
let pool = lookup("pool");
Expand All @@ -164,7 +164,7 @@ impl Loader {
build.cmdline = cmdline;
build.desc = desc;
build.depfile = depfile;
build.parse_showincludes = parse_showincludes;
build.deps = deps;
build.rspfile = rspfile;
build.pool = pool;
build.hide_success = hide_success;
Expand Down
2 changes: 1 addition & 1 deletion src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl Runner {
let cmdline = build.cmdline.clone().unwrap();
let depfile = build.depfile.clone().map(PathBuf::from);
let rspfile = build.rspfile.clone();
let parse_showincludes = build.parse_showincludes;
let parse_showincludes = build.parse_showincludes();
let hide_progress = build.hide_progress;

let tid = self.tids.claim();
Expand Down
2 changes: 1 addition & 1 deletion src/work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl<'a> Work<'a> {
}

pub fn want_every_file(&mut self, exclude: Option<FileId>) -> anyhow::Result<()> {
for id in self.graph.files.all_ids() {
for id in self.graph.files.by_id.all_ids() {
if let Some(exclude) = exclude {
if id == exclude {
continue;
Expand Down
Loading