Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
75 changes: 75 additions & 0 deletions src/check/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use crate::build::run_command;
use color_eyre::eyre::{eyre, Result};
use fs_err as fs;
use std::path::Path;
use std::process::Command;
use tracing::{info, instrument};

#[instrument(level = "trace", skip_all)]
pub fn execute(
package_dir: &Path,
release: bool,
profile: Option<&str>,
targets: Vec<String>,
packages: Vec<String>,
features: Vec<String>,
all_features: bool,
no_default_features: bool,
verbose: bool,
) -> Result<()> {
let package_dir = fs::canonicalize(package_dir)?;

if !package_dir.exists() {
let error = format!("Directory {:?} doesnt exists.", package_dir);
return Err(eyre!(error));
}

info!("Checking package in {:?}...", package_dir);

let mut args: Vec<String> = vec!["check", "--target-dir", "target"]
.iter()
.map(|v| v.to_string())
.collect();

if release {
args.push("--release".to_string());
}

if let Some(prof) = profile {
args.push("--profile".to_string());
args.push(prof.to_string());
}

for target in targets {
args.push("--target".to_string());
args.push(target);
}

for package in packages {
args.push("--package".to_string());
args.push(package);
}

if all_features {
args.push("--all-features".to_string());
}

if no_default_features {
args.push("--no-default-features".to_string());
}

if !features.is_empty() {
args.push("--features".to_string());
args.push(features.join(","));
}

run_command(
Command::new("cargo")
.args(&args[..])
.current_dir(&package_dir),
verbose,
)?;

info!("Done checking package in {:?}.", package_dir);
Ok(())
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod boot_real_node;
pub mod build;
pub mod build_start_package;
pub mod chain;
pub mod check;
pub mod connect;
pub mod dev_ui;
pub mod inject_message;
Expand Down
107 changes: 106 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use tracing_subscriber::{
};

use kit::{
boot_fake_node, boot_real_node, build, build_start_package, chain, connect, dev_ui,
boot_fake_node, boot_real_node, build, build_start_package, chain, check, connect, dev_ui,
inject_message, new, publish, remove_package, reset_cache, run_tests, setup, start_package,
update, view_api, KIT_LOG_PATH_DEFAULT,
};
Expand Down Expand Up @@ -206,6 +206,41 @@ async fn execute(
)
.await
}
Some(("check", matches)) => {
let package_dir = PathBuf::from(matches.get_one::<String>("DIR").unwrap());
let release = matches.get_one::<bool>("RELEASE").unwrap();
let profile = matches.get_one::<String>("PROFILE");
let targets: Vec<String> = matches
.get_many::<String>("TARGET")
.unwrap_or_default()
.map(|s| s.to_string())
.collect();
let packages: Vec<String> = matches
.get_many::<String>("PACKAGE")
.unwrap_or_default()
.map(|s| s.to_string())
.collect();
let features: Vec<String> = matches
.get_many::<String>("FEATURES")
.unwrap_or_default()
.map(|s| s.to_string())
.collect();
let all_features = matches.get_one::<bool>("ALL_FEATURES").unwrap();
let no_default_features = matches.get_one::<bool>("NO_DEFAULT_FEATURES").unwrap();
let verbose = matches.get_one::<bool>("VERBOSE").unwrap();

check::execute(
&package_dir,
*release,
profile.map(|s| s.as_str()),
targets,
packages,
features,
*all_features,
*no_default_features,
*verbose,
)
}
Some(("build", matches)) => {
let package_dir = PathBuf::from(matches.get_one::<String>("DIR").unwrap());
let no_ui = matches.get_one::<bool>("NO_UI").unwrap();
Expand Down Expand Up @@ -704,6 +739,76 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result<Command> {
.required(false)
)
)
.subcommand(Command::new("check")
.about("Check a Kinode package for errors")
.arg(
Arg::new("DIR")
.action(ArgAction::Set)
.help("The package directory to check")
.default_value(current_dir)
.required(false),
)
.arg(
Arg::new("RELEASE")
.action(ArgAction::SetTrue)
.short('r')
.long("release")
.help("Check artifacts in release mode, with optimizations")
.required(false),
)
.arg(
Arg::new("PROFILE")
.action(ArgAction::Set)
.long("profile")
.help("Check artifacts with the specified profile")
.required(false),
)
.arg(
Arg::new("TARGET")
.action(ArgAction::Append)
.long("target")
.help("Check for the target triple (can specify multiple times)")
.required(false),
)
.arg(
Arg::new("PACKAGE")
.action(ArgAction::Append)
.short('p')
.long("package")
.help("Package(s) to check (can specify multiple times)")
.required(false),
)
.arg(
Arg::new("FEATURES")
.action(ArgAction::Append)
.short('F')
.long("features")
.help("Space or comma separated list of features to activate")
.required(false),
)
.arg(
Arg::new("ALL_FEATURES")
.action(ArgAction::SetTrue)
.long("all-features")
.help("Activate all available features")
.required(false),
)
.arg(
Arg::new("NO_DEFAULT_FEATURES")
.action(ArgAction::SetTrue)
.long("no-default-features")
.help("Do not activate the `default` feature")
.required(false),
)
.arg(
Arg::new("VERBOSE")
.action(ArgAction::SetTrue)
.short('v')
.long("verbose")
.help("If set, output stdout and stderr")
.required(false),
),
)
.subcommand(Command::new("build")
.about("Build a Hyperware package")
.visible_alias("b")
Expand Down