Skip to content

Commit 0cc7468

Browse files
committed
Clean up unwraps
1 parent cb6c2c4 commit 0cc7468

File tree

8 files changed

+183
-72
lines changed

8 files changed

+183
-72
lines changed

Cargo.lock

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

cli/src/package.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl PackageCommand {
5555
pub fn run(self, _global: GlobalOptions) -> CliResult<()> {
5656
match &self.command {
5757
Command::GenerateLockfile => {
58-
self.load_manifest()?.lock()?;
58+
self.load_manifest()?.regenerate_lock()?;
5959
}
6060
Command::DebugResolution => {
6161
let path = self.find_manifest()?;

core/src/program.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ use crate::{
3131
label::Label,
3232
metrics::increment,
3333
package::PackageMap,
34+
position::TermPos,
3435
term::{
35-
make as mk_term, make::builder, record::Field, BinaryOp, MergePriority, RichTerm, Term,
36+
make::{self as mk_term, builder},
37+
record::Field,
38+
BinaryOp, MergePriority, RichTerm, RuntimeContract, Term,
3639
},
3740
};
3841

@@ -191,6 +194,9 @@ pub struct Program<EC: EvalCache> {
191194
/// be evaluated, but it can be set by the user (for example by the `--field` argument of the
192195
/// CLI) to evaluate only a specific field.
193196
pub field: FieldPath,
197+
/// Extra contracts to apply to the main program source. Note that the contract is applied to
198+
/// the whole value before fields are extracted.
199+
pub contracts: Vec<RuntimeContract>,
194200
}
195201

196202
/// The Possible Input Sources, anything that a Nickel program can be created from
@@ -235,6 +241,7 @@ impl<EC: EvalCache> Program<EC> {
235241
color_opt: clap::ColorChoice::Auto.into(),
236242
overrides: Vec::new(),
237243
field: FieldPath::new(),
244+
contracts: Vec::new(),
238245
})
239246
}
240247

@@ -278,6 +285,7 @@ impl<EC: EvalCache> Program<EC> {
278285
color_opt: clap::ColorChoice::Auto.into(),
279286
overrides: Vec::new(),
280287
field: FieldPath::new(),
288+
contracts: Vec::new(),
281289
})
282290
}
283291

@@ -360,6 +368,10 @@ impl<EC: EvalCache> Program<EC> {
360368
self.overrides.extend(overrides);
361369
}
362370

371+
pub fn add_contract(&mut self, contract: RuntimeContract) {
372+
self.contracts.push(contract);
373+
}
374+
363375
/// Adds import paths to the end of the list.
364376
pub fn add_import_paths<P>(&mut self, paths: impl Iterator<Item = P>)
365377
where
@@ -407,7 +419,7 @@ impl<EC: EvalCache> Program<EC> {
407419
fn prepare_eval_impl(&mut self, for_query: bool) -> Result<Closure, Error> {
408420
// If there are no overrides, we avoid the boilerplate of creating an empty record and
409421
// merging it with the current program
410-
let prepared_body = if self.overrides.is_empty() {
422+
let mut prepared_body = if self.overrides.is_empty() {
411423
self.vm.prepare_eval(self.main_id)?
412424
} else {
413425
let mut record = builder::Record::new();
@@ -436,6 +448,14 @@ impl<EC: EvalCache> Program<EC> {
436448
mk_term::op2(BinaryOp::Merge(Label::default().into()), t, built_record)
437449
};
438450

451+
if !self.contracts.is_empty() {
452+
prepared_body = RuntimeContract::apply_all(
453+
prepared_body,
454+
self.contracts.iter().cloned(),
455+
TermPos::None,
456+
);
457+
}
458+
439459
let prepared = Closure::atomic_closure(prepared_body);
440460

441461
let result = if for_query {

flake.nix

-5
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@
310310
})
311311
)
312312
boost # implicit dependency of nix
313-
openssl # for git2; not needed if we switch to gitoxide
314313
];
315314

316315
# seems to be needed for consumer cargoArtifacts to be able to use
@@ -331,10 +330,6 @@
331330
version
332331
cargoArtifacts;
333332

334-
# openssl and pkg-config are for git2; not needed if we switch to gitoxide
335-
buildInputs = with pkgs; [ pkg-config ];
336-
nativeBuildInputs = with pkgs; [ openssl ];
337-
338333
cargoExtraArgs = "${cargoBuildExtraArgs} ${extraBuildArgs} --package ${cargoPackage}";
339334
} // extraArgs);
340335

package/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ readme.workspace = true
1515

1616
[dependencies]
1717
directories.workspace = true
18-
gix = { version = "0.63.0", features = ["blocking-network-client", "blocking-http-transport-reqwest-rust-tls"] }
18+
gix = { version = "0.63.0", features = ["blocking-network-client", "blocking-http-transport-reqwest-rust-tls", "serde"] }
1919
nickel-lang-core = { workspace = true, default-features = false }
2020
serde.workspace = true
2121
serde_json.workspace = true

package/src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::path::PathBuf;
22

33
use directories::ProjectDirs;
4-
use serde::{Deserialize, Serialize};
54

65
pub mod error;
76
pub mod lock;
@@ -13,17 +12,17 @@ pub use manifest::ManifestFile;
1312
/// A source includes the place to fetch a package from (e.g. git or a registry),
1413
/// along with possibly some narrowing-down of the allowed versions (e.g. a range
1514
/// of versions, or a git commit id).
16-
#[derive(Clone, Debug, Serialize, Deserialize)]
15+
#[derive(Clone, Debug)]
1716
pub enum PackageSource {
18-
// TODO: support branches other than HEAD
17+
// TODO: allow targeting branches or revisions, and allow supplying a relative path
1918
Git {
20-
url: String,
19+
url: gix::Url,
2120
//tree: Option<git2::Oid>,
2221
},
2322
Path {
2423
path: PathBuf,
2524
},
26-
// TODO: non-git packages
25+
// TODO: packages in a repository
2726
}
2827

2928
impl PackageSource {

0 commit comments

Comments
 (0)