Skip to content

Commit

Permalink
Use 120 char line width
Browse files Browse the repository at this point in the history
  • Loading branch information
tarkah committed Feb 13, 2024
1 parent 1a85bbd commit acb2879
Show file tree
Hide file tree
Showing 72 changed files with 290 additions and 988 deletions.
44 changes: 9 additions & 35 deletions crates/boulder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ pub struct Target {
}

impl Builder {
pub fn new(
recipe_path: &Path,
env: Env,
profile: profile::Id,
ccache: bool,
) -> Result<Self, Error> {
pub fn new(recipe_path: &Path, env: Env, profile: profile::Id, ccache: bool) -> Result<Self, Error> {
let recipe = Recipe::load(recipe_path)?;

let macros = Macros::load(&env)?;
Expand Down Expand Up @@ -170,23 +165,14 @@ impl Builder {

let build_dir = &job.build_dir;
let work_dir = &job.work_dir;
let current_dir = if work_dir.exists() {
&work_dir
} else {
&build_dir
};
let current_dir = if work_dir.exists() { &work_dir } else { &build_dir };

for command in &script.commands {
match command {
script::Command::Break(breakpoint) => {
let line_num = breakpoint_line(
breakpoint,
&self.recipe,
job.target,
*step,
)
.map(|line_num| format!(" at line {line_num}"))
.unwrap_or_default();
let line_num = breakpoint_line(breakpoint, &self.recipe, job.target, *step)
.map(|line_num| format!(" at line {line_num}"))
.unwrap_or_default();

println!(
"\n{}{} {}",
Expand All @@ -200,10 +186,7 @@ impl Builder {
);

// Write env to $HOME/.profile
std::fs::write(
build_dir.join(".profile"),
build_profile(script),
)?;
std::fs::write(build_dir.join(".profile"), build_profile(script))?;

let mut command = process::Command::new("/bin/bash")
.arg("--login")
Expand Down Expand Up @@ -323,17 +306,13 @@ pub fn build_profile(script: &Script) -> String {
.as_deref()
.unwrap_or_default()
.lines()
.filter(|line| {
!line.starts_with("#!") && !line.starts_with("set -") && !line.starts_with("TERM=")
})
.filter(|line| !line.starts_with("#!") && !line.starts_with("set -") && !line.starts_with("TERM="))
.join("\n");

let action_functions = script
.resolved_actions
.iter()
.map(|(identifier, command)| {
format!("a_{identifier}() {{\n{command}\n}}\nexport -f a_{identifier}")
})
.map(|(identifier, command)| format!("a_{identifier}() {{\n{command}\n}}\nexport -f a_{identifier}"))
.join("\n");

let definition_vars = script
Expand All @@ -345,12 +324,7 @@ pub fn build_profile(script: &Script) -> String {
format!("{env}\n{action_functions}\n{definition_vars}")
}

fn breakpoint_line(
breakpoint: &Breakpoint,
recipe: &Recipe,
build_target: BuildTarget,
step: Step,
) -> Option<usize> {
fn breakpoint_line(breakpoint: &Breakpoint, recipe: &Recipe, build_target: BuildTarget, step: Step) -> Option<usize> {
let profile = recipe.build_target_profile_key(build_target);

let has_key = |line: &str, key: &str| {
Expand Down
7 changes: 1 addition & 6 deletions crates/boulder/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ pub enum Subcommand {
pub fn process() -> Result<(), Error> {
let Command { global, subcommand } = Command::parse();

let env = Env::new(
global.cache_dir,
global.config_dir,
global.data_dir,
global.moss_root,
)?;
let env = Env::new(global.cache_dir, global.config_dir, global.data_dir, global.moss_root)?;

match subcommand {
Subcommand::Build(command) => build::handle(command, env)?,
Expand Down
7 changes: 1 addition & 6 deletions crates/boulder/src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ pub struct Command {
default_value = "false"
)]
ccache: bool,
#[arg(
short,
long,
default_value = ".",
help = "Directory to store build results"
)]
#[arg(short, long, default_value = ".", help = "Directory to store build results")]
output: PathBuf,
#[arg(default_value = "./stone.yml", help = "Path to recipe file")]
recipe: PathBuf,
Expand Down
4 changes: 1 addition & 3 deletions crates/boulder/src/cli/chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ pub struct Command {
}

pub fn handle(command: Command, env: Env) -> Result<(), Error> {
let Command {
recipe: recipe_path,
} = command;
let Command { recipe: recipe_path } = command;

if !recipe_path.exists() {
return Err(Error::MissingRecipe(recipe_path));
Expand Down
9 changes: 2 additions & 7 deletions crates/boulder/src/cli/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,10 @@ pub async fn add<'a>(
Ok(())
}

pub async fn update<'a>(
env: &'a Env,
manager: profile::Manager<'a>,
profile: &profile::Id,
) -> Result<(), Error> {
pub async fn update<'a>(env: &'a Env, manager: profile::Manager<'a>, profile: &profile::Id) -> Result<(), Error> {
let repos = manager.repositories(profile)?.clone();

let mut moss_client =
moss::Client::with_explicit_repositories("boulder", &env.moss_dir, repos).await?;
let mut moss_client = moss::Client::with_explicit_repositories("boulder", &env.moss_dir, repos).await?;
moss_client.refresh_repositories().await?;

println!("Profile {profile} updated");
Expand Down
21 changes: 4 additions & 17 deletions crates/boulder/src/cli/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ pub enum Upstream {
fn parse_upstream(s: &str) -> Result<Upstream, String> {
match s.strip_prefix("git|") {
Some(rev) => Ok(Upstream::Git(rev.to_string())),
None => Ok(Upstream::Plain(
s.parse::<Url>().map_err(|e| e.to_string())?,
)),
None => Ok(Upstream::Plain(s.parse::<Url>().map_err(|e| e.to_string())?)),
}
}

Expand All @@ -77,12 +75,7 @@ pub fn handle(command: Command) -> Result<(), Error> {
}
}

fn update(
recipe: Option<PathBuf>,
overwrite: bool,
version: String,
upstreams: Vec<Upstream>,
) -> Result<(), Error> {
fn update(recipe: Option<PathBuf>, overwrite: bool, version: String, upstreams: Vec<Upstream>) -> Result<(), Error> {
if overwrite && recipe.is_none() {
return Err(Error::OverwriteRecipeRequired);
}
Expand All @@ -91,10 +84,7 @@ fn update(
fs::read_to_string(recipe).map_err(Error::Read)?
} else {
let mut bytes = vec![];
io::stdin()
.lock()
.read_to_end(&mut bytes)
.map_err(Error::Read)?;
io::stdin().lock().read_to_end(&mut bytes).map_err(Error::Read)?;
String::from_utf8(bytes)?
};

Expand All @@ -111,10 +101,7 @@ fn update(
GitUpstream(usize, serde_yaml::Value, String),
}

let mut updates = vec![
Update::Version(version),
Update::Release(parsed.source.release + 1),
];
let mut updates = vec![Update::Version(version), Update::Release(parsed.source.release + 1)];

for (i, (original, update)) in parsed.upstreams.iter().zip(upstreams).enumerate() {
match (original, update) {
Expand Down
12 changes: 2 additions & 10 deletions crates/boulder/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,11 @@ use thiserror::Error;

use crate::Paths;

pub fn exec(
paths: &Paths,
networking: bool,
f: impl FnMut() -> Result<(), ExecError>,
) -> Result<(), Error> {
pub fn exec(paths: &Paths, networking: bool, f: impl FnMut() -> Result<(), ExecError>) -> Result<(), Error> {
run(paths, networking, f)
}

fn run(
paths: &Paths,
networking: bool,
f: impl FnMut() -> Result<(), ExecError>,
) -> Result<(), Error> {
fn run(paths: &Paths, networking: bool, f: impl FnMut() -> Result<(), ExecError>) -> Result<(), Error> {
let rootfs = paths.rootfs().host;
let artefacts = paths.artefacts();
let build = paths.build();
Expand Down
20 changes: 2 additions & 18 deletions crates/boulder/src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,8 @@ pub fn calculate(builder: &Builder) -> Vec<&str> {
packages.push(CCACHE_PACKAGE);
}

packages.extend(
builder
.recipe
.parsed
.build
.build_deps
.iter()
.map(String::as_str),
);
packages.extend(
builder
.recipe
.parsed
.build
.check_deps
.iter()
.map(String::as_str),
);
packages.extend(builder.recipe.parsed.build.build_deps.iter().map(String::as_str));
packages.extend(builder.recipe.parsed.build.check_deps.iter().map(String::as_str));

for upstream in &builder.recipe.parsed.upstreams {
if let Upstream::Plain { uri, .. } = upstream {
Expand Down
8 changes: 1 addition & 7 deletions crates/boulder/src/job/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ pub enum Step {
}

impl Step {
const NORMAL: &'static [Self] = &[
Step::Prepare,
Step::Setup,
Step::Build,
Step::Install,
Step::Check,
];
const NORMAL: &'static [Self] = &[Step::Prepare, Step::Setup, Step::Build, Step::Install, Step::Check];
const WORKLOAD: &'static [Self] = &[Step::Prepare, Step::Setup, Step::Build, Step::Workload];

pub fn abbrev(&self) -> &str {
Expand Down
10 changes: 3 additions & 7 deletions crates/boulder/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ impl Macros {

let matcher = |p: &Path| p.extension().and_then(|s| s.to_str()) == Some("yml");

let arch_files =
util::sync::enumerate_files(&arch_dir, matcher).map_err(Error::ArchFiles)?;
let action_files =
util::sync::enumerate_files(&actions_dir, matcher).map_err(Error::ActionFiles)?;
let arch_files = util::sync::enumerate_files(&arch_dir, matcher).map_err(Error::ArchFiles)?;
let action_files = util::sync::enumerate_files(&actions_dir, matcher).map_err(Error::ActionFiles)?;

let mut arch = HashMap::new();
let mut actions = vec![];

for file in arch_files {
let relative = file
.strip_prefix(&arch_dir)
.unwrap_or_else(|_| unreachable!());
let relative = file.strip_prefix(&arch_dir).unwrap_or_else(|_| unreachable!());

let identifier = relative.with_extension("").display().to_string();

Expand Down
12 changes: 2 additions & 10 deletions crates/boulder/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,10 @@ pub struct Paths {
}

impl Paths {
pub fn new(
recipe: &Recipe,
host_root: impl Into<PathBuf>,
guest_root: impl Into<PathBuf>,
) -> io::Result<Self> {
pub fn new(recipe: &Recipe, host_root: impl Into<PathBuf>, guest_root: impl Into<PathBuf>) -> io::Result<Self> {
let id = Id::new(recipe);

let recipe_dir = recipe
.path
.parent()
.unwrap_or(&PathBuf::default())
.canonicalize()?;
let recipe_dir = recipe.path.parent().unwrap_or(&PathBuf::default()).canonicalize()?;

let job = Self {
id,
Expand Down
3 changes: 1 addition & 2 deletions crates/boulder/src/pgo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ pub fn stages(recipe: &Recipe, target: BuildTarget) -> Option<Vec<Stage>> {
build.workload.is_some().then(|| {
let mut stages = vec![Stage::One];

if matches!(recipe.parsed.options.toolchain, Toolchain::Llvm) && recipe.parsed.options.cspgo
{
if matches!(recipe.parsed.options.toolchain, Toolchain::Llvm) && recipe.parsed.options.cspgo {
stages.push(Stage::Two);
}

Expand Down
8 changes: 1 addition & 7 deletions crates/boulder/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ impl Id {
Self(
identifier
.chars()
.map(|c| {
if c.is_alphanumeric() || c == '-' {
c
} else {
'_'
}
})
.map(|c| if c.is_alphanumeric() || c == '-' { c } else { '_' })
.collect(),
)
}
Expand Down
23 changes: 4 additions & 19 deletions crates/boulder/src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ impl Recipe {
let source = fs::read_to_string(&path)?;
let parsed = stone_recipe::from_str(&source)?;

Ok(Self {
path,
source,
parsed,
})
Ok(Self { path, source, parsed })
}

pub fn build_targets(&self) -> Vec<BuildTarget> {
Expand All @@ -44,8 +40,7 @@ impl Recipe {
} else {
let mut targets = vec![];

if self.parsed.architectures.contains(&host_string)
|| self.parsed.architectures.contains(&"native".into())
if self.parsed.architectures.contains(&host_string) || self.parsed.architectures.contains(&"native".into())
{
targets.push(BuildTarget::Native(host));
}
Expand All @@ -66,12 +61,7 @@ impl Recipe {
pub fn build_target_profile_key(&self, target: BuildTarget) -> Option<String> {
let target_string = target.to_string();

if self
.parsed
.profiles
.iter()
.any(|kv| kv.key == target_string)
{
if self.parsed.profiles.iter().any(|kv| kv.key == target_string) {
Some(target_string)
} else if target.emul32() && self.parsed.profiles.iter().any(|kv| &kv.key == "emul32") {
Some("emul32".to_string())
Expand All @@ -83,12 +73,7 @@ impl Recipe {
pub fn build_target_definition(&self, target: BuildTarget) -> &stone_recipe::Build {
let key = self.build_target_profile_key(target);

if let Some(profile) = self
.parsed
.profiles
.iter()
.find(|kv| Some(&kv.key) == key.as_ref())
{
if let Some(profile) = self.parsed.profiles.iter().find(|kv| Some(&kv.key) == key.as_ref()) {
&profile.value
} else {
&self.parsed.build
Expand Down
7 changes: 3 additions & 4 deletions crates/boulder/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ pub async fn populate(builder: &Builder, repositories: repository::Map) -> Resul
// Recreate root
util::recreate_dir(&rootfs).await?;

let mut moss_client =
moss::Client::with_explicit_repositories("boulder", &builder.env.moss_dir, repositories)
.await?
.ephemeral(&rootfs)?;
let mut moss_client = moss::Client::with_explicit_repositories("boulder", &builder.env.moss_dir, repositories)
.await?
.ephemeral(&rootfs)?;

moss_client.install(&packages, true).await?;

Expand Down
Loading

0 comments on commit acb2879

Please sign in to comment.