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
78 changes: 78 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ serde_json = "1"
sha2 = "0.10"
flate2 = "1"
tar = "0.4"
ureq = "2"
ureq = { version = "2", features = ["native-certs"] }
wright-analyzer = { path = "crates/wright-analyzer" }
wright-core = { path = "crates/wright-core" }
wright-driver = { path = "crates/wright-driver" }
Expand Down
2 changes: 1 addition & 1 deletion crates/wright-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub(crate) struct CommonArgs {
/// Include/project root for source inputs.
#[arg(long, value_name = "DIR")]
pub(crate) root: Option<PathBuf>,
/// Explicit local first-party OPY provider executable.
/// Override the first-party OPY provider executable.
#[arg(long, value_name = "PATH")]
pub(crate) opy_provider: Option<PathBuf>,
/// WIR transformation policy.
Expand Down
86 changes: 79 additions & 7 deletions crates/wright-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::sync::Arc;
use clap::{CommandFactory, Parser};
use wright_driver::config::{InputSpec, OutputFormat, SessionConfig, SourceKind};
use wright_driver::result::exit;
use wright_driver::source_provider::SourceBackend;

use crate::cli::{
Cli, Command, CommonArgs, ConvertTargetArg, OutputFormatArg, ProviderCommand, ProviderNameArg,
Expand Down Expand Up @@ -117,7 +118,7 @@ fn main() -> ExitCode {
fn run_workflow(command: Command) -> ExitCode {
let (name, config, presentation, convert_target) = match command {
Command::Compile(args) => {
let mut config = config_from_common(&args.common);
let mut config = config_from_common(&args.common, true);
config.output = args.output;
(
"compile",
Expand All @@ -128,24 +129,24 @@ fn run_workflow(command: Command) -> ExitCode {
}
Command::Convert(args) => (
"convert",
config_from_common(&args.common),
config_from_common(&args.common, false),
present::Presentation::from_common(&args.common),
Some(args.target),
),
Command::Check(args) => (
"check",
config_from_common(&args),
config_from_common(&args, true),
present::Presentation::from_common(&args),
None,
),
Command::Analyze(args) => (
"analyze",
config_from_common(&args),
config_from_common(&args, false),
present::Presentation::from_common(&args),
None,
),
Command::Lint(args) => {
let mut config = config_from_common(&args.common);
let mut config = config_from_common(&args.common, false);
for rule in &args.disable_rule {
config.lint.disable(rule);
}
Expand Down Expand Up @@ -173,7 +174,7 @@ fn run_workflow(command: Command) -> ExitCode {
}
Command::Inspect(args) => (
"inspect",
config_from_common(&args),
config_from_common(&args, false),
present::Presentation::from_common(&args),
None,
),
Expand Down Expand Up @@ -239,13 +240,20 @@ fn run_workflow(command: Command) -> ExitCode {
ExitCode::from(code)
}

fn config_from_common(common: &CommonArgs) -> SessionConfig {
fn config_from_common(common: &CommonArgs, provider_workflow: bool) -> SessionConfig {
let input = match &common.input {
Some(path) if path.as_os_str() != "-" => InputSpec::Path(path.clone()),
_ => InputSpec::Stdin,
};
SessionConfig {
input,
source_backend: if is_opy_input(common)
&& (provider_workflow || common.opy_provider.is_some())
{
SourceBackend::Provider
} else {
SourceBackend::Native
},
kind: match common.kind {
cli::SourceKindArg::Auto => SourceKind::Auto,
cli::SourceKindArg::Opy => SourceKind::Opy,
Expand All @@ -272,6 +280,19 @@ fn config_from_common(common: &CommonArgs) -> SessionConfig {
}
}

fn is_opy_input(common: &CommonArgs) -> bool {
match common.kind {
cli::SourceKindArg::Opy => true,
cli::SourceKindArg::Auto => common
.input
.as_deref()
.and_then(|path| path.extension())
.and_then(|extension| extension.to_str())
.is_some_and(|extension| extension.eq_ignore_ascii_case("opy")),
_ => false,
}
}

/// Run one driver workflow and render its envelope in the CLI presentation.
fn run_command<T: serde::Serialize>(
session: &mut wright_driver::CompilerSession,
Expand All @@ -287,3 +308,54 @@ fn run_command<T: serde::Serialize>(
present::render(&envelope, presentation);
code
}

#[cfg(test)]
mod tests {
use super::*;

fn common(input: Option<&str>, kind: cli::SourceKindArg) -> CommonArgs {
CommonArgs {
input: input.map(Into::into),
kind,
locale: None,
root: None,
opy_provider: None,
profile: cli::ProfileArg::Off,
format: cli::OutputFormatArg::Json,
renderer: cli::RendererArg::Plain,
color: cli::ColorArg::Never,
}
}

#[test]
fn ordinary_opy_check_and_compile_select_the_provider_backend() {
let opy = common(Some("main.opy"), cli::SourceKindArg::Auto);
assert_eq!(
config_from_common(&opy, true).source_backend,
SourceBackend::Provider
);

let workshop = common(Some("main.txt"), cli::SourceKindArg::Auto);
assert_eq!(
config_from_common(&workshop, true).source_backend,
SourceBackend::Native
);

let explicit_opy = common(None, cli::SourceKindArg::Opy);
assert_eq!(
config_from_common(&explicit_opy, true).source_backend,
SourceBackend::Provider
);
assert_eq!(
config_from_common(&opy, false).source_backend,
SourceBackend::Native
);

let mut explicit_provider = common(Some("main.opy"), cli::SourceKindArg::Auto);
explicit_provider.opy_provider = Some("opy-provider".into());
assert_eq!(
config_from_common(&explicit_provider, false).source_backend,
SourceBackend::Provider
);
}
}
Loading
Loading