-
Notifications
You must be signed in to change notification settings - Fork 24
/
cargo-deploy.rs
73 lines (70 loc) · 2.11 KB
/
cargo-deploy.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! # `cargo deploy`
//! Run a binary on a constellation cluster
//!
//! ## Usage
//! ```text
//! cargo deploy [options] <host> [--] [<args>]...
//! ```
//!
//! ## Options
//! ```text
//! -h --help Show this screen.
//! -V --version Show version.
//! --format=<fmt> Output format [possible values: human, json] [defa ult: human]
//! ```
//!
//! Note: --format can also be given as an env var, such as `CONSTELLATION_FORMAT=json`
#![warn(
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unused_results,
clippy::pedantic
)] // from https://github.com/rust-unofficial/patterns/blob/master/anti_patterns/deny-warnings.md
use std::{env, iter, net, process};
fn main() {
let args = env::args().skip(2);
let deploy_args = args.collect::<Vec<_>>();
let _addr: net::SocketAddr = deploy_args[0].parse().unwrap();
let args = iter::once(String::from("build"))
.chain(iter::once(String::from("--message-format=json")))
.chain(deploy_args.clone().into_iter().skip(1))
.collect::<Vec<_>>();
let output = process::Command::new("cargo")
.args(&args)
.stderr(process::Stdio::inherit())
.output()
.expect("Failed to invoke cargo");
let mut bin = None;
for message in serde_json::Deserializer::from_slice(&output.stdout)
.into_iter::<constellation_internal::cargo_metadata::Message>()
{
if let constellation_internal::cargo_metadata::Message::CompilerArtifact { artifact } =
message.unwrap_or_else(|_| {
panic!("Failed to parse output of cargo") // itertools::join(args.iter(), " ")
}) {
if artifact.target.kind == vec![String::from("bin")] {
assert_eq!(artifact.filenames.len(), 1);
assert!(bin.is_none());
bin = Some(artifact.filenames.into_iter().next().unwrap());
}
}
}
let bin = bin.expect("No binary found");
process::exit(
process::Command::new("deploy")
.args(&deploy_args)
.arg(&bin)
.stdout(process::Stdio::inherit())
.stderr(process::Stdio::inherit())
.output()
.expect("Failed to invoke deploy")
.status
.code()
.unwrap_or(101),
);
}