Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ users)
## External dependencies

## Format upgrade
* Fix switch and repo format upgrade on Windows. A block occurred because the global lock fd was reopened instead of using the one already opened. [#6839 @rjbou]

## Sandbox
* Allow the macOS sandbox to write in the `/var/folders/` and `/var/db/mds/` directories as it is required by some of macOS core tools [#4797 @kit-ty-kate - fix #4389 #6460]
Expand Down Expand Up @@ -164,6 +165,7 @@ users)
* `OpamRepositoryState.load_opams_from_diff` track added packages to avoid removing version-equivalent packages [#6774 @arozovyk fix #6754]
* `OpamGlobalState.all_installed_versions`: was added [#6818 @dra27]
* `OpamGlobalState.installed_versions`: was removed [#6818 @dra27]
* `OpamStateTypes.global_state`: add field `lock` that contains the global lock (not config one) [#6839 @rjbou]

## opam-solver

Expand Down
1 change: 1 addition & 0 deletions src/client/opamAdminCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,7 @@ let get_virtual_switch_state repo_root env =
in
let gt = {
global_lock = OpamSystem.lock_none;
lock = OpamSystem.lock_none;
root = OpamStateConfig.(!r.root_dir);
config = OpamStd.Option.Op.(OpamStateConfig.(
load ~lock_kind:`Lock_read !r.root_dir) +!
Expand Down
18 changes: 13 additions & 5 deletions src/client/opamClient.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1849,9 +1849,15 @@ let init
OpamStd.Sys.exit_because `Aborted);
try
(* Create the content of ~/.opam/config *)
let repos = match repo with
| Some r -> [r.repo_name, (r.repo_url, r.repo_trust)]
| None -> OpamFile.InitConfig.repositories init_config
let repos =
match repo with
| Some r ->
[r.repo_name,
OpamFile.Repo_config.create ?trust:r.repo_trust r.repo_url]
| None ->
List.map (fun (n,(u,t)) ->
n, OpamFile.Repo_config.create ?trust:t u)
(OpamFile.InitConfig.repositories init_config)
in
let config =
update_with_init_config
Expand All @@ -1862,7 +1868,7 @@ let init
let config, mechanism, system_packages, msys2_check_root =
if Sys.win32 then
determine_windows_configuration ?cygwin_setup ?git_location
~bypass_checks ~interactive config
~bypass_checks ~interactive config
else
config, None, [], None
in
Expand Down Expand Up @@ -1899,7 +1905,9 @@ let init
else config
in
OpamFile.Config.write config_f config;
let repos_config = OpamRepositoryName.Map.of_list repos in
let repos_config =
OpamFile.Repos_config.create (OpamRepositoryName.Map.of_list repos)
in
OpamFile.Repos_config.write (OpamPath.repos_config root)
repos_config;

Expand Down
5 changes: 4 additions & 1 deletion src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2565,6 +2565,7 @@ let repository cli =
OpamGlobalState.with_ `Lock_none @@ fun gt ->
let repos =
OpamStateConfig.Repos.safe_read ~lock_kind:`Lock_read gt
|> OpamFile.Repos_config.repos
in
let not_found =
List.filter (fun r -> not (OpamRepositoryName.Map.mem r repos)) names
Expand Down Expand Up @@ -4330,6 +4331,7 @@ let clean cli =
@@ fun _lock ->
let repos_config =
OpamStateConfig.Repos.safe_read ~lock_kind:`Lock_write gt
|> OpamFile.Repos_config.repos
in
let all_repos =
OpamRepositoryName.Map.keys repos_config |>
Expand Down Expand Up @@ -4368,7 +4370,8 @@ let clean cli =
OpamConsole.msg "Updating %s\n"
(OpamFile.to_string (OpamPath.repos_config root));
if not dry_run then
OpamFile.Repos_config.write (OpamPath.repos_config root) repos_config);
OpamFile.Repos_config.write (OpamPath.repos_config root)
(OpamFile.Repos_config.create repos_config));
if repo_cache then
(OpamConsole.msg "Clearing repository cache\n";
if not dry_run then OpamRepositoryState.Cache.remove ());
Expand Down
145 changes: 143 additions & 2 deletions src/format/opamFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ module ConfigSyntax = struct
let internal = "config"
let format_version = OpamVersion.of_string "2.1"
let file_format_version = OpamVersion.of_string "2.0"
let root_version = OpamVersion.of_string "2.2"
let root_version = OpamVersion.of_string "2.6~alpha1"

let default_old_root_version = OpamVersion.of_string "2.1~~previous"

Expand Down Expand Up @@ -1966,7 +1966,9 @@ module InitConfig = struct
include SyntaxFile(InitConfigSyntax)
end

module Repos_configSyntax = struct
(** Repositories configuration *)

module Repos_config_LegacySyntax = struct

let internal = "repos-config"
let format_version = OpamVersion.of_string "2.0"
Expand Down Expand Up @@ -2000,6 +2002,145 @@ module Repos_configSyntax = struct
let pp = pp_cond ()

end

module Repos_config_Legacy = struct
include Repos_config_LegacySyntax
include SyntaxFile(Repos_config_LegacySyntax)
module BestEffort = MakeBestEffort(Repos_config_LegacySyntax)
end

(* A repository configuration section "repo" in <repos/reposèconfig> file *)

module Repo_configSyntax = struct
let internal = "repo-config"
let format_version = OpamVersion.of_string "2.6"

type t = {
url: url;
trust: trust_anchors option;
errors: (string * Pp.bad_format) list;
}

let empty = {
url = OpamUrl.empty;
trust = None;
Comment thread
rjbou marked this conversation as resolved.
errors = [];
}

let create ?trust url = { url; trust; errors = [] }

let url t = t.url
let trust t = t.trust

let fields = [
"url", Pp.ppacc
(fun url t -> { t with url })
(fun { url; _ } -> url)
Pp.V.url;
"fingerprint", Pp.ppacc_opt
(fun fingerprints t ->
match t.trust with
| Some x -> { t with trust = Some { x with fingerprints }}
| None -> { t with trust = Some { fingerprints; quorum = 1}})
(fun t ->
match t.trust with
| Some {fingerprints; _} -> Some fingerprints
| None -> None)
(Pp.V.map_list ~depth:1 Pp.V.string);
"quorum",
Pp.ppacc_opt
(fun quorum t ->
match t.trust with
| Some x -> { t with trust = Some { x with quorum }}
| None -> { t with trust = Some { quorum; fingerprints = []}})
(fun t ->
match t.trust with
| Some {quorum; _} -> Some quorum
| None -> None)
Pp.V.int;
]

let pp_contents : (opamfile_item list, t) OpamPp.t =
let name = internal in
Pp.I.fields ~name ~empty fields
-| Pp.I.on_errors ~name (fun t e -> {t with errors = e::t.errors})
-| Pp.pp ~name
(fun ~pos t ->
if t.url = OpamUrl.empty then
OpamPp.bad_format ~pos "missing URL in repo field"
else t)
(fun x -> x)

let pp = Pp.I.map_file pp_contents

end

module Repo_config = struct
include Repo_configSyntax
include SyntaxFile(Repo_configSyntax)
end

(* Repositories configuration <repos/repos-config> *)

module Repos_configSyntax = struct

let internal = "repos-config"
let format_version = OpamVersion.of_string "2.6"
let file_format_version = OpamVersion.of_string "2.0"

type repo = Repo_config.t
type t = {
opam_version: opam_version;
repos : repo OpamRepositoryName.Map.t;
}

let empty = {
opam_version = file_format_version;
repos = OpamRepositoryName.Map.empty;
}

let create ?opam_version repos = {
opam_version = OpamStd.Option.default file_format_version opam_version;
repos;
}

let opam_version t = t.opam_version
let repos t = t.repos
let with_opam_version opam_version t = { t with opam_version }
let with_repos repos t = { t with repos }

let fields = [
"opam-version", Pp.ppacc with_opam_version opam_version

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't opam-version kept at 2.0 but a new field be added similar to opam-root-version in /config?

(Pp.V.string -| Pp.of_module "opam-version" (module OpamVersion));
]

let sections = [
"repo", Pp.ppacc with_repos repos
((Pp.map_list
(Pp.map_pair
(Pp.pp
(fun ~pos -> function
| Some o -> OpamRepositoryName.of_string o
| None -> Pp.bad_format ~pos "missing repo name")
(fun b -> Some (OpamRepositoryName.to_string b)))
Repo_config.pp_contents))
-| Pp.of_pair "RepositoryNameMap"
OpamRepositoryName.Map.(of_list, bindings))
]

let pp_cond ?f ?condition () =
let name = internal in
let format_version = file_format_version in
Pp.I.map_file @@
Pp.I.check_opam_version ?f ~format_version ()
-| Pp.I.opam_version ~format_version ()
-| Pp.I.fields ~name ~empty ~sections fields
-| Pp.I.show_errors ~name ?condition ()

let pp = pp_cond ()

end

module Repos_config = struct
include Repos_configSyntax
include SyntaxFile(Repos_configSyntax)
Expand Down
33 changes: 32 additions & 1 deletion src/format/opamFile.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1067,12 +1067,43 @@ module Repo_config_legacy : sig
include IO_FILE with type t := t
end

module Repos_config: sig
module Repos_config_Legacy: sig
type t = (url * trust_anchors option) OpamRepositoryName.Map.t
include IO_FILE with type t := t
module BestEffort: BestEffortRead with type t := t
end

module Repo_config: sig
type t = {
url: url;
trust: trust_anchors option;
errors: (string * OpamPp.bad_format) list;
}

val create: ?trust:trust_anchors -> url -> t

val url: t -> url
val trust: t -> trust_anchors option

include IO_FILE with type t := t
end

module Repos_config: sig
type repo = Repo_config.t
type t = {
opam_version: opam_version;
repos : repo OpamTypes.repository_name_map;
}

val create:
?opam_version:opam_version -> repo OpamTypes.repository_name_map -> t

val repos: t -> repo OpamTypes.repository_name_map

include IO_FILE with type t := t
module BestEffort: BestEffortRead with type t := t
end

module Switch_config: sig
type t = {
opam_version: OpamVersion.t;
Expand Down
Loading