Skip to content
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

Fix falsely triggered recompilation of unchanged packages #5907

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/client/opamClient.ml
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,9 @@ let update
let repo_changed =
not
(OpamRepositoryName.Map.equal
(OpamPackage.Map.equal (OpamFile.OPAM.effectively_equal))
(OpamPackage.Map.equal (OpamFile.OPAM.effectively_equal None)) (* TODO: We'd need OpamPackage.Map.equal_binding
(of type "(key -> 'a -> 'a -> bool) -> 'a t -> 'a t -> bool")
to do it effeciently to putting None for now *)
rt_before.repo_opams rt.repo_opams)
in

Expand Down
2 changes: 1 addition & 1 deletion src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@ let reinstall cli =
try
let installed = OpamPackage.Map.find nv st.installed_opams in
let upstream = OpamPackage.Map.find nv st.opams in
if not (OpamFile.OPAM.effectively_equal installed upstream) &&
if not (OpamFile.OPAM.effectively_equal (Some nv) installed upstream) &&
OpamConsole.confirm
"Metadata of %s were updated. Force-update, without performing \
the reinstallation?" (OpamPackage.to_string nv)
Expand Down
2 changes: 1 addition & 1 deletion src/client/opamPinCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ and source_pin
using the one found locally.";
Some local
| Some local, Some vers when
not OpamFile.(OPAM.effectively_equal
not OpamFile.(OPAM.effectively_equal (Some nv)
(OPAM.with_url URL.empty local)
(OPAM.with_url URL.empty vers)) ->
OpamConsole.warning
Expand Down
2 changes: 1 addition & 1 deletion src/client/opamSwitchCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ let import_t ?ask importfile t =
OpamSwitchState.find_installed_package_by_name t name
in
let installed = OpamSwitchState.opam t pkg in
if OpamFile.OPAM.effectively_equal
if OpamFile.OPAM.effectively_equal (Some pkg)
~modulo_state:true installed imported then
reinst
else OpamPackage.Set.add pkg reinst
Expand Down
10 changes: 5 additions & 5 deletions src/format/opamFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3548,7 +3548,7 @@ module OPAM = struct

(** Extra stuff for opam files *)

let effective_part ?(modulo_state=false) (t:t) =
let effective_part ?(modulo_state=false) nv (t:t) =
let t_modulo_state = if modulo_state then empty else t in
let effective_url u =
match URL.checksum u with
Expand All @@ -3560,8 +3560,8 @@ module OPAM = struct
{
opam_version = empty.opam_version;

name = t.name;
version = t.version;
name = (match t.name, nv with Some _ as x, _ -> x | None, Some nv -> Some nv.OpamPackage.name | None, None -> None);
version = (match t.version, nv with Some _ as x, _ -> x | None, Some nv -> Some nv.OpamPackage.version | None, None -> None);

depends = t_modulo_state.depends;
depopts = t_modulo_state.depopts;
Expand Down Expand Up @@ -3631,8 +3631,8 @@ module OPAM = struct
deprecated_build_doc = t.deprecated_build_doc;
}

let effectively_equal ?(modulo_state=false) o1 o2 =
effective_part ~modulo_state o1 = effective_part ~modulo_state o2
let effectively_equal ?(modulo_state=false) nv o1 o2 =
effective_part ~modulo_state nv o1 = effective_part ~modulo_state nv o2

let equal o1 o2 =
with_metadata_dir None o1 = with_metadata_dir None o2
Expand Down
4 changes: 2 additions & 2 deletions src/format/opamFile.mli
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,13 @@ module OPAM: sig
fields set to their empty values. Useful for comparisons.
@param ?modulo_state if [true], eliminates the fields relying on the state
of the switch (depends, available, …). This is [false] by default. *)
val effective_part: ?modulo_state:bool -> t -> t
val effective_part: ?modulo_state:bool -> package option -> t -> t

(** Returns true if the effective parts of the two package definitions are
equal.
@param ?modulo_state if [true], considers the fields relying on the state
of the switch (depends, available, …) equal. This is [false] by default *)
val effectively_equal: ?modulo_state:bool -> t -> t -> bool
val effectively_equal: ?modulo_state:bool -> package option -> t -> t -> bool

(** Compares two package definitions, ignoring the virtual fields bound to
file location ([metadata_dir]...) *)
Expand Down
2 changes: 1 addition & 1 deletion src/state/opamPackageVar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ let build_id st opam =
in
let opam_hash =
OpamHash.compute_from_string ~kind
(OpamFile.OPAM.write_to_string (OpamFile.OPAM.effective_part opam))
(OpamFile.OPAM.write_to_string (OpamFile.OPAM.effective_part (Some nv) opam))
in
let hash =
OpamHash.compute_from_string ~kind
Expand Down
6 changes: 3 additions & 3 deletions src/state/opamSwitchState.ml
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ let load lock_kind gt rt switch =
metadata or the archive hash changing and they don't have an archive
hash. Therefore, dev package update needs to add to the reinstall file *)
let changed =
OpamPackage.Map.merge (fun _ opam_new opam_installed ->
OpamPackage.Map.merge (fun nv opam_new opam_installed ->
match opam_new, opam_installed with
| Some r, Some i when not (OpamFile.OPAM.effectively_equal ~modulo_state:true i r) ->
| Some r, Some i when not (OpamFile.OPAM.effectively_equal ~modulo_state:true (Some nv) i r) ->
Some ()
| _ -> None)
opams installed_opams
Expand Down Expand Up @@ -1215,7 +1215,7 @@ let update_package_metadata nv opam st =
reinstall = lazy
(match OpamPackage.Map.find_opt nv st.installed_opams with
| Some inst ->
if OpamFile.OPAM.effectively_equal inst opam
if OpamFile.OPAM.effectively_equal (Some nv) inst opam
then OpamPackage.Set.remove nv (Lazy.force st.reinstall)
else OpamPackage.Set.add nv (Lazy.force st.reinstall)
| _ -> Lazy.force st.reinstall);
Expand Down
2 changes: 1 addition & 1 deletion src/state/opamUpdate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ let pinned_package st ?version ?(autolock=false) ?(working_dir=false) name =
o |> OpamFile.OPAM.with_url_opt None
|> OpamFile.OPAM.with_version v
in
OpamFile.OPAM.effectively_equal
OpamFile.OPAM.effectively_equal (Some nv)
(cleanup_opam (OpamFormatUpgrade.opam_file a))
(cleanup_opam (OpamFormatUpgrade.opam_file b))
in
Expand Down