Skip to content
Merged
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
2 changes: 1 addition & 1 deletion crates/cli/src/execve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use nix::unistd::execve as nix_execve;
#[cfg(unix)]
use std::ffi::CString;

use libpkgx::env::PlatformCaseAwareEnvKey;
use libpkgx::platform_case_aware_env_key::PlatformCaseAwareEnvKey;
use std::{collections::HashMap, error::Error};

#[cfg(unix)]
Expand Down
22 changes: 14 additions & 8 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ use std::{collections::HashMap, error::Error, fmt::Write, sync::Arc, time::Durat
use execve::execve;
use indicatif::{ProgressBar, ProgressState, ProgressStyle};
use libpkgx::{
env::{self, construct_platform_case_aware_env_key},
hydrate::hydrate,
install_multi, pantry_db,
resolve::resolve,
sync,
types::PackageReq,
utils,
env, hydrate::hydrate, install_multi, pantry_db,
platform_case_aware_env_key::construct_platform_case_aware_env_key, resolve::resolve, sync,
types::PackageReq, utils,
};
use regex::Regex;
use rusqlite::Connection;
Expand Down Expand Up @@ -135,7 +131,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
})
.await?;

let resolution = resolve(graph, &config).await?;
let resolution = resolve(&graph, &config).await?;

let spinner_clone = spinner.clone();
let clear_progress_bar = move || {
Expand Down Expand Up @@ -227,6 +223,16 @@ async fn main() -> Result<(), Box<dyn Error>> {
pkgx_lvl.to_string(),
);

// TODO should be output by +syntax too
env.insert(
construct_platform_case_aware_env_key("PKGX_ENV".to_string()),
graph
.iter()
.map(|pkg| format!("{}", pkg))
.collect::<Vec<String>>()
.join(env::SEP),
);

clear_progress_bar();

if flags.shebang {
Expand Down
63 changes: 5 additions & 58 deletions crates/lib/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,15 @@ use std::{
#[cfg(unix)]
use std::str::FromStr;

#[cfg(windows)]
use std::{
fmt,
hash::{Hash, Hasher},
use crate::{
platform_case_aware_env_key::{construct_platform_case_aware_env_key, PlatformCaseAwareEnvKey},
types::Installation,
};

#[cfg(windows)]
#[derive(Clone)]
pub struct CaseInsensitiveKey(pub String);

#[cfg(windows)]
impl PartialEq for CaseInsensitiveKey {
fn eq(&self, other: &Self) -> bool {
self.0.eq_ignore_ascii_case(&other.0)
}
}

#[cfg(windows)]
impl fmt::Display for CaseInsensitiveKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}

#[cfg(windows)]
impl Eq for CaseInsensitiveKey {}

#[cfg(windows)]
impl Hash for CaseInsensitiveKey {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.to_lowercase().hash(state);
}
}

#[cfg(windows)]
impl fmt::Debug for CaseInsensitiveKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.0)
}
}

#[cfg(windows)]
pub type PlatformCaseAwareEnvKey = CaseInsensitiveKey;
#[cfg(not(windows))]
pub type PlatformCaseAwareEnvKey = String;

#[cfg(windows)]
pub fn construct_platform_case_aware_env_key(key: String) -> PlatformCaseAwareEnvKey {
CaseInsensitiveKey(key)
}

#[cfg(not(windows))]
pub fn construct_platform_case_aware_env_key(key: String) -> PlatformCaseAwareEnvKey {
key
}

use crate::types::Installation;

#[cfg(unix)]
const SEP: &str = ":";
pub const SEP: &str = ":";
#[cfg(windows)]
const SEP: &str = ";";
pub const SEP: &str = ";";

pub fn map(installations: &Vec<Installation>) -> HashMap<String, Vec<String>> {
let mut vars: HashMap<EnvKey, OrderedSet<PathBuf>> = HashMap::new();
Expand Down
1 change: 1 addition & 0 deletions crates/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod install_multi;
mod inventory;
mod pantry;
pub mod pantry_db;
pub mod platform_case_aware_env_key;
pub mod resolve;
pub mod sync;
pub mod types;
Expand Down
55 changes: 55 additions & 0 deletions crates/lib/src/platform_case_aware_env_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#[cfg(windows)]
use std::{
fmt,
hash::{Hash, Hasher},
};

#[cfg(windows)]
#[derive(Clone)]
pub struct CaseInsensitiveKey(pub String);

#[cfg(windows)]
impl PartialEq for CaseInsensitiveKey {
fn eq(&self, other: &Self) -> bool {
self.0.eq_ignore_ascii_case(&other.0)
}
}

#[cfg(windows)]
impl fmt::Display for CaseInsensitiveKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}

#[cfg(windows)]
impl Eq for CaseInsensitiveKey {}

#[cfg(windows)]
impl Hash for CaseInsensitiveKey {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.to_lowercase().hash(state);
}
}

#[cfg(windows)]
impl fmt::Debug for CaseInsensitiveKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.0)
}
}

#[cfg(windows)]
pub type PlatformCaseAwareEnvKey = CaseInsensitiveKey;
#[cfg(not(windows))]
pub type PlatformCaseAwareEnvKey = String;

#[cfg(windows)]
pub fn construct_platform_case_aware_env_key(key: String) -> PlatformCaseAwareEnvKey {
CaseInsensitiveKey(key)
}

#[cfg(not(windows))]
pub fn construct_platform_case_aware_env_key(key: String) -> PlatformCaseAwareEnvKey {
key
}
11 changes: 7 additions & 4 deletions crates/lib/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,30 @@ pub struct Resolution {
//TODO no need to take array since it doesn’t consider anything
use futures::stream::{FuturesUnordered, StreamExt};

pub async fn resolve(reqs: Vec<PackageReq>, config: &Config) -> Result<Resolution, Box<dyn Error>> {
pub async fn resolve(
reqs: &Vec<PackageReq>,
config: &Config,
) -> Result<Resolution, Box<dyn Error>> {
let mut rv = Resolution::default();

// Create a FuturesUnordered to run the tasks concurrently
let mut futures = FuturesUnordered::new();

for req in reqs {
futures.push(async move {
if let Some(installation) = cellar::resolve(&req, config).await? {
if let Some(installation) = cellar::resolve(req, config).await? {
Ok::<_, Box<dyn Error>>((
Some((installation.clone(), installation.pkg.clone())),
None,
))
} else if let Some(version) = inventory::select(&req, config).await? {
} else if let Some(version) = inventory::select(req, config).await? {
let pkg = Package {
project: req.project.clone(),
version,
};
Ok::<_, Box<dyn Error>>((None, Some(pkg)))
} else {
Err(Box::new(ResolveError { pkg: req }) as Box<dyn Error>)
Err(Box::new(ResolveError { pkg: req.clone() }) as Box<dyn Error>)
}
});
}
Expand Down