-
Notifications
You must be signed in to change notification settings - Fork 28
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
Populate pin-depends
only with the packages that needs to be pinned in the switch
#400
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -170,6 +170,24 @@ let root_pin_depends local_opam_files = | |
local_opam_files [] | ||
|> D.Pin_depends.sort_uniq | ||
|
||
let get_local_pins source_config = | ||
match (source_config : D.Source_opam_config.t) with | ||
| { repositories = Some _; _ } -> | ||
(* ignore local pins with using x-opam-monorepo-repositories *) | ||
[] | ||
| _ -> | ||
OpamGlobalState.with_ `Lock_none @@ fun global_state -> | ||
OpamSwitchState.with_ `Lock_none global_state @@ fun switch_state -> | ||
OpamPinned.packages switch_state | ||
|> OpamPackage.Set.to_seq | ||
|> Seq.filter_map (fun pkg -> | ||
match OpamSwitchState.url switch_state pkg with | ||
| None -> | ||
(* ignore version-pinned packages *) | ||
None | ||
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. Maybe it would make more sense to make this into a named function |
||
| Some url -> Some (pkg, OpamFile.URL.url url)) | ||
|> List.of_seq | ||
|
||
let pull_pin_depends ~global_state pin_depends = | ||
let open Result.O in | ||
if Base.List.is_empty pin_depends then Ok OpamPackage.Name.Map.empty | ||
|
@@ -570,11 +588,28 @@ let run (`Root root) (`Recurse_opam recurse) (`Build_only build_only) | |
~require_cross_compile ~preferred_versions ~ocaml_version | ||
~local_opam_files:opam_files ~target_packages | ||
in | ||
let dependency_table = | ||
let aux { D.Opam.Dependency_entry.package_summary; vendored } = | ||
(package_summary.package, vendored) | ||
in | ||
dependency_entries |> List.to_seq |> Seq.map aux |> OpamPackage.Map.of_seq | ||
in | ||
Common.Logs.app (fun l -> l "Calculating exact pins for each of them."); | ||
let* duniverse = compute_duniverse ~dependency_entries >>= resolve_ref in | ||
let target_depexts = target_depexts opam_files target_packages in | ||
let* pin_depends = root_pin_depends opam_files in | ||
let local_pins = get_local_pins source_config in | ||
let pin_depends = | ||
List.filter | ||
~f:(fun (p, _) -> | ||
match OpamPackage.Map.find_opt p dependency_table with | ||
| None -> assert false | ||
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. In this case |
||
| Some vendored -> not vendored) | ||
pin_depends | ||
@ local_pins | ||
in | ||
let lockfile = | ||
D.Lockfile.create ~source_config ~root_packages:target_packages | ||
D.Lockfile.create ~source_config ~root_packages:target_packages ~pin_depends | ||
~dependency_entries ~root_depexts:target_depexts ~duniverse () | ||
in | ||
let cli_args = raw_cli_args () in | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
opam-version: "2.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
opam-version: "2.0" | ||
depends: [ | ||
"dune" | ||
"b" | ||
"c" | ||
] | ||
pin-depends: ["b.dev" "./duniverse/b"] | ||
x-opam-monorepo-opam-provided: ["b"] | ||
x-opam-monorepo-opam-repositories: [ | ||
"file://$OPAM_MONOREPO_CWD/minimal-repo" | ||
"file://$OPAM_MONOREPO_CWD/repo" | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
opam-version: "2.0" | ||
depends: [ | ||
"dune" | ||
] | ||
build: [ "dune" "build" ] | ||
dev-repo: "git+https://github.com/b/b" | ||
url { | ||
src: "https://b.com/b.tbz" | ||
checksum: [ | ||
"sha256=0000000000000000000000000000000000000000000000000000000000000000" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
opam-version: "2.0" | ||
depends: [ | ||
"dune" | ||
] | ||
build: [ "dune" "build" ] | ||
dev-repo: "git+https://github.com/c/c" | ||
url { | ||
src: "https://c.com/c.tbz" | ||
checksum: [ | ||
"sha256=0000000000000000000000000000000000000000000000000000000000000001" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
opam-version: "2.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
We have a simple project with a single package defined at the root. | ||
It has a `x-opam-monorepo-opam-repositories` field set to use a local | ||
opam-repository for locking and a pinned package. | ||
|
||
$ cat pin-depends.opam | ||
opam-version: "2.0" | ||
depends: [ | ||
"dune" | ||
"b" | ||
"c" | ||
] | ||
pin-depends: ["b.dev" "./duniverse/b"] | ||
x-opam-monorepo-opam-provided: ["b"] | ||
x-opam-monorepo-opam-repositories: [ | ||
"file://$OPAM_MONOREPO_CWD/minimal-repo" | ||
"file://$OPAM_MONOREPO_CWD/repo" | ||
] | ||
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. I don't think printing it here makes sense. If you want to have the contents of the |
||
|
||
We provided a minimal opam-repository but locking should be successful. | ||
|
||
$ gen-minimal-repo | ||
$ opam-monorepo lock | ||
==> Using 1 locally scanned package as the target. | ||
==> Found 10 opam dependencies for the target package. | ||
==> Querying opam database for their metadata and Dune compatibility. | ||
==> Calculating exact pins for each of them. | ||
==> Wrote lockfile with 1 entries to $TESTCASE_ROOT/pin-depends.opam.locked. You can now run opam monorepo pull to fetch their sources. | ||
|
||
The lockfile should contain the base packages, dune and our 2 dependencies | ||
`b` and `c` which should be pulled in the duniverse | ||
|
||
$ cat pin-depends.opam.locked | sed 's|file://.*/pin-depends.t/|file://$LOCAL_PATH/|' | ||
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. Could you make this print just the relevant subsets of the lockfile? Otherwise the test is full of incidental content of the lockfile that will need to keep getting updated. Something like |
||
opam-version: "2.0" | ||
synopsis: "opam-monorepo generated lockfile" | ||
maintainer: "opam-monorepo" | ||
depends: [ | ||
"b" {= "dev"} | ||
"base-bigarray" {= "base"} | ||
"base-threads" {= "base"} | ||
"base-unix" {= "base"} | ||
"c" {= "1" & ?vendor} | ||
"dune" {= "2.9.1"} | ||
"ocaml" {= "4.13.1"} | ||
"ocaml-base-compiler" {= "4.13.1"} | ||
"ocaml-config" {= "2"} | ||
"ocaml-options-vanilla" {= "1"} | ||
] | ||
pin-depends: [ | ||
"b.dev" | ||
"file://$LOCAL_PATH/duniverse/b" | ||
] | ||
x-opam-monorepo-duniverse-dirs: [ | ||
[ | ||
"https://c.com/c.tbz" | ||
"c" | ||
[ | ||
"sha256=0000000000000000000000000000000000000000000000000000000000000001" | ||
] | ||
] | ||
] | ||
x-opam-monorepo-opam-provided: ["b"] | ||
x-opam-monorepo-opam-repositories: [ | ||
"file://$OPAM_MONOREPO_CWD/minimal-repo" "file://$OPAM_MONOREPO_CWD/repo" | ||
] | ||
x-opam-monorepo-root-packages: ["pin-depends"] | ||
x-opam-monorepo-version: "0.3" |
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.
Small typo: