-
Notifications
You must be signed in to change notification settings - Fork 409
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
feat: introduce the @pkg-install alias #11046
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 |
---|---|---|
|
@@ -338,6 +338,19 @@ let gen_rules_group_part_or_root sctx dir_contents cctxs ~source_dir ~dir | |
contexts | ||
;; | ||
|
||
let gen_project_rule_for_package_alias sctx project = | ||
let ctx = Super_context.context sctx in | ||
let ctx_name = Context.name ctx in | ||
let* is_lock_dir_active = Lock_dir.lock_dir_active ctx_name in | ||
if is_lock_dir_active | ||
then ( | ||
let dir = | ||
Path.Build.append_source (Context.build_dir ctx) @@ Dune_project.root project | ||
in | ||
Pkg_rules.gen_rule_alias_from_package_universe ~dir ctx_name) | ||
else Memo.return () | ||
;; | ||
|
||
(* Warn whenever [(name <name>)]) is missing from the [dune-project] file *) | ||
let missing_project_name = | ||
Warning.make | ||
|
@@ -355,6 +368,7 @@ let gen_project_rules = | |
and+ () = Odoc.gen_project_rules sctx project | ||
and+ () = Odoc_new.gen_project_rules sctx project | ||
and+ () = Ocaml_index.project_rule sctx project | ||
and+ () = gen_project_rule_for_package_alias sctx project | ||
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. This needs to be done only once per context rather than for every project |
||
and+ () = | ||
let version = 2, 8 in | ||
match Dune_project.allow_approximate_merlin project with | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1937,6 +1937,25 @@ let build_rule context_name ~source_deps (pkg : Pkg.t) = | |
~directory_targets:[ pkg.write_paths.target_dir ] | ||
;; | ||
|
||
let gen_rule_alias_from_package_universe ~dir ctx_name = | ||
let target_path_of_pkg pkg = | ||
let pkg_name = Dune_lang.Package_name.to_string pkg in | ||
Path.Build.L.relative | ||
Private_context.t.build_dir | ||
[ Context_name.to_string ctx_name; ".pkg"; pkg_name; "target" ] | ||
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. You should go through the paths module to get this path |
||
|> Path.build | ||
in | ||
let* packages = | ||
Package_universe.lock_dir (Project_dependencies ctx_name) | ||
>>| (fun lock_dir -> lock_dir.packages) | ||
>>| Dune_lang.Package_name.Map.keys | ||
in | ||
let alias = Alias.make Alias0.pkg_install ~dir in | ||
List.map ~f:target_path_of_pkg packages | ||
|> Action_builder.paths | ||
|> Rules.Produce.Alias.add_deps alias | ||
;; | ||
|
||
let gen_rules context_name (pkg : Pkg.t) = | ||
let* source_deps, copy_rules = source_rules pkg in | ||
let* () = copy_rules | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
This test verifies the @pkg-deps alias fetch and build the project dependencies | ||
without building the project itself. | ||
|
||
$ . ./helpers.sh | ||
|
||
Create a fake library to install in the target project as a dependency: | ||
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 didn't really get why you need a fake library and executable in this test. I see the following as sufficient:
Everything else seems redundant. 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. As we want to build the library and ensure it is installed, you need the fake library to make sure dune build correctly. Otherwise, it will fail when you try to use it as a dependency. |
||
$ mkdir foo | ||
$ cd foo | ||
$ cat > dune-project <<EOF | ||
> (lang dune 3.16) | ||
> (package (name foo)) | ||
> EOF | ||
$ cat > foo.ml <<EOF | ||
> let foo = "Hello, World!" | ||
> EOF | ||
$ cat > dune <<EOF | ||
> (library | ||
> (public_name foo)) | ||
> EOF | ||
$ cd .. | ||
$ tar cf foo.tar foo | ||
$ rm -rf foo | ||
|
||
Make an opam package for the library: | ||
$ mkpkg foo <<EOF | ||
> build: [ | ||
> [ | ||
> "dune" | ||
> "build" | ||
> "-p" | ||
> name | ||
> "@install" | ||
> ] | ||
> ] | ||
> url { | ||
> src: "$PWD/foo.tar" | ||
> } | ||
> EOF | ||
|
||
Create a project using the fake library as a dependency: | ||
$ cat > dune-project << EOF | ||
> (lang dune 3.16) | ||
> (package | ||
> (name bar) | ||
> (allow_empty) | ||
> (depends foo)) | ||
> EOF | ||
$ add_mock_repo_if_needed | ||
$ dune pkg lock | ||
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. Why do you need to involve the solver in this test? 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. It was the easiest way to write the test. However, it should be possible to write it without using the |
||
Solution for dune.lock: | ||
- foo.0.0.1 | ||
|
||
Create an executable which uses the fake dependency. It ensures we build the | ||
dependency package but not the package: | ||
$ cat > dune << EOF | ||
> (executable | ||
> (name bar) | ||
> (libraries foo)) | ||
> EOF | ||
$ cat > bar.ml << EOF | ||
> let () = print_endline "source" | ||
> EOF | ||
|
||
The alias call builds the `foo` dependency but not the project itself. We | ||
verify we have the `foo` package but not the `bar.exe` in the build directory: | ||
$ dune build @pkg-deps | ||
$ ls _build/_private/default/.pkg/ | ||
foo | ||
$ ls _build/default/ | ||
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 was thinking about the way to detect that the build is happening is to maybe enable the console output and have the 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. Why should there be a build happening? This alias is supposed to only download the deps. |
||
|
||
Verify that building the `bar.exe` file is working: | ||
$ dune build ./bar.exe | ||
$ ls _build/default/bar.exe | ||
_build/default/bar.exe | ||
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. And this could then just be replaced by This has the slight downside that 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. It would mean to add a rule that depends on the 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.
|
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.
It's incorrect to mark this alias as "standard" as it's not defined in every single directory.
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.
If I don't mark it as standard, it will complain that it is not attached to any folder in the source. What is the best way to attached it to the source if I don't declare it as standard?