Skip to content

Commit

Permalink
bincode error
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <[email protected]>
  • Loading branch information
jessfraz committed Aug 26, 2023
1 parent 73bbe76 commit 794028b
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 63 deletions.
35 changes: 11 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions src/cmd_kcl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,16 @@ impl crate::cmd::Command for CmdKclExport {
let input = std::str::from_utf8(&input)?;

// Spin up websockets and do the conversion.
let engine = ctx
.export_kcl_file("", input, &self.output_dir, &self.output_format)
// This will not return until there are files.
ctx.export_kcl_file("", input, &self.output_dir, &self.output_format)
.await?;

// Now we need to wait for the engine to finish.
// Sleep for a bit to give the engine time to start.
tokio::time::sleep(std::time::Duration::from_secs(120)).await;

// Check if we have files in our output directory.
let files = std::fs::read_dir(&self.output_dir)?
.map(|res| res.map(|e| e.path()))
.collect::<Result<Vec<_>, std::io::Error>>()?;
println!("files: {:?}", files);

drop(engine);

Ok(())
}
}
56 changes: 25 additions & 31 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,25 @@ impl Context<'_> {
}
}

let user_agent = concat!(env!("CARGO_PKG_NAME"), ".rs/", env!("CARGO_PKG_VERSION"),);
let http_client = reqwest::Client::builder()
.user_agent(user_agent)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60));
let ws_client = reqwest::Client::builder()
.user_agent(user_agent)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60))
.tcp_keepalive(std::time::Duration::from_secs(600))
.http1_only();

// Get the token for that host.
let token = self.config.get(&host, "token")?;

// Create the client.
let mut client = kittycad::Client::new(token);
let mut client = kittycad::Client::new_from_reqwest(token, http_client, ws_client);

if baseurl != crate::DEFAULT_HOST {
client.set_base_url(&baseurl);
Expand All @@ -87,39 +101,17 @@ impl Context<'_> {
code: &str,
output_dir: &std::path::Path,
format: &kittycad::types::FileExportFormat,
) -> Result<kcl::engine::EngineConnection> {
// Use the host passed in if it's set.
// Otherwise, use the default host.
let host = if hostname.is_empty() {
self.config.default_host()?
} else {
hostname.to_string()
};

// Change the baseURL to the one we want.
let mut baseurl = host.to_string();
if !host.starts_with("http://") && !host.starts_with("https://") {
baseurl = format!("https://{host}");
if host.starts_with("localhost") {
baseurl = format!("http://{host}")
}
}

baseurl = baseurl.replace("http", "ws");

// Get the token for that host.
let auth_token = self.config.get(&host, "token")?;
) -> Result<()> {
let client = self.api_client("http://system76-pc:8080")?;
let ws = client
.modeling()
.commands_ws(None, None, None, None, Some(false))
.await?;

let tokens = kcl::tokeniser::lexer(code);
let program = kcl::parser::abstract_syntax_tree(&tokens)?;
let mut mem: kcl::executor::ProgramMemory = Default::default();
let mut engine = kcl::engine::EngineConnection::new(
&baseurl,
&auth_token,
"kittycad-cli",
output_dir.display().to_string().as_str(),
)
.await?;
let mut engine = kcl::engine::EngineConnection::new(ws, output_dir.display().to_string().as_str()).await?;
let _ = kcl::executor::execute(program, &mut mem, kcl::executor::BodyType::Root, &mut engine)?;
// Send an export request to the engine.
engine.send_modeling_cmd(
Expand All @@ -131,7 +123,9 @@ impl Context<'_> {
},
)?;

Ok(engine)
engine.wait_for_files().await;

Ok(())
}

/// This function opens a browser that is based on the configured
Expand Down
67 changes: 67 additions & 0 deletions tests/gear.kcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const part001 = startSketchAt([0.0000000000, 5.0000000000])
|> line([0.4900857016, -0.0240763666], %)
|> line([0.6804562304, 0.9087880491], %)
|> line([0.5711661314, -0.1430696680], %)
|> line([0.1717090983, -1.1222443518], %)
|> line([0.4435665223, -0.2097913408], %)
|> line([0.9764377140, 0.5792113521], %)
|> line([0.4729383069, -0.3507549536], %)
|> line([-0.2708257990, -1.1025288142], %)
|> line([0.3295183609, -0.3635674851], %)
|> line([1.1237654070, 0.1614549773], %)
|> line([0.3027099123, -0.5050409772], %)
|> line([-0.6721299235, -0.9149632591], %)
|> line([0.1653040161, -0.4619937756], %)
|> line([1.1000100038, -0.2808814542], %)
|> line([0.0863966776, -0.5824390901], %)
|> line([-0.9711083600, -0.5881028420], %)
|> line([-0.0240763666, -0.4900857016], %)
|> line([0.9087880491, -0.6804562304], %)
|> line([-0.1430696680, -0.5711661314], %)
|> line([-1.1222443518, -0.1717090983], %)
|> line([-0.2097913408, -0.4435665223], %)
|> line([0.5792113521, -0.9764377140], %)
|> line([-0.3507549536, -0.4729383069], %)
|> line([-1.1025288142, 0.2708257990], %)
|> line([-0.3635674851, -0.3295183609], %)
|> line([0.1614549773, -1.1237654070], %)
|> line([-0.5050409772, -0.3027099123], %)
|> line([-0.9149632591, 0.6721299235], %)
|> line([-0.4619937756, -0.1653040161], %)
|> line([-0.2808814542, -1.1000100038], %)
|> line([-0.5824390901, -0.0863966776], %)
|> line([-0.5881028420, 0.9711083600], %)
|> line([-0.4900857016, 0.0240763666], %)
|> line([-0.6804562304, -0.9087880491], %)
|> line([-0.5711661314, 0.1430696680], %)
|> line([-0.1717090983, 1.1222443518], %)
|> line([-0.4435665223, 0.2097913408], %)
|> line([-0.9764377140, -0.5792113521], %)
|> line([-0.4729383069, 0.3507549536], %)
|> line([0.2708257990, 1.1025288142], %)
|> line([-0.3295183609, 0.3635674851], %)
|> line([-1.1237654070, -0.1614549773], %)
|> line([-0.3027099123, 0.5050409772], %)
|> line([0.6721299235, 0.9149632591], %)
|> line([-0.1653040161, 0.4619937756], %)
|> line([-1.1000100038, 0.2808814542], %)
|> line([-0.0863966776, 0.5824390901], %)
|> line([0.9711083600, 0.5881028420], %)
|> line([0.0240763666, 0.4900857016], %)
|> line([-0.9087880491, 0.6804562304], %)
|> line([0.1430696680, 0.5711661314], %)
|> line([1.1222443518, 0.1717090983], %)
|> line([0.2097913408, 0.4435665223], %)
|> line([-0.5792113521, 0.9764377140], %)
|> line([0.3507549536, 0.4729383069], %)
|> line([1.1025288142, -0.2708257990], %)
|> line([0.3635674851, 0.3295183609], %)
|> line([-0.1614549773, 1.1237654070], %)
|> line([0.5050409772, 0.3027099123], %)
|> line([0.9149632591, -0.6721299235], %)
|> line([0.4619937756, 0.1653040161], %)
|> line([0.2808814542, 1.1000100038], %)
|> line([0.5824390901, 0.0863966776], %)
|> close(%)
|> extrude(1, %)
show(part001)

0 comments on commit 794028b

Please sign in to comment.