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

Switch state sometimes needs to be imported twice to take effect. #5173

Closed
ylecornec opened this issue Jul 4, 2022 · 1 comment · Fixed by #5181
Closed

Switch state sometimes needs to be imported twice to take effect. #5173

ylecornec opened this issue Jul 4, 2022 · 1 comment · Fixed by #5181

Comments

@ylecornec
Copy link

Hi, we encountered the following behavior which seems a bit surprising.

After modifying the commit of a pinned dependency in the switch state file, opam switch import has to be called twice in row for the change to take effect.

How to reproduce

This repro uses the dune package as an example but this is not specific to dune.

opam switch create repro_import_twice 4.14.0
opam pin add dune https://github.com/ocaml/dune.git\#5fadbb4873569eb8f26ee3eec5ffe78496ff0a11
opam switch export /tmp/opam.export

# modify commit for dune in the opam.export file
sed -i 's/5fadbb4873569eb8f26ee3eec5ffe78496ff0a11/a5469ae3b7d4b6a8cfd3b7f87c9ce8c75c8f4378/' /tmp/opam.export

# first import outputs "Nothing to do."
opam switch import /tmp/opam.export

# Second import updates dune
opam switch import /tmp/opam.export

# cleanup repro switch
opam switch remove repro_import_twice

opam config report

# opam config report
# opam-version         2.1.2 
# self-upgrade         no
# system               arch=x86_64 os=linux os-distribution=arch os-version=rolling
# solver               builtin-mccs+glpk
# install-criteria     -removed,-count[avoid-version,changed],-count[version-lag,request],-count[version-lag,changed],-count[missing-depexts,changed],-changed
# upgrade-criteria     -removed,-count[avoid-version,changed],-count[version-lag,solution],-count[missing-depexts,changed],-new
# jobs                 7
# repositories         1 (http), 2 (version-controlled) (default repo at 97da9a1b)
# pinned               1 (git)
# current-switch       repro_import_twice
# ocaml:native         true
# ocaml:native-tools   true
# ocaml:native-dynlink true
# ocaml:stubsdir       /home/stan/.opam/repro_import_twice/lib/ocaml/stublibs:/home/stan/.opam/repro_import_twice/lib/ocaml
# ocaml:preinstalled   false
# ocaml:compiler       4.14.0

@kit-ty-kate
Copy link
Member

I was able to reproduce the bug on master and did a diff between before the first import and after to see what has changed in the switch and got:

diff -ru /tmp/a/.opam-switch/overlay/dune/opam /tmp/b/.opam-switch/overlay/dune/opam
--- /tmp/a/.opam-switch/overlay/dune/opam	2022-07-04 17:44:03.000000000 +0100
+++ /tmp/b/.opam-switch/overlay/dune/opam	2022-07-04 17:44:09.000000000 +0100
@@ -1,8 +1,8 @@
-# This file is generated by dune, edit dune-project instead
 opam-version: "2.0"
+name: "dune"
+version: "3.3.1"
 synopsis: "Fast, portable, and opinionated build system"
-description: """
-
+description: """\
 dune is a build system that was designed to simplify the release of
 Jane Street packages. It reads metadata from "dune" files following a
 very simple s-expression syntax.
@@ -18,14 +18,18 @@
 It also supports multi-context builds, such as building against
 several opam roots/switches simultaneously. This helps maintaining
 packages across several versions of OCaml and gives cross-compilation
-for free.
-"""
-maintainer: ["Jane Street Group, LLC <[email protected]>"]
-authors: ["Jane Street Group, LLC <[email protected]>"]
+for free."""
+maintainer: "Jane Street Group, LLC <[email protected]>"
+authors: "Jane Street Group, LLC <[email protected]>"
 license: "MIT"
 homepage: "https://github.com/ocaml/dune"
 doc: "https://dune.readthedocs.io/"
 bug-reports: "https://github.com/ocaml/dune/issues"
+depends: [
+  ("ocaml" {>= "4.08"} | ("ocaml" {< "4.08~~"} & "ocamlfind-secondary"))
+  "base-unix"
+  "base-threads"
+]
 conflicts: [
   "merlin" {< "3.4.0"}
   "ocaml-lsp-server" {< "1.3.0"}
@@ -35,21 +39,21 @@
   "js_of_ocaml-compiler" {< "3.6.0"}
   "jbuilder" {= "transition"}
 ]
-dev-repo: "git+https://github.com/ocaml/dune.git"
 build: [
   ["ocaml" "bootstrap.ml" "-j" jobs]
-  ["./dune.exe" "build" "dune.install" "--release" "--profile" "dune-bootstrap" "-j" jobs]
+  [
+    "./dune.exe"
+    "build"
+    "dune.install"
+    "--release"
+    "--profile"
+    "dune-bootstrap"
+    "-j"
+    jobs
+  ]
 ]
-depends: [
-  # Please keep the lower bound in sync with .github/workflows/workflow.yml,
-  # dune-project and min_ocaml_version in bootstrap.ml
-  ("ocaml" {>= "4.08"} | ("ocaml" {< "4.08~~"} & "ocamlfind-secondary"))
-  "base-unix"
-  "base-threads"
-]
-name: "dune"
-version: "3.3.1"
+dev-repo: "git+https://github.com/ocaml/dune.git"
 url {
   src:
-    "git+https://github.com/ocaml/dune.git#5fadbb4873569eb8f26ee3eec5ffe78496ff0a11"
+    "git+https://github.com/ocaml/dune.git#a5469ae3b7d4b6a8cfd3b7f87c9ce8c75c8f4378"
 }

So the first import modifies ${SWITCH}/.opam-switch/overlay/dune/opam but does not detect the change somehow and the second finally detects it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants