Skip to content

Commit 0b984ad

Browse files
committed
Clean up most warnings
1 parent 143d570 commit 0b984ad

File tree

10 files changed

+61
-98
lines changed

10 files changed

+61
-98
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/input.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ impl<C: clap::Args + Customize> Prepare for InputOptions<C> {
5757
let resolution = manifest.resolve()?;
5858
for (pkg_id, versions) in &resolution.package_map {
5959
for v in versions {
60-
resolution
61-
.index
62-
.ensure_downloaded(pkg_id, v.clone())
63-
.unwrap();
60+
resolution.index.ensure_downloaded(pkg_id, *v).unwrap();
6461
}
6562
}
6663
let package_map = resolution.package_map(&manifest)?;

git/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77
[dependencies]
88
anyhow.workspace = true
99
gix = { workspace = true, features = ["blocking-network-client"] }
10+
serde.workspace = true
1011
tempfile.workspace = true
1112
thiserror.workspace = true
1213

git/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub struct Spec {
4949
}
5050

5151
/// The different kinds of git "thing" that we can target.
52-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
52+
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize)]
5353
pub enum Target {
5454
/// By default, we target the remote HEAD.
5555
#[default]

package/src/error.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::path::{Path, PathBuf};
22

3-
use nickel_lang_core::{eval::cache::CacheImpl, identifier::Ident, program::Program};
3+
use nickel_lang_core::{
4+
eval::cache::CacheImpl, identifier::Ident, package::ObjectId, program::Program,
5+
};
46

57
pub enum Error {
68
Io {
@@ -16,7 +18,12 @@ pub enum Error {
1618
path: PathBuf,
1719
},
1820
RestrictedPath {
19-
package: Ident,
21+
/// The url of the git package that tried the bad import.
22+
package_url: Box<gix::Url>,
23+
/// The git id of the bad package.
24+
package_commit: ObjectId,
25+
/// The relative path of the bad package within its git repo.
26+
package_path: PathBuf,
2027
attempted: PathBuf,
2128
restriction: PathBuf,
2229
},
@@ -63,13 +70,16 @@ impl std::fmt::Display for Error {
6370
}
6471
}
6572
Error::RestrictedPath {
66-
package,
6773
attempted,
6874
restriction,
75+
package_url,
76+
package_commit,
77+
package_path,
6978
} => {
7079
write!(
7180
f,
72-
"package {package} tried to import path {}, but can only import from {}",
81+
"git package {package_url}@{package_commit}/{} tried to import path {}, but can only import from {}",
82+
package_path.display(),
7383
attempted.display(),
7484
restriction.display()
7585
)

package/src/index/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl PackageIndex {
226226

227227
pub fn ensure_downloaded(&self, id: &Id, v: SemanticVersion) -> anyhow::Result<()> {
228228
let package = self
229-
.package(id, v.clone())
229+
.package(id, v)
230230
.ok_or(anyhow!("tried to download an unknown package"))?;
231231
let precise = Precise::Index {
232232
id: id.clone(),

package/src/lib.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@ pub mod util;
1010
pub use manifest::ManifestFile;
1111
use nickel_lang_core::{cache::normalize_abs_path, package::ObjectId};
1212
use pubgrub::version::SemanticVersion;
13-
use semver::Version;
1413
use serde::{Deserialize, Serialize};
1514
use util::cache_dir;
1615

17-
// TODO: allow targeting branches or revisions, and allow supplying a relative path
1816
#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize)]
1917
pub struct GitDependency {
2018
#[serde(with = "serde_url")]
2119
url: gix::Url,
22-
#[serde(with = "git_target")]
2320
spec: nickel_lang_git::Target,
2421
}
2522

@@ -87,7 +84,7 @@ impl Dependency {
8784
version: dep_version,
8885
},
8986
Precise::Index { id, version },
90-
) => id == dep_id && dep_version.matches(&version),
87+
) => id == dep_id && dep_version.matches(version),
9188
_ => false,
9289
}
9390
}
@@ -110,19 +107,6 @@ mod serde_url {
110107
}
111108
}
112109

113-
mod git_target {
114-
use nickel_lang_git::Target;
115-
use serde::{de::Error, Deserialize, Serialize as _};
116-
117-
pub fn serialize<S: serde::Serializer>(url: &Target, ser: S) -> Result<S::Ok, S::Error> {
118-
todo!()
119-
}
120-
121-
pub fn deserialize<'de, D: serde::Deserializer<'de>>(de: D) -> Result<Target, D::Error> {
122-
todo!()
123-
}
124-
}
125-
126110
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
127111
pub struct IndexPrecise {
128112
id: index::Id,
@@ -198,7 +182,7 @@ impl Precise {
198182

199183
pub fn version(&self) -> Option<SemanticVersion> {
200184
match self {
201-
Precise::Index { version, .. } => Some(version.clone()),
185+
Precise::Index { version, .. } => Some(*version),
202186
_ => None,
203187
}
204188
}

package/src/lock.rs

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ pub struct LockFile {
6161
}
6262

6363
impl LockFile {
64-
// TODO: move the implementation here
6564
pub fn new(manifest: &ManifestFile, resolution: &Resolution) -> Result<Self, Error> {
6665
// We don't put all packages in the lock file: we ignore dependencies (and therefore also
6766
// transitive dependencies) of path deps. In order to figure out what to include, we

package/src/manifest.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl Realization {
195195
return Ok(());
196196
}
197197
(Dependency::Git(git), _) => {
198-
let id = self.realize_one(&git)?;
198+
let id = self.realize_one(git)?;
199199
UnversionedPrecise::Git {
200200
id,
201201
url: git.url.clone(),
@@ -206,12 +206,18 @@ impl Realization {
206206
(Dependency::Path { path }, Some(relative_to)) => {
207207
let p = normalize_rel_path(&relative_to.local_path().join(path));
208208
match relative_to {
209-
Precise::Git { id, url: repo, .. } => {
209+
Precise::Git {
210+
id,
211+
url: repo,
212+
path,
213+
} => {
210214
let repo_path = repo_root(id);
211215
let p = p
212216
.strip_prefix(&repo_path)
213217
.map_err(|_| Error::RestrictedPath {
214-
package: "TODO".into(),
218+
package_url: Box::new(repo.clone()),
219+
package_commit: *id,
220+
package_path: path.clone(),
215221
attempted: p.clone(),
216222
restriction: repo_path.to_owned(),
217223
})?;

package/src/resolve.rs

+31-66
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,21 @@
1010
//! with version `2.0`. Since we present them to pubgrub
1111
//! as different packages, they can both appear in the final resolution.
1212
13-
use std::{
14-
borrow::Borrow,
15-
collections::HashMap,
16-
path::{Path, PathBuf},
17-
};
13+
use std::{borrow::Borrow, collections::HashMap, path::PathBuf};
1814

1915
use nickel_lang_core::{cache::normalize_path, identifier::Ident, package::PackageMap};
2016
use pubgrub::{
2117
report::{DefaultStringReporter, Reporter as _},
2218
solver::DependencyProvider,
23-
version::{SemanticVersion, Version},
19+
version::SemanticVersion,
2420
};
25-
use semver::Comparator;
2621

2722
use crate::{
2823
error::{Error, IoResultExt as _},
2924
index::{Id, IndexDependency, PackageIndex},
3025
lock::LockFile,
3126
manifest::Realization,
32-
util::semver_to_pg,
33-
Dependency, GitDependency, IndexPrecise, ManifestFile, ObjectId, Precise, UnversionedPackage,
34-
VersionReq,
27+
Dependency, IndexPrecise, ManifestFile, ObjectId, Precise, VersionReq,
3528
};
3629

3730
type VersionRange = pubgrub::range::Range<SemanticVersion>;
@@ -104,18 +97,6 @@ impl PackageRegistry {
10497
}
10598
}
10699

107-
fn bucket_versions(
108-
vs: impl Iterator<Item = SemanticVersion>,
109-
) -> impl Iterator<Item = SemanticVersion> {
110-
let mut vs: Vec<_> = vs
111-
.map(BucketVersion::from)
112-
.map(SemanticVersion::from)
113-
.collect();
114-
vs.sort();
115-
vs.dedup();
116-
vs.into_iter()
117-
}
118-
119100
/// A bucket version represents a collection of compatible semver versions.
120101
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
121102
pub enum BucketVersion {
@@ -298,32 +279,25 @@ impl DependencyProvider<Package, SemanticVersion> for PackageRegistry {
298279
let deps = self
299280
.unversioned_deps(p)
300281
.into_iter()
301-
.map(|dep| {
302-
match dep {
303-
Dependency::Git(_) | Dependency::Path { .. } => {
304-
let dep_precise = self.realized_unversioned.dependency
305-
[&(precise.clone(), dep.clone())]
306-
.clone();
307-
(
308-
Package::Unversioned(dep_precise.into()),
309-
VersionRange::any(),
310-
)
311-
}
312-
// We're making a proxy for every dependency on a repo package, but we could skip
313-
// the proxy if the dependency range stays within a single semver range.
314-
Dependency::Index { id, version } => {
315-
let pkg = Package::Bucket(Bucket {
316-
id,
317-
version: version.clone().into(),
318-
});
319-
320-
let range = match version {
321-
VersionReq::Compatible(v) => VersionRange::higher_than(v),
322-
VersionReq::Exact(v) => VersionRange::exact(v),
323-
};
324-
325-
(pkg, range)
326-
}
282+
.map(|dep| match dep {
283+
Dependency::Git(_) | Dependency::Path { .. } => {
284+
let dep_precise = self.realized_unversioned.dependency
285+
[&(precise.clone(), dep.clone())]
286+
.clone();
287+
(Package::Unversioned(dep_precise), VersionRange::any())
288+
}
289+
Dependency::Index { id, version } => {
290+
let pkg = Package::Bucket(Bucket {
291+
id,
292+
version: version.clone().into(),
293+
});
294+
295+
let range = match version {
296+
VersionReq::Compatible(v) => VersionRange::higher_than(v),
297+
VersionReq::Exact(v) => VersionRange::exact(v),
298+
};
299+
300+
(pkg, range)
327301
}
328302
})
329303
.collect();
@@ -358,13 +332,6 @@ impl DependencyProvider<Package, SemanticVersion> for PackageRegistry {
358332
}
359333
}
360334

361-
fn version_req_to_range(req: &VersionReq) -> pubgrub::range::Range<SemanticVersion> {
362-
match req {
363-
VersionReq::Compatible(v) => VersionRange::higher_than(v.clone()),
364-
VersionReq::Exact(v) => VersionRange::exact(v.clone()),
365-
}
366-
}
367-
368335
pub struct Resolution {
369336
pub realization: Realization,
370337
pub package_map: HashMap<Id, Vec<SemanticVersion>>,
@@ -375,12 +342,12 @@ pub fn resolve(manifest: &ManifestFile) -> Result<Resolution, Error> {
375342
resolve_with_lock(manifest, &LockFile::default())
376343
}
377344

378-
fn previously_locked(top_level: &Package, lock: &LockFile) -> HashMap<Package, SemanticVersion> {
345+
fn previously_locked(_top_level: &Package, lock: &LockFile) -> HashMap<Package, SemanticVersion> {
379346
fn precise_to_index(p: &Precise) -> Option<IndexPrecise> {
380347
match p {
381348
Precise::Index { id, version } => Some(IndexPrecise {
382349
id: id.clone(),
383-
version: version.clone(),
350+
version: *version,
384351
}),
385352
_ => None,
386353
}
@@ -414,11 +381,10 @@ fn previously_locked(top_level: &Package, lock: &LockFile) -> HashMap<Package, S
414381
pub fn resolve_with_lock(manifest: &ManifestFile, lock: &LockFile) -> Result<Resolution, Error> {
415382
let mut realization = Realization::default();
416383

417-
// FIXME: figure out how to represent the top-level package, recalling that `realization` assumes
418-
// that every time we need to look up a dependency we need a parent package.
384+
// TODO: this assumes that the top-level package has a path. Is there a a use-case for resolving
385+
// packages without a top-level path?
419386
let root_path = manifest.parent_dir.as_deref();
420387
for dep in manifest.dependencies.values() {
421-
// FIXME: unwrap
422388
realization.realize_all(root_path.unwrap(), dep, None)?;
423389
}
424390
let top_level = UnversionedPrecise::Path {
@@ -449,7 +415,7 @@ pub fn resolve_with_lock(manifest: &ManifestFile, lock: &LockFile) -> Result<Res
449415
let mut selected = HashMap::<Id, Vec<SemanticVersion>>::new();
450416
for (pkg, vers) in resolution.iter() {
451417
if let Package::Bucket(Bucket { id, .. }) = pkg {
452-
selected.entry(id.clone()).or_default().push(vers.clone());
418+
selected.entry(id.clone()).or_default().push(*vers);
453419
}
454420
}
455421
Ok(Resolution {
@@ -478,12 +444,11 @@ impl Resolution {
478444
},
479445
Dependency::Index { id, version } => Precise::Index {
480446
id: id.clone(),
481-
version: self.package_map[id]
447+
version: *self.package_map[id]
482448
.iter()
483449
.filter(|v| version.matches(v))
484450
.max()
485-
.unwrap()
486-
.clone(),
451+
.unwrap(),
487452
},
488453
}
489454
}
@@ -500,7 +465,7 @@ impl Resolution {
500465
.collect()
501466
}
502467
Precise::Index { id, version } => {
503-
let pkg = self.index.package(id, version.clone()).unwrap();
468+
let pkg = self.index.package(id, *version).unwrap();
504469
pkg.deps
505470
.into_iter()
506471
.map(move |(dep_name, dep)| {
@@ -529,7 +494,7 @@ impl Resolution {
529494
let index_precises = self.package_map.iter().flat_map(|(id, vs)| {
530495
vs.iter().map(|v| Precise::Index {
531496
id: id.clone(),
532-
version: v.clone(),
497+
version: *v,
533498
})
534499
});
535500
ret.extend(index_precises);

0 commit comments

Comments
 (0)