Skip to content

Commit

Permalink
integrate bytestream support
Browse files Browse the repository at this point in the history
  • Loading branch information
DolceTriade committed Jan 2, 2024
1 parent a0a88bc commit 0d86b5d
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 17 deletions.
1 change: 1 addition & 0 deletions blade/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rust_binary(
deps = [
"//blade/db",
"//blade/bep",
"//blade/bytestream",
"//blade/state",
"//blade/tailwindmerge",
"@crate//:actix-files",
Expand Down
13 changes: 12 additions & 1 deletion blade/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ cfg_if! {
db_path: String,
#[arg(short='d', long="print_message", value_name = "PATTERN", default_value="")]
debug_message_pattern: String,
#[arg(short='l', long="allow_local", value_name = "ALLOW_LOCAL", default_value="false")]
allow_local: bool,
#[arg(short='o', long="bytestream_override", value_name = "OVERRIDE")]
bytestream_overrides: Vec<String>,

}

#[actix_web::main]
Expand All @@ -48,8 +53,14 @@ cfg_if! {
conf.leptos_options.site_addr = args.http_host;
let addr = conf.leptos_options.site_addr;
let routes = generate_route_list(App);
let mut bs = bytestream::Client::new();
for o in &args.bytestream_overrides {
if let Some(s) = o.split_once('=') {
bs.add_override(s.0, s.1);
}
}
let db_manager = db::new(&args.db_path)?;
let state = Arc::new(state::Global { db_manager });
let state = Arc::new(state::Global { db_manager, allow_local: args.allow_local, bytestream_client: bs });
let actix_state = state.clone();
log::info!("Starting blade server at: {}", addr.to_string());
let fut1 = HttpServer::new(move || {
Expand Down
49 changes: 36 additions & 13 deletions blade/routes/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,39 @@ use leptos_router::*;

use crate::components::card::Card;
use crate::components::shellout::ShellOut;
use crate::components::testsummary::TestSummary;
use crate::components::testrunlist::TestRunList;
use crate::components::testresults::TestResults;
use crate::components::testrunlist::TestRunList;
use crate::components::testsummary::TestSummary;

#[cfg(feature = "ssr")]
use std::sync::Arc;

#[server]
pub async fn get_artifact(uri: String) -> Result<Vec<u8>, ServerFnError> {
let uri = url::Url::parse(&uri).map_err(|e| ServerFnError::ServerError(format!("{e:#?}")))?;
if uri.scheme() == "file" {
let path = uri
.to_file_path()
.map_err(|e| ServerFnError::ServerError(format!("{e:#?}")))?;
return std::fs::read(path).map_err(|e| ServerFnError::ServerError(format!("{e:#?}")));
let global: Arc<state::Global> = use_context::<Arc<state::Global>>().unwrap();
let parsed =
url::Url::parse(&uri).map_err(|e| ServerFnError::ServerError(format!("{e:#?}")))?;
match parsed.scheme() {
"file" => {
if !global.allow_local {
return Err(ServerFnError::ServerError("not implemented".to_string()));
}
let path = parsed
.to_file_path()
.map_err(|e| ServerFnError::ServerError(format!("{e:#?}")))?;
return std::fs::read(path).map_err(|e| ServerFnError::ServerError(format!("{e:#?}")));
}
"bytestream" | "http" | "https" => {
return global
.bytestream_client
.download_file(&uri)
.await
.map_err(|e| ServerFnError::ServerError(format!("failed to get artifact: {e}")));
}
_ => {
Err(ServerFnError::ServerError("not implemented".to_string()))
}
}
Err(ServerFnError::ServerError("not implemented".to_string()))
}

fn get_run(
Expand Down Expand Up @@ -131,10 +150,14 @@ pub fn Test() -> impl IntoView {
move |uri| async move {
match uri {
None => None,
Some(uri) => get_artifact(uri.to_string()).await.ok().as_ref().and_then(|v| {
let c = std::io::Cursor::new(v);
junit_parser::from_reader(c).ok()
}),
Some(uri) => get_artifact(uri.to_string())
.await
.ok()
.as_ref()
.and_then(|v| {
let c = std::io::Cursor::new(v);
junit_parser::from_reader(c).ok()
}),
}
},
);
Expand Down
1 change: 1 addition & 0 deletions blade/state/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rust_library(
"@crate//:futures",
"@crate//:serde",
"@crate//:tokio",
"//blade/bytestream",
],
}),
)
2 changes: 2 additions & 0 deletions blade/state/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ pub trait DBManager: std::marker::Send + std::marker::Sync {

pub struct Global {
pub db_manager: Box<dyn DBManager>,
pub bytestream_client: bytestream::Client,
pub allow_local: bool,
}

}
Expand Down
7 changes: 4 additions & 3 deletions tailwindcss/tailwindcss.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def _srcs_aspect_impl(target, ctx):
# print their paths.
for src in ctx.rule.attr.srcs:
srcs.append(src.files)
for dep in ctx.rule.attr.deps:
if SrcsInfo in dep:
srcs.append(dep[SrcsInfo].srcs)
if hasattr(ctx.rule.attr, "deps"):
for dep in ctx.rule.attr.deps:
if SrcsInfo in dep:
srcs.append(dep[SrcsInfo].srcs)
return [SrcsInfo(srcs = depset(transitive = srcs))]

_srcs_aspect = aspect(
Expand Down

0 comments on commit 0d86b5d

Please sign in to comment.