forked from NationTech/harmony
chore: reformat & clippy cleanup (#96)
Clippy is now added to the `check` in the pipeline Co-authored-by: Ian Letourneau <letourneau.ian@gmail.com> Reviewed-on: NationTech/harmony#96
This commit is contained in:
@@ -95,7 +95,7 @@ pub async fn handle_events() {
|
||||
));
|
||||
(*progresses_guard).insert(PROGRESS_DEPLOYMENT.to_string(), multi_progress);
|
||||
}
|
||||
HarmonyComposerEvent::DeploymentCompleted { details } => println!("\n"),
|
||||
HarmonyComposerEvent::DeploymentCompleted => println!("\n"),
|
||||
HarmonyComposerEvent::Shutdown => {
|
||||
for (_, progresses) in (*progresses_guard).iter() {
|
||||
progresses.clear().unwrap();
|
||||
|
||||
@@ -11,7 +11,7 @@ pub enum HarmonyComposerEvent {
|
||||
ProjectCompiled,
|
||||
ProjectCompilationFailed { details: String },
|
||||
DeploymentStarted { target: String },
|
||||
DeploymentCompleted { details: String },
|
||||
DeploymentCompleted,
|
||||
Shutdown,
|
||||
}
|
||||
|
||||
|
||||
@@ -80,14 +80,13 @@ async fn main() {
|
||||
instrumentation::instrument(HarmonyComposerEvent::ProjectInitializationStarted).unwrap();
|
||||
|
||||
let harmony_bin_path: PathBuf = match harmony_path {
|
||||
true => {
|
||||
compile_harmony(
|
||||
cli_args.compile_method,
|
||||
cli_args.compile_platform,
|
||||
cli_args.harmony_path.clone(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
true => compile_harmony(
|
||||
cli_args.compile_method,
|
||||
cli_args.compile_platform,
|
||||
cli_args.harmony_path.clone(),
|
||||
)
|
||||
.await
|
||||
.expect("couldn't compile harmony"),
|
||||
false => todo!("implement autodetect code"),
|
||||
};
|
||||
|
||||
@@ -145,10 +144,9 @@ async fn main() {
|
||||
.expect("failed to run harmony deploy");
|
||||
|
||||
let deploy_output = deploy.wait_with_output().unwrap();
|
||||
instrumentation::instrument(HarmonyComposerEvent::DeploymentCompleted {
|
||||
details: String::from_utf8(deploy_output.stdout).unwrap(),
|
||||
})
|
||||
.unwrap();
|
||||
debug!("{}", String::from_utf8(deploy_output.stdout).unwrap());
|
||||
|
||||
instrumentation::instrument(HarmonyComposerEvent::DeploymentCompleted).unwrap();
|
||||
}
|
||||
Commands::All(_args) => todo!(
|
||||
"take all previous match arms and turn them into separate functions, and call them all one after the other"
|
||||
@@ -173,7 +171,7 @@ async fn compile_harmony(
|
||||
method: Option<CompileMethod>,
|
||||
platform: Option<String>,
|
||||
harmony_location: String,
|
||||
) -> PathBuf {
|
||||
) -> Result<PathBuf, String> {
|
||||
let platform = match platform {
|
||||
Some(p) => p,
|
||||
None => current_platform::CURRENT_PLATFORM.to_string(),
|
||||
@@ -203,6 +201,7 @@ async fn compile_harmony(
|
||||
details: "compiling project with cargo".to_string(),
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
compile_cargo(platform, harmony_location).await
|
||||
}
|
||||
CompileMethod::Docker => {
|
||||
@@ -210,16 +209,28 @@ async fn compile_harmony(
|
||||
details: "compiling project with docker".to_string(),
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
compile_docker(platform, harmony_location).await
|
||||
}
|
||||
};
|
||||
|
||||
instrumentation::instrument(HarmonyComposerEvent::ProjectCompiled).unwrap();
|
||||
path
|
||||
match path {
|
||||
Ok(path) => {
|
||||
instrumentation::instrument(HarmonyComposerEvent::ProjectCompiled).unwrap();
|
||||
Ok(path)
|
||||
}
|
||||
Err(err) => {
|
||||
instrumentation::instrument(HarmonyComposerEvent::ProjectCompilationFailed {
|
||||
details: err.clone(),
|
||||
})
|
||||
.unwrap();
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: make sure this works with cargo workspaces
|
||||
async fn compile_cargo(platform: String, harmony_location: String) -> PathBuf {
|
||||
async fn compile_cargo(platform: String, harmony_location: String) -> Result<PathBuf, String> {
|
||||
let metadata = MetadataCommand::new()
|
||||
.manifest_path(format!("{}/Cargo.toml", harmony_location))
|
||||
.exec()
|
||||
@@ -268,7 +279,10 @@ async fn compile_cargo(platform: String, harmony_location: String) -> PathBuf {
|
||||
}
|
||||
}
|
||||
|
||||
cargo_build.wait().expect("run cargo command failed");
|
||||
let res = cargo_build.wait(); //.expect("run cargo command failed");
|
||||
if res.is_err() {
|
||||
return Err("cargo build failed".into());
|
||||
}
|
||||
|
||||
let bin = artifacts
|
||||
.last()
|
||||
@@ -286,10 +300,10 @@ async fn compile_cargo(platform: String, harmony_location: String) -> PathBuf {
|
||||
let _copy_res = fs::copy(&bin, &bin_out).await;
|
||||
}
|
||||
|
||||
bin_out
|
||||
Ok(bin_out)
|
||||
}
|
||||
|
||||
async fn compile_docker(platform: String, harmony_location: String) -> PathBuf {
|
||||
async fn compile_docker(platform: String, harmony_location: String) -> Result<PathBuf, String> {
|
||||
let docker_client =
|
||||
bollard::Docker::connect_with_local_defaults().expect("couldn't connect to docker");
|
||||
|
||||
@@ -305,7 +319,7 @@ async fn compile_docker(platform: String, harmony_location: String) -> PathBuf {
|
||||
.await
|
||||
.expect("list containers failed");
|
||||
|
||||
if containers.len() > 0 {
|
||||
if !containers.is_empty() {
|
||||
docker_client
|
||||
.remove_container("harmony_build", None::<RemoveContainerOptions>)
|
||||
.await
|
||||
@@ -367,12 +381,12 @@ async fn compile_docker(platform: String, harmony_location: String) -> PathBuf {
|
||||
}
|
||||
|
||||
// wait until container is no longer running
|
||||
while let Some(_) = wait.next().await {}
|
||||
while (wait.next().await).is_some() {}
|
||||
|
||||
// hack that should be cleaned up
|
||||
if platform.contains("windows") {
|
||||
return PathBuf::from(format!("{}/harmony.exe", harmony_location));
|
||||
Ok(PathBuf::from(format!("{}/harmony.exe", harmony_location)))
|
||||
} else {
|
||||
return PathBuf::from(format!("{}/harmony", harmony_location));
|
||||
Ok(PathBuf::from(format!("{}/harmony", harmony_location)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user