Skip to content

Commit

Permalink
fix: use best_platform to verify the run platform (#1472)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-arts authored Jun 5, 2024
1 parent fee64d9 commit 3501f01
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use clap::Parser;
use dialoguer::theme::ColorfulTheme;
use itertools::Itertools;
use miette::{miette, Context, Diagnostic, IntoDiagnostic};
use rattler_conda_types::Platform;

use crate::activation::get_environment_variables;
use crate::environment::verify_prefix_location_unchanged;
Expand Down Expand Up @@ -62,6 +61,9 @@ pub async fn execute(args: Args) -> miette::Result<()> {

// Extract the passed in environment name.
let environment = project.environment_from_name_or_env_var(args.environment.clone())?;

let best_platform = environment.best_platform();

// Find the environment to run the task in, if any were specified.
let explicit_environment = if environment.is_default() {
None
Expand Down Expand Up @@ -99,10 +101,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
let search_environment = SearchEnvironments::from_opt_env(
&project,
explicit_environment.clone(),
explicit_environment
.as_ref()
.map(|e| e.best_platform())
.or(Some(Platform::current())),
Some(best_platform),
)
.with_disambiguate_fn(disambiguate_task_interactive);

Expand Down
34 changes: 33 additions & 1 deletion src/project/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<'p> Environment<'p> {
/// Return all tasks available for the given environment
/// This will not return task prefixed with _
pub fn get_filtered_tasks(&self) -> HashSet<TaskName> {
self.tasks(Some(Platform::current()))
self.tasks(Some(self.best_platform()))
.into_iter()
.flat_map(|tasks| {
tasks.into_iter().filter_map(|(key, _)| {
Expand Down Expand Up @@ -716,4 +716,36 @@ mod tests {
vec!["https://1.com/", "https://2.com/"]
)
}

#[test]
fn test_validate_platform() {
let manifest = Project::from_str(
Path::new("pixi.toml"),
r#"
[project]
name = "foobar"
channels = ["conda-forge"]
platforms = ["osx-64", "linux-64", "win-64"]
"#,
)
.unwrap();
let env = manifest.default_environment();
// This should also work on OsxArm64
assert!(env.validate_platform_support(Some(Platform::Osx64)).is_ok());

let manifest = Project::from_str(
Path::new("pixi.toml"),
r#"
[project]
name = "foobar"
channels = ["conda-forge"]
platforms = ["emscripten-wasm32"]
"#,
)
.unwrap();
let env = manifest.default_environment();
assert!(env
.validate_platform_support(Some(Platform::EmscriptenWasm32))
.is_ok());
}
}
5 changes: 3 additions & 2 deletions src/task/task_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ mod tests {
[project]
name = "foo"
channels = ["foo"]
platforms = ["linux-64", "osx-arm64", "win-64", "osx-64"]
platforms = ["linux-64", "win-64", "osx-64"]
[tasks]
test = "cargo test"
Expand All @@ -216,7 +216,8 @@ mod tests {
test = ["test"]
"#;
let project = Project::from_str(Path::new("pixi.toml"), manifest_str).unwrap();
let search = SearchEnvironments::from_opt_env(&project, None, None);
let env = project.default_environment();
let search = SearchEnvironments::from_opt_env(&project, None, Some(env.best_platform()));
let result = search.find_task("test".into(), FindTaskSource::CmdArgs);
assert!(result.is_ok());
assert!(result.unwrap().0.name().is_default());
Expand Down

0 comments on commit 3501f01

Please sign in to comment.