Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xtask/latest redirect #3231

Merged
merged 4 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[alias]
xtask = "run --package xtask --"
xdoc = "run --package xtask --features=deploy-docs --"
xdoc = "run --package xtask --features=deploy-docs,preview-docs --"
xfmt = "xtask fmt-packages"
qa = "xtask run-example qa-test"
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ exclude = [
"qa-test",
"xtensa-lx",
"xtensa-lx-rt",
"xtensa-lx-rt-procmacros",
"xtensa-lx-rt-proc-macros",
]
5 changes: 4 additions & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "xtask"
name = "xtask"
version = "0.0.0"
edition = "2021"
publish = false
Expand All @@ -16,6 +16,8 @@ esp-metadata = { path = "../esp-metadata", features = ["clap"] }
kuchikiki = "0.8.2"
log = "0.4.22"
minijinja = "2.5.0"
opener = { version = "0.7.2", optional = true }
rocket = { version = "0.5.1", optional = true }
semver = { version = "1.0.23", features = ["serde"] }
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0.70"
Expand All @@ -32,3 +34,4 @@ reqwest = { version = "0.12.12", features = [

[features]
deploy-docs = ["dep:reqwest"]
preview-docs = ["dep:rocket", "dep:opener"]
41 changes: 39 additions & 2 deletions xtask/src/documentation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
collections::HashSet,
fs,
fs::{self, create_dir_all},
io::Write,
path::{Path, PathBuf},
};

Expand Down Expand Up @@ -139,6 +140,35 @@ fn build_documentation_for_package(
)
})?;

// create "/latest" redirect - assuming that the current version is the latest
let latest_path = if package.chip_features_matter() {
output_path
.parent()
.unwrap()
.parent()
.unwrap()
.join("latest")
} else {
output_path.parent().unwrap().join("latest")
};
log::info!("Creating latest version redirect at {:?}", latest_path);
create_dir_all(latest_path.clone())?;
std::fs::File::create(latest_path.clone().join("index.html"))?.write_all(
format!(
"<meta http-equiv=\"refresh\" content=\"0; url=../{}/\" />",
if package.chip_features_matter() {
version.to_string()
} else {
format!(
"{}/{}",
version.to_string(),
package.to_string().replace('-', "_")
)
}
)
.as_bytes(),
)?;

Ok(())
}

Expand Down Expand Up @@ -255,6 +285,9 @@ fn apply_feature_rules(package: &Package, config: &Config) -> Vec<String> {
Package::EspHalEmbassy => {
features.push("esp-hal/unstable".to_owned());
}
Package::EspIeee802154 => {
features.push("esp-hal/unstable".to_owned());
}
_ => {}
}

Expand Down Expand Up @@ -337,7 +370,7 @@ pub fn build_documentation_index(workspace: &Path, packages: &mut [Package]) ->
let mut device_doc_paths = Vec::new();

// Each path we iterate over should be the directory for a given version of
// the package's documentation:
// the package's documentation: (except latest)
for version_path in fs::read_dir(package_docs_path)? {
let version_path = version_path?.path();
if version_path.is_file() {
Expand All @@ -348,6 +381,10 @@ pub fn build_documentation_index(workspace: &Path, packages: &mut [Package]) ->
continue;
}

if version_path.file_name().unwrap() == "latest" {
continue;
}

for path in fs::read_dir(&version_path)? {
let path = path?.path();
if path.is_dir() {
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum Package {
QaTest,
XtensaLx,
XtensaLxRt,
XtensaLxRtProcmacros,
XtensaLxRtProcMacros,
}

impl Package {
Expand Down
34 changes: 30 additions & 4 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use strum::IntoEnumIterator;
use xtask::{
cargo::{CargoAction, CargoArgsBuilder},
firmware::Metadata,
target_triple,
Package,
Version,
target_triple, Package, Version,
};

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -104,6 +102,9 @@ struct BuildDocumentationIndexArgs {
/// Package(s) to build documentation index for.
#[arg(long, value_enum, value_delimiter = ',', default_values_t = Package::iter())]
packages: Vec<Package>,
#[cfg(feature = "preview-docs")]
#[arg(long)]
serve: bool,
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -514,7 +515,32 @@ fn build_documentation_index(
workspace: &Path,
mut args: BuildDocumentationIndexArgs,
) -> Result<()> {
xtask::documentation::build_documentation_index(workspace, &mut args.packages)
xtask::documentation::build_documentation_index(workspace, &mut args.packages)?;

#[cfg(feature = "preview-docs")]
if args.serve {
std::thread::spawn(|| {
std::thread::sleep(std::time::Duration::from_millis(1000));
opener::open_browser("http://127.0.0.1:8000/").ok();
});

rocket::async_main(
{
rocket::build().mount(
"/",
rocket::fs::FileServer::new(
"docs",
rocket::fs::Options::Index
| rocket::fs::Options::IndexFile
| rocket::fs::Options::DotFiles,
),
)
}
.launch(),
)?;
}

Ok(())
}

fn build_package(workspace: &Path, args: BuildPackageArgs) -> Result<()> {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion xtensa-lx-rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ features = ["esp32"]

[dependencies]
document-features = "0.2.10"
macros = { version = "0.2.2", package = "xtensa-lx-rt-proc-macros", path = "../xtensa-lx-rt-procmacros" }
macros = { version = "0.2.2", package = "xtensa-lx-rt-proc-macros", path = "../xtensa-lx-rt-proc-macros" }
r0 = "1.0.0"
xtensa-lx = { version = "0.10.0", path = "../xtensa-lx" }

Expand Down
Loading