-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internal repos-config
new syntax
#6393
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1386,7 +1386,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.4" | ||
|
||
let default_old_root_version = OpamVersion.of_string "2.1~~previous" | ||
|
||
|
@@ -1957,13 +1957,17 @@ module InitConfig = struct | |
include SyntaxFile(InitConfigSyntax) | ||
end | ||
|
||
module Repos_configSyntax = struct | ||
module Repos_config_LegacySyntax = struct | ||
|
||
let internal = "repos-config" | ||
let format_version = OpamVersion.of_string "2.0" | ||
let file_format_version = OpamVersion.of_string "2.0" | ||
|
||
type t = (url * trust_anchors option) OpamRepositoryName.Map.t | ||
type repo = { | ||
repoc_url: url; | ||
repoc_trust: trust_anchors option; | ||
} | ||
type t = repo OpamRepositoryName.Map.t | ||
|
||
let empty = OpamRepositoryName.Map.empty | ||
|
||
|
@@ -1973,8 +1977,10 @@ module Repos_configSyntax = struct | |
((Pp.V.map_list ~depth:1 @@ | ||
InitConfigSyntax.pp_repository_def -| | ||
Pp.pp | ||
(fun ~pos:_ (name, url, ta) -> (name, (url, ta))) | ||
(fun (name, (url, ta)) -> (name, url, ta))) -| | ||
(fun ~pos:_ (name, repoc_url, repoc_trust) -> | ||
(name, {repoc_url; repoc_trust})) | ||
(fun (name, {repoc_url; repoc_trust}) -> | ||
(name, repoc_url, repoc_trust))) -| | ||
Pp.of_pair "repository-url-list" | ||
OpamRepositoryName.Map.(of_list, bindings)); | ||
] | ||
|
@@ -1991,6 +1997,122 @@ 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 | ||
|
||
module Repos_configSyntax = struct | ||
|
||
let internal = "repos-config" | ||
let format_version = OpamVersion.of_string "2.1" | ||
let file_format_version = OpamVersion.of_string "2.0" | ||
|
||
type repo = { | ||
repoc_url: url; | ||
repoc_trust: trust_anchors option; | ||
} | ||
type t = repo OpamRepositoryName.Map.t | ||
|
||
let empty = OpamRepositoryName.Map.empty | ||
|
||
let pp_repo = | ||
let empty = { repoc_url = OpamUrl.empty; repoc_trust = None } in | ||
Pp.I.fields ~name:"repos-config-repo" ~empty [ | ||
"url", Pp.ppacc | ||
(fun repoc_url t -> { t with repoc_url }) | ||
(fun { repoc_url; _ } -> repoc_url) | ||
Pp.V.url; | ||
"fingerprint", Pp.ppacc_opt | ||
(fun fingerprints t -> | ||
match t.repoc_trust with | ||
| Some x -> { t with repoc_trust = Some { x with fingerprints }} | ||
| None -> { t with repoc_trust = Some { fingerprints; quorum = 1}}) | ||
(fun t -> | ||
match t.repoc_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.repoc_trust with | ||
| Some x -> { t with repoc_trust = Some { x with quorum }} | ||
| None -> { t with repoc_trust = Some { quorum; fingerprints = []}}) | ||
(fun t -> | ||
match t.repoc_trust with | ||
| Some {quorum; _} -> Some quorum | ||
| None -> None) | ||
Pp.V.int; | ||
] | ||
|
||
let sections = | ||
Pp.map_list | ||
(Pp.I.section "repo" | ||
-| Pp.pp ~name:"repo section" | ||
(fun ~pos (name_opt, content) -> | ||
let url = "repo", (Some pos, "missing URL") in | ||
let name_repo = "repo", (Some pos, "missing repository name") in | ||
let repo, errs = Pp.parse ~pos pp_repo content in | ||
let nr, errs = | ||
match name_opt with | ||
| Some name -> | ||
Some (OpamRepositoryName.of_string name, repo), errs | ||
| None -> | ||
None, name_repo::errs | ||
in | ||
if OpamUrl.equal OpamUrl.empty repo.repoc_url then | ||
None, url::errs | ||
else nr, errs | ||
) | ||
(function | ||
| Some (name, repo), _ -> | ||
Some (OpamRepositoryName.to_string name), | ||
Pp.print pp_repo (repo, []) | ||
| None, _ -> None, [])) | ||
-| Pp.pp ~name:"repositories" | ||
(fun ~pos:_ repos -> | ||
let repos, errs = List.split repos in | ||
let repos = List.filter_map Fun.id repos in | ||
let map = OpamRepositoryName.Map.of_list repos in | ||
let errs = List.flatten errs in | ||
map, errs) | ||
(fun (map, _errs) -> | ||
OpamRepositoryName.Map.bindings map | ||
|> List.map (fun x -> Some x, [])) | ||
Comment on lines
+2076
to
+2084
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two functions can be done more efficiently in one fold each |
||
|
||
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 ~optional:true ?f ~format_version () -| | ||
Pp.I.opam_version ~format_version ~undefined:true () -| | ||
Pp.I.partition (fun i -> match i.pelem with | ||
| Section ({ section_kind={pelem="repo";_}; section_name=Some _; _ }) -> | ||
false | ||
| _ -> true) | ||
-| Pp.map_pair | ||
(* we need to keep the fields parser in order to display | ||
unknown field errors *) | ||
(let condition = | ||
(* we need to propagate the BestEffort condition value *) | ||
OpamStd.Option.map (fun cond -> fun () -> cond empty) condition | ||
in | ||
Pp.I.fields ~name ~empty:() [] | ||
-| Pp.I.show_errors ~name ?condition () | ||
-| Pp.pp (fun ~pos:_ _ -> ()) (fun () -> ()) | ||
) | ||
(sections | ||
-| Pp.I.show_errors ~name ?condition ()) | ||
-| Pp.pp (fun ~pos:_ (_, map) -> map) | ||
(fun t -> (), t) | ||
|
||
let pp = pp_cond () | ||
|
||
end | ||
|
||
module Repos_config = struct | ||
include Repos_configSyntax | ||
include SyntaxFile(Repos_configSyntax) | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -352,7 +352,7 @@ let opam_file_from_1_2_to_2_0 ?filename opam = | |||||||||||||||||
|
||||||||||||||||||
(* Global state changes that need to be propagated *) | ||||||||||||||||||
let gtc_none = { gtc_repo = false; gtc_switch = false } | ||||||||||||||||||
let _gtc_repo = { gtc_repo = true; gtc_switch = false } | ||||||||||||||||||
let gtc_repo = { gtc_repo = true; gtc_switch = false } | ||||||||||||||||||
let _gtc_switch = { gtc_repo = false; gtc_switch = true } | ||||||||||||||||||
let _gtc_both = { gtc_repo = true; gtc_switch = true } | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -770,7 +770,10 @@ let from_1_3_dev7_to_2_0_alpha ~on_the_fly:_ root conf = | |||||||||||||||||
in | ||||||||||||||||||
OpamFile.Repos_config.write (OpamPath.repos_config root) | ||||||||||||||||||
(OpamRepositoryName.Map.of_list | ||||||||||||||||||
(List.map (fun (_, r, u) -> r, (u,None)) prio_repositories)); | ||||||||||||||||||
(List.map (fun (_, repo_name, repoc_url) -> | ||||||||||||||||||
repo_name, | ||||||||||||||||||
OpamFile.Repos_config.{repoc_url; repoc_trust = None}) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably best to use the proper naming syntax instead of the local open one to avoid confusion in the future between values and fields:
Suggested change
|
||||||||||||||||||
prio_repositories)); | ||||||||||||||||||
let prio_repositories = | ||||||||||||||||||
List.stable_sort (fun (prio1, _, _) (prio2, _, _) -> prio2 - prio1) | ||||||||||||||||||
prio_repositories | ||||||||||||||||||
|
@@ -1147,6 +1150,32 @@ let v2_2 = OpamVersion.of_string "2.2" | |||||||||||||||||
|
||||||||||||||||||
let from_2_2_beta_to_2_2 ~on_the_fly:_ _ conf = conf, gtc_none | ||||||||||||||||||
|
||||||||||||||||||
let v2_3 = OpamVersion.of_string "2.3" | ||||||||||||||||||
|
||||||||||||||||||
let from_2_2_to_2_3 ~on_the_fly:_ _ conf = conf, gtc_none | ||||||||||||||||||
|
||||||||||||||||||
let v2_4 = OpamVersion.of_string "2.4" | ||||||||||||||||||
|
||||||||||||||||||
let from_2_3_to_2_4 ~on_the_fly root conf = | ||||||||||||||||||
(if on_the_fly then | ||||||||||||||||||
OpamConsole.error_and_exit `Internal_error | ||||||||||||||||||
"This 2.4 upgrade should be a hard upgrade"); | ||||||||||||||||||
let f = OpamPath.repos_config root in | ||||||||||||||||||
OpamStd.Option.iter (fun old_repoconfig -> | ||||||||||||||||||
let repos = | ||||||||||||||||||
OpamRepositoryName.Map.map (fun old_repo -> | ||||||||||||||||||
let OpamFile.Repos_config_Legacy.{repoc_url; repoc_trust} = | ||||||||||||||||||
old_repo | ||||||||||||||||||
in | ||||||||||||||||||
OpamFile.Repos_config.{repoc_url; repoc_trust}) | ||||||||||||||||||
Comment on lines
+1167
to
+1170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
old_repoconfig | ||||||||||||||||||
in | ||||||||||||||||||
OpamFile.Repos_config.write f repos) | ||||||||||||||||||
(OpamFile.Repos_config_Legacy.BestEffort.read_opt | ||||||||||||||||||
(OpamFile.make | ||||||||||||||||||
(OpamFile.filename f))); | ||||||||||||||||||
Comment on lines
+1175
to
+1176
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
conf, gtc_repo | ||||||||||||||||||
|
||||||||||||||||||
(* To add an upgrade layer | ||||||||||||||||||
* If it is a light upgrade, returns as second element if the repo or switch | ||||||||||||||||||
need an light upgrade with `gtc_*` values. | ||||||||||||||||||
|
@@ -1156,7 +1185,7 @@ let from_2_2_beta_to_2_2 ~on_the_fly:_ _ conf = conf, gtc_none | |||||||||||||||||
|
||||||||||||||||||
let latest_version = OpamFile.Config.root_version | ||||||||||||||||||
|
||||||||||||||||||
let latest_hard_upgrade = (* to *) v2_0_beta5 | ||||||||||||||||||
let latest_hard_upgrade = (* to *) v2_4 | ||||||||||||||||||
|
||||||||||||||||||
(* intermediate roots that need a hard upgrade when upgrading from them *) | ||||||||||||||||||
let v2_1_intermediate_roots = [ | ||||||||||||||||||
|
@@ -1218,9 +1247,11 @@ let as_necessary ?reinit requested_lock global_lock root config = | |||||||||||||||||
let is_2_1_intermediate_root = | ||||||||||||||||||
List.exists (OpamVersion.equal root_version) v2_1_intermediate_roots | ||||||||||||||||||
in | ||||||||||||||||||
(* As last hard upgrade is > 2.1~rc, we no more need that selection. | ||||||||||||||||||
let latest_hard_upgrade = | ||||||||||||||||||
if is_2_1_intermediate_root then v2_1_rc else latest_hard_upgrade | ||||||||||||||||||
in | ||||||||||||||||||
*) | ||||||||||||||||||
(if is_2_1_intermediate_root then [ | ||||||||||||||||||
v2_1_alpha, from_2_0_to_2_1_alpha; | ||||||||||||||||||
v2_1_alpha2, from_2_1_alpha_to_2_1_alpha2; | ||||||||||||||||||
|
@@ -1244,6 +1275,8 @@ let as_necessary ?reinit requested_lock global_lock root config = | |||||||||||||||||
v2_2_alpha, from_2_1_to_2_2_alpha; | ||||||||||||||||||
v2_2_beta, from_2_2_alpha_to_2_2_beta; | ||||||||||||||||||
v2_2, from_2_2_beta_to_2_2; | ||||||||||||||||||
v2_3, from_2_2_to_2_3; | ||||||||||||||||||
v2_4, from_2_3_to_2_4; | ||||||||||||||||||
] | ||||||||||||||||||
|> List.filter (fun (v,_) -> | ||||||||||||||||||
OpamVersion.compare root_version v < 0) | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -164,10 +164,10 @@ let load lock_kind gt = | |||||
load with best-effort (read-only)" | ||||||
(OpamVersion.to_string (OpamFile.Config.opam_root_version gt.config)) | ||||||
(OpamVersion.to_string (OpamFile.Config.root_version)); | ||||||
let mk_repo name (url, ta) = { | ||||||
let mk_repo name OpamFile.Repos_config.{repoc_url; repoc_trust} = { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
repo_name = name; | ||||||
repo_url = url; | ||||||
repo_trust = ta; | ||||||
repo_url = repoc_url; | ||||||
repo_trust = repoc_trust; | ||||||
} in | ||||||
let repositories = OpamRepositoryName.Map.mapi mk_repo repos_map in | ||||||
let repos_tmp_root = lazy (OpamFilename.mk_tmp_dir ()) in | ||||||
|
@@ -280,7 +280,9 @@ let write_config rt = | |||||
OpamFile.Repos_config.write (OpamPath.repos_config rt.repos_global.root) | ||||||
(OpamRepositoryName.Map.filter_map (fun _ r -> | ||||||
if r.repo_url = OpamUrl.empty then None | ||||||
else Some (r.repo_url, r.repo_trust)) | ||||||
else | ||||||
Some OpamFile.Repos_config.{ repoc_url = r.repo_url; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
repoc_trust = r.repo_trust}) | ||||||
rt.repositories) | ||||||
|
||||||
let check_last_update () = | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.