Skip to content

Commit

Permalink
Do not clone configs
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Aug 18, 2024
1 parent 19560d9 commit ba46d91
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
16 changes: 8 additions & 8 deletions esp-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ pub struct Config {

impl Config {
/// The configuration for the specified chip.
pub fn for_chip(chip: &Chip) -> Self {
pub fn for_chip(chip: &Chip) -> &Self {
match chip {
Chip::Esp32 => ESP32_CFG.clone(),
Chip::Esp32c2 => ESP32C2_CFG.clone(),
Chip::Esp32c3 => ESP32C3_CFG.clone(),
Chip::Esp32c6 => ESP32C6_CFG.clone(),
Chip::Esp32h2 => ESP32H2_CFG.clone(),
Chip::Esp32s2 => ESP32S2_CFG.clone(),
Chip::Esp32s3 => ESP32S3_CFG.clone(),
Chip::Esp32 => &ESP32_CFG,
Chip::Esp32c2 => &ESP32C2_CFG,
Chip::Esp32c3 => &ESP32C3_CFG,
Chip::Esp32c6 => &ESP32C6_CFG,
Chip::Esp32h2 => &ESP32H2_CFG,
Chip::Esp32s2 => &ESP32S2_CFG,
Chip::Esp32s3 => &ESP32S3_CFG,
}
}

Expand Down
31 changes: 15 additions & 16 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
process::Command,
};

use anyhow::{bail, Context as _, Result};
use anyhow::{bail, ensure, Context as _, Result};
use clap::{Args, Parser};
use esp_metadata::{Arch, Chip, Config};
use minijinja::Value;
Expand Down Expand Up @@ -225,7 +225,7 @@ fn examples(workspace: &Path, mut args: ExampleArgs, action: CargoAction) -> Res

fn build_examples(args: ExampleArgs, examples: Vec<Metadata>, package_path: &Path) -> Result<()> {
// Determine the appropriate build target for the given package and chip:
let target = target_triple(&args.package, &args.chip)?;
let target = target_triple(args.package, &args.chip)?;

if let Some(example) = examples.iter().find(|ex| Some(ex.name()) == args.example) {
// Attempt to build only the specified example:
Expand Down Expand Up @@ -257,7 +257,7 @@ fn build_examples(args: ExampleArgs, examples: Vec<Metadata>, package_path: &Pat

fn run_example(args: ExampleArgs, examples: Vec<Metadata>, package_path: &Path) -> Result<()> {
// Determine the appropriate build target for the given package and chip:
let target = target_triple(&args.package, &args.chip)?;
let target = target_triple(args.package, &args.chip)?;

// Filter the examples down to only the binary we're interested in, assuming it
// actually supports the specified chip:
Expand All @@ -280,7 +280,7 @@ fn tests(workspace: &Path, args: TestArgs, action: CargoAction) -> Result<()> {
let package_path = xtask::windows_safe_path(&workspace.join("hil-test"));

// Determine the appropriate build target for the given package and chip:
let target = target_triple(&Package::HilTest, &args.chip)?;
let target = target_triple(Package::HilTest, &args.chip)?;

// Load all tests which support the specified chip and parse their metadata:
let mut tests = xtask::load_examples(&package_path.join("tests"))?
Expand Down Expand Up @@ -373,7 +373,7 @@ fn build_documentation_for_package(
validate_package_chip(&package, chip)?;

// Determine the appropriate build target for the given package and chip:
let target = target_triple(&package, chip)?;
let target = target_triple(package, chip)?;

// Build the documentation for the specified package, targeting the
// specified chip:
Expand Down Expand Up @@ -489,7 +489,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
// is *some* overlap)

for chip in &args.chips {
let device = Config::for_chip(&chip);
let device = Config::for_chip(chip);

match package {
Package::EspBacktrace => {
Expand Down Expand Up @@ -727,7 +727,7 @@ fn run_doctests(workspace: &Path, args: ExampleArgs) -> Result<()> {
let package_path = xtask::windows_safe_path(&workspace.join(&package_name));

// Determine the appropriate build target for the given package and chip:
let target = target_triple(&args.package, &args.chip)?;
let target = target_triple(args.package, &args.chip)?;
let features = vec![args.chip.to_string()];

// Build up an array of command-line arguments to pass to `cargo`:
Expand All @@ -752,22 +752,21 @@ fn run_doctests(workspace: &Path, args: ExampleArgs) -> Result<()> {
// ----------------------------------------------------------------------------
// Helper Functions

fn target_triple<'a>(package: &'a Package, chip: &'a Chip) -> Result<&'a str> {
if *package == Package::EspLpHal {
fn target_triple(package: Package, chip: &Chip) -> Result<&str> {
if package == Package::EspLpHal {
chip.lp_target()
} else {
Ok(chip.target())
}
}

fn validate_package_chip(package: &Package, chip: &Chip) -> Result<()> {
if *package == Package::EspLpHal && !chip.has_lp_core() {
bail!(
"Invalid chip provided for package '{}': '{}'",
package,
chip
);
}
ensure!(
*package != Package::EspLpHal || chip.has_lp_core(),
"Invalid chip provided for package '{}': '{}'",
package,
chip
);

Ok(())
}
Expand Down

0 comments on commit ba46d91

Please sign in to comment.