Skip to content

Commit e552733

Browse files
committed
Set PKGX_ENV to the list of pkgspecs
1 parent 981dfab commit e552733

File tree

6 files changed

+83
-71
lines changed

6 files changed

+83
-71
lines changed

crates/cli/src/execve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use nix::unistd::execve as nix_execve;
33
#[cfg(unix)]
44
use std::ffi::CString;
55

6-
use libpkgx::env::PlatformCaseAwareEnvKey;
6+
use libpkgx::platform_case_aware_env_key::PlatformCaseAwareEnvKey;
77
use std::{collections::HashMap, error::Error};
88

99
#[cfg(unix)]

crates/cli/src/main.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@ use std::{collections::HashMap, error::Error, fmt::Write, sync::Arc, time::Durat
1111
use execve::execve;
1212
use indicatif::{ProgressBar, ProgressState, ProgressStyle};
1313
use libpkgx::{
14-
env::{self, construct_platform_case_aware_env_key},
15-
hydrate::hydrate,
16-
install_multi, pantry_db,
17-
resolve::resolve,
18-
sync,
19-
types::PackageReq,
20-
utils,
14+
env, hydrate::hydrate, install_multi, pantry_db,
15+
platform_case_aware_env_key::construct_platform_case_aware_env_key, resolve::resolve, sync,
16+
types::PackageReq, utils,
2117
};
2218
use regex::Regex;
2319
use rusqlite::Connection;
@@ -135,7 +131,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
135131
})
136132
.await?;
137133

138-
let resolution = resolve(graph, &config).await?;
134+
let resolution = resolve(&graph, &config).await?;
139135

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

226+
// TODO should be output by +syntax too
227+
env.insert(
228+
construct_platform_case_aware_env_key("PKGX_ENV".to_string()),
229+
graph
230+
.iter()
231+
.map(|pkg| format!("{}", pkg))
232+
.collect::<Vec<String>>()
233+
.join(env::SEP),
234+
);
235+
230236
clear_progress_bar();
231237

232238
if flags.shebang {

crates/lib/src/env.rs

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,68 +7,15 @@ use std::{
77
#[cfg(unix)]
88
use std::str::FromStr;
99

10-
#[cfg(windows)]
11-
use std::{
12-
fmt,
13-
hash::{Hash, Hasher},
10+
use crate::{
11+
platform_case_aware_env_key::{construct_platform_case_aware_env_key, PlatformCaseAwareEnvKey},
12+
types::Installation,
1413
};
1514

16-
#[cfg(windows)]
17-
#[derive(Clone)]
18-
pub struct CaseInsensitiveKey(pub String);
19-
20-
#[cfg(windows)]
21-
impl PartialEq for CaseInsensitiveKey {
22-
fn eq(&self, other: &Self) -> bool {
23-
self.0.eq_ignore_ascii_case(&other.0)
24-
}
25-
}
26-
27-
#[cfg(windows)]
28-
impl fmt::Display for CaseInsensitiveKey {
29-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30-
write!(f, "{}", self.0)
31-
}
32-
}
33-
34-
#[cfg(windows)]
35-
impl Eq for CaseInsensitiveKey {}
36-
37-
#[cfg(windows)]
38-
impl Hash for CaseInsensitiveKey {
39-
fn hash<H: Hasher>(&self, state: &mut H) {
40-
self.0.to_lowercase().hash(state);
41-
}
42-
}
43-
44-
#[cfg(windows)]
45-
impl fmt::Debug for CaseInsensitiveKey {
46-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47-
write!(f, "{:?}", self.0)
48-
}
49-
}
50-
51-
#[cfg(windows)]
52-
pub type PlatformCaseAwareEnvKey = CaseInsensitiveKey;
53-
#[cfg(not(windows))]
54-
pub type PlatformCaseAwareEnvKey = String;
55-
56-
#[cfg(windows)]
57-
pub fn construct_platform_case_aware_env_key(key: String) -> PlatformCaseAwareEnvKey {
58-
CaseInsensitiveKey(key)
59-
}
60-
61-
#[cfg(not(windows))]
62-
pub fn construct_platform_case_aware_env_key(key: String) -> PlatformCaseAwareEnvKey {
63-
key
64-
}
65-
66-
use crate::types::Installation;
67-
6815
#[cfg(unix)]
69-
const SEP: &str = ":";
16+
pub const SEP: &str = ":";
7017
#[cfg(windows)]
71-
const SEP: &str = ";";
18+
pub const SEP: &str = ";";
7219

7320
pub fn map(installations: &Vec<Installation>) -> HashMap<String, Vec<String>> {
7421
let mut vars: HashMap<EnvKey, OrderedSet<PathBuf>> = HashMap::new();

crates/lib/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub mod install_multi;
88
mod inventory;
99
mod pantry;
1010
pub mod pantry_db;
11+
pub mod platform_case_aware_env_key;
1112
pub mod resolve;
1213
pub mod sync;
1314
pub mod types;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#[cfg(windows)]
2+
use std::{
3+
fmt,
4+
hash::{Hash, Hasher},
5+
};
6+
7+
#[cfg(windows)]
8+
#[derive(Clone)]
9+
pub struct CaseInsensitiveKey(pub String);
10+
11+
#[cfg(windows)]
12+
impl PartialEq for CaseInsensitiveKey {
13+
fn eq(&self, other: &Self) -> bool {
14+
self.0.eq_ignore_ascii_case(&other.0)
15+
}
16+
}
17+
18+
#[cfg(windows)]
19+
impl fmt::Display for CaseInsensitiveKey {
20+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21+
write!(f, "{}", self.0)
22+
}
23+
}
24+
25+
#[cfg(windows)]
26+
impl Eq for CaseInsensitiveKey {}
27+
28+
#[cfg(windows)]
29+
impl Hash for CaseInsensitiveKey {
30+
fn hash<H: Hasher>(&self, state: &mut H) {
31+
self.0.to_lowercase().hash(state);
32+
}
33+
}
34+
35+
#[cfg(windows)]
36+
impl fmt::Debug for CaseInsensitiveKey {
37+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38+
write!(f, "{:?}", self.0)
39+
}
40+
}
41+
42+
#[cfg(windows)]
43+
pub type PlatformCaseAwareEnvKey = CaseInsensitiveKey;
44+
#[cfg(not(windows))]
45+
pub type PlatformCaseAwareEnvKey = String;
46+
47+
#[cfg(windows)]
48+
pub fn construct_platform_case_aware_env_key(key: String) -> PlatformCaseAwareEnvKey {
49+
CaseInsensitiveKey(key)
50+
}
51+
52+
#[cfg(not(windows))]
53+
pub fn construct_platform_case_aware_env_key(key: String) -> PlatformCaseAwareEnvKey {
54+
key
55+
}

crates/lib/src/resolve.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,30 @@ pub struct Resolution {
1818
//TODO no need to take array since it doesn’t consider anything
1919
use futures::stream::{FuturesUnordered, StreamExt};
2020

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

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

2730
for req in reqs {
2831
futures.push(async move {
29-
if let Some(installation) = cellar::resolve(&req, config).await? {
32+
if let Some(installation) = cellar::resolve(req, config).await? {
3033
Ok::<_, Box<dyn Error>>((
3134
Some((installation.clone(), installation.pkg.clone())),
3235
None,
3336
))
34-
} else if let Some(version) = inventory::select(&req, config).await? {
37+
} else if let Some(version) = inventory::select(req, config).await? {
3538
let pkg = Package {
3639
project: req.project.clone(),
3740
version,
3841
};
3942
Ok::<_, Box<dyn Error>>((None, Some(pkg)))
4043
} else {
41-
Err(Box::new(ResolveError { pkg: req }) as Box<dyn Error>)
44+
Err(Box::new(ResolveError { pkg: req.clone() }) as Box<dyn Error>)
4245
}
4346
});
4447
}

0 commit comments

Comments
 (0)