-
Notifications
You must be signed in to change notification settings - Fork 466
Write commit hashes into the lock dir when locking git repositories #13297
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
Changes from 5 commits
e88c32a
c11c876
0be3f8b
0eaf154
0ad8afd
b0acf2d
ac84807
2421d90
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 |
|---|---|---|
|
|
@@ -1661,6 +1661,60 @@ let package_kind = | |
| else `Non_compiler | ||
| ;; | ||
|
|
||
| let resolve_url (file_url : OpamFile.URL.t) = | ||
| let url = OpamFile.URL.url file_url in | ||
| let+ url : OpamUrl.t = | ||
| match url.backend with | ||
| | `git -> | ||
| let loc = Loc.none in | ||
| let+ mount = Mount.of_opam_url loc url in | ||
| (match Mount.backend mount with | ||
| | Path path -> | ||
| Code_error.raise | ||
| "Attempted to resolve git URL but loading it resolved to a local path" | ||
| [ "url", OpamUrl.to_dyn url; "path", Path.to_dyn path ] | ||
| | Git at_rev -> | ||
| let resolved_hash = at_rev |> Rev_store.At_rev.rev |> Rev_store.Object.to_hex in | ||
| (match !Dune_engine.Clflags.display, url.hash with | ||
| | Short, Some old_hash -> | ||
| (match String.equal resolved_hash old_hash with | ||
| | true -> () | ||
| | false -> | ||
| User_warning.emit | ||
| [ Pp.textf | ||
| "Locking repository URL %s to commit %s" | ||
| (OpamUrl.to_string url) | ||
| resolved_hash | ||
| ]) | ||
| | _ -> ()); | ||
| { url with hash = Some resolved_hash }) | ||
| | _ -> Fiber.return url | ||
| in | ||
| OpamFile.URL.with_url url file_url | ||
| ;; | ||
|
|
||
| let resolve_opam_packages opam_packages_to_lock ~resolve_package = | ||
| opam_packages_to_lock | ||
| |> List.map ~f:(fun opam_package -> | ||
| let name = OpamPackage.name opam_package |> Package_name.of_opam_package_name in | ||
| let version = OpamPackage.version opam_package in | ||
| let resolved_package = resolve_package name version in | ||
| (* resolve URLs *) | ||
| let+ resolved_package = | ||
| let opam_file = Resolved_package.opam_file resolved_package in | ||
| let+ opam_file = | ||
| match OpamFile.OPAM.url opam_file with | ||
| | None -> Fiber.return opam_file | ||
| | Some url -> | ||
| let+ url = resolve_url url in | ||
| OpamFile.OPAM.with_url url opam_file | ||
| in | ||
| Resolved_package.with_opam_file opam_file resolved_package | ||
| in | ||
| name, opam_package, resolved_package) | ||
| |> Fiber.all | ||
| ;; | ||
|
|
||
| let solve_lock_dir | ||
| solver_env | ||
| version_preference | ||
|
|
@@ -1738,8 +1792,7 @@ let solve_lock_dir | |
| (Table.find_exn candidates_cache name).resolved | ||
| |> OpamPackage.Version.Map.find version | ||
| in | ||
| let pkgs_by_name = | ||
| let open Result.O in | ||
| let* pkgs_by_name = | ||
| let+ pkgs = | ||
| let version_by_package_name = | ||
| Package_name.Map.of_list_map_exn | ||
|
|
@@ -1748,13 +1801,10 @@ let solve_lock_dir | |
| ( Package_name.of_opam_package_name (OpamPackage.name package) | ||
| , Package_version.of_opam_package_version (OpamPackage.version package) )) | ||
| in | ||
| List.map opam_packages_to_lock ~f:(fun opam_package -> | ||
| let name = | ||
| OpamPackage.name opam_package |> Package_name.of_opam_package_name | ||
| in | ||
| let resolved_package = | ||
| resolve_package name (OpamPackage.version opam_package) | ||
| in | ||
| let+ resolved_pkgs = | ||
| resolve_opam_packages opam_packages_to_lock ~resolve_package | ||
|
||
| in | ||
| List.map resolved_pkgs ~f:(fun (name, opam_package, resolved_package) -> | ||
| Lock_pkg.opam_package_to_lock_file_pkg | ||
| solver_env | ||
| stats_updater | ||
|
|
@@ -1765,22 +1815,23 @@ let solve_lock_dir | |
| ~portable_lock_dir) | ||
| |> Result.List.all | ||
| in | ||
| match Package_name.Map.of_list_map pkgs ~f:(fun pkg -> pkg.info.name, pkg) with | ||
| | Error (name, _pkg1, _pkg2) -> | ||
| Code_error.raise | ||
| "Solver selected multiple versions for the same package" | ||
| [ "name", Package_name.to_dyn name ] | ||
| | Ok pkgs_by_name -> | ||
| let reachable = | ||
| reject_unreachable_packages | ||
| solver_env | ||
| ~dune_version: | ||
| (Package_version.of_opam_package_version context.dune_version) | ||
| ~local_packages | ||
| ~pkgs_by_name | ||
| in | ||
| Package_name.Map.filteri pkgs_by_name ~f:(fun name _ -> | ||
| Package_name.Set.mem reachable name) | ||
| Result.map pkgs ~f:(fun pkgs -> | ||
| match Package_name.Map.of_list_map pkgs ~f:(fun pkg -> pkg.info.name, pkg) with | ||
| | Error (name, _pkg1, _pkg2) -> | ||
| Code_error.raise | ||
| "Solver selected multiple versions for the same package" | ||
| [ "name", Package_name.to_dyn name ] | ||
| | Ok pkgs_by_name -> | ||
| let reachable = | ||
| reject_unreachable_packages | ||
| solver_env | ||
| ~dune_version: | ||
| (Package_version.of_opam_package_version context.dune_version) | ||
| ~local_packages | ||
| ~pkgs_by_name | ||
| in | ||
| Package_name.Map.filteri pkgs_by_name ~f:(fun name _ -> | ||
| Package_name.Set.mem reachable name)) | ||
| in | ||
| let ocaml = | ||
| let open Result.O in | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #!/bin/bash | ||
|
|
||
| # dummy implementation of just enough git to be able to create a lock file | ||
|
Member
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. A bit surprised that you need this. Isn't it possible to use a remote that is on the local file system? Or does that not test everything?
Collaborator
Author
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. The
I've created #13333 to discuss this issue and it seemed to me that fitting in a fake
Member
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. Okay, so the tests are using the real git binary for git+file then?
Collaborator
Author
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. Yes, it is only used in the The |
||
|
|
||
| # we need access to the real git binary, so we expect the env to have a | ||
| # REAL_GIT variable pointing to the actual git | ||
| REAL_GIT=${REAL_GIT:-false} | ||
|
|
||
| case $1 in | ||
| init) | ||
| # we pass this over to actual git | ||
| $REAL_GIT "$@" | ||
| exit $? | ||
| ;; | ||
| ls-remote) | ||
| # hardcoded output, just HEAD pointing to a revision | ||
| echo "058003b274f05b092a391555ffdee8b36f1897b3 HEAD" | ||
| ;; | ||
| fetch) | ||
| # we don't fetch from anywhere | ||
| exit 0 | ||
| ;; | ||
| ls-tree) | ||
| # the revision that HEAD is pointing to, just a single empty file | ||
| echo "100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 empty" | ||
| exit 0 | ||
| ;; | ||
| cat-file) | ||
| IFS=':' read -r -a rev_and_path <<< "$3" | ||
| if [[ -z ${rev_and_path[1]} ]]; then | ||
| echo "" | ||
| exit 0 | ||
| fi | ||
| if [ "${rev_and_path[1]}" = ".gitmodules" ]; then | ||
| echo "does not exist" >&2 | ||
| exit 128 | ||
| fi | ||
| echo "Unsupported cat-file command: $@" >&2 | ||
| exit 2 | ||
| ;; | ||
| rev-parse) | ||
| # let git answer this one | ||
| if [ "$2" = "--is-bare-repository" ]; then | ||
| $REAL_GIT "$@" | ||
| exit $? | ||
| fi | ||
| echo "Unsupported rev-parse command: $@" >&2 | ||
| exit 2 | ||
| ;; | ||
| *) | ||
| # unsupported, exit out | ||
| echo "Unsupported command: $@" >&2 | ||
| exit 2 | ||
| ;; | ||
| esac | ||
Uh oh!
There was an error while loading. Please reload this page.