Skip to content

Commit

Permalink
Only try to fetch package manifest if deploy-docs feature is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebraham committed Feb 13, 2025
1 parent 816e7a5 commit 45606ba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[alias]
xtask = "run --package xtask --"
xdoc = "run --package xtask --features=deploy-docs --"
xfmt = "xtask fmt-packages"
qa = "xtask run-example qa-test"
qa = "xtask run-example qa-test"
11 changes: 10 additions & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ esp-metadata = { path = "../esp-metadata", features = ["clap"] }
kuchikiki = "0.8.2"
log = "0.4.22"
minijinja = "2.5.0"
reqwest = { version = "0.12.12", features = ["blocking", "json", "native-tls-vendored"] }
semver = { version = "1.0.23", features = ["serde"] }
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0.70"
strum = { version = "0.26.3", features = ["derive"] }
toml_edit = "0.22.22"
walkdir = "2.5.0"

# Only required when building documentation for deployment:
reqwest = { version = "0.12.12", features = [
"blocking",
"json",
"native-tls-vendored",
], optional = true }

[features]
deploy-docs = ["dep:reqwest"]
38 changes: 24 additions & 14 deletions xtask/src/documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,7 @@ pub fn build_documentation(

// Download the manifest from the documentation server if able,
// otherwise just create a default (empty) manifest:
let mut manifest_url = base_url
.clone()
.unwrap_or_default()
.trim_end_matches('/')
.to_string();
manifest_url.push_str(&format!("/{package}/manifest.json"));

let mut manifest = match reqwest::blocking::get(manifest_url) {
Ok(resp) => resp.json::<Manifest>()?,
Err(err) => {
log::warn!("Unable to fetch package manifest: {err}");
Manifest::default()
}
};
let mut manifest = fetch_manifest(&base_url, package)?;

// If the package does not have chip features, then just ignore
// whichever chip(s) were specified as arguments:
Expand Down Expand Up @@ -476,6 +463,29 @@ fn generate_documentation_meta_for_index(workspace: &Path) -> Result<Vec<Value>>
// ----------------------------------------------------------------------------
// Helper Functions

fn fetch_manifest(base_url: &Option<String>, package: &Package) -> Result<Manifest> {
let mut manifest_url = base_url
.clone()
.unwrap_or_default()
.trim_end_matches('/')
.to_string();
manifest_url.push_str(&format!("/{package}/manifest.json"));

#[cfg(feature = "deploy-docs")]
let manifest = match reqwest::blocking::get(manifest_url) {
Ok(resp) => resp.json::<Manifest>()?,
Err(err) => {
log::warn!("Unable to fetch package manifest: {err}");
Manifest::default()
}
};

#[cfg(not(feature = "deploy-docs"))]
let manifest = Manifest::default();

Ok(manifest)
}

fn render_template<C>(resources: &Path, template: &str, ctx: C) -> Result<String>
where
C: serde::Serialize,
Expand Down

0 comments on commit 45606ba

Please sign in to comment.