Skip to content
Draft
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
17 changes: 15 additions & 2 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ moved, etc.), please update the _API updates_ part (it helps opam library
users)

## Version
*
* Upgrade root version to 2.2~alpha [#4926 @rjbou]

## Global CLI
* Fix typo in error message for opam var [#4786 @kit-ty-kate - fix #4785]
Expand Down Expand Up @@ -154,6 +154,7 @@ users)
* Add `with-tools` variable for recommended tools [#5016 @rjbou]
* Add `x-locked` extension fields for overlay internal use, it stores if the files originate from a locked file, if so its extension [#5080 @rjbou]
* Set `depext-bypass` parsing with depth 1, no needed brakcet if single package [#5154 @rjbou]
* `repo-config"`: add an optional field for repository initialisation state [#4933 @rjbou]

## External dependencies
* Set `DEBIAN_FRONTEND=noninteractive` for unsafe-yes confirmation level [#4735 @dra27 - partially fix #4731] [2.1.0~rc2 #4739]
Expand All @@ -179,6 +180,7 @@ users)
* Set opam root version to 2.1 [#4763 @rjbou] [2.1.0~rc2 #4715]
* Fix 2.1~alpha2 to 2.1 format upgrade with reinit [#4763 @rjbou - fix #4748] [2.1.0~rc2 #4750]
* Fix bypass-check handling on reinit [#4750 @rjbou] [#4763 @rjbou] [2.1.0~rc2 #4750 #4756]
* Reorganise intermediate roots that need an uipgrade handling (for 2.1, prone to generalisation) [#4926 @rjbou]

## Sandbox
* Sync the behaviour of the macOS sandbox script with Linux's: /tmp is now ready-only [#4719 @kit-ty-kate]
Expand All @@ -187,6 +189,13 @@ users)
* Print error message if command doesn't exist [#4971 @kit-ty-kat - fix #4112]
* Resolve symlink for `ccache` directory [#5267 @rjbou - fix #5194]

## Repository
* Don't display global message when `this-switch` is given [#4899 @rjbou - fix #4889]
* Set the priority of user-set archive-mirrors higher than the repositories'.
This allows opam-repository to use the default opam.ocaml.org cache and be more resilient to changed/force-pushed or unavailable archives. [#4830 @kit-ty-kate - fixes #4411]
* [NEW] Add `--no-action` for `add` and `set-url` subcommands to permit delay the update [#XXXX rjbou - fix #4617]
* [NEW] Add `--no-action` for `add` and `set-url` subcommands to permit delay the update [#4933 rjbou - fix #4617]

## VCS
* Pass --depth=1 to git-fetch in the Git repo backend [#4442 @dra27]
* Use 4.08's unnamed functor arguments to silence warning 67 [#4775 @dra27]
Expand Down Expand Up @@ -334,7 +343,9 @@ users)
* Escape for cmdliner.1.1.1 output change [#5131 @rjbou]
* Add deprectaed flag test [#4523 @kit-ty-kate]
* Add deps-only, install formula [#4975 @AltGr]
* Update opam root version test do escape `OPAMROOTVERSION` sed, it matches generated hexa temporary directory names [#5007 @AltGr #5301 @rjbou]
* Update opam root version test:
* to escape `OPAMROOTVERSION` sed, it matches generated hexa temporary directory names [#5007 @AltGr #5301 @rjbou]
* several improvments: add repo config check, update generator [#5303 @rjbou]
* Add json output test [#5143 @rjbou]
* Add test for opam file write with format preserved bug in #4936, fixed in #4941 [#4159 @rjbou]
* Add test for switch upgrade from 2.0 root, with pinned compiler [#5176 @rjbou @kit-ty-kate]
Expand Down Expand Up @@ -517,6 +528,8 @@ users)
* `OpamFormula`: add generic `formula_to_cnf` and `formula_to_dnf`, and use them in `to_cnf` and `to_dnf` [#5171 @cannorin]
* `OpamFilter`: add `?custom` argument in `to_string` to tweak the output [#5171 @cannorin]

* `OpamFile.repos_config.t`: add an initialised state argument in map value [#4933 @rjbou]
* `OpamFormat`: add `map_options_4` [#4933 @rjbou]
## opam-core
* OpamSystem: avoid calling Unix.environment at top level [#4789 @hannesm]
* `OpamStd.ABSTRACT`: add `compare` and `equal`, that added those functions to `OpamFilename`, `OpamHash`, `OpamStd`, `OpamStd`, `OpamUrl`, and `OpamVersion` [#4918 @rjbou]
Expand Down
2 changes: 2 additions & 0 deletions src/client/opamAdminCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ let get_virtual_switch_state repo_root env =
let repo = {
repo_name = OpamRepositoryName.of_string "local";
repo_url = OpamUrl.empty;
repo_initialised = false;
repo_trust = None;
} in
let repo_file = OpamRepositoryPath.repo repo_root in
Expand All @@ -795,6 +796,7 @@ let get_virtual_switch_state repo_root env =
load ~lock_kind:`Lock_read !r.root_dir) +!
OpamFile.Config.empty);
global_variables = OpamVariable.Map.empty;
global_upgrade_status = None;
} in
let singl x = OpamRepositoryName.Map.singleton repo.repo_name x in
let repos_tmp =
Expand Down
5 changes: 3 additions & 2 deletions src/client/opamClient.ml
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,9 @@ let init
in
OpamFile.Config.write config_f config;
let repos_config =
OpamRepositoryName.Map.of_list repos |>
OpamRepositoryName.Map.map OpamStd.Option.some
List.map (fun (n, (u,t)) -> (n, (u, true, t))) repos
|> OpamRepositoryName.Map.of_list
|> OpamRepositoryName.Map.map OpamStd.Option.some
in
OpamFile.Repos_config.write (OpamPath.repos_config root)
repos_config;
Expand Down
32 changes: 19 additions & 13 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ let init cli =
let repo =
OpamStd.Option.map (fun url ->
let repo_url = OpamUrl.parse ?backend:repo_kind ~from_file:false url in
{ repo_name; repo_url; repo_trust = None })
{ repo_name; repo_url; repo_initialised = false; repo_trust = None })
repo_url
in
let gt, rt, default_compiler =
Expand Down Expand Up @@ -2215,7 +2215,13 @@ let repository cli =
otherwise be used to explicitly set the repository list at once."
Arg.(int) 1
in
let repository global_options command kind short scope rank params () =
let no_action =
mk_flag ~cli (cli_from cli2_2) ["n"; "no-action"]
"Do not automatically update when adding or changin repository url. \
You must update afterwards"
in
let repository global_options command kind short scope rank params
no_action () =
apply_global_options cli global_options;
let global = List.mem `Default scope in
let command, params, rank = match command, params, rank with
Expand Down Expand Up @@ -2288,13 +2294,14 @@ let repository cli =
in
OpamRepositoryState.with_ `Lock_write gt (fun rt ->
let rt = OpamRepositoryCommand.add rt name url trust_anchors in
let failed, rt =
OpamRepositoryCommand.update_with_auto_upgrade rt [name]
in
if failed <> [] then
(OpamRepositoryState.drop @@ OpamRepositoryCommand.remove rt name;
OpamConsole.error_and_exit `Sync_error
"Initial repository fetch failed"));
if not no_action then
let failed, rt =
OpamRepositoryCommand.update_with_auto_upgrade rt [name]
in
if failed <> [] then
(OpamRepositoryState.drop @@ OpamRepositoryCommand.remove rt name;
OpamConsole.error_and_exit `Sync_error
"Initial repository fetch failed"));
OpamGlobalState.drop @@ OpamRepositoryCommand.update_selection gt ~global
~switches (update_repos name);
if scope = [`Current_switch] then
Expand Down Expand Up @@ -2359,9 +2366,8 @@ let repository cli =
OpamGlobalState.with_ `Lock_none @@ fun gt ->
OpamRepositoryState.with_ `Lock_write gt @@ fun rt ->
let rt = OpamRepositoryCommand.set_url rt name url trust_anchors in
let _failed, _rt =
OpamRepositoryCommand.update_with_auto_upgrade rt [name]
in
if not no_action then
ignore @@ OpamRepositoryCommand.update_with_auto_upgrade rt [name];
`Ok ()
| Some `set_repos, names ->
let names = List.map OpamRepositoryName.of_string names in
Expand Down Expand Up @@ -2406,7 +2412,7 @@ let repository cli =
mk_command_ret ~cli cli_original "repository" ~doc ~man
Term.(const repository $global_options cli $command
$repo_kind_flag cli cli_original $print_short_flag cli cli_original
$scope $rank $params)
$scope $rank $params $no_action)


(* SWITCH *)
Expand Down
13 changes: 12 additions & 1 deletion src/client/opamRepositoryCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let add rt name url trust_anchors =
(OpamRepositoryName.to_string name)
(OpamUrl.to_string url)
| None ->
let repo = { repo_name = name; repo_url = url;
let repo = { repo_name = name; repo_url = url; repo_initialised = false;
repo_trust = trust_anchors; }
in
if OpamFilename.exists_dir (OpamRepositoryPath.root root name) ||
Expand Down Expand Up @@ -224,6 +224,17 @@ let update_with_auto_upgrade rt repo_names =
let repos = List.map (OpamRepositoryState.get_repo rt) repo_names in
let failed, rt = OpamUpdate.repositories rt repos in
let failed = List.map (fun r -> r.repo_name) failed in
let rt = {
rt with
repositories =
(OpamRepositoryName.Map.mapi (fun name repo ->
{ repo with
repo_initialised =
List.for_all (fun n ->
not (OpamRepositoryName.equal name n)) failed })
rt.repositories)
} in
OpamRepositoryState.write_config rt;
if OpamFormatConfig.(!r.skip_version_checks) ||
OpamClientConfig.(!r.no_auto_upgrade)
then
Expand Down
14 changes: 8 additions & 6 deletions src/core/opamFilename.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@ let touch t =
let chmod t p =
Unix.chmod (to_string t) p

let written_since file =
let last_update =
(Unix.stat (to_string file)).Unix.st_mtime
in
(Unix.time () -. last_update)

let of_string s =
let dirname = Filename.dirname s in
let basename = Filename.basename s in
Expand Down Expand Up @@ -227,6 +221,14 @@ let opt_file filename =
let with_contents fn filename =
fn (read filename)

let written_since file =
if exists file then
let last_update =
(Unix.stat (to_string file)).Unix.st_mtime
in
(Unix.time () -. last_update)
else -1.

let check_suffix filename s =
Filename.check_suffix (to_string filename) s

Expand Down
35 changes: 27 additions & 8 deletions src/format/opamFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,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.1"
let root_version = OpamVersion.of_string "2.2~alpha"

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

Expand Down Expand Up @@ -1751,25 +1751,44 @@ end
module Repos_configSyntax = struct

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

type t = ((url * trust_anchors option) option) OpamRepositoryName.Map.t
type t = ((url * bool * trust_anchors option) option) OpamRepositoryName.Map.t

let empty = OpamRepositoryName.Map.empty

let pp_repository_def =
Pp.V.map_options_4
(Pp.V.string -|
Pp.of_module "repository" (module OpamRepositoryName))
(Pp.opt @@ Pp.singleton -| Pp.V.url)
(Pp.opt @@ Pp.singleton -| Pp.V.bool)
(Pp.map_list Pp.V.string)
(Pp.opt @@
Pp.singleton -| Pp.V.int -|
OpamPp.check ~name:"quorum" ~errmsg:"quorum must be >= 0" ((<=) 0)) -|
Pp.pp
(fun ~pos:_ (name, url, initialised, fingerprints, quorum) ->
name, url, not (initialised = Some false),
match fingerprints with [] -> None | fingerprints ->
Some {fingerprints; quorum = OpamStd.Option.default 1 quorum})
(fun (name, url, initialised, ta) -> match ta with
| Some ta -> name, url, Some initialised, ta.fingerprints, Some ta.quorum
| None -> name, url, Some initialised, [], None)

let fields = [
"repositories",
Pp.ppacc (fun x _ -> x) (fun x -> x)
((Pp.V.map_list ~depth:1 @@
InitConfigSyntax.pp_repository_def -|
pp_repository_def -|
Pp.pp
(fun ~pos:_ -> function
| (name, Some url, ta) -> name, Some (url, ta)
| (name, None, _) -> name, None)
| (name, Some url, init, ta) -> name, Some (url, init, ta)
| (name, None, _, _) -> name, None)
(fun (name, def) -> match def with
| Some (url, ta) -> name, Some url, ta
| None -> name, None, None)) -|
| Some (url, init, ta) -> name, Some url, init, ta
| None -> name, None, false, None)) -|
Pp.of_pair "repository-url-list"
OpamRepositoryName.Map.(of_list, bindings));
]
Expand Down
2 changes: 1 addition & 1 deletion src/format/opamFile.mli
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ module Repo_config_legacy : sig
end

module Repos_config: sig
type t = (url * trust_anchors option) option OpamRepositoryName.Map.t
type t = (url * bool * trust_anchors option) option OpamRepositoryName.Map.t
include IO_FILE with type t := t
module BestEffort: BestEffortRead with type t := t
end
Expand Down
13 changes: 13 additions & 0 deletions src/format/opamFormat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ module V = struct
pp4 -|
pp (fun ~pos:_ (((a,b),c),d) -> a,b,c,d) (fun (a,b,c,d) -> ((a,b),c),d)

let map_options_4 pp1 pp2 pp3 pp4 pp5 =
option_depth 4 -|
option_strict -| map_option_contents
(option_strict -| map_option_contents
(option_strict -| map_option_contents
(option_strict -| map_option_contents
pp1 pp2)
pp3)
pp4)
pp5 -|
pp (fun ~pos:_ ((((a,b),c),d), e) -> a,b,c,d,e)
(fun (a,b,c,d,e) -> (((a,b),c),d),e)

let map_pair pp1 pp2 =
pp ~name:(Printf.sprintf "[%s %s]" pp1.ppname pp2.ppname)
(fun ~pos:_ v -> match v.pelem with
Expand Down
6 changes: 6 additions & 0 deletions src/format/opamFormat.mli
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ module V : sig
(value list, 'b) t -> (value list, 'c) t -> (value list, 'd) t ->
(value, 'a * 'b * 'c * 'd) t

(** Maps over four options (e.g. [v {op1} {op2} {op3} {op4}]) *)
val map_options_4 :
(value, 'a) t -> (value list, 'b) t -> (value list, 'c) t ->
(value list, 'd) t -> (value list, 'e) t ->
(value, 'a * 'b * 'c * 'd * 'e) t

(** A pair is simply a list with two elements in the [value] type *)
val map_pair :
(value, 'a) t ->
Expand Down
1 change: 1 addition & 0 deletions src/format/opamTypes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ type repository = {
repo_name : repository_name;
repo_url : url;
repo_trust : trust_anchors option;
repo_initialised: bool;
}

(** {2 Variable-based filters} *)
Expand Down
Loading