Skip to content

Commit

Permalink
Merge pull request #31 from hernoufM/env
Browse files Browse the repository at this point in the history
Fix : empty environment bug
  • Loading branch information
rjbou committed May 4, 2023
2 parents 209a576 + f8b95c2 commit e45a1e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/opamBundleMain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ let create_bundle ocamlv opamv repo debug output env test doc yes self_extract
in
let env =
match env with
| Some [] ->
(* System variables are always defined in opam, we need to
fill them to simulate empty environment and avoid undefined
variables. *)
OpamConsole.note "Empty environment";
OpamSysPoll.variables
|> List.map (fun (v,_) -> v, (lazy (Some (S "<undefined>")), "Empty environment"))
|> OpamVariable.Map.of_list
| Some e ->
let comment = "Manually defined" in
List.map (fun s ->
Expand All @@ -117,6 +125,10 @@ let create_bundle ocamlv opamv repo debug output env test doc yes self_extract
OpamVariable.of_string s, (lazy (Some (B true)), comment))
e
|> OpamVariable.Map.of_list
|> OpamVariable.Map.union (fun _poll cli -> cli)
(OpamVariable.Map.of_list
(List.map (fun (v,x) -> v, (x, "Inferred from current system"))
OpamSysPoll.variables))
| None ->
let e =
List.map (fun (v,x) -> v, (x, "Inferred from current system"))
Expand All @@ -141,7 +153,7 @@ let create_bundle ocamlv opamv repo debug output env test doc yes self_extract
let packages_filter =
let module L = OpamListCommand in
OpamFormula.ands [
if OpamVariable.Map.is_empty env then Atom L.Any else Atom L.Available;
Atom L.Available;
OpamFormula.ors [
Atom (L.Solution (L.default_dependency_toggles,
bootstrap_packages ocamlv));
Expand Down
15 changes: 14 additions & 1 deletion tests/stub/env.t
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,21 @@ Bundle package `baz`, with empty constraint specified in '--environment' option.
all dependencies.

$ opam-bundle baz --environment --repository ./REPO --ocaml=4.14.0 -y 2>&1
[NOTE] Empty environment

<><> Initialising repositories ><><><><><><><><><><><><><><><><><><><><><><><><>
[home] Initialised

<><> Resolving package set ><><><><><><><><><><><><><><><><><><><><><><><><><><>
The following packages will be included:
- bar.1
- baz.1
- foo.1
- ocaml.4.14.0
- ocaml-base-compiler.4.14.0
- ocaml-bootstrap.4.14.0
- ocaml-config.2
According to the packages' metadata, the bundle should be installable on any arch/OS.
The bundle will be installable on systems matching the following: os != "cygwin" & os != "linux"
[NOTE] Opam system sandboxing (introduced in 2.0) will be disabled in the bundle. You need to trust that the build scripts of the included packages don't write outside of their build directory and dest dir.
Continue ? [Y/n] y

Expand All @@ -348,17 +351,27 @@ all dependencies.
baz-bundle/opam-full-2.1.0-rc2.tar.gz
baz-bundle/repo/
baz-bundle/repo/archives/
baz-bundle/repo/archives/bar.1/
baz-bundle/repo/archives/bar.1/compile.tar.gz
baz-bundle/repo/archives/baz.1/
baz-bundle/repo/archives/baz.1/compile.tar.gz
baz-bundle/repo/archives/foo.1/
baz-bundle/repo/archives/foo.1/compile.tar.gz
baz-bundle/repo/archives/ocaml-base-compiler.4.14.0/
baz-bundle/repo/archives/ocaml-base-compiler.4.14.0/ocaml.tar.gz
baz-bundle/repo/archives/ocaml.4.14.0/
baz-bundle/repo/archives/ocaml.4.14.0/compile.tar.gz
baz-bundle/repo/cache/
baz-bundle/repo/packages/
baz-bundle/repo/packages/bar/
baz-bundle/repo/packages/bar/bar.1/
baz-bundle/repo/packages/bar/bar.1/opam
baz-bundle/repo/packages/baz/
baz-bundle/repo/packages/baz/baz.1/
baz-bundle/repo/packages/baz/baz.1/opam
baz-bundle/repo/packages/foo/
baz-bundle/repo/packages/foo/foo.1/
baz-bundle/repo/packages/foo/foo.1/opam
baz-bundle/repo/packages/ocaml-base-compiler/
baz-bundle/repo/packages/ocaml-base-compiler/ocaml-base-compiler.4.14.0/
baz-bundle/repo/packages/ocaml-base-compiler/ocaml-base-compiler.4.14.0/opam
Expand Down

0 comments on commit e45a1e8

Please sign in to comment.