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
Conservative lockfile generation #7732
Merged
rgrinberg
merged 2 commits into
ocaml:main
from
gridbugs:conservative-lockfile-generation
May 24, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
open Stdune | ||
open Import | ||
module Lock_dir = Dune_pkg.Lock_dir | ||
|
||
module Lock = struct | ||
module Repo = struct | ||
open Dune_pkg.Opam.Repo | ||
|
||
let term = | ||
let+ opam_repository_path = | ||
Arg.( | ||
required | ||
& opt (some string) None | ||
& info [ "opam-repository-path" ] ~docv:"PATH" | ||
~doc: | ||
"Path to a local opam repository. This should be a directory \ | ||
containing a valid opam repository such as the one at \ | ||
https://github.com/ocaml/opam-repository.") | ||
in | ||
of_opam_repo_dir_path opam_repository_path | ||
end | ||
|
||
module Env = struct | ||
module Source = struct | ||
type t = | ||
| Global | ||
| Pure | ||
|
||
let to_string = function | ||
| Global -> "global" | ||
| Pure -> "pure" | ||
|
||
let default = Global | ||
|
||
let term = | ||
let all = [ Global; Pure ] in | ||
let all_with_strings = List.map all ~f:(fun t -> (to_string t, t)) in | ||
let all_strings = List.map all_with_strings ~f:fst in | ||
let doc = | ||
sprintf | ||
"How to initialize the opam environment. Possible values are %s. \ | ||
'%s' will use the environment associated with the current opam \ | ||
switch. '%s' will use an empty environment. The default is '%s'." | ||
(String.enumerate_and all_strings) | ||
(to_string Global) (to_string Pure) (to_string default) | ||
in | ||
Arg.( | ||
value | ||
& opt (some (enum all_with_strings)) None | ||
& info [ "opam-env" ] ~doc) | ||
end | ||
|
||
open Dune_pkg.Opam.Env | ||
|
||
let term = | ||
let+ source = Source.term in | ||
match Option.value source ~default:Source.default with | ||
| Global -> global () | ||
| Pure -> empty | ||
end | ||
|
||
(* Converts the package table found inside a [Dune_project.t] into the | ||
package table expected by the dependency solver *) | ||
let opam_file_map_of_dune_package_map | ||
(dune_package_map : Package.t Package.Name.Map.t) : | ||
OpamFile.OPAM.t OpamTypes.name_map = | ||
Package.Name.Map.to_list_map dune_package_map | ||
~f:(fun dune_package_name dune_package -> | ||
let opam_package_name = | ||
Package.Name.to_opam_package_name dune_package_name | ||
in | ||
let opam_file = Package.to_opam_file dune_package in | ||
(opam_package_name, opam_file)) | ||
|> OpamPackage.Name.Map.of_list | ||
|
||
let term = | ||
let+ (common : Common.t) = Common.term | ||
and+ env = Env.term | ||
and+ repo = Repo.term in | ||
let config = Common.init common in | ||
Scheduler.go ~common ~config (fun () -> | ||
let open Fiber.O in | ||
let* source_dir = Memo.run (Source_tree.root ()) in | ||
let project = Source_tree.Dir.project source_dir in | ||
let dune_package_map = Dune_project.packages project in | ||
let opam_file_map = | ||
opam_file_map_of_dune_package_map dune_package_map | ||
in | ||
let lock_dir_path = Lock_dir.path in | ||
let summary, lock_dir = | ||
Dune_pkg.Opam.solve_lock_dir ~env ~repo ~lock_dir_path opam_file_map | ||
in | ||
Console.print_user_message | ||
(Dune_pkg.Opam.Summary.selected_packages_message summary); | ||
Lock_dir.write_disk ~lock_dir_path lock_dir; | ||
Fiber.return ()) | ||
|
||
let info = | ||
let doc = "Create a lockfile" in | ||
Cmd.info "lock" ~doc | ||
|
||
let command = Cmd.v info term | ||
end | ||
|
||
let info = | ||
let doc = "Experimental package management" in | ||
let man = | ||
[ `S "DESCRIPTION" | ||
; `P {|Commands for doing package management with dune|} | ||
; `Blocks Common.help_secs | ||
] | ||
in | ||
Cmd.info "pkg" ~doc ~man | ||
|
||
let group = Cmd.group info [ Lock.command ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
open Import | ||
|
||
val group : unit Cmd.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module Fetch = Fetch | ||
module Checksum = Checksum | ||
module Lock_dir = Lock_dir | ||
module Opam = Opam |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Before deleting, how about we make sure this is a real lock file directory if it exists to avoid unfortunate accidents. For example, we check that it has a
dune.lock
file.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.
ooh good idea! Will implement