Skip to content

Commit

Permalink
Merge pull request #4298 from rjbou/endpos
Browse files Browse the repository at this point in the history
Update opam-format to opam-file-format new type definition
  • Loading branch information
rjbou authored Dec 1, 2020
2 parents 0f9d3c9 + 6895d21 commit 8cd1955
Show file tree
Hide file tree
Showing 32 changed files with 553 additions and 435 deletions.
2 changes: 1 addition & 1 deletion .travis-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ fi
# The SHA is fixed so that upstream changes shouldn't affect CI. The SHA needs
# to be moved forwards when a new version of OCaml is added to ensure that the
# ocaml-system package is available at the correct version.
opam init --bare default git+https://github.com/ocaml/opam-repository#$OPAM_REPO_SHA
opam init --bare default git+https://github.com/ocaml/opam-repository#$OPAM_TEST_REPO_SHA
opam switch create default ocaml-system
eval $(opam env)
opam install lwt
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ env:
global:
- OPAMBSVERSION=2.1.0-alpha2
# This should be identical to the value in appveyor.yml
- OPAM_REPO_SHA=6877131f0
- OPAM_REPO_SHA=88c17a663
- OPAM_TEST_REPO_SHA=6877131f0

jobs:
include:
Expand Down
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ environment:
CYG_MIRROR: http://mirrors.kernel.org/sourceware/cygwin/
DEP_MODE: lib-ext
# This should be identical to the value in .travis.yml
OPAM_REPO_SHA: 6877131f0
OPAM_REPO_SHA: 88c17a663
OPAM_TEST_REPO_SHA: 6877131f0
matrix:
- CYG_ROOT: cygwin
CYG_ARCH: x86
Expand Down
2 changes: 1 addition & 1 deletion appveyor_test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

opam init -y -a --compiler=ocaml.4.11.1 git+https://github.com/ocaml/opam-repository#$OPAM_REPO_SHA
opam init -y -a --compiler=ocaml.4.11.1 git+https://github.com/ocaml/opam-repository#$OPAM_TEST_REPO_SHA
eval $(opam config env)
opam install -y -v ocamlfind
3 changes: 3 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ New option/command/subcommand are prefixed with ◈.
## State
*

# Opam file format
* Update opam-format lib to opam-file-format end position and new type definition [#4298 @rjbou]

## Solver
* Fix missing conflict message when trying to remove required packages [#4362 @AltGr]
* Fix the Z3 backend for upgrades [#4393 @AltGr]
Expand Down
2 changes: 1 addition & 1 deletion opam-format.opam
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ build: [
depends: [
"ocaml" {>= "4.02.3"}
"opam-core" {= version}
"opam-file-format" {>= "2.0.0~rc2"}
"opam-file-format" {>= "2.1.1"}
"dune" {>= "1.5.0"}
]
1 change: 1 addition & 0 deletions src/client/opamAction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ let prepare_package_source st nv dir =
prepare_package_build (OpamPackageVar.resolve ~opam st) opam nv dir

let compilation_env t opam =
let open OpamParserTypes in
OpamEnv.get_full ~force_path:true t ~updates:([
"CDPATH", Eq, "", Some "shell env sanitization";
"MAKEFLAGS", Eq, "", Some "make env sanitization";
Expand Down
2 changes: 2 additions & 0 deletions src/client/opamArg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ let atom_or_dir =
parse, print

let dep_formula =
let module OpamParser = OpamParser.FullPos in
let module OpamPrinter = OpamPrinter.FullPos in
let pp = OpamFormat.V.(package_formula `Conj (constraints version)) in
let parse str =
try
Expand Down
3 changes: 2 additions & 1 deletion src/client/opamCliMain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ let check_and_run_external_commands () =
let env =
if has_init then
let updates =
["PATH", PlusEq, OpamFilename.Dir.to_string plugins_bin, None]
["PATH", OpamParserTypes.PlusEq,
OpamFilename.Dir.to_string plugins_bin, None]
in
OpamStateConfig.init ~root_dir ();
match OpamStateConfig.get_switch_opt () with
Expand Down
17 changes: 11 additions & 6 deletions src/client/opamConfigCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
let log fmt = OpamConsole.log "CONFIG" fmt
let slog = OpamConsole.slog

open OpamParserTypes.FullPos
open OpamTypes
open OpamTypesBase
open OpamStateTypes
Expand Down Expand Up @@ -371,6 +372,9 @@ let switch_doc switch =
Printf.sprintf "switch %s"
(OpamConsole.colorise `bold (OpamSwitch.to_string switch))

module OpamParser = OpamParser.FullPos
module OpamPrinter = OpamPrinter.FullPos

(* General setting option function. Takes the [field] to update, the [value]
operation, [conf] the configuration according the config file (['config
confest]). If [inner] is set, it allows the modification of [InModifiable]
Expand Down Expand Up @@ -727,10 +731,10 @@ let set_var_global gt var value =
stv_find = (fun (k,_,_) -> k = var);
stv_config = gt.config;
stv_varstr = (fun v ->
OpamPrinter.Normalise.value (List (pos_null, [
Ident (pos_null, OpamVariable.to_string var);
String (pos_null, v);
String (pos_null, "Set through 'opam var'")
OpamPrinter.Normalise.value (nullify_pos @@ List (nullify_pos @@ [
nullify_pos @@ Ident (OpamVariable.to_string var);
nullify_pos @@ String v;
nullify_pos @@ String "Set through 'opam config set-var global'"
])));
stv_set_opt = (fun config value ->
let gt =
Expand All @@ -756,8 +760,9 @@ let set_var_switch gt ?st var value =
stv_varstr = (fun v ->
OpamStd.String.remove_suffix ~suffix:"\n" @@
OpamPrinter.Normalise.items
[Variable
(pos_null, OpamVariable.to_string var, String (pos_null, v))]);
[ nullify_pos @@ Variable
(nullify_pos @@ OpamVariable.to_string var,
nullify_pos @@ String v)]);
stv_set_opt = (fun swc value ->
set_opt_switch_t ~inner:true gt switch swc "variables" value);
stv_remove_elem = (fun rest switch_config ->
Expand Down
59 changes: 30 additions & 29 deletions src/client/opamListCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
(**************************************************************************)

open OpamCompat
open OpamParserTypes.FullPos
open OpamTypes
open OpamStateTypes
open OpamStd.Op
Expand Down Expand Up @@ -176,22 +177,20 @@ let rec value_strings value =
let module SS = OpamStd.String.Set in
match value with
| Bool _ | Int _ -> SS.empty
| Ident (_, s) -> SS.singleton s
| String (_, s) -> SS.singleton s
| Relop (_, _, v1, v2)
| Logop (_, _, v1, v2)
| Env_binding (_, v1, _, v2) ->
SS.union (value_strings v1) (value_strings v2)
| Prefix_relop (_, _, v)
| Pfxop (_, _, v) ->
value_strings v
| List (_, l)
| Group (_, l) ->
List.fold_left (fun acc v -> SS.union acc (value_strings v))
SS.empty l
| Option (_, v, vl) ->
List.fold_left (fun acc v -> SS.union acc (value_strings v))
(value_strings v) vl
| Ident s -> SS.singleton s
| String s -> SS.singleton s
| Relop (_, v1, v2)
| Logop (_, v1, v2)
| Env_binding (v1, _, v2) ->
SS.union (value_strings v1.pelem) (value_strings v2.pelem)
| Prefix_relop (_, v) | Pfxop (_, v) ->
value_strings v.pelem
| List l | Group l ->
List.fold_left (fun acc v -> SS.union acc (value_strings v.pelem))
SS.empty l.pelem
| Option (v, vl) ->
List.fold_left (fun acc v -> SS.union acc (value_strings v.pelem))
(value_strings v.pelem) vl.pelem

let pattern_selector patterns =
let name_patt =
Expand Down Expand Up @@ -283,13 +282,14 @@ let apply_selector ~base st = function
let content_strings nv =
let opam = get_opam st nv in
if psel.fields = [] then
List.map (fun (_,v) -> value_strings v) (OpamFile.OPAM.to_list opam)
List.map (fun (_,v) -> value_strings v.pelem)
(OpamFile.OPAM.to_list opam)
else
try
List.map
(fun f -> match OpamFile.OPAM.print_field_as_syntax f opam with
| None -> OpamStd.String.Set.empty
| Some v -> value_strings v)
| Some v -> value_strings v.pelem)
psel.fields
with Not_found ->
OpamConsole.error_and_exit `Bad_arguments
Expand Down Expand Up @@ -326,10 +326,10 @@ let apply_selector ~base st = function
(try
let root = st.switch_global.root in
let switch =
List.find (fun sw ->
OpamFilename.remove_prefix (OpamPath.Switch.root root sw) file
<> OpamFilename.to_string file)
(OpamFile.Config.installed_switches st.switch_global.config)
List.find (fun sw ->
OpamFilename.remove_prefix (OpamPath.Switch.root root sw) file
<> OpamFilename.to_string file)
(OpamFile.Config.installed_switches st.switch_global.config)
in
let rel_name =
OpamFilename.remove_prefix (OpamPath.Switch.root root switch) file
Expand Down Expand Up @@ -483,14 +483,15 @@ let version_color st nv =
(if is_available nv then [] else [`crossed;`red])

let mini_field_printer ?(prettify=false) ?(normalise=false) =
let module OpamPrinter = OpamPrinter.FullPos in
if normalise then OpamPrinter.Normalise.value else
function
| String (_, s) when prettify -> s
| List (_, l) when prettify &&
List.for_all (function String _ -> true | _ -> false) l ->
OpamStd.List.concat_map ", " (function String (_, s) -> s | _ -> assert false) l
| List (_, l) -> OpamPrinter.value_list l
| f -> OpamPrinter.Normalise.value f
fun v -> match v.pelem with
| String s when prettify -> s
| List l when prettify &&
List.for_all (function {pelem=String _;_} -> true | _ -> false) l.pelem ->
OpamStd.List.concat_map ", " (function {pelem=String s;_} -> s | _ -> assert false) l.pelem
| List l -> OpamPrinter.value_list l
| _ -> OpamPrinter.Normalise.value v

let detail_printer ?prettify ?normalise ?(sort=false) st nv =
let open OpamStd.Option.Op in
Expand Down
1 change: 1 addition & 0 deletions src/client/opamListCommand.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

(** Functions handling the "opam list" subcommand *)

open OpamParserTypes.FullPos
open OpamTypes
open OpamStateTypes

Expand Down
Loading

0 comments on commit 8cd1955

Please sign in to comment.